From e9ca68dc056795f85b8a5cf80046be3edb77c97d Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Tue, 28 Nov 2017 19:12:16 +0000 Subject: [PATCH] Fix #941: Use the right arch for foreign-arch-only packages (#943) This is a follow-up to #935. * fix regression #941: pmbootstrap doesn't automatically pick the right architecture for building when none is specified * remove obsolete --noarch-arch parameter --- pmb/build/autodetect.py | 16 ++++++++++++++++ pmb/helpers/frontend.py | 4 +++- pmb/parse/apkbuild.py | 4 ++++ pmb/parse/arguments.py | 12 +++--------- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/pmb/build/autodetect.py b/pmb/build/autodetect.py index 0dd95896..218db1f2 100644 --- a/pmb/build/autodetect.py +++ b/pmb/build/autodetect.py @@ -22,6 +22,22 @@ import pmb.chroot.apk import pmb.parse.arch +def arch(args, pkgname): + """ + Find a good default in case the user did not specify for which architecture + a package should be built. + + :returns: native architecture (x86_64 in most cases) when the APKBUILD has + "noarch" or "all". Otherwise the first architecture in the + APKBUILD. + """ + aport = pmb.build.find_aport(args, pkgname) + apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD") + if "noarch" in apkbuild["arch"] or "all" in apkbuild["arch"]: + return args.arch_native + return apkbuild["arch"][0] + + def suffix(args, apkbuild, arch): if arch == args.arch_native: return "native" diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index 5edd5401..68e7e3ca 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -27,6 +27,7 @@ import sys import pmb.aportgen import pmb.build +import pmb.build.autodetect import pmb.config import pmb.challenge import pmb.chroot @@ -141,7 +142,8 @@ def build(args): # Build all packages for package in args.packages: - pmb.build.package(args, package, args.arch, args.force, + arch_package = args.arch or pmb.build.autodetect.arch(args, package) + pmb.build.package(args, package, arch_package, args.force, args.buildinfo, args.strict) diff --git a/pmb/parse/apkbuild.py b/pmb/parse/apkbuild.py index 7b733f21..ca0a13c9 100644 --- a/pmb/parse/apkbuild.py +++ b/pmb/parse/apkbuild.py @@ -156,6 +156,10 @@ def apkbuild(args, path): raise RuntimeError("The pkgname must be equal to the name of" " the folder, that contains the APKBUILD!") + # Sanity check: arch + if not len(ret["arch"]): + raise RuntimeError("Arch must not be empty: " + path) + # Fill cache args.cache["apkbuild"][path] = ret return ret diff --git a/pmb/parse/arguments.py b/pmb/parse/arguments.py index 96ff9be9..1e51981a 100644 --- a/pmb/parse/arguments.py +++ b/pmb/parse/arguments.py @@ -270,9 +270,10 @@ 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", choices=arch_choices, default=arch_native, + build.add_argument("--arch", choices=arch_choices, default=None, help="CPU architecture to build for (default: " + - arch_native + ")") + arch_native + " or first available architecture in" + " APKBUILD)") build.add_argument("--force", action="store_true", help="even build if not" " necessary") build.add_argument("--buildinfo", action="store_true") @@ -285,13 +286,6 @@ def arguments(): " you don't need to build and install the kernel. But it" " is incompatible with how Alpine's abuild handles it.", dest="ignore_depends") - build.add_argument("--noarch-arch", dest="noarch_arch", default=None, - help="which architecture to use to build 'noarch'" - " packages. Defaults to the native arch normally," - " and to the device arch when --strict is set." - " Override in case of strict mode failing on" - " dependencies, which only exist for a certain" - " arch.") for action in [checksum, build, aportgen]: action.add_argument("packages", nargs="+")