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

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

Issue 1822633002: Make setup_toolchain.py run on non-Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 | no next file » | 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
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 if re.match(envvar + '=', line.lower()): 43 if re.match(envvar + '=', line.lower()):
44 var, setting = line.split('=', 1) 44 var, setting = line.split('=', 1)
45 if envvar == 'path': 45 if envvar == 'path':
46 # Our own rules (for running gyp-win-tool) and other actions in 46 # Our own rules (for running gyp-win-tool) and other actions in
47 # Chromium rely on python being in the path. Add the path to this 47 # Chromium rely on python being in the path. Add the path to this
48 # python here so that if it's not in the path when ninja is run 48 # python here so that if it's not in the path when ninja is run
49 # later, python will still be found. 49 # later, python will still be found.
50 setting = os.path.dirname(sys.executable) + os.pathsep + setting 50 setting = os.path.dirname(sys.executable) + os.pathsep + setting
51 env[var.upper()] = setting 51 env[var.upper()] = setting
52 break 52 break
53 for required in ('SYSTEMROOT', 'TEMP', 'TMP'): 53 if sys.platform in ('win32', 'cygwin'):
54 if required not in env: 54 for required in ('SYSTEMROOT', 'TEMP', 'TMP'):
55 raise Exception('Environment variable "%s" ' 55 if required not in env:
56 'required to be set to valid path' % required) 56 raise Exception('Environment variable "%s" '
57 'required to be set to valid path' % required)
57 return env 58 return env
58 59
59 60
60 def _DetectVisualStudioPath(): 61 def _DetectVisualStudioPath():
61 """Return path to the GYP_MSVS_VERSION of Visual Studio. 62 """Return path to the GYP_MSVS_VERSION of Visual Studio.
62 """ 63 """
63 64
64 # Use the code in build/vs_toolchain.py to avoid duplicating code. 65 # Use the code in build/vs_toolchain.py to avoid duplicating code.
65 chromium_dir = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..')) 66 chromium_dir = os.path.abspath(os.path.join(SCRIPT_DIR, '..', '..', '..'))
66 sys.path.append(os.path.join(chromium_dir, 'build')) 67 sys.path.append(os.path.join(chromium_dir, 'build'))
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 for k in os.environ: 102 for k in os.environ:
102 if k not in env: 103 if k not in env:
103 env[k] = os.environ[k] 104 env[k] = os.environ[k]
104 105
105 varlines = [] 106 varlines = []
106 for k in sorted(env.keys()): 107 for k in sorted(env.keys()):
107 varlines.append('%s=%s' % (str(k), str(env[k]))) 108 varlines.append('%s=%s' % (str(k), str(env[k])))
108 variables = '\n'.join(varlines) 109 variables = '\n'.join(varlines)
109 110
110 # Check that the json file contained the same environment as the .cmd file. 111 # Check that the json file contained the same environment as the .cmd file.
111 script = os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.cmd')) 112 if sys.platform in ('win32', 'cygwin'):
112 assert _ExtractImportantEnvironment(variables) == \ 113 script = os.path.normpath(os.path.join(sdk_dir, 'Bin/SetEnv.cmd'))
113 _ExtractImportantEnvironment(_LoadEnvFromBat([script, '/' + cpu])) 114 assert _ExtractImportantEnvironment(variables) == \
115 _ExtractImportantEnvironment(_LoadEnvFromBat([script, '/' + cpu]))
114 else: 116 else:
115 if 'GYP_MSVS_OVERRIDE_PATH' not in os.environ: 117 if 'GYP_MSVS_OVERRIDE_PATH' not in os.environ:
116 os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath() 118 os.environ['GYP_MSVS_OVERRIDE_PATH'] = _DetectVisualStudioPath()
117 # We only support x64-hosted tools. 119 # We only support x64-hosted tools.
118 args = [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'], 120 args = [os.path.normpath(os.path.join(os.environ['GYP_MSVS_OVERRIDE_PATH'],
119 'VC/vcvarsall.bat')), 121 'VC/vcvarsall.bat')),
120 'amd64_x86' if cpu == 'x86' else 'amd64'] 122 'amd64_x86' if cpu == 'x86' else 'amd64']
121 variables = _LoadEnvFromBat(args) 123 variables = _LoadEnvFromBat(args)
122 return _ExtractImportantEnvironment(variables) 124 return _ExtractImportantEnvironment(variables)
123 125
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 cpus = ('x86', 'x64') 166 cpus = ('x86', 'x64')
165 assert target_cpu in cpus 167 assert target_cpu in cpus
166 vc_bin_dir = '' 168 vc_bin_dir = ''
167 169
168 # TODO(scottmg|goma): Do we need an equivalent of 170 # TODO(scottmg|goma): Do we need an equivalent of
169 # ninja_use_custom_environment_files? 171 # ninja_use_custom_environment_files?
170 172
171 for cpu in cpus: 173 for cpu in cpus:
172 # Extract environment variables for subprocesses. 174 # Extract environment variables for subprocesses.
173 env = _LoadToolchainEnv(cpu, win_sdk_path) 175 env = _LoadToolchainEnv(cpu, win_sdk_path)
174 env['PATH'] = runtime_dirs + os.path.pathsep + env['PATH'] 176 env['PATH'] = runtime_dirs + os.pathsep + env['PATH']
175 177
176 if cpu == target_cpu: 178 if cpu == target_cpu:
177 for path in env['PATH'].split(os.pathsep): 179 for path in env['PATH'].split(os.pathsep):
178 if os.path.exists(os.path.join(path, 'cl.exe')): 180 if os.path.exists(os.path.join(path, 'cl.exe')):
179 vc_bin_dir = os.path.realpath(path) 181 vc_bin_dir = os.path.realpath(path)
180 break 182 break
181 183
182 # Add extra include directories here that need to be in front of the 184 # Add extra include directories here that need to be in front of the
183 # installed and packaged include directories. This may be needed in 185 # installed and packaged include directories. This may be needed in
184 # order to force a particular SDK version, such as to get VS 2013 to use 186 # order to force a particular SDK version, such as to get VS 2013 to use
185 # the Windows 10 SDK. Beware of making the INCLUDE variable excessively 187 # the Windows 10 SDK. Beware of making the INCLUDE variable excessively
186 # long and be sure to make corresponding changes to build\common.gypi. 188 # long and be sure to make corresponding changes to build\common.gypi.
187 # Not currently used. 189 # Not currently used.
188 #if win_sdk_path: 190 #if win_sdk_path:
scottmg 2016/03/21 17:30:14 I'm not sure why this is here, probably just nuke
Nico 2016/03/21 17:33:54 I asked here: https://codereview.chromium.org/1783
191 # # INCLUDE always uses ; separators, even on non-Windows.
189 # additional_includes = [ 192 # additional_includes = [
190 # os.path.join(win_sdk_path, 'Include', '10.0.10586.0', p) 193 # os.path.join(win_sdk_path, 'Include', '10.0.10586.0', p)
191 # for p in ['shared', 'um', 'winrt']] 194 # for p in ['shared', 'um', 'winrt']]
192 # additional_includes = os.path.pathsep.join(additional_includes) 195 # additional_includes = ';'.join(additional_includes)
193 # env['INCLUDE'] = additional_includes + os.path.pathsep + env['INCLUDE'] 196 # env['INCLUDE'] = additional_includes + ';' + env['INCLUDE']
194 env_block = _FormatAsEnvironmentBlock(env) 197 env_block = _FormatAsEnvironmentBlock(env)
195 with open('environment.' + cpu, 'wb') as f: 198 with open('environment.' + cpu, 'wb') as f:
196 f.write(env_block) 199 f.write(env_block)
197 200
198 # Create a store app version of the environment. 201 # Create a store app version of the environment.
199 if 'LIB' in env: 202 if 'LIB' in env:
200 env['LIB'] = env['LIB'] .replace(r'\VC\LIB', r'\VC\LIB\STORE') 203 env['LIB'] = env['LIB'] .replace(r'\VC\LIB', r'\VC\LIB\STORE')
201 if 'LIBPATH' in env: 204 if 'LIBPATH' in env:
202 env['LIBPATH'] = env['LIBPATH'].replace(r'\VC\LIB', r'\VC\LIB\STORE') 205 env['LIBPATH'] = env['LIBPATH'].replace(r'\VC\LIB', r'\VC\LIB\STORE')
203 env_block = _FormatAsEnvironmentBlock(env) 206 env_block = _FormatAsEnvironmentBlock(env)
204 with open('environment.winrt_' + cpu, 'wb') as f: 207 with open('environment.winrt_' + cpu, 'wb') as f:
205 f.write(env_block) 208 f.write(env_block)
206 209
207 assert vc_bin_dir 210 assert vc_bin_dir
208 print 'vc_bin_dir = "%s"' % vc_bin_dir 211 print 'vc_bin_dir = "%s"' % vc_bin_dir
209 212
210 213
211 if __name__ == '__main__': 214 if __name__ == '__main__':
212 main() 215 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698