diff --git a/bundler/lib/bundler/current_ruby.rb b/bundler/lib/bundler/current_ruby.rb index 93e0c401c056..784960198723 100644 --- a/bundler/lib/bundler/current_ruby.rb +++ b/bundler/lib/bundler/current_ruby.rb @@ -71,6 +71,8 @@ def truffleruby? def windows? Gem.win_platform? end + + # @deprecated Use windows? instead. These methods will be removed in Rubygems version 4. alias_method :mswin?, :windows? alias_method :mswin64?, :windows? alias_method :mingw?, :windows? diff --git a/bundler/lib/bundler/dependency.rb b/bundler/lib/bundler/dependency.rb index 09a145b8c8eb..1f564342169b 100644 --- a/bundler/lib/bundler/dependency.rb +++ b/bundler/lib/bundler/dependency.rb @@ -17,11 +17,11 @@ class Dependency < Gem::Dependency truffleruby: [Gem::Platform::RUBY], jruby: [Gem::Platform::JAVA, [18, 19]], windows: [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS], - # deprecated - mswin: [Gem::Platform::MSWIN, ALL_RUBY_VERSIONS], - mswin64: [Gem::Platform::MSWIN64, ALL_RUBY_VERSIONS - [18]], - mingw: [Gem::Platform::MINGW, ALL_RUBY_VERSIONS], - x64_mingw: [Gem::Platform::X64_MINGW, ALL_RUBY_VERSIONS - [18, 19]], + # @deprecated Use :windows instead. + mswin: [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS], + mswin64: [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS - [18]], + mingw: [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS], + x64_mingw: [Gem::Platform::WINDOWS, ALL_RUBY_VERSIONS - [18, 19]], }.each_with_object({}) do |(platform, spec), hash| hash[platform] = spec[0] spec[1]&.each {|version| hash[:"#{platform}_#{version}"] = spec[0] } diff --git a/bundler/lib/bundler/dsl.rb b/bundler/lib/bundler/dsl.rb index 05c60f2f1aab..ee7ba7bdefc5 100644 --- a/bundler/lib/bundler/dsl.rb +++ b/bundler/lib/bundler/dsl.rb @@ -271,6 +271,7 @@ def install_if(*args) end def platforms(*platforms) + deprecate_legacy_windows_platforms(platforms) @platforms.concat platforms yield ensure @@ -488,6 +489,16 @@ def normalize_source(source) end end + def deprecate_legacy_windows_platforms(platforms) + dep_platforms = Array(platforms).select {|pl| pl.to_s.match?(/mingw|mswin/) } + return if dep_platforms.empty? + + dep_platforms = dep_platforms.map! {|pl| ":#{pl}" }.join(", ") + message = "Platform #{dep_platforms} is deprecated. Please use platform :windows instead." + removed_message = "Platform #{dep_platforms} has been removed. Please use platform :windows instead." + Bundler::SharedHelpers.major_deprecation 3, message, removed_message: removed_message + end + def check_path_source_safety return if @sources.global_path_source.nil? diff --git a/bundler/lib/bundler/gem_helpers.rb b/bundler/lib/bundler/gem_helpers.rb index 75243873f26c..795bb576e1bb 100644 --- a/bundler/lib/bundler/gem_helpers.rb +++ b/bundler/lib/bundler/gem_helpers.rb @@ -5,13 +5,10 @@ module GemHelpers GENERIC_CACHE = { Gem::Platform::RUBY => Gem::Platform::RUBY } # rubocop:disable Style/MutableConstant GENERICS = [ [Gem::Platform.new("java"), Gem::Platform.new("java")], - [Gem::Platform.new("mswin32"), Gem::Platform.new("mswin32")], - [Gem::Platform.new("mswin64"), Gem::Platform.new("mswin64")], - [Gem::Platform.new("universal-mingw32"), Gem::Platform.new("universal-mingw32")], - [Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw32")], - [Gem::Platform.new("x86_64-mingw32"), Gem::Platform.new("x64-mingw32")], - [Gem::Platform.new("x64-mingw-ucrt"), Gem::Platform.new("x64-mingw-ucrt")], - [Gem::Platform.new("mingw32"), Gem::Platform.new("x86-mingw32")], + [Gem::Platform.new("mswin32"), Gem::Platform.new("windows")], + [Gem::Platform.new("mswin64"), Gem::Platform.new("windows")], + [Gem::Platform.new("mingw32"), Gem::Platform.new("windows")], + [Gem::Platform.new("mingw"), Gem::Platform.new("windows")], ].freeze def generic(p) diff --git a/bundler/lib/bundler/rubygems_ext.rb b/bundler/lib/bundler/rubygems_ext.rb index bc7f65c7f7eb..be571f160d5e 100644 --- a/bundler/lib/bundler/rubygems_ext.rb +++ b/bundler/lib/bundler/rubygems_ext.rb @@ -291,15 +291,21 @@ def matching_specs(platform_only = false) require "rubygems/platform" class Platform - JAVA = Gem::Platform.new("java") + JAVA = Gem::Platform.new("java") + WINDOWS = Gem::Platform.new("windows") + X64_LINUX = Gem::Platform.new("x86_64-linux") + X64_LINUX_MUSL = Gem::Platform.new("x86_64-linux-musl") + + # @deprecated Use WINDOWS instead. These constants will be removed in RubyGems 4. MSWIN = Gem::Platform.new("mswin32") MSWIN64 = Gem::Platform.new("mswin64") MINGW = Gem::Platform.new("x86-mingw32") X64_MINGW = [Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw-ucrt")].freeze - WINDOWS = [MSWIN, MSWIN64, MINGW, X64_MINGW].flatten.freeze - X64_LINUX = Gem::Platform.new("x86_64-linux") - X64_LINUX_MUSL = Gem::Platform.new("x86_64-linux-musl") + deprecate_constant :MSWIN + deprecate_constant :MSWIN64 + deprecate_constant :MINGW + deprecate_constant :X64_MINGW if X64_LINUX === X64_LINUX_MUSL remove_method :=== diff --git a/bundler/spec/bundler/dependency_spec.rb b/bundler/spec/bundler/dependency_spec.rb index 1185c4e5dd04..c9c9b0693078 100644 --- a/bundler/spec/bundler/dependency_spec.rb +++ b/bundler/spec/bundler/dependency_spec.rb @@ -99,71 +99,71 @@ end let(:deprecated) do - { mswin: Gem::Platform::MSWIN, - mswin_18: Gem::Platform::MSWIN, - mswin_19: Gem::Platform::MSWIN, - mswin_20: Gem::Platform::MSWIN, - mswin_21: Gem::Platform::MSWIN, - mswin_22: Gem::Platform::MSWIN, - mswin_23: Gem::Platform::MSWIN, - mswin_24: Gem::Platform::MSWIN, - mswin_25: Gem::Platform::MSWIN, - mswin_26: Gem::Platform::MSWIN, - mswin_27: Gem::Platform::MSWIN, - mswin_30: Gem::Platform::MSWIN, - mswin_31: Gem::Platform::MSWIN, - mswin_32: Gem::Platform::MSWIN, - mswin_33: Gem::Platform::MSWIN, - mswin_34: Gem::Platform::MSWIN, - mswin_35: Gem::Platform::MSWIN, - mswin64: Gem::Platform::MSWIN64, - mswin64_19: Gem::Platform::MSWIN64, - mswin64_20: Gem::Platform::MSWIN64, - mswin64_21: Gem::Platform::MSWIN64, - mswin64_22: Gem::Platform::MSWIN64, - mswin64_23: Gem::Platform::MSWIN64, - mswin64_24: Gem::Platform::MSWIN64, - mswin64_25: Gem::Platform::MSWIN64, - mswin64_26: Gem::Platform::MSWIN64, - mswin64_27: Gem::Platform::MSWIN64, - mswin64_30: Gem::Platform::MSWIN64, - mswin64_31: Gem::Platform::MSWIN64, - mswin64_32: Gem::Platform::MSWIN64, - mswin64_33: Gem::Platform::MSWIN64, - mswin64_34: Gem::Platform::MSWIN64, - mswin64_35: Gem::Platform::MSWIN64, - mingw: Gem::Platform::MINGW, - mingw_18: Gem::Platform::MINGW, - mingw_19: Gem::Platform::MINGW, - mingw_20: Gem::Platform::MINGW, - mingw_21: Gem::Platform::MINGW, - mingw_22: Gem::Platform::MINGW, - mingw_23: Gem::Platform::MINGW, - mingw_24: Gem::Platform::MINGW, - mingw_25: Gem::Platform::MINGW, - mingw_26: Gem::Platform::MINGW, - mingw_27: Gem::Platform::MINGW, - mingw_30: Gem::Platform::MINGW, - mingw_31: Gem::Platform::MINGW, - mingw_32: Gem::Platform::MINGW, - mingw_33: Gem::Platform::MINGW, - mingw_34: Gem::Platform::MINGW, - mingw_35: Gem::Platform::MINGW, - x64_mingw: Gem::Platform::X64_MINGW, - x64_mingw_20: Gem::Platform::X64_MINGW, - x64_mingw_21: Gem::Platform::X64_MINGW, - x64_mingw_22: Gem::Platform::X64_MINGW, - x64_mingw_23: Gem::Platform::X64_MINGW, - x64_mingw_24: Gem::Platform::X64_MINGW, - x64_mingw_25: Gem::Platform::X64_MINGW, - x64_mingw_26: Gem::Platform::X64_MINGW, - x64_mingw_27: Gem::Platform::X64_MINGW, - x64_mingw_30: Gem::Platform::X64_MINGW, - x64_mingw_31: Gem::Platform::X64_MINGW, - x64_mingw_32: Gem::Platform::X64_MINGW, - x64_mingw_33: Gem::Platform::X64_MINGW, - x64_mingw_34: Gem::Platform::X64_MINGW, - x64_mingw_35: Gem::Platform::X64_MINGW } + { mswin: Gem::Platform::WINDOWS, + mswin_18: Gem::Platform::WINDOWS, + mswin_19: Gem::Platform::WINDOWS, + mswin_20: Gem::Platform::WINDOWS, + mswin_21: Gem::Platform::WINDOWS, + mswin_22: Gem::Platform::WINDOWS, + mswin_23: Gem::Platform::WINDOWS, + mswin_24: Gem::Platform::WINDOWS, + mswin_25: Gem::Platform::WINDOWS, + mswin_26: Gem::Platform::WINDOWS, + mswin_27: Gem::Platform::WINDOWS, + mswin_30: Gem::Platform::WINDOWS, + mswin_31: Gem::Platform::WINDOWS, + mswin_32: Gem::Platform::WINDOWS, + mswin_33: Gem::Platform::WINDOWS, + mswin_34: Gem::Platform::WINDOWS, + mswin_35: Gem::Platform::WINDOWS, + mswin64: Gem::Platform::WINDOWS, + mswin64_19: Gem::Platform::WINDOWS, + mswin64_20: Gem::Platform::WINDOWS, + mswin64_21: Gem::Platform::WINDOWS, + mswin64_22: Gem::Platform::WINDOWS, + mswin64_23: Gem::Platform::WINDOWS, + mswin64_24: Gem::Platform::WINDOWS, + mswin64_25: Gem::Platform::WINDOWS, + mswin64_26: Gem::Platform::WINDOWS, + mswin64_27: Gem::Platform::WINDOWS, + mswin64_30: Gem::Platform::WINDOWS, + mswin64_31: Gem::Platform::WINDOWS, + mswin64_32: Gem::Platform::WINDOWS, + mswin64_33: Gem::Platform::WINDOWS, + mswin64_34: Gem::Platform::WINDOWS, + mswin64_35: Gem::Platform::WINDOWS, + mingw: Gem::Platform::WINDOWS, + mingw_18: Gem::Platform::WINDOWS, + mingw_19: Gem::Platform::WINDOWS, + mingw_20: Gem::Platform::WINDOWS, + mingw_21: Gem::Platform::WINDOWS, + mingw_22: Gem::Platform::WINDOWS, + mingw_23: Gem::Platform::WINDOWS, + mingw_24: Gem::Platform::WINDOWS, + mingw_25: Gem::Platform::WINDOWS, + mingw_26: Gem::Platform::WINDOWS, + mingw_27: Gem::Platform::WINDOWS, + mingw_30: Gem::Platform::WINDOWS, + mingw_31: Gem::Platform::WINDOWS, + mingw_32: Gem::Platform::WINDOWS, + mingw_33: Gem::Platform::WINDOWS, + mingw_34: Gem::Platform::WINDOWS, + mingw_35: Gem::Platform::WINDOWS, + x64_mingw: Gem::Platform::WINDOWS, + x64_mingw_20: Gem::Platform::WINDOWS, + x64_mingw_21: Gem::Platform::WINDOWS, + x64_mingw_22: Gem::Platform::WINDOWS, + x64_mingw_23: Gem::Platform::WINDOWS, + x64_mingw_24: Gem::Platform::WINDOWS, + x64_mingw_25: Gem::Platform::WINDOWS, + x64_mingw_26: Gem::Platform::WINDOWS, + x64_mingw_27: Gem::Platform::WINDOWS, + x64_mingw_30: Gem::Platform::WINDOWS, + x64_mingw_31: Gem::Platform::WINDOWS, + x64_mingw_32: Gem::Platform::WINDOWS, + x64_mingw_33: Gem::Platform::WINDOWS, + x64_mingw_34: Gem::Platform::WINDOWS, + x64_mingw_35: Gem::Platform::WINDOWS } end # rubocop:enable Naming/VariableNumber diff --git a/bundler/spec/other/ext_spec.rb b/bundler/spec/other/ext_spec.rb index 9fc0414b4d33..c4f69b17a35e 100644 --- a/bundler/spec/other/ext_spec.rb +++ b/bundler/spec/other/ext_spec.rb @@ -28,25 +28,18 @@ expect(generic(pl("java"))).to eq(pl("java")) end - it "converts mswin platform variants into x86-mswin32" do - expect(generic(pl("mswin32"))).to eq(pl("x86-mswin32")) - expect(generic(pl("i386-mswin32"))).to eq(pl("x86-mswin32")) - expect(generic(pl("x86-mswin32"))).to eq(pl("x86-mswin32")) - end - - it "converts 32-bit mingw platform variants into x86-mingw32" do - expect(generic(pl("mingw32"))).to eq(pl("x86-mingw32")) - expect(generic(pl("i386-mingw32"))).to eq(pl("x86-mingw32")) - expect(generic(pl("x86-mingw32"))).to eq(pl("x86-mingw32")) - end - - it "converts 64-bit mingw platform variants into x64-mingw32" do - expect(generic(pl("x64-mingw32"))).to eq(pl("x64-mingw32")) - expect(generic(pl("x86_64-mingw32"))).to eq(pl("x64-mingw32")) - end - - it "converts 64-bit mingw UCRT platform variants into x64-mingw-ucrt" do - expect(generic(pl("x64-mingw-ucrt"))).to eq(pl("x64-mingw-ucrt")) + it "converts windows platform variants into windows" do + expect(generic(pl("mswin32"))).to eq(pl("windows")) + expect(generic(pl("i386-mswin32"))).to eq(pl("windows")) + expect(generic(pl("x86-mswin32"))).to eq(pl("windows")) + expect(generic(pl("mingw32"))).to eq(pl("windows")) + expect(generic(pl("i386-mingw32"))).to eq(pl("windows")) + expect(generic(pl("x86-mingw32"))).to eq(pl("windows")) + expect(generic(pl("x64-mingw32"))).to eq(pl("windows")) + expect(generic(pl("x86_64-mingw32"))).to eq(pl("windows")) + expect(generic(pl("x64-mingw-ucrt"))).to eq(pl("windows")) + expect(generic(pl("aarch64-mingw"))).to eq(pl("windows")) + expect(generic(pl("aarch64-mingw-ucrt"))).to eq(pl("windows")) end end diff --git a/bundler/spec/support/platforms.rb b/bundler/spec/support/platforms.rb index 526e1c09a9c0..790fd13fdff5 100644 --- a/bundler/spec/support/platforms.rb +++ b/bundler/spec/support/platforms.rb @@ -59,7 +59,7 @@ def not_local def local_tag if RUBY_PLATFORM == "java" :jruby - elsif ["x64-mingw32", "x64-mingw-ucrt"].include?(RUBY_PLATFORM) + elsif RUBY_PLATFORM.match?(/mingw|mswin/) :windows else :ruby @@ -105,7 +105,7 @@ def lockfile_platforms(*extra, defaults: default_locked_platforms) end def default_locked_platforms - [local_platform, generic_local_platform] + [local_platform, generic_local_platform] - [Gem::Platform.new("windows")] end end end diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb index 450c2141676e..1a18ac46bbb6 100644 --- a/lib/rubygems/platform.rb +++ b/lib/rubygems/platform.rb @@ -125,6 +125,7 @@ def initialize(arch) when /^dotnet$/ then ["dotnet", nil] when /^dotnet([\d.]*)/ then ["dotnet", $1] when /linux-?(\w+)?/ then ["linux", $1] + when /windows-?(\w+)?/ then ["windows", $1] when /mingw32/ then ["mingw32", nil] when /mingw-?(\w+)?/ then ["mingw", $1] when /(mswin\d+)(\_(\d+))?/ then diff --git a/test/rubygems/test_gem_platform.rb b/test/rubygems/test_gem_platform.rb index 070c8007bc00..a78e3cf34b2c 100644 --- a/test/rubygems/test_gem_platform.rb +++ b/test/rubygems/test_gem_platform.rb @@ -121,6 +121,7 @@ def test_initialize "i386-linux" => ["x86", "linux", nil], "i586-linux-gnu" => ["x86", "linux", "gnu"], "i386-linux-gnu" => ["x86", "linux", "gnu"], + "windows" => [nil, "windows", nil], "i386-mingw32" => ["x86", "mingw32", nil], "x64-mingw-ucrt" => ["x64", "mingw", "ucrt"], "i386-mswin32" => ["x86", "mswin32", nil],