Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid expanding mtree spec during analysis phase #576

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid expanding mtree spec during analysis phase
  • Loading branch information
dzbarsky committed Oct 5, 2023
commit af1c3f079731bcd3e0101a33ed6a72388279c33c
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
push:
branches: [main]
pull_request:
branches: [main]
branches: [main, 2.x]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
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
23 changes: 16 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,16 @@ 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)
# TODO(zbarsky): do we need this blank line? Tests pass on OSX without it for me.
#content.add("")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was here to ensure the last line of the file has a trailing newline, but I think the multiline param_file_format is doing it so you're right it's unneeded. And yeah I trust our tests pretty well :)


ctx.actions.write(out, content = content)

return DefaultInfo(files = depset([out]), runfiles = ctx.runfiles([out]))

tar_lib = struct(
Expand Down