Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proto: unify envoy_proto_library/api_proto_library. #4233

Merged
merged 9 commits into from
Aug 24, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions api/bazel/api_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,26 @@ def api_proto_library(name, visibility = ["//visibility:private"], srcs = [], de
deps = [_LibrarySuffix(d, _CC_SUFFIX) for d in deps],
external_deps = [
"@com_google_protobuf//:cc_wkt_protos",
"@googleapis//:api_httpbody_protos",
"@googleapis//:http_api_protos",
"@googleapis//:rpc_status_protos",
"@com_github_gogo_protobuf//:gogo_proto_cc",
],
visibility = ["//visibility:public"],
)
py_export_suffixes = []
if (require_py == 1):
api_py_proto_library(name, srcs, deps, has_services)
py_export_suffixes = ["_py", "_py_genproto"]

# Allow unlimited visibility for consumers
export_suffixes = ["", "_cc", "_cc_validate", "_cc_proto", "_cc_proto_genproto"] + py_export_suffixes
for s in export_suffixes:
native.alias(
name = name + "_export" + s,
actual = name + s,
visibility = ["//visibility:public"],
)

def api_cc_test(name, srcs, proto_deps):
native.cc_test(
Expand Down
52 changes: 4 additions & 48 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library", "py_proto_library")
load("@com_lyft_protoc_gen_validate//bazel:pgv_proto_library.bzl", "pgv_cc_proto_library")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I will fix. But, now you have volunteered yourself as reviewer :)

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

def envoy_package():
native.package(default_visibility = ["//visibility:public"])
Expand Down Expand Up @@ -398,54 +400,8 @@ def _proto_header(proto_path):
return None

# Envoy proto targets should be specified with this function.
def envoy_proto_library(
name,
srcs = [],
deps = [],
external_deps = [],
generate_python = True):
# Ideally this would be native.{proto_library, cc_proto_library}.
# Unfortunately, this doesn't work with http_api_protos due to the PGV
# requirement to also use them in the non-native protobuf.bzl
# cc_proto_library; you end up with the same file built twice. So, also
# using protobuf.bzl cc_proto_library here.
cc_proto_deps = []
py_proto_deps = ["@com_google_protobuf//:protobuf_python"]

if "api_httpbody_protos" in external_deps:
cc_proto_deps.append("@googleapis//:api_httpbody_protos")
py_proto_deps.append("@googleapis//:api_httpbody_protos_py")

if "http_api_protos" in external_deps:
cc_proto_deps.append("@googleapis//:http_api_protos")
py_proto_deps.append("@googleapis//:http_api_protos_py")

if "well_known_protos" in external_deps:
# WKT is already included for Python as part of standard deps above.
cc_proto_deps.append("@com_google_protobuf//:cc_wkt_protos")

cc_proto_library(
name = name,
srcs = srcs,
default_runtime = "@com_google_protobuf//:protobuf",
protoc = "@com_google_protobuf//:protoc",
deps = deps + cc_proto_deps,
# Avoid generating .so, we don't need it, can interfere with builds
# such as OSS-Fuzz.
linkstatic = 1,
alwayslink = 1,
visibility = ["//visibility:public"],
)

if generate_python:
py_proto_library(
name = name + "_py",
srcs = srcs,
default_runtime = "@com_google_protobuf//:protobuf_python",
protoc = "@com_google_protobuf//:protoc",
deps = deps + py_proto_deps,
visibility = ["//visibility:public"],
)
def envoy_proto_library(name, **kwargs):
return api_proto_library(name, visibility = ["//visibility:public"], **kwargs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need visibility here, since envoy_package() already set default visibility to public.

just make this envoy_proto_library = api_proto_library?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't quite work, because api_proto_library overrides defaults itself; untangling that ball of string is best left as an exercise for another PR :)


# Envoy proto descriptor targets should be specified with this function.
# This is used for testing only.
Expand Down
2 changes: 1 addition & 1 deletion source/common/ratelimit/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ envoy_cc_library(
srcs = ["ratelimit_impl.cc"],
hdrs = ["ratelimit_impl.h"],
deps = [
":ratelimit_proto",
":ratelimit_proto_cc",
"//include/envoy/grpc:async_client_interface",
"//include/envoy/grpc:async_client_manager_interface",
"//include/envoy/ratelimit:ratelimit_interface",
Expand Down
3 changes: 1 addition & 2 deletions test/common/access_log/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ envoy_cc_library(
envoy_proto_library(
name = "access_log_formatter_fuzz_proto",
srcs = ["access_log_formatter_fuzz.proto"],
generate_python = 0,
deps = ["//test/fuzz:common_proto"],
)

Expand All @@ -33,7 +32,7 @@ envoy_cc_fuzz_test(
srcs = ["access_log_formatter_fuzz_test.cc"],
corpus = "access_log_formatter_corpus",
deps = [
":access_log_formatter_fuzz_proto",
":access_log_formatter_fuzz_proto_cc",
"//source/common/access_log:access_log_formatter_lib",
"//test/fuzz:utility_lib",
],
Expand Down
10 changes: 5 additions & 5 deletions test/common/grpc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ envoy_cc_test(
"//test/mocks/http:http_mocks",
"//test/mocks/tracing:tracing_mocks",
"//test/mocks/upstream:upstream_mocks",
"//test/proto:helloworld_proto",
"//test/proto:helloworld_proto_cc",
],
)

Expand All @@ -40,7 +40,7 @@ envoy_cc_test(
deps = [
"//source/common/buffer:buffer_lib",
"//source/common/grpc:codec_lib",
"//test/proto:helloworld_proto",
"//test/proto:helloworld_proto_cc",
],
)

Expand All @@ -51,7 +51,7 @@ envoy_cc_test(
"//source/common/grpc:common_lib",
"//source/common/http:headers_lib",
"//test/mocks/upstream:upstream_mocks",
"//test/proto:helloworld_proto",
"//test/proto:helloworld_proto_cc",
"//test/test_common:utility_lib",
],
)
Expand All @@ -66,7 +66,7 @@ envoy_cc_test(
"//source/common/tracing:http_tracer_lib",
"//test/mocks/grpc:grpc_mocks",
"//test/mocks/tracing:tracing_mocks",
"//test/proto:helloworld_proto",
"//test/proto:helloworld_proto_cc",
] + envoy_select_google_grpc(["//source/common/grpc:google_async_client_lib"]),
)

Expand Down Expand Up @@ -98,7 +98,7 @@ envoy_cc_test_library(
"//source/common/http/http2:conn_pool_lib",
"//test/integration:integration_lib",
"//test/mocks/local_info:local_info_mocks",
"//test/proto:helloworld_proto",
"//test/proto:helloworld_proto_cc",
],
)

Expand Down
9 changes: 3 additions & 6 deletions test/common/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ envoy_cc_test_library(
envoy_proto_library(
name = "conn_manager_impl_fuzz_proto",
srcs = ["conn_manager_impl_fuzz.proto"],
external_deps = ["well_known_protos"],
generate_python = 0,
deps = [
"//test/fuzz:common_proto",
],
Expand All @@ -106,7 +104,7 @@ envoy_cc_fuzz_test(
srcs = ["conn_manager_impl_fuzz_test.cc"],
corpus = "conn_manager_impl_corpus",
deps = [
":conn_manager_impl_fuzz_proto",
":conn_manager_impl_fuzz_proto_cc",
"//source/common/common:empty_string",
"//source/common/http:conn_manager_lib",
"//source/common/http:date_provider_lib",
Expand Down Expand Up @@ -207,15 +205,14 @@ envoy_cc_test(
envoy_proto_library(
name = "header_map_impl_fuzz_proto",
srcs = ["header_map_impl_fuzz.proto"],
external_deps = ["well_known_protos"],
)

envoy_cc_fuzz_test(
name = "header_map_impl_fuzz_test",
srcs = ["header_map_impl_fuzz_test.cc"],
corpus = "header_map_impl_corpus",
deps = [
":header_map_impl_fuzz_proto",
":header_map_impl_fuzz_proto_cc",
"//source/common/http:header_map_lib",
],
)
Expand Down Expand Up @@ -250,7 +247,7 @@ envoy_cc_fuzz_test(
srcs = ["utility_fuzz_test.cc"],
corpus = "utility_corpus",
deps = [
":utility_fuzz_proto",
":utility_fuzz_proto_cc",
"//source/common/http:utility_lib",
"//test/test_common:utility_lib",
],
Expand Down
2 changes: 1 addition & 1 deletion test/common/http/conn_manager_impl_corpus/example
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ actions {
stream_action {
stream_id: 0
response {
continue_100_headers {}
continue_headers {}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/common/http/conn_manager_impl_fuzz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ message RequestAction {
// TODO(htuch): Model and fuzz encoder filter buffering/resumption and different status returns.
message ResponseAction {
oneof response_action_selector {
test.fuzz.Headers continue_100_headers = 1;
test.fuzz.Headers continue_headers = 1;
test.fuzz.Headers headers = 2;
uint32 data = 3;
test.fuzz.Headers trailers = 4;
Expand Down
4 changes: 2 additions & 2 deletions test/common/http/conn_manager_impl_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ class FuzzStream {
const test::common::http::ResponseAction& response_action) {
const bool end_stream = response_action.end_stream();
switch (response_action.response_action_selector_case()) {
case test::common::http::ResponseAction::kContinue100Headers: {
case test::common::http::ResponseAction::kContinueHeaders: {
if (state == StreamState::PendingHeaders) {
auto headers = std::make_unique<TestHeaderMapImpl>(
Fuzz::fromHeaders(response_action.continue_100_headers()));
Fuzz::fromHeaders(response_action.continue_headers()));
headers->setReferenceKey(Headers::get().Status, "100");
decoder_filter_->callbacks_->encode100ContinueHeaders(std::move(headers));
}
Expand Down
4 changes: 1 addition & 3 deletions test/common/http/http2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ envoy_package()
envoy_proto_library(
name = "codec_impl_fuzz_proto",
srcs = ["codec_impl_fuzz.proto"],
external_deps = ["well_known_protos"],
generate_python = 0,
deps = ["//test/fuzz:common_proto"],
)

Expand All @@ -23,7 +21,7 @@ envoy_cc_fuzz_test(
srcs = ["codec_impl_fuzz_test.cc"],
corpus = "codec_impl_corpus",
deps = [
":codec_impl_fuzz_proto",
":codec_impl_fuzz_proto_cc",
"//source/common/http:header_map_lib",
"//source/common/http/http2:codec_lib",
"//test/fuzz:utility_lib",
Expand Down
2 changes: 1 addition & 1 deletion test/common/http/http2/codec_impl_corpus/100-continue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ actions {
stream_action {
stream_id: 0
response {
continue_100_headers {
continue_headers {
headers {
key: ":status"
value: "100"
Expand Down
4 changes: 2 additions & 2 deletions test/common/http/http2/codec_impl_corpus/example
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ actions {
stream_action {
stream_id: 3
request {
reset: 0
reset_stream: 0
}
}
}
Expand Down Expand Up @@ -252,7 +252,7 @@ actions {
stream_action {
stream_id: 4
response {
reset: 0
reset_stream: 0
}
}
}
4 changes: 2 additions & 2 deletions test/common/http/http2/codec_impl_fuzz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ message NewStream {

message DirectionalAction {
oneof directional_action_selector {
test.fuzz.Headers continue_100_headers = 1;
test.fuzz.Headers continue_headers = 1;
test.fuzz.Headers headers = 2;
uint32 data = 3;
test.fuzz.Headers trailers = 4;
uint32 reset = 5;
uint32 reset_stream = 5;
bool read_disable = 6;
}
bool end_stream = 7;
Expand Down
9 changes: 4 additions & 5 deletions test/common/http/http2/codec_impl_fuzz_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ class Stream : public LinkedObject<Stream> {
const test::common::http::http2::DirectionalAction& directional_action) {
const bool end_stream = directional_action.end_stream();
switch (directional_action.directional_action_selector_case()) {
case test::common::http::http2::DirectionalAction::kContinue100Headers: {
case test::common::http::http2::DirectionalAction::kContinueHeaders: {
if (state == StreamState::PendingHeaders) {
Http::TestHeaderMapImpl headers =
Fuzz::fromHeaders(directional_action.continue_100_headers());
Http::TestHeaderMapImpl headers = Fuzz::fromHeaders(directional_action.continue_headers());
headers.setReferenceKey(Headers::get().Status, "100");
encoder.encode100ContinueHeaders(headers);
}
Expand Down Expand Up @@ -130,10 +129,10 @@ class Stream : public LinkedObject<Stream> {
}
break;
}
case test::common::http::http2::DirectionalAction::kReset: {
case test::common::http::http2::DirectionalAction::kResetStream: {
if (state != StreamState::Closed) {
encoder.getStream().resetStream(
static_cast<Http::StreamResetReason>(directional_action.reset()));
static_cast<Http::StreamResetReason>(directional_action.reset_stream()));
request_state_ = response_state_ = StreamState::Closed;
}
break;
Expand Down
12 changes: 5 additions & 7 deletions test/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ envoy_cc_test(
name = "config_impl_test",
srcs = ["config_impl_test.cc"],
deps = [
":route_fuzz_proto",
":route_fuzz_proto_cc",
"//source/common/config:metadata_lib",
"//source/common/config:rds_json_lib",
"//source/common/http:header_map_lib",
Expand All @@ -33,10 +33,9 @@ envoy_cc_test(
envoy_proto_library(
name = "header_parser_fuzz_proto",
srcs = ["header_parser_fuzz.proto"],
generate_python = 0,
deps = [
"//test/fuzz:common_proto",
"@envoy_api//envoy/api/v2/core:base_cc_proto",
"@envoy_api//envoy/api/v2/core:base_export",
],
)

Expand All @@ -45,7 +44,7 @@ envoy_cc_fuzz_test(
srcs = ["header_parser_fuzz_test.cc"],
corpus = "header_parser_corpus",
deps = [
":header_parser_fuzz_proto",
":header_parser_fuzz_proto_cc",
"//source/common/http:header_map_lib",
"//source/common/router:header_parser_lib",
"//test/fuzz:utility_lib",
Expand Down Expand Up @@ -88,10 +87,9 @@ envoy_cc_test(
envoy_proto_library(
name = "route_fuzz_proto",
srcs = ["route_fuzz.proto"],
generate_python = 0,
deps = [
"//test/fuzz:common_proto",
"@envoy_api//envoy/api/v2:rds_cc_proto",
"@envoy_api//envoy/api/v2:rds_export",
],
)

Expand All @@ -100,7 +98,7 @@ envoy_cc_fuzz_test(
srcs = ["route_fuzz_test.cc"],
corpus = "route_corpus",
deps = [
":route_fuzz_proto",
":route_fuzz_proto_cc",
"//source/common/router:config_lib",
"//test/fuzz:utility_lib",
"//test/mocks/server:server_mocks",
Expand Down
3 changes: 2 additions & 1 deletion test/common/router/header_parser_fuzz_test.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "common/http/header_map_impl.h"
#include "common/router/header_parser.h"

#include "test/common/router/header_parser_fuzz.pb.h"
#include "test/common/router/header_parser_fuzz.pb.validate.h"
#include "test/fuzz/fuzz_runner.h"
#include "test/fuzz/utility.h"

Expand All @@ -10,6 +10,7 @@ namespace Fuzz {

DEFINE_PROTO_FUZZER(const test::common::router::TestCase& input) {
try {
MessageUtil::validate(input);
Router::HeaderParserPtr parser =
Router::HeaderParser::configure(input.headers_to_add(), input.headers_to_remove());
Http::HeaderMapImpl header_map;
Expand Down
Loading