Skip to content

Commit

Permalink
Make variables of vprotogen easier to find
Browse files Browse the repository at this point in the history
  • Loading branch information
Loyalsoldier committed Oct 4, 2020
1 parent edefca7 commit 9b249f9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 3 additions & 10 deletions infra/vprotogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,10 @@ import (
"runtime"
"strings"

"v2ray.com/core"
"v2ray.com/core/common"
)

var protoFilesUsingProtocGenGoFast = map[string]bool{"proxy/vless/encoding/addons.proto": true}

var protocMap = map[string]string{
"windows": filepath.Join(".dev", "protoc", "windows", "protoc.exe"),
"darwin": filepath.Join(".dev", "protoc", "macos", "protoc"),
"linux": filepath.Join(".dev", "protoc", "linux", "protoc"),
}

func main() {
pwd, wdErr := os.Getwd()
if wdErr != nil {
Expand All @@ -27,7 +20,7 @@ func main() {
}

GOBIN := common.GetGOBIN()
protoc := protocMap[runtime.GOOS]
protoc := core.ProtocMap[runtime.GOOS]

protoFilesMap := make(map[string][]string)
walkErr := filepath.Walk("./", func(path string, info os.FileInfo, err error) error {
Expand Down Expand Up @@ -56,7 +49,7 @@ func main() {
for _, files := range protoFilesMap {
for _, relProtoFile := range files {
var args []string
if protoFilesUsingProtocGenGoFast[relProtoFile] {
if core.ProtoFilesUsingProtocGenGoFast[relProtoFile] {
args = []string{"--gofast_out", pwd, "--plugin", "protoc-gen-gofast=" + GOBIN + "/protoc-gen-gofast"}
} else {
args = []string{"--go_out", pwd, "--go-grpc_out", pwd, "--plugin", "protoc-gen-go=" + GOBIN + "/protoc-gen-go", "--plugin", "protoc-gen-go-grpc=" + GOBIN + "/protoc-gen-go-grpc"}
Expand Down
13 changes: 13 additions & 0 deletions proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ package core
//go:generate go install -v google.golang.org/grpc/cmd/protoc-gen-go-grpc
//go:generate go install -v github.com/gogo/protobuf/protoc-gen-gofast
//go:generate go run ./infra/vprotogen/main.go

import "path/filepath"

// ProtoFilesUsingProtocGenGoFast is the map of Proto files
// that use `protoc-gen-gofast` to generate pb.go files
var ProtoFilesUsingProtocGenGoFast = map[string]bool{"proxy/vless/encoding/addons.proto": true}

// ProtocMap is the map of paths to `protoc` binary excutable files of specific platform
var ProtocMap = map[string]string{
"windows": filepath.Join(".dev", "protoc", "windows", "protoc.exe"),
"darwin": filepath.Join(".dev", "protoc", "macos", "protoc"),
"linux": filepath.Join(".dev", "protoc", "linux", "protoc"),
}

0 comments on commit 9b249f9

Please sign in to comment.