mage: add mage package

This commit is contained in:
Cadey Ratio 2017-09-30 11:43:09 -07:00
parent 141fbfed76
commit 795b4a76e6
No known key found for this signature in database
GPG Key ID: D607EE27C2E7F89A
2 changed files with 63 additions and 0 deletions

0
doc/README.md Normal file
View File

63
mage.go
View File

@ -4,13 +4,17 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"github.com/jtolds/qod"
"github.com/pkg/errors"
)
var wd string
@ -24,6 +28,31 @@ func init() {
const pkgBase = "git.xeserv.us/xena/route/"
func output(cmd string, args ...string) (string, error) {
c := exec.Command(cmd, args...)
c.Env = os.Environ()
c.Stderr = os.Stderr
b, err := c.Output()
if err != nil {
return "", errors.Wrapf(err, `failed to run %v %q`, cmd, args)
}
return string(b), nil
}
func gitTag() (string, error) {
s, err := output("git", "describe", "--tags")
if err != nil {
ee, ok := errors.Cause(err).(*exec.ExitError)
if ok && ee.Exited() {
// probably no git tag
return "dev", nil
}
return "", err
}
return strings.TrimSuffix(s, "\n"), nil
}
func shouldWork(ctx context.Context, env []string, dir string, cmdName string, args ...string) {
loc, err := exec.LookPath(cmdName)
qod.ANE(err)
@ -109,3 +138,37 @@ func Plugin() {
goBuildPlugin(ctx, filepath.Join(wd, "./bin/linux"), "plugins/autohttpagent", "autohttpagent.so")
}
// Package builds all binaries for all platforms and assembles a package of
// documentation, useful tools and all route components.
func Package() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
//os.RemoveAll("./bin/darwin")
//os.RemoveAll("./bin/linux")
//os.RemoveAll("./bin/windows")
//mg.Deps(Linux, Windows, Darwin)
ver, err := gitTag()
qod.ANE(err)
for _, osname := range []string{"linux", "windows", "darwin"} {
dir, err := ioutil.TempDir("", "route-package-"+osname)
qod.ANE(err)
qod.Printlnf("%s", dir)
for _, file := range []string{"route", "route-httpagent", "routed"} {
if osname == "windows" {
file = file + ".exe"
}
shouldWork(ctx, nil, filepath.Join(wd, "bin", osname), "cp", "-vrf", file, dir)
}
shouldWork(ctx, nil, wd, "cp", "-vrf", "doc", dir)
shouldWork(ctx, nil, wd, "cp", "-vrf", "README.md", dir)
shouldWork(ctx, nil, dir, "tar", "czf", filepath.Join(wd, "bin", fmt.Sprintf("route-%s-%s.tar.gz", ver, osname)), ".")
}
}