blob: c28ef2b2ac615348ef7ddb2d4f08eea8b45904ef [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
Mike Frysinger58f9eb72014-08-26 10:10:47 -04007from __future__ import print_function
8
David Jamese5867812012-10-19 12:02:20 -07009import os
10
Mike Frysinger58f9eb72014-08-26 10:10:47 -040011from chromite.lib import commandline
David Jamese5867812012-10-19 12:02:20 -070012from chromite.lib import cros_build_lib
Don Garrett88b8d782014-05-13 17:30:55 -070013from chromite.cbuildbot import constants
14from chromite.cbuildbot import portage_utilities
David Jamese5867812012-10-19 12:02:20 -070015
16
17def _ParseArguments(argv):
Mike Frysinger58f9eb72014-08-26 10:10:47 -040018 parser = commandline.ArgumentParser(description=__doc__)
David Jamese5867812012-10-19 12:02:20 -070019
Mike Frysinger58f9eb72014-08-26 10:10:47 -040020 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 '
24 'overlays.')
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.')
David Jamese5867812012-10-19 12:02:20 -070028
Mike Frysinger58f9eb72014-08-26 10:10:47 -040029 opts = parser.parse_args(argv)
30 opts.Freeze()
David Jamese5867812012-10-19 12:02:20 -070031
Mike Frysinger58f9eb72014-08-26 10:10:47 -040032 if opts.primary_only and opts.board is None:
David Jamese5867812012-10-19 12:02:20 -070033 parser.error('--board is required when --primary_only is supplied.')
34
Mike Frysinger58f9eb72014-08-26 10:10:47 -040035 return opts
David Jamese5867812012-10-19 12:02:20 -070036
37
38def main(argv):
Mike Frysinger58f9eb72014-08-26 10:10:47 -040039 opts = _ParseArguments(argv)
40 args = (constants.BOTH_OVERLAYS, opts.board)
David Jamese5867812012-10-19 12:02:20 -070041
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.
Mike Frysinger58f9eb72014-08-26 10:10:47 -040049 if opts.primary_only:
David Jamese5867812012-10-19 12:02:20 -070050 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
Mike Frysinger58f9eb72014-08-26 10:10:47 -040059 if opts.board_overlay and os.path.isdir(opts.board_overlay):
60 overlays.append(os.path.abspath(opts.board_overlay))
David Jamese5867812012-10-19 12:02:20 -070061
Mike Frysinger58f9eb72014-08-26 10:10:47 -040062 print('\n'.join(overlays))