5 from __future__
import print_function
14 script_dir = os.path.dirname(os.path.realpath(__file__))
15 json_data_file = os.path.join(script_dir,
'win_toolchain.json')
19 """Sets the environment to build with the selected toolchain for |cpu|."""
20 with open(json_data_file,
'r')
as tempf:
21 toolchain_data = json.load(tempf)
22 sdk_dir = toolchain_data[
'win_sdk']
23 os.environ[
'WINDOWSSDKDIR'] = sdk_dir
24 os.environ[
'WDK_DIR'] = toolchain_data[
'wdk']
26 vs_runtime_dll_dirs = toolchain_data[
'runtime_dirs']
27 runtime_path = os.pathsep.join(vs_runtime_dll_dirs)
28 os.environ[
'PATH'] = runtime_path + os.pathsep + os.environ[
'PATH']
32 assert cpu
in (
'x86',
'x64',
'arm',
'arm64')
33 with open(os.path.join(sdk_dir,
'bin',
'SetEnv.%s.json' % cpu))
as f:
34 env = json.load(f)[
'env']
35 if env[
'VSINSTALLDIR'] == [[
"..",
"..\\"]]:
37 json_relative_dir = os.path.join(sdk_dir,
'bin')
40 json_relative_dir = toolchain_data[
'path']
42 entries = [os.path.join(*([json_relative_dir] + e))
for e
in env[k]]
45 sep = os.pathsep
if k ==
'PATH' else ';'
46 env[k] = sep.join(entries)
48 env[
'PATH'] = env[
'PATH'] + os.pathsep + os.environ[
'PATH']
50 for k, v
in env.items():
55 """Returns the path to depot_tools in $PATH."""
56 for path
in os.environ[
'PATH'].
split(os.pathsep):
57 if os.path.isfile(os.path.join(path,
'gclient.py')):
59 raise Exception(
"depot_tools not found!")
63 """Load a list of SHA1s corresponding to the toolchains that we want installed
67 return [
'f53e4598951162bad6330f7a167486c7ae5db1e5']
72 return [
'418b3076791776573a815eb298c8aa590307af63']
73 raise Exception(
'Unsupported VS version %s' % version)
77 """Requests an update of the toolchain to the specific hashes we have at
78 this revision. The update outputs a .json of the various configuration
79 information required to pass to vs_env.py which we use in
80 |SetEnvironmentForCPU()|.
83 get_toolchain_args = [
85 os.path.join(depot_tools_path,
87 'get_toolchain_if_necessary.py'),
88 '--output-json', json_data_file,
90 subprocess.check_call(get_toolchain_args)
95 if not sys.platform.startswith((
'win32',
'cygwin')):
100 if len(sys.argv) < 2
or sys.argv[1]
not in commands:
101 print(
'Expected one of: %s' %
', '.join(commands), file=sys.stderr)
103 return commands[sys.argv[1]](*sys.argv[2:])
106 if __name__ ==
'__main__':