2022-01-02 21:38:21 +00:00
|
|
|
# Copyright 2022 Oliver Smith
|
2020-05-03 09:35:10 +00:00
|
|
|
# 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)
|
2021-09-20 10:00:13 +00:00
|
|
|
request.addfinalizer(pmb.helpers.logging.logfd.close)
|
2020-05-03 09:35:10 +00:00
|
|
|
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
|
pmbootstrap lint: avoid looping and copying files (MR 2100)
Before this commit, package folders were copied into the chroot one by
one in order to run apkbuild-lint on them. This logic is replaced by
mounting pmaports.git into the chroot and using a single apkbuild-lint
invocation to lint the supplied packages.
Both of these changes result in a performance improvement, especially
when linting multiple packages at once.
Before this change:
$ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
> /dev/null
real 0m5,261s
user 0m7,046s
sys 0m1,842s
Using the pmaports.git mount but calling apkbuild-lint in a loop:
$ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
> /dev/null
real 0m4,089s
user 0m6,418s
sys 0m1,219s
After this change:
$ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
> /dev/null
real 0m3,518s
user 0m5,968s
sys 0m0,959s
Additionally, running apkbuild-lint from the pmaports.git mount point
has the benefit that every printed violation contains a nice source
identifier à la "./cross/grub-x86/APKBUILD". This makes it possible to
differentiate between different packages even though only a single
apkbuild-lint invocation is used.
Relates: postmarketOS/pmaports#564
2021-08-30 07:24:46 +00:00
|
|
|
assert pmb.helpers.lint.check(args, ["hello-world"]) == ""
|
2020-05-03 09:35:10 +00:00
|
|
|
|
|
|
|
# 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'"
|
pmbootstrap lint: avoid looping and copying files (MR 2100)
Before this commit, package folders were copied into the chroot one by
one in order to run apkbuild-lint on them. This logic is replaced by
mounting pmaports.git into the chroot and using a single apkbuild-lint
invocation to lint the supplied packages.
Both of these changes result in a performance improvement, especially
when linting multiple packages at once.
Before this change:
$ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
> /dev/null
real 0m5,261s
user 0m7,046s
sys 0m1,842s
Using the pmaports.git mount but calling apkbuild-lint in a loop:
$ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
> /dev/null
real 0m4,089s
user 0m6,418s
sys 0m1,219s
After this change:
$ time ./pmbootstrap.py -q lint $(cd ../pmaports/cross; echo *) \
> /dev/null
real 0m3,518s
user 0m5,968s
sys 0m0,959s
Additionally, running apkbuild-lint from the pmaports.git mount point
has the benefit that every printed violation contains a nice source
identifier à la "./cross/grub-x86/APKBUILD". This makes it possible to
differentiate between different packages even though only a single
apkbuild-lint invocation is used.
Relates: postmarketOS/pmaports#564
2021-08-30 07:24:46 +00:00
|
|
|
assert err_str in pmb.helpers.lint.check(args, ["hello-world"])
|