blob: 5e9462fd86af9801c0b75ab53ecb6b3b5fe107bb [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.
11
12commands:
13 start: Moves an ebuild to live (intended to support development)
14 stop: Moves an ebuild to stable (use last known good)
15 info: Print package name, repo name, and source directory.
16 list: List of live ebuilds (workon ebuilds if --all)
17 list-all: List all of the live ebuilds for all setup boards
18 iterate: For each ebuild, cd to the source dir and run a command"
19
20"""
21
22from __future__ import print_function
23
24from chromite.lib import brick_lib
25from chromite.lib import commandline
26from chromite.lib import cros_build_lib
27from chromite.lib import terminal
28from chromite.lib import workon_helper
29
30
31def main(argv):
32 parser = commandline.ArgumentParser(description=__doc__)
33 parser.add_argument(
34 'command',
35 choices=('start', 'stop', 'info', 'list', 'list-all', 'iterate'),
36 help='cros_workon command to run.')
37 parser.add_argument('--board', default=cros_build_lib.GetDefaultBoard(),
38 help='The board to set package keywords for.')
39 parser.add_argument('--brick', help='The brick to set package keywords for.')
40 parser.add_argument('--host', default=False, action='store_true',
41 help='Uses the host instead of board')
42 parser.add_argument('--remote', default='',
43 help='For non-workon projects, the git remote to use.')
44 parser.add_argument('--revision', default='',
45 help='Use to override the manifest defined default '
46 'revision used for a project')
47 parser.add_argument('--command', default='git status', dest='iterate_command',
48 help='The command to be run by forall.')
49 parser.add_argument('--workon_only', default=False, action='store_true',
50 help='Apply to packages that have a workon ebuild only')
51 parser.add_argument('--all', default=False, action='store_true',
52 help='Apply to all possible packages for the '
53 'given command (overrides workon_only)')
54 parser.add_argument('packages', nargs='*',
55 help='The packages to run command against.')
56 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)
78 elif options.brick:
79 brick = brick_lib.Brick(options.brick)
80 friendly_name = brick.FriendlyName()
81 # TODO(wiley) This is a hack. It doesn't really make sense to calculate
82 # the sysroot from a brick alone, since bricks are installed
83 # into sysroots. Revisit this when blueprints are working.
84 sysroot = cros_build_lib.GetSysroot(friendly_name)
85 else:
86 cros_build_lib.Die('You must specify either --host, --board or --brick')
87
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':
97 cros_build_lib.Die('%s is not implemented.', options.command)
98 elif options.command == 'list':
99 packages = helper.ListAtoms(
100 use_all=options.all, use_workon_only=options.workon_only)
101 if packages:
102 print('\n'.join(packages))
103 elif options.command == 'iterate':
104 helper.RunCommandInPackages(options.packages, options.iterate_command,
105 use_all=options.all,
106 use_workon_only=options.workon_only)
107 except workon_helper.WorkonError as e:
108 cros_build_lib.Die(e.message)
109
110 return 0