Skip to content

Commit a04f70b

Browse files
Merge pull request #7322 from rubygems/release/bundler_2.5.3_rubygems_3.5.3
Prepare RubyGems 3.5.3 and Bundler 2.5.3
2 parents 0035192 + 4ead07d commit a04f70b

File tree

17 files changed

+140
-18
lines changed

17 files changed

+140
-18
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 3.5.3 / 2023-12-22
2+
3+
## Enhancements:
4+
5+
* Installs bundler 2.5.3 as a default gem.
6+
17
# 3.5.2 / 2023-12-21
28

39
## Enhancements:

bundler/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 2.5.3 (December 22, 2023)
2+
3+
## Bug fixes:
4+
5+
- Fix incorrect error when Gemfile overrides a gemspec development dependency [#7319](https://github.com/rubygems/rubygems/pull/7319)
6+
17
# 2.5.2 (December 21, 2023)
28

39
## Enhancements:

bundler/lib/bundler/dependency.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def should_include?
6868
@should_include && current_env? && current_platform?
6969
end
7070

71+
def gemspec_dev_dep?
72+
type == :development
73+
end
74+
7175
def current_env?
7276
return true unless @env
7377
if @env.is_a?(Hash)

bundler/lib/bundler/dsl.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,21 @@ def gem(name, *args)
103103
# if there's already a dependency with this name we try to prefer one
104104
if current = @dependencies.find {|d| d.name == dep.name }
105105
# Always prefer the dependency from the Gemfile
106-
deleted_dep = @dependencies.delete(current) if current.type == :development
106+
@dependencies.delete(current) if current.gemspec_dev_dep?
107107

108108
if current.requirement != dep.requirement
109109
current_requirement_open = current.requirements_list.include?(">= 0")
110110

111-
if current.type == :development
112-
unless current_requirement_open || dep.type == :development
113-
Bundler.ui.warn "A gemspec development dependency (#{dep.name}, #{current.requirement}) is being overridden by a Gemfile dependency (#{dep.name}, #{dep.requirement}).\n" \
114-
"This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement\n" \
111+
gemspec_dep = [dep, current].find(&:gemspec_dev_dep?)
112+
if gemspec_dep
113+
gemfile_dep = [dep, current].find(&:runtime?)
114+
115+
unless current_requirement_open
116+
Bundler.ui.warn "A gemspec development dependency (#{gemspec_dep.name}, #{gemspec_dep.requirement}) is being overridden by a Gemfile dependency (#{gemfile_dep.name}, #{gemfile_dep.requirement}).\n" \
117+
"This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement\n"
115118
end
119+
120+
return if dep.gemspec_dev_dep?
116121
else
117122
update_prompt = ""
118123

@@ -130,8 +135,8 @@ def gem(name, *args)
130135
"You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \
131136
"#{update_prompt}"
132137
end
133-
elsif current.type == :development || dep.type == :development
134-
return if deleted_dep.nil?
138+
elsif current.gemspec_dev_dep? || dep.gemspec_dev_dep?
139+
return if dep.gemspec_dev_dep?
135140
elsif current.source != dep.source
136141
raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \
137142
"You specified that #{dep.name} (#{dep.requirement}) should come from " \

bundler/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 = "2.5.2".freeze
4+
VERSION = "2.5.3".freeze
55

66
def self.bundler_major_version
77
@bundler_major_version ||= VERSION.split(".").first.to_i

bundler/spec/commands/install_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,35 @@
460460
expect(the_bundle).to include_gems("rubocop 1.37.1")
461461
end
462462

463+
it "warns when a Gemfile dependency is overriding a gemspec development dependency, with different requirements" do
464+
build_lib "my-gem", path: bundled_app do |s|
465+
s.add_development_dependency "rails", ">= 5"
466+
end
467+
468+
build_repo4 do
469+
build_gem "rails", "7.0.8"
470+
end
471+
472+
gemfile <<~G
473+
source "#{file_uri_for(gem_repo4)}"
474+
475+
gem "rails", "~> 7.0.8"
476+
477+
gemspec
478+
G
479+
480+
bundle :install
481+
482+
expect(err).to include("A gemspec development dependency (rails, >= 5) is being overridden by a Gemfile dependency (rails, ~> 7.0.8).")
483+
expect(err).to include("This behaviour may change in the future. Please remove either of them, or make sure they both have the same requirement")
484+
485+
# This is not the best behavior I believe, it would be better if both
486+
# requirements are considered if they are compatible, and a version
487+
# satisfying both is chosen. But not sure about changing it right now, so
488+
# I went with a warning for the time being.
489+
expect(the_bundle).to include_gems("rails 7.0.8")
490+
end
491+
463492
it "does not warn if a gem is added once in Gemfile and also inside a gemspec as a development dependency, with same requirements, and different sources" do
464493
build_lib "my-gem", path: bundled_app do |s|
465494
s.add_development_dependency "activesupport"

lib/rubygems.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
require "rbconfig"
1010

1111
module Gem
12-
VERSION = "3.5.2"
12+
VERSION = "3.5.3"
1313
end
1414

1515
# Must be first since it unloads the prelude from 1.9.2

lib/rubygems/safe_marshal/elements.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ def initialize(sign, data)
133133
end
134134
attr_reader :sign, :data
135135
end
136+
137+
class UserClass < Element
138+
def initialize(name, wrapped_object)
139+
@name = name
140+
@wrapped_object = wrapped_object
141+
end
142+
attr_reader :name, :wrapped_object
143+
end
136144
end
137145
end
138146
end

lib/rubygems/safe_marshal/reader.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ def read_struct
299299
end
300300

301301
def read_user_class
302-
raise NotImplementedError, "Reading Marshal objects of type user_class is not implemented"
302+
name = read_element
303+
wrapped_object = read_element
304+
Elements::UserClass.new(name, wrapped_object)
303305
end
304306
end
305307
end

lib/rubygems/safe_marshal/visitors/to_ruby.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,30 @@ def visit_Gem_SafeMarshal_Elements_Bignum(b)
247247
end
248248
end
249249

250+
def visit_Gem_SafeMarshal_Elements_UserClass(r)
251+
if resolve_class(r.name) == ::Hash && r.wrapped_object.is_a?(Elements::Hash)
252+
253+
hash = register_object({}.compare_by_identity)
254+
255+
o = r.wrapped_object
256+
o.pairs.each_with_index do |(k, v), i|
257+
push_stack i
258+
k = visit(k)
259+
push_stack k
260+
hash[k] = visit(v)
261+
end
262+
263+
if o.is_a?(Elements::HashWithDefaultValue)
264+
push_stack :default
265+
hash.default = visit(o.default)
266+
end
267+
268+
hash
269+
else
270+
raise UnsupportedError.new("Unsupported user class #{resolve_class(r.name)} in marshal stream", stack: formatted_stack)
271+
end
272+
end
273+
250274
def resolve_class(n)
251275
@class_cache[n] ||= begin
252276
to_s = resolve_symbol_name(n)
@@ -375,6 +399,12 @@ def initialize(name:, stack:)
375399
end
376400
end
377401

402+
class UnsupportedError < Error
403+
def initialize(message, stack:)
404+
super "#{message} @ #{stack.join "."}"
405+
end
406+
end
407+
378408
class FormatError < Error
379409
end
380410

0 commit comments

Comments
 (0)