blob: 95e516c8aac029da59c7c3ce6c9fa42b019d1cc1 [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 Wu708310b2018-03-28 17:24:34 +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"""Android bisector to bisect a range of android build id.
7
8Example:
9 $ ./bisect_android_build_id.py init --old rev1 --new rev2 --dut DUT
10 $ ./bisect_android_build_id.py config switch ./switch_arc_prebuilt.py
11 $ ./bisect_android_build_id.py config eval ./eval-manually.sh
12 $ ./bisect_android_build_id.py run
13
14When running switcher and evaluator, following environment variables
15will be set:
16 ANDROID_BRANCH (e.g. git_mnc-dr-arc-dev),
17 ANDROID_FLAVOR (e.g. cheets_x86-user),
18 ANDROID_BUILD_ID (e.g. 9876543),
Kuang-che Wu708310b2018-03-28 17:24:34 +080019 DUT (e.g. samus-dut, if available).
20"""
21
22from __future__ import print_function
23import logging
24
25from bisect_kit import android_util
26from bisect_kit import arc_util
Kuang-che Wu2526a672019-09-10 16:23:59 +080027from bisect_kit import bisector_cli
Kuang-che Wu708310b2018-03-28 17:24:34 +080028from bisect_kit import cli
29from bisect_kit import configure
30from bisect_kit import core
31from bisect_kit import cros_util
32
33logger = logging.getLogger(__name__)
34
Kuang-che Wu13acc7b2020-06-15 10:45:35 +080035diff_url_template = (
36 'https://android-build.googleplex.com/'
37 'builds/{new}/branches/{branch}/targets/{flavor}/cls?end={old}')
38
Kuang-che Wu708310b2018-03-28 17:24:34 +080039
40class AndroidBuildIDDomain(core.BisectDomain):
41 """BisectDomain for Android build IDs."""
42 revtype = staticmethod(android_util.argtype_android_build_id)
43 help = globals()['__doc__']
44
45 @staticmethod
46 def add_init_arguments(parser):
47 parser.add_argument(
48 '--branch',
49 metavar='ANDROID_BRANCH',
50 default=configure.get('ANDROID_BRANCH'),
51 help='git branch like "git_mnc-dr-arc-dev"')
52 parser.add_argument(
53 '--flavor',
54 metavar='ANDROID_FLAVOR',
55 default=configure.get('ANDROID_FLAVOR'),
56 help='example: cheets_x86-user')
57 parser.add_argument(
58 '--only_good_build',
59 action='store_true',
60 help='Bisect only good builds. '
61 'This flag is only needed if weird builds blocked bisection')
62
63 # Only used for Android on ChromeOS.
64 parser.add_argument(
65 '--dut',
66 type=cli.argtype_notempty,
67 metavar='DUT',
68 default=configure.get('DUT'),
69 help='For ChromeOS, address of DUT (Device Under Test)')
Kuang-che Wu708310b2018-03-28 17:24:34 +080070
71 @staticmethod
72 def init(opts):
73 if opts.dut:
74 assert cros_util.is_dut(opts.dut)
75
76 if not opts.flavor:
77 assert opts.dut
78 opts.flavor = arc_util.query_flavor(opts.dut)
79
80 if not opts.branch:
81 assert opts.dut
82 board = cros_util.query_dut_board(opts.dut)
83 version = cros_util.query_dut_short_version(opts.dut)
84 opts.branch = cros_util.query_android_branch(board, version)
85 assert opts.branch
86
Kuang-che Wu94ef56e2019-01-15 21:17:42 +080087 config = dict(branch=opts.branch, flavor=opts.flavor)
Kuang-che Wu708310b2018-03-28 17:24:34 +080088 if opts.dut:
89 config['dut'] = opts.dut
90
Kuang-che Wu0a902f42019-01-21 18:58:32 +080091 revlist = android_util.get_build_ids_between(opts.branch, opts.flavor,
92 opts.old, opts.new)
Kuang-che Wu708310b2018-03-28 17:24:34 +080093
94 if opts.only_good_build:
95 revlist = [
96 bid for bid in revlist
97 if android_util.is_good_build(opts.branch, opts.flavor, bid)
98 ]
99
Kuang-che Wu13acc7b2020-06-15 10:45:35 +0800100 details = {}
101 for i in range(1, len(revlist)):
102 url = diff_url_template.format(
103 branch=opts.branch,
104 flavor=opts.flavor,
105 old=revlist[i - 1],
106 new=revlist[i])
107 details[revlist[i]] = {'actions': [{'link': url}]}
108
109 return config, {'revlist': revlist, 'details': details}
Kuang-che Wu708310b2018-03-28 17:24:34 +0800110
111 def __init__(self, config):
112 self.config = config
113
114 def setenv(self, env, rev):
115 env['ANDROID_BRANCH'] = self.config['branch']
116 env['ANDROID_FLAVOR'] = self.config['flavor']
117 env['ANDROID_BUILD_ID'] = rev
118 if self.config.get('dut'):
119 env['DUT'] = self.config['dut']
Kuang-che Wu708310b2018-03-28 17:24:34 +0800120
Kuang-che Wu13acc7b2020-06-15 10:45:35 +0800121 def fill_candidate_summary(self, summary):
Kuang-che Wu948a79c2019-06-19 19:13:56 +0800122 if 'current_range' in summary:
123 old, new = summary['current_range']
Kuang-che Wu13acc7b2020-06-15 10:45:35 +0800124 url = diff_url_template.format(
125 branch=self.config['branch'],
126 flavor=self.config['flavor'],
127 old=old,
128 new=new)
129 summary['links'] = [dict(name='change_list', url=url)]
Kuang-che Wu708310b2018-03-28 17:24:34 +0800130
131
132if __name__ == '__main__':
Kuang-che Wu2526a672019-09-10 16:23:59 +0800133 bisector_cli.BisectorCommandLine(AndroidBuildIDDomain).main()