Avoid passing around a massive $LOAD_PATH.

Portable Ruby crashes if the $LOAD_PATH gets too big.
This commit is contained in:
Bo Anderson 2021-02-25 16:29:05 +00:00
parent 1fba9b9b53
commit 6cd1e5e384
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
12 changed files with 27 additions and 28 deletions

View File

@ -6,7 +6,7 @@
old_trap = trap("INT") { exit! 130 } old_trap = trap("INT") { exit! 130 }
require "global" require_relative "global"
require "build_options" require "build_options"
require "cxxstdlib" require "cxxstdlib"
require "keg" require "keg"

View File

@ -67,3 +67,9 @@ HOMEBREW_TEMP = Pathname(EnvVar["HOMEBREW_TEMP"]).yield_self do |tmp|
tmp.mkpath unless tmp.exist? tmp.mkpath unless tmp.exist?
tmp.realpath tmp.realpath
end.freeze end.freeze
# The Ruby path and args to use for forked Ruby calls
HOMEBREW_RUBY_EXEC_ARGS = [
RUBY_PATH,
ENV["HOMEBREW_RUBY_WARNINGS"],
].freeze

View File

@ -77,10 +77,7 @@ module Homebrew
env = ENV.to_hash env = ENV.to_hash
begin begin
exec_args = %W[ exec_args = HOMEBREW_RUBY_EXEC_ARGS + %W[
#{RUBY_PATH}
#{ENV["HOMEBREW_RUBY_WARNINGS"]}
-I #{$LOAD_PATH.join(File::PATH_SEPARATOR)}
-- --
#{HOMEBREW_LIBRARY_PATH}/test.rb #{HOMEBREW_LIBRARY_PATH}/test.rb
#{f.path} #{f.path}

View File

@ -16,13 +16,11 @@ class FormulaInfo
# Returns nil if formula is absent or if there was an error reading it. # Returns nil if formula is absent or if there was an error reading it.
def self.lookup(name) def self.lookup(name)
json = Utils.popen_read( json = Utils.popen_read(
RUBY_PATH, *HOMEBREW_RUBY_EXEC_ARGS,
ENV["HOMEBREW_RUBY_WARNINGS"],
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
HOMEBREW_LIBRARY_PATH/"brew.rb", HOMEBREW_LIBRARY_PATH/"brew.rb",
"info", "info",
"--json=v1", "--json=v1",
name name,
) )
return unless $CHILD_STATUS.success? return unless $CHILD_STATUS.success?

View File

@ -896,13 +896,12 @@ class FormulaInstaller
# 1. formulae can modify ENV, so we must ensure that each # 1. formulae can modify ENV, so we must ensure that each
# installation has a pristine ENV when it starts, forking now is # installation has a pristine ENV when it starts, forking now is
# the easiest way to do this # the easiest way to do this
args = %W[ args = [
nice #{RUBY_PATH} "nice",
#{ENV["HOMEBREW_RUBY_WARNINGS"]} *HOMEBREW_RUBY_EXEC_ARGS,
-I #{$LOAD_PATH.join(File::PATH_SEPARATOR)} "--",
-- HOMEBREW_LIBRARY_PATH/"build.rb",
#{HOMEBREW_LIBRARY_PATH}/build.rb formula.specified_path,
#{formula.specified_path}
].concat(build_argv) ].concat(build_argv)
Utils.safe_fork do Utils.safe_fork do

View File

@ -3,7 +3,7 @@
old_trap = trap("INT") { exit! 130 } old_trap = trap("INT") { exit! 130 }
require "global" require_relative "global"
require "debrew" require "debrew"
require "fcntl" require "fcntl"
require "socket" require "socket"

View File

@ -11,7 +11,6 @@ require "dependency_collector"
require "utils/bottles" require "utils/bottles"
require "patch" require "patch"
require "compilers" require "compilers"
require "global"
require "os/mac/version" require "os/mac/version"
require "extend/on_os" require "extend/on_os"

View File

@ -3,7 +3,7 @@
old_trap = trap("INT") { exit! 130 } old_trap = trap("INT") { exit! 130 }
require "global" require_relative "global"
require "extend/ENV" require "extend/ENV"
require "timeout" require "timeout"
require "debrew" require "debrew"

View File

@ -6,8 +6,7 @@ require "cmd/shared_examples/args_parse"
describe "brew test" do describe "brew test" do
it_behaves_like "parseable arguments" it_behaves_like "parseable arguments"
# randomly segfaults on Linux with portable-ruby. it "tests a given Formula", :integration_test do
it "tests a given Formula", :integration_test, :needs_macos do
install_test_formula "testball", <<~'RUBY' install_test_formula "testball", <<~'RUBY'
test do test do
assert_equal "test", shell_output("#{bin}/test") assert_equal "test", shell_output("#{bin}/test")

View File

@ -2,7 +2,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require "formula_info" require "formula_info"
require "global"
describe FormulaInfo, :integration_test do describe FormulaInfo, :integration_test do
it "tests the FormulaInfo class" do it "tests the FormulaInfo class" do

View File

@ -87,10 +87,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
) )
@ruby_args ||= begin @ruby_args ||= begin
ruby_args = [ ruby_args = HOMEBREW_RUBY_EXEC_ARGS.dup
ENV["HOMEBREW_RUBY_WARNINGS"],
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR)
]
if ENV["HOMEBREW_TESTS_COVERAGE"] if ENV["HOMEBREW_TESTS_COVERAGE"]
simplecov_spec = Gem.loaded_specs["simplecov"] simplecov_spec = Gem.loaded_specs["simplecov"]
specs = [simplecov_spec] specs = [simplecov_spec]
@ -111,12 +108,12 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
libs.each { |lib| ruby_args << "-I" << lib } libs.each { |lib| ruby_args << "-I" << lib }
ruby_args << "-rsimplecov" ruby_args << "-rsimplecov"
end 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 ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s
end end
Bundler.with_clean_env do 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 $stdout.print stdout
$stderr.print stderr $stderr.print stderr
status status

View File

@ -37,6 +37,11 @@ HOMEBREW_LOCKS = (HOMEBREW_PREFIX.parent/"locks").freeze
HOMEBREW_CELLAR = (HOMEBREW_PREFIX.parent/"cellar").freeze HOMEBREW_CELLAR = (HOMEBREW_PREFIX.parent/"cellar").freeze
HOMEBREW_LOGS = (HOMEBREW_PREFIX.parent/"logs").freeze HOMEBREW_LOGS = (HOMEBREW_PREFIX.parent/"logs").freeze
HOMEBREW_TEMP = (HOMEBREW_PREFIX.parent/"temp").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 TEST_FIXTURE_DIR = (HOMEBREW_LIBRARY_PATH/"test/support/fixtures").freeze