blob: 05f6d65be6ad97223162330bab7cee90a95cc09d [file] [log] [blame]
Mike Frysingere58c0e22017-10-04 15:43:30 -04001# -*- coding: utf-8 -*-
Christopher Wileyccd92f92015-04-14 14:14:19 -07002# Copyright 2015 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6"""This script moves ebuilds between 'stable' and 'live' states.
7
8By default 'stable' ebuilds point at and build from source at the
9last known good commit. Moving an ebuild to 'live' (via cros_workon start)
10is intended to support development. The current source tip is fetched,
11source modified and built using the unstable 'live' (9999) ebuild.
Christopher Wileyccd92f92015-04-14 14:14:19 -070012"""
13
14from __future__ import print_function
15
Christopher Wileyccd92f92015-04-14 14:14:19 -070016from chromite.lib import commandline
17from chromite.lib import cros_build_lib
18from chromite.lib import terminal
19from chromite.lib import workon_helper
20
21
Mike Frysingered5ab1d2017-10-23 14:10:28 -040022def GetParser():
23 """Get a CLI parser."""
Mike Frysinger1341bdd2017-08-04 11:04:38 -040024 parser = commandline.ArgumentParser(description=__doc__)
25 parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
Christopher Wileyccd92f92015-04-14 14:14:19 -070026 help='The board to set package keywords for.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040027 parser.add_argument('--host', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070028 help='Uses the host instead of board')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040029 parser.add_argument('--command', default='git status', dest='iterate_command',
Christopher Wileyccd92f92015-04-14 14:14:19 -070030 help='The command to be run by forall.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040031 parser.add_argument('--workon_only', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070032 help='Apply to packages that have a workon ebuild only')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040033 parser.add_argument('--all', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070034 help='Apply to all possible packages for the '
35 'given command (overrides workon_only)')
Christopher Wiley9385ea12015-05-08 13:18:45 -070036
Christopher Wiley6475b2b2015-05-12 14:25:33 -070037 commands = [
38 ('start', 'Moves an ebuild to live (intended to support development)'),
39 ('stop', 'Moves an ebuild to stable (use last known good)'),
40 ('info', 'Print package name, repo name, and source directory.'),
41 ('list', 'List of live ebuilds (workon ebuilds if --all)'),
42 ('list-all', 'List all of the live ebuilds for all setup boards'),
43 ('iterate', 'For each ebuild, cd to the source dir and run a command'),
44 ]
45 command_parsers = parser.add_subparsers(dest='command', title='commands')
46 for command, description in commands:
Mike Frysinger1341bdd2017-08-04 11:04:38 -040047 sub_parser = command_parsers.add_parser(command, description=description,
48 help=description)
49 sub_parser.add_argument('packages', nargs='*',
50 help='The packages to run command against.')
Christopher Wiley9385ea12015-05-08 13:18:45 -070051
Mike Frysingered5ab1d2017-10-23 14:10:28 -040052 return parser
53
54
55def main(argv):
56 parser = GetParser()
Christopher Wileyccd92f92015-04-14 14:14:19 -070057 options = parser.parse_args(argv)
58 options.Freeze()
59
60 if options.command == 'list-all':
61 board_to_packages = workon_helper.ListAllWorkedOnAtoms()
62 color = terminal.Color()
63 for board in sorted(board_to_packages):
64 print(color.Start(color.GREEN) + board + ':' + color.Stop())
65 for package in board_to_packages[board]:
66 print(' ' + package)
67 print('')
68 return 0
69
70 # TODO(wiley): Assert that we're not running as root.
71 cros_build_lib.AssertInsideChroot()
72
73 if options.host:
74 friendly_name = 'host'
75 sysroot = '/'
76 elif options.board:
77 friendly_name = options.board
78 sysroot = cros_build_lib.GetSysroot(board=options.board)
Christopher Wileyccd92f92015-04-14 14:14:19 -070079 else:
Don Garrettc0c74002015-10-09 12:58:19 -070080 cros_build_lib.Die('You must specify either --host, --board')
Christopher Wileyccd92f92015-04-14 14:14:19 -070081
82 helper = workon_helper.WorkonHelper(sysroot, friendly_name)
83 try:
84 if options.command == 'start':
85 helper.StartWorkingOnPackages(options.packages, use_all=options.all,
86 use_workon_only=options.workon_only)
87 elif options.command == 'stop':
88 helper.StopWorkingOnPackages(options.packages, use_all=options.all,
89 use_workon_only=options.workon_only)
90 elif options.command == 'info':
Christopher Wileya13655e2015-05-08 16:26:38 -070091 triples = helper.GetPackageInfo(options.packages, use_all=options.all,
92 use_workon_only=options.workon_only)
93 for package, repos, paths in triples:
94 print(package, ','.join(repos), ','.join(paths))
Christopher Wileyccd92f92015-04-14 14:14:19 -070095 elif options.command == 'list':
96 packages = helper.ListAtoms(
97 use_all=options.all, use_workon_only=options.workon_only)
98 if packages:
99 print('\n'.join(packages))
100 elif options.command == 'iterate':
101 helper.RunCommandInPackages(options.packages, options.iterate_command,
102 use_all=options.all,
103 use_workon_only=options.workon_only)
104 except workon_helper.WorkonError as e:
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -0400105 cros_build_lib.Die(e)
Christopher Wileyccd92f92015-04-14 14:14:19 -0700106
107 return 0