Skip to content

Commit

Permalink
[rubygems/rubygems] Skip nil-value keys to make metadata reproducible
Browse files Browse the repository at this point in the history
Nil-value keys in a mapping end with a space or not depending on
libyaml versions, and result metadata are different per platforms.
This commit makes to skip such keys to make metadata reproducible
accross platforms.

rubygems/rubygems@74b4db8d30
  • Loading branch information
nobu authored and matzbot committed Feb 21, 2024
1 parent d578684 commit c8fb4f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/rubygems/psych_tree.rb
Expand Up @@ -14,6 +14,10 @@ def visit_String(str)
@emitter.scalar str, nil, nil, false, true, quote
end

def visit_Hash(o)
super(o.dup.delete_if {|_, v| v.nil? })
end

# Noop this out so there are no anchors
def register(target, obj)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/rubygems/specification.rb
Expand Up @@ -1890,7 +1890,8 @@ def encode_with(coder) # :nodoc:

attributes = @@attributes.map(&:to_s) - %w[name version platform]
attributes.each do |name|
coder.add name, instance_variable_get("@#{name}")
value = instance_variable_get("@#{name}")
coder.add name, value unless value.nil?
end
end

Expand Down
20 changes: 20 additions & 0 deletions test/rubygems/test_gem_specification.rb
Expand Up @@ -2517,6 +2517,26 @@ def test_to_yaml_platform_nil
assert_match(/^platform: ruby$/, @a1.to_yaml)
end

def test_to_yaml_no_autorequire
yaml_str = @a1.to_yaml

refute_match(/^autorequire:/, yaml_str)
end

def test_to_yaml_no_signing_key
@a1.signing_key = nil
yaml_str = @a1.to_yaml

refute_match(/^signing_key:/, yaml_str)
end

def test_to_yaml_no_post_install_message
@a1.post_install_message = nil
yaml_str = @a1.to_yaml

refute_match(/^post_install_message:/, yaml_str)
end

def test_validate
util_setup_validate

Expand Down

0 comments on commit c8fb4f3

Please sign in to comment.