Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: win_toolchain/get_toolchain_if_necessary.py

Issue 1287543005: Make `python build/vs_toolchain.py update` mostly work on non-Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698