| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The Chromium Authors. All rights reserved. | 2 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Downloads and unpacks a toolchain for building on Windows. The contents are | 6 """Downloads and unpacks a toolchain for building on Windows. The contents are |
| 7 matched by sha1 which will be updated when the toolchain is updated. | 7 matched by sha1 which will be updated when the toolchain is updated. |
| 8 | 8 |
| 9 Having a toolchain script in depot_tools means that it's not versioned | 9 Having a toolchain script in depot_tools means that it's not versioned |
| 10 directly with the source code. That is, if the toolchain is upgraded, but | 10 directly with the source code. That is, if the toolchain is upgraded, but |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 96 |
| 97 digest = hashlib.sha1() | 97 digest = hashlib.sha1() |
| 98 for path in file_list: | 98 for path in file_list: |
| 99 digest.update(path) | 99 digest.update(path) |
| 100 with open(path, 'rb') as f: | 100 with open(path, 'rb') as f: |
| 101 digest.update(f.read()) | 101 digest.update(f.read()) |
| 102 return digest.hexdigest() | 102 return digest.hexdigest() |
| 103 | 103 |
| 104 | 104 |
| 105 def SaveTimestampsAndHash(root, sha1): | 105 def SaveTimestampsAndHash(root, sha1): |
| 106 """Save timestamps and the final hash to be able to early-out more quickly | 106 """Saves timestamps and the final hash to be able to early-out more quickly |
| 107 next time.""" | 107 next time.""" |
| 108 file_list = GetFileList(root) | 108 file_list = GetFileList(root) |
| 109 timestamps_data = { | 109 timestamps_data = { |
| 110 'files': [[f, os.stat(f).st_mtime] for f in file_list], | 110 'files': [[f, os.stat(f).st_mtime] for f in file_list], |
| 111 'sha1': sha1, | 111 'sha1': sha1, |
| 112 } | 112 } |
| 113 with open(MakeTimestampsFileName(root), 'wb') as f: | 113 with open(MakeTimestampsFileName(root), 'wb') as f: |
| 114 json.dump(timestamps_data, f) | 114 json.dump(timestamps_data, f) |
| 115 | 115 |
| 116 | 116 |
| 117 def main(): | 117 def main(): |
| 118 if not sys.platform.startswith(('cygwin', 'win32')): | 118 if not sys.platform.startswith(('cygwin', 'win32')): |
| 119 return 0 | 119 return 0 |
| 120 | 120 |
| 121 if len(sys.argv) != 1: | 121 if len(sys.argv) != 1: |
| 122 print >> sys.stderr, 'Unexpected arguments.' | 122 print >> sys.stderr, 'Unexpected arguments.' |
| 123 return 1 | 123 return 1 |
| 124 | 124 |
| 125 # Move to depot_tools\win_toolchain where we'll store our files, and where | 125 # Move to depot_tools\win_toolchain where we'll store our files, and where |
| 126 # the downloader script is. | 126 # the downloader script is. |
| 127 os.chdir(os.path.normpath(os.path.join(BASEDIR))) | 127 os.chdir(os.path.normpath(os.path.join(BASEDIR))) |
| 128 # TODO(scottmg): http://crbug.com/323300 Attempt to locate a src-internal |
| 129 # pull and use that as a signal to install Pro also. |
| 130 should_get_pro = os.path.isfile(os.path.join(BASEDIR, '.vspro')) |
| 128 toolchain_dir = '.' | 131 toolchain_dir = '.' |
| 129 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) | 132 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) |
| 130 | 133 |
| 131 sha1path = os.path.join(toolchain_dir, 'toolchain_vs2013.hash') | 134 sha1path = os.path.join(toolchain_dir, 'toolchain_vs2013.hash') |
| 132 desired_hash = '' | 135 desired_hashes = set() |
| 133 if os.path.isfile(sha1path): | 136 if os.path.isfile(sha1path): |
| 134 with open(sha1path, 'rb') as f: | 137 with open(sha1path, 'rb') as f: |
| 135 desired_hash = f.read().strip() | 138 desired_hashes = set(f.read().strip().splitlines()) |
| 136 | 139 |
| 137 # If the current hash doesn't match what we want in the file, nuke and pave. | 140 # If the current hash doesn't match what we want in the file, nuke and pave. |
| 138 # Typically this script is only run when the .sha1 one file is updated, but | 141 # Typically this script is only run when the .sha1 one file is updated, but |
| 139 # directly calling "gclient runhooks" will also run it, so we cache | 142 # directly calling "gclient runhooks" will also run it, so we cache |
| 140 # based on timestamps to make that case fast. | 143 # based on timestamps to make that case fast. |
| 141 current_hash = CalculateHash(target_dir) | 144 current_hash = CalculateHash(target_dir) |
| 142 if current_hash != desired_hash: | 145 if current_hash not in desired_hashes: |
| 143 print 'Windows toolchain out of date or doesn\'t exist, updating...' | 146 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % |
| 147 ('Pro' if should_get_pro else 'Express')) |
| 144 # This stays resident and will make the rmdir below fail. | 148 # This stays resident and will make the rmdir below fail. |
| 145 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe']) | 149 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe']) |
| 146 if os.path.isdir(target_dir): | 150 if os.path.isdir(target_dir): |
| 147 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) | 151 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) |
| 148 subprocess.check_call([ | 152 args = [sys.executable, |
| 149 sys.executable, | 153 'toolchain2013.py', |
| 150 'toolchain2013.py', | 154 '--targetdir', target_dir] |
| 151 '--targetdir', target_dir]) | 155 if not should_get_pro: |
| 156 args.append('--express') |
| 157 subprocess.check_call(args) |
| 152 current_hash = CalculateHash(target_dir) | 158 current_hash = CalculateHash(target_dir) |
| 153 if current_hash != desired_hash: | 159 if current_hash not in desired_hashes: |
| 154 print >> sys.stderr, ( | 160 print >> sys.stderr, ( |
| 155 'Got wrong hash after pulling a new toolchain. ' | 161 'Got wrong hash after pulling a new toolchain. ' |
| 156 'Wanted \'%s\', got \'%s\'.' % ( | 162 'Wanted one of \'%s\', got \'%s\'.' % ( |
| 157 desired_hash, current_hash)) | 163 desired_hashes, current_hash)) |
| 158 return 1 | 164 return 1 |
| 159 SaveTimestampsAndHash(target_dir, current_hash) | 165 SaveTimestampsAndHash(target_dir, current_hash) |
| 160 | 166 |
| 161 return 0 | 167 return 0 |
| 162 | 168 |
| 163 | 169 |
| 164 if __name__ == '__main__': | 170 if __name__ == '__main__': |
| 165 sys.exit(main()) | 171 sys.exit(main()) |
| OLD | NEW |