diff --git a/src/PackageCompiler.jl b/src/PackageCompiler.jl index 631536c5..25254595 100644 --- a/src/PackageCompiler.jl +++ b/src/PackageCompiler.jl @@ -557,6 +557,7 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector compat_level::String="major", extra_precompiles::String = "", import_into_main::Bool=true, + audit_relocatability::Bool = true ) # We call this at the very beginning to make sure that the user has a compiler available. Therefore, if no compiler # is found, we throw an error immediately, instead of making the user wait a while before the error is thrown. @@ -697,6 +698,13 @@ function create_sysimage(packages::Union{Nothing, Symbol, Vector{String}, Vector end end + if audit_relocatability + @info "Auditing sysimage relocatability" + if audit_sysimage_relocatability(sysimage_path) + @info "No issues found" + end + end + return nothing end @@ -1599,6 +1607,25 @@ function bundle_headers(dest_dir, header_files) return end +function audit_sysimage_relocatability(sysimg_path::String; paths::Vector{String} = [homedir(), DEPOT_PATH...]) + + none_found = true + sysimg_contents = open(io -> String(read(io)), sysimg_path, read=true) + + for path in paths + found = String[] + for m in eachmatch(Regex("\\Q$(path)\\E[^\0]+"), sysimg_contents) + push!(found, "[$(m.offset)] $(m.match)") + end + if !isempty(found) + @warn """absolute path `$path` found in $(length(found)) places:\n$(join(found, "\n"))""" + none_found = false + end + end + + return none_found +end + function bundle_cert(dest_dir) cert_path = joinpath(Sys.BINDIR, "..", "share", "julia", "cert.pem") share_path = joinpath(dest_dir, "share", "julia") diff --git a/test/precompile_execution.jl b/test/precompile_execution.jl index 786fde11..e5084333 100644 --- a/test/precompile_execution.jl +++ b/test/precompile_execution.jl @@ -1,3 +1,6 @@ using Example Example.domath(5) + +# intentionally put an abspath in to test the relocatability audit +test_abspath = homedir()