Skip to content

Commit 409b1c9

Browse files
authored
Merge pull request #255261 from Homebrew/binary_linked_to_library
formulae: use `binary_linked_to_library?`
2 parents f8f8bce + 413177d commit 409b1c9

File tree

8 files changed

+31
-52
lines changed

8 files changed

+31
-52
lines changed

Formula/c/cocogitto.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,9 @@ def install
4040
system "git", "commit", "-m", "chore: initial commit"
4141
assert_equal "No errored commits", shell_output("#{bin}/cog check 2>&1").strip
4242

43-
linkage_with_libgit2 = (bin/"cog").dynamically_linked_libraries.any? do |dll|
44-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
45-
46-
File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
47-
end
48-
49-
assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
43+
require "utils/linkage"
44+
library = Formula["libgit2"].opt_lib/shared_library("libgit2")
45+
assert Utils.binary_linked_to_library?(bin/"cog", library),
46+
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
5047
end
5148
end

Formula/c/convco.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ def install
3838
shell_output("#{bin}/convco check", 1).lines.first)
3939

4040
# Verify that we are using the libgit2 library
41-
linkage_with_libgit2 = (bin/"convco").dynamically_linked_libraries.any? do |dll|
42-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
43-
44-
File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
45-
end
46-
assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
41+
require "utils/linkage"
42+
library = Formula["libgit2"].opt_lib/shared_library("libgit2")
43+
assert Utils.binary_linked_to_library?(bin/"convco", library),
44+
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
4745
end
4846
end

Formula/c/corsixth.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def install
9898

9999
test do
100100
if OS.mac?
101+
require "utils/linkage"
101102
lua = Formula["lua"]
102-
103103
app = prefix/"CorsixTH.app/Contents/MacOS/CorsixTH"
104-
assert_includes app.dynamically_linked_libraries, "#{lua.opt_lib}/liblua.dylib"
104+
assert Utils.binary_linked_to_library?(app, lua.opt_lib/"liblua.dylib"), "No linkage with lua!"
105105
end
106106

107107
PTY.spawn(bin/"CorsixTH") do |r, _w, pid|

Formula/e/eza.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,9 @@ def install
5858
system "git", "commit", "-m", "Initial commit"
5959
assert_equal "--", eza_output.call
6060

61-
linkage_with_libgit2 = (bin/"eza").dynamically_linked_libraries.any? do |dll|
62-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
63-
64-
File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
65-
end
66-
67-
assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
61+
require "utils/linkage"
62+
library = Formula["libgit2"].opt_lib/shared_library("libgit2")
63+
assert Utils.binary_linked_to_library?(bin/"eza", library),
64+
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
6865
end
6966
end

Formula/g/gfold.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@ def install
4848
end
4949

5050
assert_match "\e[0m\e[32mclean\e[0m (master)", shell_output("#{bin}/gfold #{testpath} 2>&1")
51+
assert_match "gfold #{version}", shell_output("#{bin}/gfold --version")
5152

5253
# libgit2 linkage test to avoid using vendored one
5354
# https://github.com/Homebrew/homebrew-core/pull/125393#issuecomment-1465250076
54-
linkage_with_libgit2 = (bin/"gfold").dynamically_linked_libraries.any? do |dll|
55-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
56-
57-
File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
58-
end
59-
60-
assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
61-
62-
assert_match "gfold #{version}", shell_output("#{bin}/gfold --version")
55+
require "utils/linkage"
56+
library = Formula["libgit2"].opt_lib/shared_library("libgit2")
57+
assert Utils.binary_linked_to_library?(bin/"gfold", library),
58+
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
6359
end
6460
end

Formula/g/git-absorb.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ def install
5050
system "git", "add", "test"
5151
system "git", "absorb"
5252

53-
linkage_with_libgit2 = (bin/"git-absorb").dynamically_linked_libraries.any? do |dll|
54-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
55-
56-
File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
57-
end
58-
59-
assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
53+
require "utils/linkage"
54+
library = Formula["libgit2"].opt_lib/shared_library("libgit2")
55+
assert Utils.binary_linked_to_library?(bin/"git-absorb", library),
56+
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
6057
end
6158
end

Formula/g/git-branchless.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ def install
5959
system "git", "branchless", "init"
6060
assert_match "Initial Commit", shell_output("git sl").strip
6161

62-
linkage_with_libgit2 = (bin/"git-branchless").dynamically_linked_libraries.any? do |dll|
63-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
64-
65-
File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
66-
end
67-
68-
assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
62+
require "utils/linkage"
63+
library = Formula["libgit2"].opt_lib/shared_library("libgit2")
64+
assert Utils.binary_linked_to_library?(bin/"git-branchless", library),
65+
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
6966
end
7067
end

Formula/g/git-cliff.rb

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ def install
5656
- Initial commit
5757
EOS
5858

59-
linkage_with_libgit2 = (bin/"git-cliff").dynamically_linked_libraries.any? do |dll|
60-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
61-
62-
File.realpath(dll) == (Formula["libgit2"].opt_lib/shared_library("libgit2")).realpath.to_s
63-
end
64-
65-
assert linkage_with_libgit2, "No linkage with libgit2! Cargo is likely using a vendored version."
59+
require "utils/linkage"
60+
library = Formula["libgit2"].opt_lib/shared_library("libgit2")
61+
assert Utils.binary_linked_to_library?(bin/"git-cliff", library),
62+
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
6663
end
6764
end

0 commit comments

Comments
 (0)