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

Commit

Permalink
Merge #6973
Browse files Browse the repository at this point in the history
6973: Backport the latest commits on ruby core repository. r=hsbt a=hsbt

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

RSpec example of the bundled bundler was failed on Ruby 2.7 from ruby core repository. I fixed some of the issues on ruby core repository.

### What was your diagnosis of the problem?

1. I fixed the location of `lib/bundler.gemspec` to `lib/bundler/bundler.gemspec` for fixing gemspec issue of Ruby 2.6.1: ruby/ruby@7c9771b
2. The current Bundler examples relied on the same versions of Ruby that are the first binary of PATH and rspec invocation binary. But the ruby core repository uses the different versions for them.

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

I fixed the location path of bundler.gemspec and uses `ENV['BUNDLE_GEM']` instead of hard-coded `gem` command.

### Why did you choose this fix out of the possible options?

There is no options on ruby core repository. I welcome to another options.


Co-authored-by: SHIBATA Hiroshi <[email protected]>
  • Loading branch information
bundlerbot and hsbt committed Feb 20, 2019
2 parents 5dc368b + c5396b6 commit 98a0a2d
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
6 changes: 4 additions & 2 deletions lib/bundler/gem_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def install

def build_gem
file_name = nil
sh(%W[gem build -V #{spec_path}]) do
gem = ENV["BUNDLE_GEM"] ? ENV["BUNDLE_GEM"] : "gem"
sh(%W[#{gem} build -V #{spec_path}]) 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 @@ -86,7 +87,8 @@ def build_gem

def install_gem(built_gem_path = nil, local = false)
built_gem_path ||= build_gem
cmd = %W[gem install #{built_gem_path}]
gem = ENV["BUNDLE_GEM"] ? ENV["BUNDLE_GEM"] : "gem"
cmd = %W[#{gem} install #{built_gem_path}]
cmd << "--local" if local
out, status = sh_with_status(cmd)
unless status.success? && out[/Successfully installed/]
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def search_up(*names)
# avoid stepping above the tmp directory when testing
gemspec = if ENV["BUNDLE_RUBY"] && ENV["BUNDLE_GEM"]
# for Ruby Core
"lib/bundler.gemspec"
"lib/bundler/bundler.gemspec"
else
"bundler.gemspec"
end
Expand Down
12 changes: 8 additions & 4 deletions spec/commands/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ def should_not_have_gems(*gems)
gem "rack"
G

sys_exec! "gem list"
gem = ruby_core? ? ENV["BUNDLE_GEM"] : "gem"
sys_exec! "#{gem} list"
expect(out).to include("rack (1.0.0)").and include("thin (1.0)")
end

Expand Down Expand Up @@ -461,7 +462,8 @@ def should_not_have_gems(*gems)
end
bundle! :update, :all => bundle_update_requires_all?

sys_exec! "gem list"
gem = ruby_core? ? ENV["BUNDLE_GEM"] : "gem"
sys_exec! "#{gem} list"
expect(out).to include("foo (1.0.1, 1.0)")
end

Expand All @@ -485,7 +487,8 @@ def should_not_have_gems(*gems)
bundle "clean --force"

expect(out).to include("Removing foo (1.0)")
sys_exec "gem list"
gem = ruby_core? ? ENV["BUNDLE_GEM"] : "gem"
sys_exec "#{gem} list"
expect(out).not_to include("foo (1.0)")
expect(out).to include("rack (1.0.0)")
end
Expand Down Expand Up @@ -519,7 +522,8 @@ def should_not_have_gems(*gems)
expect(err).to include(system_gem_path.to_s)
expect(err).to include("grant write permissions")

sys_exec "gem list"
gem = ruby_core? ? ENV["BUNDLE_GEM"] : "gem"
sys_exec "#{gem} list"
expect(out).to include("foo (1.0)")
expect(out).to include("rack (1.0.0)")
end
Expand Down
14 changes: 11 additions & 3 deletions spec/quality_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,16 @@ def check_for_specific_pronouns(filename)
it "can still be built" do
Dir.chdir(root) do
begin
gem_command! :build, gemspec
if ruby_core?
spec = Gem::Specification.load(gemspec.to_s)
spec.bindir = "libexec"
File.open(root.join("bundler.gemspec").to_s, "w") {|f| f.write spec.to_ruby }
gem_command! :build, root.join("bundler.gemspec").to_s
FileUtils.rm(root.join("bundler.gemspec").to_s)
else
gem_command! :build, gemspec
end

if Bundler.rubygems.provides?(">= 2.4")
# there's no way around this warning
last_command.stderr.sub!(/^YAML safe loading.*/, "")
Expand All @@ -227,8 +236,7 @@ def check_for_specific_pronouns(filename)
end
ensure
# clean up the .gem generated
path_prefix = ruby_core? ? "lib/" : "./"
FileUtils.rm("#{path_prefix}bundler-#{Bundler::VERSION}.gem")
FileUtils.rm("bundler-#{Bundler::VERSION}.gem")
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ def clean_load_path(lp)

FileUtils.ln_s(bundler_dir, File.join(gems_dir, "bundler-#{Bundler::VERSION}"))

gemspec_file = ruby_core? ? "#{bundler_dir}/lib/bundler.gemspec" : "#{bundler_dir}/bundler.gemspec"
gemspec_file = ruby_core? ? "#{bundler_dir}/lib/bundler/bundler.gemspec" : "#{bundler_dir}/bundler.gemspec"
gemspec = File.read(gemspec_file).
sub("Bundler::VERSION", %("#{Bundler::VERSION}"))
gemspec = gemspec.lines.reject {|line| line =~ %r{lib/bundler/version} }.join
Expand Down
12 changes: 8 additions & 4 deletions spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,16 @@ def install_gems(*gems)
gem_repo = options.fetch(:gem_repo) { gem_repo1 }
gems.each do |g|
path = if g == :bundler
Dir.chdir(root) { gem_command! :build, gemspec.to_s }
bundler_path = if ruby_core?
root + "lib/bundler-#{Bundler::VERSION}.gem"
if ruby_core?
spec = Gem::Specification.load(gemspec.to_s)
spec.bindir = "libexec"
File.open(root.join("bundler.gemspec").to_s, "w") {|f| f.write spec.to_ruby }
Dir.chdir(root) { gem_command! :build, root.join("bundler.gemspec").to_s }
FileUtils.rm(root.join("bundler.gemspec"))
else
root + "bundler-#{Bundler::VERSION}.gem"
Dir.chdir(root) { gem_command! :build, gemspec.to_s }
end
bundler_path = root + "bundler-#{Bundler::VERSION}.gem"
elsif g.to_s =~ %r{\A/.*\.gem\z}
g
else
Expand Down
3 changes: 2 additions & 1 deletion spec/support/rubygems_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def self.install_gems(gems)
no_reqs.map!(&:first)
reqs.map! {|name, req| "'#{name}:#{req}'" }
deps = reqs.concat(no_reqs).join(" ")
cmd = "#{Gem.ruby} -S gem install #{deps} --no-document --conservative"
gem = Spec::Path.ruby_core? ? ENV["BUNDLE_GEM"] : "#{Gem.ruby} -S gem"
cmd = "#{gem} install #{deps} --no-document --conservative"
puts cmd
system(cmd) || raise("Installing gems #{deps} for the tests to use failed!")
end
Expand Down

0 comments on commit 98a0a2d

Please sign in to comment.