Skip to content

Commit

Permalink
Use ignorestatus() and isnothing() (instead of using try-catch)
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge committed Oct 16, 2024
1 parent 98ab185 commit f55b24e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/PackageCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,7 @@ function create_sysimg_from_object_file(object_files::Vector{String},
mkpath(dirname(sysimage_path))
# Prevent compiler from stripping all symbols from the shared lib.
if Sys.isapple()
try
cltools_version_cmd = `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`
cltools_version = match(r"version: (.*)\n", readchomp(cltools_version_cmd))[1]
global major_version = split(cltools_version, ".")[1]
catch e
@warn "Could not determine the version of the Command Line Tools, assuming greater than 14"
global major_version = "15"
end
if parse(Int64, major_version) > 14
if _xcode_clt_major_version() > 14
o_file_flags = `-Wl,-all_load $object_files -Wl,-ld_classic`
else
o_file_flags = `-Wl,-all_load $object_files`
Expand All @@ -734,6 +726,24 @@ function create_sysimg_from_object_file(object_files::Vector{String},
return nothing
end

function _xcode_clt_major_version()
cmd = `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`
@debug "_xcode_clt_major_version(): Attempting to run command" cmd
# The `ignorestatus` allows us to proceed (with a warning) if
# the command does not run successfully.
output = strip(read(ignorestatus(cmd), String)) * "\n"
r = r"version: (.*)\n"
m = match(r, output)
if isnothing(m)
@warn "Could not determine the version of the Command Line Tools, assuming greater than 14"
major_version_str = "15"
else
major_version_str = split(m[1], '.')[1]
end
major_version_int = parse(Int, major_version_str)
return major_version_int
end

function get_extra_linker_flags(version, compat_level, soname)
current_ver_arg = ``
compat_ver_arg = ``
Expand Down

0 comments on commit f55b24e

Please sign in to comment.