diff options
author | Helmut Grohne <helmut@subdivi.de> | 2021-06-15 14:38:59 +0200 |
---|---|---|
committer | Helmut Grohne <helmut@subdivi.de> | 2021-06-15 14:38:59 +0200 |
commit | c03690f53941e03a6f1f400da4d7313f36902426 (patch) | |
tree | 18b43edb1d6883f3947fcea1c6999ea17839d8b2 | |
parent | 511c49acc13803d851a4d0d2ef17647e3e2144b4 (diff) | |
download | mdbp-c03690f53941e03a6f1f400da4d7313f36902426.tar.gz |
implement basic debspawn backend
-rw-r--r-- | TODO.md | 2 | ||||
-rwxr-xr-x | mdbp/debspawn.py | 69 | ||||
-rwxr-xr-x | setup.py | 1 |
3 files changed, 70 insertions, 2 deletions
diff --git a/TODO.md b/TODO.md deleted file mode 100644 index c85bb89..0000000 --- a/TODO.md +++ /dev/null @@ -1,2 +0,0 @@ -* There should be a backend supporting a container thingy (e.g. `debspawn`, - `debocker`, `whalebuilder`). diff --git a/mdbp/debspawn.py b/mdbp/debspawn.py new file mode 100755 index 0000000..e98605c --- /dev/null +++ b/mdbp/debspawn.py @@ -0,0 +1,69 @@ +#!/usr/bin/python3 +# SPDX-License-Identifier: MIT +"""mdbp backend using debspawn""" + +import argparse +import itertools +import os +import pathlib +import subprocess +import sys + +from .common import buildjson, clean_dir, compute_env, get_dsc, make_option + +def main() -> None: + """Entry point for mdbp-debspawn backend""" + parser = argparse.ArgumentParser() + parser.add_argument("buildjson", type=buildjson) + args = parser.parse_args() + build = args.buildjson + + if "sourcename" in build["input"]: + raise ValueError("building a source package by name is not supported") + if "bd-uninstallable-explainer" in build: + raise ValueError("bd-uninstallable-explainer %r not supported" % + build["bd-uinstallable-explainer"]) + if build.get("buildpath"): + raise ValueError("buildpath not supported") + if build.get("hostarch") not in (None, build.get("buildarch")): + raise ValueError("cross building is not supported") + if build.get("lintian", {}).get("run", False) and \ + build["lintian"].get("options"): + raise ValueError("setting lintian options is not supported") + if build.get("network") == "disable": + raise ValueError("disabling network is not supported") + + env = compute_env(build) + if build.get("profiles"): + env["DEB_BUILD_PROFILES"] = " ".join(build["profiles"]) + enablelog = build["output"].get("log", True) + + cmd = [ + *(["sudo", "--"] if os.getuid() != 0 else ()), + "debspawn", "build", "--no-buildlog", + *make_option("--arch", build.get("buildarch")), + "--only", + dict( + any="arch", + all="indep", + binary="binary", + )[build.get("type", "binary")], + "--results-dir", build["output"]["directory"], + *(["--run-lintian"] if build.get("lintian", {}).get("run", False) + else ()), + *itertools.chain.from_iterable( + ("--setenv", "%s=%s" % item) for item in env.items()), + build["distribution"], + ] + with get_dsc(build) as dscpath: + ret = subprocess.call([*cmd, str(dscpath)], + 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(ret) + +if __name__ == "__main__": + main() @@ -20,6 +20,7 @@ setup(name="mdbp", ], entry_points=dict( console_scripts=[ + "mdbp-debspawn=mdbp.debspawn:main", "mdbp-mmdebstrap=mdbp.mmdebstrap:main", "mdbp-pbuilder=mdbp.pbuilder:main", "mdbp-sbuild=mdbp.sbuild:main", |