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

Update vprotogen #366

Merged
merged 2 commits into from
Oct 29, 2020
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
2 changes: 1 addition & 1 deletion app/log/command/config_grpc.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 app/proxyman/command/command_grpc.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 app/router/command/command_grpc.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 app/stats/command/command_grpc.pb.go

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

90 changes: 8 additions & 82 deletions infra/vprotogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,19 @@ func main() {
}

GOBIN := common.GetGOBIN()
binPath := os.Getenv("PATH")
pathSlice := []string{binPath, GOBIN, pwd}
binPath = strings.Join(pathSlice, string(os.PathListSeparator))
os.Setenv("PATH", binPath)

EXE := ""
if runtime.GOOS == "windows" {
EXE = ".exe"
}
protoc := "protoc" + EXE

if path, err := exec.LookPath(protoc); err != nil {
fmt.Println("Make sure that you have `" + protoc + "` in your system or current path, please visit https://github.com/protocolbuffers/protobuf/releases")
fmt.Println("Make sure that you have `" + protoc + "` in your system path or current path. To download it, please visit https://github.com/protocolbuffers/protobuf/releases")
os.Exit(1)
} else {
protoc = path
Expand Down Expand Up @@ -61,14 +66,13 @@ func main() {
for _, relProtoFile := range files {
var args []string
if core.ProtoFilesUsingProtocGenGoFast[relProtoFile] {
args = []string{"--gofast_out", pwd, "--plugin", "protoc-gen-gofast=" + GOBIN + "/protoc-gen-gofast" + EXE}
args = []string{"--gofast_out", pwd, "--gofast_opt", "paths=source_relative", "--plugin", "protoc-gen-gofast=" + GOBIN + "/protoc-gen-gofast" + EXE}
} else {
args = []string{"--go_out", pwd, "--go-grpc_out", pwd, "--plugin", "protoc-gen-go=" + GOBIN + "/protoc-gen-go" + EXE, "--plugin", "protoc-gen-go-grpc=" + GOBIN + "/protoc-gen-go-grpc" + EXE}
args = []string{"--go_out", pwd, "--go_opt", "paths=source_relative", "--go-grpc_out", pwd, "--go-grpc_opt", "paths=source_relative", "--plugin", "protoc-gen-go=" + GOBIN + "/protoc-gen-go" + EXE, "--plugin", "protoc-gen-go-grpc=" + GOBIN + "/protoc-gen-go-grpc" + EXE}
}
args = append(args, relProtoFile)
cmd := exec.Command(protoc, args...)
cmd.Env = append(cmd.Env, os.Environ()...)
cmd.Env = append(cmd.Env, "GOBIN="+GOBIN)
output, cmdErr := cmd.CombinedOutput()
if len(output) > 0 {
fmt.Println(string(output))
Expand All @@ -79,82 +83,4 @@ func main() {
}
}
}

moduleName, gmnErr := common.GetModuleName(pwd)
if gmnErr != nil {
fmt.Println(gmnErr)
os.Exit(1)
}
modulePath := filepath.Join(strings.Split(moduleName, "/")...)

pbGoFilesMap := make(map[string][]string)
walkErr2 := filepath.Walk(modulePath, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println(err)
return err
}

if info.IsDir() {
return nil
}

dir := filepath.Dir(path)
filename := filepath.Base(path)
if strings.HasSuffix(filename, ".pb.go") {
pbGoFilesMap[dir] = append(pbGoFilesMap[dir], path)
}

return nil
})
if walkErr2 != nil {
fmt.Println(walkErr2)
os.Exit(1)
}

var err error
for _, srcPbGoFiles := range pbGoFilesMap {
for _, srcPbGoFile := range srcPbGoFiles {
var dstPbGoFile string
dstPbGoFile, err = filepath.Rel(modulePath, srcPbGoFile)
if err != nil {
fmt.Println(err)
continue
}
err = os.Link(srcPbGoFile, dstPbGoFile)
if err != nil {
if os.IsNotExist(err) {
fmt.Printf("'%s' does not exist\n", srcPbGoFile)
continue
}
if os.IsPermission(err) {
fmt.Println(err)
continue
}
if os.IsExist(err) {
err = os.Remove(dstPbGoFile)
if err != nil {
fmt.Printf("Failed to delete file '%s'\n", dstPbGoFile)
continue
}
err = os.Rename(srcPbGoFile, dstPbGoFile)
if err != nil {
fmt.Printf("Can not move '%s' to '%s'\n", srcPbGoFile, dstPbGoFile)
}
continue
}
}
err = os.Rename(srcPbGoFile, dstPbGoFile)
if err != nil {
fmt.Printf("Can not move '%s' to '%s'\n", srcPbGoFile, dstPbGoFile)
}
continue
}
}

if err == nil {
err = os.RemoveAll(strings.Split(modulePath, "/")[0])
if err != nil {
fmt.Println(err)
}
}
}
Loading