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

Add option to edit fullPackageName for hashing in protoc-gen-ext #568

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions changelog/v0.40.3/replace-package-name-for-hashing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
changelog:
- type: NEW_FEATURE
issueLink: https://github.com/solo-io/gloo-mesh-enterprise/issues/17070
resolvesIssue: false
description: >
Add option to find and replace portion of the package name of a proto as it is used in the hash function.
It is used to provide an option for users to maintain the hashing logic when the package name of a proto changes.
10 changes: 9 additions & 1 deletion codegen/collector/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ type ProtocOptions struct {

// Extra flags to provide to invocations of protoc
ProtocExtraFlags []string

// When set, it will replace the value before the "=" with the value after it in the hash function of the generated code.
// This is use to maintain backward compatibility of the hash function in the case where the package name changes.
TransformPackageForHash string
}

type protoCompiler struct {
Expand Down Expand Up @@ -198,9 +202,13 @@ func (p *protoCompiler) writeDescriptors(protoFile, toFile string, imports []str
gogoArgs := append(defaultGogoArgs, p.customArgs...)

if compileProtos {
extArgs := gogoArgs
if p.protocOptions.TransformPackageForHash != "" {
extArgs = append(extArgs, fmt.Sprintf("transform_package_for_hash=%s", p.protocOptions.TransformPackageForHash))
}
cmd.Args = append(cmd.Args,
"--go_out="+strings.Join(gogoArgs, ",")+":"+p.descriptorOutDir,
"--ext_out="+strings.Join(gogoArgs, ",")+":"+p.descriptorOutDir,
"--ext_out="+strings.Join(extArgs, ",")+":"+p.descriptorOutDir,
)

// Externally specify mappings between proto files and generated Go code, for proto source files that do not specify `go_package`
Expand Down
24 changes: 12 additions & 12 deletions codegen/test/api/things.test.io/v1/test_api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/solo-io/go-list-licenses v0.0.4
github.com/solo-io/go-utils v0.21.4
github.com/solo-io/k8s-utils v0.0.1
github.com/solo-io/protoc-gen-ext v0.0.18
github.com/solo-io/protoc-gen-ext v0.0.20
github.com/solo-io/protoc-gen-openapi v0.2.4
github.com/spf13/pflag v1.0.5
go.uber.org/zap v1.26.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ github.com/solo-io/go-utils v0.21.4 h1:BUOrGNV+zQGIEKTS02SyPqevmkyG+AMl+0+czBg9a
github.com/solo-io/go-utils v0.21.4/go.mod h1:6e8K1spnMWwlnJRSNp/J84GEyJbrcK4Gm7i+ehzCi8c=
github.com/solo-io/k8s-utils v0.0.1 h1:e2alFsqTT7GU10d6cFDX2y+86J142DrsRwy5itvvZOI=
github.com/solo-io/k8s-utils v0.0.1/go.mod h1:53N9+9Gl2MwqIZJ7/ocA9gKvWt+6z7MPD2qKQix7oFE=
github.com/solo-io/protoc-gen-ext v0.0.18 h1:zSAL8NzWpJUGYoA5IyjHiKASNyHjR0uxBQ7eQS94i3A=
github.com/solo-io/protoc-gen-ext v0.0.18/go.mod h1:iGyCvmKmhJNXs5MgBcYFBF0om7LDnCVD2WwhOZGnqeA=
github.com/solo-io/protoc-gen-ext v0.0.20 h1:0cE+DvIp7G97/xlETL3didPQ1s5SHav5mkebljXk/Ws=
github.com/solo-io/protoc-gen-ext v0.0.20/go.mod h1:iGyCvmKmhJNXs5MgBcYFBF0om7LDnCVD2WwhOZGnqeA=
github.com/solo-io/protoc-gen-openapi v0.2.4 h1:9tqGhCAq83IRSzHhKDzpWnPlbPPORTM2izVxjLk0Ftw=
github.com/solo-io/protoc-gen-openapi v0.2.4/go.mod h1:osEjRl1miHqlq4Wl/8SEqHFoyydptPL1EzEdM9c4vfE=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down
40 changes: 20 additions & 20 deletions pkg/api/core.skv2.solo.io/v1/core.pb.clone.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading