mirror of https://github.com/v2ray/v2ray-core
generate protobuf files on the fly
parent
52e1dfaeac
commit
7cbef6723c
|
@ -1,2 +1,2 @@
|
||||||
.generated.go
|
*.generated.go
|
||||||
.pb.go
|
*.pb.go
|
||||||
|
|
|
@ -5,6 +5,7 @@ go_import_path: v2ray.com/core
|
||||||
git:
|
git:
|
||||||
depth: 5
|
depth: 5
|
||||||
script:
|
script:
|
||||||
|
- go generate v2ray.com/core/...
|
||||||
- go test -tags json v2ray.com/core/...
|
- go test -tags json v2ray.com/core/...
|
||||||
after_success:
|
after_success:
|
||||||
- ./testing/coverage/coverall
|
- ./testing/coverage/coverall
|
||||||
|
|
|
@ -55,7 +55,7 @@ func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
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 {
|
if err != nil {
|
||||||
log.Fatalf("Failed to generate chacha_core.go: %v", err)
|
log.Fatalf("Failed to generate chacha_core.go: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,3 +1,5 @@
|
||||||
|
// +build fullgen
|
||||||
|
|
||||||
package geoip
|
package geoip
|
||||||
|
|
||||||
//go:generate go run geoip_gen.go
|
//go:generate go run geoip_gen.go
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue