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 RunOrDie(command): | |
12 rc = subprocess.call(command, shell=True) | |
M-A Ruel
2013/11/26 02:07:43
that's called subprocess.check_call()
scottmg
2013/11/26 05:07:19
Done.
| |
13 if rc != 0: | |
14 raise SystemExit('%s failed.' % command) | |
15 | |
16 | |
17 def CalculateHash(root): | |
18 """Calculates the sha1 of the paths to all files in the given |root| and the | |
19 contents of those files, and returns as a hex string.""" | |
20 digest = hashlib.sha1() | |
21 count = 0 | |
22 for root, dirs, files in os.walk(root): | |
23 for name in files: | |
M-A Ruel
2013/11/26 02:07:43
I'm not sure the files are listed in deterministic
scottmg
2013/11/26 05:07:19
On 2013/11/26 02:07:43, M-A Ruel wrote:
Good poin
| |
24 path = os.path.join(root, name) | |
25 with open(path, 'rb') as f: | |
26 digest.update(path) | |
27 digest.update(f.read()) | |
M-A Ruel
2013/11/26 02:07:43
Make this a function that reads chunks. It is nece
scottmg
2013/11/26 05:07:19
The largest file is 42M, so it seems unnecessary.
| |
28 return digest.hexdigest() | |
29 | |
30 | |
31 def main(): | |
32 if sys.platform not in ('win32', 'cygwin'): | |
33 return 0 | |
34 | |
M-A Ruel
2013/11/26 02:07:43
if len(sys.argv) != 1:
print >> sys.stderr, 'Uns
scottmg
2013/11/26 05:07:19
Done.
| |
35 # cwd is assumed to be where .gclient is. | |
36 toolchain_dir = 'src/third_party/win_toolchain' | |
M-A Ruel
2013/11/26 02:07:43
os.path.join()
scottmg
2013/11/26 05:07:19
I'm not sure what you mean. This script is a DEPS
| |
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() | |
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 RunOrDie('rmdir /s/q "%s"' % target_dir) | |
54 RunOrDie([ | |
55 sys.executable, | |
M-A Ruel
2013/11/26 02:07:43
This shouldn't be run under shell=True.
scottmg
2013/11/26 05:07:19
Done.
| |
56 'src/tools/win/toolchain/toolchain2013.py', | |
M-A Ruel
2013/11/26 02:07:43
os.path.join()
also, you assume about the current
| |
57 '--targetdir=' + target_dir]) | |
58 | |
59 current_hash = CalculateHash(target_dir) | |
60 if current_hash != desired_hash: | |
61 raise SystemExit( | |
M-A Ruel
2013/11/26 02:07:43
print >> sys.stderr, 'Got ...'
return 1
scottmg
2013/11/26 05:07:19
Done.
| |
62 'Got wrong hash after pulling a new toolchain. ' | |
63 'Wanted \'%s\', got \'%s\'.' % ( | |
64 desired_hash, current_hash)) | |
65 return 0 | |
66 | |
67 | |
68 if __name__ == '__main__': | |
69 sys.exit(main()) | |
OLD | NEW |