-
Notifications
You must be signed in to change notification settings - Fork 1
/
genprotos.go
70 lines (62 loc) · 1.61 KB
/
genprotos.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build ignore
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)
func genProtos() error {
for _, pb := range []struct {
Dir string
Basename string
Package string
}{
{
Dir: "internal/apiflagdata",
Basename: "go_api_enum.proto",
Package: "google.golang.org/open2opaque/internal/apiflagdata",
},
{
Dir: "internal/dashboard",
Basename: "stats.proto",
Package: "google.golang.org/open2opaque/internal/dashboard",
},
{
Dir: "internal/fix/testdata/proto2test_go_proto",
Basename: "proto2test.proto",
Package: "google.golang.org/open2opaque/internal/fix/testdata/proto2test_go_proto",
},
{
Dir: "internal/fix/testdata/proto3test_go_proto",
Basename: "proto3test.proto",
Package: "google.golang.org/open2opaque/internal/fix/testdata/proto3test_go_proto",
},
} {
log.Printf("protoc %s/%s", pb.Dir, pb.Basename)
protoc := exec.Command("protoc",
"-I=.",
"--go_out=.",
"--go_opt=M"+pb.Basename+"="+pb.Package,
"--go_opt=paths=source_relative")
if strings.HasSuffix(pb.Dir, "/proto3test_go_proto") {
protoc.Args = append(protoc.Args, "--go_opt=default_api_level=API_HYBRID")
}
protoc.Args = append(protoc.Args, pb.Basename)
protoc.Dir = pb.Dir
protoc.Stderr = os.Stderr
if err := protoc.Run(); err != nil {
return fmt.Errorf("%v: %v", protoc.Args, err)
}
}
return nil
}
func main() {
if err := genProtos(); err != nil {
log.Fatal(err)
}
}