Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
Kuang-che Wu | 6e4beca | 2018-06-27 17:45:02 +0800 | [diff] [blame] | 2 | # -*- coding: utf-8 -*- |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 3 | # Copyright 2018 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """ChromeOS bisector to bisect local build commits. |
| 7 | |
| 8 | Example: |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 9 | $ ./bisect_cros_repo.py init --old rev1 --new rev2 \ |
| 10 | --chromeos_root ~/chromiumos |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 11 | $ ./bisect_cros_repo.py config switch ./switch_cros_localbuild.py |
| 12 | $ ./bisect_cros_repo.py config eval ./eval-manually.sh |
| 13 | $ ./bisect_cros_repo.py run |
| 14 | |
| 15 | When running switcher and evaluator, following environment variables |
| 16 | will be set: |
| 17 | BOARD (e.g. samus), |
| 18 | DUT (e.g. samus-dut), |
| 19 | INTRA_REV (e.g. 9901.0.0,9902.0.0+3), and |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 20 | CHROMEOS_ROOT (e.g. ~/chromiumos). |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 21 | """ |
| 22 | |
| 23 | from __future__ import print_function |
| 24 | import logging |
| 25 | |
| 26 | from bisect_kit import cli |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 27 | from bisect_kit import codechange |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 28 | from bisect_kit import configure |
| 29 | from bisect_kit import core |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 30 | from bisect_kit import cros_util |
| 31 | from bisect_kit import repo_util |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 32 | |
| 33 | logger = logging.getLogger(__name__) |
| 34 | |
| 35 | |
| 36 | class ChromeOSRepoDomain(core.BisectDomain): |
| 37 | """BisectDomain for ChromeOS code changes.""" |
| 38 | revtype = staticmethod(cros_util.argtype_cros_version) |
| 39 | help = globals()['__doc__'] |
| 40 | |
| 41 | @staticmethod |
| 42 | def add_init_arguments(parser): |
| 43 | parser.add_argument( |
| 44 | '--dut', |
| 45 | type=cli.argtype_notempty, |
| 46 | metavar='DUT', |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 47 | default=configure.get('DUT'), |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 48 | help='DUT address') |
| 49 | parser.add_argument( |
| 50 | '--board', |
| 51 | metavar='BOARD', |
| 52 | default=configure.get('BOARD', ''), |
| 53 | help='ChromeOS board name') |
| 54 | parser.add_argument( |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 55 | '--chromeos_root', |
| 56 | metavar='CHROMEOS_ROOT', |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 57 | type=cli.argtype_dir_path, |
| 58 | required=True, |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 59 | default=configure.get('CHROMEOS_ROOT'), |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 60 | help='ChromeOS tree root') |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 61 | parser.add_argument( |
| 62 | '--chromeos_repo_mirror_dir', |
| 63 | type=cli.argtype_dir_path, |
| 64 | default=configure.get('CHROMEOS_REPO_MIRROR_DIR', ''), |
| 65 | help='ChromeOS repo mirror path') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 66 | |
| 67 | @staticmethod |
| 68 | def init(opts): |
| 69 | if not opts.dut and not opts.board: |
| 70 | raise core.ExecutionFatalError('Neither --dut nor --board is specified') |
| 71 | |
| 72 | if opts.dut: |
| 73 | assert cros_util.is_dut(opts.dut) |
| 74 | else: |
| 75 | logger.info("Tips: unless you don't need to build, otherwise it's " |
| 76 | "recommended to specify --dut in bisector instead of " |
| 77 | "switcher and evaluator.") |
| 78 | |
| 79 | if not opts.board: |
| 80 | opts.board = cros_util.query_dut_board(opts.dut) |
| 81 | |
| 82 | if cros_util.is_cros_short_version(opts.old): |
| 83 | opts.old = cros_util.version_to_full(opts.board, opts.old) |
| 84 | if cros_util.is_cros_short_version(opts.new): |
| 85 | opts.new = cros_util.version_to_full(opts.board, opts.new) |
| 86 | |
| 87 | logger.info('Clean up previous result of "mark as stable"') |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 88 | repo_util.abandon(opts.chromeos_root, 'stabilizing_branch') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 89 | |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 90 | config = dict( |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 91 | dut=opts.dut, |
| 92 | board=opts.board, |
| 93 | chromeos_root=opts.chromeos_root, |
| 94 | chromeos_repo_mirror_dir=opts.chromeos_repo_mirror_dir) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 95 | |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 96 | spec_manager = cros_util.ChromeOSSpecManager(config) |
| 97 | cache = repo_util.RepoMirror(opts.chromeos_repo_mirror_dir) |
| 98 | |
| 99 | # Make sure all repos in between are cached |
| 100 | float_specs = spec_manager.collect_float_spec(opts.old, opts.new) |
| 101 | for spec in reversed(float_specs): |
| 102 | spec_manager.parse_spec(spec) |
| 103 | if cache.are_spec_commits_available(spec): |
| 104 | continue |
| 105 | spec_manager.sync_disk_state(spec.name) |
| 106 | |
| 107 | code_manager = codechange.CodeManager(opts.chromeos_root, spec_manager, |
| 108 | cache) |
| 109 | revlist = code_manager.build_revlist(opts.old, opts.new) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 110 | return config, revlist |
| 111 | |
| 112 | def __init__(self, config): |
| 113 | self.config = config |
| 114 | |
| 115 | def setenv(self, env, rev): |
| 116 | if self.config['dut']: |
| 117 | env['DUT'] = self.config['dut'] |
| 118 | if self.config['board']: |
| 119 | env['BOARD'] = self.config['board'] |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 120 | env['CHROMEOS_ROOT'] = self.config['chromeos_root'] |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 121 | env['CHROMEOS_REPO_MIRROR_DIR'] = self.config['chromeos_repo_mirror_dir'] |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 122 | env['INTRA_REV'] = rev |
| 123 | |
| 124 | def view(self, old, new): |
| 125 | print('old', old) |
| 126 | print('new', new) |
| 127 | |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 128 | spec_manager = cros_util.ChromeOSSpecManager(self.config) |
| 129 | cache = repo_util.RepoMirror(self.config['chromeos_repo_mirror_dir']) |
| 130 | code_manager = codechange.CodeManager(self.config['chromeos_root'], |
| 131 | spec_manager, cache) |
| 132 | code_manager.view_rev_diff(old, new) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 133 | |
| 134 | |
| 135 | if __name__ == '__main__': |
| 136 | cli.BisectorCommandLine(ChromeOSRepoDomain).main() |