diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index a0b75bd1..038b47b2 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -24,7 +24,7 @@ apk_keys_path = pmb_src + "/pmb/data/keys" apk_tools_static_min_version = "2.10.5-r0" # postmarketOS aports compatibility (checked against "version" in pmaports.cfg) -pmaports_min_version = "4" +pmaports_min_version = "5" # Version of the work folder (as asked during 'pmbootstrap init'). Increase # this number, whenever migration is required and provide the migration code, @@ -450,7 +450,7 @@ aportgen = { "prefixes": ["binutils", "busybox-static", "gcc", "musl", "grub-efi"], "confirm_overwrite": False, }, - "device": { + "device/testing": { "prefixes": ["device", "linux"], "confirm_overwrite": True, } diff --git a/pmb/config/init.py b/pmb/config/init.py index 093757ab..fedbe13b 100644 --- a/pmb/config/init.py +++ b/pmb/config/init.py @@ -5,6 +5,7 @@ import glob import os import shutil +import pmb.aportgen import pmb.config import pmb.config.pmaports import pmb.helpers.cli @@ -185,10 +186,10 @@ def ask_for_device_nonfree(args, device): :returns: answers as dict, e.g. {"firmware": True, "userland": False} """ # Parse existing APKBUILD or return defaults (when called from test case) - apkbuild_path = args.aports + "/device/device-" + device + "/APKBUILD" + apkbuild_path = pmb.helpers.devices.find_path(args, device, 'APKBUILD') ret = {"firmware": args.nonfree_firmware, "userland": args.nonfree_userland} - if not os.path.exists(apkbuild_path): + if not apkbuild_path: return ret apkbuild = pmb.parse.apkbuild(args, apkbuild_path) @@ -259,8 +260,7 @@ def ask_for_device(args): codenames) device = vendor + '-' + codename - device_exists = os.path.exists(args.aports + "/device/device-" + - device + "/deviceinfo") + device_exists = pmb.helpers.devices.find_path(args, device, 'deviceinfo') is not None if not device_exists: if device == args.device: raise RuntimeError( diff --git a/pmb/helpers/devices.py b/pmb/helpers/devices.py index d537ea81..41b8158a 100644 --- a/pmb/helpers/devices.py +++ b/pmb/helpers/devices.py @@ -5,6 +5,24 @@ import glob import pmb.parse +def find_path(args, codename, file=''): + """ + Find path to device APKBUILD under `device/*/device-`. + :param codename: device codename + :param file: file to look for (e.g. APKBUILD or deviceinfo), may be empty + :returns: path to APKBUILD + """ + g = glob.glob(args.aports + "/device/*/device-" + codename + '/' + file) + if not g: + return None + + if len(g) != 1: + raise RuntimeError(codename + " found multiple times in the device" + " subdirectory of pmaports") + + return g[0] + + def list_codenames(args, vendor=None): """ Get all devices, for which aports are available @@ -12,7 +30,7 @@ def list_codenames(args, vendor=None): :returns: ["first-device", "second-device", ...] """ ret = [] - for path in glob.glob(args.aports + "/device/device-*"): + for path in glob.glob(args.aports + "/device/*/device-*"): device = os.path.basename(path).split("-", 1)[1] if (vendor is None) or device.startswith(vendor + '-'): ret.append(device) @@ -25,7 +43,7 @@ def list_vendors(args): :returns: {"vendor1", "vendor2", ...} """ ret = set() - for path in glob.glob(args.aports + "/device/device-*"): + for path in glob.glob(args.aports + "/device/*/device-*"): vendor = os.path.basename(path).split("-", 2)[1] ret.add(vendor) return ret @@ -37,7 +55,7 @@ def list_apkbuilds(args): """ ret = {} for device in list_codenames(args): - apkbuild_path = args.aports + "/device/device-" + device + "/APKBUILD" + apkbuild_path = args.aports + "/device/*/device-" + device + "/APKBUILD" ret[device] = pmb.parse.apkbuild(args, apkbuild_path) return ret diff --git a/pmb/helpers/frontend.py b/pmb/helpers/frontend.py index b0865f6d..37713959 100644 --- a/pmb/helpers/frontend.py +++ b/pmb/helpers/frontend.py @@ -1,6 +1,5 @@ # Copyright 2020 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later -import glob import json import logging import os @@ -249,8 +248,8 @@ def kconfig(args): # Default to all kernel packages packages = [] if args.package == "" or args.package is None: - for aport in glob.glob(args.aports + "/*/linux-*"): - packages.append(os.path.basename(aport).split("linux-")[1]) + for aport in pmb.helpers.pmaports.get_list(args, "linux-*"): + packages.append(aport.split("linux-")[1]) else: packages = [args.package] diff --git a/pmb/helpers/pmaports.py b/pmb/helpers/pmaports.py index 6686bfae..e47b1c8e 100644 --- a/pmb/helpers/pmaports.py +++ b/pmb/helpers/pmaports.py @@ -12,10 +12,14 @@ import os import pmb.parse -def get_list(args): +def _glob_apkbuilds(args, pkgname='*'): + return glob.glob(args.aports + "/**/" + pkgname + "/APKBUILD", recursive=True) + + +def get_list(args, pkgname='*'): """ :returns: list of all pmaport pkgnames (["hello-world", ...]) """ ret = [] - for apkbuild in glob.glob(args.aports + "/*/*/APKBUILD"): + for apkbuild in _glob_apkbuilds(args, pkgname): ret.append(os.path.basename(os.path.dirname(apkbuild))) ret.sort() return ret @@ -31,11 +35,11 @@ def guess_main_dev(args, subpkgname): :returns: full path to the pmaport or None """ pkgname = subpkgname[:-4] - paths = glob.glob(args.aports + "/*/" + pkgname) + paths = _glob_apkbuilds(args, pkgname) if paths: logging.debug(subpkgname + ": guessed to be a subpackage of " + pkgname + " (just removed '-dev')") - return paths[0] + return os.path.dirname(paths[0]) logging.debug(subpkgname + ": guessed to be a subpackage of " + pkgname + ", which we can't find in pmaports, so it's probably in" @@ -73,11 +77,11 @@ def guess_main(args, subpkgname): pkgname = "-".join(words) # Look in pmaports - paths = glob.glob(args.aports + "/*/" + pkgname) + paths = _glob_apkbuilds(args, pkgname) if paths: logging.debug(subpkgname + ": guessed to be a subpackage of " + pkgname) - return paths[0] + return os.path.dirname(paths[0]) def find(args, package, must_exist=True): @@ -99,17 +103,17 @@ def find(args, package, must_exist=True): raise RuntimeError("Invalid pkgname: " + package) # Search in packages - paths = glob.glob(args.aports + "/*/" + package) + paths = _glob_apkbuilds(args, package) if len(paths) > 1: raise RuntimeError("Package " + package + " found in multiple" " aports subfolders. Please put it only in one" " folder.") elif len(paths) == 1: - ret = paths[0] + ret = os.path.dirname(paths[0]) # Search in subpackages and provides if not ret: - for path_current in glob.glob(args.aports + "/*/*/APKBUILD"): + for path_current in _glob_apkbuilds(args): apkbuild = pmb.parse.apkbuild(args, path_current) found = False diff --git a/pmb/install/_install.py b/pmb/install/_install.py index cf54db12..6e2f9a56 100644 --- a/pmb/install/_install.py +++ b/pmb/install/_install.py @@ -11,6 +11,7 @@ import pmb.chroot.apk import pmb.chroot.other import pmb.chroot.initfs import pmb.config +import pmb.helpers.devices import pmb.helpers.run import pmb.install.blockdevice import pmb.install.file @@ -62,8 +63,7 @@ def get_nonfree_packages(args, device): ["device-nokia-n900-nonfree-firmware"] """ # Read subpackages - apkbuild_path = args.aports + "/device/device-" + device + "/APKBUILD" - apkbuild = pmb.parse.apkbuild(args, apkbuild_path) + apkbuild = pmb.parse.apkbuild(args, pmb.helpers.devices.find_path(args, device, 'APKBUILD')) subpackages = apkbuild["subpackages"] # Check for firmware and userland diff --git a/pmb/parse/_apkbuild.py b/pmb/parse/_apkbuild.py index be751ff4..c91cc574 100644 --- a/pmb/parse/_apkbuild.py +++ b/pmb/parse/_apkbuild.py @@ -6,6 +6,7 @@ import re from collections import OrderedDict import pmb.config +import pmb.helpers.devices import pmb.parse.version # sh variable name regex: https://stackoverflow.com/a/2821201/3527128 @@ -340,8 +341,8 @@ def kernels(args, device): "downstream": "Downstream description"} """ # Read the APKBUILD - apkbuild_path = args.aports + "/device/device-" + device + "/APKBUILD" - if not os.path.exists(apkbuild_path): + apkbuild_path = pmb.helpers.devices.find_path(args, device, 'APKBUILD') + if apkbuild_path is None: return None subpackages = apkbuild(args, apkbuild_path)["subpackages"] diff --git a/pmb/parse/deviceinfo.py b/pmb/parse/deviceinfo.py index c3115a46..bfad92f2 100644 --- a/pmb/parse/deviceinfo.py +++ b/pmb/parse/deviceinfo.py @@ -3,6 +3,7 @@ import logging import os import pmb.config +import pmb.helpers.devices def sanity_check(info, path): @@ -62,15 +63,14 @@ def deviceinfo(args, device=None): logging.fatal("Please provide a path to the aports directory using the -p flag") raise RuntimeError("Aports directory missing") - aport = args.aports + "/device/device-" + device - if not os.path.exists(aport) or not os.path.exists(aport + "/deviceinfo"): + path = pmb.helpers.devices.find_path(args, device, 'deviceinfo') + if not path: raise RuntimeError( "Device '" + device + "' not found. Run 'pmbootstrap init' to" " start a new device port or to choose another device. It may have" " been renamed, see ") ret = {} - path = aport + "/deviceinfo" with open(path) as handle: for line in handle: if not line.startswith("deviceinfo_"): diff --git a/test/test_aportgen_device_wizard.py b/test/test_aportgen_device_wizard.py index 67e752c5..3e7a08c4 100644 --- a/test/test_aportgen_device_wizard.py +++ b/test/test_aportgen_device_wizard.py @@ -32,9 +32,9 @@ def args(tmpdir, request): pmb.helpers.run.user(args, ["cp", "-r", path_dev, tmpdir + "/main"]) # Copy the linux-lg-mako aport (we currently copy patches from there) - pmb.helpers.run.user(args, ["mkdir", "-p", tmpdir + "/device"]) - path_mako = args._aports_real + "/device/linux-lg-mako" - pmb.helpers.run.user(args, ["cp", "-r", path_mako, tmpdir + "/device"]) + pmb.helpers.run.user(args, ["mkdir", "-p", tmpdir + "/device/testing"]) + path_mako = args._aports_real + "/device/testing/linux-lg-mako" + pmb.helpers.run.user(args, ["cp", "-r", path_mako, tmpdir + "/device/testing"]) return args @@ -63,9 +63,9 @@ def generate(args, monkeypatch, answers): pmb.aportgen.generate(args, "linux-testsuite-testdevice") monkeypatch.undo() - apkbuild_path = (args.aports + "/device/device-testsuite-testdevice/" + apkbuild_path = (args.aports + "/device/testing/device-testsuite-testdevice/" "APKBUILD") - apkbuild_path_linux = (args.aports + "/device/" + apkbuild_path_linux = (args.aports + "/device/testing/" "linux-testsuite-testdevice/APKBUILD") # The build fails if the email is not a valid email, so remove them just for tests diff --git a/test/test_build_package.py b/test/test_build_package.py index 6ca0f3cc..1e491e7c 100644 --- a/test/test_build_package.py +++ b/test/test_build_package.py @@ -352,9 +352,9 @@ def test_build_local_source_high_level(args, tmpdir): # aports: Add deviceinfo (required by pmbootstrap to start) tmpdir = str(tmpdir) aports = tmpdir + "/aports" - aport = aports + "/device/device-" + args.device + aport = aports + "/device/testing/device-" + args.device os.makedirs(aport) - shutil.copy(args.aports + "/device/device-" + args.device + "/deviceinfo", + shutil.copy(args.aports + "/device/testing/device-" + args.device + "/deviceinfo", aport) # aports: Add modified hello-world aport (source="", uses $builddir) diff --git a/test/test_parse_apkbuild.py b/test/test_parse_apkbuild.py index 31e1b769..4ce656f0 100644 --- a/test/test_parse_apkbuild.py +++ b/test/test_parse_apkbuild.py @@ -34,7 +34,7 @@ def test_subpackages(args): assert subpkg["depends"] == ["postmarketos-base", "glibc"] # Successful extraction - path = (testdata + "/init_questions_device/aports/device/" + path = (testdata + "/init_questions_device/aports/device/testing/" "device-nonfree-firmware/APKBUILD") apkbuild = pmb.parse.apkbuild(args, path) subpkg = apkbuild["subpackages"]["device-nonfree-firmware-nonfree-firmware"] diff --git a/test/test_pkgrel_bump.py b/test/test_pkgrel_bump.py index 1d5d998d..e965a4b2 100644 --- a/test/test_pkgrel_bump.py +++ b/test/test_pkgrel_bump.py @@ -77,11 +77,11 @@ def setup_work(args, tmpdir): pmb.helpers.run.user(args, ["ln", "-s", path, tmpdir + "/"]) # Copy testdata and selected device aport - for folder in ["device", "main"]: + for folder in ["device/testing", "main"]: pmb.helpers.run.user(args, ["mkdir", "-p", args.aports, tmpdir + "/_aports/" + folder]) - pmb.helpers.run.user(args, ["cp", "-r", args.aports + "/device/device-" + - args.device, tmpdir + "/_aports/device"]) + pmb.helpers.run.user(args, ["cp", "-r", args.aports + "/device/testing/device-" + + args.device, tmpdir + "/_aports/device/testing"]) for pkgname in ["testlib", "testapp", "testsubpkg"]: pmb.helpers.run.user(args, ["cp", "-r", "test/testdata/pkgrel_bump/aports/" + pkgname, diff --git a/test/testcases_fast.sh b/test/testcases_fast.sh index d8c7d435..a66f724e 100755 --- a/test/testcases_fast.sh +++ b/test/testcases_fast.sh @@ -21,7 +21,7 @@ cd "$(dirname "$0")/.." # Make sure we have a valid device (#1128) device="$(./pmbootstrap.py config device)" work="$(./pmbootstrap.py config work)" -deviceinfo="$work/cache_git/pmaports/device/device-$device/deviceinfo" +deviceinfo="$work/cache_git/pmaports/device/testing/device-$device/deviceinfo" if ! [ -e "$deviceinfo" ]; then echo "ERROR: Could not find deviceinfo file for selected device '$device'." echo "Expected path: $deviceinfo" diff --git a/test/testdata/init_questions_device/aports/device/device-lg-mako/APKBUILD b/test/testdata/init_questions_device/aports/device/testing/device-lg-mako/APKBUILD similarity index 100% rename from test/testdata/init_questions_device/aports/device/device-lg-mako/APKBUILD rename to test/testdata/init_questions_device/aports/device/testing/device-lg-mako/APKBUILD diff --git a/test/testdata/init_questions_device/aports/device/device-lg-mako/deviceinfo b/test/testdata/init_questions_device/aports/device/testing/device-lg-mako/deviceinfo similarity index 100% rename from test/testdata/init_questions_device/aports/device/device-lg-mako/deviceinfo rename to test/testdata/init_questions_device/aports/device/testing/device-lg-mako/deviceinfo diff --git a/test/testdata/init_questions_device/aports/device/device-nonfree-firmware-and-userland/APKBUILD b/test/testdata/init_questions_device/aports/device/testing/device-nonfree-firmware-and-userland/APKBUILD similarity index 100% rename from test/testdata/init_questions_device/aports/device/device-nonfree-firmware-and-userland/APKBUILD rename to test/testdata/init_questions_device/aports/device/testing/device-nonfree-firmware-and-userland/APKBUILD diff --git a/test/testdata/init_questions_device/aports/device/device-nonfree-firmware/APKBUILD b/test/testdata/init_questions_device/aports/device/testing/device-nonfree-firmware/APKBUILD similarity index 100% rename from test/testdata/init_questions_device/aports/device/device-nonfree-firmware/APKBUILD rename to test/testdata/init_questions_device/aports/device/testing/device-nonfree-firmware/APKBUILD diff --git a/test/testdata/init_questions_device/aports/device/device-nonfree-userland/APKBUILD b/test/testdata/init_questions_device/aports/device/testing/device-nonfree-userland/APKBUILD similarity index 100% rename from test/testdata/init_questions_device/aports/device/device-nonfree-userland/APKBUILD rename to test/testdata/init_questions_device/aports/device/testing/device-nonfree-userland/APKBUILD diff --git a/test/testdata/init_questions_device/aports/device/device-sony-amami/APKBUILD b/test/testdata/init_questions_device/aports/device/testing/device-sony-amami/APKBUILD similarity index 100% rename from test/testdata/init_questions_device/aports/device/device-sony-amami/APKBUILD rename to test/testdata/init_questions_device/aports/device/testing/device-sony-amami/APKBUILD diff --git a/test/testdata/init_questions_device/aports/device/device-wileyfox-crackling/APKBUILD b/test/testdata/init_questions_device/aports/device/testing/device-wileyfox-crackling/APKBUILD similarity index 100% rename from test/testdata/init_questions_device/aports/device/device-wileyfox-crackling/APKBUILD rename to test/testdata/init_questions_device/aports/device/testing/device-wileyfox-crackling/APKBUILD