1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
|
#!/usr/bin/env python3
# Copyright 2016 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This script takes a Clang git revision as an argument, it then
creates a feature branch, puts this revision into update.py, uploads
a CL, triggers Clang Upload try bots, and tells what to do next"""
from __future__ import print_function
import argparse
import itertools
import os
import re
import subprocess
import sys
import urllib.request
from build import (CheckoutGitRepo, GetCommitDescription, GetLatestLLVMCommit,
LLVM_DIR, LLVM_GIT_URL, RunCommand)
from update import CHROMIUM_DIR, DownloadAndUnpack
# Access to //tools/rust
sys.path.append(
os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..',
'rust'))
from build_rust import RUST_GIT_URL, RUST_SRC_DIR, GetLatestRustCommit
# Path constants.
THIS_DIR = os.path.dirname(__file__)
CHROMIUM_DIR = os.path.abspath(os.path.join(THIS_DIR, '..', '..', '..'))
CLANG_UPDATE_PY_PATH = os.path.join(THIS_DIR, 'update.py')
RUST_UPDATE_PY_PATH = os.path.join(THIS_DIR, '..', '..', 'rust',
'update_rust.py')
BUILD_RUST_PY_PATH = os.path.join(THIS_DIR, '..', '..', 'rust', 'build_rust.py')
# Bots where we build Clang + Rust.
BUILD_CLANG_BOTS = [
'linux_upload_clang',
'mac_upload_clang',
'mac_upload_clang_arm',
'win_upload_clang',
]
BUILD_RUST_BOTS = [
'linux_upload_rust',
'mac_upload_rust',
'mac_upload_rust_arm',
'win_upload_rust',
]
# Keep lines in here at <= 72 columns, else they wrap in gerrit.
# There can be no whitespace line between or below these gerrit footers.
COMMIT_FOOTER = \
'''
Bug: TODO. Remove the Tricium: line below when filling this in.
Tricium: skip
Disable-Rts: True
Cq-Include-Trybots: chromium/try:chromeos-amd64-generic-cfi-thin-lto-rel
Cq-Include-Trybots: chromium/try:dawn-win10-x86-deps-rel
Cq-Include-Trybots: chromium/try:lacros-arm64-generic-rel
Cq-Include-Trybots: chromium/try:linux-chromeos-dbg
Cq-Include-Trybots: chromium/try:linux_chromium_cfi_rel_ng
Cq-Include-Trybots: chromium/try:linux_chromium_chromeos_msan_rel_ng
Cq-Include-Trybots: chromium/try:linux_chromium_msan_rel_ng
Cq-Include-Trybots: chromium/try:mac11-arm64-rel,mac_chromium_asan_rel_ng
Cq-Include-Trybots: chromium/try:ios-catalyst
Cq-Include-Trybots: chromium/try:win-asan
Cq-Include-Trybots: chromium/try:android-official,fuchsia-official
Cq-Include-Trybots: chromium/try:mac-official,linux-official
Cq-Include-Trybots: chromium/try:win-official,win32-official
Cq-Include-Trybots: chromium/try:linux-swangle-try-x64,win-swangle-try-x86
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-arm64-dbg
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-arm64-rel
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-x86-dbg
Cq-Include-Trybots: chromium/try:android-cronet-mainline-clang-x86-rel
Cq-Include-Trybots: chrome/try:iphone-device,ipad-device
Cq-Include-Trybots: chrome/try:linux-chromeos-chrome,win-arm64-rel
Cq-Include-Trybots: chrome/try:win-chrome,win64-chrome,linux-chrome,mac-chrome
Cq-Include-Trybots: chrome/try:linux-pgo,mac-pgo,win32-pgo,win64-pgo'''
RUST_BOTS = \
'''Cq-Include-Trybots: chromium/try:android-rust-arm32-rel
Cq-Include-Trybots: chromium/try:android-rust-arm64-dbg
Cq-Include-Trybots: chromium/try:android-rust-arm64-rel
Cq-Include-Trybots: chromium/try:linux-rust-x64-dbg
Cq-Include-Trybots: chromium/try:linux-rust-x64-rel
Cq-Include-Trybots: chromium/try:mac-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-dbg
Cq-Include-Trybots: chromium/try:win-rust-x64-rel'''
is_win = sys.platform.startswith('win32')
class RustVersion:
"""Holds the nightly Rust version in an explicit format."""
def __init__(self, git_hash: str, sub_revision: int):
self.git_hash = git_hash
self.short_git_hash = git_hash[slice(0, 12)]
self.sub_revision = sub_revision
def __str__(self) -> str:
"""A string containing the Rust version and sub revision.
The string is useful for humans, it contains all info needed to identify
the Rust version being built. It is also unique to a given Rust version and
subversion.
"""
return f'{self.git_hash}-{self.sub_revision}'
def __eq__(self, o) -> bool:
return (self.git_hash == o.git_hash and self.sub_revision == o.sub_revision)
class ClangVersion:
"""Holds the Clang version in an explicit format."""
def __init__(self, git_describe: str, sub_revision: str):
self.git_describe = git_describe
self.short_git_hash = re.search('-g([0-9a-f]+)', git_describe).group(1)
self.sub_revision = int(sub_revision)
def __str__(self) -> str:
"""A string containing the Clang version and sub revision.
The string is useful for humans, it contains all info needed to identify
the Clang version being built. It is also unique to a given Clang version
and subversion.
"""
return f'{self.git_describe}-{self.sub_revision}'
def __eq__(self, o) -> bool:
return (self.git_describe == o.git_describe
and self.sub_revision == o.sub_revision)
def PatchClangRevision(new_version: ClangVersion) -> ClangVersion:
with open(CLANG_UPDATE_PY_PATH) as f:
content = f.read()
REV = '\'([0-9a-z-]+)\''
SUB_REV = '([0-9]+)'
git_describe = re.search(f'CLANG_REVISION = {REV}', content).group(1)
sub_revision = re.search(f'CLANG_SUB_REVISION = {SUB_REV}', content).group(1)
old_version = ClangVersion(git_describe, sub_revision)
content = re.sub(f'CLANG_REVISION = {REV}',
f'CLANG_REVISION = \'{new_version.git_describe}\'',
content,
count=1)
content = re.sub(f'CLANG_SUB_REVISION = {SUB_REV}',
f'CLANG_SUB_REVISION = {new_version.sub_revision}',
content,
count=1)
with open(CLANG_UPDATE_PY_PATH, 'w') as f:
f.write(content)
return old_version
def PatchRustRevision(new_version: RustVersion) -> RustVersion:
with open(RUST_UPDATE_PY_PATH) as f:
content = f.read()
REV = '\'([0-9a-z-]+)\''
SUB_REV = '([0-9]+)'
git_hash = re.search(f'RUST_REVISION = {REV}', content).group(1)
sub_revision = re.search(f'RUST_SUB_REVISION = {SUB_REV}', content).group(1)
old_version = RustVersion(git_hash, sub_revision)
content = re.sub(f'RUST_REVISION = {REV}',
f'RUST_REVISION = \'{new_version.git_hash}\'',
content,
count=1)
content = re.sub(f'RUST_SUB_REVISION = {SUB_REV}',
f'RUST_SUB_REVISION = {new_version.sub_revision}',
content,
count=1)
with open(RUST_UPDATE_PY_PATH, 'w') as f:
f.write(content)
return old_version
def PatchRustStage0():
verify_stage0 = subprocess.run(
[sys.executable, BUILD_RUST_PY_PATH, '--verify-stage0-hash'],
capture_output=True,
text=True)
if verify_stage0.returncode == 0:
return
# TODO(crbug.com/1405814): We're printing a warning that the hash has
# changed, but we could require a verification step of some sort here. We
# should do the same for both Rust and Clang if we do so.
print(verify_stage0.stdout)
lines = verify_stage0.stdout.splitlines()
m = re.match('Actual hash: +([0-9a-z]+)', lines[-1])
new_stage0_hash = m.group(1)
with open(RUST_UPDATE_PY_PATH) as f:
content = f.read()
STAGE0_HASH = '\'([0-9a-z]+)\''
content = re.sub(f'STAGE0_JSON_SHA256 = {STAGE0_HASH}',
f'STAGE0_JSON_SHA256 = \'{new_stage0_hash}\'',
content,
count=1)
with open(RUST_UPDATE_PY_PATH, 'w') as f:
f.write(content)
def PatchRustRemoveOverride():
with open(RUST_UPDATE_PY_PATH) as f:
content = f.read()
REV = '([0-9a-z-]+)'
content = re.sub(f'OVERRIDE_CLANG_REVISION = \'{REV}\'',
f'OVERRIDE_CLANG_REVISION = None',
content,
count=1)
with open(RUST_UPDATE_PY_PATH, 'w') as f:
f.write(content)
def Git(*args, no_run: bool):
"""Runs a git command, or just prints it out if `no_run` is True."""
if no_run:
print('\033[91m', end='') # Color red
print('Skipped running: ', end='')
print('\033[0m', end='') # No color
print(*['git'] + [f'\'{i}\'' for i in list(args)], end='')
print()
else:
# Needs shell=True on Windows due to git.bat in depot_tools.
subprocess.check_call(['git'] + list(args), shell=is_win)
def main():
parser = argparse.ArgumentParser(description='upload new clang revision')
# TODO(crbug.com/1401042): Remove this when the cron job doesn't pass a SHA.
parser.add_argument(
'ignored',
nargs='?',
help='Ignored argument to handle the cron job passing a clang SHA')
parser.add_argument('--clang-git-hash',
type=str,
metavar='SHA1',
help='Clang git hash to build the toolchain for.')
parser.add_argument(
'--clang-sub-revision',
type=int,
default=1,
metavar='NUM',
help='Clang sub-revision to build the toolchain for. Defaults to 1.')
parser.add_argument('--rust-git-hash',
type=str,
metavar='SHA1',
help='Rust git hash to build the toolchain for.')
parser.add_argument(
'--rust-sub-revision',
type=int,
default=1,
metavar='NUM',
help='Rust sub-revision to build the toolchain for. Defaults to 1.')
parser.add_argument(
'--no-git',
action='store_true',
default=False,
help=('Print out `git` commands instead of running them. Still generates '
'a local diff for debugging purposes.'))
parser.add_argument('--skip-rust',
action='store_true',
default=False,
help=('Skip updating the rust revision.'))
parser.add_argument('--skip-clang',
action='store_true',
default=False,
help=('Skip updating the clang revision.'))
args = parser.parse_args()
if args.skip_clang and args.skip_rust:
print('Cannot set both --skip-clang and --skip-rust.')
sys.exit(1)
if args.skip_clang:
clang_version = '-skipped-'
else:
if args.clang_git_hash:
clang_git_hash = args.clang_git_hash
else:
clang_git_hash = GetLatestLLVMCommit()
# To `GetCommitDescription()`, we need a checkout. On success, the
# CheckoutLLVM() makes `LLVM_DIR` be the current working directory, so that
# we can GetCommitDescription() without changing directory.
CheckoutGitRepo("LLVM", LLVM_GIT_URL, clang_git_hash, LLVM_DIR)
clang_version = ClangVersion(GetCommitDescription(clang_git_hash),
args.clang_sub_revision)
os.chdir(CHROMIUM_DIR)
if args.skip_rust:
rust_version = '-skipped-'
else:
if args.rust_git_hash:
rust_git_hash = args.rust_git_hash
else:
rust_git_hash = GetLatestRustCommit()
CheckoutGitRepo("Rust", RUST_GIT_URL, rust_git_hash, RUST_SRC_DIR)
rust_version = RustVersion(rust_git_hash, args.rust_sub_revision)
os.chdir(CHROMIUM_DIR)
print(f'Making a patch for Clang {clang_version} and Rust {rust_version}')
branch_name = f'clang-{clang_version}_rust-{rust_version}'
Git('checkout', 'origin/main', '-b', branch_name, no_run=args.no_git)
old_clang_version = clang_version
if not args.skip_clang:
old_clang_version = PatchClangRevision(clang_version)
if args.skip_rust:
assert (clang_version !=
old_clang_version), ('Change the sub-revision of Clang if there is '
'no major version change.')
else:
old_rust_version = PatchRustRevision(rust_version)
assert (clang_version != old_clang_version
or rust_version != old_rust_version), (
'Change the sub-revision of Clang or Rust if there is '
'no major version change.')
PatchRustStage0()
if not args.skip_clang:
PatchRustRemoveOverride()
if args.skip_clang:
clang_change = '[skipping Clang]'
clang_change_log = ''
else:
clang_change = f'{old_clang_version} : {clang_version}'
clang_change_log = (
f'{LLVM_GIT_URL}/+log/'
f'{old_clang_version.short_git_hash}..{clang_version.short_git_hash}'
f'\n\n')
if args.skip_rust:
rust_change = '[skipping Rust]'
rust_change_log = ''
else:
rust_change = f'{old_rust_version} : {rust_version}'
rust_change_log = (f'{RUST_GIT_URL}/+log/'
f'{old_rust_version.short_git_hash}..'
f'{rust_version.short_git_hash}'
f'\n\n')
title = f'Roll clang+rust {clang_change} / {rust_change}'
cmd = ' '.join(sys.argv)
body = f'{clang_change_log}{rust_change_log}Ran: {cmd}'
commit_message = f'{title}\n\n{body}\n{COMMIT_FOOTER}'
if not args.skip_rust:
commit_message += f'\n{RUST_BOTS}'
Git('add',
CLANG_UPDATE_PY_PATH,
RUST_UPDATE_PY_PATH,
no_run=args.no_git)
Git('commit', '-m', commit_message, no_run=args.no_git)
Git('cl', 'upload', '-f', '--bypass-hooks', no_run=args.no_git)
if not args.skip_clang:
Git('cl',
'try',
'-B',
"chromium/try",
*itertools.chain(*[['-b', bot] for bot in BUILD_CLANG_BOTS]),
no_run=args.no_git)
Git('cl',
'try',
'-B',
"chromium/try",
*itertools.chain(*[['-b', bot] for bot in BUILD_RUST_BOTS]),
no_run=args.no_git)
print('Please, wait until the try bots succeeded '
'and then push the binaries to goma.')
print()
print('To regenerate BUILD.gn rules for Rust stdlib (needed if dep versions '
'in the stdlib change for example), run:\n tools/rust/gnrt_stdlib.py.')
print()
print('To update Abseil .def files, run:\n '
'third_party/abseil-cpp/generate_def_files.py')
if __name__ == '__main__':
sys.exit(main())
|