Fix p4runtime runtime dependencies when building with Bazel
A convenient macro for packaging together all proto and gRPC libraries
in an OSGi jar is provided. Also re-packaging of gRPC core (to avoid OSGi
split problem) is simplified by depending on a patched fork of grpc-java.
Change-Id: Idb79a5bea8ae0bc57b146bda1fc47a4568d12c60
diff --git a/protocols/grpc/BUILD b/protocols/grpc/BUILD
index e568960..56218f0 100644
--- a/protocols/grpc/BUILD
+++ b/protocols/grpc/BUILD
@@ -1,17 +1,23 @@
+load("//tools/build/bazel:osgi_java_library.bzl", "wrapped_osgi_jar")
BUNDLES = [
- "//protocols/grpc/proto:dummy_java_grpc",
- "//protocols/grpc/proto:dummy_java_proto",
+ "//protocols/grpc/proto:onos-protocols-grpc-proto",
"//protocols/grpc/api:onos-protocols-grpc-api",
"//protocols/grpc/ctl:onos-protocols-grpc-ctl",
- # gRPC dependencies
- "@runtime_grpc_core//jar",
+ # gRPC dependencies (with patched core)
+ ":grpc-core-repkg",
"@runtime_grpc_stub//jar",
"@runtime_grpc_netty//jar",
"@runtime_grpc_auth//jar",
"@runtime_grpc_protobuf//jar",
"@runtime_grpc_protobuf_lite//jar",
"@runtime_protobuf//jar",
+ "@com_google_api_grpc_proto_google_common_protos//jar",
+ "@com_google_errorprone_error_prone_annotations//jar",
+ "@com_google_auth_google_auth_library_credentials//jar",
+ "@io_opencensus_opencensus_api//jar",
+ "@io_opencensus_opencensus_contrib_grpc_metrics//jar",
+ "@com_google_code_gson_gson//jar",
# Lazily adding all netty-related packages.
# Some of them might not be necessary.
"@io_netty_netty//jar",
@@ -28,9 +34,16 @@
onos_app (
app_name = "org.onosproject.protocols.grpc",
- title = "RPC Protocol Subsystem",
+ title = "gRPC Protocol Subsystem",
category = "rotocol",
url = "ttp://onosproject.org",
description = "Exposes APIs to operate with gRPC channels",
included_bundles = BUNDLES,
)
+
+wrapped_osgi_jar(
+ name = "grpc-core-repkg",
+ jar = "@io_grpc_grpc_java//core:core",
+ deps = ["@io_opencensus_opencensus_api//jar"],
+ visibility = ["//visibility:public"],
+)
diff --git a/protocols/grpc/ctl/BUILD b/protocols/grpc/ctl/BUILD
index 2d199ef..a4c063f 100644
--- a/protocols/grpc/ctl/BUILD
+++ b/protocols/grpc/ctl/BUILD
@@ -1,8 +1,9 @@
+COMPILE_DEPS = CORE_DEPS + [
+ "//protocols/grpc/api:onos-protocols-grpc-api",
+ "//protocols/grpc/proto:onos-protocols-grpc-proto",
+ "@io_grpc_grpc_java//core",
+]
+
osgi_jar (
- deps = CORE_DEPS + [
- "//protocols/grpc/api:onos-protocols-grpc-api",
- "//protocols/grpc/proto:dummy_java_grpc",
- "//protocols/grpc/proto:dummy_java_proto",
- "@io_grpc_grpc_java//core"
- ],
+ deps = COMPILE_DEPS,
)
diff --git a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
index 464cb85..fb87571 100644
--- a/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
+++ b/protocols/grpc/ctl/src/main/java/org/onosproject/grpc/ctl/GrpcControllerImpl.java
@@ -43,8 +43,8 @@
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.grpc.api.GrpcChannelId;
import org.onosproject.grpc.api.GrpcController;
-import org.onosproject.grpc.ctl.dummy.Dummy;
-import org.onosproject.grpc.ctl.dummy.DummyServiceGrpc;
+import org.onosproject.grpc.proto.dummy.Dummy;
+import org.onosproject.grpc.proto.dummy.DummyServiceGrpc;
import org.onosproject.net.DeviceId;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
diff --git a/protocols/grpc/proto/BUILD b/protocols/grpc/proto/BUILD
index bebc0ef..fb4c33c 100644
--- a/protocols/grpc/proto/BUILD
+++ b/protocols/grpc/proto/BUILD
@@ -1,36 +1,8 @@
-load("//tools/build/bazel:osgi_java_library.bzl", "wrapped_osgi_jar")
-load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
+load("//tools/build/bazel:osgi_java_library.bzl", "osgi_proto_jar")
-wrapped_osgi_jar(
- name = "dummy_java_grpc",
- jar = ":dummy_java_grpc_native",
- deps = [
- "@io_grpc_grpc_java//stub",
- "@io_grpc_grpc_java//core",
- "@io_grpc_grpc_java//protobuf"
- ],
- visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
- name = "dummy_java_proto",
- jar = ":dummy_java_proto_native",
- deps = [
- "@com_google_protobuf//:protobuf_java",
- ],
- visibility = ["//visibility:public"],
-)
-
-java_proto_library(
- name = "dummy_java_proto_native",
- deps = [":dummy_proto"],
- visibility = ["//visibility:public"],
-)
-
-java_grpc_library(
- name = "dummy_java_grpc_native",
- srcs = [":dummy_proto"],
- deps = [":dummy_java_proto_native"],
+osgi_proto_jar(
+ proto_libs = [":dummy_proto"],
+ grpc_proto_lib = ":dummy_proto",
)
proto_library(
diff --git a/protocols/grpc/proto/dummy.proto b/protocols/grpc/proto/dummy.proto
index 74268df..003f403 100644
--- a/protocols/grpc/proto/dummy.proto
+++ b/protocols/grpc/proto/dummy.proto
@@ -1,6 +1,6 @@
syntax = "proto3";
-option java_package = "org.onosproject.grpc.ctl.dummy";
+option java_package = "org.onosproject.grpc.proto.dummy";
package dummy;
@@ -10,4 +10,4 @@
}
message DummyMessageThatNoOneWouldReallyUse {
-}
\ No newline at end of file
+}
diff --git a/protocols/p4runtime/BUILD b/protocols/p4runtime/BUILD
index 407aa46..48e4708 100644
--- a/protocols/p4runtime/BUILD
+++ b/protocols/p4runtime/BUILD
@@ -2,13 +2,7 @@
"//protocols/p4runtime/api:onos-protocols-p4runtime-api",
"//protocols/p4runtime/ctl:onos-protocols-p4runtime-ctl",
"//protocols/p4runtime/model:onos-protocols-p4runtime-model",
- "//protocols/p4runtime/proto:p4runtime_java_grpc",
- "//protocols/p4runtime/proto:p4config_java_proto",
- "//protocols/p4runtime/proto:p4data_java_proto",
- "//protocols/p4runtime/proto:p4info_java_proto",
- "//protocols/p4runtime/proto:p4runtime_java_proto",
- "//protocols/p4runtime/proto:p4types_java_proto",
- "//protocols/p4runtime/proto:status_java_proto",
+ "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto",
]
onos_app(
diff --git a/protocols/p4runtime/ctl/BUILD b/protocols/p4runtime/ctl/BUILD
index 13554c7..e060275 100644
--- a/protocols/p4runtime/ctl/BUILD
+++ b/protocols/p4runtime/ctl/BUILD
@@ -2,18 +2,12 @@
"//core/store/serializers:onos-core-serializers",
"//protocols/grpc/api:onos-protocols-grpc-api",
"//protocols/p4runtime/api:onos-protocols-p4runtime-api",
- "//protocols/p4runtime/proto:p4config_java_proto",
- "//protocols/p4runtime/proto:p4data_java_proto",
- "//protocols/p4runtime/proto:p4info_java_proto",
- "//protocols/p4runtime/proto:p4runtime_java_grpc",
- "//protocols/p4runtime/proto:p4runtime_java_proto",
- "//protocols/p4runtime/proto:status_java_proto",
+ "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto",
"@com_google_protobuf//:protobuf_java",
- "@io_grpc_grpc_java//context",
- "@io_grpc_grpc_java//core",
+ "//protocols/grpc:grpc-core-repkg",
"@io_grpc_grpc_java//netty",
"@io_grpc_grpc_java//stub",
- "@io_grpc_grpc_java_core_repkg//:internal",
+ "@com_google_api_grpc_proto_google_common_protos//jar",
]
TEST_DEPS = TEST + [
diff --git a/protocols/p4runtime/model/BUILD b/protocols/p4runtime/model/BUILD
index 1e7b506..619d8ee 100644
--- a/protocols/p4runtime/model/BUILD
+++ b/protocols/p4runtime/model/BUILD
@@ -1,5 +1,5 @@
COMPILE_DEPS = CORE_DEPS + [
- "//protocols/p4runtime/proto:p4info_java_proto",
+ "//protocols/p4runtime/proto:onos-protocols-p4runtime-proto",
"@com_google_protobuf//:protobuf_java",
]
diff --git a/protocols/p4runtime/proto/BUILD b/protocols/p4runtime/proto/BUILD
index 4c99b0d..3a9435c 100644
--- a/protocols/p4runtime/proto/BUILD
+++ b/protocols/p4runtime/proto/BUILD
@@ -1,61 +1,19 @@
-load("//tools/build/bazel:osgi_java_library.bzl", "wrapped_osgi_jar")
-load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
+load("//tools/build/bazel:osgi_java_library.bzl", "osgi_proto_jar")
-GRPC_DEPS = [
- "@io_grpc_grpc_java//stub",
- "@io_grpc_grpc_java//core",
- "@io_grpc_grpc_java//protobuf",
+PROTOS = [
+ "@com_github_p4lang_p4runtime//:" + p for p in [
+ "p4info_proto",
+ "p4types_proto",
+ "p4data_proto",
+ "p4runtime_proto",
+]] + [
+ "@com_github_p4lang_pi//:p4config_proto"
]
-PROTOBUF_DEPS = [
- "@com_google_protobuf//:protobuf_java",
-]
-
-wrapped_osgi_jar(
- name = "p4config_java_proto",
- jar = "@com_github_p4lang_pi//:p4config_java_proto_native",
- deps = PROTOBUF_DEPS,
- visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
- name = "p4data_java_proto",
- jar = "@com_github_p4lang_p4runtime//:p4data_java_proto_native",
- deps = PROTOBUF_DEPS,
- visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
- name = "p4types_java_proto",
- jar = "@com_github_p4lang_p4runtime//:p4types_java_proto_native",
- deps = PROTOBUF_DEPS,
- visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
- name = "p4info_java_proto",
- jar = "@com_github_p4lang_p4runtime//:p4info_java_proto_native",
- deps = PROTOBUF_DEPS,
- visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
- name = "p4runtime_java_proto",
- jar = "@com_github_p4lang_p4runtime//:p4runtime_java_proto_native",
- deps = PROTOBUF_DEPS,
- visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
- name = "p4runtime_java_grpc",
- jar = "@com_github_p4lang_p4runtime//:p4runtime_java_grpc_native",
- deps = GRPC_DEPS,
- visibility = ["//visibility:public"],
-)
-
-wrapped_osgi_jar(
- name = "status_java_proto",
- jar = "@com_github_googleapis//:status_java_proto_native",
- deps = PROTOBUF_DEPS,
- visibility = ["//visibility:public"],
+osgi_proto_jar(
+ proto_libs = PROTOS,
+ grpc_proto_lib = "@com_github_p4lang_p4runtime//:p4runtime_proto",
+ deps = [
+ "@com_google_api_grpc_proto_google_common_protos//jar",
+ ]
)