blob: 47853aff09186c0db28b0e6d21bc1776aee05644 [file] [log] [blame]
Kuang-che Wubfc4a642018-04-19 11:54:08 +08001#!/usr/bin/env python2
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""ChromeOS bisector to bisect local build commits.
6
7Example:
8 $ ./bisect_cros_repo.py init --old rev1 --new rev2 --repo_dir ~/chromiumos
9 $ ./bisect_cros_repo.py config switch ./switch_cros_localbuild.py
10 $ ./bisect_cros_repo.py config eval ./eval-manually.sh
11 $ ./bisect_cros_repo.py run
12
13When running switcher and evaluator, following environment variables
14will be set:
15 BOARD (e.g. samus),
16 DUT (e.g. samus-dut),
17 INTRA_REV (e.g. 9901.0.0,9902.0.0+3), and
18 REPO_DIR (e.g. ~/chromiumos).
19"""
20
21from __future__ import print_function
22import logging
23
24from bisect_kit import cli
25from bisect_kit import cros_util
26from bisect_kit import repo_util
27from bisect_kit import configure
28from bisect_kit import core
29
30logger = logging.getLogger(__name__)
31
32
33class ChromeOSRepoDomain(core.BisectDomain):
34 """BisectDomain for ChromeOS code changes."""
35 revtype = staticmethod(cros_util.argtype_cros_version)
36 help = globals()['__doc__']
37
38 @staticmethod
39 def add_init_arguments(parser):
40 parser.add_argument(
41 '--dut',
42 type=cli.argtype_notempty,
43 metavar='DUT',
44 default=configure.get('DUT', ''),
45 help='DUT address')
46 parser.add_argument(
47 '--board',
48 metavar='BOARD',
49 default=configure.get('BOARD', ''),
50 help='ChromeOS board name')
51 parser.add_argument(
52 '--repo_dir',
53 metavar='REPO_DIR',
54 type=cli.argtype_dir_path,
55 required=True,
56 default=configure.get('REPO_DIR'),
57 help='ChromeOS tree root')
58
59 @staticmethod
60 def init(opts):
61 if not opts.dut and not opts.board:
62 raise core.ExecutionFatalError('Neither --dut nor --board is specified')
63
64 if opts.dut:
65 assert cros_util.is_dut(opts.dut)
66 else:
67 logger.info("Tips: unless you don't need to build, otherwise it's "
68 "recommended to specify --dut in bisector instead of "
69 "switcher and evaluator.")
70
71 if not opts.board:
72 opts.board = cros_util.query_dut_board(opts.dut)
73
74 if cros_util.is_cros_short_version(opts.old):
75 opts.old = cros_util.version_to_full(opts.board, opts.old)
76 if cros_util.is_cros_short_version(opts.new):
77 opts.new = cros_util.version_to_full(opts.board, opts.new)
78
79 logger.info('Clean up previous result of "mark as stable"')
80 repo_util.abandon(opts.repo_dir, 'stabilizing_branch')
81
82 config = dict(dut=opts.dut, board=opts.board, repo_dir=opts.repo_dir)
83
84 manifest_manager = cros_util.ChromeOSManifestManager(config)
85 dependency_manager = repo_util.DependencyManager(opts.repo_dir,
86 manifest_manager)
87 revlist = dependency_manager.get_revlist(opts.old, opts.new)
88 return config, revlist
89
90 def __init__(self, config):
91 self.config = config
92
93 def setenv(self, env, rev):
94 if self.config['dut']:
95 env['DUT'] = self.config['dut']
96 if self.config['board']:
97 env['BOARD'] = self.config['board']
98 env['REPO_DIR'] = self.config['repo_dir']
99 env['INTRA_REV'] = rev
100
101 def view(self, old, new):
102 print('old', old)
103 print('new', new)
104
105 manifest_manager = cros_util.ChromeOSManifestManager(self.config)
106 dependency_manager = repo_util.DependencyManager(self.config['repo_dir'],
107 manifest_manager)
108 dependency_manager.view_rev_diff(old, new)
109
110
111if __name__ == '__main__':
112 cli.BisectorCommandLine(ChromeOSRepoDomain).main()