From 2fd92276547dcd3efd900b61904d24150692e379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 24 May 2021 00:11:58 +0300 Subject: [PATCH] rootfs accepts output param --- rules.bzl | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/rules.bzl b/rules.bzl index 0fbfdc4..8856b9b 100644 --- a/rules.bzl +++ b/rules.bzl @@ -14,7 +14,9 @@ _input_container = attr.label( ) def _rootfs_impl(ctx): - out = ctx.actions.declare_file(ctx.attr.name + ".tar") + out = ctx.outputs.out + if out == None: + out = ctx.actions.declare_file(ctx.attr.name + ".tar") ctx.actions.run( outputs = [out], inputs = ctx.files.src, @@ -37,6 +39,7 @@ rootfs = rule( attrs = { "src": _input_container, "_undocker": _undocker_cli, + "out": attr.output(), }, ) @@ -58,6 +61,19 @@ def _lxcconfig_impl(ctx): runfiles = ctx.runfiles(files = ctx.files.src), ) + +def lxcbundle(name, src): + rootfsname = name+"-rootfs" + rootfsnametar = rootfsname+"-tar" + rootfs(name = rootfsnametar, src = src, out = rootfsname+".tar") + lxcconfig(name, src = src) + native.genrule( + name = rootfsnametar + "-xz", + srcs = [rootfsnametar], + outs = [rootfsname + ".tar.xz"], + cmd = "xz -cf $< > $@", + ) + _lxcconfig = rule( _lxcconfig_impl, doc = "Generate lxc config from a docker container image", @@ -67,6 +83,7 @@ _lxcconfig = rule( }, ) + def lxcconfig(name, src): _lxcconfig(name = name+"/config", src = src) pkg_tar( @@ -77,15 +94,3 @@ def lxcconfig(name, src): name: "", }, ) - - -def lxcbundle(name, src): - rootfsname = name+"-rootfs" - rootfs(name = rootfsname, src = src) - lxcconfig(name, src = src) - native.genrule( - name = rootfsname + ".xz", - srcs = [rootfsname], - outs = [rootfsname + ".xz"], - cmd = "xz -cf $< > $@", - )