Index: win_toolchain/get_toolchain_if_necessary.py |
diff --git a/win_toolchain/get_toolchain_if_necessary.py b/win_toolchain/get_toolchain_if_necessary.py |
index 07e82729eee15089c6fbe9d90f4d8e99d580a6c9..b28b6e2905879624e7766a5f3beffe4dcd5bf3fd 100755 |
--- a/win_toolchain/get_toolchain_if_necessary.py |
+++ b/win_toolchain/get_toolchain_if_necessary.py |
@@ -82,11 +82,10 @@ def MakeTimestampsFileName(root): |
return os.path.join(root, '..', '.timestamps') |
-def CalculateHash(root): |
+def CalculateHash(root, expected_hash): |
"""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.""" |
- file_list = GetFileList(root) |
- |
+ file_list = GetFileList(os.path.join(root, hash)) |
# Check whether we previously saved timestamps in $root/../.timestamps. If |
# we didn't, or they don't match, then do the full calculation, otherwise |
# return the saved value. |
@@ -111,12 +110,25 @@ def CalculateHash(root): |
digest = hashlib.sha1() |
for path in file_list: |
- digest.update(str(path).replace('/', '\\')) |
+ path_without_hash = (str(path).replace('/', '\\').replace(expected_hash, '') |
+ .replace('\\\\', '\\')) |
+ digest.update(path_without_hash) |
with open(path, 'rb') as f: |
digest.update(f.read()) |
return digest.hexdigest() |
+def CalculateToolchainHashes(root): |
+ """Calculate the hash of the different toolchains installed in the |root| |
+ directory.""" |
+ hashes = [] |
+ dir_list = [ |
+ d for d in os.listdir(root) if os.path.isdir(os.path.join(root, d))] |
+ for d in dir_list: |
+ hashes.append(CalculateHash(root, d)) |
+ return hashes |
+ |
+ |
def SaveTimestampsAndHash(root, sha1): |
"""Saves timestamps and the final hash to be able to early-out more quickly |
next time.""" |
@@ -328,9 +340,9 @@ def main(): |
assert sys.platform != 'cygwin' |
# We assume that the Pro hash is the first one. |
- desired_hashes = args |
- if len(desired_hashes) == 0: |
- sys.exit('Desired hashes are required.') |
+ desired_hash = args[0] |
+ if len(desired_hash) == 0: |
scottmg
2016/01/25 23:12:53
I don't think you'll get an empty args[0] here?
Sébastien Marchand
2016/01/27 21:35:19
Moved this check earlier in the script.
|
+ sys.exit('Desired hash is required.') |
# Move to depot_tools\win_toolchain where we'll store our files, and where |
# the downloader script is. |
@@ -340,7 +352,9 @@ def main(): |
target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs_files')) |
else: |
target_dir = os.path.normpath(os.path.join(toolchain_dir, 'vs2013_files')) |
- abs_target_dir = os.path.abspath(target_dir) |
+ toolchain_target_dir = os.path.join(target_dir, desired_hash) |
+ |
+ abs_toolchain_target_dir = os.path.abspath(toolchain_target_dir) |
got_new_toolchain = False |
@@ -348,8 +362,8 @@ def main(): |
# Typically this script is only run when the .sha1 one file is updated, but |
# directly calling "gclient runhooks" will also run it, so we cache |
# based on timestamps to make that case fast. |
- current_hash = CalculateHash(target_dir) |
- if current_hash not in desired_hashes: |
+ current_hashes = CalculateToolchainHashes(target_dir) |
+ if desired_hash not in current_hashes: |
should_use_gs = False |
if (HaveSrcInternalAccess() or |
LooksLikeGoogler() or |
@@ -363,10 +377,10 @@ def main(): |
'build-instructions-windows\n\n') |
return 1 |
print('Windows toolchain out of date or doesn\'t exist, updating (Pro)...') |
- print(' current_hash: %s' % current_hash) |
- print(' desired_hashes: %s' % ', '.join(desired_hashes)) |
+ print(' current_hashes: %s' % ', '.join(current_hashes)) |
+ print(' desired_hash: %s' % desired_hash) |
sys.stdout.flush() |
- DelayBeforeRemoving(target_dir) |
+ DelayBeforeRemoving(toolchain_target_dir) |
if sys.platform == 'win32': |
# These stay resident and will make the rmdir below fail. |
kill_list = [ |
@@ -377,45 +391,45 @@ def main(): |
with open(os.devnull, 'wb') as nul: |
subprocess.call(['taskkill', '/f', '/im', process_name], |
stdin=nul, stdout=nul, stderr=nul) |
- if os.path.isdir(target_dir): |
- RmDir(target_dir) |
+ if os.path.isdir(toolchain_target_dir): |
+ RmDir(toolchain_target_dir) |
- DoTreeMirror(target_dir, desired_hashes[0]) |
+ DoTreeMirror(toolchain_target_dir, desired_hash) |
got_new_toolchain = True |
- win_sdk = os.path.join(abs_target_dir, 'win_sdk') |
+ win_sdk = os.path.join(abs_toolchain_target_dir, 'win_sdk') |
try: |
- with open(os.path.join(target_dir, 'VS_VERSION'), 'rb') as f: |
+ with open(os.path.join(toolchain_target_dir, 'VS_VERSION'), 'rb') as f: |
vs_version = f.read().strip() |
except IOError: |
# Older toolchains didn't have the VS_VERSION file, and used 'win8sdk' |
# instead of just 'win_sdk'. |
vs_version = '2013' |
- win_sdk = os.path.join(abs_target_dir, 'win8sdk') |
+ win_sdk = os.path.join(abs_toolchain_target_dir, 'win8sdk') |
data = { |
- 'path': abs_target_dir, |
+ 'path': abs_toolchain_target_dir, |
'version': vs_version, |
'win_sdk': win_sdk, |
# Added for backwards compatibility with old toolchain packages. |
'win8sdk': win_sdk, |
- 'wdk': os.path.join(abs_target_dir, 'wdk'), |
+ 'wdk': os.path.join(abs_toolchain_target_dir, 'wdk'), |
'runtime_dirs': [ |
- os.path.join(abs_target_dir, 'sys64'), |
- os.path.join(abs_target_dir, 'sys32'), |
+ os.path.join(abs_toolchain_target_dir, 'sys64'), |
+ os.path.join(abs_toolchain_target_dir, 'sys32'), |
], |
} |
with open(os.path.join(target_dir, '..', 'data.json'), 'w') as f: |
json.dump(data, f) |
if got_new_toolchain: |
- current_hash = CalculateHash(target_dir) |
- if current_hash not in desired_hashes: |
+ current_hashes = CalculateToolchainHashes(target_dir) |
+ if desired_hash not in current_hashes: |
print >> sys.stderr, ( |
'Got wrong hash after pulling a new toolchain. ' |
'Wanted one of \'%s\', got \'%s\'.' % ( |
- ', '.join(desired_hashes), current_hash)) |
+ desired_hash, ', '.join(current_hashes))) |
return 1 |
SaveTimestampsAndHash(target_dir, current_hash) |
@@ -424,7 +438,7 @@ def main(): |
options.output_json) |
if os.environ.get('GYP_MSVS_VERSION') == '2015': |
- InstallUniversalCRTIfNeeded(abs_target_dir) |
+ InstallUniversalCRTIfNeeded(abs_toolchain_target_dir) |
return 0 |