pmbootstrap lint: use CUSTOM_VALID_OPTIONS (MR 1934)

Let apkbuild-lint check options again, and pass the pmbootstrap specific
options with the new CUSTOM_VALID_OPTIONS variable. Add a test case and
adjust pmb.helpers.lint.check to return the output of apkbuild-lint, so
we can properly test it.

Related: https://gitlab.alpinelinux.org/Leo/atools/-/merge_requests/28
Fixes: pmaports#553
This commit is contained in:
Oliver Smith 2020-05-03 11:35:10 +02:00
parent df08af7984
commit f3466dcd3f
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
4 changed files with 89 additions and 5 deletions

View File

@ -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: <https://postmarketos.org/deviceinfo>
deviceinfo_attributes = [
# general

View File

@ -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)})

43
test/test_helpers_lint.py Normal file
View File

@ -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")

32
test/testdata/apkbuild/APKBUILD.lint vendored Normal file
View File

@ -0,0 +1,32 @@
# APKBUILD to test 'pmbootstrap lint', used by test/test_helpers_lint.py
# Maintainer: Oliver Smith <ollieparanoid@postmarketos.org>
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"