Skip to content

Commit c032e2c

Browse files
nobumatzbot
authored andcommitted
[rubygems/rubygems] Use caller_locations instead of splitting caller
Also limit caller ranges rubygems/rubygems@a274b1af78
1 parent c639bac commit c032e2c

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

lib/bundler/env.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def self.environment
120120
specs = Bundler.rubygems.find_name(name)
121121
out << [" #{name}", "(#{specs.map(&:version).join(",")})"] unless specs.empty?
122122
end
123-
if (exe = caller.last.split(":").first)&.match? %r{(exe|bin)/bundler?\z}
123+
if (exe = caller_locations.last.absolute_path)&.match? %r{(exe|bin)/bundler?\z}
124124
shebang = File.read(exe).lines.first
125125
shebang.sub!(/^#!\s*/, "")
126126
unless shebang.start_with?(Gem.ruby, "/usr/bin/env ruby")

lib/bundler/rubygems_integration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def replace_gem(specs, specs_by_name)
220220

221221
[::Kernel.singleton_class, ::Kernel].each do |kernel_class|
222222
redefine_method(kernel_class, :gem) do |dep, *reqs|
223-
if executables&.include?(File.basename(caller.first.split(":").first))
223+
if executables&.include?(File.basename(caller_locations(1, 1).first.path))
224224
break
225225
end
226226

lib/rubygems/specification.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ def self.remove_spec(spec)
874874
# You probably want to use one of the Enumerable methods instead.
875875

876876
def self.all
877-
warn "NOTE: Specification.all called from #{caller.first}" unless
877+
warn "NOTE: Specification.all called from #{caller(1, 1).first}" unless
878878
Gem::Deprecate.skip
879879
_all
880880
end

spec/bundler/support/builders.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ def check_test_gems!
245245
end
246246

247247
def update_repo(path, build_compact_index: true)
248-
if path == gem_repo1 && caller.first.split(" ").last != "`build_repo'"
248+
exempted_caller = Gem.ruby_version >= Gem::Version.new("3.4.0.dev") ? "#{Module.nesting.first}#build_repo" : "build_repo"
249+
if path == gem_repo1 && caller_locations(1, 1).first.label != exempted_caller
249250
raise "Updating gem_repo1 is unsupported -- use gem_repo2 instead"
250251
end
251252
return unless block_given?

0 commit comments

Comments
 (0)