OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 # TODO(hinoka): Use logging. | 6 # TODO(hinoka): Use logging. |
7 | 7 |
8 import cStringIO | 8 import cStringIO |
9 import codecs | 9 import codecs |
10 import copy | 10 import copy |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 cache_dir = r%(cache_dir)s | 75 cache_dir = r%(cache_dir)s |
76 %(target_os)s | 76 %(target_os)s |
77 %(target_os_only)s | 77 %(target_os_only)s |
78 """ | 78 """ |
79 | 79 |
80 | 80 |
81 # How many times to try before giving up. | 81 # How many times to try before giving up. |
82 ATTEMPTS = 5 | 82 ATTEMPTS = 5 |
83 | 83 |
84 GIT_CACHE_PATH = path.join(DEPOT_TOOLS_DIR, 'git_cache.py') | 84 GIT_CACHE_PATH = path.join(DEPOT_TOOLS_DIR, 'git_cache.py') |
| 85 GCLIENT_PATH = path.join(DEPOT_TOOLS_DIR, 'gclient.py') |
85 | 86 |
86 # If there is less than 100GB of disk space on the system, then we do | 87 # If there is less than 100GB of disk space on the system, then we do |
87 # a shallow checkout. | 88 # a shallow checkout. |
88 SHALLOW_CLONE_THRESHOLD = 100 * 1024 * 1024 * 1024 | 89 SHALLOW_CLONE_THRESHOLD = 100 * 1024 * 1024 * 1024 |
89 | 90 |
90 | 91 |
91 class SubprocessFailed(Exception): | 92 class SubprocessFailed(Exception): |
92 def __init__(self, message, code, output): | 93 def __init__(self, message, code, output): |
93 Exception.__init__(self, message) | 94 Exception.__init__(self, message) |
94 self.code = code | 95 self.code = code |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 has_checkout = any(path.exists(path.join(build_dir, dir_name, '.git')) | 313 has_checkout = any(path.exists(path.join(build_dir, dir_name, '.git')) |
313 for dir_name in dir_names) | 314 for dir_name in dir_names) |
314 if has_checkout: | 315 if has_checkout: |
315 for filename in os.listdir(build_dir): | 316 for filename in os.listdir(build_dir): |
316 deletion_target = path.join(build_dir, filename) | 317 deletion_target = path.join(build_dir, filename) |
317 print '.git detected in checkout, deleting %s...' % deletion_target, | 318 print '.git detected in checkout, deleting %s...' % deletion_target, |
318 remove(deletion_target) | 319 remove(deletion_target) |
319 print 'done' | 320 print 'done' |
320 | 321 |
321 | 322 |
| 323 def call_gclient(*args, **kwargs): |
| 324 """Run the "gclient.py" tool with the supplied arguments. |
| 325 |
| 326 Args: |
| 327 args: command-line arguments to pass to gclient. |
| 328 kwargs: keyword arguments to pass to call. |
| 329 """ |
| 330 cmd = [sys.executable, '-u', GCLIENT_PATH] |
| 331 cmd.extend(args) |
| 332 return call(*cmd, **kwargs) |
| 333 |
| 334 |
322 def gclient_configure(solutions, target_os, target_os_only, git_cache_dir): | 335 def gclient_configure(solutions, target_os, target_os_only, git_cache_dir): |
323 """Should do the same thing as gclient --spec='...'.""" | 336 """Should do the same thing as gclient --spec='...'.""" |
324 with codecs.open('.gclient', mode='w', encoding='utf-8') as f: | 337 with codecs.open('.gclient', mode='w', encoding='utf-8') as f: |
325 f.write(get_gclient_spec( | 338 f.write(get_gclient_spec( |
326 solutions, target_os, target_os_only, git_cache_dir)) | 339 solutions, target_os, target_os_only, git_cache_dir)) |
327 | 340 |
328 | 341 |
329 def gclient_sync(with_branch_heads, shallow, break_repo_locks): | 342 def gclient_sync(with_branch_heads, shallow, break_repo_locks): |
330 # We just need to allocate a filename. | 343 # We just need to allocate a filename. |
331 fd, gclient_output_file = tempfile.mkstemp(suffix='.json') | 344 fd, gclient_output_file = tempfile.mkstemp(suffix='.json') |
332 os.close(fd) | 345 os.close(fd) |
333 gclient_bin = 'gclient.bat' if sys.platform.startswith('win') else 'gclient' | 346 |
334 cmd = [gclient_bin, 'sync', '--verbose', '--reset', '--force', | 347 args = ['sync', '--verbose', '--reset', '--force', |
335 '--ignore_locks', '--output-json', gclient_output_file, | 348 '--ignore_locks', '--output-json', gclient_output_file, |
336 '--nohooks', '--noprehooks', '--delete_unversioned_trees'] | 349 '--nohooks', '--noprehooks', '--delete_unversioned_trees'] |
337 if with_branch_heads: | 350 if with_branch_heads: |
338 cmd += ['--with_branch_heads'] | 351 args += ['--with_branch_heads'] |
339 if shallow: | 352 if shallow: |
340 cmd += ['--shallow'] | 353 args += ['--shallow'] |
341 if break_repo_locks: | 354 if break_repo_locks: |
342 cmd += ['--break_repo_locks'] | 355 args += ['--break_repo_locks'] |
343 | 356 |
344 try: | 357 try: |
345 call(*cmd, tries=1) | 358 call_gclient(*args, tries=1) |
346 except SubprocessFailed as e: | 359 except SubprocessFailed as e: |
347 # Throw a GclientSyncFailed exception so we can catch this independently. | 360 # Throw a GclientSyncFailed exception so we can catch this independently. |
348 raise GclientSyncFailed(e.message, e.code, e.output) | 361 raise GclientSyncFailed(e.message, e.code, e.output) |
349 else: | 362 else: |
350 with open(gclient_output_file) as f: | 363 with open(gclient_output_file) as f: |
351 return json.load(f) | 364 return json.load(f) |
352 finally: | 365 finally: |
353 os.remove(gclient_output_file) | 366 os.remove(gclient_output_file) |
354 | 367 |
355 | 368 |
356 def gclient_revinfo(): | 369 def gclient_revinfo(): |
357 gclient_bin = 'gclient.bat' if sys.platform.startswith('win') else 'gclient' | 370 return call_gclient('revinfo', '-a') or '' |
358 return call(gclient_bin, 'revinfo', '-a') or '' | |
359 | 371 |
360 | 372 |
361 def create_manifest(): | 373 def create_manifest(): |
362 manifest = {} | 374 manifest = {} |
363 output = gclient_revinfo() | 375 output = gclient_revinfo() |
364 for line in output.strip().splitlines(): | 376 for line in output.strip().splitlines(): |
365 match = REVINFO_RE.match(line.strip()) | 377 match = REVINFO_RE.match(line.strip()) |
366 if match: | 378 if match: |
367 manifest[match.group(1)] = { | 379 manifest[match.group(1)] = { |
368 'repository': match.group(2), | 380 'repository': match.group(2), |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1131 # download patch failure is still an infra problem. | 1143 # download patch failure is still an infra problem. |
1132 if e.code == 3: | 1144 if e.code == 3: |
1133 # Patch download problem. | 1145 # Patch download problem. |
1134 return 87 | 1146 return 87 |
1135 # Genuine patch problem. | 1147 # Genuine patch problem. |
1136 return 88 | 1148 return 88 |
1137 | 1149 |
1138 | 1150 |
1139 if __name__ == '__main__': | 1151 if __name__ == '__main__': |
1140 sys.exit(main()) | 1152 sys.exit(main()) |
OLD | NEW |