blob: b3e09f25f75336891fea303fd27110d98fa63a27 [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 Windb873c642019-04-15 11:07:39 +020030def ParseOptions():
31 result = optparse.OptionParser()
32 result.add_option('--release',
33 help='Run on the release branch builders.',
34 default=False, action='store_true')
Rico Winde11f71d2019-04-24 13:18:15 +020035 result.add_option('--cl',
Søren Gjesseceb85a82023-04-26 09:58:03 +020036 metavar=('<url>'),
Rico Winde11f71d2019-04-24 13:18:15 +020037 help='Run the specified cl on the bots. This should be '
38 'the full url, e.g., '
39 'https://r8-review.googlesource.com/c/r8/+/37420/1')
Rico Wind8cc810a2022-06-24 09:33:34 +020040 result.add_option('--desugar-jdk11',
41 help='Run the jdk11 library desugar and archiving bot.',
Rico Wind1cd21b02019-08-14 13:26:21 +020042 default=False, action='store_true')
Søren Gjessef637d9d2022-08-24 15:32:55 +020043 result.add_option('--desugar-jdk11-legacy',
44 help='Run the jdk11 legacy library desugar and archiving bot.',
45 default=False, action='store_true')
Rico Wind8cc810a2022-06-24 09:33:34 +020046 result.add_option('--desugar-jdk8',
47 help='Run the jdk8 library desugar and archiving bot.',
48 default=False, action='store_true')
Søren Gjesseceb85a82023-04-26 09:58:03 +020049 result.add_option('--smali',
50 metavar=('<version>'),
51 help='Build smali version <version>.')
Rico Wind8cc810a2022-06-24 09:33:34 +020052
Rico Windb873c642019-04-15 11:07:39 +020053 result.add_option('--builder', help='Trigger specific builder')
54 return result.parse_args()
55
56def get_builders():
Rico Wind1cd21b02019-08-14 13:26:21 +020057
Rico Windb873c642019-04-15 11:07:39 +020058 is_release = False
Rico Wind1b52acf2021-03-21 12:36:55 +010059 main_builders = []
Rico Windb873c642019-04-15 11:07:39 +020060 release_builders = []
61 with open(LUCI_SCHEDULE, 'r') as fp:
62 lines = fp.readlines()
63 for line in lines:
Rico Windb12a44a2022-03-31 12:17:00 +020064 if 'branch-gitiles' in line:
Rico Windb873c642019-04-15 11:07:39 +020065 is_release = True
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010066 if 'main-gitiles-trigger' in line:
67 is_release = False
Rico Windb873c642019-04-15 11:07:39 +020068 match = re.match(TRIGGERS_RE, line)
69 if match:
70 builder = match.group(1)
71 if is_release:
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010072 assert 'release' in builder, builder
Rico Windb873c642019-04-15 11:07:39 +020073 release_builders.append(builder)
74 else:
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010075 assert 'release' not in builder, builder
Rico Wind1b52acf2021-03-21 12:36:55 +010076 main_builders.append(builder)
Rico Wind8cc810a2022-06-24 09:33:34 +020077 print('Desugar jdk11 builder:\n ' + DESUGAR_JDK11_BOT)
Søren Gjessef637d9d2022-08-24 15:32:55 +020078 print('Desugar jdk11 legacy builder:\n ' + DESUGAR_JDK11_LEGACY_BOT)
Rico Wind8cc810a2022-06-24 09:33:34 +020079 print('Desugar jdk8 builder:\n ' + DESUGAR_JDK8_BOT)
Søren Gjesseceb85a82023-04-26 09:58:03 +020080 print('Smali builder:\n ' + SMALI_BOT)
Morten Krogh-Jespersen6aa4ea32021-11-02 14:25:56 +010081 print('Main builders:\n ' + '\n '.join(main_builders))
82 print('Release builders:\n ' + '\n '.join(release_builders))
Rico Wind1b52acf2021-03-21 12:36:55 +010083 return (main_builders, release_builders)
Rico Windb873c642019-04-15 11:07:39 +020084
85def sanity_check_url(url):
Rico Windb12a44a2022-03-31 12:17:00 +020086 a = urlopen(url)
Rico Windb873c642019-04-15 11:07:39 +020087 if a.getcode() != 200:
88 raise Exception('Url: %s \n returned %s' % (url, a.getcode()))
89
90def trigger_builders(builders, commit):
91 commit_url = 'https://r8.googlesource.com/r8/+/%s' % commit
92 sanity_check_url(commit_url)
93 for builder in builders:
94 cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-commit', commit_url]
95 subprocess.check_call(cmd)
96
Søren Gjesseceb85a82023-04-26 09:58:03 +020097def trigger_smali_builder(version):
98 utils.check_basic_semver_version(
99 version,
100 'use semantic version of the smali version to built (pre-releases are not supported)',
101 allowPrerelease = False)
102 cmd = [
103 'bb',
104 'add',
105 'r8/ci/%s' % SMALI_BOT,
106 '-p',
Søren Gjessedab0e8f2023-04-26 11:10:40 +0200107 'test_options=["--version", "%s"]' % version
Søren Gjesseceb85a82023-04-26 09:58:03 +0200108 ]
109 subprocess.check_call(cmd)
110
Rico Winde11f71d2019-04-24 13:18:15 +0200111def trigger_cl(builders, cl_url):
112 for builder in builders:
113 cmd = ['bb', 'add', 'r8/ci/%s' % builder , '-cl', cl_url]
114 subprocess.check_call(cmd)
115
Rico Windb873c642019-04-15 11:07:39 +0200116def Main():
117 (options, args) = ParseOptions()
Søren Gjessef637d9d2022-08-24 15:32:55 +0200118 desugar = options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8
Søren Gjesseceb85a82023-04-26 09:58:03 +0200119 requires_commit = not options.cl and not desugar and not options.smali
120 if len(args) != 1 and requires_commit:
Rico Windb12a44a2022-03-31 12:17:00 +0200121 print('Takes exactly one argument, the commit to run')
Rico Windb873c642019-04-15 11:07:39 +0200122 return 1
Rico Winde11f71d2019-04-24 13:18:15 +0200123
124 if options.cl and options.release:
Rico Windb12a44a2022-03-31 12:17:00 +0200125 print('You can\'t run cls on the release bots')
Rico Winde11f71d2019-04-24 13:18:15 +0200126 return 1
127
Rico Wind8cc810a2022-06-24 09:33:34 +0200128 if options.cl and desugar:
Rico Windb12a44a2022-03-31 12:17:00 +0200129 print('You can\'t run cls on the desugar bot')
Rico Wind1cd21b02019-08-14 13:26:21 +0200130 return 1
131
Søren Gjesseceb85a82023-04-26 09:58:03 +0200132 if options.cl and options.smali:
133 print('You can\'t run cls on the smali bot')
134 return 1
135
136 if options.smali:
137 if not options.release:
138 print('Only release versions of smali can be built')
139 return 1
140
141 trigger_smali_builder(options.smali)
142 return
143
144 commit = None if not requires_commit else args[0]
Rico Wind1b52acf2021-03-21 12:36:55 +0100145 (main_builders, release_builders) = get_builders()
146 builders = release_builders if options.release else main_builders
Rico Windb873c642019-04-15 11:07:39 +0200147 if options.builder:
148 builder = options.builder
Rico Wind1b52acf2021-03-21 12:36:55 +0100149 assert builder in main_builders or builder in release_builders
Rico Winde11f71d2019-04-24 13:18:15 +0200150 builders = [options.builder]
Rico Wind8cc810a2022-06-24 09:33:34 +0200151 if desugar:
Søren Gjessef637d9d2022-08-24 15:32:55 +0200152 assert options.desugar_jdk11 or options.desugar_jdk11_legacy or options.desugar_jdk8
153 if options.desugar_jdk11:
154 builders = [DESUGAR_JDK11_BOT]
155 elif options.desugar_jdk11_legacy:
156 builders = [DESUGAR_JDK11_LEGACY_BOT]
157 else:
158 builders = [DESUGAR_JDK8_BOT]
Rico Wind1b52acf2021-03-21 12:36:55 +0100159 commit = git_utils.GetHeadRevision(utils.REPO_ROOT, use_main=True)
Rico Winde11f71d2019-04-24 13:18:15 +0200160 if options.cl:
161 trigger_cl(builders, options.cl)
Rico Windb873c642019-04-15 11:07:39 +0200162 else:
Rico Winde11f71d2019-04-24 13:18:15 +0200163 assert commit
164 trigger_builders(builders, commit)
Rico Windb873c642019-04-15 11:07:39 +0200165
166if __name__ == '__main__':
167 sys.exit(Main())