Chromium Code Reviews| 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 BASEDIR = os.path.abspath(os.path.dirname(__file__)) | |
|
M-A Ruel
2013/11/26 17:48:18
BASEDIR = os.path.dirname(os.path.abspath(__file__
scottmg
2013/11/26 17:57:54
Done.
When does it matter? os.path.abspath('') ==
M-A Ruel
2013/11/26 18:03:40
but os.path.dirname(os.getcwd()) != os.path.dirnam
| |
| 12 | |
| 13 | |
| 14 def CalculateHash(root): | |
| 15 """Calculates the sha1 of the paths to all files in the given |root| and the | |
| 16 contents of those files, and returns as a hex string.""" | |
| 17 digest = hashlib.sha1() | |
| 18 count = 0 | |
| 19 for root, dirs, files in os.walk(root): | |
| 20 dirs.sort() | |
| 21 for name in sorted(f.lower() for f in files): | |
| 22 path = os.path.normpath(os.path.join(root, name)) | |
| 23 with open(path, 'rb') as f: | |
| 24 digest.update(path.lower()) | |
|
M-A Ruel
2013/11/26 17:48:18
I'd prefer this to be outside of the with statemen
scottmg
2013/11/26 17:57:54
Done.
| |
| 25 digest.update(f.read()) | |
| 26 return digest.hexdigest() | |
| 27 | |
| 28 | |
| 29 def main(): | |
| 30 if sys.platform not in ('win32', 'cygwin'): | |
| 31 return 0 | |
| 32 | |
| 33 if len(sys.argv) != 1: | |
| 34 print >> sys.stderr, 'Unexpected arguments.' | |
| 35 return 1 | |
| 36 | |
| 37 # Move to same location as .gclient. This is a no-op when run via gclient. | |
| 38 os.chdir(os.path.normpath(os.path.join(BASEDIR, '../../../..'))) | |
| 39 toolchain_dir = 'src/third_party/win_toolchain' | |
| 40 target_dir = os.path.join(toolchain_dir, 'files') | |
| 41 | |
| 42 sha1path = os.path.join(toolchain_dir, 'toolchain.sha1') | |
| 43 desired_hash = '' | |
| 44 if os.path.isfile(sha1path): | |
| 45 with open(sha1path, 'rb') as f: | |
| 46 desired_hash = f.read().strip() | |
| 47 | |
| 48 # If the current hash doesn't match what we want in the file, nuke and pave. | |
| 49 # Note that this script is only run when a .sha1 file is updated (per DEPS) | |
| 50 # so this relatively expensive step of hashing everything only happens when | |
| 51 # the toolchain is updated. | |
| 52 current_hash = CalculateHash(target_dir) | |
|
M-A Ruel
2013/11/26 17:48:18
How long does it take in practice on a spinning dr
scottmg
2013/11/26 17:57:54
Spinning disk, pssh. Can you even build chrome on
M-A Ruel
2013/11/26 18:03:40
That's 90% of build slaves.
| |
| 53 if current_hash != desired_hash: | |
| 54 print 'Windows toolchain out of date or doesn\'t exist, updating...' | |
| 55 if os.path.isdir(target_dir): | |
| 56 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) | |
| 57 subprocess.check_call([ | |
| 58 sys.executable, | |
| 59 'src/tools/win/toolchain/toolchain2013.py', | |
| 60 '--targetdir', target_dir]) | |
| 61 | |
| 62 current_hash = CalculateHash(target_dir) | |
| 63 if current_hash != desired_hash: | |
| 64 print >> sys.stderr, ( | |
| 65 'Got wrong hash after pulling a new toolchain. ' | |
| 66 'Wanted \'%s\', got \'%s\'.' % ( | |
| 67 desired_hash, current_hash)) | |
| 68 return 1 | |
| 69 return 0 | |
| 70 | |
| 71 | |
| 72 if __name__ == '__main__': | |
| 73 sys.exit(main()) | |
| OLD | NEW |