blob: c4f3c53b550eea2086ff74ebe3418e9a58ec2794 [file] [log] [blame]
Kuang-che Wu875c89a2020-01-08 14:30:55 +08001#!/usr/bin/env python3
Kuang-che Wu6e4beca2018-06-27 17:45:02 +08002# -*- coding: utf-8 -*-
Kuang-che Wubfc4a642018-04-19 11:54:08 +08003# 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
8Example:
Kuang-che Wu94f48e52018-07-25 15:28:31 +08009 $ ./bisect_cros_repo.py init --old rev1 --new rev2 \\
10 --chromeos_root ~/chromiumos \\
Kuang-che Wud8fc9572018-10-03 21:00:41 +080011 --chromeos_mirror $CHROMEOS_MIRROR
Kuang-che Wubfc4a642018-04-19 11:54:08 +080012 $ ./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
16When running switcher and evaluator, following environment variables
17will be set:
18 BOARD (e.g. samus),
19 DUT (e.g. samus-dut),
Kuang-che Wu99e808f2019-06-26 12:17:32 +080020 CROS_VERSION (e.g. 9901.0.0,9902.0.0+3), and
Kuang-che Wuc95fc152018-06-28 18:13:22 +080021 CHROMEOS_ROOT (e.g. ~/chromiumos).
Kuang-che Wubfc4a642018-04-19 11:54:08 +080022"""
23
24from __future__ import print_function
25import logging
26
Kuang-che Wu2526a672019-09-10 16:23:59 +080027from bisect_kit import bisector_cli
Kuang-che Wubfc4a642018-04-19 11:54:08 +080028from bisect_kit import cli
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080029from bisect_kit import codechange
Kuang-che Wubfc4a642018-04-19 11:54:08 +080030from bisect_kit import configure
31from bisect_kit import core
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080032from bisect_kit import cros_util
Kuang-che Wue121fae2018-11-09 16:18:39 +080033from bisect_kit import errors
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080034from bisect_kit import repo_util
Kuang-che Wubfc4a642018-04-19 11:54:08 +080035
36logger = logging.getLogger(__name__)
37
38
Kuang-che Wue80bb872018-11-15 19:45:25 +080039def 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 Wubfc4a642018-04-19 11:54:08 +080045class ChromeOSRepoDomain(core.BisectDomain):
46 """BisectDomain for ChromeOS code changes."""
47 revtype = staticmethod(cros_util.argtype_cros_version)
Kuang-che Wu752228c2018-09-05 13:54:22 +080048 intra_revtype = staticmethod(
49 codechange.argtype_intra_rev(cros_util.argtype_cros_version))
Kuang-che Wubfc4a642018-04-19 11:54:08 +080050 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 Wue4bae0b2018-07-19 12:10:14 +080058 default=configure.get('DUT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080059 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 Wuc95fc152018-06-28 18:13:22 +080066 '--chromeos_root',
67 metavar='CHROMEOS_ROOT',
Kuang-che Wubfc4a642018-04-19 11:54:08 +080068 type=cli.argtype_dir_path,
69 required=True,
Kuang-che Wuc95fc152018-06-28 18:13:22 +080070 default=configure.get('CHROMEOS_ROOT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080071 help='ChromeOS tree root')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080072 parser.add_argument(
Kuang-che Wud8fc9572018-10-03 21:00:41 +080073 '--chromeos_mirror',
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080074 type=cli.argtype_dir_path,
Kuang-che Wud8fc9572018-10-03 21:00:41 +080075 default=configure.get('CHROMEOS_MIRROR', ''),
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080076 help='ChromeOS repo mirror path')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080077
78 @staticmethod
79 def init(opts):
80 if not opts.dut and not opts.board:
Kuang-che Wue121fae2018-11-09 16:18:39 +080081 raise errors.ArgumentError('--dut and --board', 'Neither is specified')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080082
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 Wuae6824b2019-08-27 22:20:01 +080087 'recommended to specify --dut in bisector instead of '
88 'switcher and evaluator.')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080089
90 if not opts.board:
91 opts.board = cros_util.query_dut_board(opts.dut)
92
Kuang-che Wu430c5282021-01-27 21:10:25 +080093 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 Wubfc4a642018-04-19 11:54:08 +080096 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 Wuc95fc152018-06-28 18:13:22 +0800102 repo_util.abandon(opts.chromeos_root, 'stabilizing_branch')
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800103
Kuang-che Wuc95fc152018-06-28 18:13:22 +0800104 config = dict(
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800105 dut=opts.dut,
106 board=opts.board,
107 chromeos_root=opts.chromeos_root,
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800108 chromeos_mirror=opts.chromeos_mirror)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800109
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800110 spec_manager = cros_util.ChromeOSSpecManager(config)
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800111 cache = repo_util.RepoMirror(opts.chromeos_mirror)
Zheng-Jie Changd968f552020-01-16 13:31:57 +0800112 code_manager = codechange.CodeManager(opts.chromeos_root, spec_manager,
113 cache)
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800114
Kuang-che Wu13acc7b2020-06-15 10:45:35 +0800115 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 Wue4bae0b2018-07-19 12:10:14 +0800119
Kuang-che Wu13acc7b2020-06-15 10:45:35 +0800120 return config, {'revlist': revlist, 'details': details}
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800121
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 Wuc95fc152018-06-28 18:13:22 +0800130 env['CHROMEOS_ROOT'] = self.config['chromeos_root']
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800131 env['CHROMEOS_MIRROR'] = self.config['chromeos_mirror']
Kuang-che Wu99e808f2019-06-26 12:17:32 +0800132 env['CROS_VERSION'] = rev
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800133
Kuang-che Wu13acc7b2020-06-15 10:45:35 +0800134 def fill_candidate_summary(self, summary):
Kuang-che Wu948a79c2019-06-19 19:13:56 +0800135 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 Wu948a79c2019-06-19 19:13:56 +0800139 summary['links'] = [
140 {
141 'name': 'change_list',
Zheng-Jie Chang5f9ae4e2020-02-07 14:26:06 +0800142 'url': cros_util.get_crosland_link(old_base, new_next),
Kuang-che Wu948a79c2019-06-19 19:13:56 +0800143 },
144 ]
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800145
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800146
147if __name__ == '__main__':
Kuang-che Wu2526a672019-09-10 16:23:59 +0800148 bisector_cli.BisectorCommandLine(ChromeOSRepoDomain).main()