Skip to content

Commit

Permalink
mage: Init packages once
Browse files Browse the repository at this point in the history
`go list ./...` fails when run in parallel on Windows. This also applies to running `go test ./...` and `go list/...` so we serialize tests.
  • Loading branch information
bep committed Aug 30, 2018
1 parent 293e123 commit ea8ef57
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"path/filepath"
"runtime"
"strings"
"sync"
"time"

"github.com/magefile/mage/mg"
Expand Down Expand Up @@ -98,7 +99,11 @@ func Check() {
fmt.Printf("Skip Check on %s\n", runtime.Version())
return
}
mg.Deps(Test386, Fmt, Vet)

mg.Deps(Test386)

mg.Deps(Fmt, Vet)

// don't run two tests in parallel, they saturate the CPUs anyway, and running two
// causes memory issues in CI.
mg.Deps(TestRace)
Expand Down Expand Up @@ -161,18 +166,26 @@ func Fmt() error {
return nil
}

var pkgPrefixLen = len("github.com/gohugoio/hugo")
var (
pkgPrefixLen = len("github.com/gohugoio/hugo")
pkgs []string
pkgsInit sync.Once
)

func hugoPackages() ([]string, error) {
s, err := sh.Output(goexe, "list", "./...")
if err != nil {
return nil, err
}
pkgs := strings.Split(s, "\n")
for i := range pkgs {
pkgs[i] = "." + pkgs[i][pkgPrefixLen:]
}
return pkgs, nil
var err error
pkgsInit.Do(func() {
var s string
s, err = sh.Output(goexe, "list", "./...")
if err != nil {
return
}
pkgs = strings.Split(s, "\n")
for i := range pkgs {
pkgs[i] = "." + pkgs[i][pkgPrefixLen:]
}
})
return pkgs, err
}

// Run golint linter
Expand Down

0 comments on commit ea8ef57

Please sign in to comment.