Skip to content
Closed
2 changes: 2 additions & 0 deletions bundler/lib/bundler/current_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
10 changes: 5 additions & 5 deletions bundler/lib/bundler/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] }
Expand Down
11 changes: 11 additions & 0 deletions bundler/lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def install_if(*args)
end

def platforms(*platforms)
deprecate_legacy_windows_platforms(platforms)
@platforms.concat platforms
yield
ensure
Expand Down Expand Up @@ -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?

Expand Down
11 changes: 4 additions & 7 deletions bundler/lib/bundler/gem_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purposes of generics, I've introduced a new virtual OS value "windows" which doesn't actually exist in the wild. Please let me know if I should map all these to "mingw" instead.

].freeze

def generic(p)
Expand Down
14 changes: 10 additions & 4 deletions bundler/lib/bundler/rubygems_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 :===
Expand Down
130 changes: 65 additions & 65 deletions bundler/spec/bundler/dependency_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 12 additions & 19 deletions bundler/spec/other/ext_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/support/platforms.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/rubygems/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/rubygems/test_gem_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
Loading