diff --git a/pmb/commands/__init__.py b/pmb/commands/__init__.py index 675190b2..1c379e15 100644 --- a/pmb/commands/__init__.py +++ b/pmb/commands/__init__.py @@ -16,6 +16,8 @@ from .repo_bootstrap import RepoBootstrap from .shutdown import Shutdown from .test import Test from .pull import Pull +from .kconfig_check import KConfigCheck +from .kconfig_edit import KConfigEdit """New way to model pmbootstrap subcommands that can be invoked without PmbArgs.""" @@ -24,7 +26,6 @@ unmigrated_commands = [ "init", "work_migrate", "repo_missing", - "kconfig", "export", "sideload", "netboot", @@ -75,6 +76,10 @@ def run_command(args: PmbArgs): command = Test(args.action_test) elif args.action == "pull": command = Pull() + elif args.action == "kconfig" and args.action_kconfig == "check": + command = KConfigCheck(args.kconfig_check_details, args.file, args.package) + elif args.action == "kconfig" and args.action_kconfig in ["edit", "migrate"]: + command = KConfigEdit(args.package, args.action_kconfig == "migrate") else: raise NotImplementedError(f"Command '{args.action}' is not implemented.") diff --git a/pmb/commands/kconfig_check.py b/pmb/commands/kconfig_check.py new file mode 100644 index 00000000..d9194de5 --- /dev/null +++ b/pmb/commands/kconfig_check.py @@ -0,0 +1,63 @@ +# Copyright 2024 Oliver Smith +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import annotations +from pmb import commands +from pmb.core.context import get_context +import pmb.helpers.git +import pmb.config +import logging + + +class KConfigCheck(commands.Command): + details: bool + file: str + packages: list[str] + + def __init__(self, details, file, packages): + self.details = details + self.file = file + self.packages = packages + + def run(self): + # Build the components list from cli arguments (--waydroid etc.) + components_list = [] + + # Handle passing a file directly + if self.file: + if pmb.parse.kconfig.check_file(self.file, components_list, details=self.details): + logging.info("kconfig check succeeded!") + return + raise RuntimeError("kconfig check failed!") + + # Default to all kernel packages + if not self.packages: + for pkg in pmb.helpers.pmaports.get_list(): + if pkg.startswith("linux-"): + self.packages.append(pkg.split("linux-")[1]) + + # Iterate over all kernels + error = False + skipped = 0 + self.packages.sort() + for package in self.packages: + if not get_context().force: + pkgname = package if package.startswith("linux-") else f"linux-{package}" + aport = pmb.helpers.pmaports.find(pkgname) + apkbuild = pmb.parse.apkbuild(aport) + if "!pmb:kconfigcheck" in apkbuild["options"]: + skipped += 1 + continue + if not pmb.parse.kconfig.check(package, components_list, details=self.details): + error = True + + # At least one failure + if error: + raise RuntimeError("kconfig check failed!") + else: + if skipped: + logging.info( + f"NOTE: {skipped} kernel{' was' if skipped == 1 else 's were'} skipped" + " (consider 'pmbootstrap kconfig check -f')" + ) + logging.info("kconfig check succeeded!") diff --git a/pmb/commands/kconfig_edit.py b/pmb/commands/kconfig_edit.py new file mode 100644 index 00000000..b3f0f195 --- /dev/null +++ b/pmb/commands/kconfig_edit.py @@ -0,0 +1,21 @@ +# Copyright 2024 Oliver Smith +# SPDX-License-Identifier: GPL-3.0-or-later + +from __future__ import annotations +from pmb import commands +import pmb.build +import pmb.helpers.args + + +class KConfigEdit(commands.Command): + pkgname: str + use_oldconfig: bool + + def __init__(self, pkgname, use_oldconfig): + self.pkgname = pkgname + self.use_oldconfig = use_oldconfig + pass + + def run(self): + args = pmb.helpers.args.please_i_really_need_args() + pmb.build.menuconfig(args, self.pkgname, self.use_oldconfig) diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index c2d961e3..4392e267 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -457,65 +457,6 @@ def newapkbuild(args: PmbArgs): pmb.build.newapkbuild(args.folder, pass_through, args.force) -def kconfig(args: PmbArgs): - if args.action_kconfig == "check": - details = args.kconfig_check_details - # Build the components list from cli arguments (--waydroid etc.) - components_list = [] - - # Handle passing a file directly - if args.file: - if pmb.parse.kconfig.check_file(args.file, components_list, details=details): - logging.info("kconfig check succeeded!") - return - raise RuntimeError("kconfig check failed!") - - # Default to all kernel packages - packages: list[str] - # FIXME (#2324): figure out the args.package vs args.packages situation - if isinstance(args.package, list): - packages = args.package - else: - packages = [args.package] - if not args.package: - for pkg in pmb.helpers.pmaports.get_list(): - if pkg.startswith("linux-"): - packages.append(pkg.split("linux-")[1]) - - # Iterate over all kernels - error = False - skipped = 0 - packages.sort() - for package in packages: - if not get_context().force: - pkgname = package if package.startswith("linux-") else "linux-" + package - aport = pmb.helpers.pmaports.find(pkgname) - apkbuild = pmb.parse.apkbuild(aport) - if "!pmb:kconfigcheck" in apkbuild["options"]: - skipped += 1 - continue - if not pmb.parse.kconfig.check(package, components_list, details=details): - error = True - - # At least one failure - if error: - raise RuntimeError("kconfig check failed!") - else: - if skipped: - logging.info( - "NOTE: " + str(skipped) + " kernel(s) was skipped" - " (consider 'pmbootstrap kconfig check -f')" - ) - logging.info("kconfig check succeeded!") - elif args.action_kconfig in ["edit", "migrate"]: - if args.package: - pkgname = args.package if isinstance(args.package, str) else args.package[0] - else: - pkgname = get_context().config.device - use_oldconfig = args.action_kconfig == "migrate" - pmb.build.menuconfig(args, pkgname, use_oldconfig) - - def deviceinfo_parse(args: PmbArgs): # Default to all devices devices = args.devices