Skip to content

Commit 5d1012c

Browse files
authored
Merge pull request #96 from jamestut/xcode-path-infer
Infer Xcode's SDK path dynamically
2 parents 5986b64 + 049b4b8 commit 5d1012c

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

compile_database.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
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+
try:
27+
XCODE_BASE_PATH = subprocess.check_output(
28+
["xcode-select", "-p"]
29+
).rstrip().decode('utf8')
30+
except subprocess.CalledProcessError:
31+
XCODE_BASE_PATH = '/Applications/Xcode.app/Contents/Developer'
32+
return XCODE_BASE_PATH
33+
2034

2135
def isProjectRoot(directory):
2236
return os.path.exists(os.path.join(directory, ".git"))
@@ -362,13 +376,13 @@ def InferFlagsForSwift(filename, compileFile, store):
362376
else:
363377
final_flags += [
364378
"-sdk",
365-
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/",
379+
os.path.join(getXcodeBasePath(), "Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"),
366380
]
367381
if not final_flags:
368382
final_flags = [
369383
filename,
370384
"-sdk",
371-
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/",
385+
os.path.join(getXcodeBasePath(), "Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/"),
372386
]
373387

374388
return final_flags

0 commit comments

Comments
 (0)