Kuang-che Wu | 875c89a | 2020-01-08 14:30:55 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
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), |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 20 | CROS_VERSION (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 | |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 27 | from bisect_kit import bisector_cli |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 28 | from bisect_kit import cli |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 29 | from bisect_kit import codechange |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 30 | from bisect_kit import configure |
| 31 | from bisect_kit import core |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 32 | from bisect_kit import cros_util |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 33 | from bisect_kit import errors |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 34 | from bisect_kit import repo_util |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 35 | |
| 36 | logger = logging.getLogger(__name__) |
| 37 | |
| 38 | |
Kuang-che Wu | e80bb87 | 2018-11-15 19:45:25 +0800 | [diff] [blame] | 39 | def generate_action_link(action): |
| 40 | if action['action_type'] == 'commit': |
| 41 | repo_url = action['repo_url'] |
| 42 | action['link'] = repo_url + '/+/' + action['rev'] |
| 43 | |
| 44 | |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 45 | class ChromeOSRepoDomain(core.BisectDomain): |
| 46 | """BisectDomain for ChromeOS code changes.""" |
| 47 | revtype = staticmethod(cros_util.argtype_cros_version) |
Kuang-che Wu | 752228c | 2018-09-05 13:54:22 +0800 | [diff] [blame] | 48 | intra_revtype = staticmethod( |
| 49 | codechange.argtype_intra_rev(cros_util.argtype_cros_version)) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 50 | help = globals()['__doc__'] |
| 51 | |
| 52 | @staticmethod |
| 53 | def add_init_arguments(parser): |
| 54 | parser.add_argument( |
| 55 | '--dut', |
| 56 | type=cli.argtype_notempty, |
| 57 | metavar='DUT', |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 58 | default=configure.get('DUT'), |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 59 | help='DUT address') |
| 60 | parser.add_argument( |
| 61 | '--board', |
| 62 | metavar='BOARD', |
| 63 | default=configure.get('BOARD', ''), |
| 64 | help='ChromeOS board name') |
| 65 | parser.add_argument( |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 66 | '--chromeos_root', |
| 67 | metavar='CHROMEOS_ROOT', |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 68 | type=cli.argtype_dir_path, |
| 69 | required=True, |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 70 | default=configure.get('CHROMEOS_ROOT'), |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 71 | help='ChromeOS tree root') |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 72 | parser.add_argument( |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 73 | '--chromeos_mirror', |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 74 | type=cli.argtype_dir_path, |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 75 | default=configure.get('CHROMEOS_MIRROR', ''), |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 76 | help='ChromeOS repo mirror path') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 77 | |
| 78 | @staticmethod |
| 79 | def init(opts): |
| 80 | if not opts.dut and not opts.board: |
Kuang-che Wu | e121fae | 2018-11-09 16:18:39 +0800 | [diff] [blame] | 81 | raise errors.ArgumentError('--dut and --board', 'Neither is specified') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 82 | |
| 83 | if opts.dut: |
| 84 | assert cros_util.is_dut(opts.dut) |
| 85 | else: |
| 86 | logger.info("Tips: unless you don't need to build, otherwise it's " |
Kuang-che Wu | ae6824b | 2019-08-27 22:20:01 +0800 | [diff] [blame] | 87 | 'recommended to specify --dut in bisector instead of ' |
| 88 | 'switcher and evaluator.') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 89 | |
| 90 | if not opts.board: |
| 91 | opts.board = cros_util.query_dut_board(opts.dut) |
| 92 | |
Kuang-che Wu | 430c528 | 2021-01-27 21:10:25 +0800 | [diff] [blame] | 93 | if not cros_util.is_ancestor_version(opts.old, opts.new): |
| 94 | raise errors.ArgumentError( |
| 95 | '--old and --new', '%s is not ancestor of %s' % (opts.old, opts.new)) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 96 | if cros_util.is_cros_short_version(opts.old): |
| 97 | opts.old = cros_util.version_to_full(opts.board, opts.old) |
| 98 | if cros_util.is_cros_short_version(opts.new): |
| 99 | opts.new = cros_util.version_to_full(opts.board, opts.new) |
| 100 | |
| 101 | logger.info('Clean up previous result of "mark as stable"') |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 102 | repo_util.abandon(opts.chromeos_root, 'stabilizing_branch') |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 103 | |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 104 | config = dict( |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 105 | dut=opts.dut, |
| 106 | board=opts.board, |
| 107 | chromeos_root=opts.chromeos_root, |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 108 | chromeos_mirror=opts.chromeos_mirror) |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 109 | |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 110 | spec_manager = cros_util.ChromeOSSpecManager(config) |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 111 | cache = repo_util.RepoMirror(opts.chromeos_mirror) |
Zheng-Jie Chang | d968f55 | 2020-01-16 13:31:57 +0800 | [diff] [blame] | 112 | code_manager = codechange.CodeManager(opts.chromeos_root, spec_manager, |
| 113 | cache) |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 114 | |
Kuang-che Wu | 13acc7b | 2020-06-15 10:45:35 +0800 | [diff] [blame] | 115 | revlist, details = code_manager.build_revlist(opts.old, opts.new) |
| 116 | for detail in details.values(): |
| 117 | for action in detail.get('actions', []): |
| 118 | generate_action_link(action) |
Kuang-che Wu | e4bae0b | 2018-07-19 12:10:14 +0800 | [diff] [blame] | 119 | |
Kuang-che Wu | 13acc7b | 2020-06-15 10:45:35 +0800 | [diff] [blame] | 120 | return config, {'revlist': revlist, 'details': details} |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 121 | |
| 122 | def __init__(self, config): |
| 123 | self.config = config |
| 124 | |
| 125 | def setenv(self, env, rev): |
| 126 | if self.config['dut']: |
| 127 | env['DUT'] = self.config['dut'] |
| 128 | if self.config['board']: |
| 129 | env['BOARD'] = self.config['board'] |
Kuang-che Wu | c95fc15 | 2018-06-28 18:13:22 +0800 | [diff] [blame] | 130 | env['CHROMEOS_ROOT'] = self.config['chromeos_root'] |
Kuang-che Wu | d8fc957 | 2018-10-03 21:00:41 +0800 | [diff] [blame] | 131 | env['CHROMEOS_MIRROR'] = self.config['chromeos_mirror'] |
Kuang-che Wu | 99e808f | 2019-06-26 12:17:32 +0800 | [diff] [blame] | 132 | env['CROS_VERSION'] = rev |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 133 | |
Kuang-che Wu | 13acc7b | 2020-06-15 10:45:35 +0800 | [diff] [blame] | 134 | def fill_candidate_summary(self, summary): |
Kuang-che Wu | 948a79c | 2019-06-19 19:13:56 +0800 | [diff] [blame] | 135 | if 'current_range' in summary: |
| 136 | old, new = summary['current_range'] |
| 137 | old_base, _, _ = codechange.parse_intra_rev(old) |
| 138 | _, new_next, _ = codechange.parse_intra_rev(new) |
Kuang-che Wu | 948a79c | 2019-06-19 19:13:56 +0800 | [diff] [blame] | 139 | summary['links'] = [ |
| 140 | { |
| 141 | 'name': 'change_list', |
Zheng-Jie Chang | 5f9ae4e | 2020-02-07 14:26:06 +0800 | [diff] [blame] | 142 | 'url': cros_util.get_crosland_link(old_base, new_next), |
Kuang-che Wu | 948a79c | 2019-06-19 19:13:56 +0800 | [diff] [blame] | 143 | }, |
| 144 | ] |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 145 | |
Kuang-che Wu | bfc4a64 | 2018-04-19 11:54:08 +0800 | [diff] [blame] | 146 | |
| 147 | if __name__ == '__main__': |
Kuang-che Wu | 2526a67 | 2019-09-10 16:23:59 +0800 | [diff] [blame] | 148 | bisector_cli.BisectorCommandLine(ChromeOSRepoDomain).main() |