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