Merge "Don't add apex_set deps in nondeterministic order"

This commit is contained in:
Liz Kammer 2023-04-20 19:51:21 +00:00 committed by Gerrit Code Review
commit e5eb5786e2
2 changed files with 60 additions and 19 deletions

View file

@ -5281,7 +5281,16 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
apex_set {
name: "myapex",
set: "myapex.apks",
exported_java_libs: ["myjavalib"],
exported_bootclasspath_fragments: ["my-bootclasspath-fragment"],
exported_systemserverclasspath_fragments: ["my-systemserverclasspath-fragment"],
}
java_import {
name: "myjavalib",
jars: ["myjavalib.jar"],
apex_available: ["myapex"],
permitted_packages: ["javalib"],
}
prebuilt_bootclasspath_fragment {
@ -5298,6 +5307,12 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
},
}
prebuilt_systemserverclasspath_fragment {
name: "my-systemserverclasspath-fragment",
contents: ["libbaz"],
apex_available: ["myapex"],
}
java_import {
name: "libfoo",
jars: ["libfoo.jar"],
@ -5314,6 +5329,16 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
shared_library: false,
permitted_packages: ["bar"],
}
java_sdk_library_import {
name: "libbaz",
public: {
jars: ["libbaz.jar"],
},
apex_available: ["myapex"],
shared_library: false,
permitted_packages: ["baz"],
}
`
ctx := testDexpreoptWithApexes(t, bp, "", preparer, fragment)
@ -5326,6 +5351,24 @@ func TestBootDexJarsFromSourcesAndPrebuilts(t *testing.T) {
my-bootclasspath-fragment/index.csv
out/soong/.intermediates/frameworks/base/boot/platform-bootclasspath/android_common/hiddenapi-monolithic/index-from-classes.csv
`)
myApex := ctx.ModuleForTests("myapex", "android_common_myapex").Module()
overrideNames := []string{
"",
"myjavalib.myapex",
"libfoo.myapex",
"libbar.myapex",
"libbaz.myapex",
}
mkEntries := android.AndroidMkEntriesForTest(t, ctx, myApex)
for i, e := range mkEntries {
g := e.OverrideName
if w := overrideNames[i]; w != g {
t.Errorf("Expected override name %q, got %q", w, g)
}
}
})
t.Run("prebuilt with source library preferred", func(t *testing.T) {

View file

@ -316,31 +316,29 @@ func prebuiltApexModuleCreatorMutator(ctx android.TopDownMutatorContext) {
}
}
func (p *prebuiltCommon) getExportedDependencies() map[string]exportedDependencyTag {
dependencies := make(map[string]exportedDependencyTag)
for _, dep := range p.prebuiltCommonProperties.Exported_java_libs {
dependencies[dep] = exportedJavaLibTag
}
for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
dependencies[dep] = exportedBootclasspathFragmentTag
}
for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments {
dependencies[dep] = exportedSystemserverclasspathFragmentTag
}
return dependencies
func (p *prebuiltCommon) hasExportedDeps() bool {
return len(p.prebuiltCommonProperties.Exported_java_libs) > 0 ||
len(p.prebuiltCommonProperties.Exported_bootclasspath_fragments) > 0 ||
len(p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments) > 0
}
// prebuiltApexContentsDeps adds dependencies onto the prebuilt apex module's contents.
func (p *prebuiltCommon) prebuiltApexContentsDeps(ctx android.BottomUpMutatorContext) {
module := ctx.Module()
for dep, tag := range p.getExportedDependencies() {
for _, dep := range p.prebuiltCommonProperties.Exported_java_libs {
prebuiltDep := android.PrebuiltNameFromSource(dep)
ctx.AddDependency(module, tag, prebuiltDep)
ctx.AddDependency(module, exportedJavaLibTag, prebuiltDep)
}
for _, dep := range p.prebuiltCommonProperties.Exported_bootclasspath_fragments {
prebuiltDep := android.PrebuiltNameFromSource(dep)
ctx.AddDependency(module, exportedBootclasspathFragmentTag, prebuiltDep)
}
for _, dep := range p.prebuiltCommonProperties.Exported_systemserverclasspath_fragments {
prebuiltDep := android.PrebuiltNameFromSource(dep)
ctx.AddDependency(module, exportedSystemserverclasspathFragmentTag, prebuiltDep)
}
}
@ -608,7 +606,7 @@ func createApexSelectorModule(ctx android.TopDownMutatorContext, name string, ap
// the listed modules need access to files from within the prebuilt .apex file.
func (p *prebuiltCommon) createDeapexerModuleIfNeeded(ctx android.TopDownMutatorContext, deapexerName string, apexFileSource string) {
// Only create the deapexer module if it is needed.
if len(p.getExportedDependencies()) == 0 {
if !p.hasExportedDeps() {
return
}