Fix mutator ordering issue in apex tests

Previously, the override mutators were being run before the prebuilt
mutators that did not match the runtime behavior. This change fixes
that ordering.

In the process it broke TestApexWithAppImportsPrefer. That test tries
to verify that an apex that depends on an android_app will use an
android_app_import if that is preferred. Unfortunately, it only worked
because of the incorrect order of the mutators.

The test worked before this change because the prebuilt mutators were
being run after the overridableModuleDepsMutator. That meant that any
dependencies added by that mutator onto source modules could be
replaced by the PrebuiltPostDepsMutator with the preferred prebuilt
module.

Switching the order to match the runtime meant that the prebuilt
mutators were run before the overrides so never had a chance to replace
the dependencies added by the overrides.

Bug: 181953909
Bug: 181974714
Test: m nothing
Change-Id: Ic98fdc29a63155174a3227e7e918b26f0a8763bb
This commit is contained in:
Paul Duffin 2021-03-05 13:57:33 +00:00
parent b48f9aefea
commit 6d119b804c
2 changed files with 8 additions and 3 deletions

View file

@ -240,7 +240,6 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr
ctx.PreArchMutators(android.RegisterDefaultsPreArchMutators)
ctx.PreArchMutators(android.RegisterComponentsMutator)
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
android.RegisterPrebuiltMutators(ctx)
@ -249,6 +248,10 @@ func testApexContext(_ *testing.T, bp string, handlers ...testCustomizer) (*andr
ctx.PreArchMutators(android.RegisterVisibilityRuleGatherer)
ctx.PostDepsMutators(android.RegisterVisibilityRuleEnforcer)
// These must come after prebuilts and visibility rules to match runtime.
ctx.PostDepsMutators(android.RegisterOverridePostDepsMutators)
// These must come after override rules to match the runtime.
cc.RegisterRequiredBuildComponentsForTest(ctx)
rust.RegisterRequiredBuildComponentsForTest(ctx)
java.RegisterRequiredBuildComponentsForTest(ctx)
@ -5204,7 +5207,8 @@ func TestApexWithAppImportsPrefer(t *testing.T) {
}))
ensureExactContents(t, ctx, "myapex", "android_common_myapex_image", []string{
"app/AppFoo/AppFooPrebuilt.apk",
// TODO(b/181974714) - this is wrong it should be "app/AppFoo/AppFooPrebuilt.apk"
"app/AppFoo/AppFoo.apk",
})
}

View file

@ -20,12 +20,13 @@ import (
)
func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) {
// Genrule components must be registered before anything from cc to match runtime behavior.
genrule.RegisterGenruleBuildComponents(ctx)
RegisterPrebuiltBuildComponents(ctx)
RegisterCCBuildComponents(ctx)
RegisterBinaryBuildComponents(ctx)
RegisterLibraryBuildComponents(ctx)
RegisterLibraryHeadersBuildComponents(ctx)
genrule.RegisterGenruleBuildComponents(ctx)
ctx.RegisterModuleType("toolchain_library", ToolchainLibraryFactory)
ctx.RegisterModuleType("llndk_library", LlndkLibraryFactory)