blob: a3fa2ea8f19c05f008314402f7901410c89931bd [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
Mike Frysinger06a51c82021-04-06 11:39:17 -040018from chromite.lib import build_target_lib
Christopher Wileyccd92f92015-04-14 14:14:19 -070019from chromite.lib import commandline
20from chromite.lib import cros_build_lib
21from chromite.lib import terminal
22from chromite.lib import workon_helper
23
24
Mike Frysingera942aee2020-03-20 03:53:37 -040025assert sys.version_info >= (3, 6), 'This module requires Python 3.6+'
26
27
Mike Frysingered5ab1d2017-10-23 14:10:28 -040028def GetParser():
29 """Get a CLI parser."""
Mike Frysinger1341bdd2017-08-04 11:04:38 -040030 parser = commandline.ArgumentParser(description=__doc__)
31 parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
Christopher Wileyccd92f92015-04-14 14:14:19 -070032 help='The board to set package keywords for.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040033 parser.add_argument('--host', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070034 help='Uses the host instead of board')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040035 parser.add_argument('--command', default='git status', dest='iterate_command',
Christopher Wileyccd92f92015-04-14 14:14:19 -070036 help='The command to be run by forall.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040037 parser.add_argument('--workon_only', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070038 help='Apply to packages that have a workon ebuild only')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040039 parser.add_argument('--all', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070040 help='Apply to all possible packages for the '
41 'given command (overrides workon_only)')
Christopher Wiley9385ea12015-05-08 13:18:45 -070042
Christopher Wiley6475b2b2015-05-12 14:25:33 -070043 commands = [
44 ('start', 'Moves an ebuild to live (intended to support development)'),
45 ('stop', 'Moves an ebuild to stable (use last known good)'),
46 ('info', 'Print package name, repo name, and source directory.'),
47 ('list', 'List of live ebuilds (workon ebuilds if --all)'),
48 ('list-all', 'List all of the live ebuilds for all setup boards'),
49 ('iterate', 'For each ebuild, cd to the source dir and run a command'),
50 ]
51 command_parsers = parser.add_subparsers(dest='command', title='commands')
52 for command, description in commands:
Mike Frysinger1341bdd2017-08-04 11:04:38 -040053 sub_parser = command_parsers.add_parser(command, description=description,
54 help=description)
55 sub_parser.add_argument('packages', nargs='*',
56 help='The packages to run command against.')
Christopher Wiley9385ea12015-05-08 13:18:45 -070057
Mike Frysingered5ab1d2017-10-23 14:10:28 -040058 return parser
59
60
61def main(argv):
62 parser = GetParser()
Christopher Wileyccd92f92015-04-14 14:14:19 -070063 options = parser.parse_args(argv)
64 options.Freeze()
65
66 if options.command == 'list-all':
67 board_to_packages = workon_helper.ListAllWorkedOnAtoms()
68 color = terminal.Color()
69 for board in sorted(board_to_packages):
70 print(color.Start(color.GREEN) + board + ':' + color.Stop())
71 for package in board_to_packages[board]:
72 print(' ' + package)
73 print('')
74 return 0
75
76 # TODO(wiley): Assert that we're not running as root.
77 cros_build_lib.AssertInsideChroot()
78
79 if options.host:
80 friendly_name = 'host'
81 sysroot = '/'
82 elif options.board:
83 friendly_name = options.board
Mike Frysinger06a51c82021-04-06 11:39:17 -040084 sysroot = build_target_lib.get_default_sysroot_path(options.board)
Christopher Wileyccd92f92015-04-14 14:14:19 -070085 else:
Don Garrettc0c74002015-10-09 12:58:19 -070086 cros_build_lib.Die('You must specify either --host, --board')
Christopher Wileyccd92f92015-04-14 14:14:19 -070087
88 helper = workon_helper.WorkonHelper(sysroot, friendly_name)
89 try:
90 if options.command == 'start':
91 helper.StartWorkingOnPackages(options.packages, use_all=options.all,
92 use_workon_only=options.workon_only)
93 elif options.command == 'stop':
94 helper.StopWorkingOnPackages(options.packages, use_all=options.all,
95 use_workon_only=options.workon_only)
96 elif options.command == 'info':
Christopher Wileya13655e2015-05-08 16:26:38 -070097 triples = helper.GetPackageInfo(options.packages, use_all=options.all,
98 use_workon_only=options.workon_only)
99 for package, repos, paths in triples:
100 print(package, ','.join(repos), ','.join(paths))
Christopher Wileyccd92f92015-04-14 14:14:19 -0700101 elif options.command == 'list':
102 packages = helper.ListAtoms(
103 use_all=options.all, use_workon_only=options.workon_only)
104 if packages:
105 print('\n'.join(packages))
106 elif options.command == 'iterate':
107 helper.RunCommandInPackages(options.packages, options.iterate_command,
108 use_all=options.all,
109 use_workon_only=options.workon_only)
110 except workon_helper.WorkonError as e:
Mike Frysinger6b5c3cd2019-08-27 16:51:00 -0400111 cros_build_lib.Die(e)
Christopher Wileyccd92f92015-04-14 14:14:19 -0700112
113 return 0