[rubygems/rubygems] Simplify Gem::Platform#initialize
Based on PR feedback Signed-off-by: Samuel Giddins <segiddins@segiddins.me> https://github.com/rubygems/rubygems/commit/562d7aa087
This commit is contained in:
parent
8f61e17556
commit
4be199e435
@ -88,18 +88,7 @@ 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
|
cpu, os = arch.sub(/-+$/, "").split("-", 2)
|
||||||
arch = arch.split "-"
|
|
||||||
|
|
||||||
if arch.length > 2 && !arch.last.match?(/^\d+(\.\d+)?$/) # reassemble x86-linux-{libc}
|
|
||||||
extra = arch.pop
|
|
||||||
arch.last << "-#{extra}"
|
|
||||||
end
|
|
||||||
|
|
||||||
cpu = arch.shift
|
|
||||||
if cpu.nil? || cpu == ""
|
|
||||||
raise ArgumentError, "empty cpu in platform #{arch_str.inspect}"
|
|
||||||
end
|
|
||||||
|
|
||||||
@cpu = if cpu.match?(/i\d86/)
|
@cpu = if cpu.match?(/i\d86/)
|
||||||
"x86"
|
"x86"
|
||||||
@ -107,40 +96,34 @@ class Gem::Platform
|
|||||||
cpu
|
cpu
|
||||||
end
|
end
|
||||||
|
|
||||||
if arch.length == 2 && arch.last.match?(/^\d+(\.\d+)?$/) # for command-line
|
|
||||||
@os, @version = arch
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# discard the version element, it didn't match the version pattern (\d+(\.\d+)?)
|
|
||||||
os, = arch
|
|
||||||
if os.nil?
|
if os.nil?
|
||||||
@cpu = nil
|
@cpu = nil
|
||||||
os = cpu
|
os = cpu
|
||||||
end # legacy jruby
|
end # legacy jruby
|
||||||
|
|
||||||
@os, @version = case os
|
@os, @version = case os
|
||||||
when /aix(\d+)?/ then ["aix", $1]
|
when /aix-?(\d+)?/ then ["aix", $1]
|
||||||
when /cygwin/ then ["cygwin", nil]
|
when /cygwin/ then ["cygwin", nil]
|
||||||
when /darwin(\d+)?/ then ["darwin", $1]
|
when /darwin-?(\d+)?/ then ["darwin", $1]
|
||||||
when /^macruby$/ then ["macruby", nil]
|
when "macruby" then ["macruby", nil]
|
||||||
when /freebsd(\d+)?/ then ["freebsd", $1]
|
when /^macruby-?(\d+(?:\.\d+)*)?/ then ["macruby", $1]
|
||||||
when /^java$/, /^jruby$/ then ["java", nil]
|
when /freebsd-?(\d+)?/ then ["freebsd", $1]
|
||||||
when /^java(\d+(?:\.\d+)*)?/ then ["java", $1]
|
when "java", "jruby" then ["java", nil]
|
||||||
when /^dalvik(\d+)?$/ then ["dalvik", $1]
|
when /^java-?(\d+(?:\.\d+)*)?/ then ["java", $1]
|
||||||
|
when /^dalvik-?(\d+)?$/ then ["dalvik", $1]
|
||||||
when /^dotnet$/ then ["dotnet", nil]
|
when /^dotnet$/ then ["dotnet", nil]
|
||||||
when /^dotnet(\d+(?:\.\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 = $2
|
version = $2
|
||||||
@cpu = "x86" if @cpu.nil? && os.end_with?("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]
|
||||||
when /solaris(\d+\.\d+)?/ then ["solaris", $1]
|
when /solaris-?(\d+\.\d+)?/ then ["solaris", $1]
|
||||||
when /wasi/ then ["wasi", nil]
|
when /wasi/ then ["wasi", nil]
|
||||||
# test
|
# test
|
||||||
when /^(\w+_platform)(\d+)?/ then [$1, $2]
|
when /^(\w+_platform)(\d+)?/ then [$1, $2]
|
||||||
@ -160,10 +143,7 @@ class Gem::Platform
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
if @cpu.nil? && @os && @version
|
to_a.compact.join(@cpu.nil? ? "" : "-")
|
||||||
return "#{@os}#{@version}"
|
|
||||||
end
|
|
||||||
to_a.compact.join "-"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
@ -158,6 +158,10 @@ class TestGemPlatform < Gem::TestCase
|
|||||||
"darwin0---" => [nil, "darwin", "0"],
|
"darwin0---" => [nil, "darwin", "0"],
|
||||||
"x86-linux-x8611.0l" => ["x86", "linux", "x8611"],
|
"x86-linux-x8611.0l" => ["x86", "linux", "x8611"],
|
||||||
"0-x86linuxx86---" => ["0", "linux", "x86"],
|
"0-x86linuxx86---" => ["0", "linux", "x86"],
|
||||||
|
"x86_64-macruby-x86" => ["x86_64", "macruby", nil],
|
||||||
|
"x86_64-dotnetx86" => ["x86_64", "dotnet", nil],
|
||||||
|
"x86_64-dalvik0" => ["x86_64", "dalvik", "0"],
|
||||||
|
"x86_64-dotnet1." => ["x86_64", "dotnet", "1"],
|
||||||
}
|
}
|
||||||
|
|
||||||
test_cases.each do |arch, expected|
|
test_cases.each do |arch, expected|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user