1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Sync Bundler PR #3624 with HEAD commits

This commit is contained in:
Hiroshi SHIBATA 2020-05-21 21:05:07 +09:00
parent 93ebf9643d
commit 1d889c9656
Notes: git 2020-05-22 20:33:02 +09:00
13 changed files with 100 additions and 77 deletions

View file

@ -825,7 +825,7 @@ module Bundler
Bundler::SharedHelpers.major_deprecation 2,\ Bundler::SharedHelpers.major_deprecation 2,\
"The `#{flag_name}` flag is deprecated because it relies on being " \ "The `#{flag_name}` flag is deprecated because it relies on being " \
"remembered across bundler invocations, which bundler will no longer " \ "remembered across bundler invocations, which bundler will no longer " \
"do in future versions. Instead please use `bundle config set #{name} " \ "do in future versions. Instead please use `bundle config set #{name.tr("-", "_")} " \
"'#{value}'`, and stop using this flag" "'#{value}'`, and stop using this flag"
end end
end end

View file

@ -76,10 +76,10 @@ module Bundler
end end
def __materialize__ def __materialize__
search_object = Bundler.feature_flag.specific_platform? || Bundler.settings[:force_ruby_platform] ? self : Dependency.new(name, version)
@specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name @specification = if source.is_a?(Source::Gemspec) && source.gemspec.name == name
source.gemspec.tap {|s| s.source = source } source.gemspec.tap {|s| s.source = source }
else else
search_object = Bundler.feature_flag.specific_platform? || Bundler.settings[:force_ruby_platform] ? self : Dependency.new(name, version)
platform_object = Gem::Platform.new(platform) platform_object = Gem::Platform.new(platform)
candidates = source.specs.search(search_object) candidates = source.specs.search(search_object)
same_platform_candidates = candidates.select do |spec| same_platform_candidates = candidates.select do |spec|

View file

@ -1,11 +1,5 @@
# frozen_string_literal: true # frozen_string_literal: true
# Psych could be a gem, so try to ask for it
begin
gem "psych"
rescue LoadError
end if defined?(gem)
# Psych could be in the stdlib # Psych could be in the stdlib
# but it's too late if Syck is already loaded # but it's too late if Syck is already loaded
begin begin

View file

@ -47,7 +47,6 @@ module Gem
full_require_paths full_require_paths
end end
if method_defined?(:extension_dir)
alias_method :rg_extension_dir, :extension_dir alias_method :rg_extension_dir, :extension_dir
def extension_dir def extension_dir
@bundler_extension_dir ||= if source.respond_to?(:extension_dir_name) @bundler_extension_dir ||= if source.respond_to?(:extension_dir_name)
@ -57,7 +56,6 @@ module Gem
rg_extension_dir rg_extension_dir
end end
end end
end
remove_method :gem_dir if instance_methods(false).include?(:gem_dir) remove_method :gem_dir if instance_methods(false).include?(:gem_dir)
def gem_dir def gem_dir

View file

@ -4,12 +4,6 @@ require "rubygems/installer"
module Bundler module Bundler
class RubyGemsGemInstaller < Gem::Installer class RubyGemsGemInstaller < Gem::Installer
unless respond_to?(:at)
def self.at(*args)
new(*args)
end
end
def check_executable_overwrite(filename) def check_executable_overwrite(filename)
# Bundler needs to install gems regardless of binstub overwriting # Bundler needs to install gems regardless of binstub overwriting
end end
@ -20,7 +14,7 @@ module Bundler
def build_extensions def build_extensions
extension_cache_path = options[:bundler_extension_cache_path] extension_cache_path = options[:bundler_extension_cache_path]
return super unless extension_cache_path && extension_dir = Bundler.rubygems.spec_extension_dir(spec) return super unless extension_cache_path && extension_dir = spec.extension_dir
extension_dir = Pathname.new(extension_dir) extension_dir = Pathname.new(extension_dir)
build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?) build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?)

View file

@ -102,11 +102,6 @@ module Bundler
end.flatten(1) end.flatten(1)
end end
def spec_extension_dir(spec)
return unless spec.respond_to?(:extension_dir)
spec.extension_dir
end
def stub_set_spec(stub, spec) def stub_set_spec(stub, spec)
stub.instance_variable_set(:@spec, spec) stub.instance_variable_set(:@spec, spec)
end end
@ -223,11 +218,6 @@ module Bundler
Gem.bin_path(gem, bin, ver) Gem.bin_path(gem, bin, ver)
end end
def preserve_paths
# this is a no-op outside of RubyGems 1.8
yield
end
def loaded_gem_paths def loaded_gem_paths
loaded_gem_paths = Gem.loaded_specs.map {|_, s| s.full_require_paths } loaded_gem_paths = Gem.loaded_specs.map {|_, s| s.full_require_paths }
loaded_gem_paths.flatten loaded_gem_paths.flatten

View file

@ -145,8 +145,6 @@ module Bundler
Bundler.mkdir_p bin_path, :no_sudo => true unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5") Bundler.mkdir_p bin_path, :no_sudo => true unless spec.executables.empty? || Bundler.rubygems.provides?(">= 2.7.5")
installed_spec = nil
Bundler.rubygems.preserve_paths do
installed_spec = Bundler::RubyGemsGemInstaller.at( installed_spec = Bundler::RubyGemsGemInstaller.at(
path, path,
:install_dir => install_path.to_s, :install_dir => install_path.to_s,
@ -158,7 +156,6 @@ module Bundler
:bundler_expected_checksum => spec.respond_to?(:checksum) && spec.checksum, :bundler_expected_checksum => spec.respond_to?(:checksum) && spec.checksum,
:bundler_extension_cache_path => extension_cache_path(spec) :bundler_extension_cache_path => extension_cache_path(spec)
).install ).install
end
spec.full_gem_path = installed_spec.full_gem_path spec.full_gem_path = installed_spec.full_gem_path
# SUDO HAX # SUDO HAX

View file

@ -28,9 +28,13 @@ module Bundler
# @!group Stub Delegates # @!group Stub Delegates
# This is defined directly to avoid having to load every installed spec # This is defined directly to avoid having to loading the full spec
def missing_extensions? def missing_extensions?
stub.missing_extensions? return false if default_gem?
return false if extensions.empty?
return false if File.exist? gem_build_complete_path
true
end end
def activated def activated
@ -41,8 +45,16 @@ module Bundler
stub.instance_variable_set(:@activated, activated) stub.instance_variable_set(:@activated, activated)
end end
def default_gem def extensions
stub.default_gem stub.extensions
end
def gem_build_complete_path
File.join(extension_dir, "gem.build_complete")
end
def default_gem?
stub.default_gem?
end end
def full_gem_path def full_gem_path

View file

@ -15,6 +15,9 @@ else
require "bundler" require "bundler"
end end
# Workaround for non-activated bundler spec due to missing https://github.com/rubygems/rubygems/commit/4e306d7bcdee924b8d80ca9db6125aa59ee4e5a3
gem "bundler", Bundler::VERSION if Gem.rubygems_version < Gem::Version.new("2.6.2")
# Check if an older version of bundler is installed # Check if an older version of bundler is installed
$LOAD_PATH.each do |path| $LOAD_PATH.each do |path|
next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9 next unless path =~ %r{/bundler-0\.(\d+)} && $1.to_i < 9

View file

@ -930,5 +930,24 @@ __FILE__: #{path.to_s.inspect}
expect(err).to include("custom openssl should not be loaded") expect(err).to include("custom openssl should not be loaded")
end end
end end
context "with a git gem that includes extensions" do
before do
build_git "simple_git_binary", &:add_c_extension
bundle! "config set --local path .bundle"
install_gemfile! <<-G
gem "simple_git_binary", :git => '#{lib_path("simple_git_binary-1.0")}'
G
end
it "allows calling bundle install" do
bundle! "exec bundle install"
end
it "allows calling bundle install after removing gem.build_complete" do
FileUtils.rm_rf Dir[bundled_app(".bundle/**/gem.build_complete")]
bundle! "exec #{Gem.ruby} -S bundle install"
end
end
end end
end end

View file

@ -314,17 +314,18 @@ RSpec.describe "major deprecations" do
end end
{ {
:clean => true, "clean" => ["clean", true],
:deployment => true, "deployment" => ["deployment", true],
:frozen => true, "frozen" => ["frozen", true],
:"no-cache" => true, "no-cache" => ["no_cache", true],
:"no-prune" => true, "no-prune" => ["no_prune", true],
:path => "vendor/bundle", "path" => ["path", "vendor/bundle"],
:shebang => "ruby27", "shebang" => ["shebang", "ruby27"],
:system => true, "system" => ["system", true],
:without => "development", "without" => ["without", "development"],
:with => "development", "with" => ["with", "development"],
}.each do |name, value| }.each do |name, expectations|
option_name, value = *expectations
flag_name = "--#{name}" flag_name = "--#{name}"
context "with the #{flag_name} flag" do context "with the #{flag_name} flag" do
@ -338,7 +339,7 @@ RSpec.describe "major deprecations" do
"The `#{flag_name}` flag is deprecated because it relies on " \ "The `#{flag_name}` flag is deprecated because it relies on " \
"being remembered across bundler invocations, which bundler " \ "being remembered across bundler invocations, which bundler " \
"will no longer do in future versions. Instead please use " \ "will no longer do in future versions. Instead please use " \
"`bundle config set #{name} '#{value}'`, and stop using this flag" "`bundle config set #{option_name} '#{value}'`, and stop using this flag"
) )
end end

View file

@ -15,7 +15,6 @@ RSpec.describe "require 'bundler/gem_tasks'" do
bundled_app("Rakefile").open("w") do |f| bundled_app("Rakefile").open("w") do |f|
f.write <<-RAKEFILE f.write <<-RAKEFILE
$:.unshift("#{lib_dir}")
require "bundler/gem_tasks" require "bundler/gem_tasks"
RAKEFILE RAKEFILE
end end
@ -28,8 +27,8 @@ RSpec.describe "require 'bundler/gem_tasks'" do
end end
it "includes the relevant tasks" do it "includes the relevant tasks" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do with_gem_path_as(base_system_gems.to_s) do
sys_exec "#{rake} -T", :env => { "RUBYOPT" => opt_add("-I#{lib_dir}", ENV["RUBYOPT"]) } sys_exec "#{rake} -T", :env => { "GEM_HOME" => system_gem_path.to_s }
end end
expect(err).to be_empty expect(err).to be_empty
@ -46,8 +45,8 @@ RSpec.describe "require 'bundler/gem_tasks'" do
end end
it "defines a working `rake install` task" do it "defines a working `rake install` task" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do with_gem_path_as(base_system_gems.to_s) do
sys_exec "#{rake} install", :env => { "RUBYOPT" => opt_add("-I#{lib_dir}", ENV["RUBYOPT"]) } sys_exec "#{rake} install", :env => { "GEM_HOME" => system_gem_path.to_s }
end end
expect(err).to be_empty expect(err).to be_empty
@ -69,9 +68,27 @@ RSpec.describe "require 'bundler/gem_tasks'" do
end end
end end
context "bundle path configured locally" do
before do
bundle "config set path vendor/bundle"
end
it "works" do
install_gemfile! <<-G
source "#{file_uri_for(gem_repo1)}"
gem "rake"
G
bundle! "exec rake -T"
expect(err).to be_empty
end
end
it "adds 'pkg' to rake/clean's CLOBBER" do it "adds 'pkg' to rake/clean's CLOBBER" do
with_gem_path_as(Spec::Path.base_system_gems.to_s) do with_gem_path_as(base_system_gems.to_s) do
sys_exec! %(#{rake} -e 'load "Rakefile"; puts CLOBBER.inspect') sys_exec! %(#{rake} -e 'load "Rakefile"; puts CLOBBER.inspect'), :env => { "GEM_HOME" => system_gem_path.to_s }
end end
expect(out).to eq '["pkg"]' expect(out).to eq '["pkg"]'
end end

View file

@ -767,13 +767,11 @@ end
G G
ruby <<-R ruby <<-R
if Gem::Specification.method_defined? :extension_dir
s = Gem::Specification.find_by_name '#{gem_name}' s = Gem::Specification.find_by_name '#{gem_name}'
s.extension_dir = '#{ext_dir}' s.extension_dir = '#{ext_dir}'
# Don't build extensions. # Don't build extensions.
s.class.send(:define_method, :build_extensions) { nil } s.class.send(:define_method, :build_extensions) { nil }
end
require '#{lib_dir}/bundler' require '#{lib_dir}/bundler'
gem '#{gem_name}' gem '#{gem_name}'