From 626f8896fa2aff45dee92c971ec5750eb7f8eef6 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 30 Sep 2017 08:00:25 -0700 Subject: [PATCH] mage: cache packages with `go install` if building for runtime.GOOS --- mage.go | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/mage.go b/mage.go index d49b2ef..d2c0160 100644 --- a/mage.go +++ b/mage.go @@ -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) { shouldWork(ctx, env, dir, "go", "build", "-v", pkgBase+pkgname) +} - // TODO: `go install` caching of built packages - //shouldWork(ctx, env, dir, "go", "install", pkgBase+pkgname) - //shouldWork(ctx, env, dir, "go", "build", "-v", pkgBase+pkgname) +func goInstall(ctx context.Context, env []string, pkgname string) { + shouldWork(ctx, nil, wd, "go", "install", pkgBase+pkgname) } func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) { @@ -57,23 +57,45 @@ func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) { shouldWork(ctx, nil, dir, "go", "build", "-buildmode=plugin", "-o=fname", pkgBase+pkgname) } -// Build builds the binaries for route and routed. -func Build() { +func buildBins(goos string) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() 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"} { - goBuild(ctx, []string{"GOOS=" + goos}, filepath.Join(d, goos), "cmd/"+pkg) - qod.Printlnf("built binary for %s for os %s", pkg, goos) + for _, pkg := range []string{"route-httpagent", "route", "routed"} { + 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) } } +// 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. func Plugin() { ctx, cancel := context.WithCancel(context.Background())