Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak Gem vendoring. #2603

Merged
merged 1 commit into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2
raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO

homebrew_library_path = File.dirname(File.realpath(__FILE__))
$:.unshift(homebrew_library_path)

require_relative "#{homebrew_library_path}/vendor/bundler/setup"

require "pathname"
HOMEBREW_LIBRARY_PATH = Pathname.new(homebrew_library_path)
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
$:.unshift(HOMEBREW_LIBRARY_PATH)

load_path_before_bundler = $:.dup
require_relative "#{HOMEBREW_LIBRARY_PATH}/vendor/bundler/setup"
ENV["HOMEBREW_GEMS_LOAD_PATH"] = ($: - load_path_before_bundler).join(":")

require "global"
require "tap"
Expand All @@ -25,8 +25,6 @@
exit 0
end

HOMEBREW_GEM_HOME = HOMEBREW_LIBRARY_PATH/"vendor/#{RUBY_ENGINE}/#{RUBY_VERSION}"

def require?(path)
require path
rescue LoadError => e
Expand Down Expand Up @@ -60,18 +58,21 @@ def require?(path)
path.append(Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd"))

# Add RubyGems.
ENV["GEM_HOME"] = ENV["GEM_PATH"] = HOMEBREW_GEM_HOME
HOMEBREW_GEM_HOME = HOMEBREW_LIBRARY_PATH/"vendor/#{RUBY_ENGINE}/#{RUBY_VERSION}"
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)

Expand Down
4 changes: 0 additions & 4 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ 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
Expand Down
5 changes: 4 additions & 1 deletion Library/Homebrew/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@
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_LOAD_PATH = [HOMEBREW_LIBRARY_PATH, *HOMEBREW_GEMS_LOAD_PATH].join(":")
5 changes: 4 additions & 1 deletion Library/Homebrew/os/mac/mach.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
require "macho"
require "os/mac/architecture_list"

module MachOShim
# @private
def macho
@macho ||= begin
require "macho"

MachO.open(to_s)
end
end

# @private
def mach_data
@mach_data ||= begin
require "macho"

machos = []
mach_data = []

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/test/support/lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
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].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, ENV["HOMEBREW_GEMS_LOAD_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")
Expand Down
42 changes: 0 additions & 42 deletions Library/Homebrew/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,48 +179,6 @@ def system(cmd, *args)
_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?

Expand Down