Skip to content
Snippets Groups Projects
Commit e1bbab6c authored by Mike McQuaid's avatar Mike McQuaid
Browse files

Revert "Merge pull request #2603 from MikeMcQuaid/tweak-gem-vendoring"

This reverts commit 23728729, reversing
changes made to 3e4547f5.
parent a76392dd
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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
......
......@@ -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
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 = []
......
......@@ -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")
......
......@@ -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?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment