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
This commit is contained in:
Colin Cross 2015-06-16 16:38:17 -07:00
parent 6a745c6ad0
commit 1f8c52be73
6 changed files with 79 additions and 54 deletions

View file

@ -80,7 +80,6 @@ bootstrap_go_package {
],
srcs: [
"common/arch.go",
"common/checkbuild.go",
"common/config.go",
"common/defs.go",
"common/env.go",

View file

@ -53,7 +53,7 @@ rule g.bootstrap.link
# Variant:
# Type: bootstrap_go_binary
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Android.bp:186:1
# Defined: build/soong/Android.bp:185:1
build .bootstrap/androidbp/obj/androidbp.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/androidbp/cmd/androidbp.go $
@ -77,7 +77,7 @@ default .bootstrap/bin/androidbp
# Variant:
# Type: bootstrap_go_binary
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Android.bp:162:1
# Defined: build/soong/Android.bp:161:1
build .bootstrap/androidmk/obj/androidmk.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/android.go $
@ -103,7 +103,7 @@ default .bootstrap/bin/androidmk
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Android.bp:175:1
# Defined: build/soong/Android.bp:174:1
build .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a: $
g.bootstrap.gc $
@ -334,7 +334,7 @@ default .bootstrap/soong-art/pkg/android/soong/art.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Android.bp:94:1
# Defined: build/soong/Android.bp:93:1
build .bootstrap/soong-cc/pkg/android/soong/cc.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/cc/builder.go $
@ -371,7 +371,6 @@ default .bootstrap/soong-cc/pkg/android/soong/cc.a
build .bootstrap/soong-common/pkg/android/soong/common.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/common/arch.go $
${g.bootstrap.srcDir}/build/soong/common/checkbuild.go $
${g.bootstrap.srcDir}/build/soong/common/config.go $
${g.bootstrap.srcDir}/build/soong/common/defs.go $
${g.bootstrap.srcDir}/build/soong/common/env.go $
@ -409,7 +408,7 @@ default .bootstrap/soong-env/pkg/android/soong/env.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Android.bp:119:1
# Defined: build/soong/Android.bp:118:1
build .bootstrap/soong-genrule/pkg/android/soong/genrule.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/genrule/genrule.go | $
@ -447,7 +446,7 @@ default .bootstrap/soong-glob/pkg/android/soong/glob.a
# Variant:
# Type: bootstrap_go_package
# Factory: github.com/google/blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Android.bp:139:1
# Defined: build/soong/Android.bp:138:1
build .bootstrap/soong-java/pkg/android/soong/java.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/java/app_builder.go $
@ -560,7 +559,7 @@ default .bootstrap/bin/soong_glob
# Variant:
# Type: bootstrap_go_binary
# Factory: github.com/google/blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Android.bp:132:1
# Defined: build/soong/Android.bp:131:1
build .bootstrap/soong_jar/obj/soong_jar.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/cmd/soong_jar/soong_jar.go | $

View file

@ -81,7 +81,7 @@ func main() {
ctx.RegisterEarlyMutator("test_per_src", cc.TestPerSrcMutator)
// Singletons
ctx.RegisterSingletonType("checkbuild", common.CheckbuildSingleton)
ctx.RegisterSingletonType("buildtarget", common.BuildTargetSingleton)
ctx.RegisterSingletonType("env", common.EnvSingleton)
ctx.RegisterSingletonType("logtags", java.LogtagsSingleton)

View file

@ -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,
})
}

View file

@ -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,
})
}
}

View file

@ -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
}