Anuj Jamwal | 643bf5c | 2023-08-02 18:14:20 +0000 | [diff] [blame^] | 1 | # Copyright 2023 The ChromiumOS Authors |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """Build cros_workon package incrementally. |
| 6 | |
| 7 | Simple wrapper script to build a cros_workon package incrementally. You |
| 8 | must already be cros_workon'ing the package in question. This had been |
| 9 | migrated to python from chromiumos/src/scripts/cros_workon_make. |
| 10 | """ |
| 11 | |
| 12 | import logging |
| 13 | from typing import List, Optional |
| 14 | |
| 15 | from chromite.lib import build_target_lib |
| 16 | from chromite.lib import commandline |
| 17 | from chromite.lib import cros_build_lib |
| 18 | from chromite.lib import workon_helper |
| 19 | |
| 20 | |
| 21 | def GetParser() -> commandline.ArgumentParser: |
| 22 | """Get a CLI parser.""" |
| 23 | parser = commandline.ArgumentParser(description=__doc__) |
| 24 | parser.add_argument( |
| 25 | "-b", |
| 26 | "--board", |
| 27 | "--build-target", |
| 28 | default=cros_build_lib.GetDefaultBoard(), |
| 29 | required=True, |
| 30 | help="The board to set package keywords for.", |
| 31 | ) |
| 32 | parser.add_argument( |
| 33 | "--test", |
| 34 | default=False, |
| 35 | action="store_true", |
| 36 | help="Compile and run tests as well", |
| 37 | ) |
| 38 | parser.add_argument( |
| 39 | "--reconf", |
| 40 | default=False, |
| 41 | action="store_true", |
| 42 | help="Re-run configure and prepare steps", |
| 43 | ) |
| 44 | parser.add_argument( |
| 45 | "--install", |
| 46 | default=False, |
| 47 | action="store_true", |
| 48 | help="Incrementally build and install your package", |
| 49 | ) |
| 50 | parser.add_argument( |
| 51 | "--scrub", |
| 52 | default=False, |
| 53 | action="store_true", |
| 54 | help="Blow away all in-tree files not managed by git", |
| 55 | ) |
| 56 | parser.add_argument( |
| 57 | "package", |
| 58 | help="Package to build.", |
| 59 | ) |
| 60 | return parser |
| 61 | |
| 62 | |
| 63 | def main(argv: Optional[List[str]]) -> Optional[int]: |
| 64 | commandline.RunInsideChroot() |
| 65 | |
| 66 | parser = GetParser() |
| 67 | options = parser.parse_args(argv) |
| 68 | options.Freeze() |
| 69 | |
| 70 | board = options.board |
| 71 | sysroot = build_target_lib.get_default_sysroot_path(board) |
| 72 | helper = workon_helper.WorkonHelper(sysroot, board) |
| 73 | |
| 74 | pkg = options.package |
| 75 | |
| 76 | if options.scrub: |
| 77 | logging.warning("--scrub will destroy ALL FILES unknown to git!") |
| 78 | if cros_build_lib.BooleanPrompt(): |
| 79 | helper.ScrubPackage(pkg) |
| 80 | else: |
| 81 | logging.info("Not scrubbing; exiting gracefully") |
| 82 | elif options.install: |
| 83 | helper.InstallPackage(pkg) |
| 84 | else: |
| 85 | helper.BuildPackage( |
| 86 | pkg, |
| 87 | clean=options.reconf, |
| 88 | test=options.test, |
| 89 | ) |