From aee52d28748a744b2c9390fda8f3556255359875 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Mon, 10 Feb 2025 20:19:44 +0100 Subject: [PATCH 1/2] Use preferred `:windows` value for Windows exclusively Co-authored-by: johnnyshields <27655+johnnyshields@users.noreply.github.com> --- bundler/spec/install/gemfile/platform_spec.rb | 2 +- bundler/spec/install/gemfile/specific_platform_spec.rb | 2 +- bundler/spec/runtime/platform_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bundler/spec/install/gemfile/platform_spec.rb b/bundler/spec/install/gemfile/platform_spec.rb index 64a544a54f8d..d8c1f0282a16 100644 --- a/bundler/spec/install/gemfile/platform_spec.rb +++ b/bundler/spec/install/gemfile/platform_spec.rb @@ -570,7 +570,7 @@ gemfile <<-G source "https://gem.repo1" - gem "myrack", :platform => [:windows, :mswin, :mswin64, :mingw, :x64_mingw, :jruby] + gem "myrack", :platform => [:windows, :jruby] G bundle "install" diff --git a/bundler/spec/install/gemfile/specific_platform_spec.rb b/bundler/spec/install/gemfile/specific_platform_spec.rb index bda37949ad44..257f78f2c596 100644 --- a/bundler/spec/install/gemfile/specific_platform_spec.rb +++ b/bundler/spec/install/gemfile/specific_platform_spec.rb @@ -1000,7 +1000,7 @@ gem "nokogiri" - gem "tzinfo", "~> 1.2", platforms: %i[mingw mswin x64_mingw jruby] + gem "tzinfo", "~> 1.2", platforms: %i[windows jruby] G checksums = checksums_section_when_enabled do |c| diff --git a/bundler/spec/runtime/platform_spec.rb b/bundler/spec/runtime/platform_spec.rb index a6b7a6f07aa4..562184ce1703 100644 --- a/bundler/spec/runtime/platform_spec.rb +++ b/bundler/spec/runtime/platform_spec.rb @@ -373,7 +373,7 @@ simulate_platform "x86-mswin32" do install_gemfile <<-G source "https://gem.repo1" - gem "nokogiri", :platforms => [:windows, :mswin, :mswin64, :mingw, :x64_mingw, :jruby] + gem "nokogiri", :platforms => [:windows, :jruby] gem "platform_specific" G From 0ca6dc39845a9ae3d7ea6bc0740df5db846dcfa5 Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Tue, 28 Jan 2025 23:01:15 +0900 Subject: [PATCH 2/2] Deprecate legacy windows platforms (mswin, mingw) in the Bundler DSL, in favor of using `platform :windows` This commit is only deprecation and does not change/remove any actual functionality. --- bundler/lib/bundler/dsl.rb | 11 +++++++++++ bundler/spec/bundler/dsl_spec.rb | 14 ++++++++++++++ bundler/spec/commands/cache_spec.rb | 14 +++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/bundler/lib/bundler/dsl.rb b/bundler/lib/bundler/dsl.rb index 5bfaa70e5b66..d9cc3e0f346c 100644 --- a/bundler/lib/bundler/dsl.rb +++ b/bundler/lib/bundler/dsl.rb @@ -413,6 +413,7 @@ def normalize_options(name, version, opts) next if VALID_PLATFORMS.include?(p) raise GemfileError, "`#{p}` is not a valid platform. The available options are: #{VALID_PLATFORMS.inspect}" end + deprecate_legacy_windows_platforms(platforms) # Save sources passed in a key if opts.key?("source") @@ -493,6 +494,16 @@ def normalize_source(source) end end + def deprecate_legacy_windows_platforms(platforms) + windows_platforms = platforms.select {|pl| pl.to_s.match?(/mingw|mswin/) } + return if windows_platforms.empty? + + windows_platforms = windows_platforms.map! {|pl| ":#{pl}" }.join(", ") + message = "Platform #{windows_platforms} is deprecated. Please use platform :windows instead." + removed_message = "Platform #{windows_platforms} has been removed. Please use platform :windows instead." + Bundler::SharedHelpers.major_deprecation 2, message, removed_message: removed_message + end + def check_path_source_safety return if @sources.global_path_source.nil? diff --git a/bundler/spec/bundler/dsl_spec.rb b/bundler/spec/bundler/dsl_spec.rb index f5fc0c7bbee4..9dca4ade059d 100644 --- a/bundler/spec/bundler/dsl_spec.rb +++ b/bundler/spec/bundler/dsl_spec.rb @@ -221,6 +221,11 @@ to raise_error(Bundler::GemfileError, /is not a valid platform/) end + it "raises a deprecation warning for legacy windows platforms" do + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, /\APlatform :mswin, :x64_mingw is deprecated/, removed_message: /\APlatform :mswin, :x64_mingw has been removed/) + subject.gem("foo", platforms: [:mswin, :jruby, :x64_mingw]) + end + it "rejects empty gem name" do expect { subject.gem("") }. to raise_error(Bundler::GemfileError, /an empty gem name is not valid/) @@ -285,6 +290,15 @@ end end + describe "#platforms" do + it "raises a deprecation warning for legacy windows platforms" do + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(2, /\APlatform :mswin64, :mingw is deprecated/, removed_message: /\APlatform :mswin64, :mingw has been removed/) + subject.platforms(:mswin64, :jruby, :mingw) do + subject.gem("foo") + end + end + end + context "can bundle groups of gems with" do # git "https://github.com/rails/rails.git" do # gem "railties" diff --git a/bundler/spec/commands/cache_spec.rb b/bundler/spec/commands/cache_spec.rb index ee05bf2e49bd..c4d83f054282 100644 --- a/bundler/spec/commands/cache_spec.rb +++ b/bundler/spec/commands/cache_spec.rb @@ -221,16 +221,28 @@ expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end - it "puts the gems in vendor/cache even for legacy windows rubies" do + it "puts the gems in vendor/cache even for legacy windows rubies, but prints a warning", bundler: "< 3" do gemfile <<-D source "https://gem.repo1" gem 'myrack', :platforms => [:ruby_20, :x64_mingw_20] D bundle "cache --all-platforms" + expect(err).to include("deprecated") expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).to exist end + it "prints an error when using legacy windows rubies", bundler: "3" do + gemfile <<-D + source "https://gem.repo1" + gem 'myrack', :platforms => [:ruby_20, :x64_mingw_20] + D + + bundle "cache --all-platforms", raise_on_error: false + expect(err).to include("removed") + expect(bundled_app("vendor/cache/myrack-1.0.0.gem")).not_to exist + end + it "does not attempt to install gems in without groups" do build_repo4 do build_gem "uninstallable", "2.0" do |s|