Add support for checkbuild target

Modules can choose to add "installed files", which are files that
a product can depend on to cause the module to build, and "checkbuild
files", which will only be built if another module that needs to build
depends on them.  For every target, add a module-install and a
module-checkbuild target that create dependencies on those files,
and then add a global checkbuild target that depends on all the
module-checkbuild targets.  Also add a module target for each module
that depends on module-install and module-checkbuild.

Change-Id: I801389ad6ab9806b71d92cd327a0f9cb7582e0df
This commit is contained in:
Colin Cross
2015-03-17 13:24:18 -07:00
parent 3075ad07e4
commit 9454bfafcb
5 changed files with 83 additions and 8 deletions

View File

@@ -56,6 +56,7 @@ bootstrap_go_package {
],
srcs: [
"common/arch.go",
"common/checkbuild.go",
"common/defs.go",
"common/glob.go",
"common/module.go",

View File

@@ -53,7 +53,7 @@ rule g.bootstrap.link
# Variant:
# Type: bootstrap_go_binary
# Factory: blueprint/bootstrap.newGoBinaryModule
# Defined: build/soong/Blueprints:106:1
# Defined: build/soong/Blueprints:107:1
build .bootstrap/androidmk/obj/androidmk.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/androidmk/cmd/androidmk/android.go $
@@ -79,7 +79,7 @@ default .bootstrap/bin/androidmk
# Variant:
# Type: bootstrap_go_package
# Factory: blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:119:1
# Defined: build/soong/Blueprints:120:1
build .bootstrap/androidmk-parser/pkg/android/soong/androidmk/parser.a: $
g.bootstrap.gc $
@@ -274,7 +274,7 @@ default .bootstrap/bin/minibp
# Variant:
# Type: bootstrap_go_package
# Factory: blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:79:1
# Defined: build/soong/Blueprints:80:1
build .bootstrap/soong-cc/pkg/android/soong/cc.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/cc/builder.go $
@@ -308,6 +308,7 @@ 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/defs.go $
${g.bootstrap.srcDir}/build/soong/common/glob.go $
${g.bootstrap.srcDir}/build/soong/common/module.go $
@@ -329,7 +330,7 @@ default .bootstrap/soong-common/pkg/android/soong/common.a
# Variant:
# Type: bootstrap_go_package
# Factory: blueprint/bootstrap.newGoPackageModule
# Defined: build/soong/Blueprints:66:1
# Defined: build/soong/Blueprints:67:1
build .bootstrap/soong-config/pkg/android/soong/config.a: g.bootstrap.gc $
${g.bootstrap.srcDir}/build/soong/config/config.go | $

View File

@@ -54,6 +54,7 @@ func main() {
ctx.RegisterEarlyMutator("link", cc.LinkageMutator)
// Singletons
ctx.RegisterSingletonType("checkbuild", common.CheckbuildSingleton)
configuration, err := config.New(srcDir)
if err != nil {

43
common/checkbuild.go Normal file
View File

@@ -0,0 +1,43 @@
// 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 (
"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,
Optional: true,
})
}

View File

@@ -212,18 +212,45 @@ func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
}
allInstalledFiles := []string{}
allCheckbuildFiles := []string{}
ctx.VisitAllModuleVariants(func(module blueprint.Module) {
if androidModule, ok := module.(AndroidModule); ok {
files := androidModule.base().installFiles
allInstalledFiles = append(allInstalledFiles, files...)
files = androidModule.base().checkbuildFiles
allCheckbuildFiles = append(allCheckbuildFiles, files...)
}
})
deps := []string{}
if len(allInstalledFiles) > 0 {
name := ctx.ModuleName() + "-install"
ctx.Build(pctx, blueprint.BuildParams{
Rule: blueprint.Phony,
Outputs: []string{name},
Implicits: allInstalledFiles,
})
deps = append(deps, name)
}
if len(allCheckbuildFiles) > 0 {
name := ctx.ModuleName() + "-checkbuild"
ctx.Build(pctx, blueprint.BuildParams{
Rule: blueprint.Phony,
Outputs: []string{name},
Implicits: allCheckbuildFiles,
Optional: true,
})
deps = append(deps, name)
}
if len(deps) > 0 {
ctx.Build(pctx, blueprint.BuildParams{
Rule: blueprint.Phony,
Outputs: []string{ctx.ModuleName()},
Inputs: allInstalledFiles,
Implicits: deps,
Optional: true,
})
}
}
@@ -262,6 +289,9 @@ func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
if ctx.Failed() {
return
}
a.installFiles = append(a.installFiles, androidCtx.installFiles...)
a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...)
}
type androidModuleContext struct {
@@ -300,7 +330,6 @@ func (a *androidModuleContext) InstallFile(installPath, srcPath string) {
})
a.installFiles = append(a.installFiles, fullInstallPath)
a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
}
func (a *androidModuleContext) CheckbuildFile(srcPath string) {