Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / chromite / scripts / cros_list_overlays.py
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.
4
5 """Calculate what overlays are needed for a particular board."""
6
7 from __future__ import print_function
8
9 import os
10
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
15
16
17 def _ParseArguments(argv):
18   parser = commandline.ArgumentParser(description=__doc__)
19
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 '
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.')
28
29   opts = parser.parse_args(argv)
30   opts.Freeze()
31
32   if opts.primary_only and opts.board is None:
33     parser.error('--board is required when --primary_only is supplied.')
34
35   return opts
36
37
38 def main(argv):
39   opts = _ParseArguments(argv)
40   args = (constants.BOTH_OVERLAYS, opts.board)
41
42   # Verify that a primary overlay exists.
43   try:
44     primary_overlay = portage_util.FindPrimaryOverlay(*args)
45   except portage_util.MissingOverlayException as ex:
46     cros_build_lib.Die(str(ex))
47
48   # Get the overlays to print.
49   if opts.primary_only:
50     overlays = [primary_overlay]
51   else:
52     overlays = portage_util.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 opts.board_overlay and os.path.isdir(opts.board_overlay):
60     overlays.append(os.path.abspath(opts.board_overlay))
61
62   print('\n'.join(overlays))