11# Get the compiler command from `get_compiler_cmd()`, and run `cc --version`, and parse the
22# output to determine whether or not the compiler is an Xcode Clang.
3+ #
4+ # The return value is a NamedTuple of the form (; b, ver)
5+ # b = a Bool that is true iff he compiler is an Xcode Clang.
6+ # ver = the version number of the Xcode Clang. If it's not Xcode Clang, ver is nothing.
37function _is_xcode_clt ()
48 cmd = ` $(get_compiler_cmd ()) --version`
59 @debug " _active_compiler_is_xcode_clt(): Attempting to run command" cmd
10+ # The `ignorestatus` allows us to proceed if the command does not run successfully.
611 output = " \n " * strip (read (ignorestatus (cmd), String)) * " \n "
7- is_apple_clang = occursin (r" Apple clang version" , output)
812 installed_dir_m = match (r" \n InstalledDir: ([\w\/ ]*?)\n " , output)
913 if isnothing (installed_dir_m)
10- return false
14+ return (; b = false , ver = nothing )
1115 end
12- installed_dir_str = strip (installed_dir[1 ])
13- is_xcode_app = startswith (installed_dir_str, " /Applications/Xcode.app/" )
14- is_xcode_clt = startswith (installed_dir_str, " /Library/Developer/CommandLineTools/" )
15- res = is_apple_clang && (is_xcode_app || is_xcode_clt)
16- end
17-
18- # Run `pkgutil` to get the version number of the Xcode CLT (Command Line Tools), and return
19- # the major version number as an integer.
20- function _xcode_clt_major_version ()
21- cmd = ` pkgutil --pkg-info=com.apple.pkg.CLTools_Executables`
22- @debug " _xcode_clt_major_version(): Attempting to run command" cmd
23- # The `ignorestatus` allows us to proceed if the command does
24- # not run successfully.
25- output = " \n " * strip (read (ignorestatus (cmd), String)) * " \n "
26- r = r" version: (.*)\n "
27- m = match (r, output)
28- if isnothing (m)
29- major_version_str = nothing
16+ installed_dir_str = strip (installed_dir_m[1 ])
17+ is_xcode_app = startswith (installed_dir_str, " /Applications/Xcode.app" )
18+ is_xcode_clt = startswith (installed_dir_str, " /Library/Developer/CommandLineTools" )
19+ if is_xcode_app || is_xcode_clt
20+ m = match (r" \n Apple clang version ([0-9\. ]*?) " , output)
21+ if isnothing (m)
22+ @warn " Could not determine the version of the Xcode Command Line Tools"
23+ (; b= false , ver= nothing )
24+ end
25+ ver_str = strip (m[1 ])
26+ ver = tryparse (VersionNumber, ver_str)
27+ if isnothing (ver)
28+ @warn " Could not determine the version of the Xcode Command Line Tools"
29+ (; b= false , ver= nothing )
30+ end
31+ b = true
3032 else
31- major_version_str = split (m[1 ], ' .' )[1 ]
33+ b = false
34+ ver = nothing
3235 end
33- major_version_int = parse (Int, major_version_str)
34- return major_version_int
35- end
36-
37- # Return true iff the Xcode CLT version is >= 15.
38- # "gte" = greater than or equal to.
39- function _is_gte_xcode_15 ()
40- major_version_int = _xcode_clt_major_version ()
41- isnothing (major_version_int) && return nothing
42- return major_version_int >= 15
36+ return (; b, ver)
4337end
4438
4539# Return true iff the compiler is Xcode Clang AND the Xcode CLT version is >= 15.
@@ -50,13 +44,11 @@ function _is_xcode_clt_and_is_gte_xcode_15()
5044 str = strip (get (ENV , " JULIA_PACKAGECOMPILER_XCODE_CLT_MAJOR_VERSION" , " " ))
5145 ver_int = tryparse (Int, str)
5246 (ver_int isa Int) && return ver_int
53- if _is_xcode_clt ()
54- b = _is_gte_xcode_15 ()
55- if isnothing (b)
56- @warn " Could not determine the version of the Command Line Tools, assuming less than or equal to 14"
57- end
58- return b
47+
48+ (; b, ver) = _is_xcode_clt ()
49+ if b
50+ return ver >= v " 15"
5951 else
60- false
52+ return false
6153 end
6254end
0 commit comments