 Chromium Code Reviews
 Chromium Code Reviews Issue 70493006:
  Auto-updating script for Windows toolchain  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 70493006:
  Auto-updating script for Windows toolchain  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import hashlib | |
| 6 import os | |
| 7 import subprocess | |
| 8 import sys | |
| 9 | |
| 10 | |
| 11 def CalculateHash(root): | |
| 12 """Calculates the sha1 of the paths to all files in the given |root| and the | |
| 13 contents of those files, and returns as a hex string.""" | |
| 14 digest = hashlib.sha1() | |
| 15 count = 0 | |
| 16 for root, dirs, files in os.walk(root): | |
| 17 dirs.sort() | |
| 18 files_lower = [f.lower() for f in files] | |
| 19 for name in sorted(files_lower): | |
| 
M-A Ruel
2013/11/26 16:09:50
for name in sorted(f.lower() for f in files):
 
scottmg
2013/11/26 17:41:29
Done.
 | |
| 20 path = os.path.normpath(os.path.join(root, name)) | |
| 21 with open(path, 'rb') as f: | |
| 22 digest.update(path.lower()) | |
| 23 digest.update(f.read()) | |
| 24 return digest.hexdigest() | |
| 25 | |
| 26 | |
| 27 def main(): | |
| 28 if sys.platform not in ('win32', 'cygwin'): | |
| 29 return 0 | |
| 30 | |
| 31 if len(sys.argv) != 1: | |
| 32 print >> sys.stderr, 'Unexpected arguments.' | |
| 33 return 1 | |
| 34 | |
| 35 # cwd is assumed to be where .gclient is. | |
| 
M-A Ruel
2013/11/26 16:09:50
s/<comment>/os.chdir(<path>)/
The first thing peop
 
scottmg
2013/11/26 17:41:29
Done.
 | |
| 36 toolchain_dir = 'src/third_party/win_toolchain' | |
| 37 target_dir = os.path.join(toolchain_dir, 'files') | |
| 38 | |
| 39 sha1path = os.path.join(toolchain_dir, 'toolchain.sha1') | |
| 40 desired_hash = '' | |
| 41 if os.path.isfile(sha1path): | |
| 42 with open(sha1path, 'rb') as f: | |
| 43 desired_hash = f.read().strip() | |
| 44 | |
| 45 # If the current hash doesn't match what we want in the file, nuke and pave. | |
| 46 # Note that this script is only run when a .sha1 file is updated (per DEPS) | |
| 47 # so this relatively expensive step of hashing everything only happens when | |
| 48 # the toolchain is updated. | |
| 49 current_hash = CalculateHash(target_dir) | |
| 50 if current_hash != desired_hash: | |
| 51 print 'Windows toolchain out of date or doesn\'t exist, updating...' | |
| 52 if os.path.isdir(target_dir): | |
| 53 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) | |
| 54 subprocess.check_call([ | |
| 55 sys.executable, | |
| 56 'src/tools/win/toolchain/toolchain2013.py', | |
| 57 '--targetdir=' + target_dir]) | |
| 
M-A Ruel
2013/11/26 16:09:50
'--targetdir', target_dir])
this increase the lik
 
scottmg
2013/11/26 17:41:29
Done.
 | |
| 58 | |
| 59 current_hash = CalculateHash(target_dir) | |
| 60 if current_hash != desired_hash: | |
| 61 print >> sys.stderr, ( | |
| 62 'Got wrong hash after pulling a new toolchain. ' | |
| 63 'Wanted \'%s\', got \'%s\'.' % ( | |
| 64 desired_hash, current_hash)) | |
| 65 return 1 | |
| 66 return 0 | |
| 67 | |
| 68 | |
| 69 if __name__ == '__main__': | |
| 70 sys.exit(main()) | |
| OLD | NEW |