aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2015-06-16 16:38:17 -0700
committerColin Cross <ccross@android.com>2015-06-17 10:18:35 -0700
commit1f8c52be73d31f3347bcf7f8fb29b49e87b3864e (patch)
tree23616e741990bb453c70fa2168dc31c9f690aa4a /common
parent6a745c6ad0ff590e1175cd76b81ca3fef2ec0731 (diff)
downloadbuild_soong-1f8c52be73d31f3347bcf7f8fb29b49e87b3864e.tar.gz
build_soong-1f8c52be73d31f3347bcf7f8fb29b49e87b3864e.tar.bz2
build_soong-1f8c52be73d31f3347bcf7f8fb29b49e87b3864e.zip
Add per-directory build targets
Build a map of blueprint directory to modules built from that directory, and then add phony rules to build.ninja that emulate the behavior of mma in the current build system. Also fixes checkbuild to depend on checkbuild files and installable files, but not installed files. Change-Id: I8bad6e93387940df7439dbd4554f6d79f924c65f
Diffstat (limited to 'common')
-rw-r--r--common/checkbuild.go44
-rw-r--r--common/module.go60
-rw-r--r--common/util.go11
3 files changed, 71 insertions, 44 deletions
diff --git a/common/checkbuild.go b/common/checkbuild.go
deleted file mode 100644
index 17ec37ff..00000000
--- a/common/checkbuild.go
+++ /dev/null
@@ -1,44 +0,0 @@
-// Copyright 2015 Google Inc. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package common
-
-import (
- "github.com/google/blueprint"
-)
-
-func CheckbuildSingleton() blueprint.Singleton {
- return &checkbuildSingleton{}
-}
-
-type checkbuildSingleton struct{}
-
-func (c *checkbuildSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
- deps := []string{}
- ctx.VisitAllModules(func(module blueprint.Module) {
- if a, ok := module.(AndroidModule); ok {
- if len(a.base().checkbuildFiles) > 0 {
- deps = append(deps, ctx.ModuleName(module)+"-checkbuild")
- }
- }
- })
-
- ctx.Build(pctx, blueprint.BuildParams{
- Rule: blueprint.Phony,
- Outputs: []string{"checkbuild"},
- Implicits: deps,
- // HACK: checkbuild should be an optional build, but force it enabled for now
- //Optional: true,
- })
-}
diff --git a/common/module.go b/common/module.go
index ef7c63ae..327aeca5 100644
--- a/common/module.go
+++ b/common/module.go
@@ -194,6 +194,12 @@ type AndroidModuleBase struct {
noAddressSanitizer bool
installFiles []string
checkbuildFiles []string
+
+ // Used by buildTargetSingleton to create checkbuild and per-directory build targets
+ // Only set on the final variant of each module
+ installTarget string
+ checkbuildTarget string
+ blueprintDir string
}
func (a *AndroidModuleBase) base() *AndroidModuleBase {
@@ -273,6 +279,7 @@ func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
Implicits: allInstalledFiles,
})
deps = append(deps, name)
+ a.installTarget = name
}
if len(allCheckbuildFiles) > 0 {
@@ -284,6 +291,7 @@ func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
Optional: true,
})
deps = append(deps, name)
+ a.checkbuildTarget = name
}
if len(deps) > 0 {
@@ -293,6 +301,8 @@ func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
Implicits: deps,
Optional: true,
})
+
+ a.blueprintDir = ctx.ModuleDir()
}
}
@@ -424,6 +434,7 @@ func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string
})
a.installFiles = append(a.installFiles, fullInstallPath)
+ a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
return fullInstallPath
}
@@ -467,3 +478,52 @@ func ExpandSources(ctx AndroidModuleContext, srcFiles []string) []string {
srcFiles = expandGlobs(ctx, srcFiles)
return srcFiles
}
+
+func BuildTargetSingleton() blueprint.Singleton {
+ return &buildTargetSingleton{}
+}
+
+type buildTargetSingleton struct{}
+
+func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
+ checkbuildDeps := []string{}
+
+ dirModules := make(map[string][]string)
+
+ ctx.VisitAllModules(func(module blueprint.Module) {
+ if a, ok := module.(AndroidModule); ok {
+ blueprintDir := a.base().blueprintDir
+ installTarget := a.base().installTarget
+ checkbuildTarget := a.base().checkbuildTarget
+
+ if checkbuildTarget != "" {
+ checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
+ dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget)
+ }
+
+ if installTarget != "" {
+ dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget)
+ }
+ }
+ })
+
+ // Create a top-level checkbuild target that depends on all modules
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{"checkbuild"},
+ Implicits: checkbuildDeps,
+ // HACK: checkbuild should be an optional build, but force it enabled for now
+ //Optional: true,
+ })
+
+ // Create a mm/<directory> target that depends on all modules in a directory
+ dirs := sortedKeys(dirModules)
+ for _, dir := range dirs {
+ ctx.Build(pctx, blueprint.BuildParams{
+ Rule: blueprint.Phony,
+ Outputs: []string{filepath.Join("mm", dir)},
+ Implicits: dirModules[dir],
+ Optional: true,
+ })
+ }
+}
diff --git a/common/util.go b/common/util.go
index 599b3b17..0a0ed138 100644
--- a/common/util.go
+++ b/common/util.go
@@ -14,6 +14,8 @@
package common
+import "sort"
+
func JoinWithPrefix(strs []string, prefix string) string {
if len(strs) == 0 {
return ""
@@ -65,3 +67,12 @@ func JoinWithPrefixAndQuote(strs []string, prefix string) string {
}
return string(ret)
}
+
+func sortedKeys(m map[string][]string) []string {
+ s := make([]string, 0, len(m))
+ for k := range m {
+ s = append(s, k)
+ }
+ sort.Strings(s)
+ return s
+}