diff options
author | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-26 18:51:11 +0000 |
---|---|---|
committer | scottmg@chromium.org <scottmg@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-26 18:51:11 +0000 |
commit | c46460594b7b0d5b6edde48df3bf08c6fc389bba (patch) | |
tree | 7094cc441f29d37fea34ef9956a9e6f743dda9de /tools/win | |
parent | 13428d45ffda26660e6c331f549b2364dc3e9ec3 (diff) | |
download | chromium_src-c46460594b7b0d5b6edde48df3bf08c6fc389bba.zip chromium_src-c46460594b7b0d5b6edde48df3bf08c6fc389bba.tar.gz chromium_src-c46460594b7b0d5b6edde48df3bf08c6fc389bba.tar.bz2 |
Auto-updating script for Windows toolchain
Updates third_party/win_toolchain to pull down a toolchain
based on SHA1. The intention is that this will be a DEPS hook
once it's ready for more broad usage and the rest of
infrastructure is ready.
R=maruel@chromium.org
TBR=cpu@chromium.org
BUG=323300
Review URL: https://codereview.chromium.org/70493006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237369 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/win')
-rw-r--r-- | tools/win/toolchain/get_toolchain_if_necessary.py | 75 | ||||
-rw-r--r-- | tools/win/toolchain/toolchain.py | 7 |
2 files changed, 80 insertions, 2 deletions
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 0000000..e93e6f0 --- /dev/null +++ b/tools/win/toolchain/get_toolchain_if_necessary.py @@ -0,0 +1,75 @@ +# 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.dirname(os.path.abspath(__file__)) + + +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.""" + assert not os.path.isabs(root) + assert os.path.normpath(root) == root + 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.join(root, name) + digest.update(path.lower()) + with open(path, 'rb') as f: + 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) + 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()) diff --git a/tools/win/toolchain/toolchain.py b/tools/win/toolchain/toolchain.py index e98fc9b..1c16fb1 100644 --- a/tools/win/toolchain/toolchain.py +++ b/tools/win/toolchain/toolchain.py @@ -57,10 +57,11 @@ def DeleteAllTempDirs(): def Download(url, local_path): """Download a large-ish binary file and print some status information while doing so.""" - sys.stdout.write('Downloading %s...' % url) + sys.stdout.write('Downloading %s...\n' % url) req = urllib2.urlopen(url) content_length = int(req.headers.get('Content-Length', 0)) bytes_read = 0 + terminator = '\r' if sys.stdout.isatty() else '\n' with open(local_path, 'wb') as file: while True: chunk = req.read(1024 * 1024) @@ -68,7 +69,8 @@ def Download(url, local_path): break bytes_read += len(chunk) file.write(chunk) - sys.stdout.write('.') + sys.stdout.write('... %d/%d%s' % (bytes_read, content_length, terminator)) + sys.stdout.flush() sys.stdout.write('\n') if content_length and content_length != bytes_read: raise SystemExit('Got incorrect number of bytes downloading %s' % url) @@ -224,6 +226,7 @@ def ExtractIso(iso_path): .exe).""" target_path = TempDir() sys.stdout.write('Extracting %s...\n' % iso_path) + sys.stdout.flush() # TODO(scottmg): Do this (and exe) manually with python code. # Note that at the beginning of main() we set the working directory to 7z's # location. |