Skip to content

Commit

Permalink
Use bundle install in more places.
Browse files Browse the repository at this point in the history
This provides a more consistent version for `rubocop` than relying on
`Homebrew.install_gem_setup_path!` (and we really want `brew style` to
provide consistent output).
  • Loading branch information
MikeMcQuaid committed Jan 8, 2019
1 parent 03afa5a commit efc3c0c
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def run
def install_rubocop
capture_stderr do
begin
Homebrew.install_gem_setup_path! "rubocop"
Homebrew.install_bundler_gems!
rescue SystemExit
raise CaskError, Tty.strip_ansi($stderr.string).chomp.sub(/\AError: /, "")
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/man.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def man
end

def regenerate_man_pages
Homebrew.install_gem_setup_path! "ronn"
Homebrew.install_bundler_gems!

markup = build_man_page
convert_man_page(markup, TARGET_DOC_PATH/"Manpage.md")
Expand Down
5 changes: 1 addition & 4 deletions Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def tests
FileUtils.rm_f "test/coverage/.resultset.json"
end

ENV["BUNDLE_GEMFILE"] = "#{HOMEBREW_LIBRARY_PATH}/test/Gemfile"

# Override author/committer as global settings might be invalid and thus
# will cause silent failure during the setup of dummy Git repositories.
%w[AUTHOR COMMITTER].each do |role|
Expand All @@ -86,8 +84,7 @@ def tests
ENV["GIT_#{role}_DATE"] = "Sun Jan 22 19:59:13 2017 +0000"
end

Homebrew.install_gem_setup_path! "bundler", "<2"
system "bundle", "install" unless quiet_system("bundle", "check")
Homebrew.install_bundler_gems!

parallel = true

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/vendor-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def vendor_gems
switch :debug
end.parse

Homebrew.install_gem_setup_path! "bundler", "<2"
Homebrew.install_bundler!

ohai "cd #{HOMEBREW_LIBRARY_PATH}/vendor"
(HOMEBREW_LIBRARY_PATH/"vendor").cd do
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ def check_style_json(files, options = {})
def check_style_impl(files, output_type, options = {})
fix = options[:fix]

Homebrew.install_gem_setup_path! "rubocop"
Homebrew.install_gem! "rubocop-rspec"
Homebrew.install_bundler_gems!
require "rubocop"
require "rubocops"

Expand Down
4 changes: 3 additions & 1 deletion Library/Homebrew/test/.bundle/config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
---
BUNDLE_BIN: "../bin"
BUNDLE_PATH: "../vendor/bundle"
BUNDLE_DISABLE_SHARED_GEMS: "true"
BUNDLE_BIN: "../bin"
BUNDLE_JOBS: "4"
BUNDLE_RETRY: "3"
28 changes: 21 additions & 7 deletions Library/Homebrew/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def system(cmd, *args, **options)
_system(cmd, *args, **options)
end

def install_gem!(name, version = nil)
def setup_gem_environment!
# Match where our bundler gems are.
ENV["GEM_HOME"] = "#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/vendor/bundle/ruby/#{RbConfig::CONFIG["ruby_version"]}"
ENV["GEM_PATH"] = ENV["GEM_HOME"]
Expand All @@ -217,12 +217,15 @@ def install_gem!(name, version = nil)
path.prepend(RUBY_BIN) if which("ruby") != RUBY_PATH
path.prepend(Gem.bindir)
ENV["PATH"] = path
end

def install_gem!(name)

This comment has been minimized.

Copy link
@sparta-developers

sparta-developers Jan 16, 2019

It looks like one of the places this is used is https://github.com/Homebrew/brew/blob/master/Library/Homebrew/compat/download_strategy.rb#L29-L34, where it still uses install_gem! with arity 2.

This comment has been minimized.

Copy link
@MikeMcQuaid

MikeMcQuaid Jan 17, 2019

Author Member

Thanks, good spot. Opened #5550

setup_gem_environment!

return unless Gem::Specification.find_all_by_name(name, version).empty?
return unless Gem::Specification.find_all_by_name(name).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.
Expand All @@ -238,17 +241,28 @@ def install_gem!(name, version = nil)
odie "Failed to install/update the '#{name}' gem." if exit_code.nonzero?
end

def install_gem_setup_path!(name, version = nil, executable = name)
install_gem!(name, version)
def install_gem_setup_path!(name)
install_gem!(name)

return if which(executable)
return if which(name)

odie <<~EOS
The '#{name}' gem is installed but couldn't find '#{executable}' in the PATH:
The '#{name}' gem is installed but couldn't find '#{name}' in the PATH:
#{ENV["PATH"]}
EOS
end

def install_bundler!
install_gem_setup_path! "bundler"
end

def install_bundler_gems!
install_bundler!
ENV["BUNDLE_GEMFILE"] = "#{HOMEBREW_LIBRARY_PATH}/test/Gemfile"
system "bundle", "install" unless quiet_system("bundle", "check")
setup_gem_environment!
end

# rubocop:disable Style/GlobalVars
def inject_dump_stats!(the_module, pattern)
@injected_dump_stat_modules ||= {}
Expand Down

0 comments on commit efc3c0c

Please sign in to comment.