Skip to content

Commit

Permalink
add option to edit fullPackageName for hashing in protoc-gen-ext
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolasmatt committed Jun 10, 2024
1 parent 0442ff2 commit ec9fc72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
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
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-0.20240610195035-6e88af6fc769
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-0.20240610195035-6e88af6fc769 h1:B1x91gFzZef87x0U8gcrAFCRM0nNwK86p3GyuwMV/N0=
github.com/solo-io/protoc-gen-ext v0.0.20-0.20240610195035-6e88af6fc769/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

0 comments on commit ec9fc72

Please sign in to comment.