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

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: fixes 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
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..0e6b954b26ff3dc64d40106ce83e1831ae681806
--- /dev/null
+++ b/tools/win/toolchain/get_toolchain_if_necessary.py
@@ -0,0 +1,73 @@
+# 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
+
+
+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
+
+
+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):
+ dirs.sort()
+ for name in sorted(f.lower() for f in files):
+ path = os.path.normpath(os.path.join(root, name))
+ with open(path, 'rb') as f:
+ 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.
+ digest.update(f.read())
+ return digest.hexdigest()
+
+
+def main():
+ if sys.platform not in ('win32', 'cygwin'):
+ return 0
+
+ if len(sys.argv) != 1:
+ print >> sys.stderr, 'Unexpected arguments.'
+ return 1
+
+ # Move to same location as .gclient. This is a no-op when run via gclient.
+ os.chdir(os.path.normpath(os.path.join(BASEDIR, '../../../..')))
+ toolchain_dir = 'src/third_party/win_toolchain'
+ 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().strip()
+
+ # 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)
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.
+ if current_hash != desired_hash:
+ print 'Windows toolchain out of date or doesn\'t exist, updating...'
+ if os.path.isdir(target_dir):
+ subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True)
+ subprocess.check_call([
+ sys.executable,
+ 'src/tools/win/toolchain/toolchain2013.py',
+ '--targetdir', target_dir])
+
+ current_hash = CalculateHash(target_dir)
+ if current_hash != desired_hash:
+ print >> sys.stderr, (
+ 'Got wrong hash after pulling a new toolchain. '
+ 'Wanted \'%s\', got \'%s\'.' % (
+ desired_hash, current_hash))
+ return 1
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main())

Powered by Google App Engine
This is Rietveld 408576698