[rubygems/rubygems] Ensure that Gem::Platform parses strings to a fix point
The issue was that the property that ```ruby platform = Gem::Platform.new $string platform == Gem::Platform.new(platform.to_s) ``` was not always true. This property (of acchieving a fix point) is important, since `Gem::Platform` gets serialized to a string and then deserialized back to a `Gem::Platform` object. If it doesn't deserialize to the same object, then different platforms are used for the initial serialization than subsequent runs. I used https://github.com/segiddins/Scratch/blob/main/2025/03/rubygems-platform.rb to find the failing cases and then fixed them. With this patch, the prop check test now passes. https://github.com/rubygems/rubygems/commit/313fb4bcec
This commit is contained in:
parent
72387ebd0e
commit
eb48418b40
@ -88,25 +88,32 @@ class Gem::Platform
|
|||||||
when Array then
|
when Array then
|
||||||
@cpu, @os, @version = arch
|
@cpu, @os, @version = arch
|
||||||
when String then
|
when String then
|
||||||
|
arch_str = arch
|
||||||
arch = arch.split "-"
|
arch = arch.split "-"
|
||||||
|
|
||||||
if arch.length > 2 && !arch.last.match?(/\d+(\.\d+)?$/) # reassemble x86-linux-{libc}
|
if arch.length > 2 && !arch.last.match?(/^\d+(\.\d+)?$/) # reassemble x86-linux-{libc}
|
||||||
extra = arch.pop
|
extra = arch.pop
|
||||||
arch.last << "-#{extra}"
|
arch.last << "-#{extra}"
|
||||||
end
|
end
|
||||||
|
|
||||||
cpu = arch.shift
|
cpu = arch.shift
|
||||||
|
if cpu.nil? || "" == cpu
|
||||||
@cpu = case cpu
|
raise ArgumentError, "empty cpu in platform #{arch_str.inspect}"
|
||||||
when /i\d86/ then "x86"
|
|
||||||
else cpu
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@cpu = if cpu.match?(/i\d86/)
|
||||||
|
"x86"
|
||||||
|
else
|
||||||
|
cpu
|
||||||
|
end
|
||||||
|
|
||||||
if arch.length == 2 && arch.last.match?(/^\d+(\.\d+)?$/) # for command-line
|
if arch.length == 2 && arch.last.match?(/^\d+(\.\d+)?$/) # for command-line
|
||||||
@os, @version = arch
|
@os, @version = arch
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# discard the version element, it didn't match the version pattern (\d+(\.\d+)?)
|
||||||
os, = arch
|
os, = arch
|
||||||
if os.nil?
|
if os.nil?
|
||||||
@cpu = nil
|
@cpu = nil
|
||||||
@ -120,17 +127,17 @@ class Gem::Platform
|
|||||||
when /^macruby$/ then ["macruby", nil]
|
when /^macruby$/ then ["macruby", nil]
|
||||||
when /freebsd(\d+)?/ then ["freebsd", $1]
|
when /freebsd(\d+)?/ then ["freebsd", $1]
|
||||||
when /^java$/, /^jruby$/ then ["java", nil]
|
when /^java$/, /^jruby$/ then ["java", nil]
|
||||||
when /^java([\d.]*)/ then ["java", $1]
|
when /^java(\d+(?:\.\d+)*)?/ then ["java", $1]
|
||||||
when /^dalvik(\d+)?$/ then ["dalvik", $1]
|
when /^dalvik(\d+)?$/ then ["dalvik", $1]
|
||||||
when /^dotnet$/ then ["dotnet", nil]
|
when /^dotnet$/ then ["dotnet", nil]
|
||||||
when /^dotnet([\d.]*)/ then ["dotnet", $1]
|
when /^dotnet(\d+(?:\.\d+)*)?/ then ["dotnet", $1]
|
||||||
when /linux-?(\w+)?/ then ["linux", $1]
|
when /linux-?(\w+)?/ then ["linux", $1]
|
||||||
when /mingw32/ then ["mingw32", nil]
|
when /mingw32/ then ["mingw32", nil]
|
||||||
when /mingw-?(\w+)?/ then ["mingw", $1]
|
when /mingw-?(\w+)?/ then ["mingw", $1]
|
||||||
when /(mswin\d+)(\_(\d+))?/ then
|
when /(mswin\d+)(?:\_(\d+))?/ then
|
||||||
os = $1
|
os = $1
|
||||||
version = $3
|
version = $2
|
||||||
@cpu = "x86" if @cpu.nil? && os =~ /32$/
|
@cpu = "x86" if @cpu.nil? && os.end_with?("32")
|
||||||
[os, version]
|
[os, version]
|
||||||
when /netbsdelf/ then ["netbsdelf", nil]
|
when /netbsdelf/ then ["netbsdelf", nil]
|
||||||
when /openbsd(\d+\.\d+)?/ then ["openbsd", $1]
|
when /openbsd(\d+\.\d+)?/ then ["openbsd", $1]
|
||||||
@ -154,6 +161,9 @@ class Gem::Platform
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
if @cpu.nil? && @os && @version
|
||||||
|
return "#{@os}#{@version}"
|
||||||
|
end
|
||||||
to_a.compact.join "-"
|
to_a.compact.join "-"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -148,12 +148,23 @@ class TestGemPlatform < Gem::TestCase
|
|||||||
"wasm32-wasi" => ["wasm32", "wasi", nil],
|
"wasm32-wasi" => ["wasm32", "wasi", nil],
|
||||||
"wasm32-wasip1" => ["wasm32", "wasi", nil],
|
"wasm32-wasip1" => ["wasm32", "wasi", nil],
|
||||||
"wasm32-wasip2" => ["wasm32", "wasi", nil],
|
"wasm32-wasip2" => ["wasm32", "wasi", nil],
|
||||||
|
|
||||||
|
"darwin-java-java" => ["darwin", "java", nil],
|
||||||
|
"linux-linux-linux" => ["linux", "linux", "linux"],
|
||||||
|
"linux-linux-linux1.0" => ["linux", "linux", "linux1"],
|
||||||
|
"x86x86-1x86x86x86x861linuxx86x86" => ["x86x86", "linux", "x86x86"],
|
||||||
|
"freebsd0" => [nil, "freebsd", "0"],
|
||||||
|
"darwin0" => [nil, "darwin", "0"],
|
||||||
|
"darwin0---" => [nil, "darwin", "0"],
|
||||||
|
"x86-linux-x8611.0l" => ["x86", "linux", "x8611"],
|
||||||
|
"0-x86linuxx86---" => ["0", "linux", "x86"],
|
||||||
}
|
}
|
||||||
|
|
||||||
test_cases.each do |arch, expected|
|
test_cases.each do |arch, expected|
|
||||||
platform = Gem::Platform.new arch
|
platform = Gem::Platform.new arch
|
||||||
assert_equal expected, platform.to_a, arch.inspect
|
assert_equal expected, platform.to_a, arch.inspect
|
||||||
assert_equal expected, Gem::Platform.new(platform.to_s).to_a, arch.inspect
|
platform2 = Gem::Platform.new platform.to_s
|
||||||
|
assert_equal expected, platform2.to_a, "#{arch.inspect} => #{platform2.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user