1#!/usr/bin/env python3 2# Copyright 2024 The ChromiumOS Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Runs `bb add`, with additional convenience features.""" 7 8import argparse 9import logging 10import os 11import shlex 12import sys 13from typing import Iterable, List 14 15import cros_cls 16import llvm_next 17 18 19def generate_bb_add_command( 20 use_llvm_next: bool, 21 disable_werror: bool, 22 extra_cls: Iterable[cros_cls.ChangeListURL], 23 bots: Iterable[str], 24) -> List[str]: 25 cls: List[cros_cls.ChangeListURL] = [] 26 if use_llvm_next: 27 if not llvm_next.LLVM_NEXT_TESTING_CLS: 28 raise ValueError( 29 "llvm-next testing requested, but no llvm-next CLs exist." 30 ) 31 cls += llvm_next.LLVM_NEXT_TESTING_CLS 32 33 if disable_werror: 34 cls.append(llvm_next.DISABLE_WERROR_CL) 35 36 if extra_cls: 37 cls += extra_cls 38 39 cmd = ["bb", "add"] 40 for cl in cls: 41 cmd += ("-cl", cl.crrev_url_without_http()) 42 cmd += bots 43 return cmd 44 45 46def main(argv: List[str]) -> None: 47 logging.basicConfig( 48 format=">> %(asctime)s: %(levelname)s: %(filename)s:%(lineno)d: " 49 "%(message)s", 50 level=logging.INFO, 51 ) 52 53 parser = argparse.ArgumentParser( 54 description=__doc__, 55 formatter_class=argparse.RawDescriptionHelpFormatter, 56 ) 57 parser.add_argument( 58 "--llvm-next", 59 action="store_true", 60 help="Add the current llvm-next patch set.", 61 ) 62 parser.add_argument( 63 "--disable-werror", 64 action="store_true", 65 help="Add the 'disable -Werror' patch sets", 66 ) 67 parser.add_argument( 68 "--cl", 69 action="append", 70 type=cros_cls.ChangeListURL.parse, 71 help=""" 72 CL to add to the `bb add` run. May be specified multiple times. In the 73 form crrev.com/c/123456. 74 """, 75 ) 76 parser.add_argument("bot", nargs="+", help="Bot(s) to run `bb add` with.") 77 opts = parser.parse_args(argv) 78 79 cmd = generate_bb_add_command( 80 use_llvm_next=opts.llvm_next, 81 disable_werror=opts.disable_werror, 82 extra_cls=opts.cl, 83 bots=opts.bot, 84 ) 85 logging.info("Running `bb add` command: %s...", shlex.join(cmd)) 86 # execvp raises if it fails, so no need to check. 87 os.execvp(cmd[0], cmd) 88 89 90if __name__ == "__main__": 91 main(sys.argv[1:]) 92