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

Side by Side Diff: tools/win/toolchain/get_toolchain_if_necessary.py

Issue 70493006: Auto-updating script for Windows toolchain (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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 | « third_party/win_toolchain/toolchain.sha1 ('k') | tools/win/toolchain/toolchain.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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."""
M-A Ruel 2013/11/26 18:03:40 you may want to: assert not os.path.isabs(root) as
scottmg 2013/11/26 18:17:14 Done.
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))
M-A Ruel 2013/11/26 18:03:40 technically, the normpath() call here will always
scottmg 2013/11/26 18:17:14 Yes, I guess with the assert it's ok to remove.
23 digest.update(path.lower())
24 with open(path, 'rb') as f:
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')
M-A Ruel 2013/11/26 18:03:40 Note that target_dir will be 'src/third_party/win_
scottmg 2013/11/26 18:17:14 Normalized all paths to Windows style.
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)
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())
OLDNEW
« no previous file with comments | « third_party/win_toolchain/toolchain.sha1 ('k') | tools/win/toolchain/toolchain.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698