diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 3679d4af40..ba6592eba5 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -127,6 +127,17 @@ then HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOME}/Library/Caches/Homebrew}" HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOME}/Library/Logs/Homebrew}" HOMEBREW_SYSTEM_TEMP="/private/tmp" + + # Set a variable when the macOS system Ruby is new enough to avoid spawning + # a Ruby process unnecessarily. + if [[ "$HOMEBREW_MACOS_VERSION_NUMERIC" -lt "101303" ]] + then + unset HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH + else + # Used in ruby.sh. + # shellcheck disable=SC2034 + HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH="1" + fi else HOMEBREW_PROCESSOR="$(uname -m)" HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew" @@ -157,6 +168,8 @@ else HOMEBREW_CACHE="${HOMEBREW_CACHE:-${CACHE_HOME}/Homebrew}" HOMEBREW_LOGS="${HOMEBREW_LOGS:-${CACHE_HOME}/Homebrew/Logs}" HOMEBREW_SYSTEM_TEMP="/tmp" + + unset HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH fi if [[ -n "$HOMEBREW_MACOS" || -n "$HOMEBREW_FORCE_HOMEBREW_ON_LINUX" ]] @@ -327,6 +340,12 @@ then # Don't allow non-developers to customise Ruby warnings. unset HOMEBREW_RUBY_WARNINGS + + # Disable Ruby options we don't need. RubyGems provides a decent speedup. + RUBY_DISABLE_OPTIONS="--disable=gems,did_you_mean,rubyopt" +else + # Don't disable did_you_mean for developers as it's useful. + RUBY_DISABLE_OPTIONS="--disable=gems,rubyopt" fi if [[ -z "$HOMEBREW_RUBY_WARNINGS" ]] @@ -480,5 +499,5 @@ else # Unshift command back into argument list (unless argument list was empty). [[ "$HOMEBREW_ARG_COUNT" -gt 0 ]] && set -- "$HOMEBREW_COMMAND" "$@" - { update-preinstall "$@"; exec "$HOMEBREW_RUBY_PATH" $HOMEBREW_RUBY_WARNINGS "$HOMEBREW_LIBRARY/Homebrew/brew.rb" "$@"; } + { update-preinstall "$@"; exec "$HOMEBREW_RUBY_PATH" $HOMEBREW_RUBY_WARNINGS "$RUBY_DISABLE_OPTIONS" "$HOMEBREW_LIBRARY/Homebrew/brew.rb" "$@"; } fi diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb index f81087a3dd..2ef69d6d7c 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -1,5 +1,6 @@ module Homebrew module Assertions + require "rubygems" require "test/unit/assertions" include ::Test::Unit::Assertions diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 2c90e5e939..9957789aba 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -1,13 +1,11 @@ #!/bin/sh # Make sure this shim uses the same Ruby interpreter that is used by Homebrew. -unset RUBYLIB -unset RUBYOPT if [ -z "$HOMEBREW_RUBY_PATH" ] then echo "${0##*/}: The build tool has reset ENV; --env=std required." >&2 exit 1 fi -exec "$HOMEBREW_RUBY_PATH" -x "$0" "$@" +exec "$HOMEBREW_RUBY_PATH" --disable=gems,did_you_mean,rubyopt -x "$0" "$@" #!/usr/bin/env ruby -W0 require "pathname" diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index f2ce76b0ee..f4d53e5a1b 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -100,7 +100,7 @@ module Homebrew raise "Invalid output_type for check_style_impl: #{output_type}" end - return !rubocop_success if !files.nil? && !has_non_formula + return !rubocop_success if files.present? || !has_non_formula shellcheck = which("shellcheck") shellcheck ||= which("shellcheck", ENV["HOMEBREW_PATH"]) diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 902204e1d8..f79df38dd4 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -89,6 +89,7 @@ RSpec.shared_context "integration test" do "-I", $LOAD_PATH.join(File::PATH_SEPARATOR) ] if ENV["HOMEBREW_TESTS_COVERAGE"] + require "rubygems" simplecov_spec = Gem.loaded_specs["simplecov"] specs = [simplecov_spec] simplecov_spec.runtime_dependencies.each do |dep| diff --git a/Library/Homebrew/utils/gems.rb b/Library/Homebrew/utils/gems.rb index 5b16b0bee2..04beb2c8cb 100644 --- a/Library/Homebrew/utils/gems.rb +++ b/Library/Homebrew/utils/gems.rb @@ -12,6 +12,7 @@ module Homebrew end def gem_user_bindir + require "rubygems" "#{Gem.user_dir}/bin".freeze end @@ -39,6 +40,7 @@ module Homebrew ENV["GEM_PATH"] = ENV["GEM_HOME"] # Make RubyGems notice environment changes. + require "rubygems" Gem.clear_paths Gem::Specification.reset @@ -76,6 +78,7 @@ module Homebrew end def install_bundler! + require "rubygems" setup_gem_environment!(gem_home: Gem.user_dir, gem_bindir: gem_user_bindir) install_gem_setup_path!("bundler", version: ">=2", executable: "bundle", setup_gem_environment: false) end diff --git a/Library/Homebrew/utils/ruby.sh b/Library/Homebrew/utils/ruby.sh index 91b30efe15..b1a2988505 100644 --- a/Library/Homebrew/utils/ruby.sh +++ b/Library/Homebrew/utils/ruby.sh @@ -35,9 +35,12 @@ setup-ruby-path() { HOMEBREW_RUBY_PATH="$(type -P ruby)" fi - if [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] + if [[ -n "$HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH" ]] then - ruby_version_new_enough="$("$HOMEBREW_RUBY_PATH" -rrubygems -e "puts Gem::Version.new(RUBY_VERSION.to_s.dup) >= Gem::Version.new('$minimum_ruby_version')")" + ruby_version_new_enough="true" + elif [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]] + then + ruby_version_new_enough="$("$HOMEBREW_RUBY_PATH" --disable=gems -rrubygems -e "puts Gem::Version.new(RUBY_VERSION.to_s.dup) >= Gem::Version.new('$minimum_ruby_version')")" fi if [[ -z "$HOMEBREW_RUBY_PATH" || -n "$HOMEBREW_FORCE_VENDOR_RUBY" || "$ruby_version_new_enough" != "true" ]]