Skip to content

Commit

Permalink
Move formatting logic from Gem::Platform.local to Gem::Platform::Stri…
Browse files Browse the repository at this point in the history
…ngParser
  • Loading branch information
gustavothecoder committed Dec 9, 2023
1 parent 485d0df commit ab125dc
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion bundler/lib/bundler/installer/standalone.rb
Expand Up @@ -140,7 +140,7 @@ def platform_parser
def local_platform
force_mswin_version = true
Gem::Platform::StringParser
.run(RbConfig::CONFIG["arch"])
.run(RbConfig::CONFIG["arch"], force_mswin_version)
.compact
.join "-"
end
Expand Down
5 changes: 2 additions & 3 deletions lib/rubygems/platform.rb
Expand Up @@ -14,9 +14,8 @@ class Gem::Platform

def self.local
@local ||= begin
arch = RbConfig::CONFIG["arch"]
arch = "#{arch}_60" if /mswin(?:32|64)$/.match?(arch)
new(arch)
force_mswin_version = true
new(StringParser.run(RbConfig::CONFIG["arch"], force_mswin_version))
end
end

Expand Down
59 changes: 30 additions & 29 deletions lib/rubygems/platform/string_parser.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true

module Gem::Platform::StringParser
def self.run(arch)
def self.run(arch, force_mswin_version = false)
arch = "#{arch}_60" if /mswin(?:32|64)$/.match?(arch) && force_mswin_version
arch = arch.split "-"

if arch.length > 2 && arch.last !~ /\d+(\.\d+)?$/ # reassemble x86-linux-{libc}
Expand All @@ -12,9 +13,9 @@ def self.run(arch)
cpu = arch.shift

parsed_cpu = case cpu
when /i\d86/ then "x86"
else cpu
end
when /i\d86/ then "x86"
else cpu
end

if arch.length == 2 && arch.last =~ /^\d+(\.\d+)?$/ # for command-line
parsed_os, parsed_version = arch
Expand All @@ -28,31 +29,31 @@ def self.run(arch)
end # legacy jruby

parsed_os, parsed_version = case os
when /aix(\d+)?/ then ["aix", $1]
when /cygwin/ then ["cygwin", nil]
when /darwin(\d+)?/ then ["darwin", $1]
when /^macruby$/ then ["macruby", nil]
when /freebsd(\d+)?/ then ["freebsd", $1]
when /^java$/, /^jruby$/ then ["java", nil]
when /^java([\d.]*)/ then ["java", $1]
when /^dalvik(\d+)?$/ then ["dalvik", $1]
when /^dotnet$/ then ["dotnet", nil]
when /^dotnet([\d.]*)/ then ["dotnet", $1]
when /linux-?(\w+)?/ then ["linux", $1]
when /mingw32/ then ["mingw32", nil]
when /mingw-?(\w+)?/ then ["mingw", $1]
when /(mswin\d+)(\_(\d+))?/ then
os = $1
version = $3
parsed_cpu = "x86" if parsed_cpu.nil? && os =~ /32$/
[os, version]
when /netbsdelf/ then ["netbsdelf", nil]
when /openbsd(\d+\.\d+)?/ then ["openbsd", $1]
when /solaris(\d+\.\d+)?/ then ["solaris", $1]
# test
when /^(\w+_platform)(\d+)?/ then [$1, $2]
else ["unknown", nil]
end
when /aix(\d+)?/ then ["aix", $1]
when /cygwin/ then ["cygwin", nil]
when /darwin(\d+)?/ then ["darwin", $1]
when /^macruby$/ then ["macruby", nil]
when /freebsd(\d+)?/ then ["freebsd", $1]
when /^java$/, /^jruby$/ then ["java", nil]
when /^java([\d.]*)/ then ["java", $1]
when /^dalvik(\d+)?$/ then ["dalvik", $1]
when /^dotnet$/ then ["dotnet", nil]
when /^dotnet([\d.]*)/ then ["dotnet", $1]
when /linux-?(\w+)?/ then ["linux", $1]
when /mingw32/ then ["mingw32", nil]
when /mingw-?(\w+)?/ then ["mingw", $1]
when /(mswin\d+)(\_(\d+))?/ then
os = $1
version = $3
parsed_cpu = "x86" if parsed_cpu.nil? && os =~ /32$/
[os, version]
when /netbsdelf/ then ["netbsdelf", nil]
when /openbsd(\d+\.\d+)?/ then ["openbsd", $1]
when /solaris(\d+\.\d+)?/ then ["solaris", $1]
# test
when /^(\w+_platform)(\d+)?/ then [$1, $2]
else ["unknown", nil]
end

[parsed_cpu, parsed_os, parsed_version]
end
Expand Down

0 comments on commit ab125dc

Please sign in to comment.