Chromium Code Reviews| 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 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 HaveSrcInternalAccess(): | |
| 118 """Checks whether access to src-internal is available.""" | |
| 119 with open(os.devnull, 'w') as nul: | |
| 120 if subprocess.call( | |
| 121 ['svn', 'ls', | |
| 122 'svn://svn.chromium.org/chrome-internal/trunk/src-internal/'], | |
| 123 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0: | |
| 124 return True | |
| 125 if subprocess.call( | |
| 126 ['git', 'remote', 'show', | |
| 127 'https://chrome-internal.googlesource.com/chrome/src-internal/'], | |
| 128 shell=True, stdin=nul, stdout=nul, stderr=nul) == 0: | |
| 129 return True | |
|
iannucci
2014/02/04 21:43:58
nit: this should actually return False. Otherwise
| |
| 130 | |
| 131 | |
| 117 def main(): | 132 def main(): |
| 118 if not sys.platform.startswith(('cygwin', 'win32')): | 133 if not sys.platform.startswith(('cygwin', 'win32')): |
| 119 return 0 | 134 return 0 |
| 120 | 135 |
| 121 if len(sys.argv) != 1: | 136 if len(sys.argv) != 1: |
| 122 print >> sys.stderr, 'Unexpected arguments.' | 137 print >> sys.stderr, 'Unexpected arguments.' |
| 123 return 1 | 138 return 1 |
| 124 | 139 |
| 125 # Move to depot_tools\win_toolchain where we'll store our files, and where | 140 # Move to depot_tools\win_toolchain where we'll store our files, and where |
| 126 # the downloader script is. | 141 # the downloader script is. |
| 127 os.chdir(os.path.normpath(os.path.join(BASEDIR))) | 142 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')) | |
| 131 toolchain_dir = '.' | 143 toolchain_dir = '.' |
| 132 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) | 144 target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) |
| 133 | 145 |
| 134 sha1path = os.path.join(toolchain_dir, 'toolchain_vs2013.hash') | 146 sha1path = os.path.join(toolchain_dir, 'toolchain_vs2013.hash') |
| 135 desired_hashes = set() | 147 desired_hashes = set() |
| 136 if os.path.isfile(sha1path): | 148 if os.path.isfile(sha1path): |
| 137 with open(sha1path, 'rb') as f: | 149 with open(sha1path, 'rb') as f: |
| 138 desired_hashes = set(f.read().strip().splitlines()) | 150 desired_hashes = set(f.read().strip().splitlines()) |
| 139 | 151 |
| 140 # If the current hash doesn't match what we want in the file, nuke and pave. | 152 # If the current hash doesn't match what we want in the file, nuke and pave. |
| 141 # Typically this script is only run when the .sha1 one file is updated, but | 153 # Typically this script is only run when the .sha1 one file is updated, but |
| 142 # directly calling "gclient runhooks" will also run it, so we cache | 154 # directly calling "gclient runhooks" will also run it, so we cache |
| 143 # based on timestamps to make that case fast. | 155 # based on timestamps to make that case fast. |
| 144 current_hash = CalculateHash(target_dir) | 156 current_hash = CalculateHash(target_dir) |
| 145 if current_hash not in desired_hashes: | 157 if current_hash not in desired_hashes: |
| 158 should_get_pro = (os.path.isfile(os.path.join(BASEDIR, '.vspro')) or | |
| 159 HaveSrcInternalAccess()) | |
| 146 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % | 160 print('Windows toolchain out of date or doesn\'t exist, updating (%s)...' % |
| 147 ('Pro' if should_get_pro else 'Express')) | 161 ('Pro' if should_get_pro else 'Express')) |
| 148 # This stays resident and will make the rmdir below fail. | 162 # This stays resident and will make the rmdir below fail. |
| 149 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe']) | 163 subprocess.call(['taskkill', '/f', '/im', 'mspdbsrv.exe']) |
| 150 if os.path.isdir(target_dir): | 164 if os.path.isdir(target_dir): |
| 151 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) | 165 subprocess.check_call('rmdir /s/q "%s"' % target_dir, shell=True) |
| 152 args = [sys.executable, | 166 args = [sys.executable, |
| 153 'toolchain2013.py', | 167 'toolchain2013.py', |
| 154 '--targetdir', target_dir] | 168 '--targetdir', target_dir] |
| 155 if not should_get_pro: | 169 if not should_get_pro: |
| 156 args.append('--express') | 170 args.append('--express') |
| 157 subprocess.check_call(args) | 171 subprocess.check_call(args) |
| 158 current_hash = CalculateHash(target_dir) | 172 current_hash = CalculateHash(target_dir) |
| 159 if current_hash not in desired_hashes: | 173 if current_hash not in desired_hashes: |
| 160 print >> sys.stderr, ( | 174 print >> sys.stderr, ( |
| 161 'Got wrong hash after pulling a new toolchain. ' | 175 'Got wrong hash after pulling a new toolchain. ' |
| 162 'Wanted one of \'%s\', got \'%s\'.' % ( | 176 'Wanted one of \'%s\', got \'%s\'.' % ( |
| 163 desired_hashes, current_hash)) | 177 desired_hashes, current_hash)) |
| 164 return 1 | 178 return 1 |
| 165 SaveTimestampsAndHash(target_dir, current_hash) | 179 SaveTimestampsAndHash(target_dir, current_hash) |
| 166 | 180 |
| 167 return 0 | 181 return 0 |
| 168 | 182 |
| 169 | 183 |
| 170 if __name__ == '__main__': | 184 if __name__ == '__main__': |
| 171 sys.exit(main()) | 185 sys.exit(main()) |
| OLD | NEW |