• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"""
10Create an updated VS toolchain
11
12Before you can run this script, you need a collated VC toolchain + Windows SDK.
13To generate that, run depot_tools/win_toolchain/package_from_installed.py
14That script pulls all of the compiler and SDK bits from your locally installed
15version of Visual Studio. The comments in that script include instructions on
16which components need to be installed (C++, ARM64, etc...)
17
18That script produces a .zip file with a SHA filename. Unzip that file, then
19pass the unzipped directory as the src_dir to this script.
20"""
21
22
23from __future__ import print_function
24import argparse
25import os
26import shlex
27import shutil
28import subprocess
29import sys
30
31
32ENV_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.
37IGNORE_LIST = [
38  'WindowsMobile',
39  'App Certification Kit',
40  'Debuggers',
41  'Extension SDKs',
42  'DesignTime',
43  'AccChecker',
44]
45
46
47def 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
56def 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
66def 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.copytree(src_dir, target_dir, ignore=filter_toolchain_files)
81
82
83if __name__ == '__main__':
84  main()
85