diff options
author | 2025-01-28 06:35:11 +0000 | |
---|---|---|
committer | 2025-01-28 21:16:55 +0000 | |
commit | a8b1b6dc83a89e59f2f8006e0d6b4b143b1c363c (patch) | |
tree | b1aa43fa7696d38d42894ddc135871e092d342cc | |
parent | f83bfb1ef01fc8eb46dfc400dcdefe6713e72306 (diff) |
Set JAVA_HOME for runtime via soong AndroidTest.xml template
The jdk used by Robolectric during tests should always be the ANDROID_JAVA_HOME, as such this change, reads that environment variable from the build, and uses it to set the java_folder via the {EXTRA_CONFIGS} in the build/core/robolectric_test_config_template.xml
Test: atest MyRoboTests and look at the generated xml file
Bug: 372520027
Change-Id: I158eef8d52bef55167f207131139114db9a36691
-rw-r--r-- | java/robolectric.go | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/java/robolectric.go b/java/robolectric.go index ff0c850d5..507a310d7 100644 --- a/java/robolectric.go +++ b/java/robolectric.go @@ -144,20 +144,25 @@ func (r *robolectricTest) GenerateAndroidBuildActions(ctx android.ModuleContext) r.forceOSType = ctx.Config().BuildOS r.forceArchType = ctx.Config().BuildArch - var options []tradefed.Option - options = append(options, tradefed.Option{Name: "java-flags", Value: "-Drobolectric=true"}) + var extraTestRunnerOptions []tradefed.Option + extraTestRunnerOptions = append(extraTestRunnerOptions, tradefed.Option{Name: "java-flags", Value: "-Drobolectric=true"}) if proptools.BoolDefault(r.robolectricProperties.Strict_mode, true) { - options = append(options, tradefed.Option{Name: "java-flags", Value: "-Drobolectric.strict.mode=true"}) + extraTestRunnerOptions = append(extraTestRunnerOptions, tradefed.Option{Name: "java-flags", Value: "-Drobolectric.strict.mode=true"}) } + var extraOptions []tradefed.Option + var javaHome = ctx.Config().Getenv("ANDROID_JAVA_HOME") + extraOptions = append(extraOptions, tradefed.Option{Name: "java-folder", Value: javaHome}) + r.testConfig = tradefed.AutoGenTestConfig(ctx, tradefed.AutoGenTestConfigOptions{ - TestConfigProp: r.testProperties.Test_config, - TestConfigTemplateProp: r.testProperties.Test_config_template, - TestSuites: r.testProperties.Test_suites, - TestRunnerOptions: options, - AutoGenConfig: r.testProperties.Auto_gen_config, - DeviceTemplate: "${RobolectricTestConfigTemplate}", - HostTemplate: "${RobolectricTestConfigTemplate}", + TestConfigProp: r.testProperties.Test_config, + TestConfigTemplateProp: r.testProperties.Test_config_template, + TestSuites: r.testProperties.Test_suites, + OptionsForAutogenerated: extraOptions, + TestRunnerOptions: extraTestRunnerOptions, + AutoGenConfig: r.testProperties.Auto_gen_config, + DeviceTemplate: "${RobolectricTestConfigTemplate}", + HostTemplate: "${RobolectricTestConfigTemplate}", }) r.data = android.PathsForModuleSrc(ctx, r.testProperties.Data) r.data = append(r.data, android.PathsForModuleSrc(ctx, r.testProperties.Device_common_data)...) |