Skip to content

Commit

Permalink
fix: add repo mapping to tar archive
Browse files Browse the repository at this point in the history
When using bzlmod, runfiles lookup will fail without it.
  • Loading branch information
steeve committed Sep 15, 2024
1 parent de9fd59 commit 0f5e449
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/private/tar.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,19 @@ def _tar_impl(ctx):
args.add(ctx.file.mtree, format = "@%s")
inputs.append(ctx.file.mtree)

src_runfiles = []
for src in ctx.attr.srcs:
src_di = src[DefaultInfo]
if hasattr(src_di.files_to_run, "repo_mapping_manifest"):
src_runfiles.append(depset(
direct = [src_di.files_to_run.repo_mapping_manifest],
transitive = [src_di.default_runfiles.files],
))
else:
src_runfiles.append(src_di.default_runfiles.files)
ctx.actions.run(
executable = bsdtar.tarinfo.binary,
inputs = depset(direct = inputs, transitive = [bsdtar.default.files] + [
src[DefaultInfo].default_runfiles.files
for src in ctx.attr.srcs
]),
inputs = depset(direct = inputs, transitive = [bsdtar.default.files] + src_runfiles),
outputs = [out],
arguments = [args],
mnemonic = "Tar",
Expand Down Expand Up @@ -234,6 +241,8 @@ def _mtree_impl(ctx):
workspace_name = str(ctx.workspace_name)

content.add(_mtree_line(runfiles_dir, type = "dir"))
if (hasattr(default_info.files_to_run, "repo_mapping_manifest")):
content.add(_mtree_line("{}/_repo_mapping".format(runfiles_dir), type = "file", content = default_info.files_to_run.repo_mapping_manifest.path))
content.add_all(
s.default_runfiles.files,
expand_directories = True,
Expand Down

0 comments on commit 0f5e449

Please sign in to comment.