blob: c406af9b9d1a35f11fc72572d87d135f1410579b [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)
Søren Gjesseee4c2f82024-02-16 15:46:47 +0100112 print("Check that tag %s is created and pushed to the remote (e.g by running" % version)
113 print()
114 print(" git ls-remote origin refs/tags/%s in a smali checkout)" % version)
115 print()
116 print("in a smali checkout)")
117 print()
118 answer = input("Is tag %s present? [y/N]:" % version)
119 if answer != 'y':
120 print('Aborting smali release build')
121 sys.exit(1)
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200122 cmd = [
123 'bb', 'add',
124 'r8/ci/%s' % SMALI_BOT, '-p',
125 'test_options=["--version", "%s"]' % version
126 ]
Rico Winde11f71d2019-04-24 13:18:15 +0200127 subprocess.check_call(cmd)
128
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200129
130def trigger_cl(builders, cl_url):
131 for builder in builders:
132 cmd = ['bb', 'add', 'r8/ci/%s' % builder, '-cl', cl_url]
133 subprocess.check_call(cmd)
134
135
Rico Windb873c642019-04-15 11:07:39 +0200136def Main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200137 (options, args) = ParseOptions()
138 desugar = options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8
139 requires_commit = not options.cl and not desugar and not options.smali
140 if len(args) != 1 and requires_commit:
141 print('Takes exactly one argument, the commit to run')
142 return 1
Rico Winde11f71d2019-04-24 13:18:15 +0200143
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200144 if options.cl and options.release:
145 print('You can\'t run cls on the release bots')
146 return 1
Rico Winde11f71d2019-04-24 13:18:15 +0200147
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200148 if options.cl and desugar:
149 print('You can\'t run cls on the desugar bot')
150 return 1
Rico Wind1cd21b02019-08-14 13:26:21 +0200151
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200152 if options.cl and options.smali:
153 print('You can\'t run cls on the smali bot')
154 return 1
Søren Gjesseceb85a82023-04-26 09:58:03 +0200155
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200156 if options.smali:
157 if not options.release:
158 print('Only release versions of smali can be built')
159 return 1
Søren Gjesseceb85a82023-04-26 09:58:03 +0200160
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200161 trigger_smali_builder(options.smali)
162 return
Søren Gjesseceb85a82023-04-26 09:58:03 +0200163
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200164 commit = None if not requires_commit else args[0]
165 (main_builders, release_builders) = get_builders()
166 builders = release_builders if options.release else main_builders
167 if options.builder:
168 builder = options.builder
169 assert builder in main_builders or builder in release_builders
170 builders = [options.builder]
171 if desugar:
172 assert options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8
173 if options.desugar_jdk11:
174 builders = [DESUGAR_JDK11_BOT]
175 elif options.desugar_jdk11_legacy:
176 builders = [DESUGAR_JDK11_LEGACY_BOT]
177 else:
178 builders = [DESUGAR_JDK8_BOT]
179 commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_main=True)
180 if options.cl:
181 trigger_cl(builders, options.cl)
Søren Gjessef637d9d2022-08-24 15:32:55 +0200182 else:
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200183 assert commit
184 trigger_builders(builders, commit)
185
Rico Windb873c642019-04-15 11:07:39 +0200186
187if __name__ == '__main__':
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200188 sys.exit(Main())