1+ # Get the compiler command from `get_compiler_cmd()`, and run `cc --version`, and parse the
2+ # output to determine whether or not the compiler is an Xcode Clang.
3+ function _is_xcode_clt ()
4+ cmd = ` $(get_compiler_cmd ()) --version`
5+ @debug " _active_compiler_is_xcode_clt(): Attempting to run command" cmd
6+ output = " \n " * strip (read (ignorestatus (cmd), String)) * " \n "
7+ is_apple_clang = occursin (r" Apple clang version" , output)
8+ installed_dir_m = match (r" \n InstalledDir: ([\w\/ ]*?)\n " , output)
9+ if isnothing (installed_dir_m)
10+ return false
11+ 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
30+ else
31+ major_version_str = split (m[1 ], ' .' )[1 ]
32+ 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
43+ end
44+
45+ # Return true iff the compiler is Xcode Clang AND the Xcode CLT version is >= 15.
46+ #
47+ # If the user sets the JULIA_PACKAGECOMPILER_XCODE_CLT_MAJOR_VERSION environment variable,
48+ # we skip our attempt at auto-detection, and instead use whatever value the user gave us.
49+ function _is_xcode_clt_and_is_gte_xcode_15 ()
50+ str = strip (get (ENV , " JULIA_PACKAGECOMPILER_XCODE_CLT_MAJOR_VERSION" , " " ))
51+ ver_int = tryparse (Int, str)
52+ (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
59+ else
60+ false
61+ end
62+ end
0 commit comments