[rubygems/rubygems] Fix doctor command parsing of otool output

I have several gem dylibs that have a line matching "(compatibility "
with no file path preceding it.

https://github.com/rubygems/rubygems/commit/de9dc2bdc4
This commit is contained in:
Randy Stauner 2025-04-29 11:30:05 -07:00 committed by Hiroshi SHIBATA
parent af79914002
commit 4464cbe5cd
2 changed files with 7 additions and 1 deletions

View File

@ -24,7 +24,7 @@ module Bundler
def dylibs_darwin(path)
output = `/usr/bin/otool -L #{path.shellescape}`.chomp
dylibs = output.split("\n")[1..-1].map {|l| l.match(DARWIN_REGEX).captures[0] }.uniq
dylibs = output.split("\n")[1..-1].filter_map {|l| l.match(DARWIN_REGEX)&.match(1) }.uniq
# ignore @rpath and friends
dylibs.reject {|dylib| dylib.start_with? "@" }
end

View File

@ -62,6 +62,12 @@ RSpec.describe "bundle doctor" do
expect(@stdout.string).to include("No issues")
end
it "parses otool output correctly" do
doctor = Bundler::CLI::Doctor::Diagnose.new({})
expect(doctor).to receive(:`).with("/usr/bin/otool -L fake").and_return("/home/gem/ruby/3.4.3/gems/blake3-rb-1.5.4.4/lib/digest/blake3/blake3_ext.bundle:\n\t (compatibility version 0.0.0, current version 0.0.0)\n\t/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1351.0.0)")
expect(doctor.dylibs_darwin("fake")).to eq(["/usr/lib/libSystem.B.dylib"])
end
it "exits with a message if one of the linked libraries is missing" do
doctor = Bundler::CLI::Doctor::Diagnose.new({})
expect(doctor).to receive(:bundles_for_gem).exactly(2).times.and_return ["/path/to/myrack/myrack.bundle"]