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
This commit is contained in:
Carmelo Cascone 2018-08-10 12:19:47 -07:00 committed by Thomas Vachuska
parent 0ed6443127
commit 6a1ae71db1
24 changed files with 386 additions and 237 deletions

View File

@ -11,13 +11,13 @@ generate_grpc()
load("@io_grpc_grpc_java//:repositories.bzl", "grpc_java_repositories")
grpc_java_repositories(
omit_com_google_api_grpc_google_common_protos = False,
omit_com_google_errorprone_error_prone_annotations = False,
omit_javax_annotation = False,
omit_com_google_auth_google_auth_library_credentials = False,
omit_io_opencensus_api = False,
omit_io_opencensus_grpc_metrics = False,
omit_com_google_api_grpc_google_common_protos = True,
omit_com_google_errorprone_error_prone_annotations = True,
omit_com_google_auth_google_auth_library_credentials = True,
omit_io_opencensus_api = True,
omit_io_opencensus_grpc_metrics = True,
omit_com_google_code_findbugs_jsr305 = True,
omit_com_google_code_gson = True,
omit_com_google_guava = True,
@ -43,9 +43,6 @@ grpc_java_repositories(
omit_org_apache_commons_lang3 = True
)
load("//tools/build/bazel:googleapis_workspace.bzl", "generate_googleapis")
generate_googleapis()
load("//tools/build/bazel:p4lang_workspace.bzl", "generate_p4lang")
generate_p4lang()

View File

@ -21,7 +21,10 @@ osgi_jar(
deps = COMPILE_DEPS,
# FIXME: enable building other classes as soon as we implement BUILD for
# protocols/bmv2 (based on Thrift)
srcs = ["src/main/java/org/onosproject/drivers/bmv2/Bmv2PipelineProgrammable.java"],
srcs = [
"src/main/java/org/onosproject/drivers/bmv2/Bmv2DriversLoader.java",
"src/main/java/org/onosproject/drivers/bmv2/Bmv2PipelineProgrammable.java",
],
resources_root = "src/main/resources",
resources = glob(["src/main/resources/**"]),
)

View File

@ -7,7 +7,7 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [
"//protocols/gnmi/stub:gnmi_java_grpc",
"//protocols/gnmi/stub:gnmi_java_proto",
"//protocols/grpc/api:onos-protocols-grpc-api",
"//protocols/grpc/proto:dummy_java_grpc",
"//protocols/grpc/proto:onos-protocols-grpc-proto",
]
BUNDLES = [

View File

@ -1,4 +1,4 @@
# ***** This file was auto-generated at Fri, 10 Aug 2018 17:37:37 GMT. Do not edit this file manually. *****
# ***** This file was auto-generated at Fri, 10 Aug 2018 23:10:43 GMT. Do not edit this file manually. *****
# ***** Use onos-lib-gen *****
pass_thru_pom(
@ -1480,6 +1480,51 @@ remote_jar (
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'com_google_api_grpc_proto_google_common_protos',
out = 'proto-google-common-protos-1.0.0.jar',
url = 'mvn:com.google.api.grpc:proto-google-common-protos:jar:1.0.0',
sha1 = '86f070507e28b930e50d218ee5b6788ef0dd05e6',
maven_coords = 'com.google.api.grpc:proto-google-common-protos:jar:NON-OSGI:1.0.0',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'com_google_errorprone_error_prone_annotations',
out = 'error_prone_annotations-2.1.2.jar',
url = 'mvn:com.google.errorprone:error_prone_annotations:jar:2.1.2',
sha1 = '6dcc08f90f678ac33e5ef78c3c752b6f59e63e0c',
maven_coords = 'com.google.errorprone:error_prone_annotations:jar:NON-OSGI:2.1.2',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'com_google_auth_google_auth_library_credentials',
out = 'google-auth-library-credentials-0.9.0.jar',
url = 'mvn:com.google.auth:google-auth-library-credentials:jar:0.9.0',
sha1 = '8e2b181feff6005c9cbc6f5c1c1e2d3ec9138d46',
maven_coords = 'com.google.auth:google-auth-library-credentials:jar:NON-OSGI:0.9.0',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'io_opencensus_opencensus_api',
out = 'opencensus-api-0.12.3.jar',
url = 'mvn:io.opencensus:opencensus-api:jar:0.12.3',
sha1 = '743f074095f29aa985517299545e72cc99c87de0',
maven_coords = 'io.opencensus:opencensus-api:jar:NON-OSGI:0.12.3',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'io_opencensus_opencensus_contrib_grpc_metrics',
out = 'opencensus-contrib-grpc-metrics-0.12.3.jar',
url = 'mvn:io.opencensus:opencensus-contrib-grpc-metrics:jar:0.12.3',
sha1 = 'a4c7ff238a91b901c8b459889b6d0d7a9d889b4d',
maven_coords = 'io.opencensus:opencensus-contrib-grpc-metrics:jar:NON-OSGI:0.12.3',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'openstack4j-core',
out = 'openstack4j-core-3.1.0.jar',
@ -1750,6 +1795,15 @@ remote_jar (
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'runtime-grpc-context',
out = 'grpc-context-1.14.0.jar',
url = 'mvn:io.grpc:grpc-context:jar:1.14.0',
sha1 = '77252b5f926875891aaae5629e6ab2ef968cd6c6',
maven_coords = 'io.grpc:grpc-context:jar:NON-OSGI:1.14.0',
visibility = [ 'PUBLIC' ],
)
remote_jar (
name = 'runtime-grpc-stub',
out = 'grpc-stub-1.14.0.jar',

View File

@ -283,6 +283,13 @@
"json": "mvn:org.json:json:jar:20090211",
"engine.io-client": "mvn:io.socket:engine.io-client:jar:0.8.3",
// grpc related jars
"com_google_api_grpc_proto_google_common_protos": "mvn:com.google.api.grpc:proto-google-common-protos:1.0.0",
"com_google_errorprone_error_prone_annotations": "mvn:com.google.errorprone:error_prone_annotations:2.1.2",
"com_google_auth_google_auth_library_credentials": "mvn:com.google.auth:google-auth-library-credentials:0.9.0",
"io_opencensus_opencensus_api": "mvn:io.opencensus:opencensus-api:0.12.3",
"io_opencensus_opencensus_contrib_grpc_metrics": "mvn:io.opencensus:opencensus-contrib-grpc-metrics:0.12.3",
// Openstack4j related jars
"openstack4j-core": "mvn:org.pacesys:openstack4j-core:3.1.0",
"openstack4j-http-connector": "mvn:org.pacesys.openstack4j.connectors:openstack4j-http-connector:3.1.0",
@ -318,6 +325,7 @@
// Included merely for packaging purposes into run-time.
"runtime-grpc-core":"mvn:io.grpc:grpc-core:1.14.0",
"runtime-grpc-context":"mvn:io.grpc:grpc-context:1.14.0",
"runtime-grpc-stub":"mvn:io.grpc:grpc-stub:1.14.0",
"runtime-grpc-netty":"mvn:io.grpc:grpc-netty:1.14.0",
"runtime-grpc-auth":"mvn:io.grpc:grpc-auth:1.14.0",

View File

@ -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 @@ BUNDLES = [
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"],
)

View File

@ -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,
)

View File

@ -43,8 +43,8 @@ import org.onlab.util.Tools;
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;

View File

@ -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(

View File

@ -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 @@ service DummyService {
}
message DummyMessageThatNoOneWouldReallyUse {
}
}

View File

@ -2,13 +2,7 @@ BUNDLES = [
"//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(

View File

@ -2,18 +2,12 @@ COMPILE_DEPS = CORE_DEPS + KRYO + [
"//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 + [

View File

@ -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",
]

View File

@ -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",
]
)

View File

@ -1,4 +1,4 @@
# ***** This file was auto-generated at Fri, 10 Aug 2018 17:37:35 GMT. Do not edit this file manually. *****
# ***** This file was auto-generated at Fri, 10 Aug 2018 23:10:39 GMT. Do not edit this file manually. *****
# ***** Use onos-lib-gen *****
load("//tools/build/bazel:variables.bzl", "ONOS_GROUP_ID", "ONOS_VERSION")
@ -979,6 +979,36 @@ def generated_maven_jars():
sha1 = "854b49396e1e9f9bb0ab025062ddb49c4ed65ca1",
)
native.maven_jar(
name = "com_google_api_grpc_proto_google_common_protos",
artifact = "com.google.api.grpc:proto-google-common-protos:1.0.0",
sha1 = "86f070507e28b930e50d218ee5b6788ef0dd05e6",
)
native.maven_jar(
name = "com_google_errorprone_error_prone_annotations",
artifact = "com.google.errorprone:error_prone_annotations:2.1.2",
sha1 = "6dcc08f90f678ac33e5ef78c3c752b6f59e63e0c",
)
native.maven_jar(
name = "com_google_auth_google_auth_library_credentials",
artifact = "com.google.auth:google-auth-library-credentials:0.9.0",
sha1 = "8e2b181feff6005c9cbc6f5c1c1e2d3ec9138d46",
)
native.maven_jar(
name = "io_opencensus_opencensus_api",
artifact = "io.opencensus:opencensus-api:0.12.3",
sha1 = "743f074095f29aa985517299545e72cc99c87de0",
)
native.maven_jar(
name = "io_opencensus_opencensus_contrib_grpc_metrics",
artifact = "io.opencensus:opencensus-contrib-grpc-metrics:0.12.3",
sha1 = "a4c7ff238a91b901c8b459889b6d0d7a9d889b4d",
)
native.maven_jar(
name = "openstack4j_core",
artifact = "org.pacesys:openstack4j-core:3.1.0",
@ -1159,6 +1189,12 @@ def generated_maven_jars():
sha1 = "526e5be291c96e248789d769c108a084febda07f",
)
native.maven_jar(
name = "runtime_grpc_context",
artifact = "io.grpc:grpc-context:1.14.0",
sha1 = "77252b5f926875891aaae5629e6ab2ef968cd6c6",
)
native.maven_jar(
name = "runtime_grpc_stub",
artifact = "io.grpc:grpc-stub:1.14.0",
@ -2120,6 +2156,36 @@ def generated_java_libraries():
exports = ["@engine_io_client//jar"],
)
native.java_library(
name = "com_google_api_grpc_proto_google_common_protos",
visibility = ["//visibility:public"],
exports = ["@com_google_api_grpc_proto_google_common_protos//jar"],
)
native.java_library(
name = "com_google_errorprone_error_prone_annotations",
visibility = ["//visibility:public"],
exports = ["@com_google_errorprone_error_prone_annotations//jar"],
)
native.java_library(
name = "com_google_auth_google_auth_library_credentials",
visibility = ["//visibility:public"],
exports = ["@com_google_auth_google_auth_library_credentials//jar"],
)
native.java_library(
name = "io_opencensus_opencensus_api",
visibility = ["//visibility:public"],
exports = ["@io_opencensus_opencensus_api//jar"],
)
native.java_library(
name = "io_opencensus_opencensus_contrib_grpc_metrics",
visibility = ["//visibility:public"],
exports = ["@io_opencensus_opencensus_contrib_grpc_metrics//jar"],
)
native.java_library(
name = "openstack4j_core",
visibility = ["//visibility:public"],
@ -2300,6 +2366,12 @@ def generated_java_libraries():
exports = ["@runtime_grpc_core//jar"],
)
native.java_library(
name = "runtime_grpc_context",
visibility = ["//visibility:public"],
exports = ["@runtime_grpc_context//jar"],
)
native.java_library(
name = "runtime_grpc_stub",
visibility = ["//visibility:public"],
@ -2568,6 +2640,11 @@ artifact_map["@mibs_rfc//jar"] = "mvn:org.onosproject:mibbler-mibs-rfc:jar:1.0-2
artifact_map["@io_socket_client//jar"] = "mvn:io.socket:socket.io-client:jar:NON-OSGI:0.8.3"
artifact_map["@json//jar"] = "mvn:org.json:json:jar:NON-OSGI:20090211"
artifact_map["@engine_io_client//jar"] = "mvn:io.socket:engine.io-client:jar:NON-OSGI:0.8.3"
artifact_map["@com_google_api_grpc_proto_google_common_protos//jar"] = "mvn:com.google.api.grpc:proto-google-common-protos:jar:NON-OSGI:1.0.0"
artifact_map["@com_google_errorprone_error_prone_annotations//jar"] = "mvn:com.google.errorprone:error_prone_annotations:jar:NON-OSGI:2.1.2"
artifact_map["@com_google_auth_google_auth_library_credentials//jar"] = "mvn:com.google.auth:google-auth-library-credentials:jar:NON-OSGI:0.9.0"
artifact_map["@io_opencensus_opencensus_api//jar"] = "mvn:io.opencensus:opencensus-api:jar:NON-OSGI:0.12.3"
artifact_map["@io_opencensus_opencensus_contrib_grpc_metrics//jar"] = "mvn:io.opencensus:opencensus-contrib-grpc-metrics:jar:NON-OSGI:0.12.3"
artifact_map["@openstack4j_core//jar"] = "mvn:org.pacesys:openstack4j-core:jar:3.1.0"
artifact_map["@openstack4j_http_connector//jar"] = "mvn:org.pacesys.openstack4j.connectors:openstack4j-http-connector:jar:3.1.0"
artifact_map["@openstack4j_httpclient//jar"] = "mvn:org.pacesys.openstack4j.connectors:openstack4j-httpclient:jar:3.1.0"
@ -2598,6 +2675,7 @@ artifact_map["@concurrent_hashmap//jar"] = "mvn:com.googlecode.concurrentlinkedh
artifact_map["@gnu_idn//jar"] = "mvn:org.gnu.inet:libidn:jar:NON-OSGI:1.15"
artifact_map["@sigar//jar"] = "mvn:org.knowhowlab.osgi:sigar:jar:1.6.5_01"
artifact_map["@runtime_grpc_core//jar"] = "mvn:io.grpc:grpc-core:jar:NON-OSGI:1.14.0"
artifact_map["@runtime_grpc_context//jar"] = "mvn:io.grpc:grpc-context:jar:NON-OSGI:1.14.0"
artifact_map["@runtime_grpc_stub//jar"] = "mvn:io.grpc:grpc-stub:jar:NON-OSGI:1.14.0"
artifact_map["@runtime_grpc_netty//jar"] = "mvn:io.grpc:grpc-netty:jar:NON-OSGI:1.14.0"
artifact_map["@runtime_grpc_auth//jar"] = "mvn:io.grpc:grpc-auth:jar:NON-OSGI:1.14.0"

View File

@ -1,12 +1,6 @@
package(default_visibility = [ "//visibility:public" ])
proto_library(
name = "status_proto",
srcs = ["google/rpc/status.proto"],
deps = ["@com_google_protobuf//:any_proto"]
)
java_proto_library(
name = "status_java_proto_native",
deps = [":status_proto"],
deps = ["@com_google_protobuf//:any_proto"],
visibility = [ "//visibility:public" ],
)

View File

@ -1,13 +0,0 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
COMMIT = "37cc0e5acae50ee91f00827a7010c3b07dfa5311"
SHA = "17d023f48ea290f25edaf25a967973b5a42ce6d71b1570862f302d95aa8b9f77"
def generate_googleapis():
http_archive(
name = "com_github_googleapis",
urls = ["https://github.com/googleapis/googleapis/archive/%s.zip" % COMMIT],
sha256 = SHA,
strip_prefix = "googleapis-" + COMMIT,
build_file = "//tools/build/bazel:googleapis_BUILD",
)

View File

@ -1,20 +0,0 @@
package(default_visibility = [ "//visibility:public" ])
java_library(
name = "internal",
srcs = glob([
"src/main/java/io/grpc/internal/*.java",
]),
deps = [
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//context",
"@com_google_code_findbugs_jsr305//jar",
"@com_google_code_gson_gson//jar",
"@com_google_errorprone_error_prone_annotations//jar",
"@com_google_guava_guava//jar",
"@io_opencensus_opencensus_api//jar",
"@io_opencensus_opencensus_contrib_grpc_metrics//jar",
],
)

View File

@ -1,19 +1,24 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
GRPC_VER = "1.14.0"
SHA = "657ee70cbbc7e8c5aa26d622329f5fc8bfa6ce5e960bcdbff802f785b0eba212"
GRPC_SHA = "932c6e8a9f4ea26da7dc5cdb0faed53a8bb0821c9d0b43d8ab16c3f89d0cf909"
GAPIS_COMMIT = "37cc0e5acae50ee91f00827a7010c3b07dfa5311"
GAPIS_SHA = "17d023f48ea290f25edaf25a967973b5a42ce6d71b1570862f302d95aa8b9f77"
def generate_grpc():
# Patched grpc-java that fixes the OSGi split problem.
http_archive(
name = "io_grpc_grpc_java",
urls = ["https://github.com/grpc/grpc-java/archive/v%s.zip" % GRPC_VER],
sha256 = SHA,
strip_prefix = "grpc-java-" + GRPC_VER,
urls = ["https://github.com/ccascone/grpc-java/archive/v%s-patched.zip" % GRPC_VER],
sha256 = GRPC_SHA,
strip_prefix = "grpc-java-%s-patched" % GRPC_VER,
)
# Google APIs protos (status.proto, etc.)
http_archive(
name = "io_grpc_grpc_java_core_repkg",
urls = ["https://github.com/grpc/grpc-java/archive/v%s.zip" % GRPC_VER],
sha256 = SHA,
strip_prefix = "grpc-java-%s/core" % GRPC_VER,
build_file = "//tools/build/bazel:grpc_core_repkg_BUILD",
name = "com_github_googleapis",
urls = ["https://github.com/googleapis/googleapis/archive/%s.zip" % GAPIS_COMMIT],
sha256 = GAPIS_SHA,
strip_prefix = "googleapis-" + GAPIS_COMMIT,
build_file = "//tools/build/bazel:googleapis_BUILD"
)

View File

@ -33,10 +33,58 @@ def _impl(ctx):
command = ";\n".join(cmd)
)
def _impl_alt(ctx):
ending = "-src.jar"
src_files = []
out_files = []
if len(ctx.files.srcs) == 0:
fail("Cannot generate source jars from and empty input")
for src in ctx.files.srcs:
if src.path.endswith(ending):
prefix = src.path[:-len(ending)]
src_files.append(src)
out_file = ctx.actions.declare_file(prefix + ".srcjar")
out_files.append(out_file)
if len(src_files) == 0:
fail("None of the given input files is a valid source jar (%s)"
% ", ".join([s.path for s in ctx.files.srcs]))
for i in range(len(src_files)):
cmd = "cp %s %s" % (src_files[i].path, out_files[i].path)
ctx.actions.run_shell(
inputs = [src_files[i]],
outputs = [out_files[i]],
progress_message = "Generating source jar %s" % out_files[i].basename,
command = cmd
)
return DefaultInfo(files = depset(out_files))
"""
Creates a single source jar file from a set of .srcjar files.
Args:
srcs: List of source files. Only files ending with .srcjar will be considered.
"""
java_sources = rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
},
implementation = _impl,
outputs = {"jar" : "%{name}.jar"},
)
)
"""
Returns a collection of source jar files ending with .srcjar from the given list of java_library or file labels.
Input files are expected to end with "-src.jar".
Args:
srcs: List of java_library labels.
"""
java_sources_alt = rule(
attrs = {
"srcs": attr.label_list(allow_files = True),
},
implementation = _impl_alt,
)

View File

@ -20,7 +20,12 @@ load("//tools/build/bazel:generate_test_rules.bzl", "generate_test_rules")
load("//tools/build/bazel:checkstyle.bzl", "checkstyle_test")
load("//tools/build/bazel:pom_file.bzl", "pom_file")
load("//tools/build/bazel:java_sources.bzl", "java_sources")
load("//tools/build/bazel:java_sources.bzl", "java_sources_alt")
load("//tools/build/bazel:javadoc.bzl", "javadoc")
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
def _auto_name():
return "onos-" + native.package_name().replace("/", "-")
def _all_java_sources():
return native.glob(["src/main/java/**/*.java"])
@ -381,7 +386,7 @@ def osgi_jar_with_tests(
import_packages = None,
bundle_classpath = ""):
if name == None:
name = "onos-" + native.package_name().replace("/", "-")
name = _auto_name()
if srcs == None:
srcs = _all_java_sources()
if resources == None:
@ -573,3 +578,91 @@ def osgi_jar(
web_context = web_context,
bundle_classpath = bundle_classpath,
)
"""
Creates an OSGI jar file from a set of protobuf and gRPC libraries.
Args:
name: Name of the rule to generate. Optional, defaults to a name based on the location in the source tree.
For example apps/mcast/app becomes onos-apps-mcast-app
proto_libs: (required) list of proto_library targets which generated Java classes will be included to this OSGi
jar. It is important that all the given targets reference to a single proto source files, for example
only the first 2 rules are good:
proto_library(
name = "foo_proto",
srcs = ["foo.proto"],
)
proto_library(
name = "bar_proto",
srcs = ["bar.proto"],
)
# THIS WILL NOT WORK
proto_library(
name = "foo_and_bar_proto",
srcs = ["foo.proto", "bar.proto"],
)
grpc_proto_lib: (optional) proto_library target that contains the schema of a gRPC service. If not passed,
the produced jar will NOT have any gRPC stub classes.
deps: Dependencies of the generated jar file. Expressed as a list of targets
group: Maven group ID for the resulting jar file. Optional, defaults to 'org.onosproject'
visibility: Visibility of the produced jar file to other BUILDs. Optional, defaults to public
version: Version of the generated jar file. Optional, defaults to the current ONOS version
"""
def osgi_proto_jar(
proto_libs,
grpc_proto_lib = None,
name = None,
deps = [],
group = "org.onosproject",
visibility = ["//visibility:public"],
version = ONOS_VERSION
):
if name == None:
name = _auto_name()
native.java_proto_library(
name = name + "-java-proto",
deps = proto_libs,
)
java_sources_alt(
name = name + "-proto-srcjar",
srcs = [":%s-java-proto" % name],
)
osgi_srcs = [
":%s-proto-srcjar" % name,
]
base_deps = [
"@com_google_protobuf//:protobuf_java",
]
if grpc_proto_lib != None:
grpc_java_lib = name + "-java-grpc"
java_grpc_library(
name = name + "-java-grpc",
srcs = [grpc_proto_lib],
deps = [":%s-java-proto" % name],
)
osgi_srcs.append(
":%s-java-grpc__do_not_reference__srcjar" % name
)
base_deps.extend([
"@com_google_guava_guava//jar",
"@io_grpc_grpc_java//core",
"@io_grpc_grpc_java//stub",
"@io_grpc_grpc_java//protobuf",
])
osgi_jar(
name = name,
srcs = osgi_srcs,
deps = base_deps + deps,
group = group,
visibility = visibility,
version = version,
suppress_errorprone = True,
suppress_checkstyle = True,
suppress_javadocs = True,
)

View File

@ -3,10 +3,14 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
P4RUNTIME_COMMIT = "028552d98b774301c51be0fe5bc97c9e95716759"
PI_COMMIT = "36ca74fae69c8d0a142f8bfd2487bee72505cf48"
P4RUNTIME_SHA = "f335573ea971c21a1a298954039a27881b7337a03f4523321b6458eb0558644a"
PI_SHA = "767476cf9232dc39f0115d1ffc38f9b81acec74da078c048f278804f325bf77e"
def generate_p4lang():
http_archive(
name = "com_github_p4lang_p4runtime",
urls = ["https://github.com/p4lang/p4runtime/archive/%s.zip" % P4RUNTIME_COMMIT],
sha256 = P4RUNTIME_SHA,
strip_prefix = "p4runtime-%s/proto" % P4RUNTIME_COMMIT,
build_file = "//tools/build/bazel:p4runtime_BUILD"
)
@ -14,6 +18,7 @@ def generate_p4lang():
http_archive(
name = "com_github_p4lang_pi",
urls = ["https://github.com/p4lang/PI/archive/%s.zip" % PI_COMMIT],
sha256 = PI_SHA,
strip_prefix = "PI-%s/proto" % PI_COMMIT,
build_file = "//tools/build/bazel:pi_BUILD"
)

View File

@ -1,27 +1,3 @@
package(default_visibility = ["//visibility:public"])
load("@com_google_protobuf//:protobuf.bzl", "internal_copied_filegroup")
load("@io_grpc_grpc_java//:java_grpc_library.bzl", "java_grpc_library")
proto_library(
name = "p4data_proto",
srcs = ["p4/v1/p4data.proto"],
)
proto_library(
name = "p4types_proto",
srcs = ["p4/config/v1/p4types.proto"],
)
proto_library(
name = "p4info_proto",
srcs = ["p4/config/v1/p4info.proto"],
deps = [
":p4types_proto",
"@com_google_protobuf//:any_proto"
],
)
proto_library(
name = "p4runtime_proto",
srcs = ["p4/v1/p4runtime.proto"],
@ -31,31 +7,27 @@ proto_library(
"@com_github_googleapis//:status_proto",
"@com_google_protobuf//:any_proto",
],
visibility = ["//visibility:public"],
)
java_proto_library(
name = "p4data_java_proto_native",
deps = [":p4data_proto"],
proto_library(
name = "p4data_proto",
srcs = ["p4/v1/p4data.proto"],
visibility = ["//visibility:public"],
)
java_proto_library(
name = "p4types_java_proto_native",
deps = [":p4types_proto"],
proto_library(
name = "p4types_proto",
srcs = ["p4/config/v1/p4types.proto"],
visibility = ["//visibility:public"],
)
java_proto_library(
name = "p4info_java_proto_native",
deps = [":p4info_proto"],
proto_library(
name = "p4info_proto",
srcs = ["p4/config/v1/p4info.proto"],
deps = [
":p4types_proto",
"@com_google_protobuf//:any_proto"
],
visibility = ["//visibility:public"],
)
java_proto_library(
name = "p4runtime_java_proto_native",
deps = [":p4runtime_proto"],
)
java_grpc_library(
name = "p4runtime_java_grpc_native",
srcs = [":p4runtime_proto"],
deps = [":p4runtime_java_proto_native"],
)

View File

@ -1,12 +1,5 @@
package(default_visibility = ["//visibility:public"])
proto_library(
name = "p4config_proto",
srcs = ["p4/tmp/p4config.proto"],
)
java_proto_library(
name = "p4config_java_proto_native",
deps = [":p4config_proto"],
visibility = ["//visibility:public"],
)