Merge "apexDepsMutator uses WalkDeps" am: e8bc288702
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1369776 Change-Id: I0dc292b51099f48af3a0834c88700d1d3b67ace8
This commit is contained in:
@@ -65,9 +65,9 @@ type ApexModule interface {
|
|||||||
|
|
||||||
apexModuleBase() *ApexModuleBase
|
apexModuleBase() *ApexModuleBase
|
||||||
|
|
||||||
// Marks that this module should be built for the specified APEXes.
|
// Marks that this module should be built for the specified APEX.
|
||||||
// Call this before apex.apexMutator is run.
|
// Call this before apex.apexMutator is run.
|
||||||
BuildForApexes(apexes []ApexInfo)
|
BuildForApex(apex ApexInfo)
|
||||||
|
|
||||||
// Returns the APEXes that this module will be built for
|
// Returns the APEXes that this module will be built for
|
||||||
ApexVariations() []ApexInfo
|
ApexVariations() []ApexInfo
|
||||||
@@ -96,7 +96,7 @@ type ApexModule interface {
|
|||||||
IsInstallableToApex() bool
|
IsInstallableToApex() bool
|
||||||
|
|
||||||
// Mutate this module into one or more variants each of which is built
|
// Mutate this module into one or more variants each of which is built
|
||||||
// for an APEX marked via BuildForApexes().
|
// for an APEX marked via BuildForApex().
|
||||||
CreateApexVariations(mctx BottomUpMutatorContext) []Module
|
CreateApexVariations(mctx BottomUpMutatorContext) []Module
|
||||||
|
|
||||||
// Tests if this module is available for the specified APEX or ":platform"
|
// Tests if this module is available for the specified APEX or ":platform"
|
||||||
@@ -178,18 +178,15 @@ func (m *ApexModuleBase) TestFor() []string {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ApexModuleBase) BuildForApexes(apexes []ApexInfo) {
|
func (m *ApexModuleBase) BuildForApex(apex ApexInfo) {
|
||||||
m.apexVariationsLock.Lock()
|
m.apexVariationsLock.Lock()
|
||||||
defer m.apexVariationsLock.Unlock()
|
defer m.apexVariationsLock.Unlock()
|
||||||
nextApex:
|
for _, v := range m.apexVariations {
|
||||||
for _, apex := range apexes {
|
if v.ApexName == apex.ApexName {
|
||||||
for _, v := range m.apexVariations {
|
return
|
||||||
if v.ApexName == apex.ApexName {
|
|
||||||
continue nextApex
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m.apexVariations = append(m.apexVariations, apex)
|
|
||||||
}
|
}
|
||||||
|
m.apexVariations = append(m.apexVariations, apex)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ApexModuleBase) ApexVariations() []ApexInfo {
|
func (m *ApexModuleBase) ApexVariations() []ApexInfo {
|
||||||
@@ -327,17 +324,15 @@ func apexNamesMap() map[string]map[string]bool {
|
|||||||
// depended on by the specified APEXes. Directly depending means that a module
|
// depended on by the specified APEXes. Directly depending means that a module
|
||||||
// is explicitly listed in the build definition of the APEX via properties like
|
// is explicitly listed in the build definition of the APEX via properties like
|
||||||
// native_shared_libs, java_libs, etc.
|
// native_shared_libs, java_libs, etc.
|
||||||
func UpdateApexDependency(apexes []ApexInfo, moduleName string, directDep bool) {
|
func UpdateApexDependency(apex ApexInfo, moduleName string, directDep bool) {
|
||||||
apexNamesMapMutex.Lock()
|
apexNamesMapMutex.Lock()
|
||||||
defer apexNamesMapMutex.Unlock()
|
defer apexNamesMapMutex.Unlock()
|
||||||
for _, apex := range apexes {
|
apexesForModule, ok := apexNamesMap()[moduleName]
|
||||||
apexesForModule, ok := apexNamesMap()[moduleName]
|
if !ok {
|
||||||
if !ok {
|
apexesForModule = make(map[string]bool)
|
||||||
apexesForModule = make(map[string]bool)
|
apexNamesMap()[moduleName] = apexesForModule
|
||||||
apexNamesMap()[moduleName] = apexesForModule
|
|
||||||
}
|
|
||||||
apexesForModule[apex.ApexName] = apexesForModule[apex.ApexName] || directDep
|
|
||||||
}
|
}
|
||||||
|
apexesForModule[apex.ApexName] = apexesForModule[apex.ApexName] || directDep
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(b/146393795): remove this when b/146393795 is fixed
|
// TODO(b/146393795): remove this when b/146393795 is fixed
|
||||||
|
47
apex/apex.go
47
apex/apex.go
@@ -669,7 +669,7 @@ func RegisterPreDepsMutators(ctx android.RegisterMutatorsContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
|
func RegisterPostDepsMutators(ctx android.RegisterMutatorsContext) {
|
||||||
ctx.TopDown("apex_deps", apexDepsMutator)
|
ctx.TopDown("apex_deps", apexDepsMutator).Parallel()
|
||||||
ctx.BottomUp("apex", apexMutator).Parallel()
|
ctx.BottomUp("apex", apexMutator).Parallel()
|
||||||
ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
|
ctx.BottomUp("apex_flattened", apexFlattenedMutator).Parallel()
|
||||||
ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
|
ctx.BottomUp("apex_uses", apexUsesMutator).Parallel()
|
||||||
@@ -682,33 +682,30 @@ func apexDepsMutator(mctx android.TopDownMutatorContext) {
|
|||||||
if !mctx.Module().Enabled() {
|
if !mctx.Module().Enabled() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var apexBundles []android.ApexInfo
|
a, ok := mctx.Module().(*apexBundle)
|
||||||
var directDep bool
|
if !ok || a.vndkApex {
|
||||||
if a, ok := mctx.Module().(*apexBundle); ok && !a.vndkApex {
|
|
||||||
apexBundles = []android.ApexInfo{{
|
|
||||||
ApexName: mctx.ModuleName(),
|
|
||||||
MinSdkVersion: a.minSdkVersion(mctx),
|
|
||||||
Updatable: a.Updatable(),
|
|
||||||
}}
|
|
||||||
directDep = true
|
|
||||||
} else if am, ok := mctx.Module().(android.ApexModule); ok {
|
|
||||||
apexBundles = am.ApexVariations()
|
|
||||||
directDep = false
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(apexBundles) == 0 {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
apexInfo := android.ApexInfo{
|
||||||
cur := mctx.Module().(android.DepIsInSameApex)
|
ApexName: mctx.ModuleName(),
|
||||||
|
MinSdkVersion: a.minSdkVersion(mctx),
|
||||||
mctx.VisitDirectDeps(func(child android.Module) {
|
Updatable: a.Updatable(),
|
||||||
depName := mctx.OtherModuleName(child)
|
}
|
||||||
if am, ok := child.(android.ApexModule); ok && am.CanHaveApexVariants() &&
|
mctx.WalkDeps(func(child, parent android.Module) bool {
|
||||||
(cur.DepIsInSameApex(mctx, child) || inAnySdk(child)) {
|
am, ok := child.(android.ApexModule)
|
||||||
android.UpdateApexDependency(apexBundles, depName, directDep)
|
if !ok || !am.CanHaveApexVariants() {
|
||||||
am.BuildForApexes(apexBundles)
|
return false
|
||||||
}
|
}
|
||||||
|
if !parent.(android.DepIsInSameApex).DepIsInSameApex(mctx, child) && !inAnySdk(child) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
depName := mctx.OtherModuleName(child)
|
||||||
|
// If the parent is apexBundle, this child is directly depended.
|
||||||
|
_, directDep := parent.(*apexBundle)
|
||||||
|
android.UpdateApexDependency(apexInfo, depName, directDep)
|
||||||
|
am.BuildForApex(apexInfo)
|
||||||
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user