Skip to content

Commit 2778c29

Browse files
committed
Infer Xcode's SDK path dynamically
1 parent 937bc9c commit 2778c29

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

compile_database.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
re.X,
1818
)
1919

20+
XCODE_BASE_PATH = None
21+
22+
23+
def getXcodeBasePath():
24+
global XCODE_BASE_PATH
25+
if XCODE_BASE_PATH is None:
26+
XCODE_BASE_PATH = subprocess.check_output(
27+
["xcode-select", "-p"]
28+
).rstrip().decode('utf8')
29+
return XCODE_BASE_PATH
30+
2031

2132
def isProjectRoot(directory):
2233
return os.path.exists(os.path.join(directory, ".git"))
@@ -327,13 +338,13 @@ def InferFlagsForSwift(filename, compileFile, store):
327338
else:
328339
final_flags += [
329340
"-sdk",
330-
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/",
341+
os.path.join(getXcodeBasePath(), "Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"),
331342
]
332343
if not final_flags:
333344
final_flags = [
334345
filename,
335346
"-sdk",
336-
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/",
347+
os.path.join(getXcodeBasePath(), "Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"),
337348
]
338349

339350
return final_flags

0 commit comments

Comments
 (0)