From 4464cbe5cd17cff26b4aceee83c849790b812c8b Mon Sep 17 00:00:00 2001 From: Randy Stauner Date: Tue, 29 Apr 2025 11:30:05 -0700 Subject: [PATCH] [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 --- lib/bundler/cli/doctor/diagnose.rb | 2 +- spec/bundler/commands/doctor_spec.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/bundler/cli/doctor/diagnose.rb b/lib/bundler/cli/doctor/diagnose.rb index c5da23acb8..a878025dda 100644 --- a/lib/bundler/cli/doctor/diagnose.rb +++ b/lib/bundler/cli/doctor/diagnose.rb @@ -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 diff --git a/spec/bundler/commands/doctor_spec.rb b/spec/bundler/commands/doctor_spec.rb index 456fb4ec78..5ceaf37f29 100644 --- a/spec/bundler/commands/doctor_spec.rb +++ b/spec/bundler/commands/doctor_spec.rb @@ -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"]