from jolt import attributes, BooleanParameter, Parameter
from jolt.pkgs import libcap
from jolt.plugins import git, autotools, pkgconfig
from jolt.tasks import TaskRegistry


@attributes.requires("requires_git")
@attributes.requires("requires_libcap_{caps[on,off]}")
@autotools.requires()
@pkgconfig.requires()
class CRun(autotools.Autotools):
    name = "crun"
    version = Parameter("1.26", help="crun version.")
    caps = BooleanParameter(False, help="Enable capabilities support.")
    systemd = BooleanParameter(False, help="Enable systemd support.")
    requires_git = ["git:url=https://github.com/containers/crun.git,rev={version},submodules=true"]
    requires_caps_on = ["libcap"]
    srcdir = "{git[crun]}"
    options = [
        # Unable to get ./configure to pick these up from pkg-config
        "--disable-criu",
        "--disable-seccomp",
        "--enable-embedded-yajl",
        "{caps[,--disable-caps]}",
        "{systemd[,--disable-systemd]}",
    ]


TaskRegistry.get().add_task_class(CRun)
