Project import generated by Copybara.
GitOrigin-RevId: afeb9cf5a8c069c0a566d16e1622bbb086170e4d
This commit is contained in:
@@ -9,31 +9,44 @@ def provided_args(**kwargs):
|
||||
"""Returns the keyword arguments omitting None arguments."""
|
||||
return {k: v for k, v in kwargs.items() if v != None}
|
||||
|
||||
def allowed_args(**kwargs):
|
||||
"""Returns the keyword arguments allowed for proto_library().
|
||||
def replace_suffix(string, old, new):
|
||||
"""Returns a string with an old suffix replaced by a new suffix."""
|
||||
return string.endswith(old) and string[:-len(old)] + new or string
|
||||
|
||||
def replace_deps(deps, old, new, drop_google_protobuf = True):
|
||||
"""Returns deps with an old suffix replaced by a new suffix.
|
||||
|
||||
Args:
|
||||
**kwargs: the specified keyword arguments.
|
||||
deps: the specified dep targets.
|
||||
old: the suffix to remove.
|
||||
new: the suffix to insert.
|
||||
drop_google_protobuf: if true, omit google/protobuf deps.
|
||||
Returns:
|
||||
the allowed keyword arguments.
|
||||
the modified dep targets.
|
||||
"""
|
||||
result = dict(kwargs)
|
||||
result.pop("cc_api_version", None)
|
||||
return result
|
||||
if drop_google_protobuf:
|
||||
deps = [dep for dep in deps if not dep.startswith("@com_google_protobuf//")]
|
||||
deps = [replace_suffix(dep, "any_proto", "cc_wkt_protos") for dep in deps]
|
||||
deps = [replace_suffix(dep, old, new) for dep in deps]
|
||||
return deps
|
||||
|
||||
# TODO: load this macro from a common helper file.
|
||||
def mediapipe_proto_library(
|
||||
name,
|
||||
srcs,
|
||||
deps = [],
|
||||
exports = None,
|
||||
visibility = None,
|
||||
testonly = 0,
|
||||
compatible_with = [],
|
||||
testonly = None,
|
||||
compatible_with = None,
|
||||
def_proto = True,
|
||||
def_cc_proto = True,
|
||||
def_py_proto = True,
|
||||
def_java_lite_proto = True,
|
||||
def_portable_proto = True,
|
||||
def_objc_proto = True,
|
||||
def_java_proto = True,
|
||||
def_jspb_proto = True,
|
||||
portable_deps = None):
|
||||
"""Defines the proto_library targets needed for all mediapipe platforms.
|
||||
|
||||
@@ -41,6 +54,7 @@ def mediapipe_proto_library(
|
||||
name: the new proto_library target name.
|
||||
srcs: the ".proto" source files to compile.
|
||||
deps: the proto_library targets for all referenced protobufs.
|
||||
exports: deps that are published with "import public".
|
||||
portable_deps: the portable_proto_library targets for all referenced protobufs.
|
||||
visibility: visibility of this target.
|
||||
testonly: true means the proto can be used for testing only.
|
||||
@@ -50,27 +64,30 @@ def mediapipe_proto_library(
|
||||
def_py_proto: define the py_proto_library target
|
||||
def_java_lite_proto: define the java_lite_proto_library target
|
||||
def_portable_proto: define the portable_proto_library target
|
||||
def_objc_proto: define the objc_proto_library target
|
||||
def_java_proto: define the java_proto_library target
|
||||
def_jspb_proto: define the jspb_proto_library target
|
||||
"""
|
||||
_ignore = [def_portable_proto, portable_deps]
|
||||
_ignore = [def_portable_proto, def_objc_proto, def_java_proto, def_jspb_proto, portable_deps]
|
||||
|
||||
# The proto_library targets for the compiled ".proto" source files.
|
||||
proto_deps = [":" + name]
|
||||
|
||||
if def_proto:
|
||||
native.proto_library(**allowed_args(**provided_args(
|
||||
native.proto_library(**provided_args(
|
||||
name = name,
|
||||
srcs = srcs,
|
||||
deps = deps,
|
||||
exports = exports,
|
||||
visibility = visibility,
|
||||
testonly = testonly,
|
||||
cc_api_version = 2,
|
||||
compatible_with = compatible_with,
|
||||
)))
|
||||
))
|
||||
|
||||
if def_cc_proto:
|
||||
cc_deps = [dep.replace("_proto", "_cc_proto") for dep in deps]
|
||||
cc_deps = replace_deps(deps, "_proto", "_cc_proto", False)
|
||||
mediapipe_cc_proto_library(**provided_args(
|
||||
name = name.replace("_proto", "_cc_proto"),
|
||||
name = replace_suffix(name, "_proto", "_cc_proto"),
|
||||
srcs = srcs,
|
||||
deps = proto_deps,
|
||||
cc_deps = cc_deps,
|
||||
@@ -79,22 +96,25 @@ def mediapipe_proto_library(
|
||||
))
|
||||
|
||||
if def_py_proto:
|
||||
py_deps = [dep.replace("_proto", "_py_pb2") for dep in deps]
|
||||
py_deps = replace_deps(deps, "_proto", "_py_pb2")
|
||||
mediapipe_py_proto_library(**provided_args(
|
||||
name = name.replace("_proto", "_py_pb2"),
|
||||
name = replace_suffix(name, "_proto", "_py_pb2"),
|
||||
srcs = srcs,
|
||||
proto_deps = proto_deps,
|
||||
py_proto_deps = py_deps,
|
||||
visibility = visibility,
|
||||
api_version = 2,
|
||||
visibility = visibility,
|
||||
testonly = testonly,
|
||||
))
|
||||
|
||||
if def_java_lite_proto:
|
||||
native.java_lite_proto_library(**provided_args(
|
||||
name = name.replace("_proto", "_java_proto_lite"),
|
||||
name = replace_suffix(name, "_proto", "_java_proto_lite"),
|
||||
deps = proto_deps,
|
||||
strict_deps = 0,
|
||||
visibility = visibility,
|
||||
testonly = testonly,
|
||||
compatible_with = compatible_with,
|
||||
))
|
||||
|
||||
def mediapipe_py_proto_library(
|
||||
@@ -103,14 +123,18 @@ def mediapipe_py_proto_library(
|
||||
visibility,
|
||||
py_proto_deps = [],
|
||||
proto_deps = None,
|
||||
api_version = None):
|
||||
api_version = None,
|
||||
testonly = 0):
|
||||
"""Generate py_proto_library for mediapipe open source version.
|
||||
|
||||
Args:
|
||||
name: the name of the py_proto_library.
|
||||
api_version: api version for bazel use only.
|
||||
srcs: the .proto files of the py_proto_library for Bazel use.
|
||||
visibility: visibility of this target.
|
||||
py_proto_deps: a list of dependency labels for Bazel use; must be py_proto_library.
|
||||
proto_deps: a list of dependency labels for bazel use.
|
||||
testonly: test only proto or not.
|
||||
"""
|
||||
_ignore = [api_version, proto_deps]
|
||||
py_proto_library(**provided_args(
|
||||
@@ -120,6 +144,7 @@ def mediapipe_py_proto_library(
|
||||
default_runtime = "@com_google_protobuf//:protobuf_python",
|
||||
protoc = "@com_google_protobuf//:protoc",
|
||||
deps = py_proto_deps + ["@com_google_protobuf//:protobuf_python"],
|
||||
testonly = testonly,
|
||||
))
|
||||
|
||||
def mediapipe_cc_proto_library(name, srcs, visibility, deps = [], cc_deps = [], testonly = 0):
|
||||
|
||||
Reference in New Issue
Block a user