blob: 2aacbcb16001bb89a6e3652f759b31469e1a523f [file] [log] [blame]
Christopher Wileyccd92f92015-04-14 14:14:19 -07001# 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
7By default 'stable' ebuilds point at and build from source at the
8last known good commit. Moving an ebuild to 'live' (via cros_workon start)
9is intended to support development. The current source tip is fetched,
10source modified and built using the unstable 'live' (9999) ebuild.
Christopher Wileyccd92f92015-04-14 14:14:19 -070011"""
12
Mike Frysinger06a51c82021-04-06 11:39:17 -040013from chromite.lib import build_target_lib
Christopher Wileyccd92f92015-04-14 14:14:19 -070014from chromite.lib import commandline
15from chromite.lib import cros_build_lib
16from chromite.lib import terminal
17from chromite.lib import workon_helper
18
19
Mike Frysingered5ab1d2017-10-23 14:10:28 -040020def GetParser():
21 """Get a CLI parser."""
Mike Frysinger1341bdd2017-08-04 11:04:38 -040022 parser = commandline.ArgumentParser(description=__doc__)
23 parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
Christopher Wileyccd92f92015-04-14 14:14:19 -070024 help='The board to set package keywords for.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040025 parser.add_argument('--host', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070026 help='Uses the host instead of board')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040027 parser.add_argument('--command', default='git status', dest='iterate_command',
Christopher Wileyccd92f92015-04-14 14:14:19 -070028 help='The command to be run by forall.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040029 parser.add_argument('--workon_only', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070030 help='Apply to packages that have a workon ebuild only')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040031 parser.add_argument('--all', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070032 help='Apply to all possible packages for the '
33 'given command (overrides workon_only)')
Christopher Wiley9385ea12015-05-08 13:18:45 -070034
Christopher Wiley6475b2b2015-05-12 14:25:33 -070035 commands = [
36 ('start', 'Moves an ebuild to live (intended to support development)'),
37 ('stop', 'Moves an ebuild to stable (use last known good)'),
38 ('info', 'Print package name, repo name, and source directory.'),
39 ('list', 'List of live ebuilds (workon ebuilds if --all)'),
40 ('list-all', 'List all of the live ebuilds for all setup boards'),
41 ('iterate', 'For each ebuild, cd to the source dir and run a command'),
42 ]
43 command_parsers = parser.add_subparsers(dest='command', title='commands')
44 for command, description in commands:
Mike Frysinger1341bdd2017-08-04 11:04:38 -040045 sub_parser = command_parsers.add_parser(command, description=description,
46 help=description)
47 sub_parser.add_argument('packages', nargs='*',
48 help='The packages to run command against.')
Christopher Wiley9385ea12015-05-08 13:18:45 -070049
Mike Frysingered5ab1d2017-10-23 14:10:28 -040050 return parser
51
52
53def main(argv):
54 parser = GetParser()
Christopher Wileyccd92f92015-04-14 14:14:19 -070055 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
Mike Frysinger06a51c82021-04-06 11:39:17 -040076 sysroot = build_target_lib.get_default_sysroot_path(options.board)
Christopher Wileyccd92f92015-04-14 14:14:19 -070077 else:
Don Garrettc0c74002015-10-09 12:58:19 -070078 cros_build_lib.Die('You must specify either --host, --board')
Christopher Wileyccd92f92015-04-14 14:14:19 -070079
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 Wileya13655e2015-05-08 16:26:38 -070089 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 Wileyccd92f92015-04-14 14:14:19 -070093 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:
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -0400103 cros_build_lib.Die(e)
Christopher Wileyccd92f92015-04-14 14:14:19 -0700104
105 return 0