blob: 87fd96179452117c84e06800684ab234f6472c91 [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
Mike Frysingera942aee2020-03-20 03:53:37 -040016import sys
17
Christopher Wileyccd92f92015-04-14 14:14:19 -070018from chromite.lib import commandline
19from chromite.lib import cros_build_lib
20from chromite.lib import terminal
21from chromite.lib import workon_helper
22
23
Mike Frysingera942aee2020-03-20 03:53:37 -040024assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
25
26
Mike Frysingered5ab1d2017-10-23 14:10:28 -040027def GetParser():
28 """Get a CLI parser."""
Mike Frysinger1341bdd2017-08-04 11:04:38 -040029 parser = commandline.ArgumentParser(description=__doc__)
30 parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
Christopher Wileyccd92f92015-04-14 14:14:19 -070031 help='The board to set package keywords for.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040032 parser.add_argument('--host', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070033 help='Uses the host instead of board')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040034 parser.add_argument('--command', default='git status', dest='iterate_command',
Christopher Wileyccd92f92015-04-14 14:14:19 -070035 help='The command to be run by forall.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040036 parser.add_argument('--workon_only', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070037 help='Apply to packages that have a workon ebuild only')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040038 parser.add_argument('--all', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070039 help='Apply to all possible packages for the '
40 'given command (overrides workon_only)')
Christopher Wiley9385ea12015-05-08 13:18:45 -070041
Christopher Wiley6475b2b2015-05-12 14:25:33 -070042 commands = [
43 ('start', 'Moves an ebuild to live (intended to support development)'),
44 ('stop', 'Moves an ebuild to stable (use last known good)'),
45 ('info', 'Print package name, repo name, and source directory.'),
46 ('list', 'List of live ebuilds (workon ebuilds if --all)'),
47 ('list-all', 'List all of the live ebuilds for all setup boards'),
48 ('iterate', 'For each ebuild, cd to the source dir and run a command'),
49 ]
50 command_parsers = parser.add_subparsers(dest='command', title='commands')
51 for command, description in commands:
Mike Frysinger1341bdd2017-08-04 11:04:38 -040052 sub_parser = command_parsers.add_parser(command, description=description,
53 help=description)
54 sub_parser.add_argument('packages', nargs='*',
55 help='The packages to run command against.')
Christopher Wiley9385ea12015-05-08 13:18:45 -070056
Mike Frysingered5ab1d2017-10-23 14:10:28 -040057 return parser
58
59
60def main(argv):
61 parser = GetParser()
Christopher Wileyccd92f92015-04-14 14:14:19 -070062 options = parser.parse_args(argv)
63 options.Freeze()
64
65 if options.command == 'list-all':
66 board_to_packages = workon_helper.ListAllWorkedOnAtoms()
67 color = terminal.Color()
68 for board in sorted(board_to_packages):
69 print(color.Start(color.GREEN) + board + ':' + color.Stop())
70 for package in board_to_packages[board]:
71 print(' ' + package)
72 print('')
73 return 0
74
75 # TODO(wiley): Assert that we're not running as root.
76 cros_build_lib.AssertInsideChroot()
77
78 if options.host:
79 friendly_name = 'host'
80 sysroot = '/'
81 elif options.board:
82 friendly_name = options.board
Jack Rosenthalb984e102021-04-07 21:18:29 +000083 sysroot = cros_build_lib.GetSysroot(board=options.board)
Christopher Wileyccd92f92015-04-14 14:14:19 -070084 else:
Don Garrettc0c74002015-10-09 12:58:19 -070085 cros_build_lib.Die('You must specify either --host, --board')
Christopher Wileyccd92f92015-04-14 14:14:19 -070086
87 helper = workon_helper.WorkonHelper(sysroot, friendly_name)
88 try:
89 if options.command == 'start':
90 helper.StartWorkingOnPackages(options.packages, use_all=options.all,
91 use_workon_only=options.workon_only)
92 elif options.command == 'stop':
93 helper.StopWorkingOnPackages(options.packages, use_all=options.all,
94 use_workon_only=options.workon_only)
95 elif options.command == 'info':
Christopher Wileya13655e2015-05-08 16:26:38 -070096 triples = helper.GetPackageInfo(options.packages, use_all=options.all,
97 use_workon_only=options.workon_only)
98 for package, repos, paths in triples:
99 print(package, ','.join(repos), ','.join(paths))
Christopher Wileyccd92f92015-04-14 14:14:19 -0700100 elif options.command == 'list':
101 packages = helper.ListAtoms(
102 use_all=options.all, use_workon_only=options.workon_only)
103 if packages:
104 print('\n'.join(packages))
105 elif options.command == 'iterate':
106 helper.RunCommandInPackages(options.packages, options.iterate_command,
107 use_all=options.all,
108 use_workon_only=options.workon_only)
109 except workon_helper.WorkonError as e:
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -0400110 cros_build_lib.Die(e)
Christopher Wileyccd92f92015-04-14 14:14:19 -0700111
112 return 0