Dan Albert | b6fd073 | 2023-08-31 23:08:38 +0000 | [diff] [blame^] | 1 | # |
| 2 | # Copyright (C) 2023 The Android Open Source Project |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | # |
| 16 | """Updater for rr prebuilts.""" |
| 17 | import argparse |
| 18 | import asyncio |
| 19 | import logging |
| 20 | from pathlib import Path |
| 21 | |
| 22 | from rrprebuiltupdater import BuildApi, Updater |
| 23 | |
| 24 | THIS_DIR = Path(__file__).parent |
| 25 | TOP = THIS_DIR.parent.parent |
| 26 | INSTALL_PATH = THIS_DIR / "rr/android/x86_64" |
| 27 | |
| 28 | |
| 29 | BRANCH = "aosp-rr-dev" |
| 30 | BUILD_TARGET = "linux" |
| 31 | ARTIFACT_NAME = "rr-5.6.0-Android-x86_64.tar.gz" |
| 32 | |
| 33 | |
| 34 | def parse_args() -> argparse.Namespace: |
| 35 | """Returns arguments parsed from sys.argv.""" |
| 36 | parser = argparse.ArgumentParser() |
| 37 | parser.add_argument( |
| 38 | "--no-upload", |
| 39 | dest="upload", |
| 40 | action="store_false", |
| 41 | default=True, |
| 42 | help="Do not upload the generated CL", |
| 43 | ) |
| 44 | parser.add_argument( |
| 45 | "--use-current-branch", |
| 46 | action="store_true", |
| 47 | help=( |
| 48 | "Use the current branch for the update. By default, a new branch will be " |
| 49 | "created" |
| 50 | ), |
| 51 | ) |
| 52 | parser.add_argument("-v", "--verbose", action="count", help="Increase verbosity.") |
| 53 | parser.add_argument( |
| 54 | "build_id", |
| 55 | nargs="?", |
| 56 | help=( |
| 57 | f"The build ID of the artifacts to fetch from {BRANCH}. If omitted, the " |
| 58 | "latest completed build will be used." |
| 59 | ), |
| 60 | ) |
| 61 | return parser.parse_args() |
| 62 | |
| 63 | |
| 64 | async def main() -> None: |
| 65 | """Program entry point.""" |
| 66 | args = parse_args() |
| 67 | logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO) |
| 68 | |
| 69 | build_id = args.build_id |
| 70 | if build_id is None: |
| 71 | build_id = await BuildApi(BRANCH, BUILD_TARGET).get_latest_build_id() |
| 72 | logging.info( |
| 73 | "Determined %s to be the latest build ID of branch %s target %s", |
| 74 | build_id, |
| 75 | BRANCH, |
| 76 | BUILD_TARGET, |
| 77 | ) |
| 78 | await Updater(build_id, args.use_current_branch, args.upload).run() |
| 79 | |
| 80 | |
| 81 | if __name__ == "__main__": |
| 82 | asyncio.run(main()) |