blob: 8cf6a7ef4d6c1637df68dff3f9ff7502cbdc68b6 [file] [log] [blame] [edit]
# Copyright 2021 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.
"""Completer functions to use with --b, --board, --build-target."""
import os
import re
from pathlib import Path
from typing import Iterator, List
from chromite.lib import constants
from chromite.lib import path_util
from chromite.lib import portage_util
def build_target(prefix, action, parser, parsed_args) -> List[str]: # pylint: disable=unused-argument
"""List all possible build targets."""
RE_NAME = re.compile(r'^overlay-(.*?)(-private)?$')
overlay_paths = portage_util.FindOverlays(constants.BOTH_OVERLAYS)
overlays = [os.path.basename(x) for x in overlay_paths]
build_targets = set()
for overlay in overlays:
m = RE_NAME.match(overlay)
if m and not m.group(1).startswith('variant-') and m.group(1).startswith(
prefix):
build_targets.add(m.group(1))
return sorted(build_targets)
def built_build_target(prefix, action, parser, parsed_args) -> Iterator[str]: # pylint: disable=unused-argument
"""List build targets with a sysroot."""
p = f'{prefix}*/etc/portage'
yield from (x.parent.parent.name for x in Path(
path_util.FromChrootPath(path_util.FromChrootPath('/build'))).glob(p))