From 6cd1e5e3846b4888d37a60abc379cd2b2b85b3db Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Thu, 25 Feb 2021 16:29:05 +0000 Subject: [PATCH] Avoid passing around a massive $LOAD_PATH. Portable Ruby crashes if the $LOAD_PATH gets too big. --- Library/Homebrew/build.rb | 2 +- Library/Homebrew/config.rb | 6 ++++++ Library/Homebrew/dev-cmd/test.rb | 5 +---- Library/Homebrew/formula_info.rb | 6 ++---- Library/Homebrew/formula_installer.rb | 13 ++++++------- Library/Homebrew/postinstall.rb | 2 +- Library/Homebrew/software_spec.rb | 1 - Library/Homebrew/test.rb | 2 +- Library/Homebrew/test/dev-cmd/test_spec.rb | 3 +-- Library/Homebrew/test/formula_info_spec.rb | 1 - .../helper/spec/shared_context/integration_test.rb | 9 +++------ Library/Homebrew/test/support/lib/config.rb | 5 +++++ 12 files changed, 27 insertions(+), 28 deletions(-) diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index ce81f72772..62c566f922 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -6,7 +6,7 @@ old_trap = trap("INT") { exit! 130 } -require "global" +require_relative "global" require "build_options" require "cxxstdlib" require "keg" diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index f7ce3cc14f..4369b95616 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -67,3 +67,9 @@ HOMEBREW_TEMP = Pathname(EnvVar["HOMEBREW_TEMP"]).yield_self do |tmp| tmp.mkpath unless tmp.exist? tmp.realpath end.freeze + +# The Ruby path and args to use for forked Ruby calls +HOMEBREW_RUBY_EXEC_ARGS = [ + RUBY_PATH, + ENV["HOMEBREW_RUBY_WARNINGS"], +].freeze diff --git a/Library/Homebrew/dev-cmd/test.rb b/Library/Homebrew/dev-cmd/test.rb index 7a8ba4502a..c53c59365e 100644 --- a/Library/Homebrew/dev-cmd/test.rb +++ b/Library/Homebrew/dev-cmd/test.rb @@ -77,10 +77,7 @@ module Homebrew env = ENV.to_hash begin - exec_args = %W[ - #{RUBY_PATH} - #{ENV["HOMEBREW_RUBY_WARNINGS"]} - -I #{$LOAD_PATH.join(File::PATH_SEPARATOR)} + exec_args = HOMEBREW_RUBY_EXEC_ARGS + %W[ -- #{HOMEBREW_LIBRARY_PATH}/test.rb #{f.path} diff --git a/Library/Homebrew/formula_info.rb b/Library/Homebrew/formula_info.rb index ad8035172b..1059fb5c2a 100644 --- a/Library/Homebrew/formula_info.rb +++ b/Library/Homebrew/formula_info.rb @@ -16,13 +16,11 @@ class FormulaInfo # Returns nil if formula is absent or if there was an error reading it. def self.lookup(name) json = Utils.popen_read( - RUBY_PATH, - ENV["HOMEBREW_RUBY_WARNINGS"], - "-I", $LOAD_PATH.join(File::PATH_SEPARATOR), + *HOMEBREW_RUBY_EXEC_ARGS, HOMEBREW_LIBRARY_PATH/"brew.rb", "info", "--json=v1", - name + name, ) return unless $CHILD_STATUS.success? diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index c1456aa541..20e4928cf2 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -896,13 +896,12 @@ class FormulaInstaller # 1. formulae can modify ENV, so we must ensure that each # installation has a pristine ENV when it starts, forking now is # the easiest way to do this - args = %W[ - nice #{RUBY_PATH} - #{ENV["HOMEBREW_RUBY_WARNINGS"]} - -I #{$LOAD_PATH.join(File::PATH_SEPARATOR)} - -- - #{HOMEBREW_LIBRARY_PATH}/build.rb - #{formula.specified_path} + args = [ + "nice", + *HOMEBREW_RUBY_EXEC_ARGS, + "--", + HOMEBREW_LIBRARY_PATH/"build.rb", + formula.specified_path, ].concat(build_argv) Utils.safe_fork do diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index 6856fa07ed..bd836db12a 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -3,7 +3,7 @@ old_trap = trap("INT") { exit! 130 } -require "global" +require_relative "global" require "debrew" require "fcntl" require "socket" diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 71ddf95a22..e53bf90728 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -11,7 +11,6 @@ require "dependency_collector" require "utils/bottles" require "patch" require "compilers" -require "global" require "os/mac/version" require "extend/on_os" diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index 72f373c8bb..d560da83db 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -3,7 +3,7 @@ old_trap = trap("INT") { exit! 130 } -require "global" +require_relative "global" require "extend/ENV" require "timeout" require "debrew" diff --git a/Library/Homebrew/test/dev-cmd/test_spec.rb b/Library/Homebrew/test/dev-cmd/test_spec.rb index bf4ee0660f..4466262501 100644 --- a/Library/Homebrew/test/dev-cmd/test_spec.rb +++ b/Library/Homebrew/test/dev-cmd/test_spec.rb @@ -6,8 +6,7 @@ require "cmd/shared_examples/args_parse" describe "brew test" do it_behaves_like "parseable arguments" - # randomly segfaults on Linux with portable-ruby. - it "tests a given Formula", :integration_test, :needs_macos do + it "tests a given Formula", :integration_test do install_test_formula "testball", <<~'RUBY' test do assert_equal "test", shell_output("#{bin}/test") diff --git a/Library/Homebrew/test/formula_info_spec.rb b/Library/Homebrew/test/formula_info_spec.rb index 0e8bcebb10..c9c1c7a366 100644 --- a/Library/Homebrew/test/formula_info_spec.rb +++ b/Library/Homebrew/test/formula_info_spec.rb @@ -2,7 +2,6 @@ # frozen_string_literal: true require "formula_info" -require "global" describe FormulaInfo, :integration_test do it "tests the FormulaInfo class" do 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 a4208287f3..f8e5aa9e49 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 @@ -87,10 +87,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin ) @ruby_args ||= begin - ruby_args = [ - ENV["HOMEBREW_RUBY_WARNINGS"], - "-I", $LOAD_PATH.join(File::PATH_SEPARATOR) - ] + ruby_args = HOMEBREW_RUBY_EXEC_ARGS.dup if ENV["HOMEBREW_TESTS_COVERAGE"] simplecov_spec = Gem.loaded_specs["simplecov"] specs = [simplecov_spec] @@ -111,12 +108,12 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin libs.each { |lib| ruby_args << "-I" << lib } ruby_args << "-rsimplecov" end - ruby_args << "-rtest/support/helper/integration_mocks" + ruby_args << "-r#{HOMEBREW_LIBRARY_PATH}/test/support/helper/integration_mocks" ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s end Bundler.with_clean_env do - stdout, stderr, status = Open3.capture3(env, RUBY_PATH, *@ruby_args, *args) + stdout, stderr, status = Open3.capture3(env, *@ruby_args, *args) $stdout.print stdout $stderr.print stderr status diff --git a/Library/Homebrew/test/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb index 1dede23e84..9e11210c39 100644 --- a/Library/Homebrew/test/support/lib/config.rb +++ b/Library/Homebrew/test/support/lib/config.rb @@ -37,6 +37,11 @@ HOMEBREW_LOCKS = (HOMEBREW_PREFIX.parent/"locks").freeze HOMEBREW_CELLAR = (HOMEBREW_PREFIX.parent/"cellar").freeze HOMEBREW_LOGS = (HOMEBREW_PREFIX.parent/"logs").freeze HOMEBREW_TEMP = (HOMEBREW_PREFIX.parent/"temp").freeze +HOMEBREW_RUBY_EXEC_ARGS = [ + RUBY_PATH, + ENV["HOMEBREW_RUBY_WARNINGS"], + "-I", HOMEBREW_LIBRARY_PATH/"test/support/lib" +].freeze TEST_FIXTURE_DIR = (HOMEBREW_LIBRARY_PATH/"test/support/fixtures").freeze