Skip to content

Commit

Permalink
api/build: automatically generate BUILD files. (envoyproxy#8506)
Browse files Browse the repository at this point in the history
This provides canonical BUILD formatting and puts protoxform in charge
of being able to determine import paths, without having to worry about
Bazel implications.

Part of envoyproxy#8082.

Risk level: Low
Testing: tools/proto_sync.py, visual inspection of diffs.

Signed-off-by: Harvey Tuch <[email protected]>
  • Loading branch information
htuch authored Oct 7, 2019
1 parent b8212b5 commit e53f40f
Show file tree
Hide file tree
Showing 158 changed files with 528 additions and 90 deletions.
36 changes: 9 additions & 27 deletions api/bazel/api_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ load("@com_envoyproxy_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@com_github_grpc_grpc//bazel:cc_grpc_library.bzl", "cc_grpc_library")
load(
"//bazel:external_proto_deps.bzl",
"EXTERNAL_PROTO_CC_BAZEL_DEP_MAP",
"EXTERNAL_PROTO_GO_BAZEL_DEP_MAP",
"EXTERNAL_PROTO_PY_BAZEL_DEP_MAP",
)

_PY_PROTO_SUFFIX = "_py_proto"
_CC_PROTO_SUFFIX = "_cc_proto"
Expand All @@ -25,30 +31,6 @@ _COMMON_PROTO_DEPS = [
"@com_envoyproxy_protoc_gen_validate//validate:validate_proto",
]

# When we have external proto dependencies, we need to be able to map from the
# proto_library dependency to the relevant {cc,go,py}_library when generating
# the respective language library for some target. If you add a new API
# dependency on some external proto, please provide the mappings here for
# Go/C++/Python.

_GO_BAZEL_RULE_MAPPING = {
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_go",
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_and_config_proto_go",
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:cel_go_proto",
}

_CC_BAZEL_RULE_MAPPING = {
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_cc",
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto_cc",
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
}

_PY_BAZEL_RULE_MAPPING = {
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_py",
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto_py",
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_py_proto",
}

def _proto_mapping(dep, proto_dep_map, proto_suffix):
mapped = proto_dep_map.get(dep)
if mapped == None:
Expand All @@ -57,13 +39,13 @@ def _proto_mapping(dep, proto_dep_map, proto_suffix):
return mapped

def _go_proto_mapping(dep):
return _proto_mapping(dep, _GO_BAZEL_RULE_MAPPING, _GO_PROTO_SUFFIX)
return _proto_mapping(dep, EXTERNAL_PROTO_GO_BAZEL_DEP_MAP, _GO_PROTO_SUFFIX)

def _cc_proto_mapping(dep):
return _proto_mapping(dep, _CC_BAZEL_RULE_MAPPING, _CC_PROTO_SUFFIX)
return _proto_mapping(dep, EXTERNAL_PROTO_CC_BAZEL_DEP_MAP, _CC_PROTO_SUFFIX)

def _py_proto_mapping(dep):
return _proto_mapping(dep, _PY_BAZEL_RULE_MAPPING, _PY_PROTO_SUFFIX)
return _proto_mapping(dep, EXTERNAL_PROTO_PY_BAZEL_DEP_MAP, _PY_PROTO_SUFFIX)

# TODO(htuch): Convert this to native py_proto_library once
# https://github.com/bazelbuild/bazel/issues/3935 and/or
Expand Down
37 changes: 37 additions & 0 deletions api/bazel/external_proto_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Any external dependency imported in the api/ .protos requires entries in
# the maps below, to allow the Bazel proto and language specific bindings to be
# inferred from the import directives.
#
# This file needs to be interpreted as both Python 3 and Starlark, so only the
# common subset of Python should be used.

# This maps from .proto import directive path to the Bazel dependency path for
# external dependencies. Since BUILD files are generated, this is the canonical
# place to define this mapping.
EXTERNAL_PROTO_IMPORT_BAZEL_DEP_MAP = {
"google/api/expr/v1alpha1/syntax.proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto",
"metrics.proto": "@prometheus_metrics_model//:client_model",
"opencensus/proto/trace/v1/trace.proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto",
"opencensus/proto/trace/v1/trace_config.proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto",
}

# This maps from the Bazel proto_library target to the Go language binding target for external dependencies.
EXTERNAL_PROTO_GO_BAZEL_DEP_MAP = {
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:cel_go_proto",
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_go",
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_and_config_proto_go",
}

# This maps from the Bazel proto_library target to the C++ language binding target for external dependencies.
EXTERNAL_PROTO_CC_BAZEL_DEP_MAP = {
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_cc_proto",
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_cc",
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto_cc",
}

# This maps from the Bazel proto_library target to the Python language binding target for external dependencies.
EXTERNAL_PROTO_PY_BAZEL_DEP_MAP = {
"@com_google_googleapis//google/api/expr/v1alpha1:syntax_proto": "@com_google_googleapis//google/api/expr/v1alpha1:syntax_py_proto",
"@opencensus_proto//opencensus/proto/trace/v1:trace_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_proto_py",
"@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto": "@opencensus_proto//opencensus/proto/trace/v1:trace_config_proto_py",
}
2 changes: 2 additions & 0 deletions api/envoy/admin/v2alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/admin/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
3 changes: 2 additions & 1 deletion api/envoy/api/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand All @@ -10,7 +12,6 @@ api_proto_package(
"//envoy/api/v2/core:pkg",
"//envoy/api/v2/endpoint:pkg",
"//envoy/api/v2/listener:pkg",
"//envoy/api/v2/ratelimit:pkg",
"//envoy/api/v2/route:pkg",
"//envoy/config/listener/v2:pkg",
"//envoy/type:pkg",
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v2/auth/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v2/cluster/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v2/core/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
7 changes: 3 additions & 4 deletions api/envoy/api/v2/endpoint/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/api/v2/auth:pkg",
"//envoy/api/v2/core:pkg",
],
deps = ["//envoy/api/v2/core:pkg"],
)
2 changes: 2 additions & 0 deletions api/envoy/api/v2/listener/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v2/ratelimit/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v2/route/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
3 changes: 2 additions & 1 deletion api/envoy/api/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand All @@ -10,7 +12,6 @@ api_proto_package(
"//envoy/api/v3alpha/core:pkg",
"//envoy/api/v3alpha/endpoint:pkg",
"//envoy/api/v3alpha/listener:pkg",
"//envoy/api/v3alpha/ratelimit:pkg",
"//envoy/api/v3alpha/route:pkg",
"//envoy/config/listener/v3alpha:pkg",
"//envoy/type:pkg",
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v3alpha/auth/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v3alpha/cluster/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v3alpha/core/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
7 changes: 3 additions & 4 deletions api/envoy/api/v3alpha/endpoint/BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/api/v3alpha/auth:pkg",
"//envoy/api/v3alpha/core:pkg",
],
deps = ["//envoy/api/v3alpha/core:pkg"],
)
2 changes: 2 additions & 0 deletions api/envoy/api/v3alpha/listener/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v3alpha/ratelimit/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v3alpha/route/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/accesslog/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/accesslog/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
3 changes: 2 additions & 1 deletion api/envoy/config/bootstrap/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand All @@ -9,7 +11,6 @@ api_proto_package(
"//envoy/api/v2/core:pkg",
"//envoy/config/metrics/v2:pkg",
"//envoy/config/overload/v2alpha:pkg",
"//envoy/config/ratelimit/v2:pkg",
"//envoy/config/trace/v2:pkg",
],
)
3 changes: 2 additions & 1 deletion api/envoy/config/bootstrap/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand All @@ -9,7 +11,6 @@ api_proto_package(
"//envoy/api/v3alpha/core:pkg",
"//envoy/config/metrics/v3alpha:pkg",
"//envoy/config/overload/v3alpha:pkg",
"//envoy/config/ratelimit/v3alpha:pkg",
"//envoy/config/trace/v3alpha:pkg",
],
)
2 changes: 2 additions & 0 deletions api/envoy/config/cluster/dynamic_forward_proxy/v2alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/cluster/dynamic_forward_proxy/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/cluster/redis/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/common/dynamic_forward_proxy/v2alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/common/dynamic_forward_proxy/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/common/tap/v2alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/common/tap/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/accesslog/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/accesslog/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/dubbo/router/v2alpha1/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/dubbo/router/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/fault/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/fault/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/api/v3alpha/core:pkg",
"//envoy/type:pkg",
],
deps = ["//envoy/type:pkg"],
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/api/v3alpha/core:pkg",
"//envoy/type:pkg",
],
deps = ["//envoy/type:pkg"],
)
2 changes: 2 additions & 0 deletions api/envoy/config/filter/http/buffer/v2/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
2 changes: 2 additions & 0 deletions api/envoy/config/filter/http/buffer/v3alpha/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# DO NOT EDIT. This file is generated by tools/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2
Expand Down
Loading

0 comments on commit e53f40f

Please sign in to comment.