Skip to content

Commit 0f47eb1

Browse files
authored
fix(jzero): fix gen rpc with proto include (#370)
* fix(jzero): fix gen rpc with proto include * feat(docs): add v1.1.2 release
1 parent fb1cf8e commit 0f47eb1

8 files changed

Lines changed: 45 additions & 12 deletions

File tree

cmd/jzero/internal/command/gen/gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ func GetCommand() *cobra.Command {
114114

115115
genZRpcClientCmd.Flags().StringSliceP("desc", "", []string{}, "set desc path")
116116
genZRpcClientCmd.Flags().StringSliceP("desc-ignore", "", []string{}, "set desc ignore path")
117+
genZRpcClientCmd.Flags().StringSliceP("proto-include", "", []string{}, "proto include path")
117118
genZRpcClientCmd.Flags().StringP("output", "o", "zrpcclient-go", "generate rpcclient code")
118119
genZRpcClientCmd.Flags().StringP("goModule", "", "", "set go module name")
119120
genZRpcClientCmd.Flags().StringP("goVersion", "", "", "set go version, only effect when having goModule flag")

cmd/jzero/internal/command/gen/genrpc/genrpc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func (jr *JzeroRpc) Gen() (map[string]rpcparser.Proto, error) {
186186
protoDir := filepath.Join("desc", "proto")
187187
thirdPartyProtoDir := filepath.Join("desc", "proto", "third_party")
188188
protoParser.ImportPaths = []string{protoDir, thirdPartyProtoDir}
189+
for _, v := range config.C.Gen.ProtoInclude {
190+
protoParser.ImportPaths = append(protoParser.ImportPaths, v)
191+
}
189192
protoParser.IncludeSourceCodeInfo = true
190193

191194
for _, v := range protoFiles {

cmd/jzero/internal/command/gen/genzrpcclient/genzrpcclient.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func Generate(genModule bool) (err error) {
193193
protoDir := filepath.Join("desc", "proto")
194194
thirdPartyProtoDir := filepath.Join("desc", "proto", "third_party")
195195
protoParser.ImportPaths = []string{protoDir, thirdPartyProtoDir}
196+
for _, v := range config.C.Gen.Zrpcclient.ProtoInclude {
197+
protoParser.ImportPaths = append(protoParser.ImportPaths, v)
198+
}
196199
protoParser.IncludeSourceCodeInfo = true
197200

198201
rel, err := filepath.Rel(config.C.ProtoDir(), fp)
@@ -281,8 +284,8 @@ func Generate(genModule bool) (err error) {
281284
}())
282285
}
283286

284-
if len(config.C.Gen.ProtoInclude) > 0 {
285-
protocCmd += fmt.Sprintf(" -I%s ", strings.Join(config.C.Gen.ProtoInclude, " -I"))
287+
if len(config.C.Gen.Zrpcclient.ProtoInclude) > 0 {
288+
protocCmd += fmt.Sprintf(" -I%s ", strings.Join(config.C.Gen.Zrpcclient.ProtoInclude, " -I"))
286289
}
287290

288291
logx.Debugf(protocCmd)
@@ -427,6 +430,10 @@ func generatePluginFiles(plugins []plugin.Plugin) error {
427430
protoParser.InferImportPaths = false
428431

429432
protoParser.ImportPaths = []string{pluginProtoDir, pluginThirdPartyProtoDir}
433+
434+
for _, v := range config.C.Gen.Zrpcclient.ProtoInclude {
435+
protoParser.ImportPaths = append(protoParser.ImportPaths, v)
436+
}
430437
protoParser.IncludeSourceCodeInfo = true
431438

432439
rel, err := filepath.Rel(pluginProtoDir, fp)
@@ -504,8 +511,8 @@ func generatePluginFiles(plugins []plugin.Plugin) error {
504511
}())
505512
}
506513

507-
if len(config.C.Gen.ProtoInclude) > 0 {
508-
protocCmd += fmt.Sprintf(" -I%s ", strings.Join(config.C.Gen.ProtoInclude, " -I"))
514+
if len(config.C.Gen.Zrpcclient.ProtoInclude) > 0 {
515+
protocCmd += fmt.Sprintf(" -I%s ", strings.Join(config.C.Gen.Zrpcclient.ProtoInclude, " -I"))
509516
}
510517

511518
logx.Debugf(protocCmd)
@@ -677,8 +684,8 @@ func genPluginNoRpcServiceExcludeThirdPartyProto(plugin plugin.Plugin, goModule,
677684
}(),
678685
)
679686

680-
if len(config.C.Gen.ProtoInclude) > 0 {
681-
command += fmt.Sprintf(" -I%s ", strings.Join(config.C.Gen.ProtoInclude, " -I"))
687+
if len(config.C.Gen.Zrpcclient.ProtoInclude) > 0 {
688+
command += fmt.Sprintf(" -I%s ", strings.Join(config.C.Gen.Zrpcclient.ProtoInclude, " -I"))
682689
}
683690

684691
logx.Debug(command)

cmd/jzero/internal/config/config.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@ type GenSwaggerConfig struct {
146146
type GenZrpcclientConfig struct {
147147
Hooks HooksConfig `mapstructure:"hooks"`
148148

149-
Desc []string `mapstructure:"desc"`
150-
DescIgnore []string `mapstructure:"desc-ignore"`
151-
Output string `mapstructure:"output"`
152-
GoVersion string `mapstructure:"goVersion"`
153-
GoModule string `mapstructure:"goModule"`
154-
GoPackage string `mapstructure:"goPackage"`
149+
Desc []string `mapstructure:"desc"`
150+
DescIgnore []string `mapstructure:"desc-ignore"`
151+
ProtoInclude []string `mapstructure:"proto-include"`
152+
Output string `mapstructure:"output"`
153+
GoVersion string `mapstructure:"goVersion"`
154+
GoModule string `mapstructure:"goModule"`
155+
GoPackage string `mapstructure:"goPackage"`
155156
}
156157

157158
type TemplateConfig struct {

docs/src/release/v1.0.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ order: 2
1818

1919
```shell
2020
jzero upgrade --channel v1.0.1
21+
jzero gen
2122
```

docs/src/release/v1.1.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ order: 3
3838

3939
```shell
4040
jzero upgrade --channel v1.1.0
41+
jzero gen
4142
```

docs/src/release/v1.1.1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ order: 4
1515

1616
```shell
1717
jzero upgrade --channel v1.1.1
18+
jzero gen
1819
```

docs/src/release/v1.1.2.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: v1.1.2
3+
icon: catppuccin:release
4+
order: 5
5+
---
6+
7+
## 问题修复
8+
9+
### cmd/jzero
10+
11+
* 修复生成 rpc 代码: 指定 proto-include 时不生效.([#370](https://github.com/jzero-io/jzero/pull/370))
12+
13+
## 更新步骤
14+
15+
```shell
16+
jzero upgrade --channel v1.1.2
17+
jzero gen
18+
```

0 commit comments

Comments
 (0)