SdkLibraryImport's DexJarInstallPath uses installPath from source module

Even though actual installed module path is the same as source module,
it uses impl's one.

Bug: 188179858
Bug: 193082464
Test: compare dexpreopt_config.zip files from
  1. TARGET_BUILD_UNBUNDLED_IMAGE=true m dexpreopt_config_zip
  2. m dexpreopt_config_zip
  (note that m clean should run between steps)
Test: build aosp_cf_x86_64_phone,  launch_cvd, and then
  adb wait-for-device \
      && adb root \
      && adb logcat \
      | grep -E 'ClassLoaderContext [a-z ]+ mismatch' -C 1
      and then check if there is no message.

Change-Id: I34ffd9a2d214a6614c2befc35b2beec003cfcd25
This commit is contained in:
Jeongik Cha
2021-07-08 01:13:11 +09:00
parent 49e0e81155
commit d5fe8782e0
3 changed files with 37 additions and 14 deletions

View File

@@ -4687,16 +4687,26 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency) p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency)
dexJarBuildPath := p.DexJarBuildPath() dexJarBuildPath := p.DexJarBuildPath()
stem := android.RemoveOptionalPrebuiltPrefix(name) stem := android.RemoveOptionalPrebuiltPrefix(name)
if expected, actual := ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar", android.NormalizePathForTesting(dexJarBuildPath); actual != expected { android.AssertStringEquals(t, "DexJarBuildPath should be apex-related path.",
t.Errorf("Incorrect DexJarBuildPath value '%s', expected '%s'", actual, expected) ".intermediates/myapex.deapexer/android_common/deapexer/javalib/"+stem+".jar",
} android.NormalizePathForTesting(dexJarBuildPath))
}
checkDexJarInstallPath := func(t *testing.T, ctx *android.TestContext, name string) {
// Make sure the import has been given the correct path to the dex jar.
p := ctx.ModuleForTests(name, "android_common_myapex").Module().(java.UsesLibraryDependency)
dexJarBuildPath := p.DexJarInstallPath()
stem := android.RemoveOptionalPrebuiltPrefix(name)
android.AssertStringEquals(t, "DexJarInstallPath should be apex-related path.",
"target/product/test_device/apex/myapex/javalib/"+stem+".jar",
android.NormalizePathForTesting(dexJarBuildPath))
} }
ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) { ensureNoSourceVariant := func(t *testing.T, ctx *android.TestContext, name string) {
// Make sure that an apex variant is not created for the source module. // Make sure that an apex variant is not created for the source module.
if expected, actual := []string{"android_common"}, ctx.ModuleVariantsForTests(name); !reflect.DeepEqual(expected, actual) { android.AssertArrayString(t, "Check if there is no source variant",
t.Errorf("invalid set of variants for %q: expected %q, found %q", "libfoo", expected, actual) []string{"android_common"},
} ctx.ModuleVariantsForTests(name))
} }
t.Run("prebuilt only", func(t *testing.T) { t.Run("prebuilt only", func(t *testing.T) {
@@ -4745,8 +4755,10 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
} }
checkDexJarBuildPath(t, ctx, "libfoo") checkDexJarBuildPath(t, ctx, "libfoo")
checkDexJarInstallPath(t, ctx, "libfoo")
checkDexJarBuildPath(t, ctx, "libbar") checkDexJarBuildPath(t, ctx, "libbar")
checkDexJarInstallPath(t, ctx, "libbar")
}) })
t.Run("prebuilt with source preferred", func(t *testing.T) { t.Run("prebuilt with source preferred", func(t *testing.T) {
@@ -4792,9 +4804,11 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
ctx := testDexpreoptWithApexes(t, bp, "", transform) ctx := testDexpreoptWithApexes(t, bp, "", transform)
checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") checkDexJarBuildPath(t, ctx, "prebuilt_libfoo")
checkDexJarInstallPath(t, ctx, "prebuilt_libfoo")
ensureNoSourceVariant(t, ctx, "libfoo") ensureNoSourceVariant(t, ctx, "libfoo")
checkDexJarBuildPath(t, ctx, "prebuilt_libbar") checkDexJarBuildPath(t, ctx, "prebuilt_libbar")
checkDexJarInstallPath(t, ctx, "prebuilt_libbar")
ensureNoSourceVariant(t, ctx, "libbar") ensureNoSourceVariant(t, ctx, "libbar")
}) })
@@ -4842,9 +4856,11 @@ func TestPrebuiltExportDexImplementationJars(t *testing.T) {
ctx := testDexpreoptWithApexes(t, bp, "", transform) ctx := testDexpreoptWithApexes(t, bp, "", transform)
checkDexJarBuildPath(t, ctx, "prebuilt_libfoo") checkDexJarBuildPath(t, ctx, "prebuilt_libfoo")
checkDexJarInstallPath(t, ctx, "prebuilt_libfoo")
ensureNoSourceVariant(t, ctx, "libfoo") ensureNoSourceVariant(t, ctx, "libfoo")
checkDexJarBuildPath(t, ctx, "prebuilt_libbar") checkDexJarBuildPath(t, ctx, "prebuilt_libbar")
checkDexJarInstallPath(t, ctx, "prebuilt_libbar")
ensureNoSourceVariant(t, ctx, "libbar") ensureNoSourceVariant(t, ctx, "libbar")
}) })
} }

View File

@@ -1166,7 +1166,8 @@ type Import struct {
properties ImportProperties properties ImportProperties
// output file containing classes.dex and resources // output file containing classes.dex and resources
dexJarFile android.Path dexJarFile android.Path
dexJarInstallFile android.Path
combinedClasspathFile android.Path combinedClasspathFile android.Path
classLoaderContexts dexpreopt.ClassLoaderContextMap classLoaderContexts dexpreopt.ClassLoaderContextMap
@@ -1311,6 +1312,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(j.BaseModuleName())); dexOutputPath != nil { if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(j.BaseModuleName())); dexOutputPath != nil {
j.dexJarFile = dexOutputPath j.dexJarFile = dexOutputPath
j.dexJarInstallFile = android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(j.BaseModuleName()))
// Initialize the hiddenapi structure. // Initialize the hiddenapi structure.
j.initHiddenAPI(ctx, dexOutputPath, outputFile, nil) j.initHiddenAPI(ctx, dexOutputPath, outputFile, nil)
@@ -1351,6 +1353,7 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile) dexOutputFile = j.hiddenAPIEncodeDex(ctx, dexOutputFile)
j.dexJarFile = dexOutputFile j.dexJarFile = dexOutputFile
j.dexJarInstallFile = android.PathForModuleInstall(ctx, "framework", jarName)
} }
} }
@@ -1392,7 +1395,7 @@ func (j *Import) DexJarBuildPath() android.Path {
} }
func (j *Import) DexJarInstallPath() android.Path { func (j *Import) DexJarInstallPath() android.Path {
return nil return j.dexJarInstallFile
} }
func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap { func (j *Import) ClassLoaderContexts() dexpreopt.ClassLoaderContextMap {

View File

@@ -1923,8 +1923,12 @@ type SdkLibraryImport struct {
// Is nil if the source module does not exist. // Is nil if the source module does not exist.
xmlPermissionsFileModule *sdkLibraryXml xmlPermissionsFileModule *sdkLibraryXml
// Path to the dex implementation jar obtained from the prebuilt_apex, if any. // Build path to the dex implementation jar obtained from the prebuilt_apex, if any.
dexJarFile android.Path dexJarFile android.Path
// Expected install file path of the source module(sdk_library)
// or dex implementation jar obtained from the prebuilt_apex, if any.
installFile android.Path
} }
var _ SdkLibraryDependency = (*SdkLibraryImport)(nil) var _ SdkLibraryDependency = (*SdkLibraryImport)(nil)
@@ -2136,6 +2140,9 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
var deapexerModule android.Module var deapexerModule android.Module
// Assume that source module(sdk_library) is installed in /<sdk_library partition>/framework
module.installFile = android.PathForModuleInstall(ctx, "framework", module.Stem()+".jar")
// Record the paths to the prebuilt stubs library and stubs source. // Record the paths to the prebuilt stubs library and stubs source.
ctx.VisitDirectDeps(func(to android.Module) { ctx.VisitDirectDeps(func(to android.Module) {
tag := ctx.OtherModuleDependencyTag(to) tag := ctx.OtherModuleDependencyTag(to)
@@ -2195,6 +2202,7 @@ func (module *SdkLibraryImport) GenerateAndroidBuildActions(ctx android.ModuleCo
di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo) di := ctx.OtherModuleProvider(deapexerModule, android.DeapexerProvider).(android.DeapexerInfo)
if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(module.BaseModuleName())); dexOutputPath != nil { if dexOutputPath := di.PrebuiltExportPath(apexRootRelativePathToJavaLib(module.BaseModuleName())); dexOutputPath != nil {
module.dexJarFile = dexOutputPath module.dexJarFile = dexOutputPath
module.installFile = android.PathForModuleInPartitionInstall(ctx, "apex", ai.ApexVariationName, apexRootRelativePathToJavaLib(module.BaseModuleName()))
module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil) module.initHiddenAPI(ctx, dexOutputPath, module.findScopePaths(apiScopePublic).stubsImplPath[0], nil)
} else { } else {
// This should never happen as a variant for a prebuilt_apex is only created if the // This should never happen as a variant for a prebuilt_apex is only created if the
@@ -2249,11 +2257,7 @@ func (module *SdkLibraryImport) DexJarBuildPath() android.Path {
// to satisfy UsesLibraryDependency interface // to satisfy UsesLibraryDependency interface
func (module *SdkLibraryImport) DexJarInstallPath() android.Path { func (module *SdkLibraryImport) DexJarInstallPath() android.Path {
if module.implLibraryModule == nil { return module.installFile
return nil
} else {
return module.implLibraryModule.DexJarInstallPath()
}
} }
// to satisfy UsesLibraryDependency interface // to satisfy UsesLibraryDependency interface