diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 92f50411bd..e3ab2c8719 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -12,20 +12,7 @@ if RUBY_X < 2 || (RUBY_X == 2 && RUBY_Y < 3) raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}." end -require "pathname" -HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent - -require "English" - -unless $LOAD_PATH.include?("#{HOMEBREW_LIBRARY_PATH}/cask/lib") - $LOAD_PATH.unshift("#{HOMEBREW_LIBRARY_PATH}/cask/lib") -end - -unless $LOAD_PATH.include?(HOMEBREW_LIBRARY_PATH.to_s) - $LOAD_PATH.unshift(HOMEBREW_LIBRARY_PATH.to_s) -end - -require "global" +require_relative "global" begin trap("INT", std_trap) # restore default CTRL-C handler diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index 69406d1601..11b73791f1 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -46,14 +46,3 @@ HOMEBREW_TEMP = begin tmp.mkpath unless tmp.exist? tmp.realpath end - -unless defined? HOMEBREW_LIBRARY_PATH - # Root of the Homebrew code base - HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent -end - -# Load path used by standalone scripts to access the Homebrew code base -HOMEBREW_LOAD_PATH = [ - HOMEBREW_LIBRARY_PATH, - HOMEBREW_LIBRARY_PATH/"cask/lib", -].join(File::PATH_SEPARATOR) diff --git a/Library/Homebrew/dev-cmd/ruby.rb b/Library/Homebrew/dev-cmd/ruby.rb index c244bcdf13..f658529e07 100755 --- a/Library/Homebrew/dev-cmd/ruby.rb +++ b/Library/Homebrew/dev-cmd/ruby.rb @@ -8,6 +8,6 @@ module Homebrew module_function def ruby - exec ENV["HOMEBREW_RUBY_PATH"], "-I", HOMEBREW_LOAD_PATH, "-rglobal", "-rdev-cmd/irb", *ARGV + exec ENV["HOMEBREW_RUBY_PATH"], "-I", $LOAD_PATH.join(File::PATH_SEPARATOR), "-rglobal", "-rdev-cmd/irb", *ARGV end end diff --git a/Library/Homebrew/dev-cmd/test.rb b/Library/Homebrew/dev-cmd/test.rb index 56f439e3e0..d21a62cde5 100644 --- a/Library/Homebrew/dev-cmd/test.rb +++ b/Library/Homebrew/dev-cmd/test.rb @@ -65,7 +65,7 @@ module Homebrew args = %W[ #{RUBY_PATH} -W0 - -I #{HOMEBREW_LOAD_PATH} + -I #{$LOAD_PATH.join(File::PATH_SEPARATOR)} -- #{HOMEBREW_LIBRARY_PATH}/test.rb #{f.path} diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b2f9f60063..d9565ddd7c 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -729,7 +729,7 @@ class FormulaInstaller args = %W[ nice #{RUBY_PATH} -W0 - -I #{HOMEBREW_LOAD_PATH} + -I #{$LOAD_PATH.join(File::PATH_SEPARATOR)} -- #{HOMEBREW_LIBRARY_PATH}/build.rb #{formula.specified_path} @@ -886,7 +886,7 @@ class FormulaInstaller args = %W[ nice #{RUBY_PATH} -W0 - -I #{HOMEBREW_LOAD_PATH} + -I #{$LOAD_PATH.join(File::PATH_SEPARATOR)} -- #{HOMEBREW_LIBRARY_PATH}/postinstall.rb #{formula.path} diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index a28779547e..14458727cb 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -1,4 +1,18 @@ require "pathname" +require "English" + +HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent + +unless $LOAD_PATH.include?("#{HOMEBREW_LIBRARY_PATH}/cask/lib") + $LOAD_PATH.push("#{HOMEBREW_LIBRARY_PATH}/cask/lib") +end + +unless $LOAD_PATH.include?(HOMEBREW_LIBRARY_PATH.to_s) + $LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.to_s) +end + +require "config" + require "English" require "ostruct" require "messages" @@ -12,7 +26,6 @@ HOMEBREW_PRODUCT = ENV["HOMEBREW_PRODUCT"] HOMEBREW_VERSION = ENV["HOMEBREW_VERSION"] HOMEBREW_WWW = "https://brew.sh".freeze -require "config" require "extend/git_repository" HOMEBREW_REPOSITORY.extend(GitRepositoryExtension) diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 55e0cddfde..beafd0db81 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -14,11 +14,9 @@ require "rubocop" require "rubocop/rspec/support" require "find" -$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/cask/lib")) -$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew")) -$LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib")) +$LOAD_PATH.push(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib")) -require "global" +require_relative "../global" require "test/support/no_seed_progress_formatter" require "test/support/helper/fixtures" 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 57a38e6c37..e1ac4bbcbf 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 @@ -83,8 +83,7 @@ RSpec.shared_context "integration test" do @ruby_args ||= begin ruby_args = [ "-W0", - "-I", HOMEBREW_LOAD_PATH, - "-rconfig" + "-I", $LOAD_PATH.join(File::PATH_SEPARATOR) ] if ENV["HOMEBREW_TESTS_COVERAGE"] simplecov_spec = Gem.loaded_specs["simplecov"] diff --git a/Library/Homebrew/test/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb index cc8a8d69a2..5f0b69313c 100644 --- a/Library/Homebrew/test/support/lib/config.rb +++ b/Library/Homebrew/test/support/lib/config.rb @@ -13,13 +13,7 @@ TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") do |k| end # Paths pointing into the Homebrew code base that persist across test runs -HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../..", __dir__)) HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent/"Homebrew/shims" -HOMEBREW_LOAD_PATH = [ - File.expand_path(__dir__), - HOMEBREW_LIBRARY_PATH, - HOMEBREW_LIBRARY_PATH/"cask/lib", -].join(File::PATH_SEPARATOR) # Paths redirected to a temporary directory and wiped at the end of the test run HOMEBREW_PREFIX = Pathname(TEST_TMPDIR)/"prefix"