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 \\ |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 11 | --chromeos_mirror $CHROMEOS_MIRROR |
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) |
Kuang-che Wu | 752228c | 2018-09-05 13:54:22 +0800 | [diff] [blame] | 40 | intra_revtype = staticmethod( |
| 41 | codechange.argtype_intra_rev(cros_util.argtype_cros_version)) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 42 | help = globals()['__doc__'] |
| 43 | |
| 44 | @staticmethod |
| 45 | def add_init_arguments(parser): |
| 46 | parser.add_argument( |
| 47 | '--dut', |
| 48 | type=cli.argtype_notempty, |
| 49 | metavar='DUT', |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 50 | default=configure.get('DUT'), |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 51 | help='DUT address') |
| 52 | parser.add_argument( |
| 53 | '--board', |
| 54 | metavar='BOARD', |
| 55 | default=configure.get('BOARD', ''), |
| 56 | help='ChromeOS board name') |
| 57 | parser.add_argument( |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 58 | '--chromeos_root', |
| 59 | metavar='CHROMEOS_ROOT', |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 60 | type=cli.argtype_dir_path, |
| 61 | required=True, |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 62 | default=configure.get('CHROMEOS_ROOT'), |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 63 | help='ChromeOS tree root') |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 64 | parser.add_argument( |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 65 | '--chromeos_mirror', |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 66 | type=cli.argtype_dir_path, |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 67 | default=configure.get('CHROMEOS_MIRROR', ''), |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 68 | help='ChromeOS repo mirror path') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 69 | |
| 70 | @staticmethod |
| 71 | def init(opts): |
| 72 | if not opts.dut and not opts.board: |
| 73 | raise core.ExecutionFatalError('Neither --dut nor --board is specified') |
| 74 | |
| 75 | if opts.dut: |
| 76 | assert cros_util.is_dut(opts.dut) |
| 77 | else: |
| 78 | logger.info("Tips: unless you don't need to build, otherwise it's " |
| 79 | "recommended to specify --dut in bisector instead of " |
| 80 | "switcher and evaluator.") |
| 81 | |
| 82 | if not opts.board: |
| 83 | opts.board = cros_util.query_dut_board(opts.dut) |
| 84 | |
| 85 | if cros_util.is_cros_short_version(opts.old): |
| 86 | opts.old = cros_util.version_to_full(opts.board, opts.old) |
| 87 | if cros_util.is_cros_short_version(opts.new): |
| 88 | opts.new = cros_util.version_to_full(opts.board, opts.new) |
| 89 | |
| 90 | logger.info('Clean up previous result of "mark as stable"') |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 91 | repo_util.abandon(opts.chromeos_root, 'stabilizing_branch') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 92 | |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 93 | config = dict( |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 94 | dut=opts.dut, |
| 95 | board=opts.board, |
| 96 | chromeos_root=opts.chromeos_root, |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 97 | chromeos_mirror=opts.chromeos_mirror) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 98 | |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 99 | spec_manager = cros_util.ChromeOSSpecManager(config) |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 100 | cache = repo_util.RepoMirror(opts.chromeos_mirror) |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 101 | |
| 102 | # Make sure all repos in between are cached |
| 103 | float_specs = spec_manager.collect_float_spec(opts.old, opts.new) |
| 104 | for spec in reversed(float_specs): |
| 105 | spec_manager.parse_spec(spec) |
| 106 | if cache.are_spec_commits_available(spec): |
| 107 | continue |
| 108 | spec_manager.sync_disk_state(spec.name) |
| 109 | |
| 110 | code_manager = codechange.CodeManager(opts.chromeos_root, spec_manager, |
| 111 | cache) |
| 112 | revlist = code_manager.build_revlist(opts.old, opts.new) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 113 | return config, revlist |
| 114 | |
| 115 | def __init__(self, config): |
| 116 | self.config = config |
| 117 | |
| 118 | def setenv(self, env, rev): |
| 119 | if self.config['dut']: |
| 120 | env['DUT'] = self.config['dut'] |
| 121 | if self.config['board']: |
| 122 | env['BOARD'] = self.config['board'] |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 123 | env['CHROMEOS_ROOT'] = self.config['chromeos_root'] |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 124 | env['CHROMEOS_MIRROR'] = self.config['chromeos_mirror'] |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 125 | env['INTRA_REV'] = rev |
| 126 | |
| 127 | def view(self, old, new): |
| 128 | print('old', old) |
| 129 | print('new', new) |
| 130 | |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 131 | spec_manager = cros_util.ChromeOSSpecManager(self.config) |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 132 | cache = repo_util.RepoMirror(self.config['chromeos_mirror']) |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 133 | code_manager = codechange.CodeManager(self.config['chromeos_root'], |
| 134 | spec_manager, cache) |
| 135 | code_manager.view_rev_diff(old, new) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 136 | |
| 137 | |
| 138 | if __name__ == '__main__': |
| 139 | cli.BisectorCommandLine(ChromeOSRepoDomain).main() |