OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Downloads and unpacks a toolchain for building on Windows. The contents are | 6 """Downloads and unpacks a toolchain for building on Windows. The contents are |
7 matched by sha1 which will be updated when the toolchain is updated. | 7 matched by sha1 which will be updated when the toolchain is updated. |
8 | 8 |
9 Having a toolchain script in depot_tools means that it's not versioned | 9 Having a toolchain script in depot_tools means that it's not versioned |
10 directly with the source code. That is, if the toolchain is upgraded, but | 10 directly with the source code. That is, if the toolchain is upgraded, but |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 return True | 121 return True |
122 return subprocess.call( | 122 return subprocess.call( |
123 ['git', '-c', 'core.askpass=true', 'remote', 'show', | 123 ['git', '-c', 'core.askpass=true', 'remote', 'show', |
124 'https://chrome-internal.googlesource.com/chrome/src-internal/'], | 124 'https://chrome-internal.googlesource.com/chrome/src-internal/'], |
125 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0 | 125 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0 |
126 | 126 |
127 | 127 |
128 def LooksLikeGoogler(): | 128 def LooksLikeGoogler(): |
129 """Checks for a USERDOMAIN environment variable of 'GOOGLE', which | 129 """Checks for a USERDOMAIN environment variable of 'GOOGLE', which |
130 probably implies the current user is a Googler.""" | 130 probably implies the current user is a Googler.""" |
131 return os.environ.get('USERDOMAIN').upper() == 'GOOGLE' | 131 return os.environ.get('USERDOMAIN', '').upper() == 'GOOGLE' |
132 | 132 |
133 | 133 |
134 def CanAccessToolchainBucket(): | 134 def CanAccessToolchainBucket(): |
135 """Checks whether the user has access to gs://chrome-wintoolchain/.""" | 135 """Checks whether the user has access to gs://chrome-wintoolchain/.""" |
136 gsutil = download_from_google_storage.Gsutil( | 136 gsutil = download_from_google_storage.Gsutil( |
137 download_from_google_storage.GSUTIL_DEFAULT_PATH, boto_path=None) | 137 download_from_google_storage.GSUTIL_DEFAULT_PATH, boto_path=None) |
138 code, _, _ = gsutil.check_call('ls', 'gs://chrome-wintoolchain/') | 138 code, _, _ = gsutil.check_call('ls', 'gs://chrome-wintoolchain/') |
139 return code == 0 | 139 return code == 0 |
140 | 140 |
141 | 141 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 assert os.path.basename(filename) == filename | 183 assert os.path.basename(filename) == filename |
184 target_path = os.path.join(temp_dir, filename) | 184 target_path = os.path.join(temp_dir, filename) |
185 gsutil = download_from_google_storage.Gsutil( | 185 gsutil = download_from_google_storage.Gsutil( |
186 download_from_google_storage.GSUTIL_DEFAULT_PATH, boto_path=None) | 186 download_from_google_storage.GSUTIL_DEFAULT_PATH, boto_path=None) |
187 code = gsutil.call('cp', 'gs://chrome-wintoolchain/' + filename, target_path) | 187 code = gsutil.call('cp', 'gs://chrome-wintoolchain/' + filename, target_path) |
188 if code != 0: | 188 if code != 0: |
189 sys.exit('gsutil failed') | 189 sys.exit('gsutil failed') |
190 return temp_dir, target_path | 190 return temp_dir, target_path |
191 | 191 |
192 | 192 |
193 def RmDir(path): | |
194 """Deletes path and all the files it contains.""" | |
195 if sys.platform != 'win32': | |
196 shutil.rmtree(path, ignore_errors=True) | |
197 else: | |
198 # shutil.rmtree() doesn't delete read-only files on Windows. | |
199 subprocess.check_call('rmdir /s/q "%s"' % path, shell=True) | |
200 | |
201 | |
193 def DoTreeMirror(target_dir, tree_sha1): | 202 def DoTreeMirror(target_dir, tree_sha1): |
194 """In order to save temporary space on bots that do not have enough space to | 203 """In order to save temporary space on bots that do not have enough space to |
195 download ISOs, unpack them, and copy to the target location, the whole tree | 204 download ISOs, unpack them, and copy to the target location, the whole tree |
196 is uploaded as a zip to internal storage, and then mirrored here.""" | 205 is uploaded as a zip to internal storage, and then mirrored here.""" |
197 temp_dir, local_zip = DownloadUsingGsutil(tree_sha1 + '.zip') | 206 temp_dir, local_zip = DownloadUsingGsutil(tree_sha1 + '.zip') |
198 sys.stdout.write('Extracting %s...\n' % local_zip) | 207 sys.stdout.write('Extracting %s...\n' % local_zip) |
199 sys.stdout.flush() | 208 sys.stdout.flush() |
200 with zipfile.ZipFile(local_zip, 'r', zipfile.ZIP_DEFLATED, True) as zf: | 209 with zipfile.ZipFile(local_zip, 'r', zipfile.ZIP_DEFLATED, True) as zf: |
201 zf.extractall(target_dir) | 210 zf.extractall(target_dir) |
202 if temp_dir: | 211 if temp_dir: |
203 subprocess.check_call('rmdir /s/q "%s"' % temp_dir, shell=True) | 212 RmDir(temp_dir) |
204 | 213 |
205 | 214 |
206 def main(): | 215 def main(): |
207 if not sys.platform.startswith(('cygwin', 'win32')): | 216 if not sys.platform.startswith(('cygwin', 'win32')): |
208 return 0 | 217 return 0 |
209 | 218 |
210 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 219 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
211 parser.add_option('--output-json', metavar='FILE', | 220 parser.add_option('--output-json', metavar='FILE', |
212 help='write information about toolchain to FILE') | 221 help='write information about toolchain to FILE') |
213 options, args = parser.parse_args() | 222 options, args = parser.parse_args() |
214 | 223 |
215 if sys.platform == 'cygwin': | 224 if sys.platform == 'cygwin': |
216 # This script requires Windows Python, so invoke with depot_tools' Python. | 225 # This script requires Windows Python, so invoke with depot_tools' Python. |
217 def winpath(path): | 226 def winpath(path): |
218 return subprocess.check_output(['cygpath', '-w', path]).strip() | 227 return subprocess.check_output(['cygpath', '-w', path]).strip() |
219 python = os.path.join(DEPOT_TOOLS_PATH, 'python.bat') | 228 python = os.path.join(DEPOT_TOOLS_PATH, 'python.bat') |
220 cmd = [python, winpath(__file__)] | 229 cmd = [python, winpath(__file__)] |
221 if options.output_json: | 230 if options.output_json: |
222 cmd.extend(['--output-json', winpath(options.output_json)]) | 231 cmd.extend(['--output-json', winpath(options.output_json)]) |
223 cmd.extend(args) | 232 cmd.extend(args) |
224 sys.exit(subprocess.call(cmd)) | 233 sys.exit(subprocess.call(cmd)) |
234 assert sys.platform != 'cygwin' | |
225 | 235 |
226 # We assume that the Pro hash is the first one. | 236 # We assume that the Pro hash is the first one. |
227 desired_hashes = args | 237 desired_hashes = args |
228 if len(desired_hashes) == 0: | 238 if len(desired_hashes) == 0: |
229 sys.exit('Desired hashes are required.') | 239 sys.exit('Desired hashes are required.') |
230 | 240 |
231 # Move to depot_tools\win_toolchain where we'll store our files, and where | 241 # Move to depot_tools\win_toolchain where we'll store our files, and where |
232 # the downloader script is. | 242 # the downloader script is. |
233 os.chdir(os.path.normpath(os.path.join(BASEDIR))) | 243 os.chdir(os.path.normpath(os.path.join(BASEDIR))) |
234 toolchain_dir = '.' | 244 toolchain_dir = '.' |
(...skipping 21 matching lines...) Expand all Loading... | |
256 if not should_use_gs: | 266 if not should_use_gs: |
257 print('Please follow the instructions at ' | 267 print('Please follow the instructions at ' |
258 'http://www.chromium.org/developers/how-tos/' | 268 'http://www.chromium.org/developers/how-tos/' |
259 'build-instructions-windows') | 269 'build-instructions-windows') |
260 return 1 | 270 return 1 |
261 print('Windows toolchain out of date or doesn\'t exist, updating (Pro)...') | 271 print('Windows toolchain out of date or doesn\'t exist, updating (Pro)...') |
262 print(' current_hash: %s' % current_hash) | 272 print(' current_hash: %s' % current_hash) |
263 print(' desired_hashes: %s' % ', '.join(desired_hashes)) | 273 print(' desired_hashes: %s' % ', '.join(desired_hashes)) |
264 sys.stdout.flush() | 274 sys.stdout.flush() |
265 DelayBeforeRemoving(target_dir) | 275 DelayBeforeRemoving(target_dir) |
266 # This stays resident and will make the rmdir below fail. | 276 # This stays resident and will make the rmdir below fail. |
scottmg
2015/06/23 20:37:46
maybe move this comment inside the if win32.
Nico
2015/06/23 21:01:17
Done.
| |
267 with open(os.devnull, 'wb') as nul: | 277 if sys.platform == 'win32': |
268 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe'], | 278 with open(os.devnull, 'wb') as nul: |
269 stdin=nul, stdout=nul, stderr=nul) | 279 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe'], |
280 stdin=nul, stdout=nul, stderr=nul) | |
270 if os.path.isdir(target_dir): | 281 if os.path.isdir(target_dir): |
271 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) | 282 RmDir(target_dir) |
272 | 283 |
273 DoTreeMirror(target_dir, desired_hashes[0]) | 284 DoTreeMirror(target_dir, desired_hashes[0]) |
274 | 285 |
275 got_new_toolchain = True | 286 got_new_toolchain = True |
276 | 287 |
277 win_sdk = os.path.join(abs_target_dir, 'win_sdk') | 288 win_sdk = os.path.join(abs_target_dir, 'win_sdk') |
278 try: | 289 try: |
279 with open(os.path.join(target_dir, 'VS_VERSION'), 'rb') as f: | 290 with open(os.path.join(target_dir, 'VS_VERSION'), 'rb') as f: |
280 vs_version = f.read().strip() | 291 vs_version = f.read().strip() |
281 except IOError: | 292 except IOError: |
(...skipping 29 matching lines...) Expand all Loading... | |
311 | 322 |
312 if options.output_json: | 323 if options.output_json: |
313 shutil.copyfile(os.path.join(target_dir, '..', 'data.json'), | 324 shutil.copyfile(os.path.join(target_dir, '..', 'data.json'), |
314 options.output_json) | 325 options.output_json) |
315 | 326 |
316 return 0 | 327 return 0 |
317 | 328 |
318 | 329 |
319 if __name__ == '__main__': | 330 if __name__ == '__main__': |
320 sys.exit(main()) | 331 sys.exit(main()) |
OLD | NEW |