blob: 8ddee5f181caf82f0b9fbeba078be2dde07c86d6 [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
13from __future__ import print_function
14
Christopher Wileyccd92f92015-04-14 14:14:19 -070015from chromite.lib import commandline
16from chromite.lib import cros_build_lib
17from chromite.lib import terminal
18from chromite.lib import workon_helper
19
20
21def main(argv):
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('--remote', default='',
Christopher Wileyccd92f92015-04-14 14:14:19 -070028 help='For non-workon projects, the git remote to use.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040029 parser.add_argument('--revision', default='',
Christopher Wileyccd92f92015-04-14 14:14:19 -070030 help='Use to override the manifest defined default '
31 'revision used for a project')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040032 parser.add_argument('--command', default='git status', dest='iterate_command',
Christopher Wileyccd92f92015-04-14 14:14:19 -070033 help='The command to be run by forall.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040034 parser.add_argument('--workon_only', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070035 help='Apply to packages that have a workon ebuild only')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040036 parser.add_argument('--all', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070037 help='Apply to all possible packages for the '
38 'given command (overrides workon_only)')
Christopher Wiley9385ea12015-05-08 13:18:45 -070039
Christopher Wiley6475b2b2015-05-12 14:25:33 -070040 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 Frysinger1341bdd2017-08-04 11:04:38 -040050 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 Wiley9385ea12015-05-08 13:18:45 -070054
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
76 sysroot = cros_build_lib.GetSysroot(board=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:
103 cros_build_lib.Die(e.message)
104
105 return 0