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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 | 51 |
52 def GetFileList(root): | 52 def GetFileList(root): |
53 """Gets a normalized list of files under |root|.""" | 53 """Gets a normalized list of files under |root|.""" |
54 assert not os.path.isabs(root) | 54 assert not os.path.isabs(root) |
55 assert os.path.normpath(root) == root | 55 assert os.path.normpath(root) == root |
56 file_list = [] | 56 file_list = [] |
57 for base, _, files in os.walk(root): | 57 for base, _, files in os.walk(root): |
58 paths = [os.path.join(base, f) for f in files] | 58 paths = [os.path.join(base, f) for f in files] |
59 file_list.extend(x.lower() for x in paths) | 59 file_list.extend(x.lower() for x in paths) |
60 return sorted(file_list) | 60 return sorted(file_list, key=lambda s: s.replace('/', '\\')) |
61 | 61 |
62 | 62 |
63 def MakeTimestampsFileName(root): | 63 def MakeTimestampsFileName(root): |
64 return os.path.join(root, '..', '.timestamps') | 64 return os.path.join(root, '..', '.timestamps') |
65 | 65 |
66 | 66 |
67 def CalculateHash(root): | 67 def CalculateHash(root): |
68 """Calculates the sha1 of the paths to all files in the given |root| and the | 68 """Calculates the sha1 of the paths to all files in the given |root| and the |
69 contents of those files, and returns as a hex string.""" | 69 contents of those files, and returns as a hex string.""" |
70 file_list = GetFileList(root) | 70 file_list = GetFileList(root) |
(...skipping 15 matching lines...) Expand all Loading... |
86 if matches: | 86 if matches: |
87 for disk, cached in zip(file_list, timestamps_data['files']): | 87 for disk, cached in zip(file_list, timestamps_data['files']): |
88 if disk != cached[0] or os.stat(disk).st_mtime != cached[1]: | 88 if disk != cached[0] or os.stat(disk).st_mtime != cached[1]: |
89 matches = False | 89 matches = False |
90 break | 90 break |
91 if matches: | 91 if matches: |
92 return timestamps_data['sha1'] | 92 return timestamps_data['sha1'] |
93 | 93 |
94 digest = hashlib.sha1() | 94 digest = hashlib.sha1() |
95 for path in file_list: | 95 for path in file_list: |
96 digest.update(path) | 96 digest.update(str(path).replace('/', '\\')) |
97 with open(path, 'rb') as f: | 97 with open(path, 'rb') as f: |
98 digest.update(f.read()) | 98 digest.update(f.read()) |
99 return digest.hexdigest() | 99 return digest.hexdigest() |
100 | 100 |
101 | 101 |
102 def SaveTimestampsAndHash(root, sha1): | 102 def SaveTimestampsAndHash(root, sha1): |
103 """Saves timestamps and the final hash to be able to early-out more quickly | 103 """Saves timestamps and the final hash to be able to early-out more quickly |
104 next time.""" | 104 next time.""" |
105 file_list = GetFileList(root) | 105 file_list = GetFileList(root) |
106 timestamps_data = { | 106 timestamps_data = { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 322 |
323 if options.output_json: | 323 if options.output_json: |
324 shutil.copyfile(os.path.join(target_dir, '..', 'data.json'), | 324 shutil.copyfile(os.path.join(target_dir, '..', 'data.json'), |
325 options.output_json) | 325 options.output_json) |
326 | 326 |
327 return 0 | 327 return 0 |
328 | 328 |
329 | 329 |
330 if __name__ == '__main__': | 330 if __name__ == '__main__': |
331 sys.exit(main()) | 331 sys.exit(main()) |
OLD | NEW |