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 14 matching lines...) Expand all Loading... | |
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 | 29 import ctypes.wintypes |
30 import hashlib | 30 import hashlib |
31 import json | 31 import json |
32 import os | 32 import os |
33 import subprocess | 33 import subprocess |
34 import sys | 34 import sys |
35 import time | |
35 | 36 |
36 | 37 |
37 BASEDIR = os.path.dirname(os.path.abspath(__file__)) | 38 BASEDIR = os.path.dirname(os.path.abspath(__file__)) |
38 | 39 |
39 | 40 |
40 GetFileAttributes = ctypes.windll.kernel32.GetFileAttributesW | 41 GetFileAttributes = ctypes.windll.kernel32.GetFileAttributesW |
41 GetFileAttributes.argtypes = (ctypes.wintypes.LPWSTR,) | 42 GetFileAttributes.argtypes = (ctypes.wintypes.LPWSTR,) |
42 GetFileAttributes.restype = ctypes.wintypes.DWORD | 43 GetFileAttributes.restype = ctypes.wintypes.DWORD |
43 FILE_ATTRIBUTE_HIDDEN = 0x2 | 44 FILE_ATTRIBUTE_HIDDEN = 0x2 |
44 FILE_ATTRIBUTE_SYSTEM = 0x4 | 45 FILE_ATTRIBUTE_SYSTEM = 0x4 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 # If the current hash doesn't match what we want in the file, nuke and pave. | 152 # If the current hash doesn't match what we want in the file, nuke and pave. |
152 # Typically this script is only run when the .sha1 one file is updated, but | 153 # Typically this script is only run when the .sha1 one file is updated, but |
153 # directly calling "gclient runhooks" will also run it, so we cache | 154 # directly calling "gclient runhooks" will also run it, so we cache |
154 # based on timestamps to make that case fast. | 155 # based on timestamps to make that case fast. |
155 current_hash = CalculateHash(target_dir) | 156 current_hash = CalculateHash(target_dir) |
156 if current_hash not in desired_hashes: | 157 if current_hash not in desired_hashes: |
157 should_get_pro = (os.path.isfile(os.path.join(BASEDIR, '.vspro')) or | 158 should_get_pro = (os.path.isfile(os.path.join(BASEDIR, '.vspro')) or |
158 HaveSrcInternalAccess()) | 159 HaveSrcInternalAccess()) |
159 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % | 160 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % |
160 ('Pro' if should_get_pro else 'Express')) | 161 ('Pro' if should_get_pro else 'Express')) |
162 print ' current_hash', current_hash | |
163 print ' desired_hashes', desired_hashes | |
M-A Ruel
2014/02/13 02:46:46
print(' desired hashes: %s' % desired_hashes)
I
scottmg
2014/02/13 17:54:47
Done.
| |
164 # A small grace period before deleting the old directory and causing a new | |
165 # toolchain to be pulled. | |
166 if os.path.isdir(target_dir): | |
M-A Ruel
2014/02/13 02:46:46
if bool(int(os.environ.get('CHROME_HEADLESS', '0')
scottmg
2014/02/13 17:54:47
Done.
| |
167 for i in range(9, 0, -1): | |
168 sys.stdout.write( | |
169 '\rRemoving old toolchain in %ds... (Ctrl-C to cancel)' % i) | |
170 sys.stdout.flush() | |
171 time.sleep(1) | |
172 print | |
161 # This stays resident and will make the rmdir below fail. | 173 # This stays resident and will make the rmdir below fail. |
162 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe']) | 174 with open(os.devnull, 'w') as nul: |
M-A Ruel
2014/02/13 02:46:46
'wb'
You don't want non-binary on Windows...
scottmg
2014/02/13 17:54:47
Done.
| |
175 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe'], | |
176 stdin=nul, stdout=nul, stderr=nul) | |
163 if os.path.isdir(target_dir): | 177 if os.path.isdir(target_dir): |
164 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) | 178 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) |
165 args = [sys.executable, | 179 args = [sys.executable, |
166 'toolchain2013.py', | 180 'toolchain2013.py', |
167 '--targetdir', target_dir] | 181 '--targetdir', target_dir] |
168 if not should_get_pro: | 182 if not should_get_pro: |
169 args.append('--express') | 183 args.append('--express') |
170 subprocess.check_call(args) | 184 subprocess.check_call(args) |
171 current_hash = CalculateHash(target_dir) | 185 current_hash = CalculateHash(target_dir) |
172 if current_hash not in desired_hashes: | 186 if current_hash not in desired_hashes: |
173 print >> sys.stderr, ( | 187 print >> sys.stderr, ( |
174 'Got wrong hash after pulling a new toolchain. ' | 188 'Got wrong hash after pulling a new toolchain. ' |
175 'Wanted one of \'%s\', got \'%s\'.' % ( | 189 'Wanted one of \'%s\', got \'%s\'.' % ( |
176 desired_hashes, current_hash)) | 190 desired_hashes, current_hash)) |
177 return 1 | 191 return 1 |
178 SaveTimestampsAndHash(target_dir, current_hash) | 192 SaveTimestampsAndHash(target_dir, current_hash) |
179 | 193 |
180 return 0 | 194 return 0 |
181 | 195 |
182 | 196 |
183 if __name__ == '__main__': | 197 if __name__ == '__main__': |
184 sys.exit(main()) | 198 sys.exit(main()) |
OLD | NEW |