summaryrefslogtreecommitdiff
path: root/scripts/cros_list_overlays.py
blob: 754a041d8df725f4e7df005c664198655cfacb3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""Calculate what overlays are needed for a particular board."""

from __future__ import print_function

import os

from chromite.cbuildbot import constants
from chromite.lib import commandline
from chromite.lib import cros_build_lib
from chromite.lib import portage_util


def _ParseArguments(argv):
  parser = commandline.ArgumentParser(description=__doc__)

  parser.add_argument('--board', default=None, help='Board name')
  parser.add_argument('--board_overlay', default=None,
                      help='Location of the board overlay. Used by '
                           './setup_board to allow developers to add custom '
                           'overlays.')
  parser.add_argument('--primary_only', default=False, action='store_true',
                      help='Only return the path to the primary overlay. This '
                           'only makes sense when --board is specified.')
  parser.add_argument('-a', '--all', default=False, action='store_true',
                      help='Show all overlays (even common ones).')

  opts = parser.parse_args(argv)
  opts.Freeze()

  if opts.primary_only and opts.board is None:
    parser.error('--board is required when --primary_only is supplied.')

  return opts


def main(argv):
  opts = _ParseArguments(argv)
  args = (constants.BOTH_OVERLAYS, opts.board)

  # Verify that a primary overlay exists.
  try:
    primary_overlay = portage_util.FindPrimaryOverlay(*args)
  except portage_util.MissingOverlayException as ex:
    cros_build_lib.Die(str(ex))

  # Get the overlays to print.
  if opts.primary_only:
    overlays = [primary_overlay]
  else:
    overlays = portage_util.FindOverlays(*args)

  # Exclude any overlays in src/third_party, for backwards compatibility with
  # scripts that expected these to not be listed.
  if not opts.all:
    ignore_prefix = os.path.join(constants.SOURCE_ROOT, 'src', 'third_party')
    overlays = [o for o in overlays if not o.startswith(ignore_prefix)]

  if opts.board_overlay and os.path.isdir(opts.board_overlay):
    overlays.append(os.path.abspath(opts.board_overlay))

  print('\n'.join(overlays))