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.dirname(os.path.abspath(__file__)) |
| 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 assert not os.path.isabs(root) |
| 18 assert os.path.normpath(root) == root |
| 19 digest = hashlib.sha1() |
| 20 count = 0 |
| 21 for root, dirs, files in os.walk(root): |
| 22 dirs.sort() |
| 23 for name in sorted(f.lower() for f in files): |
| 24 path = os.path.join(root, name) |
| 25 digest.update(path.lower()) |
| 26 with open(path, 'rb') as f: |
| 27 digest.update(f.read()) |
| 28 return digest.hexdigest() |
| 29 |
| 30 |
| 31 def main(): |
| 32 if sys.platform not in ('win32', 'cygwin'): |
| 33 return 0 |
| 34 |
| 35 if len(sys.argv) != 1: |
| 36 print >> sys.stderr, 'Unexpected arguments.' |
| 37 return 1 |
| 38 |
| 39 # Move to same location as .gclient. This is a no-op when run via gclient. |
| 40 os.chdir(os.path.normpath(os.path.join(BASEDIR, '..\\..\\..\\..'))) |
| 41 toolchain_dir = 'src\\third_party\\win_toolchain' |
| 42 target_dir = os.path.join(toolchain_dir, 'files') |
| 43 |
| 44 sha1path = os.path.join(toolchain_dir, 'toolchain.sha1') |
| 45 desired_hash = '' |
| 46 if os.path.isfile(sha1path): |
| 47 with open(sha1path, 'rb') as f: |
| 48 desired_hash = f.read().strip() |
| 49 |
| 50 # If the current hash doesn't match what we want in the file, nuke and pave. |
| 51 # Note that this script is only run when a .sha1 file is updated (per DEPS) |
| 52 # so this relatively expensive step of hashing everything only happens when |
| 53 # the toolchain is updated. |
| 54 current_hash = CalculateHash(target_dir) |
| 55 if current_hash != desired_hash: |
| 56 print 'Windows toolchain out of date or doesn\'t exist, updating...' |
| 57 if os.path.isdir(target_dir): |
| 58 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) |
| 59 subprocess.check_call([ |
| 60 sys.executable, |
| 61 'src\\tools\\win\\toolchain\\toolchain2013.py', |
| 62 '--targetdir', target_dir]) |
| 63 |
| 64 current_hash = CalculateHash(target_dir) |
| 65 if current_hash != desired_hash: |
| 66 print >> sys.stderr, ( |
| 67 'Got wrong hash after pulling a new toolchain. ' |
| 68 'Wanted \'%s\', got \'%s\'.' % ( |
| 69 desired_hash, current_hash)) |
| 70 return 1 |
| 71 return 0 |
| 72 |
| 73 |
| 74 if __name__ == '__main__': |
| 75 sys.exit(main()) |
OLD | NEW |