forked from llvm/llvm-project
- Notifications
You must be signed in to change notification settings - Fork 339
/
Copy pathsysroot.py
executable file
·103 lines (84 loc) · 3.94 KB
/
sysroot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
"""Helps manage sysroots."""
importargparse
importos
importsubprocess
importsys
defmake_fake_sysroot(out_dir):
defcmdout(cmd):
returnsubprocess.check_output(cmd).decode(sys.stdout.encoding).strip()
ifsys.platform=='win32':
defmkjunction(dst, src):
subprocess.check_call(['mklink', '/j', dst, src], shell=True)
os.mkdir(out_dir)
p=os.getenv('ProgramFiles(x86)', 'C:\\Program Files (x86)')
winsdk=os.getenv('WindowsSdkDir')
ifnotwinsdk:
winsdk=os.path.join(p, 'Windows Kits', '10')
print('%WindowsSdkDir% not set. You might want to run this from')
print('a Visual Studio cmd prompt. Defaulting to', winsdk)
os.mkdir(os.path.join(out_dir, 'Windows Kits'))
mkjunction(os.path.join(out_dir, 'Windows Kits', '10'), winsdk)
vswhere=os.path.join(
p, 'Microsoft Visual Studio', 'Installer', 'vswhere')
vcid='Microsoft.VisualStudio.Component.VC.Tools.x86.x64'
vsinstalldir=cmdout(
[vswhere, '-latest', '-products', '*', '-requires', vcid,
'-property', 'installationPath'])
mkjunction(os.path.join(out_dir, 'VC'),
os.path.join(vsinstalldir, 'VC'))
# Not all MSVC versions ship the DIA SDK, so the junction destination
# might not exist. That's fine.
mkjunction(os.path.join(out_dir, 'DIA SDK'),
os.path.join(vsinstalldir, 'DIA SDK'))
elifsys.platform=='darwin':
# The SDKs used by default in compiler-rt/cmake/base-config-ix.cmake.
# COMPILER_RT_ENABLE_IOS defaults to on.
# COMPILER_RT_ENABLE_WATCHOS and COMPILER_RT_ENABLE_TV default to off.
# compiler-rt/cmake/config-ix.cmake sets DARWIN_EMBEDDED_PLATFORMS
# depending on these.
sdks= ['macosx', 'iphoneos', 'iphonesimulator']
os.mkdir(out_dir)
forsdkinsdks:
sdkpath=cmdout(['xcrun', '-sdk', sdk, '-show-sdk-path'])
# sdkpath is something like /.../SDKs/MacOSX11.1.sdk, which is a
# symlink to MacOSX.sdk in the same directory. Resolve the symlink,
# to make the symlink in out_dir less likely to break when the SDK
# is updated (which will bump the number on xcrun's output, but not
# on the symlink destination).
sdkpath=os.path.realpath(sdkpath)
os.symlink(sdkpath, os.path.join(out_dir, os.path.basename(sdkpath)))
else:
os.symlink('/', out_dir)
print('Done. Pass these flags to cmake:')
abs_out_dir=os.path.abspath(out_dir)
ifsys.platform=='win32':
# CMake doesn't like backslashes in commandline args.
abs_out_dir=abs_out_dir.replace(os.path.sep, '/')
print(' -DLLVM_WINSYSROOT='+abs_out_dir)
elifsys.platform=='darwin':
flags= [
'-DCMAKE_OSX_SYSROOT='+os.path.join(abs_out_dir, 'MacOSX.sdk'),
# For find_darwin_sdk_dir() in
# compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake
'-DDARWIN_macosx_CACHED_SYSROOT='+
os.path.join(abs_out_dir, 'MacOSX.sdk'),
'-DDARWIN_iphoneos_CACHED_SYSROOT='+
os.path.join(abs_out_dir, 'iPhoneOS.sdk'),
'-DDARWIN_iphonesimulator_CACHED_SYSROOT='+
os.path.join(abs_out_dir, 'iPhoneSimulator.sdk'),
]
print(' '+' '.join(flags))
else:
print(' -DCMAKE_SYSROOT='+abs_out_dir+' to cmake.')
defmain():
parser=argparse.ArgumentParser(description=__doc__)
subparsers=parser.add_subparsers(dest='command', required=True)
makefake=subparsers.add_parser('make-fake',
help='Create a sysroot that symlinks to local directories.')
makefake.add_argument('--out-dir', required=True)
args=parser.parse_args()
assertargs.command=='make-fake'
make_fake_sysroot(args.out_dir)
if__name__=='__main__':
main()