mage: cache packages with `go install` if building for runtime.GOOS

This commit is contained in:
Cadey Ratio 2017-09-30 08:00:25 -07:00
parent 7e105f5720
commit 626f8896fa
No known key found for this signature in database
GPG Key ID: D607EE27C2E7F89A
1 changed files with 32 additions and 10 deletions

36
mage.go
View File

@ -42,10 +42,10 @@ func shouldWork(ctx context.Context, env []string, dir string, cmdName string, a
func goBuild(ctx context.Context, env []string, dir string, pkgname string) { func goBuild(ctx context.Context, env []string, dir string, pkgname string) {
shouldWork(ctx, env, dir, "go", "build", "-v", pkgBase+pkgname) shouldWork(ctx, env, dir, "go", "build", "-v", pkgBase+pkgname)
}
// TODO: `go install` caching of built packages func goInstall(ctx context.Context, env []string, pkgname string) {
//shouldWork(ctx, env, dir, "go", "install", pkgBase+pkgname) shouldWork(ctx, nil, wd, "go", "install", pkgBase+pkgname)
//shouldWork(ctx, env, dir, "go", "build", "-v", pkgBase+pkgname)
} }
func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) { func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) {
@ -57,21 +57,43 @@ func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) {
shouldWork(ctx, nil, dir, "go", "build", "-buildmode=plugin", "-o=fname", pkgBase+pkgname) shouldWork(ctx, nil, dir, "go", "build", "-buildmode=plugin", "-o=fname", pkgBase+pkgname)
} }
// Build builds the binaries for route and routed. func buildBins(goos string) {
func Build() {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
d := filepath.Join(wd, "./bin") d := filepath.Join(wd, "./bin")
for _, goos := range []string{"linux", "darwin", "windows"} {
os.Mkdir(filepath.Join(d, goos), 0777) os.Mkdir(filepath.Join(d, goos), 0777)
for _, pkg := range []string{"route-httpagent", "route", "routed"} { for _, pkg := range []string{"route-httpagent", "route", "routed"} {
goBuild(ctx, []string{"GOOS=" + goos}, filepath.Join(d, goos), "cmd/"+pkg) goBuild(ctx, []string{"GOOS=" + goos}, filepath.Join(d, goos), "cmd/"+pkg)
if goos == runtime.GOOS {
goInstall(ctx, nil, "cmd/"+pkg)
}
qod.Printlnf("built binary for %s for os %s", pkg, goos) qod.Printlnf("built binary for %s for os %s", pkg, goos)
} }
} }
// Linux builds binaries for linux
func Linux() {
buildBins("linux")
}
// Windows builds binaries for windows
func Windows() {
buildBins("windows")
}
// Darwin builds binaries for darwin
func Darwin() {
buildBins("darwin")
}
// Build builds the binaries for route and routed.
func Build() {
buildBins(runtime.GOOS)
} }
// Plugin builds all of the plugins for programs wanting to augment themselves with route. // Plugin builds all of the plugins for programs wanting to augment themselves with route.