mage: add mage package
This commit is contained in:
parent
141fbfed76
commit
795b4a76e6
63
mage.go
63
mage.go
|
@ -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)), ".")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue