diff options
author | David RodrÃguez <[email protected]> | 2024-12-23 12:24:49 +0100 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2024-12-24 12:07:54 +0900 |
commit | 42026ec3da6acb2c398bea8c8dc97103a7c936ec (patch) | |
tree | 0d5475bfb73eada6d13d18cff713a036d0cd54fa | |
parent | 0d81177c2013b0a596eb4caebe0bcca557144139 (diff) |
Fix bundled gems warning for sub feature locations
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12439
-rw-r--r-- | lib/bundled_gems.rb | 29 | ||||
-rw-r--r-- | spec/bundled_gems_spec.rb | 7 |
2 files changed, 13 insertions, 23 deletions
diff --git a/lib/bundled_gems.rb b/lib/bundled_gems.rb index efaba69aa7..e09402b1a6 100644 --- a/lib/bundled_gems.rb +++ b/lib/bundled_gems.rb @@ -142,29 +142,24 @@ module Gem::BUNDLED_GEMS # :nodoc: # are costly (see [Bug #20641]), so we first do a much cheaper check # to exclude the vast majority of candidates. if feature.include?("/") - # If requiring $LIBDIR/mutex_m.rb, we check SINCE_FAST_PATH["mutex_m"] - # We'll fail to warn requires for files that are not the entry point - # of the gem, e.g. require "logger/formatter.rb" won't warn. - # But that's acceptable because this warning is best effort, - # and in the overwhelming majority of cases logger.rb will end - # up required. - return unless SINCE_FAST_PATH[File.basename(feature, ".*")] + # bootsnap expands `require "csv"` to `require "#{LIBDIR}/csv.rb"`, + # and `require "syslog"` to `require "#{ARCHDIR}/syslog.so"`. + name = feature.delete_prefix(ARCHDIR).delete_prefix(LIBDIR).sub(LIBEXT, "") + segments = name.split("/") + name = segments.first + if !SINCE[name] + name = segments[0..1].join("-") + return unless SINCE[name] + end else - return unless SINCE_FAST_PATH[feature] + name = feature.sub(LIBEXT, "") + return unless SINCE_FAST_PATH[name] end - # bootsnap expands `require "csv"` to `require "#{LIBDIR}/csv.rb"`, - # and `require "syslog"` to `require "#{ARCHDIR}/syslog.so"`. - name = feature.delete_prefix(ARCHDIR) - name.delete_prefix!(LIBDIR) - name.tr!("/", "-") - name.sub!(LIBEXT, "") return if specs.include?(name) _t, path = $:.resolve_feature_path(feature) if gem = find_gem(path) return if specs.include?(gem) - caller = caller_locations(3, 3)&.find {|c| c&.absolute_path} - return if find_gem(caller&.absolute_path) elsif SINCE[name] && !path gem = true else @@ -177,8 +172,6 @@ module Gem::BUNDLED_GEMS # :nodoc: gem = name "#{feature} was loaded from the standard library, but" elsif gem - return if WARNED[gem] - WARNED[gem] = true "#{feature} is found in #{gem}, which" else return diff --git a/spec/bundled_gems_spec.rb b/spec/bundled_gems_spec.rb index e04f46fd7b..46443ea250 100644 --- a/spec/bundled_gems_spec.rb +++ b/spec/bundled_gems_spec.rb @@ -128,11 +128,8 @@ RSpec.describe "bundled_gems.rb" do require "fiddle/import" RUBY - expect(err).to include(/fiddle was loaded from (.*) from Ruby 3.5.0/) - # We should assert caller location of sub-feature like below: - # expect(err).to include(/-e:7/) - # The current warning message is the location of fiddle itself on sub-feature. - expect(err).to include(/fiddle\/import\.rb:2/) # brittle + expect(err).to include(/fiddle\/import is found in fiddle, which will no longer be part of the default gems starting from Ruby 3\.5\.0/) + expect(err).to include(/-e:7/) end it "Show warning when bundle exec with ruby and script" do |