Revert^2 "Preopt APEX system server jars."
This reverts commit 92346c4832
.
Reason for revert: Fixed build error.
The build error is fixed by ag/15841934. This CL remains unchanged. This
CL will be submitted AFTER ag/15841934 is submitted.
Bug: 200024131
Test: 1. Patch this CL and ag/15841934 into internal master.
2. sudo vendor/google/build/build_test.bash
Change-Id: I5f2b8357846fc7dda56e25ebe6ffb095e8047ec8
This commit is contained in:
@@ -17,6 +17,7 @@ package java
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"android/soong/android"
|
||||
@@ -24,11 +25,17 @@ import (
|
||||
"android/soong/dexpreopt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
RegisterFakeRuntimeApexMutator()
|
||||
}
|
||||
|
||||
func TestDexpreoptEnabled(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
bp string
|
||||
enabled bool
|
||||
name string
|
||||
bp string
|
||||
moduleName string
|
||||
apexVariant bool
|
||||
enabled bool
|
||||
}{
|
||||
{
|
||||
name: "app",
|
||||
@@ -148,13 +155,81 @@ func TestDexpreoptEnabled(t *testing.T) {
|
||||
}`,
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
name: "apex variant",
|
||||
bp: `
|
||||
java_library {
|
||||
name: "foo",
|
||||
installable: true,
|
||||
srcs: ["a.java"],
|
||||
apex_available: ["com.android.apex1"],
|
||||
}`,
|
||||
apexVariant: true,
|
||||
enabled: false,
|
||||
},
|
||||
{
|
||||
name: "apex variant of apex system server jar",
|
||||
bp: `
|
||||
java_library {
|
||||
name: "service-foo",
|
||||
installable: true,
|
||||
srcs: ["a.java"],
|
||||
apex_available: ["com.android.apex1"],
|
||||
}`,
|
||||
moduleName: "service-foo",
|
||||
apexVariant: true,
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
name: "apex variant of prebuilt apex system server jar",
|
||||
bp: `
|
||||
java_library {
|
||||
name: "prebuilt_service-foo",
|
||||
installable: true,
|
||||
srcs: ["a.java"],
|
||||
apex_available: ["com.android.apex1"],
|
||||
}`,
|
||||
moduleName: "prebuilt_service-foo",
|
||||
apexVariant: true,
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
name: "platform variant of apex system server jar",
|
||||
bp: `
|
||||
java_library {
|
||||
name: "service-foo",
|
||||
installable: true,
|
||||
srcs: ["a.java"],
|
||||
apex_available: ["com.android.apex1"],
|
||||
}`,
|
||||
moduleName: "service-foo",
|
||||
apexVariant: false,
|
||||
enabled: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
ctx, _ := testJava(t, test.bp)
|
||||
preparers := android.GroupFixturePreparers(
|
||||
PrepareForTestWithJavaDefaultModules,
|
||||
PrepareForTestWithFakeApexMutator,
|
||||
dexpreopt.FixtureSetApexSystemServerJars("com.android.apex1:service-foo"),
|
||||
)
|
||||
|
||||
dexpreopt := ctx.ModuleForTests("foo", "android_common").MaybeRule("dexpreopt")
|
||||
result := preparers.RunTestWithBp(t, test.bp)
|
||||
ctx := result.TestContext
|
||||
|
||||
moduleName := "foo"
|
||||
if test.moduleName != "" {
|
||||
moduleName = test.moduleName
|
||||
}
|
||||
|
||||
variant := "android_common"
|
||||
if test.apexVariant {
|
||||
variant += "_apex1000"
|
||||
}
|
||||
|
||||
dexpreopt := ctx.ModuleForTests(moduleName, variant).MaybeRule("dexpreopt")
|
||||
enabled := dexpreopt.Rule != nil
|
||||
|
||||
if enabled != test.enabled {
|
||||
@@ -220,3 +295,145 @@ func TestDex2oatToolDeps(t *testing.T) {
|
||||
testDex2oatToolDep(true, true, true, prebuiltDex2oatPath)
|
||||
testDex2oatToolDep(false, true, false, prebuiltDex2oatPath)
|
||||
}
|
||||
|
||||
func TestDexpreoptBuiltInstalledForApex(t *testing.T) {
|
||||
preparers := android.GroupFixturePreparers(
|
||||
PrepareForTestWithJavaDefaultModules,
|
||||
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"],
|
||||
}`)
|
||||
ctx := result.TestContext
|
||||
module := ctx.ModuleForTests("service-foo", "android_common_apex1000")
|
||||
library := module.Module().(*Library)
|
||||
|
||||
installs := library.dexpreopter.DexpreoptBuiltInstalledForApex()
|
||||
|
||||
android.AssertIntEquals(t, "install count", 2, len(installs))
|
||||
|
||||
android.AssertStringEquals(t, "installs[0] FullModuleName",
|
||||
"service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex",
|
||||
installs[0].FullModuleName())
|
||||
|
||||
android.AssertStringEquals(t, "installs[0] SubModuleName",
|
||||
"-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex",
|
||||
installs[0].SubModuleName())
|
||||
|
||||
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"],
|
||||
}`)
|
||||
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(
|
||||
PrepareForTestWithJavaDefaultModules,
|
||||
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"],
|
||||
}`)
|
||||
ctx := result.TestContext
|
||||
module := ctx.ModuleForTests("service-foo", "android_common_apex1000")
|
||||
|
||||
entriesList := android.AndroidMkEntriesForTest(t, ctx, module.Module())
|
||||
entriesList = filterDexpreoptEntriesList(entriesList)
|
||||
|
||||
android.AssertIntEquals(t, "entries count", 2, len(entriesList))
|
||||
|
||||
verifyEntries(t,
|
||||
"entriesList[0]",
|
||||
"service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.odex",
|
||||
"/dexpreopt/oat/arm64/javalib.odex",
|
||||
"/system/framework/oat/arm64",
|
||||
"apex@com.android.apex1@javalib@service-foo.jar@classes.odex",
|
||||
entriesList[0])
|
||||
|
||||
verifyEntries(t,
|
||||
"entriesList[1]",
|
||||
"service-foo-dexpreopt-arm64-apex@com.android.apex1@javalib@service-foo.jar@classes.vdex",
|
||||
"/dexpreopt/oat/arm64/javalib.vdex",
|
||||
"/system/framework/oat/arm64",
|
||||
"apex@com.android.apex1@javalib@service-foo.jar@classes.vdex",
|
||||
entriesList[1])
|
||||
|
||||
// Not an APEX system server jar.
|
||||
result = preparers.RunTestWithBp(t, `
|
||||
java_library {
|
||||
name: "foo",
|
||||
installable: true,
|
||||
srcs: ["a.java"],
|
||||
}`)
|
||||
ctx = result.TestContext
|
||||
module = ctx.ModuleForTests("foo", "android_common")
|
||||
|
||||
entriesList = android.AndroidMkEntriesForTest(t, ctx, module.Module())
|
||||
entriesList = filterDexpreoptEntriesList(entriesList)
|
||||
|
||||
android.AssertIntEquals(t, "entries count", 0, len(entriesList))
|
||||
}
|
||||
|
Reference in New Issue
Block a user