Skip to content

Commit 87b544b

Browse files
hsbtk0kubun
authored andcommitted
Merge RubyGems/Bundler 4.0.5
1 parent 91a4926 commit 87b544b

23 files changed

Lines changed: 343 additions & 93 deletions

lib/bundler/definition.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ def converge_specs(specs)
10771077
end
10781078
end
10791079

1080-
if parent_dep
1080+
if parent_dep && parent_dep.source.is_a?(Source::Path)
10811081
replacement_source = parent_dep.source
10821082
else
10831083
replacement_source = sources.get(lockfile_source)

lib/bundler/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: false
22

33
module Bundler
4-
VERSION = "4.0.4".freeze
4+
VERSION = "4.0.5".freeze
55

66
def self.bundler_major_version
77
@bundler_major_version ||= gem_version.segments.first

lib/rubygems.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
require "rbconfig"
1010

1111
module Gem
12-
VERSION = "4.0.4"
12+
VERSION = "4.0.5"
1313
end
1414

1515
require_relative "rubygems/defaults"
@@ -192,11 +192,12 @@ def self.try_activate(path)
192192
begin
193193
spec.activate
194194
rescue Gem::LoadError => e # this could fail due to gem dep collisions, go lax
195-
spec_by_name = Gem::Specification.find_by_name(spec.name)
196-
if spec_by_name.nil?
195+
spec = Gem::Specification.find_unloaded_by_path(path)
196+
spec ||= Gem::Specification.find_by_name(spec.name)
197+
if spec.nil?
197198
raise e
198199
else
199-
spec_by_name.activate
200+
spec.activate
200201
end
201202
end
202203

lib/rubygems/bundler_version_finder.rb

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ def self.bundler_version
1010
v ||= bundle_update_bundler_version
1111
return if v == true
1212

13+
v ||= bundle_config_version
14+
1315
v ||= lockfile_version
1416
return unless v
1517

@@ -49,21 +51,7 @@ def self.lockfile_version
4951
private_class_method :lockfile_version
5052

5153
def self.lockfile_contents
52-
gemfile = ENV["BUNDLE_GEMFILE"]
53-
gemfile = nil if gemfile&.empty?
54-
55-
unless gemfile
56-
begin
57-
Gem::Util.traverse_parents(Dir.pwd) do |directory|
58-
next unless gemfile = Gem::GEM_DEP_FILES.find {|f| File.file?(f) }
59-
60-
gemfile = File.join directory, gemfile
61-
break
62-
end
63-
rescue Errno::ENOENT
64-
return
65-
end
66-
end
54+
gemfile = gemfile_path
6755

6856
return unless gemfile
6957

@@ -82,19 +70,24 @@ def self.lockfile_contents
8270
private_class_method :lockfile_contents
8371

8472
def self.bundle_config_version
85-
config_file = bundler_config_file
86-
return unless config_file && File.file?(config_file)
73+
version = nil
8774

88-
contents = File.read(config_file)
89-
contents =~ /^BUNDLE_VERSION:\s*["']?([^"'\s]+)["']?\s*$/
75+
[bundler_local_config_file, bundler_global_config_file].each do |config_file|
76+
next unless config_file && File.file?(config_file)
9077

91-
$1
78+
contents = File.read(config_file)
79+
contents =~ /^BUNDLE_VERSION:\s*["']?([^"'\s]+)["']?\s*$/
80+
81+
version = $1
82+
break if version
83+
end
84+
85+
version
9286
end
9387
private_class_method :bundle_config_version
9488

95-
def self.bundler_config_file
96-
# see Bundler::Settings#global_config_file and local_config_file
97-
# global
89+
def self.bundler_global_config_file
90+
# see Bundler::Settings#global_config_file
9891
if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty?
9992
ENV["BUNDLE_CONFIG"]
10093
elsif ENV["BUNDLE_USER_CONFIG"] && !ENV["BUNDLE_USER_CONFIG"].empty?
@@ -103,10 +96,36 @@ def self.bundler_config_file
10396
ENV["BUNDLE_USER_HOME"] + "config"
10497
elsif Gem.user_home && !Gem.user_home.empty?
10598
Gem.user_home + ".bundle/config"
106-
else
107-
# local
108-
"config"
10999
end
110100
end
111-
private_class_method :bundler_config_file
101+
private_class_method :bundler_global_config_file
102+
103+
def self.bundler_local_config_file
104+
gemfile = gemfile_path
105+
return unless gemfile
106+
107+
File.join(File.dirname(gemfile), ".bundle", "config")
108+
end
109+
private_class_method :bundler_local_config_file
110+
111+
def self.gemfile_path
112+
gemfile = ENV["BUNDLE_GEMFILE"]
113+
gemfile = nil if gemfile&.empty?
114+
115+
unless gemfile
116+
begin
117+
Gem::Util.traverse_parents(Dir.pwd) do |directory|
118+
next unless gemfile = Gem::GEM_DEP_FILES.find {|f| File.file?(f) }
119+
120+
gemfile = File.join directory, gemfile
121+
break
122+
end
123+
rescue Errno::ENOENT
124+
return
125+
end
126+
end
127+
128+
gemfile
129+
end
130+
private_class_method :gemfile_path
112131
end

lib/rubygems/commands/pristine_command.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def description # :nodoc:
8888
will revert them. All extensions are rebuilt and all bin stubs for the gem
8989
are regenerated after checking for modifications.
9090
91+
Rebuilding extensions also refreshes C-extension gems against updated system
92+
libraries (for example after OS or package upgrades) to avoid mismatches like
93+
outdated library version warnings.
94+
9195
If the cached gem cannot be found it will be downloaded.
9296
9397
If --no-extensions is provided pristine will not attempt to restore a gem

lib/rubygems/ext/builder.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ def initialize(spec, build_args = spec.build_args, target_rbconfig = Gem.target_
163163
@gem_dir = spec.full_gem_path
164164
@target_rbconfig = target_rbconfig
165165
@build_jobs = build_jobs
166-
167-
@ran_rake = false
168166
end
169167

170168
##
@@ -177,7 +175,6 @@ def builder_for(extension) # :nodoc:
177175
when /configure/ then
178176
Gem::Ext::ConfigureBuilder
179177
when /rakefile/i, /mkrf_conf/i then
180-
@ran_rake = true
181178
Gem::Ext::RakeBuilder
182179
when /CMakeLists.txt/ then
183180
Gem::Ext::CmakeBuilder.new
@@ -250,8 +247,6 @@ def build_extensions
250247
FileUtils.rm_f @spec.gem_build_complete_path
251248

252249
@spec.extensions.each do |extension|
253-
break if @ran_rake
254-
255250
build_extension extension, dest_path
256251
end
257252

lib/rubygems/specification.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -959,6 +959,15 @@ def self.find_by_path(path)
959959
specification_record.find_by_path(path)
960960
end
961961

962+
##
963+
# Return the best specification that contains the file matching +path+
964+
# amongst the specs that are not loaded. This method is different than
965+
# +find_inactive_by_path+ as it will filter out loaded specs by their name.
966+
967+
def self.find_unloaded_by_path(path)
968+
specification_record.find_unloaded_by_path(path)
969+
end
970+
962971
##
963972
# Return the best specification that contains the file matching +path+
964973
# amongst the specs that are not activated.

lib/rubygems/specification_policy.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ def validate_values
436436
warning "deprecated autorequire specified" if @specification.autorequire
437437

438438
@specification.executables.each do |executable|
439+
validate_executable(executable)
439440
validate_shebang_line_in(executable)
440441
end
441442

@@ -449,6 +450,13 @@ def validate_attribute_present(attribute)
449450
warning("no #{attribute} specified") if value.nil? || value.empty?
450451
end
451452

453+
def validate_executable(executable)
454+
separators = [File::SEPARATOR, File::ALT_SEPARATOR, File::PATH_SEPARATOR].compact.map {|sep| Regexp.escape(sep) }.join
455+
return unless executable.match?(/[\s#{separators}]/)
456+
457+
error "executable \"#{executable}\" contains invalid characters"
458+
end
459+
452460
def validate_shebang_line_in(executable)
453461
executable_path = File.join(@specification.bindir, executable)
454462
return if File.read(executable_path, 2) == "#!"

lib/rubygems/specification_record.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,19 @@ def find_by_path(path)
154154
spec.to_spec
155155
end
156156

157+
##
158+
# Return the best specification that contains the file matching +path+
159+
# amongst the specs that are not loaded. This method is different than
160+
# +find_inactive_by_path+ as it will filter out loaded specs by their name.
161+
162+
def find_unloaded_by_path(path)
163+
stub = stubs.find do |s|
164+
next if Gem.loaded_specs[s.name]
165+
s.contains_requirable_file? path
166+
end
167+
stub&.to_spec
168+
end
169+
157170
##
158171
# Return the best specification in the record that contains the file
159172
# matching +path+ amongst the specs that are not activated.

lib/rubygems/version.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

3-
require_relative "deprecate"
4-
53
##
64
# The Version class processes string versions into comparable
75
# values. A version string should normally be a series of numbers
@@ -152,6 +150,9 @@
152150
# For the last example, single-digit versions are automatically extended with
153151
# a zero to give a sensible result.
154152

153+
# Workaround for directly loading Gem::Version in some cases
154+
module Gem; end
155+
155156
class Gem::Version
156157
include Comparable
157158

0 commit comments

Comments
 (0)