1 # 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.
5 """Calculate what overlays are needed for a particular board."""
7 from __future__ import print_function
11 from chromite.cbuildbot import constants
12 from chromite.lib import commandline
13 from chromite.lib import cros_build_lib
14 from chromite.lib import portage_util
17 def _ParseArguments(argv):
18 parser = commandline.ArgumentParser(description=__doc__)
20 parser.add_argument('--board', default=None, help='Board name')
21 parser.add_argument('--board_overlay', default=None,
22 help='Location of the board overlay. Used by '
23 './setup_board to allow developers to add custom '
25 parser.add_argument('--primary_only', default=False, action='store_true',
26 help='Only return the path to the primary overlay. This '
27 'only makes sense when --board is specified.')
29 opts = parser.parse_args(argv)
32 if opts.primary_only and opts.board is None:
33 parser.error('--board is required when --primary_only is supplied.')
39 opts = _ParseArguments(argv)
40 args = (constants.BOTH_OVERLAYS, opts.board)
42 # Verify that a primary overlay exists.
44 primary_overlay = portage_util.FindPrimaryOverlay(*args)
45 except portage_util.MissingOverlayException as ex:
46 cros_build_lib.Die(str(ex))
48 # Get the overlays to print.
50 overlays = [primary_overlay]
52 overlays = portage_util.FindOverlays(*args)
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)]
59 if opts.board_overlay and os.path.isdir(opts.board_overlay):
60 overlays.append(os.path.abspath(opts.board_overlay))
62 print('\n'.join(overlays))