aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2017-10-30 13:42:06 -0700
committerDan Willemsen <dwillemsen@google.com>2017-11-08 00:44:47 -0800
commitd9e8f0a95af1f068b1c4ead2b3e40eea64929da8 (patch)
tree3c6d4e66e974b98d7445d36111dca62cbd4955e3 /ui
parentd293e65c820805bd526d3cf84ab13df0d85c42da (diff)
downloadbuild_soong-d9e8f0a95af1f068b1c4ead2b3e40eea64929da8.tar.gz
build_soong-d9e8f0a95af1f068b1c4ead2b3e40eea64929da8.tar.bz2
build_soong-d9e8f0a95af1f068b1c4ead2b3e40eea64929da8.zip
Setup java paths in soong_ui
This way config.mk no longer needs to check which java is in PATH and fix it. It'll be consistent for all build steps under soong_ui. Also unify handling of ANDROID_JAVA_HOME / JAVA_HOME with OVERRIDE_ANDROID_JAVA_HOME / EXPERIMENTAL_USE_OPENJDK9. Test: m nothing Test: build/soong/soong_ui.bash --make-mode nothing (w/o envsetup.sh) Test: aosp_arm ninja files are the same before/after Test: before/after ninja files match with OVERRIDE_ANDROID_JAVA_HOME Test: before/after ninja files match with EXPERIMENTAL_USE_OPENJDK9 Change-Id: Icdb65093d9c346524074de239a4f895e4230a24d
Diffstat (limited to 'ui')
-rw-r--r--ui/build/config.go38
-rw-r--r--ui/build/sandbox_darwin.go10
-rw-r--r--ui/build/soong.go4
-rw-r--r--ui/build/util.go8
4 files changed, 41 insertions, 19 deletions
diff --git a/ui/build/config.go b/ui/build/config.go
index 191a1029..940bb2fb 100644
--- a/ui/build/config.go
+++ b/ui/build/config.go
@@ -104,6 +104,9 @@ func NewConfig(ctx Context, args ...string) Config {
"MAKEFLAGS",
"MAKELEVEL",
"MFLAGS",
+
+ // Set in envsetup.sh, reset in makefiles
+ "ANDROID_JAVA_TOOLCHAIN",
)
// Tell python not to spam the source tree with .pyc files.
@@ -117,14 +120,12 @@ func NewConfig(ctx Context, args ...string) Config {
log.Fatalln("Error verifying tree state:", err)
}
- if srcDir, err := filepath.Abs("."); err == nil {
- if strings.ContainsRune(srcDir, ' ') {
- log.Println("You are building in a directory whose absolute path contains a space character:")
- log.Println()
- log.Printf("%q\n", srcDir)
- log.Println()
- log.Fatalln("Directory names containing spaces are not supported")
- }
+ if srcDir := absPath(ctx, "."); strings.ContainsRune(srcDir, ' ') {
+ log.Println("You are building in a directory whose absolute path contains a space character:")
+ log.Println()
+ log.Printf("%q\n", srcDir)
+ log.Println()
+ log.Fatalln("Directory names containing spaces are not supported")
}
if outDir := ret.OutDir(); strings.ContainsRune(outDir, ' ') {
@@ -143,6 +144,27 @@ func NewConfig(ctx Context, args ...string) Config {
log.Fatalln("Directory names containing spaces are not supported")
}
+ // Configure Java-related variables, including adding it to $PATH
+ javaHome := func() string {
+ if override, ok := ret.environ.Get("OVERRIDE_ANDROID_JAVA_HOME"); ok {
+ return override
+ }
+ if v, ok := ret.environ.Get("EXPERIMENTAL_USE_OPENJDK9"); ok && v != "" {
+ return filepath.Join("prebuilts/jdk/jdk9", ret.HostPrebuiltTag())
+ }
+ return filepath.Join("prebuilts/jdk/jdk8", ret.HostPrebuiltTag())
+ }()
+ absJavaHome := absPath(ctx, javaHome)
+
+ newPath := []string{filepath.Join(absJavaHome, "bin")}
+ if path, ok := ret.environ.Get("PATH"); ok && path != "" {
+ newPath = append(newPath, path)
+ }
+ ret.environ.Unset("OVERRIDE_ANDROID_JAVA_HOME")
+ ret.environ.Set("JAVA_HOME", absJavaHome)
+ ret.environ.Set("ANDROID_JAVA_HOME", javaHome)
+ ret.environ.Set("PATH", strings.Join(newPath, string(filepath.ListSeparator)))
+
return Config{ret}
}
diff --git a/ui/build/sandbox_darwin.go b/ui/build/sandbox_darwin.go
index 2cf6e20e..56791f78 100644
--- a/ui/build/sandbox_darwin.go
+++ b/ui/build/sandbox_darwin.go
@@ -50,14 +50,8 @@ func (c *Cmd) sandboxSupported() bool {
func (c *Cmd) wrapSandbox() {
homeDir, _ := c.Environment.Get("HOME")
- outDir, err := filepath.Abs(c.config.OutDir())
- if err != nil {
- c.ctx.Fatalln("Failed to get absolute path of OUT_DIR:", err)
- }
- distDir, err := filepath.Abs(c.config.DistDir())
- if err != nil {
- c.ctx.Fatalln("Failed to get absolute path of DIST_DIR:", err)
- }
+ outDir := absPath(c.ctx, c.config.OutDir())
+ distDir := absPath(c.ctx, c.config.DistDir())
c.Args[0] = c.Path
c.Path = sandboxExecPath
diff --git a/ui/build/soong.go b/ui/build/soong.go
index 8220597d..d3bcf876 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -77,9 +77,7 @@ func runSoong(ctx Context, config Config) {
var cfg microfactory.Config
cfg.Map("github.com/google/blueprint", "build/blueprint")
- if absPath, err := filepath.Abs("."); err == nil {
- cfg.TrimPath = absPath
- }
+ cfg.TrimPath = absPath(ctx, ".")
minibp := filepath.Join(config.SoongOutDir(), ".minibootstrap/minibp")
if _, err := microfactory.Build(&cfg, minibp, "github.com/google/blueprint/bootstrap/minibp"); err != nil {
diff --git a/ui/build/util.go b/ui/build/util.go
index 2555e8a4..f698ccd0 100644
--- a/ui/build/util.go
+++ b/ui/build/util.go
@@ -24,6 +24,14 @@ import (
"unsafe"
)
+func absPath(ctx Context, p string) string {
+ ret, err := filepath.Abs(p)
+ if err != nil {
+ ctx.Fatalf("Failed to get absolute path: %v", err)
+ }
+ return ret
+}
+
// indexList finds the index of a string in a []string
func indexList(s string, list []string) int {
for i, l := range list {