Mike Frysinger | f1ba7ad | 2022-09-12 05:42:57 -0400 | [diff] [blame] | 1 | # Copyright 2015 The ChromiumOS Authors |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | |
| 5 | """This script moves ebuilds between 'stable' and 'live' states. |
| 6 | |
| 7 | By default 'stable' ebuilds point at and build from source at the |
| 8 | last known good commit. Moving an ebuild to 'live' (via cros_workon start) |
| 9 | is intended to support development. The current source tip is fetched, |
| 10 | source modified and built using the unstable 'live' (9999) ebuild. |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 11 | """ |
| 12 | |
Mike Frysinger | 06a51c8 | 2021-04-06 11:39:17 -0400 | [diff] [blame] | 13 | from chromite.lib import build_target_lib |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 14 | from chromite.lib import commandline |
| 15 | from chromite.lib import cros_build_lib |
| 16 | from chromite.lib import terminal |
| 17 | from chromite.lib import workon_helper |
| 18 | |
| 19 | |
Mike Frysinger | ed5ab1d | 2017-10-23 14:10:28 -0400 | [diff] [blame] | 20 | def GetParser(): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 21 | """Get a CLI parser.""" |
| 22 | parser = commandline.ArgumentParser(description=__doc__) |
| 23 | parser.add_argument( |
| 24 | "--board", |
| 25 | default=cros_build_lib.GetDefaultBoard(), |
| 26 | help="The board to set package keywords for.", |
| 27 | ) |
| 28 | parser.add_argument( |
| 29 | "--host", |
| 30 | default=False, |
| 31 | action="store_true", |
| 32 | help="Uses the host instead of board", |
| 33 | ) |
| 34 | parser.add_argument( |
| 35 | "--command", |
| 36 | default="git status", |
| 37 | dest="iterate_command", |
| 38 | help="The command to be run by forall.", |
| 39 | ) |
| 40 | parser.add_argument( |
| 41 | "--workon_only", |
| 42 | default=False, |
| 43 | action="store_true", |
| 44 | help="Apply to packages that have a workon ebuild only", |
| 45 | ) |
| 46 | parser.add_argument( |
| 47 | "--all", |
| 48 | default=False, |
| 49 | action="store_true", |
| 50 | help="Apply to all possible packages for the " |
| 51 | "given command (overrides workon_only)", |
| 52 | ) |
Christopher Wiley | 9385ea1 | 2015-05-08 13:18:45 -0700 | [diff] [blame] | 53 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 54 | commands = [ |
| 55 | ("start", "Moves an ebuild to live (intended to support development)"), |
| 56 | ("stop", "Moves an ebuild to stable (use last known good)"), |
| 57 | ("info", "Print package name, repo name, and source directory."), |
| 58 | ("list", "List of live ebuilds (workon ebuilds if --all)"), |
| 59 | ("list-all", "List all of the live ebuilds for all setup boards"), |
| 60 | ("iterate", "For each ebuild, cd to the source dir and run a command"), |
| 61 | ] |
| 62 | command_parsers = parser.add_subparsers(dest="command", title="commands") |
| 63 | for command, description in commands: |
| 64 | sub_parser = command_parsers.add_parser( |
| 65 | command, description=description, help=description |
| 66 | ) |
| 67 | sub_parser.add_argument( |
| 68 | "packages", nargs="*", help="The packages to run command against." |
| 69 | ) |
Christopher Wiley | 9385ea1 | 2015-05-08 13:18:45 -0700 | [diff] [blame] | 70 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 71 | return parser |
Mike Frysinger | ed5ab1d | 2017-10-23 14:10:28 -0400 | [diff] [blame] | 72 | |
| 73 | |
| 74 | def main(argv): |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 75 | parser = GetParser() |
| 76 | options = parser.parse_args(argv) |
| 77 | options.Freeze() |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 78 | |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 79 | if options.command == "list-all": |
| 80 | board_to_packages = workon_helper.ListAllWorkedOnAtoms() |
| 81 | color = terminal.Color() |
| 82 | for board in sorted(board_to_packages): |
| 83 | print(color.Start(color.GREEN) + board + ":" + color.Stop()) |
| 84 | for package in board_to_packages[board]: |
| 85 | print(" " + package) |
| 86 | print("") |
| 87 | return 0 |
| 88 | |
| 89 | # TODO(wiley): Assert that we're not running as root. |
| 90 | cros_build_lib.AssertInsideChroot() |
| 91 | |
| 92 | if options.host: |
| 93 | friendly_name = "host" |
| 94 | sysroot = "/" |
| 95 | elif options.board: |
| 96 | friendly_name = options.board |
| 97 | sysroot = build_target_lib.get_default_sysroot_path(options.board) |
| 98 | else: |
| 99 | cros_build_lib.Die("You must specify either --host, --board") |
| 100 | |
| 101 | helper = workon_helper.WorkonHelper(sysroot, friendly_name) |
| 102 | try: |
| 103 | if options.command == "start": |
| 104 | helper.StartWorkingOnPackages( |
| 105 | options.packages, |
| 106 | use_all=options.all, |
| 107 | use_workon_only=options.workon_only, |
| 108 | ) |
| 109 | elif options.command == "stop": |
| 110 | helper.StopWorkingOnPackages( |
| 111 | options.packages, |
| 112 | use_all=options.all, |
| 113 | use_workon_only=options.workon_only, |
| 114 | ) |
| 115 | elif options.command == "info": |
| 116 | triples = helper.GetPackageInfo( |
| 117 | options.packages, |
| 118 | use_all=options.all, |
| 119 | use_workon_only=options.workon_only, |
| 120 | ) |
| 121 | for package, repos, paths in triples: |
| 122 | print(package, ",".join(repos), ",".join(paths)) |
| 123 | elif options.command == "list": |
| 124 | packages = helper.ListAtoms( |
| 125 | use_all=options.all, use_workon_only=options.workon_only |
| 126 | ) |
| 127 | if packages: |
| 128 | print("\n".join(packages)) |
| 129 | elif options.command == "iterate": |
| 130 | helper.RunCommandInPackages( |
| 131 | options.packages, |
Mike Frysinger | e86f8d7 | 2023-08-08 00:29:38 -0400 | [diff] [blame^] | 132 | ["bash", "-c", options.iterate_command], |
Alex Klein | 1699fab | 2022-09-08 08:46:06 -0600 | [diff] [blame] | 133 | use_all=options.all, |
| 134 | use_workon_only=options.workon_only, |
| 135 | ) |
| 136 | except workon_helper.WorkonError as e: |
| 137 | cros_build_lib.Die(e) |
| 138 | |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 139 | return 0 |