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

Use bundle install in more places. #5497

Merged
merged 3 commits into from
Jan 8, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
2 changes: 1 addition & 1 deletion Library/Homebrew/test/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ GEM
rspec-support (3.8.0)
rspec-wait (0.0.9)
rspec (>= 3, < 4)
rubocop (0.62.0)
rubocop (0.61.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
Expand Down
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)
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
2 changes: 1 addition & 1 deletion Library/Homebrew/vendor/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GEM
plist (3.5.0)
powerpack (0.1.2)
rainbow (3.0.0)
rubocop (0.62.0)
rubocop (0.61.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
Expand Down