mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-12-31 22:45:39 -05:00
@@ -20,6 +20,11 @@ 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"
|
||||
@@ -27,7 +32,7 @@ func main() {
|
||||
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
|
||||
@@ -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))
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user