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

Side by Side Diff: win_toolchain/get_toolchain_if_necessary.py

Issue 168603004: Move toolchain update control into src, but keep download logic in depot_tools (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: reitveld Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « update_depot_tools.bat ('k') | win_toolchain/toolchain2013.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 11 matching lines...) Expand all
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 29 import ctypes.wintypes
30 import hashlib 30 import hashlib
31 import json 31 import json
32 import optparse
32 import os 33 import os
34 import shutil
33 import subprocess 35 import subprocess
34 import sys 36 import sys
35 import time 37 import time
36 38
37 39
38 BASEDIR = os.path.dirname(os.path.abspath(__file__)) 40 BASEDIR = os.path.dirname(os.path.abspath(__file__))
39 41
40 42
41 GetFileAttributes = ctypes.windll.kernel32.GetFileAttributesW 43 GetFileAttributes = ctypes.windll.kernel32.GetFileAttributesW
42 GetFileAttributes.argtypes = (ctypes.wintypes.LPWSTR,) 44 GetFileAttributes.argtypes = (ctypes.wintypes.LPWSTR,)
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 '\rRemoving old toolchain in %ds... (Ctrl-C to cancel)' % i) 140 '\rRemoving old toolchain in %ds... (Ctrl-C to cancel)' % i)
139 sys.stdout.flush() 141 sys.stdout.flush()
140 time.sleep(1) 142 time.sleep(1)
141 print 143 print
142 144
143 145
144 def main(): 146 def main():
145 if not sys.platform.startswith(('cygwin', 'win32')): 147 if not sys.platform.startswith(('cygwin', 'win32')):
146 return 0 148 return 0
147 149
148 if len(sys.argv) != 1: 150 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__)
149 print >> sys.stderr, 'Unexpected arguments.' 151 parser.add_option('--output-json', metavar='FILE',
150 return 1 152 help='write information about toolchain to FILE')
153 options, args = parser.parse_args()
154
155 desired_hashes = set(args)
151 156
152 # Move to depot_tools\win_toolchain where we'll store our files, and where 157 # Move to depot_tools\win_toolchain where we'll store our files, and where
153 # the downloader script is. 158 # the downloader script is.
154 os.chdir(os.path.normpath(os.path.join(BASEDIR))) 159 os.chdir(os.path.normpath(os.path.join(BASEDIR)))
155 toolchain_dir = '.' 160 toolchain_dir = '.'
156 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) 161 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files'))
157 162
158 sha1path = os.path.join(toolchain_dir, 'toolchain_vs2013.hash')
159 desired_hashes = set()
160 if os.path.isfile(sha1path):
161 with open(sha1path, 'rb') as f:
162 desired_hashes = set(f.read().strip().splitlines())
163
164 # If the current hash doesn't match what we want in the file, nuke and pave. 163 # If the current hash doesn't match what we want in the file, nuke and pave.
165 # Typically this script is only run when the .sha1 one file is updated, but 164 # Typically this script is only run when the .sha1 one file is updated, but
166 # directly calling "gclient runhooks" will also run it, so we cache 165 # directly calling "gclient runhooks" will also run it, so we cache
167 # based on timestamps to make that case fast. 166 # based on timestamps to make that case fast.
168 current_hash = CalculateHash(target_dir) 167 current_hash = CalculateHash(target_dir)
169 if current_hash not in desired_hashes: 168 if current_hash not in desired_hashes:
170 should_get_pro = (os.path.isfile(os.path.join(BASEDIR, '.vspro')) or 169 should_get_pro = (os.path.isfile(os.path.join(BASEDIR, '.vspro')) or
171 HaveSrcInternalAccess()) 170 HaveSrcInternalAccess())
172 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % 171 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' %
173 ('Pro' if should_get_pro else 'Express')) 172 ('Pro' if should_get_pro else 'Express'))
(...skipping 14 matching lines...) Expand all
188 subprocess.check_call(args) 187 subprocess.check_call(args)
189 current_hash = CalculateHash(target_dir) 188 current_hash = CalculateHash(target_dir)
190 if current_hash not in desired_hashes: 189 if current_hash not in desired_hashes:
191 print >> sys.stderr, ( 190 print >> sys.stderr, (
192 'Got wrong hash after pulling a new toolchain. ' 191 'Got wrong hash after pulling a new toolchain. '
193 'Wanted one of \'%s\', got \'%s\'.' % ( 192 'Wanted one of \'%s\', got \'%s\'.' % (
194 desired_hashes, current_hash)) 193 desired_hashes, current_hash))
195 return 1 194 return 1
196 SaveTimestampsAndHash(target_dir, current_hash) 195 SaveTimestampsAndHash(target_dir, current_hash)
197 196
197 if options.output_json:
198 shutil.copyfile(os.path.join(target_dir, 'data.json'), options.output_json)
199
198 return 0 200 return 0
199 201
200 202
201 if __name__ == '__main__': 203 if __name__ == '__main__':
202 sys.exit(main()) 204 sys.exit(main())
OLDNEW
« no previous file with comments | « update_depot_tools.bat ('k') | win_toolchain/toolchain2013.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698