Debian Codegraph @

infra/bots/assets/win_toolchain/create.py

raw
1 #!/usr/bin/env python
2 #
3 # Copyright 2016 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8
9 """
10 Create an updated VS toolchain
11
12 Before you can run this script, you need a collated VC toolchain + Windows SDK.
13 To generate that, run depot_tools/win_toolchain/package_from_installed.py
14 That script pulls all of the compiler and SDK bits from your locally installed
15 version of Visual Studio. The comments in that script include instructions on
16 which components need to be installed (C++, ARM64, etc...)
17
18 That script produces a .zip file with a SHA filename. Unzip that file, then
19 pass the unzipped directory as the src_dir to this script.
20 """
21
22
23 from __future__ import print_function
24 import argparse
25 import os
26 import shlex
27 import shutil
28 import subprocess
29 import sys
30
31
32 ENV_VAR = 'WIN_TOOLCHAIN_SRC_DIR'
33
34
35 # By default the toolchain includes a bunch of unnecessary stuff with long path
36 # names. Trim out directories with these names.
37 IGNORE_LIST = [
38 'WindowsMobile',
39 'App Certification Kit',
40 'Debuggers',
41 'Extension SDKs',
42 'DesignTime',
43 'AccChecker',
44 ]
45
46
47 def getenv(key):
48 val = os.environ.get(key)
49 if not val:
50 print(('Environment variable %s not set; you should run this via '
51 'create_and_upload.py.' % key), file=sys.stderr)
52 sys.exit(1)
53 return val
54
55
56 def filter_toolchain_files(dirname, files):
57 """Callback for shutil.copytree. Return lists of files to skip."""
58 split = dirname.split(os.path.sep)
59 for ign in IGNORE_LIST:
60 if ign in split:
61 print('Ignoring dir %s' % dirname)
62 return files
63 return []
64
65
66 def main():
67 if sys.platform != 'win32':
68 print('This script only runs on Windows.', file=sys.stderr)
69 sys.exit(1)
70
71 parser = argparse.ArgumentParser()
72 parser.add_argument('--target_dir', '-t', required=True)
73 args = parser.parse_args()
74
75 # Obtain src_dir from create_and_upload via an environment variable, since
76 # this script is called via `sk` and not directly.
77 src_dir = getenv(ENV_VAR)
78
79 target_dir = os.path.abspath(args.target_dir)
80 shutil.rmtree(target_dir)
81 shutil.copytree(src_dir, target_dir, ignore=filter_toolchain_files)
82
83
84 if __name__ == '__main__':
85 main()