summaryrefslogtreecommitdiff
path: root/mdbp/sbuild.py
diff options
context:
space:
mode:
Diffstat (limited to 'mdbp/sbuild.py')
-rw-r--r--mdbp/sbuild.py40
1 files changed, 33 insertions, 7 deletions
diff --git a/mdbp/sbuild.py b/mdbp/sbuild.py
index 8330e6e..7041090 100644
--- a/mdbp/sbuild.py
+++ b/mdbp/sbuild.py
@@ -5,12 +5,15 @@
import argparse
import contextlib
import pathlib
+import shlex
import subprocess
import sys
import typing
-from .common import AddSpaceSeparatedValues, buildjson, clean_dir, \
- compute_env, get_dsc, temporary_static_file
+from .common import AddSpaceSeparatedValues, build_subdir, buildjson, \
+ clean_dir, compute_env, get_dsc, hook_commands, parse_dsc, \
+ temporary_static_file
+
PerlValue = typing.Union[None, str, typing.List[typing.Any],
typing.Dict[str, typing.Any]]
@@ -45,13 +48,13 @@ def add_external_command(
conf: typing.Dict[str, PerlValue], stage: str, command: str
) -> None:
"""Modify the given conf object to add the given command on the given
- external_commands stage.
+ external_commands stage. The special meaning of % in sbuild is escaped.
"""
extcomm = conf.setdefault("external_commands", {})
assert isinstance(extcomm, dict)
comms = extcomm.setdefault(stage, [])
assert isinstance(comms, list)
- comms.append(command)
+ comms.append(command.replace("%", "%%"))
def main() -> None:
@@ -114,16 +117,39 @@ def main() -> None:
"finished-build-commands",
"mv /etc/resolv.conf.disabled /etc/resolv.conf",
)
+ hooknamemap = {
+ "prebuild": "starting-build-commands",
+ "postbuildsuccess": "finished-build-commands",
+ "postbuildfailure": "build-failed-commands",
+ }
with contextlib.ExitStack() as stack:
- sbuildconf = stack.enter_context(temporary_static_file(perl_conf(sbc)))
-
try:
thing = build["input"]["sourcename"]
+ subdir = shlex.quote(thing) + "-*"
with contextlib.suppress(KeyError):
thing += "_" + build["input"]["version"]
+ subdir = shlex.quote(
+ build_subdir(
+ build["input"]["sourcename"], build["input"]["version"]
+ )
+ )
except KeyError:
- thing = str(stack.enter_context(get_dsc(build)).absolute())
+ dscpath = stack.enter_context(get_dsc(build))
+ thing = str(dscpath.absolute())
+ dsc = parse_dsc(dscpath)
+ subdir = shlex.quote(build_subdir(dsc["Source"], dsc["Version"]))
+
+ for hook in build.get("hooks", ()):
+ add_external_command(
+ sbc,
+ hooknamemap[hook["type"]],
+ " || return $?; ".join(
+ hook_commands(hook, "./" + subdir)
+ ),
+ )
+
+ sbuildconf = stack.enter_context(temporary_static_file(perl_conf(sbc)))
ret = subprocess.call(["sbuild", *args.sbuildopts, thing],
env=dict(SBUILD_CONFIG=str(sbuildconf),