Merge remote-tracking branch 'aosp/upstream'

* aosp/upstream:
  Cap the number of cpus for Go compiles
  Try to make GOROOT relative in Go 1.10

Bug: 74093084
Test: check goroot in out/soong/**/build.ninja
Change-Id: Ic49c2a07e9b076cd2797a129a1f5dc561871abe2
diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go
index 4f7d916..e9a8f01 100644
--- a/bootstrap/bootstrap.go
+++ b/bootstrap/bootstrap.go
@@ -39,7 +39,15 @@
 		// 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())
+				numCpu := runtime.NumCPU()
+				// This will cause us to recompile all go programs if the
+				// number of cpus changes. We don't get a lot of benefit from
+				// higher values, so cap this to make it cheaper to move trees
+				// between machines.
+				if numCpu > 8 {
+					numCpu = 8
+				}
+				return fmt.Sprintf("-c %d", numCpu)
 			}
 		}
 		return ""
diff --git a/bootstrap/config.go b/bootstrap/config.go
index 3aa97a5..5785ea7 100644
--- a/bootstrap/config.go
+++ b/bootstrap/config.go
@@ -15,7 +15,10 @@
 package bootstrap
 
 import (
+	"os"
+	"path/filepath"
 	"runtime"
+	"strings"
 
 	"github.com/google/blueprint"
 )
@@ -39,7 +42,16 @@
 		return NinjaBuildDir
 	})
 	goRoot = bootstrapVariable("goRoot", func() string {
-		return runtime.GOROOT()
+		goroot := runtime.GOROOT()
+		// Prefer to omit absolute paths from the ninja file
+		if cwd, err := os.Getwd(); err == nil {
+			if relpath, err := filepath.Rel(cwd, goroot); err == nil {
+				if !strings.HasPrefix(relpath, "../") {
+					goroot = relpath
+				}
+			}
+		}
+		return goroot
 	})
 	compileCmd = bootstrapVariable("compileCmd", func() string {
 		return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/compile"