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