Skip to content

Commit

Permalink
zip_file: upgrade to fix bazel incompatibility
Browse files Browse the repository at this point in the history
Multiple changes rolled out to Bazel break our compatibility with the
latest version:
 - bazelbuild/bazel#5817
 - bazelbuild/bazel#5818
 - bazelbuild/bazel#5825

Update our version of zip_file to be compatible with these changes.
  • Loading branch information
cryslith authored and celskeggs committed Sep 3, 2019
1 parent cf47cbf commit cdaa056
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions platform/bazel/zip_file.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def collect_runfiles(targets):
Returns:
A list of Bazel files.
"""
data = depset()
data = []
for target in targets:
if hasattr(target, "runfiles"):
data += target.runfiles.files
Expand All @@ -156,18 +156,16 @@ def collect_runfiles(targets):
data += target.data_runfiles.files
if hasattr(target, "default_runfiles"):
data += target.default_runfiles.files
return data
return depset(data)

def _zip_file(ctx):
"""Implementation of zip_file() rule."""
for s, d in ctx.attr.mappings.items():
if (s.startswith("/") or s.endswith("/") or
d.startswith("/") or d.endswith("/")):
fail("mappings should not begin or end with slash")
srcs = depset()
srcs += ctx.files.srcs
srcs += ctx.files.data
srcs += collect_runfiles(ctx.attr.data)
srcs = depset(ctx.files.srcs + ctx.files.data,
transitive=[collect_runfiles(ctx.attr.data)]).to_list()
mapped = _map_sources(ctx, srcs, ctx.attr.mappings)
cmd = [
"#!/bin/sh",
Expand Down Expand Up @@ -203,16 +201,12 @@ def _zip_file(ctx):
'cd "${repo}"',
'rm -rf "${tmp}"',
]
if hasattr(ctx, "bin_dir"):
script = ctx.new_file(ctx.bin_dir, "%s.sh" % ctx.label.name)
else:
# TODO(kchodorow): remove this once Bazel 4.0+ is required.
script = ctx.new_file(ctx.configuration.bin_dir, "%s.sh" % ctx.label.name)
ctx.file_action(output = script, content = "\n".join(cmd), executable = True)
script = ctx.actions.declare_file("%s.sh" % ctx.label.name)
ctx.actions.write(output = script, content = "\n".join(cmd), is_executable = True)
inputs = [ctx.file._zipper]
inputs += [dep.zip_file for dep in ctx.attr.deps]
inputs += srcs.to_list()
ctx.action(
inputs += srcs
ctx.actions.run(
inputs = inputs,
outputs = [ctx.outputs.out],
executable = script,
Expand Down Expand Up @@ -281,6 +275,6 @@ zip_file = rule(
"deps": attr.label_list(providers = ["zip_file"]),
"exclude": attr.string_list(),
"mappings": attr.string_dict(),
"_zipper": attr.label(default = Label(ZIPPER), single_file = True),
"_zipper": attr.label(default = Label(ZIPPER), allow_single_file = True),
},
)

0 comments on commit cdaa056

Please sign in to comment.