build files to a directory named bin
This commit is contained in:
parent
834422055d
commit
a758254057
|
@ -1,3 +1,4 @@
|
|||
.DS_Store
|
||||
.env
|
||||
var
|
||||
bin
|
|
@ -0,0 +1,59 @@
|
|||
// +build mage
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/jtolds/qod"
|
||||
)
|
||||
|
||||
var wd string
|
||||
|
||||
func init() {
|
||||
lwd, err := os.Getwd()
|
||||
qod.ANE(err)
|
||||
|
||||
wd = lwd
|
||||
}
|
||||
|
||||
const pkgBase = "git.xeserv.us/xena/route/"
|
||||
|
||||
func shouldWork(ctx context.Context, env []string, dir string, cmdName string, args ...string) {
|
||||
loc, err := exec.LookPath(cmdName)
|
||||
qod.ANE(err)
|
||||
|
||||
cmd := exec.CommandContext(ctx, loc, args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = env
|
||||
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
log.Printf("starting process, env: %v, pwd: %s, cmd: %s, args: %v", env, dir, loc, args)
|
||||
err = cmd.Run()
|
||||
qod.ANE(err)
|
||||
}
|
||||
|
||||
func goBuild(ctx context.Context, env []string, dir string, pkgname string) {
|
||||
shouldWork(ctx, env, dir, "go", "build", pkgBase+pkgname)
|
||||
}
|
||||
|
||||
// Build builds the binaries for route and routed.
|
||||
func Build() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
err := os.Mkdir("bin", 0777)
|
||||
qod.ANE(err)
|
||||
|
||||
d := filepath.Join(wd, "./bin")
|
||||
|
||||
for _, pkg := range []string{"helloserver", "httpagent", "route", "routed"} {
|
||||
goBuild(ctx, os.Environ(), d, "cmd/"+pkg)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue