cloudwego / kitex

Go RPC framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
6.92k stars 806 forks source link

kitex_gen is not generated due to the -use option #729

Open rushwing opened 1 year ago

rushwing commented 1 year ago

Describe the bug

Generate code with "-use" flag failed, error message: "kitex_gen is not generated due to the -use option"

To Reproduce

Steps to reproduce the behavior:

  1. Create a local module _samplemodule which may contains several services inside of it.
  2. cd into /cmd/service_a/ folder, exec command: "kitex -v -module sample_module -service service_a ../../kitex_gen/service_a ../../idl/service_a.thrift"
  3. Observe whether the related codes and folders are generated.
  4. kitex_gen folder was not generated, seen error message.

Expected behavior

Expected the project to be generated as the following layout:

. ├── client // contain the client code ├── cmd // contain the code of several services │ ├── api // contain service apis code │ ├── service_a │ │ ├── script // generated by kitex │ │ │ └── bootstrap.sh // bootstrap.sh generated by kitex │ │ ├── service // contain service code │ │ ├── build.sh // build.sh generated by kitex │ │ ├── go.mod // go.mod generated by kitex │ │ ├── handler.go // handler.go generated by kitex │ │ └── main.go // main.go generated by kitex │ └── service_b ├── kitex_gen // -use flag to specify the import path │ ├── service_a // generated by kitex │ └── service_b // generated by kitex ├── idl // project idls for different services ├── pkg // dependencies ├── go.mod // generated by kitex └── go.sum // generated by kitex

Screenshots

N/A

Kitex version:

v0.4.2

Environment:

The output of go env:

GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/danielwong/Library/Caches/go-build" GOENV="/Users/danielwong/Library/Application Support/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/danielwong/Dev/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/danielwong/Dev/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/homebrew/Cellar/go/1.19.2/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.2/libexec/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.19.2" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="xxxxx" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ql/05dw_j5x4pg52d5dfl4kbqgr0000gn/T/go-build2202954618=/tmp/go-build -gno-record-gcc-switches -fno-common"

Additional context

verbose log:

go: creating new go.mod: module sample_module go: to add module requirements and sums: go mod tidy thriftgo -v -o kitex_gen -g go:naming_style=golint,ignore_initialisms,gen_setter,gen_deep_equal,compatible_names,package_prefix=../../kitex_gen/service_a -p kitex=/Users/danielwong/Dev/go/bin/kitex:"Verbose=true,GenerateMain=true,GenerateInvoker=false,Version=v0.4.2,NoFastAPI=false,ModuleName=sample_module,ServiceName=service_a,Use=../../kitex_gen/service_a,IDLType=thrift,Includes=,ThriftOptions=naming_style=golint;ignore_initialisms;gen_setter;gen_deep_equal;compatible_names,ProtobufOptions=,IDL=../../idl/service_a.thrift,OutputPath=/Users/danielwong/Dev/XXX/sample_module/cmd/service_a,PackagePrefix=../../kitex_gen/service_a,CombineService=false,CopyIDL=false,Features=" ../../idl/service_a.thrift [INFO] Generating: "go" [INFO] option: naming_style=golint [INFO] option: ignore_initialisms= [INFO] option: gen_setter= [INFO] option: gen_deep_equal= [INFO] option: compatible_names= [INFO] option: package_prefix=../../kitex_gen/service_a [INFO] Processing ../../idl/service_a.thrift [INFO] Got 2 contents [INFO] Run plugin "kitex" [WARN] option:naming_style=golint [WARN] option:ignore_initialisms= [WARN] option:gen_setter= [WARN] option:gen_deep_equal= [WARN] option:compatible_names= [WARN] option:package_prefix=../../kitex_gen/service_a [WARN] /Users/danielwong/Dev/XXX/sample_module/cmd/service_a/script/bootstrap.shexists. Skipped. [WARN] Write/Users/danielwong/Dev/XXX/sample_module/cmd/service_a/build.sh [WARN] Write/Users/danielwong/Dev/XXX/sample_module/cmd/service_a/main.go [WARN] Write/Users/danielwong/Dev/XXX/sample_module/cmd/service_a/handler.go kitex_gen is not generated due to the -use option

YangruiEmma commented 1 year ago

kitex_gen is not generated due to the -use option

this is not error msg, just tell you kitex_gen is not generated, because you use -use option

rushwing commented 1 year ago

kitex_gen is not generated due to the -use option

this is not error msg, just tell you kitex_gen is not generated, because you use -use option

https://github.com/cloudwego/kitex-examples/issues/30 I referred to this thread which said that we could use "-use" parameter to specify the import path.

So If I want to use "-use" parameter, I need to:

  1. generate kitex_gen folder first
  2. copy the kitex_gen folder to the place I want
  3. next time I could generate codes without generate kitex_gen folder again.

Correct me if I had something wrong.

YangruiEmma commented 1 year ago

could you tell me what is your requirement? -use just for the scenario that you don't want to generate kitex_gen in your project, you can specify another repository

rushwing commented 1 year ago

There would be more than one service in my project, but all of them included in one module. I want to generate the kitex_gen folder in the root folder of the project, rather than in each service folder. Just like the easynote demo project.

Screen Shot 2022-12-02 at 15 04 09

If I use default command to generate: kitex -module xxxx -service xxxx xxx.idl The kitex_gen folder would be generated under the service folder, rather than in the root folder of the project.

YangruiEmma commented 1 year ago

if you exec kitex tool in your root folder, then all service code will be generated together, and which subpackage depends on your idl definition namespace go