Skip to content

Commit

Permalink
CPP: modify package namespace to split on dot (#838)
Browse files Browse the repository at this point in the history
Fixing C++ namespace to only use dot-notation splitting.

For example, a proto that is in a package: `my_project` will use the
same C++ namespace, avoiding the conversion to `my::project` as is done
prior to this PR.

Also updated protoc-gen-star to v2.0.4 @496ad1ac90a4 (ability to use
`SplitOnDot`) using:
`go get github.com/lyft/protoc-gen-star/v2@496ad1ac90a4`

Fixes #822

---------

Signed-off-by: Adi Suissa-Peleg <[email protected]>
  • Loading branch information
adisuissa authored Mar 15, 2024
1 parent 03a680d commit 7d833c1
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def go_third_party():
go_repository(
name = "com_github_lyft_protoc_gen_star_v2",
importpath = "github.com/lyft/protoc-gen-star/v2",
sum = "h1:/3+/2sWyXeMLzKd1bX+ixWKgEMsULrIivpDsuaF441o=",
version = "v2.0.3",
sum = "h1:sIXJOMrYnQZJu7OB7ANSF4MYri2fTEGIsRLz6LwI4xE=",
version = "v2.0.4-0.20230330145011-496ad1ac90a4",
)
go_repository(
name = "com_github_pkg_errors",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/iancoleman/strcase v0.3.0
github.com/lyft/protoc-gen-star/v2 v2.0.3
github.com/lyft/protoc-gen-star/v2 v2.0.4-0.20230330145011-496ad1ac90a4
golang.org/x/net v0.20.0
google.golang.org/protobuf v1.32.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lyft/protoc-gen-star/v2 v2.0.3 h1:/3+/2sWyXeMLzKd1bX+ixWKgEMsULrIivpDsuaF441o=
github.com/lyft/protoc-gen-star/v2 v2.0.3/go.mod h1:amey7yeodaJhXSbf/TlLvWiqQfLOSpEk//mLlc+axEk=
github.com/lyft/protoc-gen-star/v2 v2.0.4-0.20230330145011-496ad1ac90a4 h1:sIXJOMrYnQZJu7OB7ANSF4MYri2fTEGIsRLz6LwI4xE=
github.com/lyft/protoc-gen-star/v2 v2.0.4-0.20230330145011-496ad1ac90a4/go.mod h1:amey7yeodaJhXSbf/TlLvWiqQfLOSpEk//mLlc+axEk=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
8 changes: 4 additions & 4 deletions templates/cc/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ pgv::Validator<{{ class . }}> {{ staticVarName . }}(static_cast<bool(*)(const {{
} // namespace validate
} // namespace pgv
{{ range .Package.ProtoName.Split }}
{{ range .Package.ProtoName.SplitOnDot }}
namespace {{ . }} {
{{- end }}
{{ range .AllMessages }}
{{- template "msg" . }}
{{ end }}
{{ range .Package.ProtoName.Split -}}
{{ range .Package.ProtoName.SplitOnDot -}}
} // namespace
{{ end }}
`
Expand All @@ -62,7 +62,7 @@ const headerFileTpl = `// Code generated by protoc-gen-validate
#include "validate/validate.h"
#include "{{ output .File ".h" }}"
{{ range .Package.ProtoName.Split }}
{{ range .Package.ProtoName.SplitOnDot }}
namespace {{ . }} {
{{- end }}
Expand All @@ -72,7 +72,7 @@ using std::string;
{{- template "decl" . }}
{{ end }}
{{ range .Package.ProtoName.Split -}}
{{ range .Package.ProtoName.SplitOnDot -}}
} // namespace
{{ end }}
Expand Down
2 changes: 1 addition & 1 deletion templates/cc/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (fns CCFuncs) className(ent childEntity) string {
}

func (fns CCFuncs) packageName(msg pgs.Entity) string {
return "::" + strings.Join(msg.Package().ProtoName().Split(), "::")
return "::" + strings.Join(msg.Package().ProtoName().SplitOnDot(), "::")
}

func (fns CCFuncs) quote(s interface {
Expand Down
4 changes: 2 additions & 2 deletions templates/ccnop/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const headerFileTpl = `// Code generated by protoc-gen-validate
#include "validate/validate.h"
#include "{{ output .File ".h" }}"
{{ range .Package.ProtoName.Split }}
{{ range .Package.ProtoName.SplitOnDot }}
namespace {{ . }} {
{{- end }}
Expand All @@ -21,7 +21,7 @@ using std::string;
extern inline bool Validate(__attribute__((unused)) const {{ class . }}& m, __attribute__((unused)) pgv::ValidationMsg* err) { return true; }
{{ end }}
{{ range .Package.ProtoName.Split -}}
{{ range .Package.ProtoName.SplitOnDot -}}
} // namespace
{{ end }}
Expand Down

0 comments on commit 7d833c1

Please sign in to comment.