Skip to content

Commit f55b24e

Browse files
committed
Use ignorestatus() and isnothing() (instead of using try-catch)
1 parent 98ab185 commit f55b24e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/PackageCompiler.jl

+19-9
Original file line numberDiff line numberDiff line change
@@ -712,15 +712,7 @@ function create_sysimg_from_object_file(object_files::Vector{String},
712712
mkpath(dirname(sysimage_path))
713713
# Prevent compiler from stripping all symbols from the shared lib.
714714
if Sys.isapple()
715-
try
716-
cltools_version_cmd = `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`
717-
cltools_version = match(r"version: (.*)\n", readchomp(cltools_version_cmd))[1]
718-
global major_version = split(cltools_version, ".")[1]
719-
catch e
720-
@warn "Could not determine the version of the Command Line Tools, assuming greater than 14"
721-
global major_version = "15"
722-
end
723-
if parse(Int64, major_version) > 14
715+
if _xcode_clt_major_version() > 14
724716
o_file_flags = `-Wl,-all_load $object_files -Wl,-ld_classic`
725717
else
726718
o_file_flags = `-Wl,-all_load $object_files`
@@ -734,6 +726,24 @@ function create_sysimg_from_object_file(object_files::Vector{String},
734726
return nothing
735727
end
736728

729+
function _xcode_clt_major_version()
730+
cmd = `pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`
731+
@debug "_xcode_clt_major_version(): Attempting to run command" cmd
732+
# The `ignorestatus` allows us to proceed (with a warning) if
733+
# the command does not run successfully.
734+
output = strip(read(ignorestatus(cmd), String)) * "\n"
735+
r = r"version: (.*)\n"
736+
m = match(r, output)
737+
if isnothing(m)
738+
@warn "Could not determine the version of the Command Line Tools, assuming greater than 14"
739+
major_version_str = "15"
740+
else
741+
major_version_str = split(m[1], '.')[1]
742+
end
743+
major_version_int = parse(Int, major_version_str)
744+
return major_version_int
745+
end
746+
737747
function get_extra_linker_flags(version, compat_level, soname)
738748
current_ver_arg = ``
739749
compat_ver_arg = ``

0 commit comments

Comments
 (0)