2015-01-31 02:27:36 +01:00
|
|
|
// 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 (
|
|
|
|
"path/filepath"
|
2015-03-24 19:13:38 +01:00
|
|
|
|
2015-12-01 01:06:01 +01:00
|
|
|
"android/soong"
|
2015-06-18 00:09:06 +02:00
|
|
|
"android/soong/glob"
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
"github.com/google/blueprint"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
DeviceSharedLibrary = "shared_library"
|
|
|
|
DeviceStaticLibrary = "static_library"
|
|
|
|
DeviceExecutable = "executable"
|
|
|
|
HostSharedLibrary = "host_shared_library"
|
|
|
|
HostStaticLibrary = "host_static_library"
|
|
|
|
HostExecutable = "host_executable"
|
|
|
|
)
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
type androidBaseContext interface {
|
|
|
|
Arch() Arch
|
2015-05-07 23:11:29 +02:00
|
|
|
HostOrDevice() HostOrDevice
|
2015-11-25 02:53:15 +01:00
|
|
|
HostType() HostType
|
2015-03-24 19:13:38 +01:00
|
|
|
Host() bool
|
|
|
|
Device() bool
|
2015-05-01 01:36:18 +02:00
|
|
|
Darwin() bool
|
2015-03-24 19:13:38 +01:00
|
|
|
Debug() bool
|
2015-04-08 02:11:30 +02:00
|
|
|
AConfig() Config
|
2015-03-24 19:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type AndroidBaseContext interface {
|
|
|
|
blueprint.BaseModuleContext
|
|
|
|
androidBaseContext
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
type AndroidModuleContext interface {
|
|
|
|
blueprint.ModuleContext
|
2015-03-24 19:13:38 +01:00
|
|
|
androidBaseContext
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-07-01 03:15:24 +02:00
|
|
|
ExpandSources(srcFiles, excludes []string) []string
|
2015-07-15 03:26:10 +02:00
|
|
|
Glob(outDir, globPattern string, excludes []string) []string
|
2015-06-18 00:09:06 +02:00
|
|
|
|
2015-04-02 23:37:16 +02:00
|
|
|
InstallFile(installPath, srcPath string, deps ...string) string
|
|
|
|
InstallFileName(installPath, name, srcPath string, deps ...string) string
|
2015-01-31 02:27:36 +01:00
|
|
|
CheckbuildFile(srcPath string)
|
|
|
|
}
|
|
|
|
|
|
|
|
type AndroidModule interface {
|
|
|
|
blueprint.Module
|
|
|
|
|
|
|
|
GenerateAndroidBuildActions(AndroidModuleContext)
|
|
|
|
|
|
|
|
base() *AndroidModuleBase
|
2015-12-01 01:06:01 +01:00
|
|
|
Enabled() bool
|
2015-01-31 02:27:36 +01:00
|
|
|
HostOrDevice() HostOrDevice
|
|
|
|
}
|
|
|
|
|
|
|
|
type commonProperties struct {
|
2015-04-02 22:54:39 +02:00
|
|
|
Name string
|
|
|
|
Deps []string
|
|
|
|
Tags []string
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-12-01 01:06:01 +01:00
|
|
|
// emit build rules for this module
|
|
|
|
Enabled *bool `android:"arch_variant"`
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// control whether this module compiles for 32-bit, 64-bit, or both. Possible values
|
2015-01-31 02:27:36 +01:00
|
|
|
// are "32" (compile for 32-bit only), "64" (compile for 64-bit only), "both" (compile for both
|
|
|
|
// architectures), or "first" (compile for 64-bit on a 64-bit platform, and 32-bit on a 32-bit
|
|
|
|
// platform
|
|
|
|
Compile_multilib string
|
|
|
|
|
2015-05-07 23:11:29 +02:00
|
|
|
// Set by HostOrDeviceMutator
|
|
|
|
CompileHostOrDevice HostOrDevice `blueprint:"mutated"`
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
// Set by HostTypeMutator
|
|
|
|
CompileHostType HostType `blueprint:"mutated"`
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
// Set by ArchMutator
|
|
|
|
CompileArch Arch `blueprint:"mutated"`
|
|
|
|
|
|
|
|
// Set by InitAndroidModule
|
|
|
|
HostOrDeviceSupported HostOrDeviceSupported `blueprint:"mutated"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type hostAndDeviceProperties struct {
|
|
|
|
Host_supported bool
|
|
|
|
Device_supported bool
|
|
|
|
}
|
|
|
|
|
2015-03-17 23:06:21 +01:00
|
|
|
type Multilib string
|
|
|
|
|
|
|
|
const (
|
2015-03-31 02:20:39 +02:00
|
|
|
MultilibBoth Multilib = "both"
|
|
|
|
MultilibFirst Multilib = "first"
|
|
|
|
MultilibCommon Multilib = "common"
|
2015-03-17 23:06:21 +01:00
|
|
|
)
|
|
|
|
|
2015-03-18 21:28:46 +01:00
|
|
|
func InitAndroidModule(m AndroidModule,
|
2015-01-31 02:27:36 +01:00
|
|
|
propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
|
|
|
base := m.base()
|
|
|
|
base.module = m
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2015-07-09 22:57:48 +02:00
|
|
|
propertyStructs = append(propertyStructs, &base.commonProperties, &base.variableProperties)
|
2015-03-18 21:28:46 +01:00
|
|
|
|
|
|
|
return m, propertyStructs
|
|
|
|
}
|
|
|
|
|
|
|
|
func InitAndroidArchModule(m AndroidModule, hod HostOrDeviceSupported, defaultMultilib Multilib,
|
|
|
|
propertyStructs ...interface{}) (blueprint.Module, []interface{}) {
|
|
|
|
|
|
|
|
_, propertyStructs = InitAndroidModule(m, propertyStructs...)
|
|
|
|
|
|
|
|
base := m.base()
|
2015-01-31 02:27:36 +01:00
|
|
|
base.commonProperties.HostOrDeviceSupported = hod
|
2015-11-03 01:43:11 +01:00
|
|
|
base.commonProperties.Compile_multilib = string(defaultMultilib)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
|
|
|
if hod == HostAndDeviceSupported {
|
|
|
|
// Default to module to device supported, host not supported, can override in module
|
|
|
|
// properties
|
|
|
|
base.hostAndDeviceProperties.Device_supported = true
|
|
|
|
propertyStructs = append(propertyStructs, &base.hostAndDeviceProperties)
|
|
|
|
}
|
|
|
|
|
2015-11-03 01:43:11 +01:00
|
|
|
return InitArchModule(m, propertyStructs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// A AndroidModuleBase object contains the properties that are common to all Android
|
|
|
|
// modules. It should be included as an anonymous field in every module
|
|
|
|
// struct definition. InitAndroidModule should then be called from the module's
|
|
|
|
// factory function, and the return values from InitAndroidModule should be
|
|
|
|
// returned from the factory function.
|
|
|
|
//
|
|
|
|
// The AndroidModuleBase type is responsible for implementing the
|
|
|
|
// GenerateBuildActions method to support the blueprint.Module interface. This
|
|
|
|
// method will then call the module's GenerateAndroidBuildActions method once
|
|
|
|
// for each build variant that is to be built. GenerateAndroidBuildActions is
|
|
|
|
// passed a AndroidModuleContext rather than the usual blueprint.ModuleContext.
|
|
|
|
// AndroidModuleContext exposes extra functionality specific to the Android build
|
|
|
|
// system including details about the particular build variant that is to be
|
|
|
|
// generated.
|
|
|
|
//
|
|
|
|
// For example:
|
|
|
|
//
|
|
|
|
// import (
|
|
|
|
// "android/soong/common"
|
2015-03-23 20:57:34 +01:00
|
|
|
// "github.com/google/blueprint"
|
2015-01-31 02:27:36 +01:00
|
|
|
// )
|
|
|
|
//
|
|
|
|
// type myModule struct {
|
|
|
|
// common.AndroidModuleBase
|
|
|
|
// properties struct {
|
|
|
|
// MyProperty string
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func NewMyModule() (blueprint.Module, []interface{}) {
|
|
|
|
// m := &myModule{}
|
|
|
|
// return common.InitAndroidModule(m, &m.properties)
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// func (m *myModule) GenerateAndroidBuildActions(ctx common.AndroidModuleContext) {
|
|
|
|
// // Get the CPU architecture for the current build variant.
|
|
|
|
// variantArch := ctx.Arch()
|
|
|
|
//
|
|
|
|
// // ...
|
|
|
|
// }
|
|
|
|
type AndroidModuleBase struct {
|
|
|
|
// Putting the curiously recurring thing pointing to the thing that contains
|
|
|
|
// the thing pattern to good use.
|
|
|
|
module AndroidModule
|
|
|
|
|
|
|
|
commonProperties commonProperties
|
2015-07-09 22:57:48 +02:00
|
|
|
variableProperties variableProperties
|
2015-01-31 02:27:36 +01:00
|
|
|
hostAndDeviceProperties hostAndDeviceProperties
|
|
|
|
generalProperties []interface{}
|
|
|
|
archProperties []*archProperties
|
|
|
|
|
|
|
|
noAddressSanitizer bool
|
|
|
|
installFiles []string
|
|
|
|
checkbuildFiles []string
|
2015-06-17 01:38:17 +02:00
|
|
|
|
|
|
|
// 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
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidModuleBase) base() *AndroidModuleBase {
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
2015-05-07 23:11:29 +02:00
|
|
|
func (a *AndroidModuleBase) SetHostOrDevice(hod HostOrDevice) {
|
|
|
|
a.commonProperties.CompileHostOrDevice = hod
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (a *AndroidModuleBase) SetHostType(ht HostType) {
|
|
|
|
a.commonProperties.CompileHostType = ht
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func (a *AndroidModuleBase) SetArch(arch Arch) {
|
|
|
|
a.commonProperties.CompileArch = arch
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidModuleBase) HostOrDevice() HostOrDevice {
|
2015-05-07 23:11:29 +02:00
|
|
|
return a.commonProperties.CompileHostOrDevice
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (a *AndroidModuleBase) HostType() HostType {
|
|
|
|
return a.commonProperties.CompileHostType
|
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
func (a *AndroidModuleBase) HostSupported() bool {
|
|
|
|
return a.commonProperties.HostOrDeviceSupported == HostSupported ||
|
|
|
|
a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
|
|
|
|
a.hostAndDeviceProperties.Host_supported
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidModuleBase) DeviceSupported() bool {
|
|
|
|
return a.commonProperties.HostOrDeviceSupported == DeviceSupported ||
|
|
|
|
a.commonProperties.HostOrDeviceSupported == HostAndDeviceSupported &&
|
|
|
|
a.hostAndDeviceProperties.Device_supported
|
|
|
|
}
|
|
|
|
|
2015-12-01 01:06:01 +01:00
|
|
|
func (a *AndroidModuleBase) Enabled() bool {
|
|
|
|
if a.commonProperties.Enabled == nil {
|
|
|
|
if a.HostSupported() && a.HostOrDevice().Host() && a.HostType() == Windows {
|
|
|
|
return false
|
|
|
|
} else {
|
|
|
|
return true
|
|
|
|
}
|
2015-11-25 02:53:15 +01:00
|
|
|
}
|
2015-12-01 01:06:01 +01:00
|
|
|
return *a.commonProperties.Enabled
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidModuleBase) computeInstallDeps(
|
|
|
|
ctx blueprint.ModuleContext) []string {
|
|
|
|
|
|
|
|
result := []string{}
|
|
|
|
ctx.VisitDepsDepthFirstIf(isFileInstaller,
|
|
|
|
func(m blueprint.Module) {
|
|
|
|
fileInstaller := m.(fileInstaller)
|
|
|
|
files := fileInstaller.filesToInstall()
|
|
|
|
result = append(result, files...)
|
|
|
|
})
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidModuleBase) filesToInstall() []string {
|
|
|
|
return a.installFiles
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *AndroidModuleBase) NoAddressSanitizer() bool {
|
|
|
|
return p.noAddressSanitizer
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidModuleBase) generateModuleTarget(ctx blueprint.ModuleContext) {
|
|
|
|
if a != ctx.FinalModule().(AndroidModule).base() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
allInstalledFiles := []string{}
|
2015-03-17 21:24:18 +01:00
|
|
|
allCheckbuildFiles := []string{}
|
2015-01-31 02:27:36 +01:00
|
|
|
ctx.VisitAllModuleVariants(func(module blueprint.Module) {
|
2015-03-27 00:10:12 +01:00
|
|
|
a := module.(AndroidModule).base()
|
|
|
|
allInstalledFiles = append(allInstalledFiles, a.installFiles...)
|
|
|
|
allCheckbuildFiles = append(allCheckbuildFiles, a.checkbuildFiles...)
|
2015-01-31 02:27:36 +01:00
|
|
|
})
|
|
|
|
|
2015-03-17 21:24:18 +01:00
|
|
|
deps := []string{}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
if len(allInstalledFiles) > 0 {
|
2015-03-17 21:24:18 +01:00
|
|
|
name := ctx.ModuleName() + "-install"
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: blueprint.Phony,
|
|
|
|
Outputs: []string{name},
|
|
|
|
Implicits: allInstalledFiles,
|
|
|
|
})
|
|
|
|
deps = append(deps, name)
|
2015-06-17 01:38:17 +02:00
|
|
|
a.installTarget = name
|
2015-03-17 21:24:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(allCheckbuildFiles) > 0 {
|
|
|
|
name := ctx.ModuleName() + "-checkbuild"
|
2015-01-31 02:27:36 +01:00
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
2015-03-17 21:24:18 +01:00
|
|
|
Rule: blueprint.Phony,
|
|
|
|
Outputs: []string{name},
|
|
|
|
Implicits: allCheckbuildFiles,
|
|
|
|
Optional: true,
|
|
|
|
})
|
|
|
|
deps = append(deps, name)
|
2015-06-17 01:38:17 +02:00
|
|
|
a.checkbuildTarget = name
|
2015-03-17 21:24:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if len(deps) > 0 {
|
|
|
|
ctx.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: blueprint.Phony,
|
|
|
|
Outputs: []string{ctx.ModuleName()},
|
|
|
|
Implicits: deps,
|
|
|
|
Optional: true,
|
2015-01-31 02:27:36 +01:00
|
|
|
})
|
2015-06-17 01:38:17 +02:00
|
|
|
|
|
|
|
a.blueprintDir = ctx.ModuleDir()
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 23:25:03 +01:00
|
|
|
func (a *AndroidModuleBase) androidBaseContextFactory(ctx blueprint.BaseModuleContext) androidBaseContextImpl {
|
|
|
|
return androidBaseContextImpl{
|
|
|
|
arch: a.commonProperties.CompileArch,
|
|
|
|
hod: a.commonProperties.CompileHostOrDevice,
|
2015-11-25 02:53:15 +01:00
|
|
|
ht: a.commonProperties.CompileHostType,
|
2015-10-29 23:25:03 +01:00
|
|
|
config: ctx.Config().(Config),
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *AndroidModuleBase) GenerateBuildActions(ctx blueprint.ModuleContext) {
|
|
|
|
androidCtx := &androidModuleContext{
|
2015-10-29 23:25:03 +01:00
|
|
|
ModuleContext: ctx,
|
|
|
|
androidBaseContextImpl: a.androidBaseContextFactory(ctx),
|
|
|
|
installDeps: a.computeInstallDeps(ctx),
|
|
|
|
installFiles: a.installFiles,
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-12-01 01:06:01 +01:00
|
|
|
if !a.Enabled() {
|
2015-01-31 02:27:36 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
a.module.GenerateAndroidBuildActions(androidCtx)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-03-27 00:10:12 +01:00
|
|
|
a.installFiles = append(a.installFiles, androidCtx.installFiles...)
|
|
|
|
a.checkbuildFiles = append(a.checkbuildFiles, androidCtx.checkbuildFiles...)
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
a.generateModuleTarget(ctx)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
type androidBaseContextImpl struct {
|
2015-04-08 02:11:30 +02:00
|
|
|
arch Arch
|
2015-05-07 23:11:29 +02:00
|
|
|
hod HostOrDevice
|
2015-11-25 02:53:15 +01:00
|
|
|
ht HostType
|
2015-04-08 02:11:30 +02:00
|
|
|
debug bool
|
|
|
|
config Config
|
2015-03-24 19:13:38 +01:00
|
|
|
}
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
type androidModuleContext struct {
|
|
|
|
blueprint.ModuleContext
|
2015-03-24 19:13:38 +01:00
|
|
|
androidBaseContextImpl
|
2015-10-29 01:23:31 +01:00
|
|
|
installDeps []string
|
|
|
|
installFiles []string
|
|
|
|
checkbuildFiles []string
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *androidModuleContext) Build(pctx *blueprint.PackageContext, params blueprint.BuildParams) {
|
|
|
|
params.Optional = true
|
|
|
|
a.ModuleContext.Build(pctx, params)
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
func (a *androidBaseContextImpl) Arch() Arch {
|
2015-01-31 02:27:36 +01:00
|
|
|
return a.arch
|
|
|
|
}
|
|
|
|
|
2015-05-07 23:11:29 +02:00
|
|
|
func (a *androidBaseContextImpl) HostOrDevice() HostOrDevice {
|
|
|
|
return a.hod
|
|
|
|
}
|
|
|
|
|
2015-11-25 02:53:15 +01:00
|
|
|
func (a *androidBaseContextImpl) HostType() HostType {
|
|
|
|
return a.ht
|
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
func (a *androidBaseContextImpl) Host() bool {
|
2015-05-07 23:11:29 +02:00
|
|
|
return a.hod.Host()
|
2015-03-24 19:13:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *androidBaseContextImpl) Device() bool {
|
2015-05-07 23:11:29 +02:00
|
|
|
return a.hod.Device()
|
2015-03-24 19:13:38 +01:00
|
|
|
}
|
|
|
|
|
2015-05-01 01:36:18 +02:00
|
|
|
func (a *androidBaseContextImpl) Darwin() bool {
|
2015-11-25 02:53:15 +01:00
|
|
|
return a.hod.Host() && a.ht == Darwin
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
|
|
|
|
2015-03-24 19:13:38 +01:00
|
|
|
func (a *androidBaseContextImpl) Debug() bool {
|
|
|
|
return a.debug
|
|
|
|
}
|
|
|
|
|
2015-04-08 02:11:30 +02:00
|
|
|
func (a *androidBaseContextImpl) AConfig() Config {
|
|
|
|
return a.config
|
|
|
|
}
|
|
|
|
|
2015-04-02 23:37:16 +02:00
|
|
|
func (a *androidModuleContext) InstallFileName(installPath, name, srcPath string,
|
|
|
|
deps ...string) string {
|
|
|
|
|
2015-04-08 02:11:30 +02:00
|
|
|
config := a.AConfig()
|
2015-01-31 02:27:36 +01:00
|
|
|
var fullInstallPath string
|
2015-05-07 23:11:29 +02:00
|
|
|
if a.hod.Device() {
|
2015-01-31 02:27:36 +01:00
|
|
|
// TODO: replace unset with a device name once we have device targeting
|
2015-04-02 23:37:16 +02:00
|
|
|
fullInstallPath = filepath.Join(config.DeviceOut(), "system",
|
|
|
|
installPath, name)
|
2015-01-31 02:27:36 +01:00
|
|
|
} else {
|
2015-11-25 02:53:15 +01:00
|
|
|
// TODO
|
|
|
|
if a.ht == Windows {
|
|
|
|
fullInstallPath = filepath.Join(config.BuildDir(), "host", "windows-x86", installPath, name)
|
|
|
|
} else {
|
|
|
|
fullInstallPath = filepath.Join(config.HostOut(), installPath, name)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2015-04-02 23:37:16 +02:00
|
|
|
deps = append(deps, a.installDeps...)
|
|
|
|
|
2015-01-31 02:27:36 +01:00
|
|
|
a.ModuleContext.Build(pctx, blueprint.BuildParams{
|
|
|
|
Rule: Cp,
|
|
|
|
Outputs: []string{fullInstallPath},
|
|
|
|
Inputs: []string{srcPath},
|
2015-04-02 23:37:16 +02:00
|
|
|
OrderOnly: deps,
|
2015-01-31 02:27:36 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
a.installFiles = append(a.installFiles, fullInstallPath)
|
2015-06-17 01:38:17 +02:00
|
|
|
a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
|
2015-04-02 23:37:16 +02:00
|
|
|
return fullInstallPath
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a *androidModuleContext) InstallFile(installPath, srcPath string, deps ...string) string {
|
|
|
|
return a.InstallFileName(installPath, filepath.Base(srcPath), srcPath, deps...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (a *androidModuleContext) CheckbuildFile(srcPath string) {
|
|
|
|
a.checkbuildFiles = append(a.checkbuildFiles, srcPath)
|
|
|
|
}
|
|
|
|
|
|
|
|
type fileInstaller interface {
|
|
|
|
filesToInstall() []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func isFileInstaller(m blueprint.Module) bool {
|
|
|
|
_, ok := m.(fileInstaller)
|
|
|
|
return ok
|
|
|
|
}
|
|
|
|
|
|
|
|
func isAndroidModule(m blueprint.Module) bool {
|
|
|
|
_, ok := m.(AndroidModule)
|
|
|
|
return ok
|
|
|
|
}
|
2015-04-08 20:21:40 +02:00
|
|
|
|
2015-07-01 03:15:24 +02:00
|
|
|
func findStringInSlice(str string, slice []string) int {
|
|
|
|
for i, s := range slice {
|
|
|
|
if s == str {
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *androidModuleContext) ExpandSources(srcFiles, excludes []string) []string {
|
2015-04-08 20:21:40 +02:00
|
|
|
prefix := ModuleSrcDir(ctx)
|
2015-07-01 03:15:24 +02:00
|
|
|
for i, e := range excludes {
|
|
|
|
j := findStringInSlice(e, srcFiles)
|
|
|
|
if j != -1 {
|
|
|
|
srcFiles = append(srcFiles[:j], srcFiles[j+1:]...)
|
2015-04-08 20:21:40 +02:00
|
|
|
}
|
2015-07-01 03:15:24 +02:00
|
|
|
|
|
|
|
excludes[i] = filepath.Join(prefix, e)
|
2015-04-08 20:21:40 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 03:15:24 +02:00
|
|
|
for i, srcFile := range srcFiles {
|
|
|
|
srcFiles[i] = filepath.Join(prefix, srcFile)
|
2015-06-18 00:09:06 +02:00
|
|
|
}
|
|
|
|
|
2015-07-01 03:15:24 +02:00
|
|
|
if !hasGlob(srcFiles) {
|
|
|
|
return srcFiles
|
2015-06-18 00:09:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
globbedSrcFiles := make([]string, 0, len(srcFiles))
|
|
|
|
for _, s := range srcFiles {
|
2015-07-01 03:15:24 +02:00
|
|
|
if glob.IsGlob(s) {
|
2015-07-15 03:26:10 +02:00
|
|
|
globbedSrcFiles = append(globbedSrcFiles, ctx.Glob("src_glob", s, excludes)...)
|
2015-06-18 00:09:06 +02:00
|
|
|
} else {
|
|
|
|
globbedSrcFiles = append(globbedSrcFiles, s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return globbedSrcFiles
|
|
|
|
}
|
|
|
|
|
2015-07-15 03:26:10 +02:00
|
|
|
func (ctx *androidModuleContext) Glob(outDir, globPattern string, excludes []string) []string {
|
|
|
|
ret, err := Glob(ctx, filepath.Join(ModuleOutDir(ctx), outDir), globPattern, excludes)
|
2015-06-18 00:09:06 +02:00
|
|
|
if err != nil {
|
|
|
|
ctx.ModuleErrorf("glob: %s", err.Error())
|
|
|
|
}
|
|
|
|
return ret
|
2015-04-08 20:21:40 +02:00
|
|
|
}
|
2015-06-17 01:38:17 +02:00
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
func init() {
|
|
|
|
soong.RegisterSingletonType("buildtarget", BuildTargetSingleton)
|
|
|
|
}
|
|
|
|
|
2015-06-17 01:38:17 +02:00
|
|
|
func BuildTargetSingleton() blueprint.Singleton {
|
|
|
|
return &buildTargetSingleton{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type buildTargetSingleton struct{}
|
|
|
|
|
|
|
|
func (c *buildTargetSingleton) GenerateBuildActions(ctx blueprint.SingletonContext) {
|
|
|
|
checkbuildDeps := []string{}
|
|
|
|
|
|
|
|
dirModules := make(map[string][]string)
|
2015-06-18 00:17:12 +02:00
|
|
|
hasBPFile := make(map[string]bool)
|
|
|
|
bpFiles := []string{}
|
2015-06-17 01:38:17 +02:00
|
|
|
|
|
|
|
ctx.VisitAllModules(func(module blueprint.Module) {
|
|
|
|
if a, ok := module.(AndroidModule); ok {
|
|
|
|
blueprintDir := a.base().blueprintDir
|
|
|
|
installTarget := a.base().installTarget
|
|
|
|
checkbuildTarget := a.base().checkbuildTarget
|
2015-06-18 00:17:12 +02:00
|
|
|
bpFile := ctx.BlueprintFile(module)
|
2015-06-17 01:38:17 +02:00
|
|
|
|
|
|
|
if checkbuildTarget != "" {
|
|
|
|
checkbuildDeps = append(checkbuildDeps, checkbuildTarget)
|
|
|
|
dirModules[blueprintDir] = append(dirModules[blueprintDir], checkbuildTarget)
|
|
|
|
}
|
|
|
|
|
|
|
|
if installTarget != "" {
|
|
|
|
dirModules[blueprintDir] = append(dirModules[blueprintDir], installTarget)
|
|
|
|
}
|
2015-06-18 00:17:12 +02:00
|
|
|
|
|
|
|
if !hasBPFile[bpFile] {
|
|
|
|
hasBPFile[bpFile] = true
|
|
|
|
bpFiles = append(bpFiles, bpFile)
|
|
|
|
}
|
2015-06-17 01:38:17 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|