From 07753d8467d27c241006085b3314fb60f7a68d72 Mon Sep 17 00:00:00 2001 From: satayev Date: Tue, 25 May 2021 19:50:30 +0100 Subject: [PATCH] Use stem when filtering boot jars. For testing purposes, a boot jar may be provided by a test java_library that has a different content name, but sets "stem" property to match the original java_library. Given that Stem() returns either the property value or module name, it is safe to replace all content names by their stems. Bug: 180105615 Test: atest CtsClasspathsTestCases sdkextensions_e2e_tests Change-Id: Ic519ffa0c5b616abddf15b41c934421dfac2e78a --- java/base.go | 6 ++++++ java/bootclasspath_fragment.go | 13 ++++++++++++- java/systemserver_classpath_fragment.go | 13 ++++++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/java/base.go b/java/base.go index 25cc68fb0..cf6fafaaa 100644 --- a/java/base.go +++ b/java/base.go @@ -1778,3 +1778,9 @@ type ProvidesUsesLib interface { func (j *Module) ProvidesUsesLib() *string { return j.usesLibraryProperties.Provides_uses_lib } + +type ModuleWithStem interface { + Stem() string +} + +var _ ModuleWithStem = (*Module)(nil) diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go index 188d36225..44803a9ec 100644 --- a/java/bootclasspath_fragment.go +++ b/java/bootclasspath_fragment.go @@ -496,10 +496,21 @@ func (b *BootclasspathFragmentModule) ClasspathFragmentToConfiguredJarList(ctx a global := dexpreopt.GetGlobalConfig(ctx) + // Convert content names to their appropriate stems, in case a test library is overriding an actual boot jar + var stems []string + for _, name := range b.properties.Contents { + dep := ctx.GetDirectDepWithTag(name, bootclasspathFragmentContentDepTag) + if m, ok := dep.(ModuleWithStem); ok { + stems = append(stems, m.Stem()) + } else { + ctx.PropertyErrorf("contents", "%v is not a ModuleWithStem", name) + } + } + // Only create configs for updatable boot jars. Non-updatable boot jars must be part of the // platform_bootclasspath's classpath proto config to guarantee that they come before any // updatable jars at runtime. - return global.UpdatableBootJars.Filter(b.properties.Contents) + return global.UpdatableBootJars.Filter(stems) } func (b *BootclasspathFragmentModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig { diff --git a/java/systemserver_classpath_fragment.go b/java/systemserver_classpath_fragment.go index 9111c309f..f973cf45a 100644 --- a/java/systemserver_classpath_fragment.go +++ b/java/systemserver_classpath_fragment.go @@ -97,10 +97,21 @@ func (s *SystemServerClasspathModule) GenerateAndroidBuildActions(ctx android.Mo func (s *SystemServerClasspathModule) ClasspathFragmentToConfiguredJarList(ctx android.ModuleContext) android.ConfiguredJarList { global := dexpreopt.GetGlobalConfig(ctx) + // Convert content names to their appropriate stems, in case a test library is overriding an actual boot jar + var stems []string + for _, name := range s.properties.Contents { + dep := ctx.GetDirectDepWithTag(name, systemServerClasspathFragmentContentDepTag) + if m, ok := dep.(ModuleWithStem); ok { + stems = append(stems, m.Stem()) + } else { + ctx.PropertyErrorf("contents", "%v is not a ModuleWithStem", name) + } + } + // Only create configs for updatable boot jars. Non-updatable system server jars must be part of the // platform_systemserverclasspath's classpath proto config to guarantee that they come before any // updatable jars at runtime. - return global.UpdatableSystemServerJars.Filter(s.properties.Contents) + return global.UpdatableSystemServerJars.Filter(stems) } type systemServerClasspathFragmentContentDependencyTag struct {