Handle installation rules for co-existing prebuilts
Every module belonging to a single mainline module family will be
hidden from make, except the one which has been flagged using
apex_contributions
Details
- Introduce a new `source_apex_name` property to prebuilt_apex and
override_apex. This property will be used to identify the source
equivalent of a prebuilt soong apex module.
- Create an N-ary tree from source to prebuilt(s). The tree wil be
rooted at the source module.
- In a subsequent mutator, visit every node in the tree(s). Query
apex_contributions and store the handle of the node which is "active"
(if any)
- In the same mutator, do another pass over the tree. Invoke
`HideFromMake` on every node which is not "active". The two-pass
approach is needed PrebuiltSelectionInfoProvider does not know about
the inter source-prebuilt dependency, this dependency can only be
known by doing a graph walk of the N-ary tree.
Some tangential implementation details
- Each prebuilt apex has an internal deapxer module that is responsible
for generating the deapex ninja rules. The name of this internal
module uses the BaseModuleName (without the prebuilt_ prefix). Since
we can have multiple prebuilt soong modules in trunk stable, change
this to follow the name of the prebuilt module in order to avoid name
collisions. Update existing unit tests accordingly
Bug: 316179314
Test: go test ./apex -run TestInstallationRulesForMultipleApexPrebuilts
Test: m nothing --no-skip-soong-tests
Test: presubmits
Change-Id: I58aa99d5e6a9859954614e6db9a8e9e2e581642d
diff --git a/android/apex_contributions.go b/android/apex_contributions.go
index a309640..236abf6 100644
--- a/android/apex_contributions.go
+++ b/android/apex_contributions.go
@@ -102,7 +102,6 @@
ctx.ModuleErrorf("%s listed in apex_contributions %s does not exist\n", content, m.Name())
}
pi := &PrebuiltSelectionInfo{
- baseModuleName: RemoveOptionalPrebuiltPrefix(content),
selectedModuleName: content,
metadataModuleName: m.Name(),
apiDomain: m.ApiDomain(),
@@ -126,7 +125,8 @@
// This provider will be used in prebuilt_select mutator to redirect deps
var PrebuiltSelectionInfoProvider = blueprint.NewMutatorProvider[PrebuiltSelectionInfoMap]("prebuilt_select")
-// Map of baseModuleName to the selected source or prebuilt
+// Map of selected module names to a metadata object
+// The metadata contains information about the api_domain of the selected module
type PrebuiltSelectionInfoMap map[string]PrebuiltSelectionInfo
// Add a new entry to the map with some validations
@@ -134,18 +134,10 @@
if p == nil {
return
}
- // Do not allow dups. If the base module (without the prebuilt_) has been added before, raise an exception.
- if old, exists := (*pm)[p.baseModuleName]; exists {
- ctx.ModuleErrorf("Cannot use Soong module: %s from apex_contributions: %s because it has been added previously as: %s from apex_contributions: %s\n",
- p.selectedModuleName, p.metadataModuleName, old.selectedModuleName, old.metadataModuleName,
- )
- }
- (*pm)[p.baseModuleName] = *p
+ (*pm)[p.selectedModuleName] = *p
}
type PrebuiltSelectionInfo struct {
- // e.g. libc
- baseModuleName string
// e.g. (libc|prebuilt_libc)
selectedModuleName string
// Name of the apex_contributions module
@@ -156,12 +148,9 @@
// Returns true if `name` is explicitly requested using one of the selected
// apex_contributions metadata modules.
-func (p *PrebuiltSelectionInfoMap) IsSelected(baseModuleName, name string) bool {
- if i, exists := (*p)[baseModuleName]; exists {
- return i.selectedModuleName == name
- } else {
- return false
- }
+func (p *PrebuiltSelectionInfoMap) IsSelected(name string) bool {
+ _, exists := (*p)[name]
+ return exists
}
// Return the list of soong modules selected for this api domain