From 459f97ef1dfb6f89afdc10dca2b04a546a6b3882 Mon Sep 17 00:00:00 2001 From: drebrez Date: Tue, 24 Oct 2017 18:18:42 +0200 Subject: [PATCH] Support multiple architectures in `pmbootstrap menuconfig` command (#814) --- pmb/build/menuconfig.py | 28 +++++++++++++++++++++++++++- pmb/helpers/frontend.py | 2 +- pmb/parse/arguments.py | 7 +++++-- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/pmb/build/menuconfig.py b/pmb/build/menuconfig.py index 9fbd780f..18ebda45 100644 --- a/pmb/build/menuconfig.py +++ b/pmb/build/menuconfig.py @@ -28,7 +28,32 @@ import pmb.helpers.run import pmb.parse -def menuconfig(args, pkgname, arch): +def get_arch(args, apkbuild): + """ + Get the architecture, that the user wants to run menuconfig on, depending on + the APKBUILD and on the --arch parameter. + + :param apkbuild: looks like: {"pkgname": "linux-...", "arch": ["all"]} + or: {"pkgname": "linux-...", "arch": ["armhf"]} + """ + pkgname = apkbuild["pkgname"] + + # Multiple architectures (requires --arch) + if "all" in apkbuild["arch"]: + if args.arch is None: + raise RuntimeError("Package '" + pkgname + "' supports multiple" + " architectures, please use '--arch' to specify" + " the desired architecture.") + return args.arch + + # Single architecture (--arch must be unset or match) + if args.arch is None or args.arch == apkbuild["arch"][0]: + return apkbuild["arch"][0] + raise RuntimeError("Package '" + pkgname + "' only supports the '" + + apkbuild["arch"][0] + "' architecture.") + + +def menuconfig(args, pkgname): # Pkgname: allow omitting "linux-" prefix if pkgname.startswith("linux-"): pkgname_ = pkgname.split("linux-")[1] @@ -40,6 +65,7 @@ def menuconfig(args, pkgname, arch): # Read apkbuild aport = pmb.build.find_aport(args, pkgname) apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD") + arch = get_arch(args, apkbuild) # Set up build tools and makedepends pmb.build.init(args) diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index 6c154e87..94e93ff9 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -150,7 +150,7 @@ def export(args): def menuconfig(args): - pmb.build.menuconfig(args, args.package, args.deviceinfo["arch"]) + pmb.build.menuconfig(args, args.package) def kconfig_check(args): diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 9f20047d..4adfb291 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -101,6 +101,8 @@ def arguments_initfs(subparser): def arguments(): parser = argparse.ArgumentParser(prog="pmbootstrap") + arch_native = pmb.parse.arch.alpine_native() + arch_choices = set(pmb.config.build_device_architectures + [arch_native]) # Other parser.add_argument("-V", "--version", action="version", @@ -227,6 +229,7 @@ def arguments(): # Action: menuconfig / parse_apkbuild menuconfig = sub.add_parser("menuconfig", help="run menuconfig on" " a kernel aport") + menuconfig.add_argument("--arch", choices=arch_choices) parse_apkbuild = sub.add_parser("parse_apkbuild") for action in [menuconfig, parse_apkbuild]: action.add_argument("package") @@ -237,7 +240,7 @@ def arguments(): " (aport/APKBUILD) based on an upstream aport from Alpine") build = sub.add_parser("build", help="create a package for a" " specific architecture") - build.add_argument("--arch") + build.add_argument("--arch", choices=arch_choices) build.add_argument("--force", action="store_true") build.add_argument("--buildinfo", action="store_true") build.add_argument("--strict", action="store_true", help="(slower) zap and install only" @@ -319,7 +322,7 @@ def arguments(): setattr(args, varname, old.replace("$WORK", args.work)) # Add convenience shortcuts - setattr(args, "arch_native", pmb.parse.arch.alpine_native()) + setattr(args, "arch_native", arch_native) # Add a caching dict (caches parsing of files etc. for the current session) setattr(args, "cache", {"apkindex": {},