summaryrefslogtreecommitdiff
path: root/java/dexpreopt_test.go
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2021-05-13 02:38:35 +0100
committer Martin Stjernholm <mast@google.com> 2021-05-18 21:58:38 +0100
commit0e4ccebb1681ba464d4ae816347fbd86159d354c (patch)
tree6db58d0283709bdf252a38624fb9b44f654a8e82 /java/dexpreopt_test.go
parent0780372ae82137817b7f352e066d65bd988fcc01 (diff)
Don't fail if the target module is disabled in dex2oat tool
dependencies. dexpreopt.RegisterToolDeps runs late after prebuilt dependencies have been resolved, and there's special code in dex2oatPathFromDep to resolve the prebuilt from the source module. However, if the source module is disabled then the dependencies check in validateAndroidModule will complain, so we need to disable that check in this particular situation. Also add a comment to explain why dexpreopt.RegisterToolDeps needs to run so late. Test: m nothing Bug: 145934348 Bug: 172480615 Change-Id: Ibc673303d0336768fa23261a2068e91a08f46a30
Diffstat (limited to 'java/dexpreopt_test.go')
-rw-r--r--java/dexpreopt_test.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go
index a9e0773b7..f065534d5 100644
--- a/java/dexpreopt_test.go
+++ b/java/dexpreopt_test.go
@@ -15,7 +15,12 @@
package java
import (
+ "fmt"
"testing"
+
+ "android/soong/android"
+ "android/soong/cc"
+ "android/soong/dexpreopt"
)
func TestDexpreoptEnabled(t *testing.T) {
@@ -166,3 +171,46 @@ func enabledString(enabled bool) string {
return "disabled"
}
}
+
+func TestDex2oatToolDeps(t *testing.T) {
+ preparers := android.GroupFixturePreparers(
+ cc.PrepareForTestWithCcDefaultModules,
+ PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd,
+ dexpreopt.PrepareForTestByEnablingDexpreopt)
+
+ testDex2oatToolDep := func(sourceEnabled, prebuiltEnabled, prebuiltPreferred bool,
+ expectedDex2oatPath string) {
+ name := fmt.Sprintf("sourceEnabled:%t,prebuiltEnabled:%t,prebuiltPreferred:%t",
+ sourceEnabled, prebuiltEnabled, prebuiltPreferred)
+ t.Run(name, func(t *testing.T) {
+ result := preparers.RunTestWithBp(t, fmt.Sprintf(`
+ cc_binary {
+ name: "dex2oatd",
+ enabled: %t,
+ host_supported: true,
+ }
+ cc_prebuilt_binary {
+ name: "dex2oatd",
+ enabled: %t,
+ prefer: %t,
+ host_supported: true,
+ srcs: ["x86_64/bin/dex2oatd"],
+ }
+ java_library {
+ name: "myjavalib",
+ }
+ `, sourceEnabled, prebuiltEnabled, prebuiltPreferred))
+ pathContext := android.PathContextForTesting(result.Config)
+ dex2oatPath := dexpreopt.GetCachedGlobalSoongConfig(pathContext).Dex2oat
+ android.AssertStringEquals(t, "Testing "+name, expectedDex2oatPath, android.NormalizePathForTesting(dex2oatPath))
+ })
+ }
+
+ sourceDex2oatPath := "host/linux-x86/bin/dex2oatd"
+ prebuiltDex2oatPath := ".intermediates/prebuilt_dex2oatd/linux_glibc_x86_64/dex2oatd"
+
+ testDex2oatToolDep(true, false, false, sourceDex2oatPath)
+ testDex2oatToolDep(true, true, false, sourceDex2oatPath)
+ testDex2oatToolDep(true, true, true, prebuiltDex2oatPath)
+ testDex2oatToolDep(false, true, false, prebuiltDex2oatPath)
+}