diff options
Diffstat (limited to 'mdbp/pbuilder.py')
-rw-r--r-- | mdbp/pbuilder.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/mdbp/pbuilder.py b/mdbp/pbuilder.py index e074ed4..09ea202 100644 --- a/mdbp/pbuilder.py +++ b/mdbp/pbuilder.py @@ -12,9 +12,9 @@ import sys import tempfile import typing -from .common import AddSpaceSeparatedValues, buildjson, clean_dir, \ - compute_env, get_dsc, make_option, profile_option, \ - temporary_static_file +from .common import AddSpaceSeparatedValues, build_subdir, buildjson, \ + clean_dir, compute_env, get_dsc, hook_commands, make_option, \ + parse_dsc, profile_option, temporary_static_file def find_basetgz(distribution: str, basedir: str = "/var/cache/pbuiler") -> typing.Optional[str]: @@ -28,6 +28,15 @@ def find_basetgz(distribution: str, raise ValueError("unsupported distribution %s" % distribution) +def sourcetree_location(dscpath: pathlib.Path) -> str: + """Compute a shell expression that represents the source tree location + inside pbuilder. + """ + dsc = parse_dsc(dscpath) + subdir = build_subdir(dsc["Source"], dsc["Version"]) + return '"$BUILDDIR"/' + shlex.quote(subdir) + + @contextlib.contextmanager def hookdir() -> typing.Iterator[ typing.Tuple[pathlib.Path, typing.Callable[[str, str], None]] @@ -131,8 +140,22 @@ runuser -u pbuilder -- lintian %s "${BUILDDIR:-/tmp/buildd}"/*.changes shlex.join(build["lintian"].get("options", [])), ), ) + + dscpath = stack.enter_context(get_dsc(build)) + sourcetree = sourcetree_location(dscpath) + + for hook in build.get("hooks", ()): + addhook({ + "prebuild": "A", + "postbuildsuccess": "B", + "postbuildfailure": "C", + }[hook["type"]], + "#!/bin/sh\n%s\n" % + " || return $?\n".join( + hook_commands(hook, sourcetree))) + cmd.extend(["--hookdir", str(hookdirname), *args.pbuilderopts, - str(stack.enter_context(get_dsc(build)))]) + str(dscpath)]) ret = subprocess.call(cmd, env=compute_env(build), stdout=None if enablelog else subprocess.DEVNULL, |