[前][次][番号順一覧][スレッド一覧]

ruby-changes:61073

From: Josef <ko1@a...>
Date: Fri, 8 May 2020 07:39:42 +0900 (JST)
Subject: [ruby-changes:61073] 856cbbdd52 (master): [rubygems/rubygems] Track removed methods calls and warn during build time.

https://git.ruby-lang.org/ruby.git/commit/?id=856cbbdd52

From 856cbbdd52eaafd27c21a8f4dea7e89373667694 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20=C5=A0im=C3=A1nek?= <josef.simanek@g...>
Date: Sun, 19 Apr 2020 17:43:31 +0200
Subject: [rubygems/rubygems] Track removed methods calls and warn during build
 time. move rubyforge_project= to removed methods

https://github.com/rubygems/rubygems/commit/223f7fd470

diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 6ff9a89..eb62287 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -6,6 +6,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L6
 # See LICENSE.txt for permissions.
 #++
 
+require 'set'
 require 'rubygems/version'
 require 'rubygems/requirement'
 require 'rubygems/platform'
@@ -193,6 +194,12 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L194
   @@spec_with_requirable_file = {}
   @@active_stub_with_requirable_file = {}
 
+  # Tracking removed method calls to warn users during build time.
+  REMOVED_METHODS = [:rubyforge_project=].freeze # :nodoc:
+  def removed_method_calls
+    @removed_method_calls ||= Set.new
+  end
+
   ######################################################################
   # :section: Required gemspec attributes
 
@@ -728,13 +735,6 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L735
   attr_writer :original_platform # :nodoc:
 
   ##
-  # Deprecated via specification policy and ignored during runtime.
-  #
-  # Formerly used to set rubyforge project.
-
-  attr_accessor :rubyforge_project
-
-  ##
   # The Gem::Specification version of this gemspec.
   #
   # Do not set this, it is set automatically when the gem is packaged.
@@ -2099,9 +2099,15 @@ class Gem::Specification < Gem::BasicSpecification https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification.rb#L2099
   end
 
   ##
+  # Track removed method calls to warn about during build time.
   # Warn about unknown attributes while loading a spec.
 
   def method_missing(sym, *a, &b) # :nodoc:
+    if REMOVED_METHODS.include?(sym)
+      removed_method_calls << sym
+      return
+    end
+
     if @specification_version > CURRENT_SPECIFICATION_VERSION and
       sym.to_s =~ /=$/
       warn "ignoring #{sym} loading #{full_name}" if $DEBUG
diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb
index 8d4958c..4b525df 100644
--- a/lib/rubygems/specification_policy.rb
+++ b/lib/rubygems/specification_policy.rb
@@ -21,8 +21,6 @@ class Gem::SpecificationPolicy https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L21
     funding_uri
   ].freeze # :nodoc:
 
-  DEPRECATED_ATTRIBUTES = [:rubyforge_project].freeze #:nodoc:
-
   def initialize(specification)
     @warnings = 0
 
@@ -78,7 +76,7 @@ class Gem::SpecificationPolicy https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L76
 
     validate_dependencies
 
-    validate_deprecated_attributes
+    validate_removed_attributes
 
     if @warnings > 0
       if strict
@@ -413,9 +411,9 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li https://github.com/ruby/ruby/blob/trunk/lib/rubygems/specification_policy.rb#L411
     warning "#{executable_path} is missing #! line"
   end
 
-  def validate_deprecated_attributes # :nodoc:
-    DEPRECATED_ATTRIBUTES.each do |attr|
-      warning("#{attr} is deprecated") unless @specification.send(attr).nil?
+  def validate_removed_attributes # :nodoc:
+    @specification.removed_method_calls.each do |attr|
+      warning("#{attr} is deprecated and ignored. Please remove this from your gemspec to ensure that your gem continues to build in the future.")
     end
   end
 
diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb
index cf4a4de..21cd7c8 100644
--- a/test/rubygems/test_gem_specification.rb
+++ b/test/rubygems/test_gem_specification.rb
@@ -3128,24 +3128,19 @@ http://spdx.org/licenses or 'Nonstandard' for a nonstandard license. https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_specification.rb#L3128
     warning
   end
 
-  def test_deprecated_attributes
-    assert_equal Gem::SpecificationPolicy::DEPRECATED_ATTRIBUTES, [:rubyforge_project]
+  def test_removed_methods
+    assert_equal Gem::Specification::REMOVED_METHODS, [:rubyforge_project=]
   end
 
-  def test_validate_deprecated_attributes
+  def test_validate_removed_rubyforge_project
     util_setup_validate
 
     use_ui @ui do
-      Gem::SpecificationPolicy::DEPRECATED_ATTRIBUTES.each do |attr|
-        @a1.send("#{attr}=", 'invalid-attribute')
-      end
-
+      @a1.rubyforge_project = 'invalid-attribute'
       @a1.validate
     end
 
-    Gem::SpecificationPolicy::DEPRECATED_ATTRIBUTES.each do |attr|
-      assert_match "#{attr} is deprecated", @ui.error
-    end
+    assert_match "rubyforge_project= is deprecated", @ui.error
   end
 
   def test_validate_license_values
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]