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 | |
| 5 | """ |
| 6 | Calculate what overlays are needed for a particular board. |
| 7 | """ |
| 8 | |
| 9 | import optparse |
| 10 | import os |
| 11 | |
| 12 | from chromite.lib import cros_build_lib |
| 13 | from chromite.buildbot import constants |
| 14 | from chromite.buildbot import portage_utilities |
| 15 | |
| 16 | |
| 17 | def _ParseArguments(argv): |
| 18 | parser = optparse.OptionParser(usage='USAGE: %prog [options]') |
| 19 | |
| 20 | parser.add_option('--board', default=None, help='Board name') |
| 21 | parser.add_option('--board_overlay', default=None, |
| 22 | help='Location of the board overlay. Used by ./setup_board ' |
| 23 | 'to allow developers to add custom overlays.') |
| 24 | parser.add_option('--primary_only', default=False, action='store_true', |
| 25 | help='Only return the path to the primary overlay. This ' |
| 26 | 'only makes sense when --board is specified.') |
| 27 | |
| 28 | flags, remaining_arguments = parser.parse_args(argv) |
| 29 | |
| 30 | if flags.primary_only and flags.board is None: |
| 31 | parser.error('--board is required when --primary_only is supplied.') |
| 32 | |
| 33 | if remaining_arguments: |
| 34 | parser.print_help() |
| 35 | parser.error('Invalid arguments') |
| 36 | |
| 37 | return flags |
| 38 | |
| 39 | |
| 40 | def main(argv): |
| 41 | flags = _ParseArguments(argv) |
| 42 | args = (constants.BOTH_OVERLAYS, flags.board) |
| 43 | |
| 44 | # Verify that a primary overlay exists. |
| 45 | try: |
| 46 | primary_overlay = portage_utilities.FindPrimaryOverlay(*args) |
| 47 | except portage_utilities.MissingOverlayException as ex: |
| 48 | cros_build_lib.Die(str(ex)) |
| 49 | |
| 50 | # Get the overlays to print. |
| 51 | if flags.primary_only: |
| 52 | overlays = [primary_overlay] |
| 53 | else: |
| 54 | overlays = portage_utilities.FindOverlays(*args) |
| 55 | |
| 56 | # Exclude any overlays in src/third_party, for backwards compatibility with |
| 57 | # scripts that expected these to not be listed. |
| 58 | ignore_prefix = os.path.join(constants.SOURCE_ROOT, 'src', 'third_party') |
| 59 | overlays = [o for o in overlays if not o.startswith(ignore_prefix)] |
| 60 | |
| 61 | if flags.board_overlay and os.path.isdir(flags.board_overlay): |
| 62 | overlays.append(os.path.abspath(flags.board_overlay)) |
| 63 | |
| 64 | print '\n'.join(overlays) |