mage: build plugins too
This commit is contained in:
parent
40c879d9f8
commit
13f59562cd
29
mage.go
29
mage.go
|
@ -8,6 +8,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/jtolds/qod"
|
||||
)
|
||||
|
@ -29,7 +30,7 @@ func shouldWork(ctx context.Context, env []string, dir string, cmdName string, a
|
|||
|
||||
cmd := exec.CommandContext(ctx, loc, args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = env
|
||||
cmd.Env = append(env, os.Environ()...)
|
||||
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
@ -43,6 +44,15 @@ func goBuild(ctx context.Context, env []string, dir string, pkgname string) {
|
|||
shouldWork(ctx, env, dir, "go", "build", pkgBase+pkgname)
|
||||
}
|
||||
|
||||
func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) {
|
||||
if runtime.GOOS != "linux" {
|
||||
qod.Printlnf("plugins don't work on non-linux machines yet :(")
|
||||
return
|
||||
}
|
||||
|
||||
shouldWork(ctx, nil, dir, "go", "build", "-buildmode=plugin", "-o=fname", pkgBase+pkgname)
|
||||
}
|
||||
|
||||
// Build builds the binaries for route and routed.
|
||||
func Build() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
@ -50,7 +60,20 @@ func Build() {
|
|||
|
||||
d := filepath.Join(wd, "./bin")
|
||||
|
||||
for _, pkg := range []string{"helloserver", "httpagent", "route", "routed"} {
|
||||
goBuild(ctx, os.Environ(), d, "cmd/"+pkg)
|
||||
for _, goos := range []string{"linux", "darwin", "windows"} {
|
||||
|
||||
os.Mkdir(filepath.Join(d, goos), 0777)
|
||||
for _, pkg := range []string{"route-httpagent", "route", "routed"} {
|
||||
goBuild(ctx, append(os.Environ(), "GOOS="+goos), filepath.Join(d, goos), "cmd/"+pkg)
|
||||
qod.Printlnf("built binary for %s for os %s", pkg, goos)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin builds all of the plugins for programs wanting to augment themselves with route.
|
||||
func Plugin() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
goBuildPlugin(ctx, filepath.Join(wd, "./bin/linux"), "plugins/autohttpagent", "autohttpagent.so")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue