Skip to content

Commit

Permalink
optimize(tool): use embedded thriftgo as default option (#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeyJavaBean authored Nov 6, 2024
1 parent bd00ab7 commit f66a3a7
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 37 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/cloudwego/localsession v0.1.1
github.com/cloudwego/netpoll v0.6.4
github.com/cloudwego/runtimex v0.1.0
github.com/cloudwego/thriftgo v0.3.17
github.com/cloudwego/thriftgo v0.3.18
github.com/golang/mock v1.6.0
github.com/google/pprof v0.0.0-20240727154555-813a5fbdbec8
github.com/jhump/protoreflect v1.8.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/cloudwego/netpoll v0.6.4 h1:z/dA4sOTUQof6zZIO4QNnLBXsDFFFEos9OOGloR6k
github.com/cloudwego/netpoll v0.6.4/go.mod h1:BtM+GjKTdwKoC8IOzD08/+8eEn2gYoiNLipFca6BVXQ=
github.com/cloudwego/runtimex v0.1.0 h1:HG+WxWoj5/CDChDZ7D99ROwvSMkuNXAqt6hnhTTZDiI=
github.com/cloudwego/runtimex v0.1.0/go.mod h1:23vL/HGV0W8nSCHbe084AgEBdDV4rvXenEUMnUNvUd8=
github.com/cloudwego/thriftgo v0.3.17 h1:k0iQe2jEAN1WhPsXWvatwHzoxObUSX2Nw5NqdnywS8k=
github.com/cloudwego/thriftgo v0.3.17/go.mod h1:AdLEJJVGW/ZJYvkkYAZf5SaJH+pA3OyC801WSwqcBwI=
github.com/cloudwego/thriftgo v0.3.18 h1:gnr1vz7G3RbwwCK9AMKHZf63VYGa7ene6WbI9VrBJSw=
github.com/cloudwego/thriftgo v0.3.18/go.mod h1:AdLEJJVGW/ZJYvkkYAZf5SaJH+pA3OyC801WSwqcBwI=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
4 changes: 3 additions & 1 deletion tool/cmd/kitex/args/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ func (a *Arguments) buildFlags(version string) *flag.FlagSet {
f.BoolVar(&a.NoDependencyCheck, "no-dependency-check", false,
"Skip dependency checking.")
f.BoolVar(&a.Rapid, "rapid", false,
"Use embedded thriftgo.")
"Try some experimental features to generate code faster.")
f.BoolVar(&a.LocalThriftgo, "local_thriftgo", false,
"Use local thriftgo exec instead of kitex embedded thriftgo.")
f.Var(&a.BuiltinTpl, "tpl", "Specify kitex built-in template.")

a.RecordCmd = os.Args
Expand Down
3 changes: 2 additions & 1 deletion tool/cmd/kitex/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ func main() {
os.Exit(1)
}

if args.IDLType == "thrift" && args.Rapid {
if args.IDLType == "thrift" && !args.LocalThriftgo {
err = sdk.InvokeThriftgoBySDK(curpath, cmd)
} else {
log.Warn("You are using local thriftgo. Please make sure the version is matched with kitex tool.")
err = kargs.ValidateCMD(cmd.Path, args.IDLType)
if err != nil {
log.Warn(err)
Expand Down
31 changes: 1 addition & 30 deletions tool/cmd/kitex/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package utils

import (
"os"
"os/exec"
"strings"

Expand All @@ -29,45 +28,17 @@ func OnKitexToolNormalExit(args kargs.Arguments) {
cmd := "go mod edit -replace github.com/apache/thrift=github.com/apache/[email protected]"
argv := strings.Split(cmd, " ")
err := exec.Command(argv[0], argv[1:]...).Run()

res := "Done"
if err != nil {
res = err.Error()
log.Warn("Adding apache/[email protected] to go.mod failed:%s\n please execute the following command manually:\n%s", err.Error(), cmd)
}
log.Warn("Adding apache/[email protected] to go.mod for generated code ..........", res)
}

log.Warn("Code Generation is Done!")

// remove kitex.yaml generated from v0.4.4 which is renamed as kitex_info.yaml
if args.ServiceName != "" {
DeleteKitexYaml()
}

// If hessian option is java_extension, replace *java.Object to java.Object
if thriftgo.EnableJavaExtension(args.Config) {
if err := thriftgo.Hessian2PatchByReplace(args.Config, ""); err != nil {
log.Warn("replace java object fail, you can fix it then regenerate", err)
}
}
}

func DeleteKitexYaml() {
// try to read kitex.yaml
data, err := os.ReadFile("kitex.yaml")
if err != nil {
if !os.IsNotExist(err) {
log.Warn("kitex.yaml, which is used to record tool info, is deprecated, it's renamed as kitex_info.yaml, you can delete it or ignore it.")
}
return
}
// if kitex.yaml exists, check content and delete it.
if strings.HasPrefix(string(data), "kitexinfo:") {
err = os.Remove("kitex.yaml")
if err != nil {
log.Warn("kitex.yaml, which is used to record tool info, is deprecated, it's renamed as kitex_info.yaml, you can delete it or ignore it.")
} else {
log.Warn("kitex.yaml, which is used to record tool info, is deprecated, it's renamed as kitex_info.yaml, so it's automatically deleted now.")
}
}
}
4 changes: 3 additions & 1 deletion tool/internal_pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ type Config struct {

NoDependencyCheck bool
Rapid bool
BuiltinTpl util.StringSlice // specify the built-in template to use
LocalThriftgo bool

BuiltinTpl util.StringSlice // specify the built-in template to use
}

// Pack packs the Config into a slice of "key=val" strings.
Expand Down
2 changes: 1 addition & 1 deletion tool/internal_pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func TestConfig_Pack(t *testing.T) {
{
name: "some",
fields: fields{Features: []feature{feature(999)}, ThriftPluginTimeLimit: 30 * time.Second},
wantRes: []string{"Verbose=false", "GenerateMain=false", "GenerateInvoker=false", "Version=", "NoFastAPI=false", "ModuleName=", "ServiceName=", "Use=", "IDLType=", "Includes=", "ThriftOptions=", "ProtobufOptions=", "Hessian2Options=", "IDL=", "OutputPath=", "PackagePrefix=", "CombineService=false", "CopyIDL=false", "ProtobufPlugins=", "Features=999", "FrugalPretouch=false", "ThriftPluginTimeLimit=30s", "CompilerPath=", "ExtensionFile=", "Record=false", "RecordCmd=", "TemplateDir=", "GenPath=", "DeepCopyAPI=false", "Protocol=", "HandlerReturnKeepResp=false", "NoDependencyCheck=false", "Rapid=false", "BuiltinTpl="},
wantRes: []string{"Verbose=false", "GenerateMain=false", "GenerateInvoker=false", "Version=", "NoFastAPI=false", "ModuleName=", "ServiceName=", "Use=", "IDLType=", "Includes=", "ThriftOptions=", "ProtobufOptions=", "Hessian2Options=", "IDL=", "OutputPath=", "PackagePrefix=", "CombineService=false", "CopyIDL=false", "ProtobufPlugins=", "Features=999", "FrugalPretouch=false", "ThriftPluginTimeLimit=30s", "CompilerPath=", "ExtensionFile=", "Record=false", "RecordCmd=", "TemplateDir=", "GenPath=", "DeepCopyAPI=false", "Protocol=", "HandlerReturnKeepResp=false", "NoDependencyCheck=false", "Rapid=false", "LocalThriftgo=false", "BuiltinTpl="},
},
}
for _, tt := range tests {
Expand Down

0 comments on commit f66a3a7

Please sign in to comment.