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

Unified 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: nicer output Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/win_toolchain/toolchain.sha1 ('k') | tools/win/toolchain/toolchain.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/win/toolchain/get_toolchain_if_necessary.py
diff --git a/tools/win/toolchain/get_toolchain_if_necessary.py b/tools/win/toolchain/get_toolchain_if_necessary.py
new file mode 100644
index 0000000000000000000000000000000000000000..8d9e25fec83c6f9dad2d3e2595333b1710d1d9c7
--- /dev/null
+++ b/tools/win/toolchain/get_toolchain_if_necessary.py
@@ -0,0 +1,69 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import hashlib
+import os
+import subprocess
+import sys
+
+
+def RunOrDie(command):
+ 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.
+ if rc != 0:
+ raise SystemExit('%s failed.' % command)
+
+
+def CalculateHash(root):
+ """Calculates the sha1 of the paths to all files in the given |root| and the
+ contents of those files, and returns as a hex string."""
+ digest = hashlib.sha1()
+ count = 0
+ for root, dirs, files in os.walk(root):
+ 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
+ path = os.path.join(root, name)
+ with open(path, 'rb') as f:
+ digest.update(path)
+ 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.
+ return digest.hexdigest()
+
+
+def main():
+ if sys.platform not in ('win32', 'cygwin'):
+ return 0
+
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.
+ # cwd is assumed to be where .gclient is.
+ 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
+ target_dir = os.path.join(toolchain_dir, 'files')
+
+ sha1path = os.path.join(toolchain_dir, 'toolchain.sha1')
+ desired_hash = ''
+ if os.path.isfile(sha1path):
+ with open(sha1path, 'rb') as f:
+ desired_hash = f.read()
+
+ # If the current hash doesn't match what we want in the file, nuke and pave.
+ # Note that this script is only run when a .sha1 file is updated (per DEPS)
+ # so this relatively expensive step of hashing everything only happens when
+ # the toolchain is updated.
+ current_hash = CalculateHash(target_dir)
+ if current_hash != desired_hash:
+ print 'Windows toolchain out of date or doesn\'t exist, updating...'
+ if os.path.isdir(target_dir):
+ RunOrDie('rmdir /s/q "%s"' % target_dir)
+ RunOrDie([
+ 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.
+ 'src/tools/win/toolchain/toolchain2013.py',
M-A Ruel 2013/11/26 02:07:43 os.path.join() also, you assume about the current
+ '--targetdir=' + target_dir])
+
+ current_hash = CalculateHash(target_dir)
+ if current_hash != desired_hash:
+ 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.
+ 'Got wrong hash after pulling a new toolchain. '
+ 'Wanted \'%s\', got \'%s\'.' % (
+ desired_hash, current_hash))
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())
« 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