Support parallel Go compiles with Go 1.9
Change-Id: I80f3ad6e563fef1b4f22e936016675262f7ce8bf
This commit is contained in:
parent
53d563facb
commit
c54c072667
2 changed files with 17 additions and 2 deletions
|
@ -16,6 +16,7 @@ package bootstrap
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"go/build"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
@ -34,10 +35,20 @@ var (
|
|||
goTestRunnerCmd = pctx.StaticVariable("goTestRunnerCmd", filepath.Join(bootstrapDir, "bin", "gotestrunner"))
|
||||
pluginGenSrcCmd = pctx.StaticVariable("pluginGenSrcCmd", filepath.Join(bootstrapDir, "bin", "loadplugins"))
|
||||
|
||||
parallelCompile = pctx.StaticVariable("parallelCompile", func() string {
|
||||
// Parallel compilation is only supported on >= go1.9
|
||||
for _, r := range build.Default.ReleaseTags {
|
||||
if r == "go1.9" {
|
||||
return fmt.Sprintf("-c %d", runtime.NumCPU())
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}())
|
||||
|
||||
compile = pctx.StaticRule("compile",
|
||||
blueprint.RuleParams{
|
||||
Command: "GOROOT='$goRoot' $compileCmd -o $out -p $pkgPath -complete " +
|
||||
"$incFlags -pack $in",
|
||||
Command: "GOROOT='$goRoot' $compileCmd $parallelCompile -o $out " +
|
||||
"-p $pkgPath -complete $incFlags -pack $in",
|
||||
CommandDeps: []string{"$compileCmd"},
|
||||
Description: "compile $out",
|
||||
},
|
||||
|
|
|
@ -69,6 +69,7 @@ var (
|
|||
|
||||
goToolDir = filepath.Join(runtime.GOROOT(), "pkg", "tool", runtime.GOOS+"_"+runtime.GOARCH)
|
||||
goVersion = findGoVersion()
|
||||
isGo18 = strings.Contains(goVersion, "go1.8")
|
||||
)
|
||||
|
||||
func findGoVersion() string {
|
||||
|
@ -276,6 +277,9 @@ func (p *GoPackage) Compile(outDir, trimPath string) error {
|
|||
"-o", p.output,
|
||||
"-p", p.Name,
|
||||
"-complete", "-pack", "-nolocalimports")
|
||||
if !isGo18 {
|
||||
cmd.Args = append(cmd.Args, "-c", fmt.Sprintf("%d", runtime.NumCPU()))
|
||||
}
|
||||
if race {
|
||||
cmd.Args = append(cmd.Args, "-race")
|
||||
fmt.Fprintln(hash, "-race")
|
||||
|
|
Loading…
Reference in a new issue