From 13f59562cde3ad8f7e223d323c2ea71469e63678 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 30 Sep 2017 07:20:44 -0700 Subject: [PATCH] mage: build plugins too --- mage.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/mage.go b/mage.go index 024541d..fe19219 100644 --- a/mage.go +++ b/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") +}