summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHelmut Grohne <helmut@subdivi.de>2021-05-27 11:54:04 +0200
committerHelmut Grohne <helmut@subdivi.de>2021-05-27 11:54:04 +0200
commit69fdfcdda423b55c7251e4d46e82563cda98a63d (patch)
tree4299a69f4ae7461065f3f1bb48ac9f2ba557f058
parentafff0dc73188ac323ec0265cc6b39c67f9fd7474 (diff)
downloadmdbp-69fdfcdda423b55c7251e4d46e82563cda98a63d.tar.gz
add new field .output.artifacts to schema
Using the field you can specify an ORed set of positive glob-style patterns for artifacts to retain in the .output.directory. It defaults to including all artifacts.
-rw-r--r--.pylintrc2
-rw-r--r--TODO.md1
-rw-r--r--mdbp/build_schema.json7
-rw-r--r--mdbp/common.py10
-rw-r--r--mdbp/mmdebstrap.py10
-rw-r--r--mdbp/pbuilder.py16
-rw-r--r--mdbp/sbuild.py25
-rw-r--r--mdbp/streamapi.py5
8 files changed, 52 insertions, 24 deletions
diff --git a/.pylintrc b/.pylintrc
new file mode 100644
index 0000000..fc2a971
--- /dev/null
+++ b/.pylintrc
@@ -0,0 +1,2 @@
+[MESSAGES CONTROL]
+disable=subprocess-run-check
diff --git a/TODO.md b/TODO.md
index 1407dc8..c85bb89 100644
--- a/TODO.md
+++ b/TODO.md
@@ -1,3 +1,2 @@
-* It should be requestable which build artifacts are to be retained.
* There should be a backend supporting a container thingy (e.g. `debspawn`,
`debocker`, `whalebuilder`).
diff --git a/mdbp/build_schema.json b/mdbp/build_schema.json
index 2a357c9..c908fb6 100644
--- a/mdbp/build_schema.json
+++ b/mdbp/build_schema.json
@@ -152,6 +152,13 @@
"type": "boolean",
"default": true,
"description": "whether to output the build log on the stdout file descriptor"
+ },
+ "artifacts": {
+ "type": "array",
+ "items": { "type": "string" },
+ "uniqueItems": true,
+ "default": [ "*" ],
+ "description": "Any build artifact that matches any of these glob style patterns is included in the output. Patterns allow *, ?, [ranges] and [!ranges]."
}
}
}
diff --git a/mdbp/common.py b/mdbp/common.py
index ba4b20d..df434cb 100644
--- a/mdbp/common.py
+++ b/mdbp/common.py
@@ -4,6 +4,7 @@
from __future__ import annotations
import argparse
import contextlib
+import fnmatch
import hashlib
import importlib.resources
import json
@@ -181,3 +182,12 @@ def tar_add(tarobj: tarfile.TarFile, path: pathlib.Path) -> None:
info.mtime = int(statres.st_mtime)
with path.open("rb") as fobj:
tarobj.addfile(info, fobj)
+
+
+def clean_dir(directory: pathlib.Path, patterns: typing.List[str]) -> None:
+ """Delete all entries of `directory` that match none of the given
+ `patterns`."""
+ for entry in directory.iterdir():
+ if not any(fnmatch.fnmatchcase(entry.name, pattern)
+ for pattern in patterns):
+ entry.unlink()
diff --git a/mdbp/mmdebstrap.py b/mdbp/mmdebstrap.py
index 18dfc31..aa1f461 100644
--- a/mdbp/mmdebstrap.py
+++ b/mdbp/mmdebstrap.py
@@ -16,8 +16,8 @@ import subprocess
import sys
import typing
-from .common import buildjson, compute_env, download_dsc, get_dsc_files, \
- json_load, profile_option
+from .common import buildjson, clean_dir, compute_env, download_dsc, \
+ get_dsc_files, json_load, profile_option
libc = ctypes.CDLL(ctypes.util.find_library("c"))
def unshare_network() -> None:
@@ -117,6 +117,7 @@ def hook_main(buildjsonfilename: str, chrootname: str) -> None:
priv_drop(["lintian", *build["lintian"].get("options", ()),
"%s_%s.changes" % (dscpath.stem, hostarch)],
chroot=chroot, setuid="build", chdir=buildpath.parent)
+ clean_dir(fullbuildpath.parent, build["output"].get("artifacts", ["*"]))
class RawStoreAction(argparse.Action):
"""An action that stores the raw value in addition to the type-parsed
@@ -189,8 +190,9 @@ def main() -> None:
if "dscpath" in build["input"] else ()),
'--customize-hook=mdbp-mmdebstrap --hook-helper %s "$1"' %
shlex.quote(args.raw_buildjson),
- "--customize-hook=sync-out " +
- shlex.join([str(buildpath.parent), build["output"]["directory"]]),
+ *(["--customize-hook=sync-out " +
+ shlex.join([str(buildpath.parent), build["output"]["directory"]])]
+ if build["output"].get("artifacts", ["*"]) else ()),
build["distribution"],
"/dev/null",
args.mirror,
diff --git a/mdbp/pbuilder.py b/mdbp/pbuilder.py
index 64d218d..269b220 100644
--- a/mdbp/pbuilder.py
+++ b/mdbp/pbuilder.py
@@ -10,7 +10,7 @@ import subprocess
import sys
import tempfile
-from .common import buildjson, compute_env, get_dsc, make_option, \
+from .common import buildjson, clean_dir, compute_env, get_dsc, make_option, \
profile_option
def main() -> None:
@@ -79,12 +79,14 @@ runuser -u pbuilder -- lintian %s "${BUILDDIR:-/tmp/buildd}"/*.changes
""" % (shlex.join(apt_get), shlex.join(build["lintian"].get("options", []))))
hook.chmod(0o755)
cmd.extend(["--hookdir", hookdirn, str(dscpath)])
- proc = subprocess.Popen(cmd, env=compute_env(build),
- stdout=None if enablelog
- else subprocess.DEVNULL,
- stderr=subprocess.STDOUT if enablelog
- else subprocess.DEVNULL)
- sys.exit(proc.wait())
+ cproc = subprocess.run(cmd, env=compute_env(build),
+ stdout=None if enablelog
+ else subprocess.DEVNULL,
+ stderr=subprocess.STDOUT if enablelog
+ else subprocess.DEVNULL)
+ clean_dir(pathlib.Path(build["output"]["directory"]),
+ build["output"].get("artifacts", ["*"]))
+ sys.exit(cproc.returncode)
if __name__ == "__main__":
main()
diff --git a/mdbp/sbuild.py b/mdbp/sbuild.py
index edb3531..5309031 100644
--- a/mdbp/sbuild.py
+++ b/mdbp/sbuild.py
@@ -4,12 +4,13 @@
import argparse
import contextlib
+import pathlib
import subprocess
import sys
import tempfile
import typing
-from .common import buildjson, compute_env, get_dsc
+from .common import buildjson, clean_dir, compute_env, get_dsc
PerlValue = typing.Union[None, str, typing.List[typing.Any],
typing.Dict[str, typing.Any]]
@@ -89,16 +90,18 @@ def main() -> None:
except KeyError:
thing = str(stack.enter_context(get_dsc(build)).absolute())
- proc = subprocess.Popen(["sbuild", thing],
- env=dict(SBUILD_CONFIG=sbuildconf.name,
- PATH="/usr/bin:/bin"),
- cwd=build["output"]["directory"],
- stdout=None if build["output"].get("log", True)
- else subprocess.DEVNULL,
- stderr=subprocess.STDOUT
- if build["output"].get("log", True)
- else subprocess.DEVNULL)
- sys.exit(proc.wait())
+ cproc = subprocess.run(["sbuild", thing],
+ env=dict(SBUILD_CONFIG=sbuildconf.name,
+ PATH="/usr/bin:/bin"),
+ cwd=build["output"]["directory"],
+ stdout=None if build["output"].get("log", True)
+ else subprocess.DEVNULL,
+ stderr=subprocess.STDOUT
+ if build["output"].get("log", True)
+ else subprocess.DEVNULL)
+ clean_dir(pathlib.Path(build["output"]["directory"]),
+ build["output"].get("artifacts", ["*"]))
+ sys.exit(cproc.returncode)
if __name__ == "__main__":
main()
diff --git a/mdbp/streamapi.py b/mdbp/streamapi.py
index 8f67366..f36208a 100644
--- a/mdbp/streamapi.py
+++ b/mdbp/streamapi.py
@@ -12,6 +12,7 @@ Differences to the regular backend API:
"""
import argparse
+import fnmatch
import json
import pathlib
import subprocess
@@ -67,7 +68,9 @@ def main() -> None:
sys.exit(code)
with tarfile.open(fileobj=sys.stdout.buffer, mode="w|") as outtar:
for elem in outdir.iterdir():
- tar_add(outtar, elem)
+ if any(fnmatch.fnmatchcase(elem.name, pattern)
+ for pattern in build["output"].get("artifacts", ["*"])):
+ tar_add(outtar, elem)
if __name__ == "__main__":
main()