Skip to content

Commit

Permalink
Add TF wheel compliance verification in Bazel build rule.
Browse files Browse the repository at this point in the history
The compliance check is disabled by default, but can be turned on by `--//tensorflow/tools/pip_package:wheel_compliance=true` option.

PiperOrigin-RevId: 689511666
  • Loading branch information
Google-ML-Automation committed Nov 4, 2024
1 parent 28dd1dd commit a128bdb
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions third_party/tsl/third_party/py/python_wheel_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ def _unpacked_wheel_impl(ctx):
if linker_input.libraries and linker_input.libraries[0].dynamic_library:
lib = linker_input.libraries[0].dynamic_library
libs.append(lib)
wheel = [
w
for w in ctx.files.wheel_rule_outputs
if w.basename.endswith(".whl")
][0]
script = """
{zipper} x {wheel} -d {output}
for lib in {libs}; do
cp $lib {output}/tensorflow
done
""".format(
zipper = ctx.executable.zipper.path,
wheel = ctx.file.wheel.path,
wheel = wheel.path,
output = output_dir.path,
libs = " ".join(["'%s'" % lib.path for lib in libs]),
)
ctx.actions.run_shell(
inputs = [ctx.file.wheel] + libs,
inputs = ctx.files.wheel_rule_outputs + libs,
command = script,
outputs = [output_dir],
tools = [ctx.executable.zipper],
Expand All @@ -34,7 +39,7 @@ def _unpacked_wheel_impl(ctx):
_unpacked_wheel = rule(
implementation = _unpacked_wheel_impl,
attrs = {
"wheel": attr.label(mandatory = True, allow_single_file = True),
"wheel_rule_outputs": attr.label(mandatory = True, allow_files = True),
"zipper": attr.label(
default = Label("@bazel_tools//tools/zip:zipper"),
cfg = "exec",
Expand All @@ -48,7 +53,7 @@ def wheel_library(name, wheel, deps = [], wheel_deps = []):
unpacked_wheel_name = name + "_unpacked_wheel"
_unpacked_wheel(
name = unpacked_wheel_name,
wheel = wheel,
wheel_rule_outputs = wheel,
deps = wheel_deps,
)
native.py_library(
Expand Down

0 comments on commit a128bdb

Please sign in to comment.