From f5db1b4306305256fb282617afe8e12fcbda72d8 Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Wed, 26 Jun 2019 20:24:24 +0200 Subject: [PATCH] apkbuild parser: support depends="$depends ..." (!1795) Properly handle the following two cases in APKBUILDs: * depends="$depends ..." * depends="${depends} ..." First I've attempted to refactor the parsing code to do this in a more generic way. But I've realized that it would make more sense to retire the python based APKBUILD parsing approach altogether and finally use a shell script parser. Let's discuss this in #1801. --- pmb/parse/_apkbuild.py | 7 +++++++ test/test_parse_apkbuild.py | 6 ++++++ test/testdata/apkbuild/APKBUILD.depends-in-depends | 8 ++++++++ 3 files changed, 21 insertions(+) create mode 100644 test/testdata/apkbuild/APKBUILD.depends-in-depends diff --git a/pmb/parse/_apkbuild.py b/pmb/parse/_apkbuild.py index 1013cfb1..34e7784b 100644 --- a/pmb/parse/_apkbuild.py +++ b/pmb/parse/_apkbuild.py @@ -170,6 +170,13 @@ def apkbuild(args, path, check_pkgver=True, check_pkgname=True): i += 1 line_value = lines[i][:-1] + # Support depends="$depends hello-world" (#1800) + if attribute == "depends" and ("${depends}" in value or + "$depends" in value): + previous = " ".join(ret["depends"]) if "depends" in ret else "" + value = value.replace("${depends}", previous) + value = value.replace("$depends", previous) + # Split up arrays, delete empty strings inside the list if options["array"]: if value: diff --git a/test/test_parse_apkbuild.py b/test/test_parse_apkbuild.py index 27fb7ea9..eee813d4 100644 --- a/test/test_parse_apkbuild.py +++ b/test/test_parse_apkbuild.py @@ -72,3 +72,9 @@ def test_kernels(args): ret = {"downstream": "Downstream description", "mainline": "Mainline description"} assert func(args, device) == ret + + +def test_depends_in_depends(args): + path = pmb_src + "/test/testdata/apkbuild/APKBUILD.depends-in-depends" + apkbuild = pmb.parse.apkbuild(args, path, check_pkgname=False) + assert apkbuild["depends"] == ["first", "second", "third"] diff --git a/test/testdata/apkbuild/APKBUILD.depends-in-depends b/test/testdata/apkbuild/APKBUILD.depends-in-depends new file mode 100644 index 00000000..c7f5d88a --- /dev/null +++ b/test/testdata/apkbuild/APKBUILD.depends-in-depends @@ -0,0 +1,8 @@ +pkgname="depends-in-depends" +pkgver="1.0.0" +pkgrel=0 +arch="armhf" +depends="first" +depends="$depends second" +depends="${depends} third" +pkgdesc="depends-in-depends test"