Skip to content

Commit 42026ec

Browse files
deivid-rodriguezhsbt
authored andcommitted
Fix bundled gems warning for sub feature locations
1 parent 0d81177 commit 42026ec

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

lib/bundled_gems.rb

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -142,29 +142,24 @@ def self.warning?(name, specs: nil)
142142
# are costly (see [Bug #20641]), so we first do a much cheaper check
143143
# to exclude the vast majority of candidates.
144144
if feature.include?("/")
145-
# If requiring $LIBDIR/mutex_m.rb, we check SINCE_FAST_PATH["mutex_m"]
146-
# We'll fail to warn requires for files that are not the entry point
147-
# of the gem, e.g. require "logger/formatter.rb" won't warn.
148-
# But that's acceptable because this warning is best effort,
149-
# and in the overwhelming majority of cases logger.rb will end
150-
# up required.
151-
return unless SINCE_FAST_PATH[File.basename(feature, ".*")]
145+
# bootsnap expands `require "csv"` to `require "#{LIBDIR}/csv.rb"`,
146+
# and `require "syslog"` to `require "#{ARCHDIR}/syslog.so"`.
147+
name = feature.delete_prefix(ARCHDIR).delete_prefix(LIBDIR).sub(LIBEXT, "")
148+
segments = name.split("/")
149+
name = segments.first
150+
if !SINCE[name]
151+
name = segments[0..1].join("-")
152+
return unless SINCE[name]
153+
end
152154
else
153-
return unless SINCE_FAST_PATH[feature]
155+
name = feature.sub(LIBEXT, "")
156+
return unless SINCE_FAST_PATH[name]
154157
end
155158

156-
# bootsnap expands `require "csv"` to `require "#{LIBDIR}/csv.rb"`,
157-
# and `require "syslog"` to `require "#{ARCHDIR}/syslog.so"`.
158-
name = feature.delete_prefix(ARCHDIR)
159-
name.delete_prefix!(LIBDIR)
160-
name.tr!("/", "-")
161-
name.sub!(LIBEXT, "")
162159
return if specs.include?(name)
163160
_t, path = $:.resolve_feature_path(feature)
164161
if gem = find_gem(path)
165162
return if specs.include?(gem)
166-
caller = caller_locations(3, 3)&.find {|c| c&.absolute_path}
167-
return if find_gem(caller&.absolute_path)
168163
elsif SINCE[name] && !path
169164
gem = true
170165
else
@@ -177,8 +172,6 @@ def self.warning?(name, specs: nil)
177172
gem = name
178173
"#{feature} was loaded from the standard library, but"
179174
elsif gem
180-
return if WARNED[gem]
181-
WARNED[gem] = true
182175
"#{feature} is found in #{gem}, which"
183176
else
184177
return

spec/bundled_gems_spec.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,8 @@ def script(code, options = {})
128128
require "fiddle/import"
129129
RUBY
130130

131-
expect(err).to include(/fiddle was loaded from (.*) from Ruby 3.5.0/)
132-
# We should assert caller location of sub-feature like below:
133-
# expect(err).to include(/-e:7/)
134-
# The current warning message is the location of fiddle itself on sub-feature.
135-
expect(err).to include(/fiddle\/import\.rb:2/) # brittle
131+
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/)
132+
expect(err).to include(/-e:7/)
136133
end
137134

138135
it "Show warning when bundle exec with ruby and script" do

0 commit comments

Comments
 (0)