Skip to content

Commit

Permalink
Remove Gem::Specification#mark_version
Browse files Browse the repository at this point in the history
This gets in the middle if we ever start allowing to build as if using a
different RubyGems version than the one being run.

This could be useful to make `gem rebuild` a little more usable, and
it's already done by Bundler specs which already make this method a noop
when they need this.

I'm not sure forcefully setting this, even if user explicitly specified
something else is helpful.

Since this could potentially prevent gems explicitly setting a constant
RubyGems version from building, I changed the error of incorrect
RubyGems version from a hard error to a warning, since it will start
happening in those cases if we stop overwriting the version.
  • Loading branch information
deivid-rodriguez committed Apr 29, 2024
1 parent d95430f commit 5261076
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
1 change: 0 additions & 1 deletion bundler/spec/support/builders.rb
Expand Up @@ -518,7 +518,6 @@ def _build(options)

if options[:rubygems_version]
@spec.rubygems_version = options[:rubygems_version]
def @spec.mark_version; end

def @spec.validate(*); end
end
Expand Down
1 change: 0 additions & 1 deletion lib/rubygems/package.rb
Expand Up @@ -294,7 +294,6 @@ def build(skip_validation = false, strict_validation = false)

Gem.load_yaml

@spec.mark_version
@spec.validate true, strict_validation unless skip_validation

setup_signer(
Expand Down
12 changes: 1 addition & 11 deletions lib/rubygems/specification.rb
Expand Up @@ -194,7 +194,7 @@ def self.clear_specs # :nodoc:
NOT_FOUND = Struct.new(:to_spec, :this).new # :nodoc:

# Tracking removed method calls to warn users during build time.
REMOVED_METHODS = [:rubyforge_project=].freeze # :nodoc:
REMOVED_METHODS = [:rubyforge_project=, :mark_version].freeze # :nodoc:
def removed_method_calls
@removed_method_calls ||= []
end
Expand Down Expand Up @@ -1874,8 +1874,6 @@ def doc_dir(type = nil)
end

def encode_with(coder) # :nodoc:
mark_version

coder.add "name", @name
coder.add "version", @version
platform = case @original_platform
Expand Down Expand Up @@ -2170,13 +2168,6 @@ def internal_init # :nodoc:
@spec_file = nil
end

##
# Sets the rubygems_version to the current RubyGems version.

def mark_version
@rubygems_version = Gem::VERSION
end

##
# Track removed method calls to warn about during build time.
# Warn about unknown attributes while loading a spec.
Expand Down Expand Up @@ -2494,7 +2485,6 @@ def test_files # :nodoc:
# still have their default values are omitted.

def to_ruby
mark_version
result = []
result << "# -*- encoding: utf-8 -*-"
result << "#{Gem::StubSpecification::PREFIX}#{name} #{version} #{platform} #{raw_require_paths.join("\0")}"
Expand Down
4 changes: 3 additions & 1 deletion lib/rubygems/specification_policy.rb
Expand Up @@ -274,7 +274,9 @@ def validate_rubygems_version

return if rubygems_version == Gem::VERSION

error "expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"
warning "expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"

@specification.rubygems_version = Gem::VERSION
end

def validate_required_attributes
Expand Down
1 change: 0 additions & 1 deletion test/rubygems/test_gem.rb
Expand Up @@ -1281,7 +1281,6 @@ def test_self_try_activate_missing_prerelease
def test_self_try_activate_missing_extensions
spec = util_spec "ext", "1" do |s|
s.extensions = %w[ext/extconf.rb]
s.mark_version
s.installed_by_version = v("2.2")
end

Expand Down
16 changes: 9 additions & 7 deletions test/rubygems/test_gem_specification.rb
Expand Up @@ -56,7 +56,6 @@ def make_spec_c1
s.add_dependency "jabber4r", "> 0.0.0"
s.add_dependency "pqa", ["> 0.4", "<= 0.6"]

s.mark_version
s.files = %w[lib/code.rb]
end
end
Expand All @@ -69,7 +68,6 @@ def ext_spec(platform: Gem::Platform::RUBY)
s.license = "MIT"
s.platform = platform

s.mark_version
s.files = %w[lib/code.rb]
s.installed_by_version = v("2.2")
end
Expand All @@ -96,7 +94,6 @@ def setup
s.requirements << "A working computer"
s.license = "MIT"

s.mark_version
s.files = %w[lib/code.rb]
end

Expand Down Expand Up @@ -3187,7 +3184,7 @@ def test_validate_license_in_a_non_packaging_context
end

def test_removed_methods
assert_equal Gem::Specification::REMOVED_METHODS, [:rubyforge_project=]
assert_equal Gem::Specification::REMOVED_METHODS, [:rubyforge_project=, :mark_version]
end

def test_validate_removed_rubyforge_project
Expand Down Expand Up @@ -3480,12 +3477,17 @@ def test_validate_rubygems_version
util_setup_validate

@a1.rubygems_version = "3"
e = assert_raise Gem::InvalidSpecificationException do

use_ui @ui do
@a1.validate
end

assert_equal "expected RubyGems version #{Gem::VERSION}, was 3",
e.message
expected = <<~EXPECTED
#{w}: expected RubyGems version #{Gem::VERSION}, was 3
#{w}: See https://guides.rubygems.org/specification-reference/ for help
EXPECTED

assert_equal expected, @ui.error
end

def test_validate_specification_version
Expand Down

0 comments on commit 5261076

Please sign in to comment.