David James | e586781 | 2012-10-19 12:02:20 -0700 | [diff] [blame] | 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 | |
Don Garrett | 25f309a | 2014-03-19 14:02:12 -0700 | [diff] [blame] | 5 | """Calculate what overlays are needed for a particular board.""" |
David James | e586781 | 2012-10-19 12:02:20 -0700 | [diff] [blame] | 6 | |
| 7 | import optparse |
| 8 | import os |
| 9 | |
| 10 | from chromite.lib import cros_build_lib |
Don Garrett | 88b8d78 | 2014-05-13 17:30:55 -0700 | [diff] [blame^] | 11 | from chromite.cbuildbot import constants |
| 12 | from chromite.cbuildbot import portage_utilities |
David James | e586781 | 2012-10-19 12:02:20 -0700 | [diff] [blame] | 13 | |
| 14 | |
| 15 | def _ParseArguments(argv): |
| 16 | parser = optparse.OptionParser(usage='USAGE: %prog [options]') |
| 17 | |
| 18 | parser.add_option('--board', default=None, help='Board name') |
| 19 | parser.add_option('--board_overlay', default=None, |
| 20 | help='Location of the board overlay. Used by ./setup_board ' |
| 21 | 'to allow developers to add custom overlays.') |
| 22 | parser.add_option('--primary_only', default=False, action='store_true', |
| 23 | help='Only return the path to the primary overlay. This ' |
| 24 | 'only makes sense when --board is specified.') |
| 25 | |
| 26 | flags, remaining_arguments = parser.parse_args(argv) |
| 27 | |
| 28 | if flags.primary_only and flags.board is None: |
| 29 | parser.error('--board is required when --primary_only is supplied.') |
| 30 | |
| 31 | if remaining_arguments: |
| 32 | parser.print_help() |
| 33 | parser.error('Invalid arguments') |
| 34 | |
| 35 | return flags |
| 36 | |
| 37 | |
| 38 | def main(argv): |
| 39 | flags = _ParseArguments(argv) |
| 40 | args = (constants.BOTH_OVERLAYS, flags.board) |
| 41 | |
| 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. |
| 49 | if flags.primary_only: |
| 50 | 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 | |
| 59 | if flags.board_overlay and os.path.isdir(flags.board_overlay): |
| 60 | overlays.append(os.path.abspath(flags.board_overlay)) |
| 61 | |
| 62 | print '\n'.join(overlays) |