Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Merge #7474
Browse files Browse the repository at this point in the history
7474: Fix `bundle exec rake install` failing r=deivid-rodriguez a=deivid-rodriguez

### What was the end-user problem that led to this PR?

The problem was that I noticed `bundle exec rake install` was failing on my gem using the latest prerelease of bundler.

### What was your diagnosis of the problem?

My diagnosis was that `bundler` silences output of rubygems by default, and in a `bundle exec` context, `bundler/setup` is always required by subprocesses. So, the `rake install` task is silencing rubygems, but it requires it to not be silent:

https://github.com/bundler/bundler/blob/bada03dd6d4d15828fb5b2cf7f744948e88a69a3/lib/bundler/gem_helper.rb#L91-L92

### What is your fix for the problem, implemented in this PR?

My fix is to wrap the execution of the rubygems subprocess with `Bundler.with_original_env` so that the `gem` command runs without `bundler` involved.

Co-authored-by: David Rodríguez <deivid.rodriguez@riseup.net>
(cherry picked from commit f44ebf0)
  • Loading branch information
bundlerbot authored and deivid-rodriguez committed Dec 13, 2019
1 parent cd3fb55 commit 4e5e9cd
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 21 deletions.
22 changes: 12 additions & 10 deletions lib/bundler/gem_helper.rb
Expand Up @@ -73,8 +73,7 @@ def install

def build_gem
file_name = nil
gem = ENV["GEM_COMMAND"] ? ENV["GEM_COMMAND"] : "gem"
sh("#{gem} build -V #{spec_path}".shellsplit) do
sh("#{gem_command} build -V #{spec_path}".shellsplit) do
file_name = File.basename(built_gem_path)
SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) }
FileUtils.mv(built_gem_path, "pkg")
Expand All @@ -85,11 +84,10 @@ def build_gem

def install_gem(built_gem_path = nil, local = false)
built_gem_path ||= build_gem
gem = ENV["GEM_COMMAND"] ? ENV["GEM_COMMAND"] : "gem"
cmd = "#{gem} install #{built_gem_path}"
cmd = "#{gem_command} install #{built_gem_path}"
cmd += " --local" if local
out, status = sh_with_status(cmd.shellsplit)
unless status.success? && out[/Successfully installed/]
_, status = sh_with_status(cmd.shellsplit)
unless status.success?
raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output"
end
Bundler.ui.confirm "#{name} (#{version}) installed."
Expand All @@ -98,13 +96,13 @@ def install_gem(built_gem_path = nil, local = false)
protected

def rubygem_push(path)
gem_command = %W[gem push #{path}]
gem_command << "--key" << gem_key if gem_key
gem_command << "--host" << allowed_push_host if allowed_push_host
cmd = %W[#{gem_command} push #{path}]
cmd << "--key" << gem_key if gem_key
cmd << "--host" << allowed_push_host if allowed_push_host
unless allowed_push_host || Bundler.user_home.join(".gem/credentials").file?
raise "Your rubygems.org credentials aren't set. Run `gem push` to set them."
end
sh_with_input(gem_command)
sh_with_input(cmd)
Bundler.ui.confirm "Pushed #{name} #{version} to #{gem_push_host}"
end

Expand Down Expand Up @@ -211,5 +209,9 @@ def gem_key
def gem_push?
!%w[n no nil false off 0].include?(ENV["gem_push"].to_s.downcase)
end

def gem_command
ENV["GEM_COMMAND"] ? ENV["GEM_COMMAND"] : "gem"
end
end
end
2 changes: 1 addition & 1 deletion spec/commands/clean_spec.rb
Expand Up @@ -782,7 +782,7 @@ def should_not_have_gems(*gems)
expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist

bundle! :clean
expect(out).to eq("")
expect(out).to be_empty

expect(vendored_gems("bundler/gems/extensions")).to exist
expect(vendored_gems("bundler/gems/very_simple_git_binary-1.0-#{revision[0..11]}")).to exist
Expand Down
2 changes: 1 addition & 1 deletion spec/commands/exec_spec.rb
Expand Up @@ -104,7 +104,7 @@
install_gemfile ""
sys_exec "#{Gem.ruby} #{command.path}"

expect(out).to eq("")
expect(out).to be_empty
expect(err).to be_empty
end

Expand Down
2 changes: 1 addition & 1 deletion spec/commands/outdated_spec.rb
Expand Up @@ -228,7 +228,7 @@ def test_group_option(group = nil, gems_list_size = 1)
context "and no gems are outdated" do
it "has empty output" do
subject
expect(out).to eq("")
expect(out).to be_empty
end
end
end
Expand Down
24 changes: 23 additions & 1 deletion spec/runtime/gem_tasks_spec.rb
Expand Up @@ -6,23 +6,33 @@
f.write <<-GEMSPEC
Gem::Specification.new do |s|
s.name = "foo"
s.version = "1.0"
s.summary = "dummy"
s.author = "Perry Mason"
end
GEMSPEC
end

bundled_app("Rakefile").open("w") do |f|
f.write <<-RAKEFILE
$:.unshift("#{lib_dir}")
require "bundler/gem_tasks"
RAKEFILE
end

install_gemfile! <<-G
source "#{file_uri_for(gem_repo1)}"
gem "rake"
G
end

it "includes the relevant tasks" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do
sys_exec "#{rake} -T", "RUBYOPT" => "-I#{lib_dir}"
end

expect(err).to eq("")
expect(err).to be_empty
expected_tasks = [
"rake build",
"rake clean",
Expand All @@ -35,6 +45,18 @@
expect(exitstatus).to eq(0) if exitstatus
end

it "defines a working `rake install` task" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do
sys_exec "#{rake} install", "RUBYOPT" => "-I#{lib_dir}"
end

expect(err).to be_empty

bundle! "exec rake install"

expect(err).to be_empty
end

it "adds 'pkg' to rake/clean's CLOBBER" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do
sys_exec! %(#{rake} -e 'load "Rakefile"; puts CLOBBER.inspect')
Expand Down
12 changes: 6 additions & 6 deletions spec/runtime/setup_spec.rb
Expand Up @@ -130,7 +130,7 @@ def clean_load_path(lp)
load_path = out.split("\n")
rack_load_order = load_path.index {|path| path.include?("rack") }

expect(err).to eq("")
expect(err).to be_empty
expect(load_path).to include(a_string_ending_with("dash_i_dir"), "rubylib_dir")
expect(rack_load_order).to be > 0
end
Expand Down Expand Up @@ -1042,7 +1042,7 @@ def Bundler.require(path)
RUBY

expect(err).to be_empty
expect(out).to eq("")
expect(out).to be_empty
end
end

Expand Down Expand Up @@ -1098,8 +1098,8 @@ def lock_with(bundler_version = nil)
it "does not change the lock or warn" do
lockfile lock_with(Bundler::VERSION.succ)
ruby "require '#{lib_dir}/bundler/setup'"
expect(out).to eq("")
expect(err).to eq("")
expect(out).to be_empty
expect(err).to be_empty
lockfile_should_be lock_with(Bundler::VERSION.succ)
end
end
Expand Down Expand Up @@ -1162,8 +1162,8 @@ def lock_with(ruby_version = nil)
let(:ruby_version) { "5.5.5" }
it "does not change the lock or warn" do
expect { ruby! "require '#{lib_dir}/bundler/setup'" }.not_to change { lockfile }
expect(out).to eq("")
expect(err).to eq("")
expect(out).to be_empty
expect(err).to be_empty
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support/path.rb
Expand Up @@ -22,7 +22,7 @@ def bindir
end

def gem_bin
@gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -I#{spec_dir}/rubygems -S gem --backtrace"
@gem_bin ||= ruby_core? ? ENV["GEM_COMMAND"] : "#{Gem.ruby} -S gem --backtrace"
end

def spec_dir
Expand Down

0 comments on commit 4e5e9cd

Please sign in to comment.