1
0
Fork 1
mirror of https://gitlab.postmarketos.org/postmarketOS/pmbootstrap.git synced 2025-07-13 03:19:47 +03: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
This commit is contained in:
Johannes Marbach 2021-08-30 09:24:46 +02:00 committed by Clayton Craft
parent 0b95779e30
commit ac4c967e18
No known key found for this signature in database
GPG key ID: 7A3461CA187CEA54
5 changed files with 48 additions and 16 deletions

View file

@ -1,6 +1,7 @@
# Copyright 2021 Danct12 <danct12@disroot.org>
# SPDX-License-Identifier: GPL-3.0-or-later
import logging
import os
import pmb.chroot
import pmb.chroot.apk
@ -9,16 +10,39 @@ import pmb.helpers.run
import pmb.helpers.pmaports
def check(args, pkgname):
pmb.chroot.apk.install(args, ["atools"])
def check(args, pkgnames):
"""
Run apkbuild-lint on the supplied packages
# Run apkbuild-lint on copy of pmaport in chroot
:param pkgnames: Names of the packages to lint
"""
pmb.chroot.apk.install(args, ["atools"])
pmb.build.init(args)
pmb.build.copy_to_buildpath(args, pkgname)
logging.info("(native) linting " + pkgname + " with apkbuild-lint")
# 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")
options = pmb.config.apkbuild_custom_valid_options
return pmb.chroot.user(args, ["apkbuild-lint", "APKBUILD"],
return pmb.chroot.root(args, ["apkbuild-lint"] + apkbuilds,
check=False, output="stdout",
output_return=True,
working_dir="/home/pmos/build",
working_dir=pmaports,
env={"CUSTOM_VALID_OPTIONS": " ".join(options)})