Skip to content

Commit 597299d

Browse files
committed
Codesign macOS libraries after modifying them
1 parent 07bbf23 commit 597299d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

stdlib/Libdl/test/runtests.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ end
267267

268268
## Tests for LazyLibrary
269269
@testset "LazyLibrary" begin; mktempdir() do dir
270+
# We require `codesign` to run these tests
271+
if Sys.isapple() && Sys.which("codesign") === nothing
272+
@warn("Unable to run `LazyLibrary` tests on macOS without `codesign` tool!")
273+
return
274+
end
275+
270276
# Create custom-named libccalltest libraries, to avoid failing these tests
271277
# because some other test has already loaded `libccalltest` via `ccall()` or somesuch
272278
lct_name = "libcc4llt3st"
@@ -283,6 +289,19 @@ end
283289
str_replace(lct_path, "libccalltest" => lct_name)
284290
str_replace(lctd_path, "libccalltest" => lct_name)
285291

292+
# If we're on macOS, we need to codesign after modifying these libraries.
293+
if Sys.isapple()
294+
function read_stderr(cmd)
295+
io = IOBuffer()
296+
run(pipeline(cmd; stderr=io))
297+
return String(take!(io))
298+
end
299+
out = read_stderr(`codesign --sign - --option=runtime --timestamp --force $(lct_path)`)
300+
@test endswith(out, "replacing existing signature\n")
301+
out = read_stderr(`codesign --sign - --option=runtime --timestamp --force $(lctd_path)`)
302+
@test endswith(out, "replacing existing signature\n")
303+
end
304+
286305
default_rtld_flags = Base.Libc.Libdl.default_rtld_flags
287306
# Ensure that our modified copy of `libccalltest` is not currently loaded
288307
@test !any(contains.(dllist(), lct_path))

0 commit comments

Comments
 (0)