1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-26 01:15:38 +00:00

generate protobuf files on the fly

This commit is contained in:
Darien Raymond 2017-01-02 20:43:41 +01:00
parent 52e1dfaeac
commit 7cbef6723c
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
7 changed files with 71 additions and 5 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
.generated.go
.pb.go
*.generated.go
*.pb.go

View File

@ -5,6 +5,7 @@ go_import_path: v2ray.com/core
git:
depth: 5
script:
- go generate v2ray.com/core/...
- go test -tags json v2ray.com/core/...
after_success:
- ./testing/coverage/coverall

View File

@ -55,7 +55,7 @@ func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
}
func main() {
file, err := os.OpenFile("chacha_core_generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
file, err := os.OpenFile("chacha_core.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
log.Fatalf("Failed to generate chacha_core.go: %v", err)
}

View File

@ -0,0 +1,7 @@
// +build windows darwin linux
package genproto
//go:generate go get -u "github.com/golang/protobuf/protoc-gen-go"
//go:generate go get -u "github.com/golang/protobuf/proto"
//go:generate go run main.go

57
tools/genproto/main.go Normal file
View File

@ -0,0 +1,57 @@
// +build generate
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
var protocMap = map[string]string{
"windows": filepath.Join(os.Getenv("GOPATH"), "src", "v2ray.com", "core", ".dev", "protoc", "windows", "protoc.exe"),
"darwin": filepath.Join(os.Getenv("GOPATH"), "src", "v2ray.com", "core", ".dev", "protoc", "macos", "protoc"),
"linux": filepath.Join(os.Getenv("GOPATH"), "src", "v2ray.com", "core", ".dev", "protoc", "linux", "protoc"),
}
func main() {
protofiles := make(map[string][]string)
protoc := protocMap[runtime.GOOS]
gosrc := filepath.Join(os.Getenv("GOPATH"), "src")
filepath.Walk(filepath.Join(gosrc, "v2ray.com", "core"), 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, ".proto") {
protofiles[dir] = append(protofiles[dir], path)
}
return nil
})
for _, files := range protofiles {
args := []string{"--proto_path", gosrc, "--go_out", gosrc}
args = append(args, files...)
cmd := exec.Command(protoc, args...)
cmd.Env = append(cmd.Env, os.Environ()...)
output, err := cmd.CombinedOutput()
if len(output) > 0 {
fmt.Println(string(output))
}
if err != nil {
fmt.Println(err)
}
}
}

View File

@ -1,3 +1,5 @@
// +build fullgen
package geoip
//go:generate go run geoip_gen.go

File diff suppressed because one or more lines are too long