Skip to content

Commit

Permalink
cc: Convert base file name to screaming snake case
Browse files Browse the repository at this point in the history
This patch converts the base file name into screaming snake case instead
of upper for cc macro generation.

This is motivated by:

INFO: From Compiling external/com_github_openzipkin_zipkinapi/zipkin-jsonv2.pb.validate.cc:
In file included from bazel-out/k8-opt/bin/external/com_github_openzipkin_zipkinapi/zipkin-jsonv2.pb.validate.cc:5:
bazel-out/k8-opt/bin/external/com_github_openzipkin_zipkinapi/zipkin-jsonv2.pb.validate.h:37:31: warning: ISO C99 requires whitespace after the macro name [-Wc99-extensions]
                              ^
1 warning generated.

As reported in
envoyproxy/envoy#6985 (comment).

Signed-off-by: Dhi Aurrahman <dio@tetrate.io>
  • Loading branch information
dio committed Sep 4, 2019
1 parent b2e4ad3 commit dbffd7c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
1 change: 1 addition & 0 deletions templates/cc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//templates/shared:go_default_library",
"//vendor/github.com/iancoleman/strcase:go_default_library",
"//vendor/github.com/lyft/protoc-gen-star:go_default_library",
"//vendor/github.com/lyft/protoc-gen-star/lang/go:go_default_library",
"@com_github_golang_protobuf//ptypes:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion templates/cc/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ using std::string;
} // namespace
{{ end }}
#define X_{{ .Package.ProtoName.ScreamingSnakeCase }}_{{ .File.InputPath.BaseName | upper }}(X) \
#define X_{{ .Package.ProtoName.ScreamingSnakeCase }}_{{ .File.InputPath.BaseName | screaming_snake_case }}(X) \
{{ range .AllMessages -}}
X({{class . }}) \
{{ end }}
Expand Down
8 changes: 5 additions & 3 deletions templates/cc/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/duration"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/iancoleman/strcase"
pgs "github.com/lyft/protoc-gen-star"
pgsgo "github.com/lyft/protoc-gen-star/lang/go"
)
Expand Down Expand Up @@ -95,9 +96,10 @@ func RegisterHeader(tpl *template.Template, params pgs.Parameters) {
fns := CCFuncs{pgsgo.InitContext(params)}

tpl.Funcs(map[string]interface{}{
"class": fns.className,
"output": fns.output,
"upper": strings.ToUpper,
"class": fns.className,
"output": fns.output,
"upper": strings.ToUpper,
"screaming_snake_case": strcase.ToScreamingSnake,
})

template.Must(tpl.Parse(headerFileTpl))
Expand Down
19 changes: 10 additions & 9 deletions tests/harness/cases/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load(
"//bazel:pgv_proto_library.bzl",
"pgv_gogo_proto_library",
"pgv_go_proto_library",
"pgv_cc_proto_library",
"pgv_go_proto_library",
"pgv_gogo_proto_library",
"pgv_java_proto_library",
"pgv_python_proto_library",
)
Expand All @@ -17,6 +17,7 @@ proto_library(
"bool.proto",
"bytes.proto",
"enums.proto",
"filename-with-dash.proto",
"kitchen_sink.proto",
"maps.proto",
"messages.proto",
Expand All @@ -31,8 +32,8 @@ proto_library(
],
visibility = ["//visibility:public"],
deps = [
"//validate:validate_proto",
"//tests/harness/cases/other_package:embed_proto",
"//validate:validate_proto",
"@com_google_protobuf//:any_proto",
"@com_google_protobuf//:duration_proto",
"@com_google_protobuf//:timestamp_proto",
Expand Down Expand Up @@ -70,34 +71,34 @@ pgv_gogo_proto_library(

pgv_cc_proto_library(
name = "cc",
deps = [":cases_proto"],
cc_deps = [
"//tests/harness/cases/other_package:cc",
],
visibility = ["//tests:__subpackages__"],
deps = [":cases_proto"],
)

java_proto_library(
name = "cases_java_proto",
deps = [":cases_proto"],
visibility = ["//visibility:public"],
deps = [":cases_proto"],
)

pgv_java_proto_library(
name = "java",
deps = [":cases_proto"],
visibility = ["//visibility:public"],
java_deps = [
":cases_java_proto",
"//tests/harness/cases/other_package:java",
],
visibility = ["//visibility:public"],
deps = [":cases_proto"],
)

pgv_python_proto_library(
name = "python",
deps = [":cases_proto"],
visibility = ["//visibility:public"],
python_deps = [
"//tests/harness/cases/other_package:python",
],
visibility = ["//visibility:public"],
deps = [":cases_proto"],
)
6 changes: 6 additions & 0 deletions tests/harness/cases/filename-with-dash.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
syntax = "proto3";

package tests.harness.cases;
option go_package = "cases";

import "validate/validate.proto";
2 changes: 2 additions & 0 deletions tests/harness/cc/harness.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "tests/harness/cases/bytes.pb.validate.h"
#include "tests/harness/cases/enums.pb.h"
#include "tests/harness/cases/enums.pb.validate.h"
#include "tests/harness/cases/filename-with-dash.pb.h"
#include "tests/harness/cases/filename-with-dash.pb.validate.h"
#include "tests/harness/cases/maps.pb.h"
#include "tests/harness/cases/maps.pb.validate.h"
#include "tests/harness/cases/messages.pb.h"
Expand Down

0 comments on commit dbffd7c

Please sign in to comment.