diff --git a/api/BUILD b/api/BUILD index fcaf98d2..6a638ded 100644 --- a/api/BUILD +++ b/api/BUILD @@ -1,5 +1,4 @@ -load("//bazel:api_build_system.bzl", "api_proto_library") -load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library", "go_grpc_library") +load("//bazel:api_build_system.bzl", "api_proto_library", "api_go_proto_library", "api_go_grpc_library") licenses(["notice"]) # Apache 2 @@ -8,16 +7,9 @@ api_proto_library( srcs = ["address.proto"], ) -go_proto_library( - name = "address_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/address", +api_go_proto_library( + name = "address", proto = ":address", - visibility = ["//visibility:public"], - deps = [ - "@com_github_gogo_protobuf//:gogo_proto_go", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - ], ) api_proto_library( @@ -26,19 +18,10 @@ api_proto_library( deps = [":address"], ) -go_proto_library( - name = "base_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/base", +api_go_proto_library( + name = "base", proto = ":base", - visibility = ["//visibility:public"], - deps = [ - ":address_go_proto", - "@com_github_gogo_protobuf//:gogo_proto_go", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_github_golang_protobuf//ptypes/struct:go_default_library", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - ], + deps = [":address_go_proto"], ) api_proto_library( @@ -57,11 +40,9 @@ api_proto_library( ], ) -go_proto_library( - name = "bootstrap_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/bootstrap", +api_go_proto_library( + name = "bootstrap", proto = ":bootstrap", - visibility = ["//visibility:public"], deps = [ ":address_go_proto", ":base_go_proto", @@ -72,9 +53,6 @@ go_proto_library( ":sds_go_grpc", ":stats_go_proto", ":trace_go_proto", - "@com_github_gogo_protobuf//:gogo_proto_go", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", ], ) @@ -84,17 +62,10 @@ api_proto_library( deps = [":base"], ) -go_proto_library( - name = "health_check_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/health_check", +api_go_proto_library( + name = "health_check", proto = ":health_check", - visibility = ["//visibility:public"], - deps = [ - ":base_go_proto", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - ], + deps = [":base_go_proto"], ) api_proto_library( @@ -112,11 +83,9 @@ api_proto_library( ], ) -go_grpc_library( - name = "cds_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/cds", +api_go_grpc_library( + name = "cds", proto = ":cds", - visibility = ["//visibility:public"], deps = [ ":address_go_proto", ":base_go_proto", @@ -125,12 +94,6 @@ go_grpc_library( ":health_check_go_proto", ":protocol_go_proto", ":sds_go_grpc", - "@com_github_gogo_protobuf//:gogo_proto_go", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_github_golang_protobuf//ptypes/struct:go_default_library", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - "@googleapis//:http_api_go_proto", ], ) @@ -143,17 +106,12 @@ api_proto_library( ], ) -go_proto_library( - name = "config_source_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/config_source", +api_go_proto_library( + name = "config_source", proto = ":config_source", - visibility = ["//visibility:public"], deps = [ ":base_go_proto", ":grpc_service_go_proto", - "@com_github_gogo_protobuf//:gogo_proto_go", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", ], ) @@ -164,15 +122,10 @@ api_proto_library( deps = [":base"], ) -go_grpc_library( - name = "discovery_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/discovery", +api_go_grpc_library( + name = "discovery", proto = ":discovery", - visibility = ["//visibility:public"], - deps = [ - ":base_go_proto", - "@com_github_golang_protobuf//ptypes/any:go_default_library", - ], + deps = [":base_go_proto"], ) api_proto_library( @@ -187,20 +140,14 @@ api_proto_library( ], ) -go_grpc_library( - name = "eds_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/eds", +api_go_grpc_library( + name = "eds", proto = ":eds", - visibility = ["//visibility:public"], deps = [ ":address_go_proto", ":base_go_proto", ":discovery_go_grpc", ":health_check_go_proto", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - "@googleapis//:http_api_go_proto", ], ) @@ -210,16 +157,10 @@ api_proto_library( deps = [":base"], ) -go_proto_library( - name = "grpc_service_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/grpc_service", +api_go_proto_library( + name = "grpc_service", proto = ":grpc_service", - visibility = ["//visibility:public"], - deps = [ - ":base_go_proto", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - ], + deps = [":base_go_proto"], ) api_proto_library( @@ -232,16 +173,12 @@ api_proto_library( ], ) -go_grpc_library( - name = "hds_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/hds", +api_go_grpc_library( + name = "hds", proto = ":hds", - visibility = ["//visibility:public"], deps = [ ":base_go_proto", ":health_check_go_proto", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@googleapis//:http_api_go_proto", ], ) @@ -257,20 +194,14 @@ api_proto_library( ], ) -go_grpc_library( - name = "lds_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/lds", +api_go_grpc_library( + name = "lds", proto = ":lds", - visibility = ["//visibility:public"], deps = [ ":address_go_proto", ":base_go_proto", ":discovery_go_grpc", ":sds_go_grpc", - "@com_github_golang_protobuf//ptypes/struct:go_default_library", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - "@googleapis//:http_api_go_proto", ], ) @@ -291,15 +222,9 @@ api_proto_library( srcs = ["protocol.proto"], ) -go_proto_library( - name = "protocol_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/protocol", +api_go_proto_library( + name = "protocol", proto = ":protocol", - visibility = ["//visibility:public"], - deps = [ - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - ], ) api_proto_library( @@ -308,14 +233,9 @@ api_proto_library( has_services = 1, ) -go_grpc_library( - name = "rls_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/rls", +api_go_grpc_library( + name = "rls", proto = ":rls", - visibility = ["//visibility:public"], - deps = [ - "@com_lyft_protoc_gen_validate//validate:go_default_library", - ], ) api_proto_library( @@ -329,20 +249,13 @@ api_proto_library( ], ) -go_grpc_library( - name = "rds_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/rds", +api_go_grpc_library( + name = "rds", proto = ":rds", - visibility = ["//visibility:public"], deps = [ ":auth_go_proto", ":base_go_proto", ":discovery_go_grpc", - "@com_github_gogo_protobuf//:gogo_proto_go", - "@com_github_golang_protobuf//ptypes/duration:go_default_library", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - "@googleapis//:http_api_go_proto", ], ) @@ -357,18 +270,13 @@ api_proto_library( ], ) -go_grpc_library( - name = "sds_go_grpc", - importpath = "github.com/envoyproxy/data-plane-api/api/sds", +api_go_grpc_library( + name = "sds", proto = ":sds", - visibility = ["//visibility:public"], deps = [ ":base_go_proto", ":config_source_go_proto", ":discovery_go_grpc", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - "@googleapis//:http_api_go_proto", ], ) @@ -380,16 +288,11 @@ api_proto_library( ], ) -go_proto_library( - name = "stats_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/stats", +api_go_proto_library( + name = "stats", proto = ":stats", - visibility = ["//visibility:public"], deps = [ ":address_go_proto", - "@com_github_golang_protobuf//ptypes/struct:go_default_library", - "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", ], ) @@ -398,15 +301,9 @@ api_proto_library( srcs = ["trace.proto"], ) -go_proto_library( - name = "trace_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/api/trace", +api_go_proto_library( + name = "trace", proto = ":trace", - visibility = ["//visibility:public"], - deps = [ - "@com_github_golang_protobuf//ptypes/struct:go_default_library", - "@com_lyft_protoc_gen_validate//validate:go_default_library", - ], ) api_proto_library( @@ -417,16 +314,12 @@ api_proto_library( ], ) -go_proto_library( - name = "auth_go_proto", - importpath = "github.com/envoyproxy/data-plane-api/auth", +api_go_proto_library( + name = "auth", proto = ":auth", - visibility = ["//visibility:public"], deps = [ "//api:address_go_proto", "//api:sds_go_grpc", - "@com_github_golang_protobuf//ptypes/struct:go_default_library", - "@com_github_golang_protobuf//ptypes/timestamp:go_default_library", "@googleapis//:rpc_status_go_proto", ], ) diff --git a/bazel/api_build_system.bzl b/bazel/api_build_system.bzl index e3cde960..89a6ecb6 100644 --- a/bazel/api_build_system.bzl +++ b/bazel/api_build_system.bzl @@ -1,8 +1,13 @@ load("@com_google_protobuf//:protobuf.bzl", "py_proto_library") load("@com_lyft_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library", "go_grpc_library") +load("@io_bazel_rules_go//go:def.bzl", "go_test") _PY_SUFFIX="_py" _CC_SUFFIX="_cc" +_GO_PROTO_SUFFIX="_go_proto" +_GO_GRPC_SUFFIX="_go_grpc" +_GO_IMPORTPATH_PREFIX="github.com/envoyproxy/data-plane-api/api/" def _Suffix(d, suffix): return d + suffix @@ -34,6 +39,39 @@ def api_py_proto_library(name, srcs = [], deps = [], has_services = 0): visibility = ["//visibility:public"], ) +def api_go_proto_library(name, proto, deps = []): + go_proto_library( + name = _Suffix(name, _GO_PROTO_SUFFIX), + importpath = _Suffix(_GO_IMPORTPATH_PREFIX, name), + proto = proto, + visibility = ["//visibility:public"], + deps = deps + [ + "@com_github_gogo_protobuf//:gogo_proto_go", + "@com_github_golang_protobuf//ptypes/duration:go_default_library", + "@com_github_golang_protobuf//ptypes/struct:go_default_library", + "@com_github_golang_protobuf//ptypes/timestamp:go_default_library", + "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", + "@com_lyft_protoc_gen_validate//validate:go_default_library", + ] + ) + +def api_go_grpc_library(name, proto, deps = []): + go_grpc_library( + name = _Suffix(name, _GO_GRPC_SUFFIX), + importpath = _Suffix(_GO_IMPORTPATH_PREFIX, name), + proto = proto, + visibility = ["//visibility:public"], + deps = deps + [ + "@com_github_gogo_protobuf//:gogo_proto_go", + "@com_github_golang_protobuf//ptypes/duration:go_default_library", + "@com_github_golang_protobuf//ptypes/struct:go_default_library", + "@com_github_golang_protobuf//ptypes/wrappers:go_default_library", + "@com_github_golang_protobuf//ptypes/any:go_default_library", + "@com_lyft_protoc_gen_validate//validate:go_default_library", + "@googleapis//:http_api_go_proto", + ] + ) + # TODO(htuch): has_services is currently ignored but will in future support # gRPC stub generation. # TODO(htuch): Automatically generate go_proto_library and go_grpc_library @@ -87,3 +125,12 @@ def api_cc_test(name, srcs, proto_deps): srcs = srcs, deps = [_LibrarySuffix(d, _CC_SUFFIX) for d in proto_deps], ) + +def api_go_test(name, size, importpath, srcs = [], deps = []): + go_test( + name = name, + size = size, + srcs = srcs, + importpath = importpath, + deps = deps, + ) diff --git a/test/build/BUILD b/test/build/BUILD index 39570930..d214a2dc 100644 --- a/test/build/BUILD +++ b/test/build/BUILD @@ -1,5 +1,4 @@ -load("//bazel:api_build_system.bzl", "api_cc_test") -load("@io_bazel_rules_go//go:def.bzl", "go_test") +load("//bazel:api_build_system.bzl", "api_cc_test", "api_go_test") licenses(["notice"]) # Apache 2 @@ -19,7 +18,7 @@ api_cc_test( ], ) -go_test( +api_go_test( name = "go_build_test", size = "small", srcs = ["go_build_test.go"],