[rubygems/rubygems] Add Specification#validate_for_resolution
This method validates only what is required for resolution, skipping any irrelevant metadata validation. This will be used by Bundler instead of doing a full validation, allowing gem authors to use `bundle` commands immediately in newly created gems without first having to fix invalid metafata fields in the default gemspec. https://github.com/rubygems/rubygems/commit/da7704cfc0
This commit is contained in:
parent
9f420e2ba5
commit
39951293b4
@ -32,6 +32,9 @@ module Gem
|
||||
|
||||
require "rubygems/specification"
|
||||
|
||||
# Can be removed once RubyGems 3.5.15 support is dropped
|
||||
VALIDATES_FOR_RESOLUTION = Specification.new.respond_to?(:validate_for_resolution).freeze
|
||||
|
||||
class Specification
|
||||
require_relative "match_metadata"
|
||||
require_relative "match_platform"
|
||||
@ -131,6 +134,12 @@ module Gem
|
||||
!default_gem? && !File.directory?(full_gem_path)
|
||||
end
|
||||
|
||||
unless VALIDATES_FOR_RESOLUTION
|
||||
def validate_for_resolution
|
||||
SpecificationPolicy.new(self).validate_for_resolution
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dependencies_to_gemfile(dependencies, group = nil)
|
||||
@ -150,6 +159,14 @@ module Gem
|
||||
end
|
||||
end
|
||||
|
||||
unless VALIDATES_FOR_RESOLUTION
|
||||
class SpecificationPolicy
|
||||
def validate_for_resolution
|
||||
validate_required!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module BetterPermissionError
|
||||
def data
|
||||
super
|
||||
|
@ -2586,6 +2586,10 @@ class Gem::Specification < Gem::BasicSpecification
|
||||
@test_files.delete_if {|x| File.directory?(x) && !File.symlink?(x) }
|
||||
end
|
||||
|
||||
def validate_for_resolution
|
||||
Gem::SpecificationPolicy.new(self).validate_for_resolution
|
||||
end
|
||||
|
||||
def validate_metadata
|
||||
Gem::SpecificationPolicy.new(self).validate_metadata
|
||||
end
|
||||
|
@ -45,6 +45,7 @@ class Gem::SpecificationPolicy
|
||||
|
||||
def validate(strict = false)
|
||||
validate_required!
|
||||
validate_required_metadata!
|
||||
|
||||
validate_optional(strict) if packaging || strict
|
||||
|
||||
@ -85,15 +86,17 @@ class Gem::SpecificationPolicy
|
||||
|
||||
validate_authors_field
|
||||
|
||||
validate_metadata
|
||||
|
||||
validate_licenses_length
|
||||
|
||||
validate_lazy_metadata
|
||||
|
||||
validate_duplicate_dependencies
|
||||
end
|
||||
|
||||
def validate_required_metadata!
|
||||
validate_metadata
|
||||
|
||||
validate_lazy_metadata
|
||||
end
|
||||
|
||||
def validate_optional(strict)
|
||||
validate_licenses
|
||||
|
||||
@ -120,6 +123,13 @@ class Gem::SpecificationPolicy
|
||||
end
|
||||
end
|
||||
|
||||
##
|
||||
# Implementation for Specification#validate_for_resolution
|
||||
|
||||
def validate_for_resolution
|
||||
validate_required!
|
||||
end
|
||||
|
||||
##
|
||||
# Implementation for Specification#validate_metadata
|
||||
|
||||
|
@ -3951,6 +3951,40 @@ end
|
||||
assert_equal ["default-2.0.0.0"], Gem::Specification.map(&:full_name)
|
||||
end
|
||||
|
||||
def test_validate_for_resolution_validates_required_attributes
|
||||
e = assert_raise Gem::InvalidSpecificationException do
|
||||
@a1.version = nil
|
||||
@a1.validate_for_resolution
|
||||
end
|
||||
|
||||
assert_equal "missing value for attribute version", e.message
|
||||
end
|
||||
|
||||
def test_validate_for_resolution_validates_name
|
||||
e = assert_raise Gem::InvalidSpecificationException do
|
||||
@a1.name = 123
|
||||
@a1.validate_for_resolution
|
||||
end
|
||||
|
||||
assert_equal 'invalid value for attribute name: "123" must be a string', e.message
|
||||
end
|
||||
|
||||
def test_validate_for_resolution_validates_duplicate_dependencies
|
||||
e = assert_raise Gem::InvalidSpecificationException do
|
||||
@a1.add_dependency "foo", "1.2.3"
|
||||
@a1.add_dependency "foo", "3.4.5"
|
||||
@a1.validate_for_resolution
|
||||
end
|
||||
|
||||
assert_match "duplicate dependency on foo", e.message
|
||||
end
|
||||
|
||||
def test_validate_for_resolution_ignores_metadata
|
||||
@a1.summary = "TODO: Invalid summary"
|
||||
@a1.metadata["homepage_uri"] = "TODO: Invalid homepage URI"
|
||||
@a1.validate_for_resolution
|
||||
end
|
||||
|
||||
def util_setup_deps
|
||||
@gem = util_spec "awesome", "1.0" do |awesome|
|
||||
awesome.add_runtime_dependency "bonobo", []
|
||||
|
Loading…
x
Reference in New Issue
Block a user