Refactor go BUILD targets. (#406)

Created new definitions in api_build_system.bzl that wrap
go_proto_library, go_grpc_library, and go_test. Changed rules in api/BUILD and
test/build/BUILD to use these new definitions. In the future these
definitions could be expanded upon for auto generation in api_proto_library.

Signed-off-by: Kyle Myerson <kmyerson@google.com>
pull/408/head
kmyerson 7 years ago committed by htuch
parent a4b80d6c43
commit 90698c6388
  1. 189
      api/BUILD
  2. 47
      bazel/api_build_system.bzl
  3. 5
      test/build/BUILD

@ -1,5 +1,4 @@
load("//bazel:api_build_system.bzl", "api_proto_library") load("//bazel:api_build_system.bzl", "api_proto_library", "api_go_proto_library", "api_go_grpc_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library", "go_grpc_library")
licenses(["notice"]) # Apache 2 licenses(["notice"]) # Apache 2
@ -8,16 +7,9 @@ api_proto_library(
srcs = ["address.proto"], srcs = ["address.proto"],
) )
go_proto_library( api_go_proto_library(
name = "address_go_proto", name = "address",
importpath = "github.com/envoyproxy/data-plane-api/api/address",
proto = ":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( api_proto_library(
@ -26,19 +18,10 @@ api_proto_library(
deps = [":address"], deps = [":address"],
) )
go_proto_library( api_go_proto_library(
name = "base_go_proto", name = "base",
importpath = "github.com/envoyproxy/data-plane-api/api/base",
proto = ":base", proto = ":base",
visibility = ["//visibility:public"], deps = [":address_go_proto"],
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",
],
) )
api_proto_library( api_proto_library(
@ -57,11 +40,9 @@ api_proto_library(
], ],
) )
go_proto_library( api_go_proto_library(
name = "bootstrap_go_proto", name = "bootstrap",
importpath = "github.com/envoyproxy/data-plane-api/api/bootstrap",
proto = ":bootstrap", proto = ":bootstrap",
visibility = ["//visibility:public"],
deps = [ deps = [
":address_go_proto", ":address_go_proto",
":base_go_proto", ":base_go_proto",
@ -72,9 +53,6 @@ go_proto_library(
":sds_go_grpc", ":sds_go_grpc",
":stats_go_proto", ":stats_go_proto",
":trace_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"], deps = [":base"],
) )
go_proto_library( api_go_proto_library(
name = "health_check_go_proto", name = "health_check",
importpath = "github.com/envoyproxy/data-plane-api/api/health_check",
proto = ":health_check", proto = ":health_check",
visibility = ["//visibility:public"], deps = [":base_go_proto"],
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",
],
) )
api_proto_library( api_proto_library(
@ -112,11 +83,9 @@ api_proto_library(
], ],
) )
go_grpc_library( api_go_grpc_library(
name = "cds_go_grpc", name = "cds",
importpath = "github.com/envoyproxy/data-plane-api/api/cds",
proto = ":cds", proto = ":cds",
visibility = ["//visibility:public"],
deps = [ deps = [
":address_go_proto", ":address_go_proto",
":base_go_proto", ":base_go_proto",
@ -125,12 +94,6 @@ go_grpc_library(
":health_check_go_proto", ":health_check_go_proto",
":protocol_go_proto", ":protocol_go_proto",
":sds_go_grpc", ":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( api_go_proto_library(
name = "config_source_go_proto", name = "config_source",
importpath = "github.com/envoyproxy/data-plane-api/api/config_source",
proto = ":config_source", proto = ":config_source",
visibility = ["//visibility:public"],
deps = [ deps = [
":base_go_proto", ":base_go_proto",
":grpc_service_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"], deps = [":base"],
) )
go_grpc_library( api_go_grpc_library(
name = "discovery_go_grpc", name = "discovery",
importpath = "github.com/envoyproxy/data-plane-api/api/discovery",
proto = ":discovery", proto = ":discovery",
visibility = ["//visibility:public"], deps = [":base_go_proto"],
deps = [
":base_go_proto",
"@com_github_golang_protobuf//ptypes/any:go_default_library",
],
) )
api_proto_library( api_proto_library(
@ -187,20 +140,14 @@ api_proto_library(
], ],
) )
go_grpc_library( api_go_grpc_library(
name = "eds_go_grpc", name = "eds",
importpath = "github.com/envoyproxy/data-plane-api/api/eds",
proto = ":eds", proto = ":eds",
visibility = ["//visibility:public"],
deps = [ deps = [
":address_go_proto", ":address_go_proto",
":base_go_proto", ":base_go_proto",
":discovery_go_grpc", ":discovery_go_grpc",
":health_check_go_proto", ":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"], deps = [":base"],
) )
go_proto_library( api_go_proto_library(
name = "grpc_service_go_proto", name = "grpc_service",
importpath = "github.com/envoyproxy/data-plane-api/api/grpc_service",
proto = ":grpc_service", proto = ":grpc_service",
visibility = ["//visibility:public"], deps = [":base_go_proto"],
deps = [
":base_go_proto",
"@com_github_golang_protobuf//ptypes/duration:go_default_library",
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
) )
api_proto_library( api_proto_library(
@ -232,16 +173,12 @@ api_proto_library(
], ],
) )
go_grpc_library( api_go_grpc_library(
name = "hds_go_grpc", name = "hds",
importpath = "github.com/envoyproxy/data-plane-api/api/hds",
proto = ":hds", proto = ":hds",
visibility = ["//visibility:public"],
deps = [ deps = [
":base_go_proto", ":base_go_proto",
":health_check_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( api_go_grpc_library(
name = "lds_go_grpc", name = "lds",
importpath = "github.com/envoyproxy/data-plane-api/api/lds",
proto = ":lds", proto = ":lds",
visibility = ["//visibility:public"],
deps = [ deps = [
":address_go_proto", ":address_go_proto",
":base_go_proto", ":base_go_proto",
":discovery_go_grpc", ":discovery_go_grpc",
":sds_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"], srcs = ["protocol.proto"],
) )
go_proto_library( api_go_proto_library(
name = "protocol_go_proto", name = "protocol",
importpath = "github.com/envoyproxy/data-plane-api/api/protocol",
proto = ":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( api_proto_library(
@ -308,14 +233,9 @@ api_proto_library(
has_services = 1, has_services = 1,
) )
go_grpc_library( api_go_grpc_library(
name = "rls_go_grpc", name = "rls",
importpath = "github.com/envoyproxy/data-plane-api/api/rls",
proto = ":rls", proto = ":rls",
visibility = ["//visibility:public"],
deps = [
"@com_lyft_protoc_gen_validate//validate:go_default_library",
],
) )
api_proto_library( api_proto_library(
@ -329,20 +249,13 @@ api_proto_library(
], ],
) )
go_grpc_library( api_go_grpc_library(
name = "rds_go_grpc", name = "rds",
importpath = "github.com/envoyproxy/data-plane-api/api/rds",
proto = ":rds", proto = ":rds",
visibility = ["//visibility:public"],
deps = [ deps = [
":auth_go_proto", ":auth_go_proto",
":base_go_proto", ":base_go_proto",
":discovery_go_grpc", ":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( api_go_grpc_library(
name = "sds_go_grpc", name = "sds",
importpath = "github.com/envoyproxy/data-plane-api/api/sds",
proto = ":sds", proto = ":sds",
visibility = ["//visibility:public"],
deps = [ deps = [
":base_go_proto", ":base_go_proto",
":config_source_go_proto", ":config_source_go_proto",
":discovery_go_grpc", ":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( api_go_proto_library(
name = "stats_go_proto", name = "stats",
importpath = "github.com/envoyproxy/data-plane-api/api/stats",
proto = ":stats", proto = ":stats",
visibility = ["//visibility:public"],
deps = [ deps = [
":address_go_proto", ":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"], srcs = ["trace.proto"],
) )
go_proto_library( api_go_proto_library(
name = "trace_go_proto", name = "trace",
importpath = "github.com/envoyproxy/data-plane-api/api/trace",
proto = ":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( api_proto_library(
@ -417,16 +314,12 @@ api_proto_library(
], ],
) )
go_proto_library( api_go_proto_library(
name = "auth_go_proto", name = "auth",
importpath = "github.com/envoyproxy/data-plane-api/auth",
proto = ":auth", proto = ":auth",
visibility = ["//visibility:public"],
deps = [ deps = [
"//api:address_go_proto", "//api:address_go_proto",
"//api:sds_go_grpc", "//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", "@googleapis//:rpc_status_go_proto",
], ],
) )

@ -1,8 +1,13 @@
load("@com_google_protobuf//:protobuf.bzl", "py_proto_library") 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("@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" _PY_SUFFIX="_py"
_CC_SUFFIX="_cc" _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): def _Suffix(d, suffix):
return d + suffix return d + suffix
@ -34,6 +39,39 @@ def api_py_proto_library(name, srcs = [], deps = [], has_services = 0):
visibility = ["//visibility:public"], 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 # TODO(htuch): has_services is currently ignored but will in future support
# gRPC stub generation. # gRPC stub generation.
# TODO(htuch): Automatically generate go_proto_library and go_grpc_library # 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, srcs = srcs,
deps = [_LibrarySuffix(d, _CC_SUFFIX) for d in proto_deps], 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,
)

@ -1,5 +1,4 @@
load("//bazel:api_build_system.bzl", "api_cc_test") load("//bazel:api_build_system.bzl", "api_cc_test", "api_go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_test")
licenses(["notice"]) # Apache 2 licenses(["notice"]) # Apache 2
@ -19,7 +18,7 @@ api_cc_test(
], ],
) )
go_test( api_go_test(
name = "go_build_test", name = "go_build_test",
size = "small", size = "small",
srcs = ["go_build_test.go"], srcs = ["go_build_test.go"],

Loading…
Cancel
Save