From 8fe4f6f8d50a9016702690c175687f6bd366dd59 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Thu, 5 Oct 2023 15:36:55 -0400 Subject: [PATCH] Avoid expanding mtree spec during analysis phase (#576) * Avoid expanding mtree spec during analysis phase * Update tar.bzl remove comment and unused code --------- Co-authored-by: Alex Eagle --- .gitignore | 1 + lib/private/tar.bzl | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index bf0f9f6..ceee65c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ bazel-* **/.terraform/* test-out/ +.DS_Store diff --git a/lib/private/tar.bzl b/lib/private/tar.bzl index bc581e9..bc3c160 100644 --- a/lib/private/tar.bzl +++ b/lib/private/tar.bzl @@ -73,7 +73,7 @@ def _tar_impl(ctx): args = ctx.actions.args() # Set mode - args.add("--" + ctx.attr.mode) + args.add(ctx.attr.mode, format = "--%s") # User-provided args first args.add_all(ctx.attr.args) @@ -82,9 +82,9 @@ def _tar_impl(ctx): _add_compress_options(ctx.attr.compress, args) out = ctx.outputs.out or ctx.actions.declare_file(ctx.attr.name + ".tar") - args.add_all(["--file", out.path]) + args.add("--file", out) - args.add("@" + ctx.file.mtree.path) + args.add(ctx.file.mtree, format = "@%s") inputs.append(ctx.file.mtree) ctx.actions.run( @@ -97,6 +97,10 @@ def _tar_impl(ctx): return DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out])) +def _default_mtree_line(file): + # Functions passed to map_each cannot take optional arguments. + return _mtree_line(file) + def _mtree_line(file, uid = "0", gid = "0", time = "1672560000", mode = "0755"): return " ".join([ file.short_path, @@ -109,11 +113,13 @@ def _mtree_line(file, uid = "0", gid = "0", time = "1672560000", mode = "0755"): ]) def _mtree_impl(ctx): - specification = [] out = ctx.outputs.out or ctx.actions.declare_file(ctx.attr.name + ".spec") - for s in ctx.files.srcs: - specification.append(_mtree_line(s)) - ctx.actions.write(out, "\n".join(specification + [""])) + + content = ctx.actions.args() + content.set_param_file_format("multiline") + content.add_all(ctx.files.srcs, map_each = _default_mtree_line) + ctx.actions.write(out, content = content) + return DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out])) tar_lib = struct(