blob: 0c44d24f97127b609fba6cad09ce61e9d271ac2d [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Rico Windb873c642019-04-15 11:07:39 +02002# Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
6# Convenience script for triggering bots on specific commits.
7
8import json
Rico Wind1cd21b02019-08-14 13:26:21 +02009import git_utils
Rico Windb873c642019-04-15 11:07:39 +020010import optparse
11import os
12import re
13import subprocess
14import sys
15import urllib
Rico Windb12a44a2022-03-31 12:17:00 +020016from urllib.request import urlopen
Rico Windb873c642019-04-15 11:07:39 +020017import utils
18
19LUCI_SCHEDULE = os.path.join(utils.REPO_ROOT, 'infra', 'config', 'global',
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010020 'generated', 'luci-scheduler.cfg')
Rico Windb873c642019-04-15 11:07:39 +020021# Trigger lines have the format:
22# triggers: "BUILDER_NAME"
23TRIGGERS_RE = r'^ triggers: "(\w.*)"'
24
Rico Wind8cc810a2022-06-24 09:33:34 +020025DESUGAR_JDK11_BOT = 'lib_desugar-archive-jdk11'
Søren Gjessef637d9d2022-08-24 15:32:55 +020026DESUGAR_JDK11_LEGACY_BOT = 'lib_desugar-archive-jdk11-legacy'
Søren Gjesse45c70382022-06-24 10:37:07 +020027DESUGAR_JDK8_BOT = 'lib_desugar-archive-jdk8'
Søren Gjesseceb85a82023-04-26 09:58:03 +020028SMALI_BOT = 'smali'
Rico Wind1cd21b02019-08-14 13:26:21 +020029
Rico Wind8cc810a2022-06-24 09:33:34 +020030
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020031def ParseOptions():
32 result = optparse.OptionParser()
33 result.add_option('--release',
34 help='Run on the release branch builders.',
35 default=False,
36 action='store_true')
37 result.add_option('--cl',
38 metavar=('<url>'),
39 help='Run the specified cl on the bots. This should be '
40 'the full url, e.g., '
41 'https://r8-review.googlesource.com/c/r8/+/37420/1')
42 result.add_option('--desugar-jdk11',
43 help='Run the jdk11 library desugar and archiving bot.',
44 default=False,
45 action='store_true')
46 result.add_option(
47 '--desugar-jdk11-legacy',
48 help='Run the jdk11 legacy library desugar and archiving bot.',
49 default=False,
50 action='store_true')
51 result.add_option('--desugar-jdk8',
52 help='Run the jdk8 library desugar and archiving bot.',
53 default=False,
54 action='store_true')
55 result.add_option('--smali',
56 metavar=('<version>'),
57 help='Build smali version <version>.')
58
59 result.add_option('--builder', help='Trigger specific builder')
60 return result.parse_args()
61
Rico Windb873c642019-04-15 11:07:39 +020062
63def get_builders():
Rico Wind1cd21b02019-08-14 13:26:21 +020064
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020065 is_release = False
66 main_builders = []
67 release_builders = []
68 with open(LUCI_SCHEDULE, 'r') as fp:
69 lines = fp.readlines()
70 for line in lines:
71 if 'branch-gitiles' in line:
72 is_release = True
73 if 'main-gitiles-trigger' in line:
74 is_release = False
75 match = re.match(TRIGGERS_RE, line)
76 if match:
77 builder = match.group(1)
78 if is_release:
79 assert 'release' in builder, builder
80 release_builders.append(builder)
81 else:
82 assert 'release' not in builder, builder
83 main_builders.append(builder)
84 print('Desugar jdk11 builder:\n ' + DESUGAR_JDK11_BOT)
85 print('Desugar jdk11 legacy builder:\n ' + DESUGAR_JDK11_LEGACY_BOT)
86 print('Desugar jdk8 builder:\n ' + DESUGAR_JDK8_BOT)
87 print('Smali builder:\n ' + SMALI_BOT)
88 print('Main builders:\n ' + '\n '.join(main_builders))
89 print('Release builders:\n ' + '\n '.join(release_builders))
90 return (main_builders, release_builders)
91
Rico Windb873c642019-04-15 11:07:39 +020092
93def sanity_check_url(url):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020094 a = urlopen(url)
95 if a.getcode() != 200:
96 raise Exception('Url: %s \n returned %s' % (url, a.getcode()))
97
Rico Windb873c642019-04-15 11:07:39 +020098
99def trigger_builders(builders, commit):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200100 commit_url = 'https://r8.googlesource.com/r8/+/%s' % commit
101 sanity_check_url(commit_url)
102 for builder in builders:
103 cmd = ['bb', 'add', 'r8/ci/%s' % builder, '-commit', commit_url]
104 subprocess.check_call(cmd)
105
Rico Windb873c642019-04-15 11:07:39 +0200106
Søren Gjesseceb85a82023-04-26 09:58:03 +0200107def trigger_smali_builder(version):
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200108 utils.check_basic_semver_version(
109 version,
110 'use semantic version of the smali version to built (pre-releases are not supported)',
111 allowPrerelease=False)
112 cmd = [
113 'bb', 'add',
114 'r8/ci/%s' % SMALI_BOT, '-p',
115 'test_options=["--version", "%s"]' % version
116 ]
Rico Winde11f71d2019-04-24 13:18:15 +0200117 subprocess.check_call(cmd)
118
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200119
120def trigger_cl(builders, cl_url):
121 for builder in builders:
122 cmd = ['bb', 'add', 'r8/ci/%s' % builder, '-cl', cl_url]
123 subprocess.check_call(cmd)
124
125
Rico Windb873c642019-04-15 11:07:39 +0200126def Main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200127 (options, args) = ParseOptions()
128 desugar = options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8
129 requires_commit = not options.cl and not desugar and not options.smali
130 if len(args) != 1 and requires_commit:
131 print('Takes exactly one argument, the commit to run')
132 return 1
Rico Winde11f71d2019-04-24 13:18:15 +0200133
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200134 if options.cl and options.release:
135 print('You can\'t run cls on the release bots')
136 return 1
Rico Winde11f71d2019-04-24 13:18:15 +0200137
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200138 if options.cl and desugar:
139 print('You can\'t run cls on the desugar bot')
140 return 1
Rico Wind1cd21b02019-08-14 13:26:21 +0200141
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200142 if options.cl and options.smali:
143 print('You can\'t run cls on the smali bot')
144 return 1
Søren Gjesseceb85a82023-04-26 09:58:03 +0200145
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200146 if options.smali:
147 if not options.release:
148 print('Only release versions of smali can be built')
149 return 1
Søren Gjesseceb85a82023-04-26 09:58:03 +0200150
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200151 trigger_smali_builder(options.smali)
152 return
Søren Gjesseceb85a82023-04-26 09:58:03 +0200153
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200154 commit = None if not requires_commit else args[0]
155 (main_builders, release_builders) = get_builders()
156 builders = release_builders if options.release else main_builders
157 if options.builder:
158 builder = options.builder
159 assert builder in main_builders or builder in release_builders
160 builders = [options.builder]
161 if desugar:
162 assert options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8
163 if options.desugar_jdk11:
164 builders = [DESUGAR_JDK11_BOT]
165 elif options.desugar_jdk11_legacy:
166 builders = [DESUGAR_JDK11_LEGACY_BOT]
167 else:
168 builders = [DESUGAR_JDK8_BOT]
169 commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_main=True)
170 if options.cl:
171 trigger_cl(builders, options.cl)
Søren Gjessef637d9d2022-08-24 15:32:55 +0200172 else:
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200173 assert commit
174 trigger_builders(builders, commit)
175
Rico Windb873c642019-04-15 11:07:39 +0200176
177if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200178 sys.exit(Main())