diff options
author | 2025-01-28 14:00:12 -0800 | |
---|---|---|
committer | 2025-02-03 22:19:24 -0800 | |
commit | 388c6618a8a4a5bedd42ffc4874e2f6663e01289 (patch) | |
tree | dc1947fc3a719fcc9bc8824eb963ec004345e878 /java/dexpreopt_test.go | |
parent | 90d7df966c7c79a5d0c7380d4d3dc59bd339baad (diff) |
Move installation of dexpreopted system server classpath libraries into apex
System server jars in apexes currently use a heuristic to determine
whether or not they are the "main" variant in order to create rules
that copy their dexpreopt artifacts to the final installed location
and their dex jars to a known location for other modules to reference.
The heuristic depends on knowing all apexes that depend on the
module, which will not be possible when the apex info mutator is
rewritten to support future incremental analysis.
Instead, export the dexpreopt artifacts and dex jars, and let the
apex decide whether or not to install them.
Bug: 372543712
Test: all soong tests pass
Change-Id: I478bc2edceca4614e08e9a695b05d091e5437ba1
Diffstat (limited to 'java/dexpreopt_test.go')
-rw-r--r-- | java/dexpreopt_test.go | 130 |
1 files changed, 26 insertions, 104 deletions
diff --git a/java/dexpreopt_test.go b/java/dexpreopt_test.go index 53a0d71fd..bf660475f 100644 --- a/java/dexpreopt_test.go +++ b/java/dexpreopt_test.go @@ -17,7 +17,6 @@ package java import ( "fmt" "runtime" - "strings" "testing" "android/soong/android" @@ -309,7 +308,7 @@ func TestDex2oatToolDeps(t *testing.T) { testDex2oatToolDep(false, true, false, prebuiltDex2oatPath) } -func TestDexpreoptBuiltInstalledForApex(t *testing.T) { +func TestApexSystemServerDexpreoptInstalls(t *testing.T) { preparers := android.GroupFixturePreparers( PrepareForTestWithDexpreopt, PrepareForTestWithFakeApexMutator, @@ -329,114 +328,35 @@ func TestDexpreoptBuiltInstalledForApex(t *testing.T) { module := ctx.ModuleForTests("service-foo", "android_common_apex1000") library := module.Module().(*Library) - installs := library.dexpreopter.DexpreoptBuiltInstalledForApex() + installs := library.dexpreopter.ApexSystemServerDexpreoptInstalls() + dexJars := library.dexpreopter.ApexSystemServerDexJars() android.AssertIntEquals(t, "install count", 2, len(installs)) + android.AssertIntEquals(t, "dexjar count", 1, len(dexJars)) - android.AssertStringEquals(t, "installs[0] FullModuleName", - "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex", - installs[0].FullModuleName()) + android.AssertPathRelativeToTopEquals(t, "installs[0] OutputPathOnHost", + "out/soong/.intermediates/service-foo/android_common_apex1000/dexpreopt/service-foo/oat/arm64/javalib.odex", + installs[0].OutputPathOnHost) - android.AssertStringEquals(t, "installs[0] SubModuleName", - "-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex", - installs[0].SubModuleName()) + android.AssertPathRelativeToTopEquals(t, "installs[0] InstallDirOnDevice", + "out/target/product/test_device/system/framework/oat/arm64", + installs[0].InstallDirOnDevice) - android.AssertStringEquals(t, "installs[1] FullModuleName", - "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", - installs[1].FullModuleName()) - - android.AssertStringEquals(t, "installs[1] SubModuleName", - "-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", - installs[1].SubModuleName()) - - // Not an APEX system server jar. - result = preparers.RunTestWithBp(t, ` - java_library { - name: "foo", - installable: true, - srcs: ["a.java"], - sdk_version: "current", - }`) - ctx = result.TestContext - module = ctx.ModuleForTests("foo", "android_common") - library = module.Module().(*Library) - - installs = library.dexpreopter.DexpreoptBuiltInstalledForApex() - - android.AssertIntEquals(t, "install count", 0, len(installs)) -} - -func filterDexpreoptEntriesList(entriesList []android.AndroidMkEntries) []android.AndroidMkEntries { - var results []android.AndroidMkEntries - for _, entries := range entriesList { - if strings.Contains(entries.EntryMap["LOCAL_MODULE"][0], "-dexpreopt-") { - results = append(results, entries) - } - } - return results -} - -func verifyEntries(t *testing.T, message string, expectedModule string, - expectedPrebuiltModuleFile string, expectedModulePath string, expectedInstalledModuleStem string, - entries android.AndroidMkEntries) { - android.AssertStringEquals(t, message+" LOCAL_MODULE", expectedModule, - entries.EntryMap["LOCAL_MODULE"][0]) - - android.AssertStringEquals(t, message+" LOCAL_MODULE_CLASS", "ETC", - entries.EntryMap["LOCAL_MODULE_CLASS"][0]) - - android.AssertStringDoesContain(t, message+" LOCAL_PREBUILT_MODULE_FILE", - entries.EntryMap["LOCAL_PREBUILT_MODULE_FILE"][0], expectedPrebuiltModuleFile) - - android.AssertStringDoesContain(t, message+" LOCAL_MODULE_PATH", - entries.EntryMap["LOCAL_MODULE_PATH"][0], expectedModulePath) - - android.AssertStringEquals(t, message+" LOCAL_INSTALLED_MODULE_STEM", - expectedInstalledModuleStem, entries.EntryMap["LOCAL_INSTALLED_MODULE_STEM"][0]) - - android.AssertStringEquals(t, message+" LOCAL_NOT_AVAILABLE_FOR_PLATFORM", - "false", entries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"][0]) -} - -func TestAndroidMkEntriesForApex(t *testing.T) { - preparers := android.GroupFixturePreparers( - PrepareForTestWithDexpreopt, - PrepareForTestWithFakeApexMutator, - dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"), - ) - - // An APEX system server jar. - result := preparers.RunTestWithBp(t, ` - java_library { - name: "service-foo", - installable: true, - srcs: ["a.java"], - apex_available: ["com.android.apex1"], - sdk_version: "current", - }`) - ctx := result.TestContext - module := ctx.ModuleForTests("service-foo", "android_common_apex1000") - - entriesList := android.AndroidMkEntriesForTest(t, ctx, module.Module()) - entriesList = filterDexpreoptEntriesList(entriesList) + android.AssertStringEquals(t, "installs[0] InstallFileOnDevice", + "apex@com.android.apex1@javalib@service-foo.jar@classes.odex", + installs[0].InstallFileOnDevice) - android.AssertIntEquals(t, "entries count", 2, len(entriesList)) + android.AssertPathRelativeToTopEquals(t, "installs[1] OutputPathOnHost", + "out/soong/.intermediates/service-foo/android_common_apex1000/dexpreopt/service-foo/oat/arm64/javalib.vdex", + installs[1].OutputPathOnHost) - verifyEntries(t, - "entriesList[0]", - "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex", - "/dexpreopt/service-foo/oat/arm64/javalib.odex", - "/system/framework/oat/arm64", - "apex@com.android.apex1@javalib@service-foo.jar@classes.odex", - entriesList[0]) + android.AssertPathRelativeToTopEquals(t, "installs[1] InstallDirOnDevice", + "out/target/product/test_device/system/framework/oat/arm64", + installs[1].InstallDirOnDevice) - verifyEntries(t, - "entriesList[1]", - "service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", - "/dexpreopt/service-foo/oat/arm64/javalib.vdex", - "/system/framework/oat/arm64", + android.AssertStringEquals(t, "installs[1] InstallFileOnDevice", "apex@com.android.apex1@javalib@service-foo.jar@classes.vdex", - entriesList[1]) + installs[1].InstallFileOnDevice) // Not an APEX system server jar. result = preparers.RunTestWithBp(t, ` @@ -448,11 +368,13 @@ func TestAndroidMkEntriesForApex(t *testing.T) { }`) ctx = result.TestContext module = ctx.ModuleForTests("foo", "android_common") + library = module.Module().(*Library) - entriesList = android.AndroidMkEntriesForTest(t, ctx, module.Module()) - entriesList = filterDexpreoptEntriesList(entriesList) + installs = library.dexpreopter.ApexSystemServerDexpreoptInstalls() + dexJars = library.dexpreopter.ApexSystemServerDexJars() - android.AssertIntEquals(t, "entries count", 0, len(entriesList)) + android.AssertIntEquals(t, "install count", 0, len(installs)) + android.AssertIntEquals(t, "dexjar count", 0, len(dexJars)) } func TestGenerateProfileEvenIfDexpreoptIsDisabled(t *testing.T) { |