2025-11-16 11:39:27 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
2026-01-29 10:58:51 +01:00
|
|
|
from typing import Iterable
|
2025-11-16 11:39:27 +01:00
|
|
|
from argparse import Namespace, ArgumentParser
|
|
|
|
|
|
2026-01-27 10:22:16 +01:00
|
|
|
from ...App import Scope
|
2026-01-25 15:18:27 +01:00
|
|
|
from ...lib.log import *
|
2025-11-16 11:39:27 +01:00
|
|
|
from ..Cmd import Cmd
|
2026-01-27 10:22:16 +01:00
|
|
|
from ..CmdProjects import CmdProjects
|
2025-11-16 11:39:27 +01:00
|
|
|
|
|
|
|
|
# TODO: seems at least partly redundant to CmdPkgRequires / print_pkg_relations
|
|
|
|
|
class CmdRequiredOsPkg(Cmd): # export
|
|
|
|
|
|
2026-01-27 10:22:16 +01:00
|
|
|
def __init__(self, parent: CmdProjects) -> None:
|
|
|
|
|
super().__init__(parent, 'required-os-pkg', help='List distribution packages required for a package')
|
2025-11-16 11:39:27 +01:00
|
|
|
|
|
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
|
|
|
super().add_arguments(parser)
|
|
|
|
|
parser.add_argument('module', nargs='*', help='Modules')
|
|
|
|
|
parser.add_argument('--flavours', help='Dependency flavours', default='build')
|
|
|
|
|
parser.add_argument('--skip-excluded', action='store_true', default=False,
|
|
|
|
|
help='Output empty prerequisite list if module is excluded')
|
2026-01-29 10:43:14 +01:00
|
|
|
parser.add_argument('--quote', action='store_true', default=False,
|
|
|
|
|
help='Put double quotes around each listed dependency')
|
2025-11-16 11:39:27 +01:00
|
|
|
|
2026-01-27 14:31:25 +01:00
|
|
|
async def _run(self, args: Namespace) -> None:
|
2025-11-16 11:39:27 +01:00
|
|
|
modules = args.module
|
|
|
|
|
flavours = args.flavours.split()
|
|
|
|
|
if 'build' in flavours and not 'run' in flavours:
|
|
|
|
|
# TODO: This adds too much. Only the run dependencies of the build dependencies would be needed.
|
|
|
|
|
flavours.append('run')
|
2026-01-25 15:18:27 +01:00
|
|
|
log(DEBUG, "flavours = " + args.flavours)
|
2026-01-29 10:58:51 +01:00
|
|
|
deps = self.app.get_project_refs(modules, ['pkg.requires.jw'], flavours,
|
2026-01-26 13:13:12 +01:00
|
|
|
scope = Scope.Subtree, add_self=True, names_only=True)
|
2025-11-16 11:39:27 +01:00
|
|
|
if args.skip_excluded:
|
|
|
|
|
for d in deps:
|
|
|
|
|
if self.app.is_excluded_from_build(d) is not None:
|
|
|
|
|
deps.remove(d)
|
|
|
|
|
subsecs = self.app.os_cascade()
|
2026-01-25 15:18:27 +01:00
|
|
|
log(DEBUG, "subsecs = ", subsecs)
|
2025-11-16 11:39:27 +01:00
|
|
|
requires = []
|
2026-01-29 10:58:51 +01:00
|
|
|
for sec in subsecs:
|
|
|
|
|
for flavour in flavours:
|
|
|
|
|
vals = self.app.get_values(deps, ['pkg.requires.' + sec], [flavour])
|
2025-11-16 11:39:27 +01:00
|
|
|
if vals:
|
|
|
|
|
requires = requires + vals
|
2026-01-29 10:43:14 +01:00
|
|
|
if args.quote:
|
|
|
|
|
requires = [f'"{dep}"' for dep in requires]
|
2025-11-16 11:39:27 +01:00
|
|
|
# TODO: add all not in build tree as -devel
|
2026-01-29 10:58:51 +01:00
|
|
|
print(' '.join(requires))
|