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 <alex@aspect.dev>
This commit is contained in:
David Zbarsky 2023-10-05 15:36:55 -04:00 committed by GitHub
parent 20480444e6
commit 8fe4f6f8d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
bazel-* bazel-*
**/.terraform/* **/.terraform/*
test-out/ test-out/
.DS_Store

View File

@ -73,7 +73,7 @@ def _tar_impl(ctx):
args = ctx.actions.args() args = ctx.actions.args()
# Set mode # Set mode
args.add("--" + ctx.attr.mode) args.add(ctx.attr.mode, format = "--%s")
# User-provided args first # User-provided args first
args.add_all(ctx.attr.args) args.add_all(ctx.attr.args)
@ -82,9 +82,9 @@ def _tar_impl(ctx):
_add_compress_options(ctx.attr.compress, args) _add_compress_options(ctx.attr.compress, args)
out = ctx.outputs.out or ctx.actions.declare_file(ctx.attr.name + ".tar") 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) inputs.append(ctx.file.mtree)
ctx.actions.run( ctx.actions.run(
@ -97,6 +97,10 @@ def _tar_impl(ctx):
return DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out])) 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"): def _mtree_line(file, uid = "0", gid = "0", time = "1672560000", mode = "0755"):
return " ".join([ return " ".join([
file.short_path, file.short_path,
@ -109,11 +113,13 @@ def _mtree_line(file, uid = "0", gid = "0", time = "1672560000", mode = "0755"):
]) ])
def _mtree_impl(ctx): def _mtree_impl(ctx):
specification = []
out = ctx.outputs.out or ctx.actions.declare_file(ctx.attr.name + ".spec") out = ctx.outputs.out or ctx.actions.declare_file(ctx.attr.name + ".spec")
for s in ctx.files.srcs:
specification.append(_mtree_line(s)) content = ctx.actions.args()
ctx.actions.write(out, "\n".join(specification + [""])) 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])) return DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out]))
tar_lib = struct( tar_lib = struct(