Skip to content

Commit e1bbab6

Browse files
committed
Revert "Merge pull request #2603 from MikeMcQuaid/tweak-gem-vendoring"
This reverts commit 2372872, reversing changes made to 3e4547f.
1 parent a76392d commit e1bbab6

File tree

6 files changed

+64
-25
lines changed

6 files changed

+64
-25
lines changed

Library/Homebrew/brew.rb

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
RUBY_TWO = RUBY_VERSION.split(".").first.to_i >= 2
99
raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO
1010

11-
require "pathname"
12-
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
13-
$:.unshift(HOMEBREW_LIBRARY_PATH)
11+
homebrew_library_path = File.dirname(File.realpath(__FILE__))
12+
$:.unshift(homebrew_library_path)
13+
14+
require_relative "#{homebrew_library_path}/vendor/bundler/setup"
1415

15-
load_path_before_bundler = $:.dup
16-
require_relative "#{HOMEBREW_LIBRARY_PATH}/vendor/bundler/setup"
17-
ENV["HOMEBREW_GEMS_LOAD_PATH"] = ($: - load_path_before_bundler).join(":")
16+
require "pathname"
17+
HOMEBREW_LIBRARY_PATH = Pathname.new(homebrew_library_path)
1818

1919
require "global"
2020
require "tap"
@@ -25,6 +25,8 @@
2525
exit 0
2626
end
2727

28+
HOMEBREW_GEM_HOME = HOMEBREW_LIBRARY_PATH/"vendor/#{RUBY_ENGINE}/#{RUBY_VERSION}"
29+
2830
def require?(path)
2931
require path
3032
rescue LoadError => e
@@ -58,21 +60,18 @@ def require?(path)
5860
path.append(Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd"))
5961

6062
# Add RubyGems.
61-
HOMEBREW_GEM_HOME = HOMEBREW_LIBRARY_PATH/"vendor/#{RUBY_ENGINE}/#{RUBY_VERSION}"
63+
ENV["GEM_HOME"] = ENV["GEM_PATH"] = HOMEBREW_GEM_HOME
6264
path.append(HOMEBREW_GEM_HOME/"bin")
6365

66+
# Make RubyGems notice environment changes.
67+
Gem.clear_paths
68+
Gem::Specification.reset
69+
6470
# Add SCM wrappers.
6571
path.append(HOMEBREW_SHIMS_PATH/"scm")
6672

6773
ENV["PATH"] = path
6874

69-
# Setup RubyGems environment.
70-
ENV["GEM_HOME"] = ENV["GEM_PATH"] = HOMEBREW_GEM_HOME
71-
# Make RubyGems notice environment changes.
72-
Gem.clear_paths
73-
Gem::Specification.reset
74-
Homebrew.run_bundler_if_needed! unless HOMEBREW_GEM_HOME.exist?
75-
7675
if cmd
7776
internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd)
7877

Library/Homebrew/brew.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ then
6969
odie "Cowardly refusing to continue at this prefix: $HOMEBREW_PREFIX"
7070
fi
7171

72+
# Save value to use for installing gems
73+
export GEM_OLD_HOME="$GEM_HOME"
74+
export GEM_OLD_PATH="$GEM_PATH"
75+
7276
# Users may have these set, pointing the system Ruby
7377
# at non-system gem paths
7478
unset GEM_HOME

Library/Homebrew/config.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,5 @@
4646
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
4747
end
4848

49-
# Load path to vendored gems used by Homebrew
50-
HOMEBREW_GEMS_LOAD_PATH = ENV["HOMEBREW_GEMS_LOAD_PATH"]
51-
5249
# Load path used by standalone scripts to access the Homebrew code base
53-
HOMEBREW_LOAD_PATH = [HOMEBREW_LIBRARY_PATH, *HOMEBREW_GEMS_LOAD_PATH].join(":")
50+
HOMEBREW_LOAD_PATH = HOMEBREW_LIBRARY_PATH

Library/Homebrew/os/mac/mach.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
require "macho"
12
require "os/mac/architecture_list"
23

34
module MachOShim
45
# @private
56
def macho
67
@macho ||= begin
7-
require "macho"
8-
98
MachO.open(to_s)
109
end
1110
end
1211

1312
# @private
1413
def mach_data
1514
@mach_data ||= begin
16-
require "macho"
17-
1815
machos = []
1916
mach_data = []
2017

Library/Homebrew/test/support/lib/config.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
end
1515

1616
# Paths pointing into the Homebrew code base that persist across test runs
17-
HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../../..", __FILE__))
18-
HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent+"Homebrew/shims"
19-
HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH, ENV["HOMEBREW_GEMS_LOAD_PATH"]].join(":")
17+
HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../../..", __FILE__))
18+
HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent+"Homebrew/shims"
19+
HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":")
2020

2121
# Paths redirected to a temporary directory and wiped at the end of the test run
2222
HOMEBREW_PREFIX = Pathname.new(TEST_TMPDIR).join("prefix")

Library/Homebrew/utils.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,48 @@ def system(cmd, *args)
179179
_system(cmd, *args)
180180
end
181181

182+
def install_gem_setup_path!(name, version = nil, executable = name)
183+
# Respect user's preferences for where gems should be installed.
184+
ENV["GEM_HOME"] = ENV["GEM_OLD_HOME"].to_s
185+
ENV["GEM_HOME"] = Gem.user_dir if ENV["GEM_HOME"].empty?
186+
ENV["GEM_PATH"] = ENV["GEM_OLD_PATH"] unless ENV["GEM_OLD_PATH"].to_s.empty?
187+
188+
# Make rubygems notice env changes.
189+
Gem.clear_paths
190+
Gem::Specification.reset
191+
192+
# Add Gem binary directory and (if missing) Ruby binary directory to PATH.
193+
path = PATH.new(ENV["PATH"])
194+
path.prepend(RUBY_BIN) if which("ruby") != RUBY_PATH
195+
path.prepend(Gem.bindir)
196+
ENV["PATH"] = path
197+
198+
if Gem::Specification.find_all_by_name(name, version).empty?
199+
ohai "Installing or updating '#{name}' gem"
200+
install_args = %W[--no-ri --no-rdoc #{name}]
201+
install_args << "--version" << version if version
202+
203+
# Do `gem install [...]` without having to spawn a separate process or
204+
# having to find the right `gem` binary for the running Ruby interpreter.
205+
require "rubygems/commands/install_command"
206+
install_cmd = Gem::Commands::InstallCommand.new
207+
install_cmd.handle_options(install_args)
208+
exit_code = 1 # Should not matter as `install_cmd.execute` always throws.
209+
begin
210+
install_cmd.execute
211+
rescue Gem::SystemExitException => e
212+
exit_code = e.exit_code
213+
end
214+
odie "Failed to install/update the '#{name}' gem." if exit_code.nonzero?
215+
end
216+
217+
return if which(executable)
218+
odie <<-EOS.undent
219+
The '#{name}' gem is installed but couldn't find '#{executable}' in the PATH:
220+
#{ENV["PATH"]}
221+
EOS
222+
end
223+
182224
def run_bundler_if_needed!
183225
return unless Pathname.glob("#{HOMEBREW_GEM_HOME}/bin/*").empty?
184226

0 commit comments

Comments
 (0)