Skip to content

Commit

Permalink
Avoid expanding mtree spec during analysis phase (#576)
Browse files Browse the repository at this point in the history
* Avoid expanding mtree spec during analysis phase

* Update tar.bzl

remove comment and unused code

---------

Co-authored-by: Alex Eagle <alex@aspect.dev>
  • Loading branch information
dzbarsky and alexeagle committed Oct 5, 2023
1 parent 2048044 commit 8fe4f6f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bazel-*
**/.terraform/*
test-out/
.DS_Store
20 changes: 13 additions & 7 deletions lib/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit 8fe4f6f

Please sign in to comment.