-
Notifications
You must be signed in to change notification settings - Fork 1
/
plugin.go
46 lines (40 loc) · 990 Bytes
/
plugin.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
package plugin
import (
"fmt"
"github.com/mrosset/via/pkg"
"os"
"os/exec"
"path/filepath"
)
// Plugin is the interface that provides a via plugin
type Plugin interface {
SetConfig(*via.Config)
Execute() error
}
// Executes 'cmd' with 'args' useing os.Stdout and os.Stderr
func execs(cmd string, args ...string) error {
e := exec.Command(cmd, args...)
e.Stderr = os.Stderr
e.Stdout = os.Stdout
return e.Run()
}
func build(out string, in string) error {
return execs("go", "build", "-buildmode=plugin", "-o", out, in)
}
// Build builds all of plugin files in
// FIXME: the plugins directory location is not well defined
func Build(config *via.Config) error {
glob := config.Plans.Join("..", "..", "plugins", "*.go").String()
files, err := filepath.Glob(glob)
if err != nil {
return err
}
for _, in := range files {
out := in[:len(in)-3] + ".so"
fmt.Printf("plugin: %s -> %s\n", in, out)
if err := build(out, in); err != nil {
return err
}
}
return nil
}