| 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 collections | 10 import collections |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 # Before we do anything, break all git_cache locks. | 536 # Before we do anything, break all git_cache locks. |
| 537 if path.isdir(git_cache_dir): | 537 if path.isdir(git_cache_dir): |
| 538 git('cache', 'unlock', '-vv', '--force', '--all', | 538 git('cache', 'unlock', '-vv', '--force', '--all', |
| 539 '--cache-dir', git_cache_dir) | 539 '--cache-dir', git_cache_dir) |
| 540 for item in os.listdir(git_cache_dir): | 540 for item in os.listdir(git_cache_dir): |
| 541 filename = os.path.join(git_cache_dir, item) | 541 filename = os.path.join(git_cache_dir, item) |
| 542 if item.endswith('.lock'): | 542 if item.endswith('.lock'): |
| 543 raise Exception('%s exists after cache unlock' % filename) | 543 raise Exception('%s exists after cache unlock' % filename) |
| 544 first_solution = True | 544 first_solution = True |
| 545 for sln in solutions: | 545 for sln in solutions: |
| 546 # This is so we can loop back and try again if we need to wait for the | 546 # Just in case we're hitting a different git server than the one from |
| 547 # git mirrors to update from SVN. | 547 # which the target revision was polled, we retry some. |
| 548 done = False | 548 done = False |
| 549 tries_left = 60 | 549 deadline = time.time() + 60 # One minute (5 tries with exp. backoff). |
| 550 tries = 0 |
| 550 while not done: | 551 while not done: |
| 551 name = sln['name'] | 552 name = sln['name'] |
| 552 url = sln['url'] | 553 url = sln['url'] |
| 553 if url == CHROMIUM_SRC_URL or url + '.git' == CHROMIUM_SRC_URL: | 554 if url == CHROMIUM_SRC_URL or url + '.git' == CHROMIUM_SRC_URL: |
| 554 # Experiments show there's little to be gained from | 555 # Experiments show there's little to be gained from |
| 555 # a shallow clone of src. | 556 # a shallow clone of src. |
| 556 shallow = False | 557 shallow = False |
| 557 sln_dir = path.join(build_dir, name) | 558 sln_dir = path.join(build_dir, name) |
| 558 s = ['--shallow'] if shallow else [] | 559 s = ['--shallow'] if shallow else [] |
| 559 populate_cmd = (['cache', 'populate', '--ignore_locks', '-v', | 560 populate_cmd = (['cache', 'populate', '--ignore_locks', '-v', |
| (...skipping 15 matching lines...) Expand all Loading... |
| 575 git('fetch', 'origin', cwd=sln_dir) | 576 git('fetch', 'origin', cwd=sln_dir) |
| 576 for ref in refs: | 577 for ref in refs: |
| 577 refspec = '%s:%s' % (ref, ref.lstrip('+')) | 578 refspec = '%s:%s' % (ref, ref.lstrip('+')) |
| 578 git('fetch', 'origin', refspec, cwd=sln_dir) | 579 git('fetch', 'origin', refspec, cwd=sln_dir) |
| 579 | 580 |
| 580 revision = get_target_revision(name, url, revisions) or 'HEAD' | 581 revision = get_target_revision(name, url, revisions) or 'HEAD' |
| 581 force_revision(sln_dir, revision) | 582 force_revision(sln_dir, revision) |
| 582 done = True | 583 done = True |
| 583 except SubprocessFailed as e: | 584 except SubprocessFailed as e: |
| 584 # Exited abnormally, theres probably something wrong. | 585 # Exited abnormally, theres probably something wrong. |
| 586 print 'Something failed: %s.' % str(e) |
| 587 |
| 588 if time.time() > deadline: |
| 589 overrun = time.time() - deadline |
| 590 print 'Ran %s seconds past deadline. Aborting.' % overrun |
| 591 raise |
| 592 |
| 585 # Lets wipe the checkout and try again. | 593 # Lets wipe the checkout and try again. |
| 586 tries_left -= 1 | 594 tries += 1 |
| 587 if tries_left > 0: | 595 sleep_secs = 2**tries |
| 588 print 'Something failed: %s.' % str(e) | 596 print 'waiting %s seconds and trying again...' % sleep_secs |
| 589 print 'waiting 5 seconds and trying again...' | 597 time.sleep(sleep_secs) |
| 590 time.sleep(5) | |
| 591 else: | |
| 592 raise | |
| 593 remove(sln_dir) | 598 remove(sln_dir) |
| 594 | 599 |
| 595 git('clean', '-dff', cwd=sln_dir) | 600 git('clean', '-dff', cwd=sln_dir) |
| 596 | 601 |
| 597 if first_solution: | 602 if first_solution: |
| 598 git_ref = git('log', '--format=%H', '--max-count=1', | 603 git_ref = git('log', '--format=%H', '--max-count=1', |
| 599 cwd=sln_dir).strip() | 604 cwd=sln_dir).strip() |
| 600 first_solution = False | 605 first_solution = False |
| 601 return git_ref | 606 return git_ref |
| 602 | 607 |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1190 except Exception: | 1195 except Exception: |
| 1191 # Unexpected failure. | 1196 # Unexpected failure. |
| 1192 emit_flag(options.flag_file) | 1197 emit_flag(options.flag_file) |
| 1193 raise | 1198 raise |
| 1194 else: | 1199 else: |
| 1195 emit_flag(options.flag_file) | 1200 emit_flag(options.flag_file) |
| 1196 | 1201 |
| 1197 | 1202 |
| 1198 if __name__ == '__main__': | 1203 if __name__ == '__main__': |
| 1199 sys.exit(main()) | 1204 sys.exit(main()) |
| OLD | NEW |