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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 ['svn', 'ls', | 122 ['svn', 'ls', |
122 'svn://svn.chromium.org/chrome-internal/trunk/src-internal/'], | 123 'svn://svn.chromium.org/chrome-internal/trunk/src-internal/'], |
123 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0: | 124 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0: |
124 return True | 125 return True |
125 return subprocess.call( | 126 return subprocess.call( |
126 ['git', 'remote', 'show', | 127 ['git', 'remote', 'show', |
127 'https://chrome-internal.googlesource.com/chrome/src-internal/'], | 128 'https://chrome-internal.googlesource.com/chrome/src-internal/'], |
128 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0 | 129 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0 |
129 | 130 |
130 | 131 |
| 132 def DelayBeforeRemoving(target_dir): |
| 133 """A grace period before deleting the out of date toolchain directory.""" |
| 134 if (os.path.isdir(target_dir) and |
| 135 not bool(int(os.environ.get('CHROME_HEADLESS', '0')))): |
| 136 for i in range(9, 0, -1): |
| 137 sys.stdout.write( |
| 138 '\rRemoving old toolchain in %ds... (Ctrl-C to cancel)' % i) |
| 139 sys.stdout.flush() |
| 140 time.sleep(1) |
| 141 print |
| 142 |
| 143 |
131 def main(): | 144 def main(): |
132 if not sys.platform.startswith(('cygwin', 'win32')): | 145 if not sys.platform.startswith(('cygwin', 'win32')): |
133 return 0 | 146 return 0 |
134 | 147 |
135 if len(sys.argv) != 1: | 148 if len(sys.argv) != 1: |
136 print >> sys.stderr, 'Unexpected arguments.' | 149 print >> sys.stderr, 'Unexpected arguments.' |
137 return 1 | 150 return 1 |
138 | 151 |
139 # Move to depot_tools\win_toolchain where we'll store our files, and where | 152 # Move to depot_tools\win_toolchain where we'll store our files, and where |
140 # the downloader script is. | 153 # the downloader script is. |
(...skipping 10 matching lines...) Expand all Loading... |
151 # If the current hash doesn't match what we want in the file, nuke and pave. | 164 # 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 | 165 # 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 | 166 # directly calling "gclient runhooks" will also run it, so we cache |
154 # based on timestamps to make that case fast. | 167 # based on timestamps to make that case fast. |
155 current_hash = CalculateHash(target_dir) | 168 current_hash = CalculateHash(target_dir) |
156 if current_hash not in desired_hashes: | 169 if current_hash not in desired_hashes: |
157 should_get_pro = (os.path.isfile(os.path.join(BASEDIR, '.vspro')) or | 170 should_get_pro = (os.path.isfile(os.path.join(BASEDIR, '.vspro')) or |
158 HaveSrcInternalAccess()) | 171 HaveSrcInternalAccess()) |
159 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % | 172 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % |
160 ('Pro' if should_get_pro else 'Express')) | 173 ('Pro' if should_get_pro else 'Express')) |
| 174 print(' current_hash: %s' % current_hash) |
| 175 print(' desired_hashes: %s' % desired_hashes) |
| 176 DelayBeforeRemoving(target_dir) |
161 # This stays resident and will make the rmdir below fail. | 177 # This stays resident and will make the rmdir below fail. |
162 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe']) | 178 with open(os.devnull, 'wb') as nul: |
| 179 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe'], |
| 180 stdin=nul, stdout=nul, stderr=nul) |
163 if os.path.isdir(target_dir): | 181 if os.path.isdir(target_dir): |
164 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) | 182 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) |
165 args = [sys.executable, | 183 args = [sys.executable, |
166 'toolchain2013.py', | 184 'toolchain2013.py', |
167 '--targetdir', target_dir] | 185 '--targetdir', target_dir] |
168 if not should_get_pro: | 186 if not should_get_pro: |
169 args.append('--express') | 187 args.append('--express') |
170 subprocess.check_call(args) | 188 subprocess.check_call(args) |
171 current_hash = CalculateHash(target_dir) | 189 current_hash = CalculateHash(target_dir) |
172 if current_hash not in desired_hashes: | 190 if current_hash not in desired_hashes: |
173 print >> sys.stderr, ( | 191 print >> sys.stderr, ( |
174 'Got wrong hash after pulling a new toolchain. ' | 192 'Got wrong hash after pulling a new toolchain. ' |
175 'Wanted one of \'%s\', got \'%s\'.' % ( | 193 'Wanted one of \'%s\', got \'%s\'.' % ( |
176 desired_hashes, current_hash)) | 194 desired_hashes, current_hash)) |
177 return 1 | 195 return 1 |
178 SaveTimestampsAndHash(target_dir, current_hash) | 196 SaveTimestampsAndHash(target_dir, current_hash) |
179 | 197 |
180 return 0 | 198 return 0 |
181 | 199 |
182 | 200 |
183 if __name__ == '__main__': | 201 if __name__ == '__main__': |
184 sys.exit(main()) | 202 sys.exit(main()) |
OLD | NEW |