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

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

Issue 913373002: Update Chomium's build files to work w/ latest GN binaries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn_cpu_arch_changes
Patch Set: merge to #317214 Created 5 years, 10 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
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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 setting = os.path.dirname(sys.executable) + os.pathsep + setting 44 setting = os.path.dirname(sys.executable) + os.pathsep + setting
45 env[var.upper()] = setting 45 env[var.upper()] = setting
46 break 46 break
47 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): 47 for required in ('SYSTEMROOT', 'TEMP', 'TMP'):
48 if required not in env: 48 if required not in env:
49 raise Exception('Environment variable "%s" ' 49 raise Exception('Environment variable "%s" '
50 'required to be set to valid path' % required) 50 'required to be set to valid path' % required)
51 return env 51 return env
52 52
53 53
54 def _SetupScript(target_arch, sdk_dir): 54 def _SetupScript(target_cpu, sdk_dir):
55 """Returns a command (with arguments) to be used to set up the 55 """Returns a command (with arguments) to be used to set up the
56 environment.""" 56 environment."""
57 # Check if we are running in the SDK command line environment and use 57 # Check if we are running in the SDK command line environment and use
58 # the setup script from the SDK if so. |target_arch| should be either 58 # the setup script from the SDK if so. |target_cpu| should be either
59 # 'x86' or 'x64'. 59 # 'x86' or 'x64'.
60 assert target_arch in ('x86', 'x64') 60 assert target_cpu in ('x86', 'x64')
61 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir: 61 if bool(int(os.environ.get('DEPOT_TOOLS_WIN_TOOLCHAIN', 1))) and sdk_dir:
62 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')), 62 return [os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.Cmd')),
63 '/' + target_arch] 63 '/' + target_cpu]
64 else: 64 else:
65 # We only support x64-hosted tools. 65 # We only support x64-hosted tools.
66 # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual 66 # TODO(scottmg|dpranke): Non-depot_tools toolchain: need to get Visual
67 # Studio install location from registry. 67 # Studio install location from registry.
68 return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], 68 return [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'],
69 'VC/vcvarsall.bat')), 69 'VC/vcvarsall.bat')),
70 'amd64_x86' if target_arch == 'x86' else 'amd64'] 70 'amd64_x86' if target_cpu == 'x86' else 'amd64']
71 71
72 72
73 def _FormatAsEnvironmentBlock(envvar_dict): 73 def _FormatAsEnvironmentBlock(envvar_dict):
74 """Format as an 'environment block' directly suitable for CreateProcess. 74 """Format as an 'environment block' directly suitable for CreateProcess.
75 Briefly this is a list of key=value\0, terminated by an additional \0. See 75 Briefly this is a list of key=value\0, terminated by an additional \0. See
76 CreateProcess documentation for more details.""" 76 CreateProcess documentation for more details."""
77 block = '' 77 block = ''
78 nul = '\0' 78 nul = '\0'
79 for key, value in envvar_dict.iteritems(): 79 for key, value in envvar_dict.iteritems():
80 block += key + '=' + value + nul 80 block += key + '=' + value + nul
(...skipping 12 matching lines...) Expand all
93 with open("gyp-win-tool", 'w') as tool_file: 93 with open("gyp-win-tool", 'w') as tool_file:
94 tool_file.write(''.join([tool_source[0], 94 tool_file.write(''.join([tool_source[0],
95 '# Generated by setup_toolchain.py do not edit.\n'] 95 '# Generated by setup_toolchain.py do not edit.\n']
96 + tool_source[1:])) 96 + tool_source[1:]))
97 97
98 98
99 def main(): 99 def main():
100 if len(sys.argv) != 6: 100 if len(sys.argv) != 6:
101 print('Usage setup_toolchain.py ' 101 print('Usage setup_toolchain.py '
102 '<visual studio path> <win tool path> <win sdk path> ' 102 '<visual studio path> <win tool path> <win sdk path> '
103 '<runtime dirs> <cpu_arch>') 103 '<runtime dirs> <target_cpu>')
104 sys.exit(2) 104 sys.exit(2)
105 tool_source = sys.argv[2] 105 tool_source = sys.argv[2]
106 win_sdk_path = sys.argv[3] 106 win_sdk_path = sys.argv[3]
107 runtime_dirs = sys.argv[4] 107 runtime_dirs = sys.argv[4]
108 cpu_arch = sys.argv[5] 108 target_cpu = sys.argv[5]
109 109
110 _CopyTool(tool_source) 110 _CopyTool(tool_source)
111 111
112 archs = ('x86', 'x64') 112 cpus = ('x86', 'x64')
113 assert cpu_arch in archs 113 assert target_cpu in cpus
114 vc_bin_dir = '' 114 vc_bin_dir = ''
115 115
116 # TODO(scottmg|goma): Do we need an equivalent of 116 # TODO(scottmg|goma): Do we need an equivalent of
117 # ninja_use_custom_environment_files? 117 # ninja_use_custom_environment_files?
118 118
119 for arch in archs: 119 for cpu in cpus:
120 # Extract environment variables for subprocesses. 120 # Extract environment variables for subprocesses.
121 args = _SetupScript(arch, win_sdk_path) 121 args = _SetupScript(cpu, win_sdk_path)
122 args.extend(('&&', 'set')) 122 args.extend(('&&', 'set'))
123 popen = subprocess.Popen( 123 popen = subprocess.Popen(
124 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 124 args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
125 variables, _ = popen.communicate() 125 variables, _ = popen.communicate()
126 env = _ExtractImportantEnvironment(variables) 126 env = _ExtractImportantEnvironment(variables)
127 env['PATH'] = runtime_dirs + ';' + env['PATH'] 127 env['PATH'] = runtime_dirs + ';' + env['PATH']
128 128
129 if arch == cpu_arch: 129 if cpu == target_cpu:
130 for path in env['PATH'].split(os.pathsep): 130 for path in env['PATH'].split(os.pathsep):
131 if os.path.exists(os.path.join(path, 'cl.exe')): 131 if os.path.exists(os.path.join(path, 'cl.exe')):
132 vc_bin_dir = os.path.realpath(path) 132 vc_bin_dir = os.path.realpath(path)
133 break 133 break
134 134
135 # The Windows SDK include directories must be first. They both have a sal.h, 135 # The Windows SDK include directories must be first. They both have a sal.h,
136 # and the SDK one is newer and the SDK uses some newer features from it not 136 # and the SDK one is newer and the SDK uses some newer features from it not
137 # present in the Visual Studio one. 137 # present in the Visual Studio one.
138 138
139 if win_sdk_path: 139 if win_sdk_path:
140 additional_includes = ('{sdk_dir}\\Include\\shared;' + 140 additional_includes = ('{sdk_dir}\\Include\\shared;' +
141 '{sdk_dir}\\Include\\um;' + 141 '{sdk_dir}\\Include\\um;' +
142 '{sdk_dir}\\Include\\winrt;').format( 142 '{sdk_dir}\\Include\\winrt;').format(
143 sdk_dir=win_sdk_path) 143 sdk_dir=win_sdk_path)
144 env['INCLUDE'] = additional_includes + env['INCLUDE'] 144 env['INCLUDE'] = additional_includes + env['INCLUDE']
145 env_block = _FormatAsEnvironmentBlock(env) 145 env_block = _FormatAsEnvironmentBlock(env)
146 with open('environment.' + arch, 'wb') as f: 146 with open('environment.' + cpu, 'wb') as f:
147 f.write(env_block) 147 f.write(env_block)
148 148
149 assert vc_bin_dir 149 assert vc_bin_dir
150 print 'vc_bin_dir = "%s"' % vc_bin_dir 150 print 'vc_bin_dir = "%s"' % vc_bin_dir
151 151
152 152
153 if __name__ == '__main__': 153 if __name__ == '__main__':
154 main() 154 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698