Skip to content

Commit 3894841

Browse files
hsbtk0kubun
authored andcommitted
Merge RubyGems-3.5.19 and Bundler-2.5.19
1 parent ef3c4a7 commit 3894841

File tree

126 files changed

+1867
-498
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

126 files changed

+1867
-498
lines changed

lib/bundler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ def eval_gemspec(path, contents)
652652
rescue ScriptError, StandardError => e
653653
msg = "There was an error while loading `#{path.basename}`: #{e.message}"
654654

655-
raise GemspecError, Dsl::DSLError.new(msg, path, e.backtrace, contents)
655+
raise GemspecError, Dsl::DSLError.new(msg, path.to_s, e.backtrace, contents)
656656
end
657657

658658
def configure_gem_path

lib/bundler/cli/add.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def inject_dependencies
3434
end
3535

3636
def validate_options!
37-
raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic]
37+
raise InvalidOption, "You cannot specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic]
3838

3939
# raise error when no gems are specified
4040
raise InvalidOption, "Please specify gems to add." if gems.empty?

lib/bundler/cli/gem.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ def run
191191
templates.merge!("standard.yml.tt" => ".standard.yml")
192192
end
193193

194-
templates.merge!("exe/newgem.tt" => "exe/#{name}") if config[:exe]
194+
if config[:exe]
195+
templates.merge!("exe/newgem.tt" => "exe/#{name}")
196+
executables.push("exe/#{name}")
197+
end
195198

196199
if extension == "c"
197200
templates.merge!(

lib/bundler/cli/lock.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ def run
1515
end
1616

1717
print = options[:print]
18-
previous_ui_level = Bundler.ui.level
19-
Bundler.ui.level = "silent" if print
18+
previous_output_stream = Bundler.ui.output_stream
19+
Bundler.ui.output_stream = :stderr if print
2020

2121
Bundler::Fetcher.disable_endpoint = options["full-index"]
2222

@@ -48,8 +48,8 @@ def run
4848
options["add-platform"].each do |platform_string|
4949
platform = Gem::Platform.new(platform_string)
5050
if platform.to_s == "unknown"
51-
Bundler.ui.warn "The platform `#{platform_string}` is unknown to RubyGems " \
52-
"and adding it will likely lead to resolution errors"
51+
Bundler.ui.error "The platform `#{platform_string}` is unknown to RubyGems and can't be added to the lockfile."
52+
exit 1
5353
end
5454
definition.add_platform(platform)
5555
end
@@ -68,7 +68,7 @@ def run
6868
end
6969
end
7070

71-
Bundler.ui.level = previous_ui_level
71+
Bundler.ui.output_stream = previous_output_stream
7272
end
7373
end
7474
end

lib/bundler/cli/outdated.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run
5454
end
5555

5656
if options[:parseable]
57-
Bundler.ui.silence(&definition_resolution)
57+
Bundler.ui.progress(&definition_resolution)
5858
else
5959
definition_resolution.call
6060
end

lib/bundler/definition.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,11 @@ def should_add_extra_platforms?
511511
end
512512

513513
def lockfile_exists?
514-
file_exists?(lockfile)
515-
end
516-
517-
def file_exists?(file)
518-
file && File.exist?(file)
514+
lockfile && File.exist?(lockfile)
519515
end
520516

521517
def write_lock(file, preserve_unknown_sections)
522-
return if Definition.no_lock
518+
return if Definition.no_lock || file.nil?
523519

524520
contents = to_lock
525521

@@ -536,7 +532,7 @@ def write_lock(file, preserve_unknown_sections)
536532

537533
preserve_unknown_sections ||= !updating_major && (Bundler.frozen_bundle? || !(unlocking? || @unlocking_bundler))
538534

539-
if file_exists?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
535+
if File.exist?(file) && lockfiles_equal?(@lockfile_contents, contents, preserve_unknown_sections)
540536
return if Bundler.frozen_bundle?
541537
SharedHelpers.filesystem_access(file) { FileUtils.touch(file) }
542538
return

lib/bundler/dsl.rb

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,20 @@ def initialize
4242
end
4343

4444
def eval_gemfile(gemfile, contents = nil)
45-
expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
46-
original_gemfile = @gemfile
47-
@gemfile = expanded_gemfile_path
48-
@gemfiles << expanded_gemfile_path
49-
contents ||= Bundler.read_file(@gemfile.to_s)
50-
instance_eval(contents, @gemfile.to_s, 1)
51-
rescue Exception => e # rubocop:disable Lint/RescueException
52-
message = "There was an error " \
53-
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
54-
"`#{File.basename gemfile.to_s}`: #{e.message}"
55-
56-
raise DSLError.new(message, gemfile, e.backtrace, contents)
57-
ensure
58-
@gemfile = original_gemfile
45+
with_gemfile(gemfile) do |current_gemfile|
46+
contents ||= Bundler.read_file(current_gemfile)
47+
instance_eval(contents, current_gemfile, 1)
48+
rescue GemfileEvalError => e
49+
message = "There was an error evaluating `#{File.basename current_gemfile}`: #{e.message}"
50+
raise DSLError.new(message, current_gemfile, e.backtrace, contents)
51+
rescue GemfileError, InvalidArgumentError, InvalidOption, DeprecatedError, ScriptError => e
52+
message = "There was an error parsing `#{File.basename current_gemfile}`: #{e.message}"
53+
raise DSLError.new(message, current_gemfile, e.backtrace, contents)
54+
rescue StandardError => e
55+
raise unless e.backtrace_locations.first.path == current_gemfile
56+
message = "There was an error parsing `#{File.basename current_gemfile}`: #{e.message}"
57+
raise DSLError.new(message, current_gemfile, e.backtrace, contents)
58+
end
5959
end
6060

6161
def gemspec(opts = nil)
@@ -219,7 +219,7 @@ def git(uri, options = {}, &blk)
219219
end
220220

221221
def github(repo, options = {})
222-
raise ArgumentError, "GitHub sources require a block" unless block_given?
222+
raise InvalidArgumentError, "GitHub sources require a block" unless block_given?
223223
github_uri = @git_sources["github"].call(repo)
224224
git_options = normalize_hash(options).merge("uri" => github_uri)
225225
git_source = @sources.add_git_source(git_options)
@@ -285,6 +285,16 @@ def check_primary_source_safety
285285

286286
private
287287

288+
def with_gemfile(gemfile)
289+
expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
290+
original_gemfile = @gemfile
291+
@gemfile = expanded_gemfile_path
292+
@gemfiles << expanded_gemfile_path
293+
yield @gemfile.to_s
294+
ensure
295+
@gemfile = original_gemfile
296+
end
297+
288298
def add_git_sources
289299
git_source(:github) do |repo_name|
290300
if repo_name =~ GITHUB_PULL_REQUEST_URL
@@ -577,7 +587,7 @@ def to_s
577587

578588
return m unless backtrace && dsl_path && contents
579589

580-
trace_line = backtrace.find {|l| l.include?(dsl_path.to_s) } || trace_line
590+
trace_line = backtrace.find {|l| l.include?(dsl_path) } || trace_line
581591
return m unless trace_line
582592
line_numer = trace_line.split(":")[1].to_i - 1
583593
return m unless line_numer
@@ -603,7 +613,7 @@ def to_s
603613

604614
def parse_line_number_from_description
605615
description = self.description
606-
if dsl_path && description =~ /((#{Regexp.quote File.expand_path(dsl_path)}|#{Regexp.quote dsl_path.to_s}):\d+)/
616+
if dsl_path && description =~ /((#{Regexp.quote File.expand_path(dsl_path)}|#{Regexp.quote dsl_path}):\d+)/
607617
trace_line = Regexp.last_match[1]
608618
description = description.sub(/\n.*\n(\.\.\.)? *\^~+$/, "").sub(/#{Regexp.quote trace_line}:\s*/, "").sub("\n", " - ")
609619
end

lib/bundler/errors.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,15 @@ def initialize(orig_exception, msg)
217217
end
218218

219219
class InsecureInstallPathError < BundlerError
220-
def initialize(path)
220+
def initialize(name, path)
221+
@name = name
221222
@path = path
222223
end
223224

224225
def message
225-
"The installation path is insecure. Bundler cannot continue.\n" \
226-
"#{@path} is world-writable (without sticky bit).\n" \
227-
"Bundler cannot safely replace gems in world-writeable directories due to potential vulnerabilities.\n" \
228-
"Please change the permissions of this directory or choose a different install path."
226+
"Bundler cannot reinstall #{@name} because there's a previous installation of it at #{@path} that is unsafe to remove.\n" \
227+
"The parent of #{@path} is world-writable and does not have the sticky bit set, making it insecure to remove due to potential vulnerabilities.\n" \
228+
"Please change the permissions of #{File.dirname(@path)} or choose a different install path."
229229
end
230230

231231
status_code(38)
@@ -244,4 +244,6 @@ def message
244244

245245
status_code(39)
246246
end
247+
248+
class InvalidArgumentError < BundlerError; status_code(40); end
247249
end

lib/bundler/fetcher.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require_relative "vendored_persistent"
44
require_relative "vendored_timeout"
55
require "cgi"
6-
require "securerandom"
6+
require_relative "vendored_securerandom"
77
require "zlib"
88

99
module Bundler
@@ -182,7 +182,7 @@ def user_agent
182182
agent << " ci/#{cis.join(",")}" if cis.any?
183183

184184
# add a random ID so we can consolidate runs server-side
185-
agent << " " << SecureRandom.hex(8)
185+
agent << " " << Gem::SecureRandom.hex(8)
186186

187187
# add any user agent strings set in the config
188188
extra_ua = Bundler.settings[:user_agent]

lib/bundler/inline.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,9 @@ def gemfile(install = false, options = {}, &gemfile)
4646
Bundler::Plugin.gemfile_install(&gemfile) if Bundler.feature_flag.plugins?
4747
builder = Bundler::Dsl.new
4848
builder.instance_eval(&gemfile)
49-
builder.check_primary_source_safety
5049

5150
Bundler.settings.temporary(deployment: false, frozen: false) do
5251
definition = builder.to_definition(nil, true)
53-
def definition.lock(*); end
5452
definition.validate_runtime!
5553

5654
if install || definition.missing_specs?
@@ -62,8 +60,25 @@ def definition.lock(*); end
6260
end
6361
end
6462

65-
runtime = Bundler::Runtime.new(nil, definition)
66-
runtime.setup.require
63+
begin
64+
runtime = Bundler::Runtime.new(nil, definition).setup
65+
rescue Gem::LoadError => e
66+
name = e.name
67+
version = e.requirement.requirements.first[1]
68+
activated_version = Gem.loaded_specs[name].version
69+
70+
Bundler.ui.info \
71+
"The #{name} gem was resolved to #{version}, but #{activated_version} was activated by Bundler while installing it, causing a conflict. " \
72+
"Bundler will now retry resolving with #{activated_version} instead."
73+
74+
builder.dependencies.delete_if {|d| d.name == name }
75+
builder.instance_eval { gem name, activated_version }
76+
definition = builder.to_definition(nil, true)
77+
78+
retry
79+
end
80+
81+
runtime.require
6782
end
6883
end
6984

0 commit comments

Comments
 (0)