Add extra dependency from apex to bootclasspath fragments to modules
An extra dependency from apex modules to their bootclasspath fragments
and from bootclasspath fragments to their contents is necessary, as the
existing one with bcpfTag return false from ReplaceSourceWithPrebuilt
to never rewrite the dependency to the prebuilt fragment, and we'll
need a dependency to the prebuilt fragment in the next CL.
Bug: 372543712
Test: all soong tests pass
Change-Id: I87ff3afa0d5c90936664dd493654f1d64230b8a9
diff --git a/java/bootclasspath_fragment.go b/java/bootclasspath_fragment.go
index d5296e2..4d35b9f 100644
--- a/java/bootclasspath_fragment.go
+++ b/java/bootclasspath_fragment.go
@@ -89,6 +89,19 @@
// The tag used for the dependency between the bootclasspath_fragment module and its contents.
var bootclasspathFragmentContentDepTag = bootclasspathFragmentContentDependencyTag{}
+type moduleInFragmentDependencyTag struct {
+ blueprint.DependencyTag
+}
+
+func (m moduleInFragmentDependencyTag) ExcludeFromVisibilityEnforcement() {
+}
+
+// moduleInFragmentDepTag is added alongside bootclasspathFragmentContentDependencyTag,
+// but doesn't set ReplaceSourceWithPrebuilt. It is used to find modules in the fragment
+// by traversing from the apex to the fragment to the module, which prevents having to
+// construct a dependency on the apex variant of the fragment directly.
+var moduleInFragmentDepTag = moduleInFragmentDependencyTag{}
+
var _ android.ExcludeFromVisibilityEnforcementTag = bootclasspathFragmentContentDepTag
var _ android.ReplaceSourceWithPrebuilt = bootclasspathFragmentContentDepTag
var _ android.SdkMemberDependencyTag = bootclasspathFragmentContentDepTag
@@ -415,6 +428,9 @@
if bcpTag, ok := tag.(bootclasspathDependencyTag); ok && bcpTag.typ == fragment {
return false
}
+ if tag == moduleInFragmentDepTag {
+ return false
+ }
panic(fmt.Errorf("boot_image module %q should not have a dependency tag %s", b, android.PrettyPrintTag(tag)))
}
@@ -471,6 +487,10 @@
// Add dependencies on all the fragments.
b.properties.BootclasspathFragmentsDepsProperties.addDependenciesOntoFragments(ctx)
+
+ for _, name := range b.properties.Contents.GetOrDefault(ctx, nil) {
+ ctx.AddDependency(ctx.Module(), moduleInFragmentDepTag, name)
+ }
}
func (b *BootclasspathFragmentModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
diff --git a/java/sdk_library_test.go b/java/sdk_library_test.go
index 0aed4b8..0d872f0 100644
--- a/java/sdk_library_test.go
+++ b/java/sdk_library_test.go
@@ -993,8 +993,6 @@
CheckModuleDependencies(t, result.TestContext, "combined", "android_common", []string{
// Each use of :sdklib{...} adds a dependency onto prebuilt_sdklib.
`prebuilt_sdklib`,
- `prebuilt_sdklib`,
- `prebuilt_sdklib`,
`prebuilt_sdklib.stubs`,
`prebuilt_sdklib.stubs.source`,
})
diff --git a/java/testing.go b/java/testing.go
index 378e2dd..5ee659c 100644
--- a/java/testing.go
+++ b/java/testing.go
@@ -18,7 +18,6 @@
"fmt"
"reflect"
"regexp"
- "sort"
"strings"
"testing"
@@ -611,14 +610,13 @@
ctx.VisitDirectDeps(module, func(m blueprint.Module) {
deps = append(deps, m.Name())
})
- sort.Strings(deps)
-
- return deps
+ return android.SortedUniqueStrings(deps)
}
// CheckModuleDependencies checks if the expected dependencies of the module are
// identical to the actual dependencies.
func CheckModuleDependencies(t *testing.T, ctx *android.TestContext, name, variant string, expected []string) {
+ t.Helper()
deps := getModuleDependencies(t, ctx, name, variant)
if actual := deps; !reflect.DeepEqual(expected, actual) {