Use the python flatbuffers library with the correct file paths
PiperOrigin-RevId: 334662368 Change-Id: I648738fc64997b4b21afffcf125732f0d13b45de
This commit is contained in:
parent
11fc1489d0
commit
f98fc1387d
third_party/flatbuffers
20
third_party/flatbuffers/BUILD.bazel
vendored
20
third_party/flatbuffers/BUILD.bazel
vendored
@ -1,4 +1,5 @@
|
|||||||
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
|
load("@build_bazel_rules_android//android:rules.bzl", "android_library")
|
||||||
|
load(":build_defs.bzl", "flatbuffer_py_strip_prefix_srcs")
|
||||||
|
|
||||||
package(default_visibility = ["//visibility:public"])
|
package(default_visibility = ["//visibility:public"])
|
||||||
|
|
||||||
@ -102,8 +103,8 @@ cc_library(
|
|||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
flatbuffer_py_strip_prefix_srcs(
|
||||||
name = "runtime_py_srcs",
|
name = "flatbuffer_py_strip_prefix",
|
||||||
srcs = [
|
srcs = [
|
||||||
"python/flatbuffers/__init__.py",
|
"python/flatbuffers/__init__.py",
|
||||||
"python/flatbuffers/builder.py",
|
"python/flatbuffers/builder.py",
|
||||||
@ -114,6 +115,21 @@ filegroup(
|
|||||||
"python/flatbuffers/table.py",
|
"python/flatbuffers/table.py",
|
||||||
"python/flatbuffers/util.py",
|
"python/flatbuffers/util.py",
|
||||||
],
|
],
|
||||||
|
strip_prefix = "python/flatbuffers/",
|
||||||
|
)
|
||||||
|
|
||||||
|
filegroup(
|
||||||
|
name = "runtime_py_srcs",
|
||||||
|
srcs = [
|
||||||
|
"__init__.py",
|
||||||
|
"builder.py",
|
||||||
|
"compat.py",
|
||||||
|
"encode.py",
|
||||||
|
"number_types.py",
|
||||||
|
"packer.py",
|
||||||
|
"table.py",
|
||||||
|
"util.py",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
py_library(
|
py_library(
|
||||||
|
28
third_party/flatbuffers/build_defs.bzl
vendored
28
third_party/flatbuffers/build_defs.bzl
vendored
@ -361,18 +361,30 @@ _gen_flatbuffer_srcs = rule(
|
|||||||
output_to_genfiles = True,
|
output_to_genfiles = True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def flatbuffer_py_strip_prefix_srcs(name, srcs = [], strip_prefix = ""):
|
||||||
|
"""Strips path prefix.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
name: Rule name. (required)
|
||||||
|
srcs: Source .py files. (required)
|
||||||
|
strip_prefix: Path that needs to be stripped from the srcs filepaths. (required)
|
||||||
|
"""
|
||||||
|
for src in srcs:
|
||||||
|
native.genrule(
|
||||||
|
name = name + "_" + src.replace(".", "_").replace("/", "_"),
|
||||||
|
srcs = [src],
|
||||||
|
outs = [src.replace(strip_prefix, "")],
|
||||||
|
cmd = "cp $< $@",
|
||||||
|
)
|
||||||
|
|
||||||
def _concat_flatbuffer_py_srcs_impl(ctx):
|
def _concat_flatbuffer_py_srcs_impl(ctx):
|
||||||
# Merge all generated python files. The files are concatenated and the
|
# Merge all generated python files.
|
||||||
# import statements are removed. Finally we import the flatbuffer runtime
|
command = "find '%s' -name '*.py' -exec cat {} + | sed '/import flatbuffers/d'"
|
||||||
# library.
|
command += " | sed '1s/^/import flatbuffers\\'$'\\n/' > %s"
|
||||||
ctx.actions.run_shell(
|
ctx.actions.run_shell(
|
||||||
inputs = ctx.attr.deps[0].files,
|
inputs = ctx.attr.deps[0].files,
|
||||||
outputs = [ctx.outputs.out],
|
outputs = [ctx.outputs.out],
|
||||||
command = (
|
command = command % (
|
||||||
"find '%s' -name '*.py' -exec cat {} + |" +
|
|
||||||
"sed 's/from flatbuffers.compat import import_numpy/import numpy as np' |" +
|
|
||||||
"sed '/np = import_numpy()/d' > %s"
|
|
||||||
) % (
|
|
||||||
ctx.attr.deps[0].files.to_list()[0].path,
|
ctx.attr.deps[0].files.to_list()[0].path,
|
||||||
ctx.outputs.out.path,
|
ctx.outputs.out.path,
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user