blob: 2cead1b9bcc20badeed52b8b65525e8b79b91865 [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
Alex Deymo075c2292014-09-04 18:31:50 -070011from chromite.cbuildbot import constants
Bertrand SIMONNET07bc5c02015-03-06 17:38:01 -080012from chromite.lib import brick_lib
Mike Frysinger58f9eb72014-08-26 10:10:47 -040013from chromite.lib import commandline
David Jamese5867812012-10-19 12:02:20 -070014from chromite.lib import cros_build_lib
Alex Deymo075c2292014-09-04 18:31:50 -070015from chromite.lib import portage_util
David Jamese5867812012-10-19 12:02:20 -070016
17
18def _ParseArguments(argv):
Mike Frysinger58f9eb72014-08-26 10:10:47 -040019 parser = commandline.ArgumentParser(description=__doc__)
David Jamese5867812012-10-19 12:02:20 -070020
Mike Frysinger58f9eb72014-08-26 10:10:47 -040021 parser.add_argument('--board', default=None, help='Board name')
22 parser.add_argument('--board_overlay', default=None,
23 help='Location of the board overlay. Used by '
24 './setup_board to allow developers to add custom '
25 'overlays.')
26 parser.add_argument('--primary_only', default=False, action='store_true',
27 help='Only return the path to the primary overlay. This '
28 'only makes sense when --board is specified.')
Mike Frysinger320b5012014-10-31 16:46:41 -040029 parser.add_argument('-a', '--all', default=False, action='store_true',
30 help='Show all overlays (even common ones).')
Bertrand SIMONNET07bc5c02015-03-06 17:38:01 -080031 parser.add_argument('--brick', help='Main brick to use')
David Jamese5867812012-10-19 12:02:20 -070032
Mike Frysinger58f9eb72014-08-26 10:10:47 -040033 opts = parser.parse_args(argv)
34 opts.Freeze()
David Jamese5867812012-10-19 12:02:20 -070035
Mike Frysinger58f9eb72014-08-26 10:10:47 -040036 if opts.primary_only and opts.board is None:
David Jamese5867812012-10-19 12:02:20 -070037 parser.error('--board is required when --primary_only is supplied.')
38
Bertrand SIMONNET07bc5c02015-03-06 17:38:01 -080039 if opts.brick:
40 if opts.board:
41 parser.error('--board and --brick are incompatible.')
42
43 if opts.all:
44 parser.error('Cannot list all overlays with --brick')
45
Mike Frysinger58f9eb72014-08-26 10:10:47 -040046 return opts
David Jamese5867812012-10-19 12:02:20 -070047
48
49def main(argv):
Mike Frysinger58f9eb72014-08-26 10:10:47 -040050 opts = _ParseArguments(argv)
51 args = (constants.BOTH_OVERLAYS, opts.board)
David Jamese5867812012-10-19 12:02:20 -070052
Bertrand SIMONNET07bc5c02015-03-06 17:38:01 -080053 if opts.brick:
54 main_brick = brick_lib.Brick(opts.brick)
55 overlays = [b.OverlayDir() for b in main_brick.BrickStack()]
David Jamese5867812012-10-19 12:02:20 -070056 else:
Bertrand SIMONNET07bc5c02015-03-06 17:38:01 -080057 # Verify that a primary overlay exists.
58 try:
59 primary_overlay = portage_util.FindPrimaryOverlay(*args)
60 except portage_util.MissingOverlayException as ex:
61 cros_build_lib.Die(str(ex))
62
63 # Get the overlays to print.
64 if opts.primary_only:
65 overlays = [primary_overlay]
66 else:
67 overlays = portage_util.FindOverlays(*args)
David Jamese5867812012-10-19 12:02:20 -070068
69 # Exclude any overlays in src/third_party, for backwards compatibility with
70 # scripts that expected these to not be listed.
Mike Frysinger320b5012014-10-31 16:46:41 -040071 if not opts.all:
72 ignore_prefix = os.path.join(constants.SOURCE_ROOT, 'src', 'third_party')
73 overlays = [o for o in overlays if not o.startswith(ignore_prefix)]
David Jamese5867812012-10-19 12:02:20 -070074
Mike Frysinger58f9eb72014-08-26 10:10:47 -040075 if opts.board_overlay and os.path.isdir(opts.board_overlay):
76 overlays.append(os.path.abspath(opts.board_overlay))
David Jamese5867812012-10-19 12:02:20 -070077
Mike Frysinger58f9eb72014-08-26 10:10:47 -040078 print('\n'.join(overlays))