blob: 08574a9d2300f961afd3f1247ae3ed404589784a [file] [log] [blame]
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001#!/usr/bin/env python2
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),
20 INTRA_REV (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
27from bisect_kit import cli
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080028from bisect_kit import codechange
Kuang-che Wubfc4a642018-04-19 11:54:08 +080029from bisect_kit import configure
30from bisect_kit import core
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080031from bisect_kit import cros_util
32from bisect_kit import repo_util
Kuang-che Wubfc4a642018-04-19 11:54:08 +080033
34logger = logging.getLogger(__name__)
35
36
37class ChromeOSRepoDomain(core.BisectDomain):
38 """BisectDomain for ChromeOS code changes."""
39 revtype = staticmethod(cros_util.argtype_cros_version)
Kuang-che Wu752228c2018-09-05 13:54:22 +080040 intra_revtype = staticmethod(
41 codechange.argtype_intra_rev(cros_util.argtype_cros_version))
Kuang-che Wubfc4a642018-04-19 11:54:08 +080042 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 Wue4bae0b2018-07-19 12:10:14 +080050 default=configure.get('DUT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080051 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 Wuc95fc152018-06-28 18:13:22 +080058 '--chromeos_root',
59 metavar='CHROMEOS_ROOT',
Kuang-che Wubfc4a642018-04-19 11:54:08 +080060 type=cli.argtype_dir_path,
61 required=True,
Kuang-che Wuc95fc152018-06-28 18:13:22 +080062 default=configure.get('CHROMEOS_ROOT'),
Kuang-che Wubfc4a642018-04-19 11:54:08 +080063 help='ChromeOS tree root')
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080064 parser.add_argument(
Kuang-che Wud8fc9572018-10-03 21:00:41 +080065 '--chromeos_mirror',
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080066 type=cli.argtype_dir_path,
Kuang-che Wud8fc9572018-10-03 21:00:41 +080067 default=configure.get('CHROMEOS_MIRROR', ''),
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080068 help='ChromeOS repo mirror path')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080069
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 Wuc95fc152018-06-28 18:13:22 +080091 repo_util.abandon(opts.chromeos_root, 'stabilizing_branch')
Kuang-che Wubfc4a642018-04-19 11:54:08 +080092
Kuang-che Wuc95fc152018-06-28 18:13:22 +080093 config = dict(
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080094 dut=opts.dut,
95 board=opts.board,
96 chromeos_root=opts.chromeos_root,
Kuang-che Wud8fc9572018-10-03 21:00:41 +080097 chromeos_mirror=opts.chromeos_mirror)
Kuang-che Wubfc4a642018-04-19 11:54:08 +080098
Kuang-che Wue4bae0b2018-07-19 12:10:14 +080099 spec_manager = cros_util.ChromeOSSpecManager(config)
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800100 cache = repo_util.RepoMirror(opts.chromeos_mirror)
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800101
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 Wubfc4a642018-04-19 11:54:08 +0800113 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 Wuc95fc152018-06-28 18:13:22 +0800123 env['CHROMEOS_ROOT'] = self.config['chromeos_root']
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800124 env['CHROMEOS_MIRROR'] = self.config['chromeos_mirror']
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800125 env['INTRA_REV'] = rev
126
127 def view(self, old, new):
128 print('old', old)
129 print('new', new)
130
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800131 spec_manager = cros_util.ChromeOSSpecManager(self.config)
Kuang-che Wud8fc9572018-10-03 21:00:41 +0800132 cache = repo_util.RepoMirror(self.config['chromeos_mirror'])
Kuang-che Wue4bae0b2018-07-19 12:10:14 +0800133 code_manager = codechange.CodeManager(self.config['chromeos_root'],
134 spec_manager, cache)
135 code_manager.view_rev_diff(old, new)
Kuang-che Wubfc4a642018-04-19 11:54:08 +0800136
137
138if __name__ == '__main__':
139 cli.BisectorCommandLine(ChromeOSRepoDomain).main()