From 80f3700a72a160eb7e676f46165f37fb29fa5607 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 11:59:28 -0500 Subject: [PATCH 1/8] gfold: use `binary_linked_to_library?` --- Formula/g/gfold.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Formula/g/gfold.rb b/Formula/g/gfold.rb index e955ddc1b4a57..79c778361200d 100644 --- a/Formula/g/gfold.rb +++ b/Formula/g/gfold.rb @@ -48,17 +48,13 @@ def install end assert_match "\e[0m\e[32mclean\e[0m (master)", shell_output("#{bin}/gfold #{testpath} 2>&1") + assert_match "gfold #{version}", shell_output("#{bin}/gfold --version") # libgit2 linkage test to avoid using vendored one # https://github.com/Homebrew/homebrew-core/pull/125393#issuecomment-1465250076 - linkage_with_libgit2 = (bin/"gfold").dynamically_linked_libraries.any? do |dll| - next false unless dll.start_with?(HOMEBREW_PREFIX.to_s) - - File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s - end - - assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version." - - assert_match "gfold #{version}", shell_output("#{bin}/gfold --version") + require "utils/linkage" + library = Formula["libgit2"].opt_lib/shared_library("libgit2") + assert Utils.binary_linked_to_library?(bin/"gfold", library), + "No linkage with #{library.basename}! Cargo is likely using a vendored version." end end From c148526283162ee98b8ec7d255faaf32a548dd14 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 12:01:55 -0500 Subject: [PATCH 2/8] git-cliff: use `binary_linked_to_library?` --- Formula/g/git-cliff.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Formula/g/git-cliff.rb b/Formula/g/git-cliff.rb index 06e03e50b6d71..be03eaaef7fbc 100644 --- a/Formula/g/git-cliff.rb +++ b/Formula/g/git-cliff.rb @@ -56,12 +56,9 @@ def install - Initial commit EOS - linkage_with_libgit2 = (bin/"git-cliff").dynamically_linked_libraries.any? do |dll| - next false unless dll.start_with?(HOMEBREW_PREFIX.to_s) - - File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s - end - - assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version." + require "utils/linkage" + library = Formula["libgit2"].opt_lib/shared_library("libgit2") + assert Utils.binary_linked_to_library?(bin/"git-cliff", library), + "No linkage with #{library.basename}! Cargo is likely using a vendored version." end end From b715a5c6b3c0bd34e3bb96f629ed967ffd29834f Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 12:02:49 -0500 Subject: [PATCH 3/8] git-branchless: use `binary_linked_to_library?` --- Formula/g/git-branchless.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Formula/g/git-branchless.rb b/Formula/g/git-branchless.rb index 6c1066735e8c4..2a8fc190286a1 100644 --- a/Formula/g/git-branchless.rb +++ b/Formula/g/git-branchless.rb @@ -59,12 +59,9 @@ def install system "git", "branchless", "init" assert_match "Initial Commit", shell_output("git sl").strip - linkage_with_libgit2 = (bin/"git-branchless").dynamically_linked_libraries.any? do |dll| - next false unless dll.start_with?(HOMEBREW_PREFIX.to_s) - - File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s - end - - assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version." + require "utils/linkage" + library = Formula["libgit2"].opt_lib/shared_library("libgit2") + assert Utils.binary_linked_to_library?(bin/"git-branchless", library), + "No linkage with #{library.basename}! Cargo is likely using a vendored version." end end From f6dbcb65ba67ecd520592e8dde0faa37d28aa12a Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 12:03:16 -0500 Subject: [PATCH 4/8] git-absorb: use `binary_linked_to_library?` --- Formula/g/git-absorb.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Formula/g/git-absorb.rb b/Formula/g/git-absorb.rb index dc1ac14b1190f..ba5d2760b3b1e 100644 --- a/Formula/g/git-absorb.rb +++ b/Formula/g/git-absorb.rb @@ -50,12 +50,9 @@ def install system "git", "add", "test" system "git", "absorb" - linkage_with_libgit2 = (bin/"git-absorb").dynamically_linked_libraries.any? do |dll| - next false unless dll.start_with?(HOMEBREW_PREFIX.to_s) - - File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s - end - - assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version." + require "utils/linkage" + library = Formula["libgit2"].opt_lib/shared_library("libgit2") + assert Utils.binary_linked_to_library?(bin/"git-absorb", library), + "No linkage with #{library.basename}! Cargo is likely using a vendored version." end end From 44cc657656d15d188a4200ab9faf5fcf47875c01 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 12:04:04 -0500 Subject: [PATCH 5/8] eza: use `binary_linked_to_library?` --- Formula/e/eza.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Formula/e/eza.rb b/Formula/e/eza.rb index f69815adf9c8e..a3fcb2056b124 100644 --- a/Formula/e/eza.rb +++ b/Formula/e/eza.rb @@ -58,12 +58,9 @@ def install system "git", "commit", "-m", "Initial commit" assert_equal "--", eza_output.call - linkage_with_libgit2 = (bin/"eza").dynamically_linked_libraries.any? do |dll| - next false unless dll.start_with?(HOMEBREW_PREFIX.to_s) - - File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s - end - - assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version." + require "utils/linkage" + library = Formula["libgit2"].opt_lib/shared_library("libgit2") + assert Utils.binary_linked_to_library?(bin/"eza", library), + "No linkage with #{library.basename}! Cargo is likely using a vendored version." end end From ace4b1f6b58c6cc5a1ac3adc5e3a422dc6596131 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 12:06:41 -0500 Subject: [PATCH 6/8] cocogitto: use `binary_linked_to_library?` --- Formula/c/cocogitto.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Formula/c/cocogitto.rb b/Formula/c/cocogitto.rb index ac519c5c9cb4c..5f1994b39f96c 100644 --- a/Formula/c/cocogitto.rb +++ b/Formula/c/cocogitto.rb @@ -40,12 +40,9 @@ def install system "git", "commit", "-m", "chore: initial commit" assert_equal "No errored commits", shell_output("#{bin}/cog check 2>&1").strip - linkage_with_libgit2 = (bin/"cog").dynamically_linked_libraries.any? do |dll| - next false unless dll.start_with?(HOMEBREW_PREFIX.to_s) - - File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s - end - - assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version." + require "utils/linkage" + library = Formula["libgit2"].opt_lib/shared_library("libgit2") + assert Utils.binary_linked_to_library?(bin/"cog", library), + "No linkage with #{library.basename}! Cargo is likely using a vendored version." end end From 8cb45d554b8d9f6e2c6edb27f67a5d98b2e7e4f4 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 12:07:18 -0500 Subject: [PATCH 7/8] convco: use `binary_linked_to_library?` --- Formula/c/convco.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Formula/c/convco.rb b/Formula/c/convco.rb index 94cf972c7567b..39e49e93cf656 100644 --- a/Formula/c/convco.rb +++ b/Formula/c/convco.rb @@ -38,11 +38,9 @@ def install shell_output("#{bin}/convco check", 1).lines.first) # Verify that we are using the libgit2 library - linkage_with_libgit2 = (bin/"convco").dynamically_linked_libraries.any? do |dll| - next false unless dll.start_with?(HOMEBREW_PREFIX.to_s) - - File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s - end - assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version." + require "utils/linkage" + library = Formula["libgit2"].opt_lib/shared_library("libgit2") + assert Utils.binary_linked_to_library?(bin/"convco", library), + "No linkage with #{library.basename}! Cargo is likely using a vendored version." end end From 413177dbf1bf344f5ef01887f9db8d48d51e9731 Mon Sep 17 00:00:00 2001 From: Michael Cho Date: Thu, 20 Nov 2025 12:17:29 -0500 Subject: [PATCH 8/8] corsixth: use `binary_linked_to_library?` --- Formula/c/corsixth.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Formula/c/corsixth.rb b/Formula/c/corsixth.rb index d965369edb2b8..8276215fb3d00 100644 --- a/Formula/c/corsixth.rb +++ b/Formula/c/corsixth.rb @@ -98,10 +98,10 @@ def install test do if OS.mac? + require "utils/linkage" lua = Formula["lua"] - app = prefix/"CorsixTH.app/Contents/MacOS/CorsixTH" - assert_includes app.dynamically_linked_libraries, "#{lua.opt_lib}/liblua.dylib" + assert Utils.binary_linked_to_library?(app, lua.opt_lib/"liblua.dylib"), "No linkage with lua!" end PTY.spawn(bin/"CorsixTH") do |r, _w, pid|