diff options
Diffstat (limited to 'mdbp/mmdebstrap.py')
-rw-r--r-- | mdbp/mmdebstrap.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/mdbp/mmdebstrap.py b/mdbp/mmdebstrap.py index 9726a03..b3fa161 100644 --- a/mdbp/mmdebstrap.py +++ b/mdbp/mmdebstrap.py @@ -15,10 +15,9 @@ import subprocess import sys import typing -import debian.debian_support - -from .common import JsonObject, buildjson, clean_dir, compute_env, \ - download_dsc, get_dsc_files, json_load, parse_dsc, profile_option +from .common import JsonObject, build_subdir, buildjson, clean_dir, \ + compute_env, download_dsc, get_dsc_files, json_load, parse_dsc, \ + profile_option libc = ctypes.CDLL(ctypes.util.find_library("c")) def unshare_network() -> None: @@ -70,11 +69,6 @@ def native_architecture() -> str: return subprocess.check_output(["dpkg", "--print-architecture"], encoding="ascii").strip() -def build_subdir(dsc: debian.deb822.Dsc) -> str: - """Compute the subdirectory that dpkg-source normally extracts to.""" - ver = debian.debian_support.BaseVersion(dsc["Version"]).upstream_version - assert ver is not None # please mypy - return "%s-%s" % (dsc["Source"], ver) def hook_main(build: JsonObject, chroot: pathlib.Path) -> None: """The entry point for the --hook-helper invocation run from mmdebstrap.""" @@ -97,7 +91,7 @@ def hook_main(build: JsonObject, chroot: pathlib.Path) -> None: chroot=chroot, chdir=builddir, setuid="build") [dscpath] = fullbuilddir.glob(build["input"]["sourcename"] + "_*.dsc") dsc = parse_dsc(dscpath) - subdir = build_subdir(dsc) + subdir = build_subdir(dsc["Source"], dsc["Version"]) priv_drop(["dpkg-source", "--no-check", "--extract", dscpath.name, subdir], setuid="build", chroot=chroot, chdir=builddir) for path in [*get_dsc_files(dscpath, dsc), dscpath]: @@ -127,6 +121,19 @@ def hook_main(build: JsonObject, chroot: pathlib.Path) -> None: '-oDebug::pkgDepCache::AutoInstall=1', '-oDebug::BuildDeps=1'] priv_drop(cmd, chroot=chroot, chdir=builddir / subdir) + env = compute_env(build) + + def run_hooks(hooktype: str) -> None: + for hook in build.get("hooks", ()): + if hook["type"] != hooktype: + continue + priv_drop(["sh", "-c", hook["command"]], chroot=chroot, env=env, + setuid=None if hook.get("user", "root") == "root" + else "build", + chdir="/" if hook.get("cwd", "root") == "root" + else builddir / subdir) + + run_hooks("prebuild") try: priv_drop( [ @@ -140,10 +147,13 @@ def hook_main(build: JsonObject, chroot: pathlib.Path) -> None: setuid="build", privnet=not build.get("network") in ("enable", "try-enable"), chdir=builddir / subdir, - env=compute_env(build), + env=env, ) except subprocess.CalledProcessError as cpe: + run_hooks("postbuildfailure") sys.exit(cpe.returncode) + else: + run_hooks("postbuildsuccess") shutil.rmtree(fullbuilddir / subdir) if build.get("lintian", {}).get("run"): priv_drop([*apt_get, "install", "lintian"], chroot=chroot) |