vs_toolchain.py
Go to the documentation of this file.
1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 
5 from __future__ import print_function
6 
7 import json
8 import os
9 import os.path
10 import subprocess
11 import sys
12 
13 
14 script_dir = os.path.dirname(os.path.realpath(__file__))
15 json_data_file = os.path.join(script_dir, 'win_toolchain.json')
16 
17 
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']
25  # Include the VS runtime in the PATH in case it's not machine-installed.
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']
29 
30  # Set up the architecture-specific environment from the SetEnv files. See
31  # _LoadToolchainEnv() from setup_toolchain.py in Chromium.
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'] == [["..", "..\\"]]:
36  # Old-style paths were relative to the win_sdk\bin directory.
37  json_relative_dir = os.path.join(sdk_dir, 'bin')
38  else:
39  # New-style paths are relative to the toolchain directory.
40  json_relative_dir = toolchain_data['path']
41  for k in env:
42  entries = [os.path.join(*([json_relative_dir] + e)) for e in env[k]]
43  # clang-cl wants INCLUDE to be ;-separated even on non-Windows,
44  # lld-link wants LIB to be ;-separated even on non-Windows. Path gets :.
45  sep = os.pathsep if k == 'PATH' else ';'
46  env[k] = sep.join(entries)
47  # PATH is a bit of a special case, it's in addition to the current PATH.
48  env['PATH'] = env['PATH'] + os.pathsep + os.environ['PATH']
49 
50  for k, v in env.items():
51  os.environ[k] = v
52 
53 
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')):
58  return path
59  raise Exception("depot_tools not found!")
60 
61 
63  """Load a list of SHA1s corresponding to the toolchains that we want installed
64  to build with."""
65  if version == '2015':
66  # Update 3 final with 10.0.15063.468 SDK and no vctip.exe.
67  return ['f53e4598951162bad6330f7a167486c7ae5db1e5']
68  if version == '2017':
69  # VS 2017 Update 9 (15.9.12) with 10.0.18362 SDK, 10.0.17763 version of
70  # Debuggers, and 10.0.17134 version of d3dcompiler_47.dll, with ARM64
71  # libraries.
72  return ['418b3076791776573a815eb298c8aa590307af63']
73  raise Exception('Unsupported VS version %s' % version)
74 
75 
76 def Update(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()|.
81  """
82  depot_tools_path = FindDepotTools()
83  get_toolchain_args = [
84  sys.executable,
85  os.path.join(depot_tools_path,
86  'win_toolchain',
87  'get_toolchain_if_necessary.py'),
88  '--output-json', json_data_file,
89  ] + _GetDesiredVsToolchainHashes(version)
90  subprocess.check_call(get_toolchain_args)
91  return 0
92 
93 
94 def main():
95  if not sys.platform.startswith(('win32', 'cygwin')):
96  return 0
97  commands = {
98  'update': Update,
99  }
100  if len(sys.argv) < 2 or sys.argv[1] not in commands:
101  print('Expected one of: %s' % ', '.join(commands), file=sys.stderr)
102  return 1
103  return commands[sys.argv[1]](*sys.argv[2:])
104 
105 
106 if __name__ == '__main__':
107  sys.exit(main())
vs_toolchain._GetDesiredVsToolchainHashes
def _GetDesiredVsToolchainHashes(version)
Definition: vs_toolchain.py:62
vs_toolchain.FindDepotTools
def FindDepotTools()
Definition: vs_toolchain.py:54
vs_toolchain.Update
def Update(version)
Definition: vs_toolchain.py:76
vs_toolchain.main
def main()
Definition: vs_toolchain.py:94
main
Definition: main.py:1
vs_toolchain.SetEnvironmentForCPU
def SetEnvironmentForCPU(cpu)
Definition: vs_toolchain.py:18
open
#define open
Definition: test-fs.c:46
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
split
static void split(const char *s, char ***ss, size_t *ns)
Definition: debug/trace.cc:111


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:52