From f451ea9c9f8c5d11798cdd1ecf8f8865cd3654d2 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 7 May 2026 19:11:54 +0900 Subject: [ruby/rubygems] Capture Gemfile source location for each override Bundler::Dsl#override now records caller_locations(1, 1).first on each Override so the originating Gemfile line can be surfaced in later diagnostics. https://github.com/ruby/rubygems/commit/ef73385cdc Co-Authored-By: Claude Opus 4.7 (1M context) --- lib/bundler/dsl.rb | 3 ++- lib/bundler/override.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 46389b6c68..d67291514b 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -201,8 +201,9 @@ module Bundler validate_override_uniqueness!(target, field) end + source_location = caller_locations(1, 1)&.first operations.each do |field, operation| - @overrides << Override.new(target, field, operation) + @overrides << Override.new(target, field, operation, source_location: source_location) end end diff --git a/lib/bundler/override.rb b/lib/bundler/override.rb index ed5b51281f..7b71415290 100644 --- a/lib/bundler/override.rb +++ b/lib/bundler/override.rb @@ -9,12 +9,18 @@ module Bundler overrides.find {|o| o.target == :all && o.field == field } end - attr_reader :target, :field, :operation + attr_reader :target, :field, :operation, :source_location - def initialize(target, field, operation) + def initialize(target, field, operation, source_location: nil) @target = target @field = field @operation = operation + @source_location = source_location + end + + def source_location_label + return nil unless @source_location + "#{File.basename(@source_location.path)}:#{@source_location.lineno}" end def apply_to(requirement) -- cgit v1.2.3