diff options
author | 2021-09-16 06:15:39 +0000 | |
---|---|---|
committer | 2021-09-16 06:25:26 +0000 | |
commit | 519c5c82e596959b683570d387aba43bae8fd65a (patch) | |
tree | ddf50ea990f4c9a1e00db3adde1b5dca22276be1 /java/testing.go | |
parent | 92346c483249726164f4bd140413d60391121763 (diff) |
Revert^2 "Preopt APEX system server jars."
This reverts commit 92346c483249726164f4bd140413d60391121763.
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
Diffstat (limited to 'java/testing.go')
-rw-r--r-- | java/testing.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/java/testing.go b/java/testing.go index 8860b45fa..d8a77cf37 100644 --- a/java/testing.go +++ b/java/testing.go @@ -431,3 +431,45 @@ func CheckMergedCompatConfigInputs(t *testing.T, result *android.TestResult, mes output := sourceGlobalCompatConfig.Output(allOutputs[0]) android.AssertPathsRelativeToTopEquals(t, message+": inputs", expectedPaths, output.Implicits) } + +// Register the fake APEX mutator to `android.InitRegistrationContext` as if the real mutator exists +// at runtime. This must be called in `init()` of a test if the test is going to use the fake APEX +// mutator. Otherwise, we will be missing the runtime mutator because "soong-apex" is not a +// dependency, which will cause an inconsistency between testing and runtime mutators. +func RegisterFakeRuntimeApexMutator() { + registerFakeApexMutator(android.InitRegistrationContext) +} + +var PrepareForTestWithFakeApexMutator = android.GroupFixturePreparers( + android.FixtureRegisterWithContext(registerFakeApexMutator), +) + +func registerFakeApexMutator(ctx android.RegistrationContext) { + ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) { + ctx.BottomUp("apex", fakeApexMutator).Parallel() + }) +} + +type apexModuleBase interface { + ApexAvailable() []string +} + +var _ apexModuleBase = (*Library)(nil) +var _ apexModuleBase = (*SdkLibrary)(nil) + +// A fake APEX mutator that creates a platform variant and an APEX variant for modules with +// `apex_available`. It helps us avoid a dependency on the real mutator defined in "soong-apex", +// which will cause a cyclic dependency, and it provides an easy way to create an APEX variant for +// testing without dealing with all the complexities in the real mutator. +func fakeApexMutator(mctx android.BottomUpMutatorContext) { + switch mctx.Module().(type) { + case *Library, *SdkLibrary: + if len(mctx.Module().(apexModuleBase).ApexAvailable()) > 0 { + modules := mctx.CreateVariations("", "apex1000") + apexInfo := android.ApexInfo{ + ApexVariationName: "apex1000", + } + mctx.SetVariationProvider(modules[1], android.ApexInfoProvider, apexInfo) + } + } +} |