| #!/usr/bin/python |
| # Copyright 2017 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| from os import path |
| import subprocess |
| import sys |
| |
| BLACKLIST_FILE_PATH = path.join(path.dirname(path.abspath(__file__)), 'blink_revisions_blacklist') |
| UPLOADED_REVS_FILE_PATH = path.join(path.dirname(path.abspath(__file__)), 'uploaded_revs.txt') |
| |
| # For info on exit codes for bisect scripts: |
| # https://git-scm.com/docs/git-bisect#_bisect_run |
| GIT_BISECT_SKIP_EXIT_CODE = 125 |
| GIT_ABORT_BISECT_EXIT_CODE = 128 |
| |
| |
| def main(): |
| if len(sys.argv) < 2: |
| print('Must include google storage path to revs') |
| sys.exit(GIT_ABORT_BISECT_EXIT_CODE) |
| storage_prefix = sys.argv[1] |
| revision = query_revision() |
| if is_blacklisted(revision): |
| print('Rev is blacklisted') |
| sys.exit(GIT_BISECT_SKIP_EXIT_CODE) |
| else: |
| check_if_revision_stored(storage_prefix, revision) |
| |
| |
| def query_revision(): |
| git_rev_process = popen(['git', 'rev-parse', 'BISECT_HEAD']) |
| git_rev_out, _ = git_rev_process.communicate() |
| if git_rev_process.returncode: |
| print('Error finding revision for BISECT_HEAD') |
| print(git_rev_out) |
| sys.exit(1) |
| return git_rev_out.strip() |
| |
| |
| def is_blacklisted(revision): |
| with open(BLACKLIST_FILE_PATH, 'r') as blacklist_file: |
| blacklist_revisions = blacklist_file.readlines()[0].split() |
| return revision in blacklist_revisions |
| |
| def is_uploaded(revision_storage_path): |
| with open(UPLOADED_REVS_FILE_PATH, 'r') as uploaded_revs_file: |
| revs = uploaded_revs_file.readlines() |
| return revision_storage_path + '\n' in revs |
| |
| def check_if_revision_stored(storage_prefix, revision): |
| revision_storage_path = '{}{}'.format(storage_prefix, revision) |
| if is_uploaded(revision_storage_path): |
| print('Found as uploaded') |
| sys.exit(0) |
| print('Could not find revision', revision) |
| sys.exit(1) |
| |
| |
| def popen(arguments): |
| return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| |
| |
| if __name__ == '__main__': |
| main() |