-
Notifications
You must be signed in to change notification settings - Fork 4
/
Magefile.go
56 lines (48 loc) · 982 Bytes
/
Magefile.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
//go:build mage
package main
import (
"embed"
"errors"
"io/fs"
"os"
"strings"
"github.com/magefile/mage/sh"
)
//go:embed *.proto testproto
var files embed.FS
// Gen (re-)generates auto-generated code.
func Gen() error {
var fileArgs []string
if err := fs.WalkDir(files, ".", func(p string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
if strings.HasSuffix(p, ".pb.go") {
if r := os.Remove(p); r != nil {
return r
}
}
if !strings.HasSuffix(p, ".proto") {
return nil
}
fileArgs = append(fileArgs, p)
return nil
}); err != nil {
return err
}
if r := os.Mkdir("goproto", 0755); r != nil && !errors.Is(r, os.ErrExist) {
return r
}
args := append([]string{
// "-I=.",
"--go_out=.", "--go_opt=paths=source_relative",
"--go-grpc_out=.", "--go-grpc_opt=paths=source_relative",
}, fileArgs...)
if err := sh.Run("protoc", args...); err != nil {
return err
}
return nil
}