2015-03-18 21:28:46 +01:00
|
|
|
// Copyright 2015 Google Inc. All rights reserved.
|
2015-01-31 02:27:36 +01:00
|
|
|
//
|
|
|
|
// 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 cc
|
|
|
|
|
|
|
|
// This file contains the module types for compiling C/C++ for Android, and converts the properties
|
|
|
|
// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
|
|
|
|
// is handled in builder.go
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2016-08-03 23:12:14 +02:00
|
|
|
"strconv"
|
2015-01-31 02:27:36 +01:00
|
|
|
"strings"
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
"github.com/google/blueprint"
|
2015-10-29 01:23:31 +01:00
|
|
|
"github.com/google/blueprint/proptools"
|
2015-03-24 01:50:24 +01:00
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
"android/soong"
|
2016-05-19 00:37:25 +02:00
|
|
|
"android/soong/android"
|
2016-07-29 22:44:28 +02:00
|
|
|
"android/soong/cc/config"
|
2015-03-18 21:28:46 +01:00
|
|
|
"android/soong/genrule"
|
2015-01-31 02:27:36 +01:00
|
|
|
)
|
|
|
|
|
2015-06-17 23:20:06 +02:00
|
|
|
func init() {
|
2016-01-04 23:34:37 +01:00
|
|
|
soong.RegisterModuleType("cc_defaults", defaultsFactory)
|
|
|
|
|
|
|
|
soong.RegisterModuleType("toolchain_library", toolchainLibraryFactory)
|
2015-06-17 23:20:06 +02:00
|
|
|
|
|
|
|
// LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by
|
|
|
|
// the Go initialization order because this package depends on common, so common's init
|
|
|
|
// functions will run first.
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterBottomUpMutator("link", linkageMutator)
|
2016-06-18 01:45:24 +02:00
|
|
|
android.RegisterBottomUpMutator("ndk_api", ndkApiMutator)
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator)
|
2016-08-04 22:02:36 +02:00
|
|
|
android.RegisterBottomUpMutator("begin", beginMutator)
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterBottomUpMutator("deps", depsMutator)
|
2016-01-06 23:41:07 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan))
|
|
|
|
android.RegisterBottomUpMutator("asan", sanitizerMutator(asan))
|
2016-01-06 23:41:07 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan))
|
|
|
|
android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan))
|
2016-07-29 22:44:28 +02:00
|
|
|
|
|
|
|
pctx.Import("android/soong/cc/config")
|
2015-06-17 23:20:06 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type Deps struct {
|
|
|
|
SharedLibs, LateSharedLibs []string
|
|
|
|
StaticLibs, LateStaticLibs, WholeStaticLibs []string
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
ReexportSharedLibHeaders, ReexportStaticLibHeaders []string
|
|
|
|
|
2016-04-11 23:37:39 +02:00
|
|
|
ObjFiles []string
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-04-20 23:21:14 +02:00
|
|
|
GeneratedSources []string
|
|
|
|
GeneratedHeaders []string
|
|
|
|
|
2015-03-24 01:50:24 +01:00
|
|
|
CrtBegin, CrtEnd string
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type PathDeps struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
SharedLibs, LateSharedLibs android.Paths
|
|
|
|
StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
ObjFiles android.Paths
|
|
|
|
WholeStaticLibObjFiles android.Paths
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
GeneratedSources android.Paths
|
|
|
|
GeneratedHeaders android.Paths
|
2016-04-20 23:21:14 +02:00
|
|
|
|
2016-07-09 09:14:08 +02:00
|
|
|
Flags, ReexportedFlags []string
|
2015-09-24 00:26:20 +02:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
CrtBegin, CrtEnd android.OptionalPath
|
2015-09-24 00:26:20 +02:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type Flags struct {
|
2015-04-22 22:07:53 +02:00
|
|
|
GlobalFlags []string // Flags that apply to C, C++, and assembly source files
|
|
|
|
AsFlags []string // Flags that apply to assembly source files
|
|
|
|
CFlags []string // Flags that apply to C and C++ source files
|
|
|
|
ConlyFlags []string // Flags that apply to C source files
|
|
|
|
CppFlags []string // Flags that apply to C++ source files
|
|
|
|
YaccFlags []string // Flags that apply to Yacc source files
|
|
|
|
LdFlags []string // Flags that apply to linker command lines
|
2016-01-06 23:41:07 +01:00
|
|
|
libFlags []string // Flags to add libraries early to the link order
|
2015-04-22 22:07:53 +02:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
Toolchain config.Toolchain
|
2015-04-22 22:07:53 +02:00
|
|
|
Clang bool
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
RequiredInstructionSet string
|
2016-01-06 23:41:07 +01:00
|
|
|
DynamicLinker string
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
CFlagsDeps android.Paths // Files depended on by compiler flags
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-04-11 23:37:39 +02:00
|
|
|
type ObjectLinkerProperties struct {
|
|
|
|
// names of other cc_object modules to link into this module using partial linking
|
|
|
|
Objs []string `android:"arch_variant"`
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// Properties used to compile all C or C++ modules
|
|
|
|
type BaseProperties struct {
|
|
|
|
// compile module with clang instead of gcc
|
|
|
|
Clang *bool `android:"arch_variant"`
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2015-05-11 22:39:40 +02:00
|
|
|
// Minimum sdk version supported when compiling against the ndk
|
|
|
|
Sdk_version string
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// don't insert default compiler flags into asflags, cflags,
|
|
|
|
// cppflags, conlyflags, ldflags, or include_dirs
|
|
|
|
No_default_compiler_flags *bool
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
AndroidMkSharedLibs []string `blueprint:"mutated"`
|
2016-05-25 00:39:04 +02:00
|
|
|
HideFromMake bool `blueprint:"mutated"`
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type UnusedProperties struct {
|
2016-04-16 01:27:17 +02:00
|
|
|
Native_coverage *bool
|
|
|
|
Required []string
|
|
|
|
Tags []string
|
2015-11-03 01:43:11 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type ModuleContextIntf interface {
|
|
|
|
static() bool
|
|
|
|
staticBinary() bool
|
|
|
|
clang() bool
|
2016-07-29 22:44:28 +02:00
|
|
|
toolchain() config.Toolchain
|
2016-01-04 23:34:37 +01:00
|
|
|
noDefaultCompilerFlags() bool
|
|
|
|
sdk() bool
|
|
|
|
sdkVersion() string
|
2016-03-31 06:00:30 +02:00
|
|
|
selectedStl() string
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type ModuleContext interface {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleContext
|
2016-01-04 23:34:37 +01:00
|
|
|
ModuleContextIntf
|
|
|
|
}
|
|
|
|
|
|
|
|
type BaseModuleContext interface {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.BaseContext
|
2016-01-04 23:34:37 +01:00
|
|
|
ModuleContextIntf
|
|
|
|
}
|
|
|
|
|
2016-07-27 19:31:13 +02:00
|
|
|
type CustomizerFlagsContext interface {
|
|
|
|
BaseModuleContext
|
|
|
|
AppendCflags(...string)
|
|
|
|
AppendLdflags(...string)
|
|
|
|
AppendAsflags(...string)
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type Customizer interface {
|
2016-07-27 19:31:13 +02:00
|
|
|
Flags(CustomizerFlagsContext)
|
2016-01-04 23:34:37 +01:00
|
|
|
Properties() []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type feature interface {
|
|
|
|
begin(ctx BaseModuleContext)
|
|
|
|
deps(ctx BaseModuleContext, deps Deps) Deps
|
|
|
|
flags(ctx ModuleContext, flags Flags) Flags
|
|
|
|
props() []interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
type compiler interface {
|
2016-08-01 22:20:05 +02:00
|
|
|
compilerInit(ctx BaseModuleContext)
|
|
|
|
compilerDeps(ctx BaseModuleContext, deps Deps) Deps
|
|
|
|
compilerFlags(ctx ModuleContext, flags Flags) Flags
|
|
|
|
compilerProps() []interface{}
|
|
|
|
|
2016-07-27 19:31:13 +02:00
|
|
|
appendCflags([]string)
|
|
|
|
appendAsflags([]string)
|
2016-05-19 00:37:25 +02:00
|
|
|
compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type linker interface {
|
2016-08-01 22:20:05 +02:00
|
|
|
linkerInit(ctx BaseModuleContext)
|
|
|
|
linkerDeps(ctx BaseModuleContext, deps Deps) Deps
|
|
|
|
linkerFlags(ctx ModuleContext, flags Flags) Flags
|
|
|
|
linkerProps() []interface{}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
|
2016-07-27 19:31:13 +02:00
|
|
|
appendLdflags([]string)
|
2016-04-12 00:06:20 +02:00
|
|
|
installable() bool
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type installer interface {
|
2016-08-01 22:20:05 +02:00
|
|
|
installerProps() []interface{}
|
2016-05-19 00:37:25 +02:00
|
|
|
install(ctx ModuleContext, path android.Path)
|
2016-01-04 23:34:37 +01:00
|
|
|
inData() bool
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
type dependencyTag struct {
|
|
|
|
blueprint.BaseDependencyTag
|
|
|
|
name string
|
|
|
|
library bool
|
2016-06-07 03:22:19 +02:00
|
|
|
|
|
|
|
reexportFlags bool
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
2016-06-07 03:22:19 +02:00
|
|
|
sharedDepTag = dependencyTag{name: "shared", library: true}
|
|
|
|
sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
|
|
|
|
lateSharedDepTag = dependencyTag{name: "late shared", library: true}
|
|
|
|
staticDepTag = dependencyTag{name: "static", library: true}
|
|
|
|
staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
|
|
|
|
lateStaticDepTag = dependencyTag{name: "late static", library: true}
|
|
|
|
wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
|
|
|
|
genSourceDepTag = dependencyTag{name: "gen source"}
|
|
|
|
genHeaderDepTag = dependencyTag{name: "gen header"}
|
|
|
|
objDepTag = dependencyTag{name: "obj"}
|
|
|
|
crtBeginDepTag = dependencyTag{name: "crtbegin"}
|
|
|
|
crtEndDepTag = dependencyTag{name: "crtend"}
|
|
|
|
reuseObjTag = dependencyTag{name: "reuse objects"}
|
2016-06-18 01:45:24 +02:00
|
|
|
ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
|
|
|
|
ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
|
2016-04-12 00:06:20 +02:00
|
|
|
)
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// Module contains the properties and members used by all C/C++ module types, and implements
|
|
|
|
// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
|
|
|
|
// to construct the output file. Behavior can be customized with a Customizer interface
|
|
|
|
type Module struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultableModule
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
Properties BaseProperties
|
|
|
|
unused UnusedProperties
|
|
|
|
|
|
|
|
// initialize before calling Init
|
2016-05-19 00:37:25 +02:00
|
|
|
hod android.HostOrDeviceSupported
|
|
|
|
multilib android.Multilib
|
2015-04-25 02:31:52 +02:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
// delegates, initialize before calling Init
|
2016-07-27 19:31:13 +02:00
|
|
|
Customizer Customizer
|
2016-01-04 23:34:37 +01:00
|
|
|
features []feature
|
|
|
|
compiler compiler
|
|
|
|
linker linker
|
|
|
|
installer installer
|
2016-04-05 00:07:06 +02:00
|
|
|
stl *stl
|
2016-01-06 23:41:07 +01:00
|
|
|
sanitize *sanitize
|
|
|
|
|
|
|
|
androidMkSharedLibDeps []string
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
outputFile android.OptionalPath
|
2015-04-28 22:30:13 +02:00
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
cachedToolchain config.Toolchain
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (c *Module) Init() (blueprint.Module, []interface{}) {
|
|
|
|
props := []interface{}{&c.Properties, &c.unused}
|
2016-07-27 19:31:13 +02:00
|
|
|
if c.Customizer != nil {
|
|
|
|
props = append(props, c.Customizer.Properties()...)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
if c.compiler != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
props = append(props, c.compiler.compilerProps()...)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
if c.linker != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
props = append(props, c.linker.linkerProps()...)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
if c.installer != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
props = append(props, c.installer.installerProps()...)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
props = append(props, c.stl.props()...)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
props = append(props, c.sanitize.props()...)
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
for _, feature := range c.features {
|
|
|
|
props = append(props, feature.props()...)
|
|
|
|
}
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
_, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
return android.InitDefaultableModule(c, c, props...)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-03-17 23:06:21 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type baseModuleContext struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.BaseContext
|
2016-01-04 23:34:37 +01:00
|
|
|
moduleContextImpl
|
|
|
|
}
|
2015-11-03 01:43:11 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type moduleContext struct {
|
2016-05-19 00:37:25 +02:00
|
|
|
android.ModuleContext
|
2016-01-04 23:34:37 +01:00
|
|
|
moduleContextImpl
|
2015-03-17 23:06:21 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
type moduleContextImpl struct {
|
|
|
|
mod *Module
|
|
|
|
ctx BaseModuleContext
|
|
|
|
}
|
|
|
|
|
2016-07-27 19:31:13 +02:00
|
|
|
func (ctx *moduleContextImpl) AppendCflags(flags ...string) {
|
|
|
|
CheckBadCompilerFlags(ctx.ctx, "", flags)
|
|
|
|
ctx.mod.compiler.appendCflags(flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) AppendAsflags(flags ...string) {
|
|
|
|
CheckBadCompilerFlags(ctx.ctx, "", flags)
|
|
|
|
ctx.mod.compiler.appendAsflags(flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) AppendLdflags(flags ...string) {
|
|
|
|
CheckBadLinkerFlags(ctx.ctx, "", flags)
|
|
|
|
ctx.mod.linker.appendLdflags(flags)
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (ctx *moduleContextImpl) clang() bool {
|
|
|
|
return ctx.mod.clang(ctx.ctx)
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func (ctx *moduleContextImpl) toolchain() config.Toolchain {
|
2016-01-04 23:34:37 +01:00
|
|
|
return ctx.mod.toolchain(ctx.ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) static() bool {
|
|
|
|
if ctx.mod.linker == nil {
|
|
|
|
panic(fmt.Errorf("static called on module %q with no linker", ctx.ctx.ModuleName()))
|
|
|
|
}
|
|
|
|
if linker, ok := ctx.mod.linker.(baseLinkerInterface); ok {
|
|
|
|
return linker.static()
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("static called on module %q that doesn't use base linker", ctx.ctx.ModuleName()))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (ctx *moduleContextImpl) staticBinary() bool {
|
|
|
|
if ctx.mod.linker == nil {
|
|
|
|
panic(fmt.Errorf("staticBinary called on module %q with no linker", ctx.ctx.ModuleName()))
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
if linker, ok := ctx.mod.linker.(baseLinkerInterface); ok {
|
|
|
|
return linker.staticBinary()
|
|
|
|
} else {
|
|
|
|
panic(fmt.Errorf("staticBinary called on module %q that doesn't use base linker", ctx.ctx.ModuleName()))
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
|
|
|
|
return Bool(ctx.mod.Properties.No_default_compiler_flags)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) sdk() bool {
|
2016-06-07 21:34:45 +02:00
|
|
|
if ctx.ctx.Device() {
|
|
|
|
return ctx.mod.Properties.Sdk_version != ""
|
|
|
|
}
|
|
|
|
return false
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ctx *moduleContextImpl) sdkVersion() string {
|
2016-06-07 21:34:45 +02:00
|
|
|
if ctx.ctx.Device() {
|
|
|
|
return ctx.mod.Properties.Sdk_version
|
|
|
|
}
|
|
|
|
return ""
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
2016-03-31 06:00:30 +02:00
|
|
|
func (ctx *moduleContextImpl) selectedStl() string {
|
|
|
|
if stl := ctx.mod.stl; stl != nil {
|
|
|
|
return stl.Properties.SelectedStl
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
|
2016-01-04 23:34:37 +01:00
|
|
|
return &Module{
|
|
|
|
hod: hod,
|
|
|
|
multilib: multilib,
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
|
2016-01-04 23:34:37 +01:00
|
|
|
module := newBaseModule(hod, multilib)
|
2016-04-05 00:07:06 +02:00
|
|
|
module.stl = &stl{}
|
2016-01-06 23:41:07 +01:00
|
|
|
module.sanitize = &sanitize{}
|
2016-01-04 23:34:37 +01:00
|
|
|
return module
|
|
|
|
}
|
2015-03-19 01:17:35 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
|
2016-01-04 23:34:37 +01:00
|
|
|
ctx := &moduleContext{
|
2016-05-19 00:37:25 +02:00
|
|
|
ModuleContext: actx,
|
2016-01-04 23:34:37 +01:00
|
|
|
moduleContextImpl: moduleContextImpl{
|
|
|
|
mod: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx.ctx = ctx
|
|
|
|
|
2016-07-27 19:31:13 +02:00
|
|
|
if c.Customizer != nil {
|
|
|
|
c.Customizer.Flags(ctx)
|
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
flags := Flags{
|
|
|
|
Toolchain: c.toolchain(ctx),
|
|
|
|
Clang: c.clang(ctx),
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
if c.compiler != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
flags = c.compiler.compilerFlags(ctx, flags)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
if c.linker != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
flags = c.linker.linkerFlags(ctx, flags)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
flags = c.stl.flags(ctx, flags)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
flags = c.sanitize.flags(ctx, flags)
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
for _, feature := range c.features {
|
|
|
|
flags = feature.flags(ctx, flags)
|
|
|
|
}
|
2015-03-18 21:28:46 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
|
|
|
|
flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
|
|
|
|
flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
|
|
|
// Optimization to reduce size of build.ninja
|
|
|
|
// Replace the long list of flags for each file with a module-local variable
|
|
|
|
ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
|
|
|
|
ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
|
|
|
|
ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
|
|
|
|
flags.CFlags = []string{"$cflags"}
|
|
|
|
flags.CppFlags = []string{"$cppflags"}
|
|
|
|
flags.AsFlags = []string{"$asflags"}
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
deps := c.depsToPaths(ctx)
|
2015-01-31 02:27:36 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
|
2016-07-09 09:14:08 +02:00
|
|
|
flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var objFiles android.Paths
|
2016-01-04 23:34:37 +01:00
|
|
|
if c.compiler != nil {
|
2016-04-20 23:21:14 +02:00
|
|
|
objFiles = c.compiler.compile(ctx, flags, deps)
|
2016-01-04 23:34:37 +01:00
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2015-03-18 22:01:18 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
if c.linker != nil {
|
|
|
|
outputFile := c.linker.link(ctx, flags, deps, objFiles)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
2016-05-19 00:37:25 +02:00
|
|
|
c.outputFile = android.OptionalPathForPath(outputFile)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if c.installer != nil && c.linker.installable() {
|
2016-01-04 23:34:37 +01:00
|
|
|
c.installer.install(ctx, outputFile)
|
|
|
|
if ctx.Failed() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 22:44:28 +02:00
|
|
|
func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
|
2016-01-04 23:34:37 +01:00
|
|
|
if c.cachedToolchain == nil {
|
2016-07-29 22:44:28 +02:00
|
|
|
c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
return c.cachedToolchain
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (c *Module) begin(ctx BaseModuleContext) {
|
|
|
|
if c.compiler != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
c.compiler.compilerInit(ctx)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
if c.linker != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
c.linker.linkerInit(ctx)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
c.stl.begin(ctx)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
c.sanitize.begin(ctx)
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
for _, feature := range c.features {
|
|
|
|
feature.begin(ctx)
|
|
|
|
}
|
2015-04-25 02:31:52 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
func (c *Module) deps(ctx BaseModuleContext) Deps {
|
|
|
|
deps := Deps{}
|
|
|
|
|
|
|
|
if c.compiler != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
deps = c.compiler.compilerDeps(ctx, deps)
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
|
|
|
if c.linker != nil {
|
2016-08-01 22:20:05 +02:00
|
|
|
deps = c.linker.linkerDeps(ctx, deps)
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
2016-04-05 00:07:06 +02:00
|
|
|
if c.stl != nil {
|
|
|
|
deps = c.stl.deps(ctx, deps)
|
|
|
|
}
|
2016-01-06 23:41:07 +01:00
|
|
|
if c.sanitize != nil {
|
|
|
|
deps = c.sanitize.deps(ctx, deps)
|
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
for _, feature := range c.features {
|
|
|
|
deps = feature.deps(ctx, deps)
|
|
|
|
}
|
|
|
|
|
|
|
|
deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
|
|
|
|
deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
|
|
|
|
deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
|
|
|
|
deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
|
|
|
|
deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
|
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
for _, lib := range deps.ReexportSharedLibHeaders {
|
|
|
|
if !inList(lib, deps.SharedLibs) {
|
|
|
|
ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, lib := range deps.ReexportStaticLibHeaders {
|
|
|
|
if !inList(lib, deps.StaticLibs) {
|
|
|
|
ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
return deps
|
|
|
|
}
|
|
|
|
|
2016-08-04 22:02:36 +02:00
|
|
|
func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
|
2016-01-04 23:34:37 +01:00
|
|
|
ctx := &baseModuleContext{
|
2016-05-19 00:37:25 +02:00
|
|
|
BaseContext: actx,
|
2016-01-04 23:34:37 +01:00
|
|
|
moduleContextImpl: moduleContextImpl{
|
|
|
|
mod: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx.ctx = ctx
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
c.begin(ctx)
|
2016-08-04 22:02:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
|
|
|
|
ctx := &baseModuleContext{
|
|
|
|
BaseContext: actx,
|
|
|
|
moduleContextImpl: moduleContextImpl{
|
|
|
|
mod: c,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
ctx.ctx = ctx
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
deps := c.deps(ctx)
|
2015-04-28 22:30:13 +02:00
|
|
|
|
2016-07-12 01:11:59 +02:00
|
|
|
c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
|
|
|
|
c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
|
2016-07-09 08:23:48 +02:00
|
|
|
|
2016-06-18 01:45:24 +02:00
|
|
|
variantNdkLibs := []string{}
|
|
|
|
variantLateNdkLibs := []string{}
|
2016-07-09 08:23:48 +02:00
|
|
|
if ctx.sdk() {
|
2016-06-18 01:45:24 +02:00
|
|
|
version := ctx.sdkVersion()
|
|
|
|
|
|
|
|
// Rewrites the names of shared libraries into the names of the NDK
|
|
|
|
// libraries where appropriate. This returns two slices.
|
|
|
|
//
|
|
|
|
// The first is a list of non-variant shared libraries (either rewritten
|
|
|
|
// NDK libraries to the modules in prebuilts/ndk, or not rewritten
|
|
|
|
// because they are not NDK libraries).
|
|
|
|
//
|
|
|
|
// The second is a list of ndk_library modules. These need to be
|
|
|
|
// separated because they are a variation dependency and must be added
|
|
|
|
// in a different manner.
|
|
|
|
rewriteNdkLibs := func(list []string) ([]string, []string) {
|
|
|
|
variantLibs := []string{}
|
|
|
|
nonvariantLibs := []string{}
|
|
|
|
for _, entry := range list {
|
2016-07-09 08:23:48 +02:00
|
|
|
if inList(entry, ndkPrebuiltSharedLibraries) {
|
2016-06-18 01:45:24 +02:00
|
|
|
if !inList(entry, ndkMigratedLibs) {
|
|
|
|
nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
|
|
|
|
} else {
|
|
|
|
variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
nonvariantLibs = append(variantLibs, entry)
|
2016-07-09 08:23:48 +02:00
|
|
|
}
|
|
|
|
}
|
2016-06-18 01:45:24 +02:00
|
|
|
return nonvariantLibs, variantLibs
|
2016-07-09 08:23:48 +02:00
|
|
|
}
|
|
|
|
|
2016-06-18 01:45:24 +02:00
|
|
|
deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
|
|
|
|
deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
|
2016-07-09 08:23:48 +02:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
|
|
|
|
deps.WholeStaticLibs...)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
for _, lib := range deps.StaticLibs {
|
|
|
|
depTag := staticDepTag
|
|
|
|
if inList(lib, deps.ReexportStaticLibHeaders) {
|
|
|
|
depTag = staticExportDepTag
|
|
|
|
}
|
2016-07-14 23:49:58 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
|
2016-06-07 03:22:19 +02:00
|
|
|
}
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
|
|
|
|
deps.LateStaticLibs...)
|
2015-03-24 22:15:58 +01:00
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
for _, lib := range deps.SharedLibs {
|
|
|
|
depTag := sharedDepTag
|
|
|
|
if inList(lib, deps.ReexportSharedLibHeaders) {
|
|
|
|
depTag = sharedExportDepTag
|
|
|
|
}
|
2016-07-14 23:49:58 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
|
2016-06-07 03:22:19 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
|
|
|
|
deps.LateSharedLibs...)
|
2016-04-11 23:37:39 +02:00
|
|
|
|
2016-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
|
|
|
|
actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
|
2016-04-20 23:21:14 +02:00
|
|
|
|
2016-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, objDepTag, deps.ObjFiles...)
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
if deps.CrtBegin != "" {
|
2016-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
if deps.CrtEnd != "" {
|
2016-07-08 19:41:41 +02:00
|
|
|
actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
|
2015-03-24 22:15:58 +01:00
|
|
|
}
|
2016-06-18 01:45:24 +02:00
|
|
|
|
|
|
|
version := ctx.sdkVersion()
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{
|
|
|
|
{"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
|
|
|
|
actx.AddVariationDependencies([]blueprint.Variation{
|
|
|
|
{"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
|
2015-10-29 23:25:03 +01:00
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-08-04 22:02:36 +02:00
|
|
|
func beginMutator(ctx android.BottomUpMutatorContext) {
|
|
|
|
if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
|
|
|
|
c.beginMutator(ctx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
func depsMutator(ctx android.BottomUpMutatorContext) {
|
2016-07-11 23:36:48 +02:00
|
|
|
if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
|
2015-10-29 23:25:03 +01:00
|
|
|
c.depsMutator(ctx)
|
|
|
|
}
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-01-04 23:34:37 +01:00
|
|
|
func (c *Module) clang(ctx BaseModuleContext) bool {
|
|
|
|
clang := Bool(c.Properties.Clang)
|
|
|
|
|
|
|
|
if c.Properties.Clang == nil {
|
|
|
|
if ctx.Host() {
|
|
|
|
clang = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
|
|
|
|
clang = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !c.toolchain(ctx).ClangSupported() {
|
|
|
|
clang = false
|
|
|
|
}
|
|
|
|
|
|
|
|
return clang
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
// Convert dependencies to paths. Returns a PathDeps containing paths
|
2016-05-19 00:37:25 +02:00
|
|
|
func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
2016-04-12 00:06:20 +02:00
|
|
|
var depPaths PathDeps
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 21:34:45 +02:00
|
|
|
// Whether a module can link to another module, taking into
|
|
|
|
// account NDK linking.
|
2016-08-03 23:12:14 +02:00
|
|
|
checkLinkType := func(from, to *Module) {
|
2016-06-07 21:34:45 +02:00
|
|
|
if from.Target().Os != android.Android {
|
|
|
|
// Host code is not restricted
|
2016-08-03 23:12:14 +02:00
|
|
|
return
|
2016-06-07 21:34:45 +02:00
|
|
|
}
|
|
|
|
if from.Properties.Sdk_version == "" {
|
|
|
|
// Platform code can link to anything
|
2016-08-03 23:12:14 +02:00
|
|
|
return
|
2016-06-07 21:34:45 +02:00
|
|
|
}
|
|
|
|
if _, ok := to.linker.(*toolchainLibraryLinker); ok {
|
|
|
|
// These are always allowed
|
2016-08-03 23:12:14 +02:00
|
|
|
return
|
2016-06-07 21:34:45 +02:00
|
|
|
}
|
|
|
|
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
|
|
|
|
// These are allowed, but don't set sdk_version
|
2016-08-03 23:12:14 +02:00
|
|
|
return
|
2016-06-07 21:34:45 +02:00
|
|
|
}
|
2016-07-08 05:41:36 +02:00
|
|
|
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
|
|
|
|
// These are allowed, but don't set sdk_version
|
2016-08-03 23:12:14 +02:00
|
|
|
return
|
2016-07-08 05:41:36 +02:00
|
|
|
}
|
2016-06-18 01:45:24 +02:00
|
|
|
if _, ok := to.linker.(*stubLinker); ok {
|
|
|
|
// These aren't real libraries, but are the stub shared libraries that are included in
|
|
|
|
// the NDK.
|
2016-08-03 23:12:14 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if to.Properties.Sdk_version == "" {
|
|
|
|
// NDK code linking to platform code is never okay.
|
|
|
|
ctx.ModuleErrorf("depends on non-NDK-built library %q",
|
|
|
|
ctx.OtherModuleName(to))
|
|
|
|
}
|
|
|
|
|
|
|
|
// All this point we know we have two NDK libraries, but we need to
|
|
|
|
// check that we're not linking against anything built against a higher
|
|
|
|
// API level, as it is only valid to link against older or equivalent
|
|
|
|
// APIs.
|
|
|
|
|
|
|
|
if from.Properties.Sdk_version == "current" {
|
|
|
|
// Current can link against anything.
|
|
|
|
return
|
|
|
|
} else if to.Properties.Sdk_version == "current" {
|
|
|
|
// Current can't be linked against by anything else.
|
|
|
|
ctx.ModuleErrorf("links %q built against newer API version %q",
|
|
|
|
ctx.OtherModuleName(to), "current")
|
|
|
|
}
|
|
|
|
|
|
|
|
fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("sdk_version",
|
|
|
|
"Invalid sdk_version value (must be int): %q",
|
|
|
|
from.Properties.Sdk_version)
|
|
|
|
}
|
|
|
|
toApi, err := strconv.Atoi(to.Properties.Sdk_version)
|
|
|
|
if err != nil {
|
|
|
|
ctx.PropertyErrorf("sdk_version",
|
|
|
|
"Invalid sdk_version value (must be int): %q",
|
|
|
|
to.Properties.Sdk_version)
|
|
|
|
}
|
|
|
|
|
|
|
|
if toApi > fromApi {
|
|
|
|
ctx.ModuleErrorf("links %q built against newer API version %q",
|
|
|
|
ctx.OtherModuleName(to), to.Properties.Sdk_version)
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
2016-06-07 21:34:45 +02:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
|
|
|
name := ctx.OtherModuleName(m)
|
|
|
|
tag := ctx.OtherModuleDependencyTag(m)
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
a, _ := m.(android.Module)
|
2016-04-12 00:06:20 +02:00
|
|
|
if a == nil {
|
|
|
|
ctx.ModuleErrorf("module %q not an android module", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 21:34:45 +02:00
|
|
|
cc, _ := m.(*Module)
|
|
|
|
if cc == nil {
|
2016-04-20 23:21:14 +02:00
|
|
|
switch tag {
|
2016-05-19 00:37:25 +02:00
|
|
|
case android.DefaultsDepTag:
|
2016-04-20 23:21:14 +02:00
|
|
|
case genSourceDepTag:
|
|
|
|
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
|
|
|
|
depPaths.GeneratedSources = append(depPaths.GeneratedSources,
|
|
|
|
genRule.GeneratedSourceFiles()...)
|
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
|
|
|
|
}
|
|
|
|
case genHeaderDepTag:
|
|
|
|
if genRule, ok := m.(genrule.SourceFileGenerator); ok {
|
|
|
|
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
|
|
|
|
genRule.GeneratedSourceFiles()...)
|
2016-07-09 09:14:08 +02:00
|
|
|
depPaths.Flags = append(depPaths.Flags,
|
2016-05-19 00:37:25 +02:00
|
|
|
includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}))
|
2016-04-20 23:21:14 +02:00
|
|
|
} else {
|
|
|
|
ctx.ModuleErrorf("module %q is not a genrule", name)
|
|
|
|
}
|
|
|
|
default:
|
2016-04-12 00:06:20 +02:00
|
|
|
ctx.ModuleErrorf("depends on non-cc module %q", name)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
return
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if !a.Enabled() {
|
|
|
|
ctx.ModuleErrorf("depends on disabled module %q", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-02 02:09:44 +02:00
|
|
|
if a.Target().Os != ctx.Os() {
|
|
|
|
ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if a.Target().Arch.ArchType != ctx.Arch().ArchType {
|
|
|
|
ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
|
2016-04-12 00:06:20 +02:00
|
|
|
return
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2015-04-22 22:07:53 +02:00
|
|
|
|
2016-06-07 21:34:45 +02:00
|
|
|
if !cc.outputFile.Valid() {
|
2016-04-12 00:06:20 +02:00
|
|
|
ctx.ModuleErrorf("module %q missing output file", name)
|
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if tag == reuseObjTag {
|
|
|
|
depPaths.ObjFiles = append(depPaths.ObjFiles,
|
2016-06-07 21:34:45 +02:00
|
|
|
cc.compiler.(*libraryCompiler).reuseObjFiles...)
|
2016-04-12 00:06:20 +02:00
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-06-07 03:22:19 +02:00
|
|
|
if t, ok := tag.(dependencyTag); ok && t.library {
|
2016-06-07 21:34:45 +02:00
|
|
|
if i, ok := cc.linker.(exportedFlagsProducer); ok {
|
2016-07-09 09:14:08 +02:00
|
|
|
flags := i.exportedFlags()
|
|
|
|
depPaths.Flags = append(depPaths.Flags, flags...)
|
2016-06-07 03:22:19 +02:00
|
|
|
|
|
|
|
if t.reexportFlags {
|
2016-07-09 09:14:08 +02:00
|
|
|
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
|
2016-06-07 03:22:19 +02:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
2016-06-07 21:34:45 +02:00
|
|
|
|
2016-08-03 23:12:14 +02:00
|
|
|
checkLinkType(c, cc)
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-05-19 00:37:25 +02:00
|
|
|
var depPtr *android.Paths
|
2016-04-12 00:06:20 +02:00
|
|
|
|
|
|
|
switch tag {
|
2016-06-18 01:45:24 +02:00
|
|
|
case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
|
2016-04-12 00:06:20 +02:00
|
|
|
depPtr = &depPaths.SharedLibs
|
2016-06-18 01:45:24 +02:00
|
|
|
case lateSharedDepTag, ndkLateStubDepTag:
|
2016-04-12 00:06:20 +02:00
|
|
|
depPtr = &depPaths.LateSharedLibs
|
2016-06-07 03:22:19 +02:00
|
|
|
case staticDepTag, staticExportDepTag:
|
2016-04-12 00:06:20 +02:00
|
|
|
depPtr = &depPaths.StaticLibs
|
|
|
|
case lateStaticDepTag:
|
|
|
|
depPtr = &depPaths.LateStaticLibs
|
|
|
|
case wholeStaticDepTag:
|
|
|
|
depPtr = &depPaths.WholeStaticLibs
|
2016-07-12 22:13:09 +02:00
|
|
|
staticLib, _ := cc.linker.(libraryInterface)
|
2016-04-12 00:06:20 +02:00
|
|
|
if staticLib == nil || !staticLib.static() {
|
2016-06-07 21:34:45 +02:00
|
|
|
ctx.ModuleErrorf("module %q not a static library", name)
|
2016-04-12 00:06:20 +02:00
|
|
|
return
|
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-04-12 00:06:20 +02:00
|
|
|
if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
|
|
|
|
postfix := " (required by " + ctx.OtherModuleName(m) + ")"
|
|
|
|
for i := range missingDeps {
|
|
|
|
missingDeps[i] += postfix
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
ctx.AddMissingDependencies(missingDeps)
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
2016-04-12 00:06:20 +02:00
|
|
|
depPaths.WholeStaticLibObjFiles =
|
2016-07-12 22:13:09 +02:00
|
|
|
append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
|
2016-04-12 00:06:20 +02:00
|
|
|
case objDepTag:
|
|
|
|
depPtr = &depPaths.ObjFiles
|
|
|
|
case crtBeginDepTag:
|
2016-06-07 21:34:45 +02:00
|
|
|
depPaths.CrtBegin = cc.outputFile
|
2016-04-12 00:06:20 +02:00
|
|
|
case crtEndDepTag:
|
2016-06-07 21:34:45 +02:00
|
|
|
depPaths.CrtEnd = cc.outputFile
|
2016-04-12 00:06:20 +02:00
|
|
|
default:
|
2016-06-07 03:22:19 +02:00
|
|
|
panic(fmt.Errorf("unknown dependency tag: %s", tag))
|
2016-04-12 00:06:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if depPtr != nil {
|
2016-06-07 21:34:45 +02:00
|
|
|
*depPtr = append(*depPtr, cc.outputFile.Path())
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
return depPaths
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Module) InstallInData() bool {
|
|
|
|
if c.installer == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return c.installer.inData()
|
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
//
|
|
|
|
// Defaults
|
|
|
|
//
|
|
|
|
type Defaults struct {
|
|
|
|
android.ModuleBase
|
|
|
|
android.DefaultsModule
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
2016-04-20 23:21:14 +02:00
|
|
|
}
|
2016-01-04 23:34:37 +01:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func defaultsFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := &Defaults{}
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
propertyStructs := []interface{}{
|
|
|
|
&BaseProperties{},
|
|
|
|
&BaseCompilerProperties{},
|
|
|
|
&BaseLinkerProperties{},
|
|
|
|
&LibraryCompilerProperties{},
|
|
|
|
&FlagExporterProperties{},
|
|
|
|
&LibraryLinkerProperties{},
|
|
|
|
&BinaryLinkerProperties{},
|
|
|
|
&TestLinkerProperties{},
|
|
|
|
&UnusedProperties{},
|
|
|
|
&StlProperties{},
|
|
|
|
&SanitizeProperties{},
|
|
|
|
&StripProperties{},
|
2016-06-18 01:45:24 +02:00
|
|
|
}
|
2016-04-20 23:21:14 +02:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
_, propertyStructs = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
|
|
|
|
android.MultilibDefault, propertyStructs...)
|
2015-03-18 21:28:46 +01:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
return android.InitDefaultsModule(module, module, propertyStructs...)
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
//
|
|
|
|
// Device libraries shipped with gcc
|
|
|
|
//
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
type toolchainLibraryLinker struct {
|
|
|
|
baseLinker
|
2016-01-04 23:34:37 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
var _ baseLinkerInterface = (*toolchainLibraryLinker)(nil)
|
2015-03-26 22:43:45 +01:00
|
|
|
|
2016-08-01 22:20:05 +02:00
|
|
|
func (*toolchainLibraryLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
|
2016-07-29 21:48:20 +02:00
|
|
|
// toolchain libraries can't have any dependencies
|
|
|
|
return deps
|
2016-07-27 19:31:13 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func (*toolchainLibraryLinker) buildStatic() bool {
|
|
|
|
return true
|
2016-03-31 02:35:50 +02:00
|
|
|
}
|
2015-05-01 01:36:18 +02:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func (*toolchainLibraryLinker) buildShared() bool {
|
|
|
|
return false
|
2015-05-01 01:36:18 +02:00
|
|
|
}
|
2015-04-27 20:13:34 +02:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func toolchainLibraryFactory() (blueprint.Module, []interface{}) {
|
|
|
|
module := newBaseModule(android.DeviceSupported, android.MultilibBoth)
|
|
|
|
module.compiler = &baseCompiler{}
|
|
|
|
module.linker = &toolchainLibraryLinker{}
|
|
|
|
module.Properties.Clang = proptools.BoolPtr(false)
|
|
|
|
return module.Init()
|
2015-03-26 22:43:45 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func (library *toolchainLibraryLinker) link(ctx ModuleContext,
|
|
|
|
flags Flags, deps PathDeps, objFiles android.Paths) android.Path {
|
2016-03-31 02:35:50 +02:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
libName := ctx.ModuleName() + staticLibraryExtension
|
|
|
|
outputFile := android.PathForModuleOut(ctx, libName)
|
2016-03-31 02:35:50 +02:00
|
|
|
|
2016-03-31 02:33:52 +02:00
|
|
|
if flags.Clang {
|
2016-07-29 21:48:20 +02:00
|
|
|
ctx.ModuleErrorf("toolchain_library must use GCC, not Clang")
|
2015-04-28 22:30:13 +02:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
CopyGccLib(ctx, libName, flagsToBuilderFlags(flags), outputFile)
|
2015-03-28 02:23:34 +01:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
ctx.CheckbuildFile(outputFile)
|
2015-01-31 02:27:36 +01:00
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
return outputFile
|
2015-01-31 02:27:36 +01:00
|
|
|
}
|
|
|
|
|
2016-07-29 21:48:20 +02:00
|
|
|
func (*toolchainLibraryLinker) installable() bool {
|
2016-01-06 23:41:07 +01:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2015-04-28 22:30:13 +02:00
|
|
|
// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
|
|
|
|
// modifies the slice contents in place, and returns a subslice of the original slice
|
|
|
|
func lastUniqueElements(list []string) []string {
|
|
|
|
totalSkip := 0
|
|
|
|
for i := len(list) - 1; i >= totalSkip; i-- {
|
|
|
|
skip := 0
|
|
|
|
for j := i - 1; j >= totalSkip; j-- {
|
|
|
|
if list[i] == list[j] {
|
|
|
|
skip++
|
|
|
|
} else {
|
|
|
|
list[j+skip] = list[j]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
totalSkip += skip
|
|
|
|
}
|
|
|
|
return list[totalSkip:]
|
|
|
|
}
|
2015-10-29 01:23:31 +01:00
|
|
|
|
|
|
|
var Bool = proptools.Bool
|