Replace android.BuildOs with Config.BuildOS
Replace the android.BuildOs constant with Config.BuildOS so that it
can vary based on the product config.
Bug: 190084016
Test: all Soong tests
Change-Id: Ia67f872d8b2ab788747a22e3a9659dc21c9775cd
diff --git a/java/dexpreopt_bootjars.go b/java/dexpreopt_bootjars.go
index dff9543..2c78d73 100644
--- a/java/dexpreopt_bootjars.go
+++ b/java/dexpreopt_bootjars.go
@@ -523,14 +523,14 @@
}
// buildBootImageVariantsForBuildOs generates rules to build the boot image variants for the
-// android.BuildOs OsType, i.e. the type of OS on which the build is being running.
+// config.BuildOS OsType, i.e. the type of OS on which the build is being running.
//
// The files need to be generated into their predefined location because they are used from there
// both within Soong and outside, e.g. for ART based host side testing and also for use by some
// cloud based tools. However, they are not needed by callers of this function and so the paths do
// not need to be returned from this func, unlike the buildBootImageVariantsForAndroidOs func.
func buildBootImageVariantsForBuildOs(ctx android.ModuleContext, image *bootImageConfig, profile android.WritablePath) {
- buildBootImageForOsType(ctx, image, profile, android.BuildOs)
+ buildBootImageForOsType(ctx, image, profile, ctx.Config().BuildOS)
}
// buildBootImageForOsType takes a bootImageConfig, a profile file and an android.OsType
diff --git a/java/dexpreopt_config.go b/java/dexpreopt_config.go
index b13955f..1507aaf 100644
--- a/java/dexpreopt_config.go
+++ b/java/dexpreopt_config.go
@@ -32,7 +32,7 @@
}
}
// We may also need the images on host in order to run host-based tests.
- for _, target := range ctx.Config().Targets[android.BuildOs] {
+ for _, target := range ctx.Config().Targets[ctx.Config().BuildOS] {
targets = append(targets, target)
}
diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go
index b25dece..8dc7b79 100644
--- a/java/dexpreopt_test.go
+++ b/java/dexpreopt_test.go
@@ -16,6 +16,7 @@
import (
"fmt"
+ "runtime"
"testing"
"android/soong/android"
@@ -173,9 +174,9 @@
}
func TestDex2oatToolDeps(t *testing.T) {
- if android.BuildOs != android.Linux {
+ if runtime.GOOS != "linux" {
// The host binary paths checked below are build OS dependent.
- t.Skipf("Unsupported build OS %s", android.BuildOs)
+ t.Skipf("Unsupported build OS %s", runtime.GOOS)
}
preparers := android.GroupFixturePreparers(
diff --git a/java/java_test.go b/java/java_test.go
index 0f9965d..b6780c2 100644
--- a/java/java_test.go
+++ b/java/java_test.go
@@ -441,7 +441,7 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
bar := ctx.ModuleForTests("bar", buildOS+"_common")
barJar := bar.Output("bar.jar").Output.String()
@@ -478,7 +478,7 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
foo := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
@@ -523,7 +523,7 @@
}
// check that -g is not overridden for host modules
- buildOS := android.BuildOs.String()
+ buildOS := result.Config.BuildOS.String()
hostBinary := result.ModuleForTests("host_binary", buildOS+"_common")
hostJavaFlags := hostBinary.Module().VariablesForTests()["javacFlags"]
if strings.Contains(hostJavaFlags, "-g:source,lines") {
@@ -1371,7 +1371,7 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
test := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
entries := android.AndroidMkEntriesForTest(t, ctx, test)[0]
@@ -1387,7 +1387,7 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
module := ctx.ModuleForTests("foo", buildOS+"_common").Module().(*TestHost)
assertDeepEquals(t, "Default installable value should be true.", proptools.BoolPtr(true),
module.properties.Installable)
diff --git a/java/kotlin_test.go b/java/kotlin_test.go
index fd2f3ca..db30696 100644
--- a/java/kotlin_test.go
+++ b/java/kotlin_test.go
@@ -15,10 +15,11 @@
package java
import (
- "android/soong/android"
"strconv"
"strings"
"testing"
+
+ "android/soong/android"
)
func TestKotlin(t *testing.T) {
@@ -114,7 +115,7 @@
t.Run("", func(t *testing.T) {
ctx, _ := testJava(t, bp)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt")
kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
@@ -182,7 +183,7 @@
android.FixtureMergeEnv(env),
).RunTestWithBp(t, bp)
- buildOS := android.BuildOs.String()
+ buildOS := result.Config.BuildOS.String()
kapt := result.ModuleForTests("foo", "android_common").Rule("kapt")
javac := result.ModuleForTests("foo", "android_common").Description("javac")
diff --git a/java/plugin_test.go b/java/plugin_test.go
index c7913d3..dc29b1c 100644
--- a/java/plugin_test.go
+++ b/java/plugin_test.go
@@ -15,7 +15,6 @@
package java
import (
- "android/soong/android"
"testing"
)
@@ -58,7 +57,7 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
@@ -98,7 +97,7 @@
}
`)
- buildOS := android.BuildOs.String()
+ buildOS := ctx.Config().BuildOS.String()
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
turbine := ctx.ModuleForTests("foo", "android_common").MaybeRule("turbine")
diff --git a/java/robolectric.go b/java/robolectric.go
index a37a118..a0c9c7f 100644
--- a/java/robolectric.go
+++ b/java/robolectric.go
@@ -83,6 +83,9 @@
testConfig android.Path
data android.Paths
+
+ forceOSType android.OsType
+ forceArchType android.ArchType
}
func (r *robolectricTest) TestSuites() []string {
@@ -115,6 +118,9 @@
}
func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) {
+ r.forceOSType = ctx.Config().BuildOS
+ r.forceArchType = ctx.Config().BuildArch
+
r.testConfig = tradefed.AutoGenRobolectricTestConfig(ctx, r.testProperties.Test_config,
r.testProperties.Test_config_template, r.testProperties.Test_suites,
r.testProperties.Auto_gen_config)
@@ -345,7 +351,7 @@
func (r *robolectricTest) InstallBypassMake() bool { return true }
func (r *robolectricTest) InstallInTestcases() bool { return true }
func (r *robolectricTest) InstallForceOS() (*android.OsType, *android.ArchType) {
- return &android.BuildOs, &android.BuildArch
+ return &r.forceOSType, &r.forceArchType
}
func robolectricRuntimesFactory() android.Module {
@@ -366,6 +372,9 @@
props robolectricRuntimesProperties
runtimes []android.InstallPath
+
+ forceOSType android.OsType
+ forceArchType android.ArchType
}
func (r *robolectricRuntimes) TestSuites() []string {
@@ -385,6 +394,9 @@
return
}
+ r.forceOSType = ctx.Config().BuildOS
+ r.forceArchType = ctx.Config().BuildArch
+
files := android.PathsForModuleSrc(ctx, r.props.Jars)
androidAllDir := android.PathForModuleInstall(ctx, "android-all")
@@ -417,5 +429,5 @@
func (r *robolectricRuntimes) InstallBypassMake() bool { return true }
func (r *robolectricRuntimes) InstallInTestcases() bool { return true }
func (r *robolectricRuntimes) InstallForceOS() (*android.OsType, *android.ArchType) {
- return &android.BuildOs, &android.BuildArch
+ return &r.forceOSType, &r.forceArchType
}
diff --git a/java/sdk_test.go b/java/sdk_test.go
index bb595a5..6d62130 100644
--- a/java/sdk_test.go
+++ b/java/sdk_test.go
@@ -255,9 +255,11 @@
` + testcase.properties + `
}`
- variant := "android_common"
- if testcase.host == android.Host {
- variant = android.BuildOs.String() + "_common"
+ variant := func(result *android.TestResult) string {
+ if testcase.host == android.Host {
+ return result.Config.BuildOS.String() + "_common"
+ }
+ return "android_common"
}
convertModulesToPaths := func(cp []string) []string {
@@ -312,7 +314,7 @@
}
checkClasspath := func(t *testing.T, result *android.TestResult, isJava8 bool) {
- foo := result.ModuleForTests("foo", variant)
+ foo := result.ModuleForTests("foo", variant(result))
javac := foo.Rule("javac")
var deps []string
@@ -376,7 +378,7 @@
checkClasspath(t, result, true /* isJava8 */)
if testcase.host != android.Host {
- aidl := result.ModuleForTests("foo", variant).Rule("aidl")
+ aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl")
android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.")
}
@@ -389,7 +391,7 @@
checkClasspath(t, result, false /* isJava8 */)
if testcase.host != android.Host {
- aidl := result.ModuleForTests("foo", variant).Rule("aidl")
+ aidl := result.ModuleForTests("foo", variant(result)).Rule("aidl")
android.AssertStringDoesContain(t, "aidl command", aidl.RuleParams.Command, testcase.aidl+" -I.")
}