Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Side by Side Diff: build/toolchain/win/setup_toolchain.py

Issue 1556993002: [gn] Detect location of Visual Studio in the registry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review fixes. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | build/vs_toolchain.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 # 4 #
5 # Copies the given "win tool" (which the toolchain uses to wrap compiler 5 # Copies the given "win tool" (which the toolchain uses to wrap compiler
6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on 6 # invocations) and the environment blocks for the 32-bit and 64-bit builds on
7 # Windows to the build directory. 7 # Windows to the build directory.
8 # 8 #
9 # The arguments are the visual studio install location and the location of the 9 # The arguments are the visual studio install location and the location of the
10 # win tool. The script assumes that the root build directory is the current dir 10 # win tool. The script assumes that the root build directory is the current dir
11 # and the files will be written to the current directory. 11 # and the files will be written to the current directory.
12 12
13 import errno 13 import errno
14 import os 14 import os
15 import re 15 import re
16 import subprocess 16 import subprocess
17 import sys 17 import sys
18 18
19 SCRIPT_DIR = os.path.dirname(__file__)
19 20
20 def _ExtractImportantEnvironment(output_of_set): 21 def _ExtractImportantEnvironment(output_of_set):
21 """Extracts environment variables required for the toolchain to run from 22 """Extracts environment variables required for the toolchain to run from
22 a textual dump output by the cmd.exe 'set' command.""" 23 a textual dump output by the cmd.exe 'set' command."""
23 envvars_to_save = ( 24 envvars_to_save = (
24 'goma_.*', # TODO(scottmg): This is ugly, but needed for goma. 25 'goma_.*', # TODO(scottmg): This is ugly, but needed for goma.
25 'include', 26 'include',
26 'lib', 27 'lib',
27 'libpath', 28 'libpath',
28 'path', 29 'path',
(...skipping 19 matching lines...) Expand all
48 setting = os.path.dirname(sys.executable) + os.pathsep + setting 49 setting = os.path.dirname(sys.executable) + os.pathsep + setting
49 env[var.upper()] = setting 50 env[var.upper()] = setting
50 break 51 break
51 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): 52 for required in ('SYSTEMROOT', 'TEMP', 'TMP'):
52 if required not in env: 53 if required not in env:
53 raise Exception('Environment variable "%s" ' 54 raise Exception('Environment variable "%s" '
54 'required to be set to valid path' % required) 55 'required to be set to valid path' % required)
55 return env 56 return env
56 57
57 58
59 def _DetectVisualStudioPath():
60 """Return path to the GYP_MSVS_VERSION of Visual Studio.
61 """
62
63 # Use the code in build/vs_toolchain.py to avoid duplicating code.
64 chromium_dir = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..'))
65 sys.path.append(os.path.join(chromium_dir, 'build'))
66 import vs_toolchain
67 return vs_toolchain.DetectVisualStudioPath()
68
69
58 def _SetupScript(target_cpu, sdk_dir): 70 def _SetupScript(target_cpu, sdk_dir):
59 """Returns a command (with arguments) to be used to set up the 71 """Returns a command (with arguments) to be used to set up the
60 environment.""" 72 environment."""
61 # Check if we are running in the SDK command line environment and use 73 # Check if we are running in the SDK command line environment and use
62 # the setup script from the SDK if so. |target_cpu| should be either 74 # the setup script from the SDK if so. |target_cpu| should be either
63 # 'x86' or 'x64'. 75 # 'x86' or 'x64'.
64 assert target_cpu in ('x86', 'x64') 76 assert target_cpu in ('x86', 'x64')
65 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir: 77 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir:
66 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), 78 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')),
67 '/' + target_cpu] 79 '/' + target_cpu]
68 else: 80 else:
81 if 'GYP_MSVS_OVERRIDE_PATH' not in os.environ:
82 os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath()
69 # We only support x64-hosted tools. 83 # We only support x64-hosted tools.
70 # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual
71 # Studio install location from registry.
72 return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], 84 return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'],
73 'VC/vcvarsall.bat')), 85 'VC/vcvarsall.bat')),
74 'amd64_x86' if target_cpu == 'x86' else 'amd64'] 86 'amd64_x86' if target_cpu == 'x86' else 'amd64']
75 87
76 88
77 def _FormatAsEnvironmentBlock(envvar_dict): 89 def _FormatAsEnvironmentBlock(envvar_dict):
78 """Format as an 'environment block' directly suitable for CreateProcess. 90 """Format as an 'environment block' directly suitable for CreateProcess.
79 Briefly this is a list of key=value\0, terminated by an additional \0. See 91 Briefly this is a list of key=value\0, terminated by an additional \0. See
80 CreateProcess documentation for more details.""" 92 CreateProcess documentation for more details."""
81 block = '' 93 block = ''
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 env_block = _FormatAsEnvironmentBlock(env) 172 env_block = _FormatAsEnvironmentBlock(env)
161 with open('environment.winrt_' + cpu, 'wb') as f: 173 with open('environment.winrt_' + cpu, 'wb') as f:
162 f.write(env_block) 174 f.write(env_block)
163 175
164 assert vc_bin_dir 176 assert vc_bin_dir
165 print 'vc_bin_dir = "%s"' % vc_bin_dir 177 print 'vc_bin_dir = "%s"' % vc_bin_dir
166 178
167 179
168 if __name__ == '__main__': 180 if __name__ == '__main__':
169 main() 181 main()
OLDNEW
« no previous file with comments | « no previous file | build/vs_toolchain.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698