blob: 4b327f8cb61d6a88cf5daaaecf14b65f2760109e [file] [log] [blame]
David Jamese5867812012-10-19 12:02:20 -07001# Copyright (c) 2012 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
Don Garrett25f309a2014-03-19 14:02:12 -07005"""Calculate what overlays are needed for a particular board."""
David Jamese5867812012-10-19 12:02:20 -07006
7import optparse
8import os
9
10from chromite.lib import cros_build_lib
11from chromite.buildbot import constants
12from chromite.buildbot import portage_utilities
13
14
15def _ParseArguments(argv):
16 parser = optparse.OptionParser(usage='USAGE: %prog [options]')
17
18 parser.add_option('--board', default=None, help='Board name')
19 parser.add_option('--board_overlay', default=None,
20 help='Location of the board overlay. Used by ./setup_board '
21 'to allow developers to add custom overlays.')
22 parser.add_option('--primary_only', default=False, action='store_true',
23 help='Only return the path to the primary overlay. This '
24 'only makes sense when --board is specified.')
25
26 flags, remaining_arguments = parser.parse_args(argv)
27
28 if flags.primary_only and flags.board is None:
29 parser.error('--board is required when --primary_only is supplied.')
30
31 if remaining_arguments:
32 parser.print_help()
33 parser.error('Invalid arguments')
34
35 return flags
36
37
38def main(argv):
39 flags = _ParseArguments(argv)
40 args = (constants.BOTH_OVERLAYS, flags.board)
41
42 # Verify that a primary overlay exists.
43 try:
44 primary_overlay = portage_utilities.FindPrimaryOverlay(*args)
45 except portage_utilities.MissingOverlayException as ex:
46 cros_build_lib.Die(str(ex))
47
48 # Get the overlays to print.
49 if flags.primary_only:
50 overlays = [primary_overlay]
51 else:
52 overlays = portage_utilities.FindOverlays(*args)
53
54 # Exclude any overlays in src/third_party, for backwards compatibility with
55 # scripts that expected these to not be listed.
56 ignore_prefix = os.path.join(constants.SOURCE_ROOT, 'src', 'third_party')
57 overlays = [o for o in overlays if not o.startswith(ignore_prefix)]
58
59 if flags.board_overlay and os.path.isdir(flags.board_overlay):
60 overlays.append(os.path.abspath(flags.board_overlay))
61
62 print '\n'.join(overlays)