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