diff --git a/pmb/config/__init__.py b/pmb/config/__init__.py index 35f4451d..a4e95365 100644 --- a/pmb/config/__init__.py +++ b/pmb/config/__init__.py @@ -246,6 +246,14 @@ apkbuild_attributes = { "source": {"array": True}, } +# Reference: https://postmarketos.org/apkbuild-options +apkbuild_custom_valid_options = [ + "!pmb:crossdirect", + "!pmb:kconfig-check", + "pmb:cross-native", + "pmb:strict", +] + # Variables from deviceinfo. Reference: deviceinfo_attributes = [ # general diff --git a/pmb/helpers/lint.py b/pmb/helpers/lint.py index 5995df7b..84ad1bb6 100644 --- a/pmb/helpers/lint.py +++ b/pmb/helpers/lint.py @@ -16,8 +16,9 @@ def check(args, pkgname): pmb.build.init(args) pmb.build.copy_to_buildpath(args, pkgname) logging.info("(native) linting " + pkgname + " with apkbuild-lint") - pmb.chroot.user(args, ["apkbuild-lint", "APKBUILD"], - check=False, output="stdout", - working_dir="/home/pmos/build", - # Workaround, until we have CUSTOM_VALID_OPTIONS (#553) - env={"SKIP_INVALID_OPTION": "1"}) + options = pmb.config.apkbuild_custom_valid_options + return pmb.chroot.user(args, ["apkbuild-lint", "APKBUILD"], + check=False, output="stdout", + output_return=True, + working_dir="/home/pmos/build", + env={"CUSTOM_VALID_OPTIONS": " ".join(options)}) diff --git a/test/test_helpers_lint.py b/test/test_helpers_lint.py new file mode 100644 index 00000000..bcffa44b --- /dev/null +++ b/test/test_helpers_lint.py @@ -0,0 +1,43 @@ +# Copyright 2020 Oliver Smith +# SPDX-License-Identifier: GPL-3.0-or-later +import os +import pytest +import shutil +import sys + +import pmb_test +import pmb_test.const +import pmb.helpers.lint +import pmb.helpers.run + + +@pytest.fixture +def args(request): + import pmb.parse + sys.argv = ["pmbootstrap", "lint"] + args = pmb.parse.arguments() + args.log = args.work + "/log_testsuite.txt" + pmb.helpers.logging.init(args) + request.addfinalizer(args.logfd.close) + return args + + +def test_pmbootstrap_lint(args, tmpdir): + args.aports = tmpdir = str(tmpdir) + + # Create hello-world pmaport in tmpdir + apkbuild_orig = f"{pmb_test.const.testdata}/apkbuild/APKBUILD.lint" + apkbuild_tmp = f"{tmpdir}/hello-world/APKBUILD" + os.makedirs(f"{tmpdir}/hello-world") + shutil.copyfile(apkbuild_orig, apkbuild_tmp) + + # Lint passes + assert pmb.helpers.lint.check(args, "hello-world") == "" + + # Change "pmb:cross-native" to non-existing "pmb:invalid-opt" + pmb.helpers.run.user(args, ["sed", "s/pmb:cross-native/pmb:invalid-opt/g", + "-i", apkbuild_tmp]) + + # Lint error + err_str = "invalid option 'pmb:invalid-opt'" + assert err_str in pmb.helpers.lint.check(args, "hello-world") diff --git a/test/testdata/apkbuild/APKBUILD.lint b/test/testdata/apkbuild/APKBUILD.lint new file mode 100644 index 00000000..a780034b --- /dev/null +++ b/test/testdata/apkbuild/APKBUILD.lint @@ -0,0 +1,32 @@ +# APKBUILD to test 'pmbootstrap lint', used by test/test_helpers_lint.py +# Maintainer: Oliver Smith +pkgname=hello-world +pkgver=1 +pkgrel=5 +pkgdesc="hello world program to be built in the testsuite" +url="https://en.wikipedia.org/wiki/%22Hello,_World!%22_program" +arch="all" +license="MIT" +source="main.c Makefile" + +# has pmbootstrap specific options (https://postmarketos.org/apkbuild-options) +options="!tracedeps pmb:cross-native pmb:strict !archcheck" + +build() { + cd "$srcdir" + make +} + +check() { + cd "$srcdir" + printf 'hello, world!\n' > expected + ./hello-world > real + diff -q expected real +} + +package() { + install -D -m755 "$srcdir"/hello-world \ + "$pkgdir"/usr/bin/hello-world +} +sha512sums="62385af6a68cd4e0c03b15992bb9f1d20b8d6c8a33724ca2d28629a139e95016d0502257f8a3a8be53eef30e11b3e372a2469cb1989dbd387ebea4464a9273ee main.c +80c32948d3254f5e4f9084d73754824e7d7d7d117770b041a1a13baf056773de265153fe518cc3e735db55b638411aa6fbd0e17b5b674dfc89e69a9391fbd3bb Makefile"