From 87d8b56eda3c158cc7e4f496741c7e9de7383cc8 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 25 Apr 2017 10:01:55 -0700 Subject: [PATCH] Make soong mm/ targets recursive Put mm/* targets into their parent directory's mm/ target. Test: examine out/soong/build.ninja Change-Id: Iacad3db8c904bb4d90b36e125bb359a7fb90368b --- android/module.go | 45 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/android/module.go b/android/module.go index 2b93d8ea4..d485fbc20 100644 --- a/android/module.go +++ b/android/module.go @@ -836,12 +836,21 @@ func BuildTargetSingleton() blueprint.Singleton { return &buildTargetSingleton{} } +func parentDir(dir string) string { + dir, _ = filepath.Split(dir) + return filepath.Clean(dir) +} + type buildTargetSingleton struct{} func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) { checkbuildDeps := []string{} - dirModules := make(map[string][]string) + mmTarget := func(dir string) string { + return filepath.Join("mm", dir) + } + + modulesInDir := make(map[string][]string) ctx.VisitAllModules(func(module blueprint.Module) { if a, ok := module.(Module); ok { @@ -851,11 +860,11 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonConte if checkbuildTarget != "" { checkbuildDeps = append(checkbuildDeps, checkbuildTarget) - dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget) + modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], checkbuildTarget) } if installTarget != "" { - dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget) + modulesInDir[blueprintDir] = append(modulesInDir[blueprintDir], installTarget) } } }) @@ -873,13 +882,35 @@ func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonConte Optional: true, }) - // Create a mm/ target that depends on all modules in a directory - dirs := sortedKeys(dirModules) + // Ensure ancestor directories are in modulesInDir + dirs := sortedKeys(modulesInDir) + for _, dir := range dirs { + dir := parentDir(dir) + for dir != "." && dir != "/" { + if _, exists := modulesInDir[dir]; exists { + break + } + modulesInDir[dir] = nil + dir = parentDir(dir) + } + } + + // Make directories build their direct subdirectories + dirs = sortedKeys(modulesInDir) + for _, dir := range dirs { + p := parentDir(dir) + if p != "." && p != "/" { + modulesInDir[p] = append(modulesInDir[p], mmTarget(dir)) + } + } + + // Create a mm/ target that depends on all modules in a directory, and depends + // on the mm/* targets of all of its subdirectories that contain Android.bp files. for _, dir := range dirs { ctx.Build(pctx, blueprint.BuildParams{ Rule: blueprint.Phony, - Outputs: []string{filepath.Join("mm", dir)}, - Implicits: dirModules[dir], + Outputs: []string{mmTarget(dir)}, + Implicits: modulesInDir[dir], // HACK: checkbuild should be an optional build, but force it // enabled for now in standalone builds Optional: ctx.Config().(Config).EmbeddedInMake(),