From ab125dc3275e3e402b724beb2541d694726d178a Mon Sep 17 00:00:00 2001 From: Gustavo Ribeiro Date: Fri, 8 Dec 2023 16:17:51 -0300 Subject: [PATCH] Move formatting logic from Gem::Platform.local to Gem::Platform::StringParser --- bundler/lib/bundler/installer/standalone.rb | 2 +- lib/rubygems/platform.rb | 5 +- lib/rubygems/platform/string_parser.rb | 59 +++++++++++---------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/bundler/lib/bundler/installer/standalone.rb b/bundler/lib/bundler/installer/standalone.rb index 8a1e4fda4746..753c43d1fbdc 100644 --- a/bundler/lib/bundler/installer/standalone.rb +++ b/bundler/lib/bundler/installer/standalone.rb @@ -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 diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index c90ed109abab..a3676520a9e9 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -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 diff --git a/lib/rubygems/platform/string_parser.rb b/lib/rubygems/platform/string_parser.rb index b65135fdd56a..05475b30cf46 100644 --- a/lib/rubygems/platform/string_parser.rb +++ b/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} @@ -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 @@ -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