Skip to content

Commit 495e049

Browse files
authored
Merge pull request Homebrew#205979 from Homebrew/formulae-linkage
formulae: use brew-provided function for checking binary linkage
2 parents 88eca35 + 53dff19 commit 495e049

File tree

15 files changed

+47
-139
lines changed

15 files changed

+47
-139
lines changed

Formula/j/jj.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,9 @@ def install
4646
(man1/"jj.1").write Utils.safe_popen_read(bin/"jj", "util", "mangen")
4747
end
4848

49-
def check_binary_linkage(binary, library)
50-
binary.dynamically_linked_libraries.any? do |dll|
51-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
52-
53-
File.realpath(dll) == File.realpath(library)
54-
end
55-
end
56-
5749
test do
50+
require "utils/linkage"
51+
5852
system bin/"jj", "init", "--git"
5953
assert_predicate testpath/".jj", :exist?
6054

@@ -64,7 +58,7 @@ def check_binary_linkage(binary, library)
6458
Formula["openssl@3"].opt_lib/shared_library("libcrypto"),
6559
Formula["openssl@3"].opt_lib/shared_library("libssl"),
6660
].each do |library|
67-
assert check_binary_linkage(bin/"jj", library),
61+
assert Utils.binary_linked_to_library?(bin/"jj", library),
6862
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
6963
end
7064
end

Formula/m/mise.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@ def caveats
5454
EOS
5555
end
5656

57-
def check_binary_linkage(binary, library)
58-
binary.dynamically_linked_libraries.any? do |dll|
59-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
60-
61-
File.realpath(dll) == File.realpath(library)
62-
end
63-
end
64-
6557
test do
6658
system bin/"mise", "settings", "set", "experimental", "true"
6759
system bin/"mise", "use", "[email protected]"

Formula/o/observerward.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,17 @@ def install
2525
system "cargo", "install", *std_cargo_args(path: "observer_ward")
2626
end
2727

28-
def check_binary_linkage(binary, library)
29-
binary.dynamically_linked_libraries.any? do |dll|
30-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
31-
32-
File.realpath(dll) == File.realpath(library)
33-
end
34-
end
35-
3628
test do
29+
require "utils/linkage"
30+
3731
system bin/"observer_ward", "-u"
3832
assert_match "0example", shell_output("#{bin}/observer_ward -t https://www.example.com/")
3933

4034
[
4135
Formula["openssl@3"].opt_lib/shared_library("libcrypto"),
4236
Formula["openssl@3"].opt_lib/shared_library("libssl"),
4337
].each do |library|
44-
assert check_binary_linkage(bin/"observer_ward", library),
38+
assert Utils.binary_linked_to_library?(bin/"observer_ward", library),
4539
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
4640
end
4741
end

Formula/p/prr.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,9 @@ def install
4242
man1.install Dir["man/*.1"]
4343
end
4444

45-
def check_binary_linkage(binary, library)
46-
binary.dynamically_linked_libraries.any? do |dll|
47-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
48-
49-
File.realpath(dll) == File.realpath(library)
50-
end
51-
end
52-
5345
test do
46+
require "utils/linkage"
47+
5448
assert_match "Failed to read config", shell_output("#{bin}/prr get Homebrew/homebrew-core/6 2>&1", 1)
5549

5650
[
@@ -59,7 +53,7 @@ def check_binary_linkage(binary, library)
5953
Formula["openssl@3"].opt_lib/shared_library("libssl"),
6054
Formula["openssl@3"].opt_lib/shared_library("libcrypto"),
6155
].each do |library|
62-
assert check_binary_linkage(bin/"prr", library),
56+
assert Utils.binary_linked_to_library?(bin/"prr", library),
6357
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
6458
end
6559
end

Formula/r/river.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,9 @@ def install
3030
system "cargo", "install", *std_cargo_args(path: "source/river")
3131
end
3232

33-
def check_binary_linkage(binary, library)
34-
binary.dynamically_linked_libraries.any? do |dll|
35-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
36-
37-
File.realpath(dll) == File.realpath(library)
38-
end
39-
end
40-
4133
test do
34+
require "utils/linkage"
35+
4236
(testpath/"example-config.toml").write <<~TOML
4337
[system]
4438
[[basic-proxy]]
@@ -52,7 +46,7 @@ def check_binary_linkage(binary, library)
5246
Formula["openssl@3"].opt_lib/shared_library("libssl"),
5347
Formula["openssl@3"].opt_lib/shared_library("libcrypto"),
5448
].each do |library|
55-
assert check_binary_linkage(bin/"river", library),
49+
assert Utils.binary_linked_to_library?(bin/"river", library),
5650
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
5751
end
5852
end

Formula/r/rust.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,9 @@ def post_install
209209
end
210210
end
211211

212-
def check_binary_linkage(binary, library)
213-
binary.dynamically_linked_libraries.any? do |dll|
214-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
215-
216-
File.realpath(dll) == File.realpath(library)
217-
end
218-
end
219-
220212
test do
213+
require "utils/linkage"
214+
221215
system bin/"rustdoc", "-h"
222216
(testpath/"hello.rs").write <<~RUST
223217
fn main() {
@@ -254,7 +248,7 @@ def check_binary_linkage(binary, library)
254248
missing_linkage = []
255249
expected_linkage.each do |binary, dylibs|
256250
dylibs.each do |dylib|
257-
next if check_binary_linkage(binary, dylib)
251+
next if Utils.binary_linked_to_library?(binary, dylib)
258252

259253
missing_linkage << "#{binary} => #{dylib}"
260254
end

Formula/s/sapling.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,9 @@ def install
102102
system "make", "-C", "eden/scm", "install-oss", "PREFIX=#{prefix}", "PYTHON=#{python3}", "PYTHON3=#{python3}"
103103
end
104104

105-
def check_binary_linkage(binary, library)
106-
binary.dynamically_linked_libraries.any? do |dll|
107-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
108-
109-
File.realpath(dll) == File.realpath(library)
110-
end
111-
end
112-
113105
test do
106+
require "utils/linkage"
107+
114108
assert_equal "Sapling #{version}", shell_output("#{bin}/sl --version").chomp
115109

116110
system bin/"sl", "config", "--user", "ui.username", "Sapling <[email protected]>"
@@ -131,7 +125,7 @@ def check_binary_linkage(binary, library)
131125
dylibs << (Formula["curl"].opt_lib/shared_library("libcurl")) if OS.linux?
132126

133127
dylibs.each do |library|
134-
assert check_binary_linkage(bin/"sl", library),
128+
assert Utils.binary_linked_to_library?(bin/"sl", library),
135129
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
136130
end
137131
end

Formula/s/sh4d0wup.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,9 @@ def install
4242
generate_completions_from_executable(bin/"sh4d0wup", "completions")
4343
end
4444

45-
def check_binary_linkage(binary, library)
46-
binary.dynamically_linked_libraries.any? do |dll|
47-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
48-
49-
File.realpath(dll) == File.realpath(library)
50-
end
51-
end
52-
5345
test do
46+
require "utils/linkage"
47+
5448
output = shell_output("#{bin}/sh4d0wup keygen tls example.com | openssl x509 -text -noout")
5549
assert_match("DNS:example.com", output)
5650

@@ -67,7 +61,7 @@ def check_binary_linkage(binary, library)
6761
Formula["openssl@3"].opt_lib/shared_library("libssl"),
6862
Formula["openssl@3"].opt_lib/shared_library("libcrypto"),
6963
].each do |library|
70-
assert check_binary_linkage(bin/"sh4d0wup", library),
64+
assert Utils.binary_linked_to_library?(bin/"sh4d0wup", library),
7165
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
7266
end
7367
end

Formula/s/sheldon.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,9 @@ def install
5050
zsh_completion.install "completions/sheldon.zsh" => "_sheldon"
5151
end
5252

53-
def check_binary_linkage(binary, library)
54-
binary.dynamically_linked_libraries.any? do |dll|
55-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
56-
57-
File.realpath(dll) == File.realpath(library)
58-
end
59-
end
60-
6153
test do
54+
require "utils/linkage"
55+
6256
touch testpath/"plugins.toml"
6357
system bin/"sheldon", "--config-dir", testpath, "--data-dir", testpath, "lock"
6458
assert_path_exists testpath/"plugins.lock"
@@ -72,7 +66,7 @@ def check_binary_linkage(binary, library)
7266
libraries << (Formula["curl"].opt_lib/shared_library("libcurl")) if OS.linux?
7367

7468
libraries.each do |library|
75-
assert check_binary_linkage(bin/"sheldon", library),
69+
assert Utils.binary_linked_to_library?(bin/"sheldon", library),
7670
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
7771
end
7872
end

Formula/s/ssh-vault.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,9 @@ def install
3030
system "cargo", "install", *std_cargo_args
3131
end
3232

33-
def check_binary_linkage(binary, library)
34-
binary.dynamically_linked_libraries.any? do |dll|
35-
next false unless dll.start_with?(HOMEBREW_PREFIX.to_s)
36-
37-
File.realpath(dll) == File.realpath(library)
38-
end
39-
end
40-
4133
test do
34+
require "utils/linkage"
35+
4236
test_key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINixf2m2nj8TDeazbWuemUY8ZHNg7znA7hVPN8TJLr2W"
4337
(testpath/"public_key").write test_key
4438
cmd = "#{bin}/ssh-vault f -k #{testpath}/public_key"
@@ -49,7 +43,7 @@ def check_binary_linkage(binary, library)
4943
Formula["openssl@3"].opt_lib/shared_library("libssl"),
5044
Formula["openssl@3"].opt_lib/shared_library("libcrypto"),
5145
].each do |library|
52-
assert check_binary_linkage(bin/"ssh-vault", library),
46+
assert Utils.binary_linked_to_library?(bin/"ssh-vault", library),
5347
"No linkage with #{library.basename}! Cargo is likely using a vendored version."
5448
end
5549
end

0 commit comments

Comments
 (0)