blob: a06e8fb667cfe643c5441cfb528e2aa3c28969d0 [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
22def main(argv):
Mike Frysinger1341bdd2017-08-04 11:04:38 -040023 parser = commandline.ArgumentParser(description=__doc__)
24 parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
Christopher Wileyccd92f92015-04-14 14:14:19 -070025 help='The board to set package keywords for.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040026 parser.add_argument('--host', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070027 help='Uses the host instead of board')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040028 parser.add_argument('--remote', default='',
Christopher Wileyccd92f92015-04-14 14:14:19 -070029 help='For non-workon projects, the git remote to use.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040030 parser.add_argument('--revision', default='',
Christopher Wileyccd92f92015-04-14 14:14:19 -070031 help='Use to override the manifest defined default '
32 'revision used for a project')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040033 parser.add_argument('--command', default='git status', dest='iterate_command',
Christopher Wileyccd92f92015-04-14 14:14:19 -070034 help='The command to be run by forall.')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040035 parser.add_argument('--workon_only', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070036 help='Apply to packages that have a workon ebuild only')
Mike Frysinger1341bdd2017-08-04 11:04:38 -040037 parser.add_argument('--all', default=False, action='store_true',
Christopher Wileyccd92f92015-04-14 14:14:19 -070038 help='Apply to all possible packages for the '
39 'given command (overrides workon_only)')
Christopher Wiley9385ea12015-05-08 13:18:45 -070040
Christopher Wiley6475b2b2015-05-12 14:25:33 -070041 commands = [
42 ('start', 'Moves an ebuild to live (intended to support development)'),
43 ('stop', 'Moves an ebuild to stable (use last known good)'),
44 ('info', 'Print package name, repo name, and source directory.'),
45 ('list', 'List of live ebuilds (workon ebuilds if --all)'),
46 ('list-all', 'List all of the live ebuilds for all setup boards'),
47 ('iterate', 'For each ebuild, cd to the source dir and run a command'),
48 ]
49 command_parsers = parser.add_subparsers(dest='command', title='commands')
50 for command, description in commands:
Mike Frysinger1341bdd2017-08-04 11:04:38 -040051 sub_parser = command_parsers.add_parser(command, description=description,
52 help=description)
53 sub_parser.add_argument('packages', nargs='*',
54 help='The packages to run command against.')
Christopher Wiley9385ea12015-05-08 13:18:45 -070055
Christopher Wileyccd92f92015-04-14 14:14:19 -070056 options = parser.parse_args(argv)
57 options.Freeze()
58
59 if options.command == 'list-all':
60 board_to_packages = workon_helper.ListAllWorkedOnAtoms()
61 color = terminal.Color()
62 for board in sorted(board_to_packages):
63 print(color.Start(color.GREEN) + board + ':' + color.Stop())
64 for package in board_to_packages[board]:
65 print(' ' + package)
66 print('')
67 return 0
68
69 # TODO(wiley): Assert that we're not running as root.
70 cros_build_lib.AssertInsideChroot()
71
72 if options.host:
73 friendly_name = 'host'
74 sysroot = '/'
75 elif options.board:
76 friendly_name = options.board
77 sysroot = cros_build_lib.GetSysroot(board=options.board)
Christopher Wileyccd92f92015-04-14 14:14:19 -070078 else:
Don Garrettc0c74002015-10-09 12:58:19 -070079 cros_build_lib.Die('You must specify either --host, --board')
Christopher Wileyccd92f92015-04-14 14:14:19 -070080
81 helper = workon_helper.WorkonHelper(sysroot, friendly_name)
82 try:
83 if options.command == 'start':
84 helper.StartWorkingOnPackages(options.packages, use_all=options.all,
85 use_workon_only=options.workon_only)
86 elif options.command == 'stop':
87 helper.StopWorkingOnPackages(options.packages, use_all=options.all,
88 use_workon_only=options.workon_only)
89 elif options.command == 'info':
Christopher Wileya13655e2015-05-08 16:26:38 -070090 triples = helper.GetPackageInfo(options.packages, use_all=options.all,
91 use_workon_only=options.workon_only)
92 for package, repos, paths in triples:
93 print(package, ','.join(repos), ','.join(paths))
Christopher Wileyccd92f92015-04-14 14:14:19 -070094 elif options.command == 'list':
95 packages = helper.ListAtoms(
96 use_all=options.all, use_workon_only=options.workon_only)
97 if packages:
98 print('\n'.join(packages))
99 elif options.command == 'iterate':
100 helper.RunCommandInPackages(options.packages, options.iterate_command,
101 use_all=options.all,
102 use_workon_only=options.workon_only)
103 except workon_helper.WorkonError as e:
104 cros_build_lib.Die(e.message)
105
106 return 0