2023-01-22 18:11:10 +00:00
|
|
|
# Copyright 2023 Danct12 <danct12@disroot.org>
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-02-06 12:03:02 +00:00
|
|
|
import logging
|
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
|
|
|
import os
|
2020-02-06 12:03:02 +00:00
|
|
|
|
|
|
|
import pmb.chroot
|
|
|
|
import pmb.chroot.apk
|
|
|
|
import pmb.build
|
|
|
|
import pmb.helpers.run
|
|
|
|
import pmb.helpers.pmaports
|
|
|
|
|
|
|
|
|
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
|
|
|
def check(args, pkgnames):
|
|
|
|
"""
|
|
|
|
Run apkbuild-lint on the supplied packages
|
2020-02-06 12:03:02 +00:00
|
|
|
|
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
|
|
|
:param pkgnames: Names of the packages to lint
|
|
|
|
"""
|
|
|
|
pmb.chroot.apk.install(args, ["atools"])
|
|
|
|
|
|
|
|
# Mount pmaports.git inside the chroot so that we don't have to copy the
|
|
|
|
# package folders
|
|
|
|
pmaports = "/mnt/pmaports"
|
|
|
|
pmb.build.mount_pmaports(args, pmaports)
|
|
|
|
|
|
|
|
# Locate all APKBUILDs and make the paths be relative to the pmaports
|
|
|
|
# root
|
|
|
|
apkbuilds = []
|
|
|
|
for pkgname in pkgnames:
|
|
|
|
aport = pmb.helpers.pmaports.find(args, pkgname)
|
|
|
|
if not os.path.exists(aport + "/APKBUILD"):
|
|
|
|
raise ValueError("Path does not contain an APKBUILD file:" +
|
|
|
|
aport)
|
|
|
|
relpath = os.path.relpath(aport, args.aports)
|
|
|
|
apkbuilds.append(f"{relpath}/APKBUILD")
|
|
|
|
|
|
|
|
# Run apkbuild-lint in chroot from the pmaports mount point. This will
|
|
|
|
# print a nice source identifier à la "./cross/grub-x86/APKBUILD" for
|
|
|
|
# each violation.
|
|
|
|
pkgstr = ", ".join(pkgnames)
|
|
|
|
logging.info(f"(native) linting {pkgstr} with apkbuild-lint")
|
2020-05-03 09:35:10 +00:00
|
|
|
options = pmb.config.apkbuild_custom_valid_options
|
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
|
|
|
return pmb.chroot.root(args, ["apkbuild-lint"] + apkbuilds,
|
2020-05-03 09:35:10 +00:00
|
|
|
check=False, output="stdout",
|
|
|
|
output_return=True,
|
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
|
|
|
working_dir=pmaports,
|
2020-05-03 09:35:10 +00:00
|
|
|
env={"CUSTOM_VALID_OPTIONS": " ".join(options)})
|