diff options
Diffstat (limited to 'Library/Homebrew')
| -rw-r--r-- | Library/Homebrew/brew.rb | 27 | ||||
| -rw-r--r-- | Library/Homebrew/brew.sh | 4 | ||||
| -rw-r--r-- | Library/Homebrew/config.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/os/mac/mach.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/test/support/lib/config.rb | 6 | ||||
| -rw-r--r-- | Library/Homebrew/utils.rb | 42 |
6 files changed, 64 insertions, 25 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index e19819cf5..6dab50f29 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -8,13 +8,13 @@ std_trap = trap("INT") { exit! 130 } # no backtrace thanks RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2 raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO -require "pathname" -HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent -$:.unshift(HOMEBREW_LIBRARY_PATH) +homebrew_library_path = File.dirname(File.realpath(__FILE__)) +$:.unshift(homebrew_library_path) + +require_relative "#{homebrew_library_path}/vendor/bundler/setup" -load_path_before_bundler = $:.dup -require_relative "#{HOMEBREW_LIBRARY_PATH}/vendor/bundler/setup" -ENV["HOMEBREW_GEMS_LOAD_PATH"] = ($: - load_path_before_bundler).join(":") +require "pathname" +HOMEBREW_LIBRARY_PATH = Pathname.new(homebrew_library_path) require "global" require "tap" @@ -25,6 +25,8 @@ if ARGV == %w[--version] || ARGV == %w[-v] exit 0 end +HOMEBREW_GEM_HOME = HOMEBREW_LIBRARY_PATH/"vendor/#{RUBY_ENGINE}/#{RUBY_VERSION}" + def require?(path) require path rescue LoadError => e @@ -58,21 +60,18 @@ begin path.append(Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd")) # Add RubyGems. - HOMEBREW_GEM_HOME = HOMEBREW_LIBRARY_PATH/"vendor/#{RUBY_ENGINE}/#{RUBY_VERSION}" + ENV["GEM_HOME"] = ENV["GEM_PATH"] = HOMEBREW_GEM_HOME path.append(HOMEBREW_GEM_HOME/"bin") + # Make RubyGems notice environment changes. + Gem.clear_paths + Gem::Specification.reset + # Add SCM wrappers. path.append(HOMEBREW_SHIMS_PATH/"scm") ENV["PATH"] = path - # Setup RubyGems environment. - ENV["GEM_HOME"] = ENV["GEM_PATH"] = HOMEBREW_GEM_HOME - # Make RubyGems notice environment changes. - Gem.clear_paths - Gem::Specification.reset - Homebrew.run_bundler_if_needed! unless HOMEBREW_GEM_HOME.exist? - if cmd internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 6f4453f28..02ce5e1c1 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -69,6 +69,10 @@ then odie "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX" fi +# Save value to use for installing gems +export GEM_OLD_HOME="$GEM_HOME" +export GEM_OLD_PATH="$GEM_PATH" + # Users may have these set, pointing the system Ruby # at non-system gem paths unset GEM_HOME diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index ef07434de..38d7c8043 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -46,8 +46,5 @@ unless defined? HOMEBREW_LIBRARY_PATH HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent end -# Load path to vendored gems used by Homebrew -HOMEBREW_GEMS_LOAD_PATH = ENV["HOMEBREW_GEMS_LOAD_PATH"] - # Load path used by standalone scripts to access the Homebrew code base -HOMEBREW_LOAD_PATH = [HOMEBREW_LIBRARY_PATH, *HOMEBREW_GEMS_LOAD_PATH].join(":") +HOMEBREW_LOAD_PATH = HOMEBREW_LIBRARY_PATH diff --git a/Library/Homebrew/os/mac/mach.rb b/Library/Homebrew/os/mac/mach.rb index 416183f68..71f501fe9 100644 --- a/Library/Homebrew/os/mac/mach.rb +++ b/Library/Homebrew/os/mac/mach.rb @@ -1,11 +1,10 @@ +require "macho" require "os/mac/architecture_list" module MachOShim # @private def macho @macho ||= begin - require "macho" - MachO.open(to_s) end end @@ -13,8 +12,6 @@ module MachOShim # @private def mach_data @mach_data ||= begin - require "macho" - machos = [] mach_data = [] diff --git a/Library/Homebrew/test/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb index 41f4cbe33..fb5c210fe 100644 --- a/Library/Homebrew/test/support/lib/config.rb +++ b/Library/Homebrew/test/support/lib/config.rb @@ -14,9 +14,9 @@ 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("../../../..", __FILE__)) -HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent+"Homebrew/shims" -HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH, ENV["HOMEBREW_GEMS_LOAD_PATH"]].join(":") +HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../../..", __FILE__)) +HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent+"Homebrew/shims" +HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":") # Paths redirected to a temporary directory and wiped at the end of the test run HOMEBREW_PREFIX = Pathname.new(TEST_TMPDIR).join("prefix") diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 6ae75a4fb..60af39d93 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -179,6 +179,48 @@ module Homebrew _system(cmd, *args) end + def install_gem_setup_path!(name, version = nil, executable = name) + # Respect user's preferences for where gems should be installed. + ENV["GEM_HOME"] = ENV["GEM_OLD_HOME"].to_s + ENV["GEM_HOME"] = Gem.user_dir if ENV["GEM_HOME"].empty? + ENV["GEM_PATH"] = ENV["GEM_OLD_PATH"] unless ENV["GEM_OLD_PATH"].to_s.empty? + + # Make rubygems notice env changes. + Gem.clear_paths + Gem::Specification.reset + + # Add Gem binary directory and (if missing) Ruby binary directory to PATH. + path = PATH.new(ENV["PATH"]) + path.prepend(RUBY_BIN) if which("ruby") != RUBY_PATH + path.prepend(Gem.bindir) + ENV["PATH"] = path + + if Gem::Specification.find_all_by_name(name, version).empty? + ohai "Installing or updating '#{name}' gem" + install_args = %W[--no-ri --no-rdoc #{name}] + install_args << "--version" << version if version + + # Do `gem install [...]` without having to spawn a separate process or + # having to find the right `gem` binary for the running Ruby interpreter. + require "rubygems/commands/install_command" + install_cmd = Gem::Commands::InstallCommand.new + install_cmd.handle_options(install_args) + exit_code = 1 # Should not matter as `install_cmd.execute` always throws. + begin + install_cmd.execute + rescue Gem::SystemExitException => e + exit_code = e.exit_code + end + odie "Failed to install/update the '#{name}' gem." if exit_code.nonzero? + end + + return if which(executable) + odie <<-EOS.undent + The '#{name}' gem is installed but couldn't find '#{executable}' in the PATH: + #{ENV["PATH"]} + EOS + end + def run_bundler_if_needed! return unless Pathname.glob("#{HOMEBREW_GEM_HOME}/bin/*").empty? |
