Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 1 | # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 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 | |
| 13 | from __future__ import print_function |
| 14 | |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 15 | from chromite.lib import commandline |
| 16 | from chromite.lib import cros_build_lib |
| 17 | from chromite.lib import terminal |
| 18 | from chromite.lib import workon_helper |
| 19 | |
| 20 | |
| 21 | def main(argv): |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 22 | parser = commandline.ArgumentParser(description=__doc__) |
| 23 | parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(), |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 24 | help='The board to set package keywords for.') |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 25 | parser.add_argument('--host', default=False, action='store_true', |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 26 | help='Uses the host instead of board') |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 27 | parser.add_argument('--remote', default='', |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 28 | help='For non-workon projects, the git remote to use.') |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 29 | parser.add_argument('--revision', default='', |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 30 | help='Use to override the manifest defined default ' |
| 31 | 'revision used for a project') |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 32 | parser.add_argument('--command', default='git status', dest='iterate_command', |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 33 | help='The command to be run by forall.') |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 34 | parser.add_argument('--workon_only', default=False, action='store_true', |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 35 | help='Apply to packages that have a workon ebuild only') |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 36 | parser.add_argument('--all', default=False, action='store_true', |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 37 | help='Apply to all possible packages for the ' |
| 38 | 'given command (overrides workon_only)') |
Christopher Wiley | 9385ea1 | 2015-05-08 13:18:45 -0700 | [diff] [blame] | 39 | |
Christopher Wiley | 6475b2b | 2015-05-12 14:25:33 -0700 | [diff] [blame] | 40 | commands = [ |
| 41 | ('start', 'Moves an ebuild to live (intended to support development)'), |
| 42 | ('stop', 'Moves an ebuild to stable (use last known good)'), |
| 43 | ('info', 'Print package name, repo name, and source directory.'), |
| 44 | ('list', 'List of live ebuilds (workon ebuilds if --all)'), |
| 45 | ('list-all', 'List all of the live ebuilds for all setup boards'), |
| 46 | ('iterate', 'For each ebuild, cd to the source dir and run a command'), |
| 47 | ] |
| 48 | command_parsers = parser.add_subparsers(dest='command', title='commands') |
| 49 | for command, description in commands: |
Mike Frysinger | 1341bdd | 2017-08-04 11:04:38 -0400 | [diff] [blame^] | 50 | sub_parser = command_parsers.add_parser(command, description=description, |
| 51 | help=description) |
| 52 | sub_parser.add_argument('packages', nargs='*', |
| 53 | help='The packages to run command against.') |
Christopher Wiley | 9385ea1 | 2015-05-08 13:18:45 -0700 | [diff] [blame] | 54 | |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 55 | options = parser.parse_args(argv) |
| 56 | options.Freeze() |
| 57 | |
| 58 | if options.command == 'list-all': |
| 59 | board_to_packages = workon_helper.ListAllWorkedOnAtoms() |
| 60 | color = terminal.Color() |
| 61 | for board in sorted(board_to_packages): |
| 62 | print(color.Start(color.GREEN) + board + ':' + color.Stop()) |
| 63 | for package in board_to_packages[board]: |
| 64 | print(' ' + package) |
| 65 | print('') |
| 66 | return 0 |
| 67 | |
| 68 | # TODO(wiley): Assert that we're not running as root. |
| 69 | cros_build_lib.AssertInsideChroot() |
| 70 | |
| 71 | if options.host: |
| 72 | friendly_name = 'host' |
| 73 | sysroot = '/' |
| 74 | elif options.board: |
| 75 | friendly_name = options.board |
| 76 | sysroot = cros_build_lib.GetSysroot(board=options.board) |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 77 | else: |
Don Garrett | c0c7400 | 2015-10-09 12:58:19 -0700 | [diff] [blame] | 78 | cros_build_lib.Die('You must specify either --host, --board') |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 79 | |
| 80 | helper = workon_helper.WorkonHelper(sysroot, friendly_name) |
| 81 | try: |
| 82 | if options.command == 'start': |
| 83 | helper.StartWorkingOnPackages(options.packages, use_all=options.all, |
| 84 | use_workon_only=options.workon_only) |
| 85 | elif options.command == 'stop': |
| 86 | helper.StopWorkingOnPackages(options.packages, use_all=options.all, |
| 87 | use_workon_only=options.workon_only) |
| 88 | elif options.command == 'info': |
Christopher Wiley | a13655e | 2015-05-08 16:26:38 -0700 | [diff] [blame] | 89 | triples = helper.GetPackageInfo(options.packages, use_all=options.all, |
| 90 | use_workon_only=options.workon_only) |
| 91 | for package, repos, paths in triples: |
| 92 | print(package, ','.join(repos), ','.join(paths)) |
Christopher Wiley | ccd92f9 | 2015-04-14 14:14:19 -0700 | [diff] [blame] | 93 | elif options.command == 'list': |
| 94 | packages = helper.ListAtoms( |
| 95 | use_all=options.all, use_workon_only=options.workon_only) |
| 96 | if packages: |
| 97 | print('\n'.join(packages)) |
| 98 | elif options.command == 'iterate': |
| 99 | helper.RunCommandInPackages(options.packages, options.iterate_command, |
| 100 | use_all=options.all, |
| 101 | use_workon_only=options.workon_only) |
| 102 | except workon_helper.WorkonError as e: |
| 103 | cros_build_lib.Die(e.message) |
| 104 | |
| 105 | return 0 |