summaryrefslogtreecommitdiff
path: root/mdbp/sbuild.py
blob: 43937bfcc2a5f66e39ff9f98638836602a8c5f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python3
# SPDX-License-Identifier: MIT
"""mdbp backend using sbuild"""

import argparse
import subprocess

from .common import buildjson, compute_env, get_dsc, make_option, \
        profile_option

def main() -> None:
    """Entry point for mdbp-sbuild backend"""
    parser = argparse.ArgumentParser()
    parser.add_argument("buildjson", type=buildjson)
    args = parser.parse_args()
    build = args.buildjson

    if build.get("network") == "disable":
        raise ValueError("disabling network not supported with sbuild")

    cmd = [
        "sbuild",
        "--dist=" + build["distribution"],
        "--no-arch-any" if build.get("type") == "all" else "--arch-any",
        "--no-arch-all" if build.get("type") == "any" else "--arch-all",
        "--bd-uninstallable-explainer=" +
            (build.get("bd-uninstallable-explainer") or ""),
        "--run-lintian" if build.get("lintian", {}).get("run") else
            "--no-run-lintian",
    ]
    cmd.extend(map("--lintian-opt=".__add__,
                   build.get("lintian", {}).get("options", ())))
    cmd.extend(make_option("--build=", build.get("buildarch")))
    cmd.extend(make_option("--host=", build.get("hostarch")))
    cmd.extend(map("--extra-repository=".__add__,
                   build.get("extrarepositories", ())))
    cmd.extend(profile_option(build, "--profiles="))
    cmd.extend(make_option("--build-path=", build.get("buildpath")))
    if build.get("network") == "try-disable":
        cmd.extend([
            "--starting-build-commands="
                "mv /etc/resolv.conf /etc/resolv.conf.disabled",
            "--finished-build-commands="
                "mv /etc/resolv.conf.disabled /etc/resolv.conf",
        ])
    with get_dsc(build) as dscpath:
        cmd.append(str(dscpath.absolute()))
        proc = subprocess.Popen(cmd, env=compute_env(build),
                                cwd=build["output"]["directory"])
        proc.wait()

if __name__ == "__main__":
    main()