Convert apex transition tag to dependency on apex
When the apex mutator moves to using an info struct instead of a simple
string it becomes difficult to add a dependency directly on the apex
variation of a module, as that would require constructing a matching
ApexInfo to locate it. Simplify adding the dependency by adding it
on the apex instead, and then traversing from the apex to the desired
module inside the apex.
This causes a few changes in behaviors that require updating tests to
match.
When AlwaysUsePrebuiltSdks is set, the previous behavior was to use
the fragment and its dependencies from the source module for the
platform bootclasspath. Since the fragment is now found by traversing
from the apex, and the prebuilt apex is preferred, the fragment from
the prebuilt will now be found instead.
prebuilt_bootclasspath lists fragments in apexes that it depends on.
Previously it would depend on the apex variant of the fragment, which
then allowed the fragment to be replaced by the variant from an
override apex that set apex_name. Now it always depends on the original
apex to find the fragment.
Test: go test ./...
Bug: 372543712
Change-Id: I1a92ff461d4706cf68a0b8b37e53dea412efb8bf
diff --git a/apex/apex.go b/apex/apex.go
index 1d74466..24b3118 100644
--- a/apex/apex.go
+++ b/apex/apex.go
@@ -1211,13 +1211,6 @@
}
}
-type apexTransitionTag interface {
- // ApexTransition is a temporary interface used to tag dependencies with the apex variation they should use
- // when the dependency is added before the apex transition mutator has run. These will be replaced with
- // dependencies on the apex instead, which will then be used to find the necessary module inside the apex.
- ApexTransition() string
-}
-
type apexTransitionMutator struct{}
func (a *apexTransitionMutator) Split(ctx android.BaseModuleContext) []string {
@@ -1232,9 +1225,6 @@
}
func (a *apexTransitionMutator) OutgoingTransition(ctx android.OutgoingTransitionContext, sourceVariation string) string {
- if tag, ok := ctx.DepTag().(apexTransitionTag); ok {
- return tag.ApexTransition()
- }
return sourceVariation
}
diff --git a/apex/apex_test.go b/apex/apex_test.go
index 8877675..0d6d319 100644
--- a/apex/apex_test.go
+++ b/apex/apex_test.go
@@ -5341,6 +5341,12 @@
exported_bootclasspath_fragments: ["art-bootclasspath-fragment"],
}
+ prebuilt_apex {
+ name: "com.android.art",
+ src: "com.android.art-arm.apex",
+ exported_bootclasspath_fragments: ["art-bootclasspath-fragment"],
+ }
+
prebuilt_bootclasspath_fragment {
name: "art-bootclasspath-fragment",
image_name: "art",
diff --git a/apex/bootclasspath_fragment_test.go b/apex/bootclasspath_fragment_test.go
index 526e596..e8e45ad 100644
--- a/apex/bootclasspath_fragment_test.go
+++ b/apex/bootclasspath_fragment_test.go
@@ -863,8 +863,8 @@
java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_myapex", []string{
"all_apex_contributions",
- "art-bootclasspath-fragment",
"bar",
+ "com.android.art",
"dex2oatd",
"foo",
})
@@ -1040,8 +1040,8 @@
"android-non-updatable.stubs.module_lib",
"android-non-updatable.stubs.system",
"android-non-updatable.stubs.test",
- "art-bootclasspath-fragment",
"bar",
+ "com.android.art",
"dex2oatd",
"foo",
})
@@ -1214,8 +1214,8 @@
"android-non-updatable.stubs.system",
"android-non-updatable.stubs.test",
"android-non-updatable.stubs.test_module_lib",
- "art-bootclasspath-fragment",
"bar",
+ "com.android.art",
"dex2oatd",
"foo",
})
@@ -1365,8 +1365,8 @@
java.CheckModuleDependencies(t, result.TestContext, "mybootclasspathfragment", "android_common_myapex", []string{
"all_apex_contributions",
- "art-bootclasspath-fragment",
"bar",
+ "com.android.art",
"dex2oatd",
"foo",
"prebuilt_sdk_module-lib_current_android-non-updatable",
diff --git a/apex/platform_bootclasspath_test.go b/apex/platform_bootclasspath_test.go
index 6ebd78f..cd8c320 100644
--- a/apex/platform_bootclasspath_test.go
+++ b/apex/platform_bootclasspath_test.go
@@ -401,17 +401,17 @@
// Needed for generating the boot image.
`platform:dex2oatd`,
- // The configured contents of BootJars.
- `com.android.art:baz`,
- `com.android.art:quuz`,
+ // The configured contents of BootJars, via their apexes if necessary.
+ `platform:com.android.art`,
+ `platform:com.android.art`,
`platform:foo`,
- // The configured contents of ApexBootJars.
- `myapex:bar`,
+ // The configured contents of ApexBootJars, via their apex.
+ `platform:myapex`,
- // The fragments.
- `com.android.art:art-bootclasspath-fragment`,
- `myapex:my-bootclasspath-fragment`,
+ // The fragments via their apexes.
+ `platform:com.android.art`,
+ `platform:myapex`,
// Impl lib of sdk_library for transitive srcjar generation
`platform:foo.impl`,
@@ -429,7 +429,7 @@
// of AlwaysUsePrebuiltsSdk(). The second is a normal library that is unaffected. The order
// matters, so that the dependencies resolved by the platform_bootclasspath matches the
// configured list.
- java.FixtureConfigureApexBootJars("myapex:foo", "myapex:bar"),
+ java.FixtureConfigureApexBootJars("myapex:foo"),
java.PrepareForTestWithJavaSdkLibraryFiles,
android.FixtureModifyProductVariables(func(variables android.FixtureProductVariables) {
variables.Always_use_prebuilt_sdks = proptools.BoolPtr(true)
@@ -545,7 +545,6 @@
java.CheckPlatformBootclasspathModules(t, result, "myplatform-bootclasspath", []string{
// The configured contents of BootJars.
"myapex:prebuilt_foo",
- "myapex:bar",
})
// Make sure that the myplatform-bootclasspath has the correct dependencies.
@@ -561,14 +560,11 @@
// Not a prebuilt as no prebuilt existed when it was added.
"platform:legacy.core.platform.api.stubs.exportable",
- // The prebuilt.
- "myapex:prebuilt_foo",
+ // The prebuilt library via the apex.
+ "platform:myapex",
- // Only a source module exists.
- "myapex:bar",
-
- // The fragments.
- "myapex:prebuilt_mybootclasspath-fragment",
+ // The fragments via the apex.
+ "platform:myapex",
// Impl lib of sdk_library for transitive srcjar generation
"platform:foo.impl",
@@ -662,7 +658,7 @@
prepareForTestWithMyapex,
java.FixtureConfigureApexBootJars("myapex:foo"),
).ExtendWithErrorHandler(android.FixtureExpectsAtLeastOneErrorMatchingPattern(
- `module "myplatform-bootclasspath" variant ".*": module "foo" from platform is not allowed in the apex boot jars list`)).
+ `module "myplatform-bootclasspath" variant ".*": failed to find module "foo" in apex "myapex"`)).
RunTestWithBp(t, `
apex {
name: "myapex",