-
Notifications
You must be signed in to change notification settings - Fork 0
/
target_build.go
63 lines (53 loc) · 1.13 KB
/
target_build.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
package main
import (
"path/filepath"
"github.com/goexl/gfx"
"github.com/goexl/gox/args"
)
func (t *target) build(plugin *plugin) (err error) {
ba := args.New().Build()
// 加入当前目录
// 防止出现错误:File does not reside within any path specified using --proto_path
if abs, ae := filepath.Abs(plugin.Source); nil != ae {
err = ae
} else {
ba.Option("proto_path", abs)
}
if nil != err {
return
}
// 添加导入目录
for _, include := range plugin.Includes {
if abs, ae := filepath.Abs(include); nil != ae {
err = ae
} else {
ba.Option("proto_path", abs)
}
if nil != err {
return
}
}
// 添加标签
for _, tag := range plugin.tags() {
ba.Flag(tag)
}
// 添加插件他输出目录
for _, out := range t.out(plugin) {
ba.Add(out)
}
// 添加选项
for _, opt := range t.opt(plugin) {
ba.Add(opt)
}
// 编译
if filenames, ge := gfx.All(plugin.Source, gfx.Matchable(plugin.buildable)); nil != ge {
err = ge
} else {
for _, filename := range filenames {
if err = plugin.protoc(plugin.Source, []string{filename}, ba.Clone()); nil != err {
break
}
}
}
return
}