Chromium Code Reviews| 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 |
| 11 you're trying to build an historical version of Chromium from before the | 11 you're trying to build an historical version of Chromium from before the |
| 12 toolchain upgrade, this will cause you to build with a newer toolchain than | 12 toolchain upgrade, this will cause you to build with a newer toolchain than |
| 13 was available when that code was committed. This is done for a two main | 13 was available when that code was committed. This is done for a two main |
| 14 reasons: 1) it would likely be annoying to have the up-to-date toolchain | 14 reasons: 1) it would likely be annoying to have the up-to-date toolchain |
| 15 removed and replaced by one without a service pack applied); 2) it would | 15 removed and replaced by one without a service pack applied); 2) it would |
| 16 require maintaining scripts that can build older not-up-to-date revisions of | 16 require maintaining scripts that can build older not-up-to-date revisions of |
| 17 the toolchain. This is likely to be a poorly tested code path that probably | 17 the toolchain. This is likely to be a poorly tested code path that probably |
| 18 won't be properly maintained. See http://crbug.com/323300. | 18 won't be properly maintained. See http://crbug.com/323300. |
| 19 | 19 |
| 20 This does not extend to major versions of the toolchain however, on the | 20 This does not extend to major versions of the toolchain however, on the |
| 21 assumption that there are more likely to be source incompatibilities between | 21 assumption that there are more likely to be source incompatibilities between |
| 22 major revisions. This script calls a subscript (currently, toolchain2013.py) | 22 major revisions. This script calls a subscript (currently, toolchain2013.py) |
| 23 to do the main work. It is expected that toolchain2013.py will always be able | 23 to do the main work. It is expected that toolchain2013.py will always be able |
| 24 to acquire/build the most current revision of a VS2013-based toolchain. In the | 24 to acquire/build the most current revision of a VS2013-based toolchain. In the |
| 25 future when a hypothetical VS2015 is released, the 2013 script will be | 25 future when a hypothetical VS2015 is released, the 2013 script will be |
| 26 maintained, and a new 2015 script would be added. | 26 maintained, and a new 2015 script would be added. |
| 27 """ | 27 """ |
| 28 | 28 |
| 29 import ctypes.wintypes | |
| 30 import hashlib | 29 import hashlib |
| 31 import json | 30 import json |
| 32 import optparse | 31 import optparse |
| 33 import os | 32 import os |
| 34 import shutil | 33 import shutil |
| 35 import subprocess | 34 import subprocess |
| 36 import sys | 35 import sys |
| 37 import time | 36 import time |
| 38 | 37 |
| 39 | 38 |
| 40 BASEDIR = os.path.dirname(os.path.abspath(__file__)) | 39 BASEDIR = os.path.dirname(os.path.abspath(__file__)) |
| 41 sys.path.append(os.path.join(BASEDIR, '..')) | 40 DEPOT_TOOLS_PATH = os.path.join(BASEDIR, '..') |
| 41 sys.path.append(DEPOT_TOOLS_PATH) | |
| 42 import download_from_google_storage | 42 import download_from_google_storage |
| 43 | 43 |
| 44 | 44 if sys.platform != 'cygwin': |
| 45 GetFileAttributes = ctypes.windll.kernel32.GetFileAttributesW | 45 import ctypes.wintypes |
| 46 GetFileAttributes.argtypes = (ctypes.wintypes.LPWSTR,) | 46 GetFileAttributes = ctypes.windll.kernel32.GetFileAttributesW |
| 47 GetFileAttributes.restype = ctypes.wintypes.DWORD | 47 GetFileAttributes.argtypes = (ctypes.wintypes.LPWSTR,) |
| 48 FILE_ATTRIBUTE_HIDDEN = 0x2 | 48 GetFileAttributes.restype = ctypes.wintypes.DWORD |
| 49 FILE_ATTRIBUTE_SYSTEM = 0x4 | 49 FILE_ATTRIBUTE_HIDDEN = 0x2 |
| 50 FILE_ATTRIBUTE_SYSTEM = 0x4 | |
| 50 | 51 |
| 51 | 52 |
| 52 def IsHidden(file_path): | 53 def IsHidden(file_path): |
| 53 """Returns whether the given |file_path| has the 'system' or 'hidden' | 54 """Returns whether the given |file_path| has the 'system' or 'hidden' |
| 54 attribute set.""" | 55 attribute set.""" |
| 55 p = GetFileAttributes(file_path) | 56 p = GetFileAttributes(file_path) |
| 56 assert p != 0xffffffff | 57 assert p != 0xffffffff |
| 57 return bool(p & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) | 58 return bool(p & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) |
| 58 | 59 |
| 59 | 60 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 | 188 |
| 188 def main(): | 189 def main(): |
| 189 if not sys.platform.startswith(('cygwin', 'win32')): | 190 if not sys.platform.startswith(('cygwin', 'win32')): |
| 190 return 0 | 191 return 0 |
| 191 | 192 |
| 192 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 193 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
| 193 parser.add_option('--output-json', metavar='FILE', | 194 parser.add_option('--output-json', metavar='FILE', |
| 194 help='write information about toolchain to FILE') | 195 help='write information about toolchain to FILE') |
| 195 options, args = parser.parse_args() | 196 options, args = parser.parse_args() |
| 196 | 197 |
| 198 if sys.platform == 'cygwin': | |
| 199 # This script requires Windows Python, so invoke with depot_tools' Python. | |
| 200 def winpath(path): | |
| 201 return subprocess.check_output(['cygpath', '-w', path]).strip() | |
| 202 python = os.path.join(DEPOT_TOOLS_PATH, 'python.bat') | |
| 203 subprocess_command = [python, winpath(__file__)] | |
|
iannucci
2014/04/11 11:01:33
nit: `cmd` would be a fine name for this variable,
Mike Wittman
2014/04/11 17:58:04
Done.
| |
| 204 if options.output_json: | |
| 205 subprocess_command.extend(['--output-json', winpath(options.output_json)]) | |
| 206 subprocess_command.extend(args) | |
| 207 p = subprocess.Popen(subprocess_command, shell=False) | |
| 208 p.communicate() | |
| 209 sys.exit(p.returncode) | |
|
iannucci
2014/04/11 11:01:33
this should be
sys.exit(subprocess.call(subproces
Mike Wittman
2014/04/11 17:58:04
Done.
| |
| 210 | |
| 197 # We assume that the Pro hash is the first one. | 211 # We assume that the Pro hash is the first one. |
| 198 desired_hashes = args | 212 desired_hashes = args |
| 199 if len(desired_hashes) == 0: | 213 if len(desired_hashes) == 0: |
| 200 sys.exit('Desired hashes are required.') | 214 sys.exit('Desired hashes are required.') |
| 201 | 215 |
| 202 # Move to depot_tools\win_toolchain where we'll store our files, and where | 216 # Move to depot_tools\win_toolchain where we'll store our files, and where |
| 203 # the downloader script is. | 217 # the downloader script is. |
| 204 os.chdir(os.path.normpath(os.path.join(BASEDIR))) | 218 os.chdir(os.path.normpath(os.path.join(BASEDIR))) |
| 205 toolchain_dir = '.' | 219 toolchain_dir = '.' |
| 206 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) | 220 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 | 262 |
| 249 if options.output_json: | 263 if options.output_json: |
| 250 shutil.copyfile(os.path.join(target_dir, '..', 'data.json'), | 264 shutil.copyfile(os.path.join(target_dir, '..', 'data.json'), |
| 251 options.output_json) | 265 options.output_json) |
| 252 | 266 |
| 253 return 0 | 267 return 0 |
| 254 | 268 |
| 255 | 269 |
| 256 if __name__ == '__main__': | 270 if __name__ == '__main__': |
| 257 sys.exit(main()) | 271 sys.exit(main()) |
| OLD | NEW |