240 if len(sys.argv) != 7:
241 print(
'Usage setup_toolchain.py '
242 '<visual studio path> <win sdk path> '
243 '<runtime dirs> <target_os> <target_cpu> '
244 '<environment block name|none>')
245 sys.exit(2)
246
247
248
249
250 toolchain_root = sys.argv[1]
251 win_sdk_path = sys.argv[2]
252
253 runtime_dirs = sys.argv[3]
254 target_os = sys.argv[4]
255 target_cpu = sys.argv[5]
256 environment_block_name = sys.argv[6]
257 if (environment_block_name == 'none'):
258 environment_block_name = ''
259
260 if (target_os == 'winuwp'):
261 target_store = True
262 else:
263 target_store = False
264
265 cpus = ('x86', 'x64', 'arm', 'arm64')
266 assert target_cpu in cpus
267 vc_bin_dir = ''
268 include = ''
269 lib = ''
270
271
272
273
274 def relflag(s):
275 try:
276 return os.path.relpath(s).replace('\\', '/')
277 except ValueError:
278 return s
279
280 def q(s):
281 return s if re.match(r'^[a-zA-Z0-9._/\\:-]*$', s) else '"' + s + '"'
282
283 for cpu in cpus:
284 if cpu == target_cpu:
285
286 env = _LoadToolchainEnv(cpu, toolchain_root, win_sdk_path, target_store)
287 env['PATH'] = runtime_dirs + os.pathsep + env['PATH']
288
290
291
292
293 include = [p.replace('"', r'\"') for p in env['INCLUDE'].split(';') if p]
294 include = list(
map(relflag, include))
295
296 lib = [p.replace('"', r'\"') for p in env['LIB'].split(';') if p]
297 lib = list(
map(relflag, lib))
298
299 include_I = ['/I' + i for i in include]
300 include_imsvc = ['-imsvc' + i for i in include]
301 libpath_flags = ['-libpath:' + i for i in lib]
302
303 if (environment_block_name != ''):
304 env_block = _FormatAsEnvironmentBlock(env)
305 with open(environment_block_name, 'w', encoding='utf8') as f:
306 f.write(env_block)
307
308 def ListToArgString(x):
310
311 def ListToArgList(x):
312 return f'[{", ".join(gn_helpers.ToGNString(i) for i in x)}]'
313
315 assert include_I
316 print(f
'include_flags_I = {ListToArgString(include_I)}')
317 print(f
'include_flags_I_list = {ListToArgList(include_I)}')
318 assert include_imsvc
319 if bool(
int(os.environ.get(
'DEPOT_TOOLS_WIN_TOOLCHAIN', 1)))
and win_sdk_path:
320 flags = ['/winsysroot' + relflag(toolchain_root)]
321 print(f
'include_flags_imsvc = {ListToArgString(flags)}')
322 print(f
'include_flags_imsvc_list = {ListToArgList(flags)}')
323 else:
324 print(f
'include_flags_imsvc = {ListToArgString(include_imsvc)}')
325 print(f
'include_flags_imsvc_list = {ListToArgList(include_imsvc)}')
327 assert libpath_flags
328 print(f
'libpath_flags = {ListToArgString(libpath_flags)}')
329 print(f
'libpath_flags_list = {ListToArgList(libpath_flags)}')
330 if bool(
int(os.environ.get(
'DEPOT_TOOLS_WIN_TOOLCHAIN', 1)))
and win_sdk_path:
331 flags = ['/winsysroot:' + relflag(toolchain_root)]
332 print(f
'libpath_lldlink_flags = {ListToArgString(flags)}')
333 print(f
'libpath_lldlink_flags_list = {ListToArgList(flags)}')
334 else:
335 print(f
'libpath_lldlink_flags = {ListToArgString(libpath_flags)}')
336 print(f
'libpath_lldlink_flags_list = {ListToArgList(libpath_flags)}')
337
338
def ToGNString(value, allow_dicts=True)
def print(*args, **kwargs)
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>