Disable RubyGems by default.

This speeds up all Ruby invocations where we don't need RubyGems by
around 10%. Where we do need RubyGems: include it manually.
This commit is contained in:
Mike McQuaid 2019-04-18 17:43:33 +09:00
parent 640234caa1
commit ef2e297d3b
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
6 changed files with 14 additions and 5 deletions

View File

@ -327,6 +327,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 +486,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

View File

@ -1,5 +1,6 @@
module Homebrew
module Assertions
require "rubygems"
require "test/unit/assertions"
include ::Test::Unit::Assertions

View File

@ -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"

View File

@ -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|

View File

@ -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

View File

@ -37,7 +37,7 @@ setup-ruby-path() {
if [[ -n "$HOMEBREW_RUBY_PATH" && -z "$HOMEBREW_FORCE_VENDOR_RUBY" ]]
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="$("$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" ]]