blob: 0e34c2fd9061e963cdde35c5f6b6a12cf79f9a98 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross3f40fa42015-01-30 17:27:36 -080022 "fmt"
Dan Albert9e10cd42016-08-03 14:12:14 -070023 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080024 "strings"
25
Colin Cross97ba0732015-03-23 17:50:24 -070026 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070027 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070028
Colin Cross463a90e2015-06-17 14:20:06 -070029 "android/soong"
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Crossca860ac2016-01-04 14:34:37 -080036 soong.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross463a90e2015-06-17 14:20:06 -070038 // LinkageMutator must be registered after common.ArchMutator, but that is guaranteed by
39 // the Go initialization order because this package depends on common, so common's init
40 // functions will run first.
Colin Crosse8a67a72016-08-07 21:17:54 -070041 android.RegisterBottomUpMutator("link", linkageMutator).Parallel()
42 android.RegisterBottomUpMutator("ndk_api", ndkApiMutator).Parallel()
43 android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator).Parallel()
44 android.RegisterBottomUpMutator("begin", beginMutator).Parallel()
45 android.RegisterBottomUpMutator("deps", depsMutator).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080046
Colin Cross635c3b02016-05-18 15:37:25 -070047 android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan))
Colin Crosse8a67a72016-08-07 21:17:54 -070048 android.RegisterBottomUpMutator("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Colin Cross635c3b02016-05-18 15:37:25 -070050 android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan))
Colin Crosse8a67a72016-08-07 21:17:54 -070051 android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan)).Parallel()
Colin Crossb98c8b02016-07-29 13:44:28 -070052
53 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070054}
55
Colin Crossca860ac2016-01-04 14:34:37 -080056type Deps struct {
57 SharedLibs, LateSharedLibs []string
58 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070059
Dan Willemsen490a8dc2016-06-06 18:22:19 -070060 ReexportSharedLibHeaders, ReexportStaticLibHeaders []string
61
Colin Cross81413472016-04-11 14:37:39 -070062 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070063
Dan Willemsenb40aab62016-04-20 14:21:14 -070064 GeneratedSources []string
65 GeneratedHeaders []string
66
Colin Cross97ba0732015-03-23 17:50:24 -070067 CrtBegin, CrtEnd string
Colin Crossc472d572015-03-17 15:06:21 -070068}
69
Colin Crossca860ac2016-01-04 14:34:37 -080070type PathDeps struct {
Colin Cross635c3b02016-05-18 15:37:25 -070071 SharedLibs, LateSharedLibs android.Paths
72 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070073
Colin Cross635c3b02016-05-18 15:37:25 -070074 ObjFiles android.Paths
75 WholeStaticLibObjFiles android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070076
Colin Cross635c3b02016-05-18 15:37:25 -070077 GeneratedSources android.Paths
78 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070079
Dan Willemsen76f08272016-07-09 00:14:08 -070080 Flags, ReexportedFlags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070081
Colin Cross635c3b02016-05-18 15:37:25 -070082 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -070083}
84
Colin Crossca860ac2016-01-04 14:34:37 -080085type Flags struct {
Colin Cross28344522015-04-22 13:07:53 -070086 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
87 AsFlags []string // Flags that apply to assembly source files
88 CFlags []string // Flags that apply to C and C++ source files
89 ConlyFlags []string // Flags that apply to C source files
90 CppFlags []string // Flags that apply to C++ source files
91 YaccFlags []string // Flags that apply to Yacc source files
92 LdFlags []string // Flags that apply to linker command lines
Colin Cross16b23492016-01-06 14:41:07 -080093 libFlags []string // Flags to add libraries early to the link order
Colin Cross28344522015-04-22 13:07:53 -070094
Colin Crossb98c8b02016-07-29 13:44:28 -070095 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -070096 Clang bool
Colin Crossca860ac2016-01-04 14:34:37 -080097
98 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -080099 DynamicLinker string
100
Colin Cross635c3b02016-05-18 15:37:25 -0700101 CFlagsDeps android.Paths // Files depended on by compiler flags
Colin Crossc472d572015-03-17 15:06:21 -0700102}
103
Colin Cross81413472016-04-11 14:37:39 -0700104type ObjectLinkerProperties struct {
105 // names of other cc_object modules to link into this module using partial linking
106 Objs []string `android:"arch_variant"`
107}
108
Colin Crossca860ac2016-01-04 14:34:37 -0800109// Properties used to compile all C or C++ modules
110type BaseProperties struct {
111 // compile module with clang instead of gcc
112 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700113
114 // Minimum sdk version supported when compiling against the ndk
115 Sdk_version string
116
Colin Crossca860ac2016-01-04 14:34:37 -0800117 // don't insert default compiler flags into asflags, cflags,
118 // cppflags, conlyflags, ldflags, or include_dirs
119 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700120
121 AndroidMkSharedLibs []string `blueprint:"mutated"`
Colin Crossbc6fb162016-05-24 15:39:04 -0700122 HideFromMake bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800123}
124
Colin Crossca860ac2016-01-04 14:34:37 -0800125type UnusedProperties struct {
Colin Cross21b481b2016-04-15 16:27:17 -0700126 Native_coverage *bool
Colin Cross21b481b2016-04-15 16:27:17 -0700127 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800128}
129
Colin Crossca860ac2016-01-04 14:34:37 -0800130type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800131 static() bool
132 staticBinary() bool
133 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700134 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800135 noDefaultCompilerFlags() bool
136 sdk() bool
137 sdkVersion() string
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700138 selectedStl() string
Colin Crossca860ac2016-01-04 14:34:37 -0800139}
140
141type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700142 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800143 ModuleContextIntf
144}
145
146type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700147 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800148 ModuleContextIntf
149}
150
Colin Crossca860ac2016-01-04 14:34:37 -0800151type feature interface {
152 begin(ctx BaseModuleContext)
153 deps(ctx BaseModuleContext, deps Deps) Deps
154 flags(ctx ModuleContext, flags Flags) Flags
155 props() []interface{}
156}
157
158type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700159 compilerInit(ctx BaseModuleContext)
160 compilerDeps(ctx BaseModuleContext, deps Deps) Deps
161 compilerFlags(ctx ModuleContext, flags Flags) Flags
162 compilerProps() []interface{}
163
Colin Cross76fada02016-07-27 10:31:13 -0700164 appendCflags([]string)
165 appendAsflags([]string)
Colin Cross635c3b02016-05-18 15:37:25 -0700166 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800167}
168
169type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700170 linkerInit(ctx BaseModuleContext)
171 linkerDeps(ctx BaseModuleContext, deps Deps) Deps
172 linkerFlags(ctx ModuleContext, flags Flags) Flags
173 linkerProps() []interface{}
174
Colin Cross635c3b02016-05-18 15:37:25 -0700175 link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700176 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800177}
178
179type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700180 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700181 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800182 inData() bool
183}
184
Colin Crossc99deeb2016-04-11 15:06:20 -0700185type dependencyTag struct {
186 blueprint.BaseDependencyTag
187 name string
188 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700189
190 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700191}
192
193var (
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700194 sharedDepTag = dependencyTag{name: "shared", library: true}
195 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
196 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
197 staticDepTag = dependencyTag{name: "static", library: true}
198 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
199 lateStaticDepTag = dependencyTag{name: "late static", library: true}
200 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
201 genSourceDepTag = dependencyTag{name: "gen source"}
202 genHeaderDepTag = dependencyTag{name: "gen header"}
203 objDepTag = dependencyTag{name: "obj"}
204 crtBeginDepTag = dependencyTag{name: "crtbegin"}
205 crtEndDepTag = dependencyTag{name: "crtend"}
206 reuseObjTag = dependencyTag{name: "reuse objects"}
Dan Albert914449f2016-06-17 16:45:24 -0700207 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
208 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700209)
210
Colin Crossca860ac2016-01-04 14:34:37 -0800211// Module contains the properties and members used by all C/C++ module types, and implements
212// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
213// to construct the output file. Behavior can be customized with a Customizer interface
214type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700215 android.ModuleBase
216 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700217
Colin Crossca860ac2016-01-04 14:34:37 -0800218 Properties BaseProperties
219 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700220
Colin Crossca860ac2016-01-04 14:34:37 -0800221 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700222 hod android.HostOrDeviceSupported
223 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700224
Colin Crossca860ac2016-01-04 14:34:37 -0800225 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700226 features []feature
227 compiler compiler
228 linker linker
229 installer installer
230 stl *stl
231 sanitize *sanitize
Colin Cross16b23492016-01-06 14:41:07 -0800232
233 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700234
Colin Cross635c3b02016-05-18 15:37:25 -0700235 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800236
Colin Crossb98c8b02016-07-29 13:44:28 -0700237 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700238
239 subAndroidMkOnce map[subAndroidMkProvider]bool
Colin Crossc472d572015-03-17 15:06:21 -0700240}
241
Colin Crossca860ac2016-01-04 14:34:37 -0800242func (c *Module) Init() (blueprint.Module, []interface{}) {
243 props := []interface{}{&c.Properties, &c.unused}
Colin Crossca860ac2016-01-04 14:34:37 -0800244 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700245 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800246 }
247 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700248 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800249 }
250 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700251 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800252 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700253 if c.stl != nil {
254 props = append(props, c.stl.props()...)
255 }
Colin Cross16b23492016-01-06 14:41:07 -0800256 if c.sanitize != nil {
257 props = append(props, c.sanitize.props()...)
258 }
Colin Crossca860ac2016-01-04 14:34:37 -0800259 for _, feature := range c.features {
260 props = append(props, feature.props()...)
261 }
Colin Crossc472d572015-03-17 15:06:21 -0700262
Colin Cross635c3b02016-05-18 15:37:25 -0700263 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700264
Colin Cross635c3b02016-05-18 15:37:25 -0700265 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700266}
267
Colin Crossb916a382016-07-29 17:28:03 -0700268// Returns true for dependency roots (binaries)
269// TODO(ccross): also handle dlopenable libraries
270func (c *Module) isDependencyRoot() bool {
271 if root, ok := c.linker.(interface {
272 isDependencyRoot() bool
273 }); ok {
274 return root.isDependencyRoot()
275 }
276 return false
277}
278
Colin Crossca860ac2016-01-04 14:34:37 -0800279type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700280 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800281 moduleContextImpl
282}
283
284type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700285 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800286 moduleContextImpl
287}
288
289type moduleContextImpl struct {
290 mod *Module
291 ctx BaseModuleContext
292}
293
Colin Crossca860ac2016-01-04 14:34:37 -0800294func (ctx *moduleContextImpl) clang() bool {
295 return ctx.mod.clang(ctx.ctx)
296}
297
Colin Crossb98c8b02016-07-29 13:44:28 -0700298func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800299 return ctx.mod.toolchain(ctx.ctx)
300}
301
302func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700303 if static, ok := ctx.mod.linker.(interface {
304 static() bool
305 }); ok {
306 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800307 }
Colin Crossb916a382016-07-29 17:28:03 -0700308 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800309}
310
311func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700312 if static, ok := ctx.mod.linker.(interface {
313 staticBinary() bool
314 }); ok {
315 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800316 }
Colin Crossb916a382016-07-29 17:28:03 -0700317 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800318}
319
320func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
321 return Bool(ctx.mod.Properties.No_default_compiler_flags)
322}
323
324func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsena96ff642016-06-07 12:34:45 -0700325 if ctx.ctx.Device() {
326 return ctx.mod.Properties.Sdk_version != ""
327 }
328 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800329}
330
331func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700332 if ctx.ctx.Device() {
333 return ctx.mod.Properties.Sdk_version
334 }
335 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800336}
337
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700338func (ctx *moduleContextImpl) selectedStl() string {
339 if stl := ctx.mod.stl; stl != nil {
340 return stl.Properties.SelectedStl
341 }
342 return ""
343}
344
Colin Cross635c3b02016-05-18 15:37:25 -0700345func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800346 return &Module{
347 hod: hod,
348 multilib: multilib,
349 }
350}
351
Colin Cross635c3b02016-05-18 15:37:25 -0700352func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800353 module := newBaseModule(hod, multilib)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700354 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800355 module.sanitize = &sanitize{}
Colin Crossca860ac2016-01-04 14:34:37 -0800356 return module
357}
358
Colin Cross635c3b02016-05-18 15:37:25 -0700359func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800360 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700361 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800362 moduleContextImpl: moduleContextImpl{
363 mod: c,
364 },
365 }
366 ctx.ctx = ctx
367
368 flags := Flags{
369 Toolchain: c.toolchain(ctx),
370 Clang: c.clang(ctx),
371 }
Colin Crossca860ac2016-01-04 14:34:37 -0800372 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700373 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800374 }
375 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700376 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800377 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700378 if c.stl != nil {
379 flags = c.stl.flags(ctx, flags)
380 }
Colin Cross16b23492016-01-06 14:41:07 -0800381 if c.sanitize != nil {
382 flags = c.sanitize.flags(ctx, flags)
383 }
Colin Crossca860ac2016-01-04 14:34:37 -0800384 for _, feature := range c.features {
385 flags = feature.flags(ctx, flags)
386 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800387 if ctx.Failed() {
388 return
389 }
390
Colin Crossb98c8b02016-07-29 13:44:28 -0700391 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
392 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
393 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800394
Colin Crossca860ac2016-01-04 14:34:37 -0800395 // Optimization to reduce size of build.ninja
396 // Replace the long list of flags for each file with a module-local variable
397 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
398 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
399 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
400 flags.CFlags = []string{"$cflags"}
401 flags.CppFlags = []string{"$cppflags"}
402 flags.AsFlags = []string{"$asflags"}
403
Colin Crossc99deeb2016-04-11 15:06:20 -0700404 deps := c.depsToPaths(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800405 if ctx.Failed() {
406 return
407 }
408
Dan Willemsen76f08272016-07-09 00:14:08 -0700409 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Colin Crossed9f8682015-03-18 17:17:35 -0700410
Colin Cross635c3b02016-05-18 15:37:25 -0700411 var objFiles android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800412 if c.compiler != nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700413 objFiles = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800414 if ctx.Failed() {
415 return
416 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800417 }
418
Colin Crossca860ac2016-01-04 14:34:37 -0800419 if c.linker != nil {
420 outputFile := c.linker.link(ctx, flags, deps, objFiles)
421 if ctx.Failed() {
422 return
423 }
Colin Cross635c3b02016-05-18 15:37:25 -0700424 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Cross5049f022015-03-18 13:28:46 -0700425
Colin Crossb916a382016-07-29 17:28:03 -0700426 if c.installer != nil {
Colin Crossca860ac2016-01-04 14:34:37 -0800427 c.installer.install(ctx, outputFile)
428 if ctx.Failed() {
429 return
430 }
431 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700432 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800433}
434
Colin Crossb98c8b02016-07-29 13:44:28 -0700435func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800436 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700437 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800438 }
Colin Crossca860ac2016-01-04 14:34:37 -0800439 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800440}
441
Colin Crossca860ac2016-01-04 14:34:37 -0800442func (c *Module) begin(ctx BaseModuleContext) {
443 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700444 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700445 }
Colin Crossca860ac2016-01-04 14:34:37 -0800446 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700447 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800448 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700449 if c.stl != nil {
450 c.stl.begin(ctx)
451 }
Colin Cross16b23492016-01-06 14:41:07 -0800452 if c.sanitize != nil {
453 c.sanitize.begin(ctx)
454 }
Colin Crossca860ac2016-01-04 14:34:37 -0800455 for _, feature := range c.features {
456 feature.begin(ctx)
457 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700458 if ctx.sdk() {
459 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
460 if err != nil {
461 ctx.PropertyErrorf("sdk_version", err.Error())
462 }
463 c.Properties.Sdk_version = strconv.Itoa(version)
464 }
Colin Crossca860ac2016-01-04 14:34:37 -0800465}
466
Colin Crossc99deeb2016-04-11 15:06:20 -0700467func (c *Module) deps(ctx BaseModuleContext) Deps {
468 deps := Deps{}
469
470 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700471 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700472 }
473 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700474 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700475 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700476 if c.stl != nil {
477 deps = c.stl.deps(ctx, deps)
478 }
Colin Cross16b23492016-01-06 14:41:07 -0800479 if c.sanitize != nil {
480 deps = c.sanitize.deps(ctx, deps)
481 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700482 for _, feature := range c.features {
483 deps = feature.deps(ctx, deps)
484 }
485
486 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
487 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
488 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
489 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
490 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
491
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700492 for _, lib := range deps.ReexportSharedLibHeaders {
493 if !inList(lib, deps.SharedLibs) {
494 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
495 }
496 }
497
498 for _, lib := range deps.ReexportStaticLibHeaders {
499 if !inList(lib, deps.StaticLibs) {
500 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
501 }
502 }
503
Colin Crossc99deeb2016-04-11 15:06:20 -0700504 return deps
505}
506
Dan Albert7e9d2952016-08-04 13:02:36 -0700507func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800508 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700509 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800510 moduleContextImpl: moduleContextImpl{
511 mod: c,
512 },
513 }
514 ctx.ctx = ctx
515
Colin Crossca860ac2016-01-04 14:34:37 -0800516 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700517}
518
519func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
520 ctx := &baseModuleContext{
521 BaseContext: actx,
522 moduleContextImpl: moduleContextImpl{
523 mod: c,
524 },
525 }
526 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800527
Colin Crossc99deeb2016-04-11 15:06:20 -0700528 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800529
Colin Crossb5bc4b42016-07-11 16:11:59 -0700530 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
531 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700532
Dan Albert914449f2016-06-17 16:45:24 -0700533 variantNdkLibs := []string{}
534 variantLateNdkLibs := []string{}
Dan Willemsen72d39932016-07-08 23:23:48 -0700535 if ctx.sdk() {
Dan Albert914449f2016-06-17 16:45:24 -0700536 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700537
Dan Albert914449f2016-06-17 16:45:24 -0700538 // Rewrites the names of shared libraries into the names of the NDK
539 // libraries where appropriate. This returns two slices.
540 //
541 // The first is a list of non-variant shared libraries (either rewritten
542 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
543 // because they are not NDK libraries).
544 //
545 // The second is a list of ndk_library modules. These need to be
546 // separated because they are a variation dependency and must be added
547 // in a different manner.
548 rewriteNdkLibs := func(list []string) ([]string, []string) {
549 variantLibs := []string{}
550 nonvariantLibs := []string{}
551 for _, entry := range list {
Dan Willemsen72d39932016-07-08 23:23:48 -0700552 if inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700553 if !inList(entry, ndkMigratedLibs) {
554 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
555 } else {
556 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
557 }
558 } else {
559 nonvariantLibs = append(variantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700560 }
561 }
Dan Albert914449f2016-06-17 16:45:24 -0700562 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700563 }
564
Dan Albert914449f2016-06-17 16:45:24 -0700565 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
566 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700567 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700568
569 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
570 deps.WholeStaticLibs...)
571
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700572 for _, lib := range deps.StaticLibs {
573 depTag := staticDepTag
574 if inList(lib, deps.ReexportStaticLibHeaders) {
575 depTag = staticExportDepTag
576 }
Colin Cross15a0d462016-07-14 14:49:58 -0700577 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700578 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700579
580 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
581 deps.LateStaticLibs...)
582
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700583 for _, lib := range deps.SharedLibs {
584 depTag := sharedDepTag
585 if inList(lib, deps.ReexportSharedLibHeaders) {
586 depTag = sharedExportDepTag
587 }
Colin Cross15a0d462016-07-14 14:49:58 -0700588 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700589 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700590
591 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
592 deps.LateSharedLibs...)
593
Colin Cross68861832016-07-08 10:41:41 -0700594 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
595 actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
Dan Willemsenb40aab62016-04-20 14:21:14 -0700596
Colin Cross68861832016-07-08 10:41:41 -0700597 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700598
599 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700600 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800601 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700602 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700603 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700604 }
Dan Albert914449f2016-06-17 16:45:24 -0700605
606 version := ctx.sdkVersion()
607 actx.AddVariationDependencies([]blueprint.Variation{
608 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
609 actx.AddVariationDependencies([]blueprint.Variation{
610 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700611}
Colin Cross21b9a242015-03-24 14:15:58 -0700612
Dan Albert7e9d2952016-08-04 13:02:36 -0700613func beginMutator(ctx android.BottomUpMutatorContext) {
614 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
615 c.beginMutator(ctx)
616 }
617}
618
Colin Cross635c3b02016-05-18 15:37:25 -0700619func depsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3f32f032016-07-11 14:36:48 -0700620 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
Colin Cross6362e272015-10-29 15:25:03 -0700621 c.depsMutator(ctx)
622 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800623}
624
Colin Crossca860ac2016-01-04 14:34:37 -0800625func (c *Module) clang(ctx BaseModuleContext) bool {
626 clang := Bool(c.Properties.Clang)
627
628 if c.Properties.Clang == nil {
629 if ctx.Host() {
630 clang = true
631 }
632
633 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
634 clang = true
635 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800636 }
Colin Cross28344522015-04-22 13:07:53 -0700637
Colin Crossca860ac2016-01-04 14:34:37 -0800638 if !c.toolchain(ctx).ClangSupported() {
639 clang = false
640 }
641
642 return clang
643}
644
Colin Crossc99deeb2016-04-11 15:06:20 -0700645// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700646func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800647 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800648
Dan Willemsena96ff642016-06-07 12:34:45 -0700649 // Whether a module can link to another module, taking into
650 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700651 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700652 if from.Target().Os != android.Android {
653 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700654 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700655 }
656 if from.Properties.Sdk_version == "" {
657 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700658 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700659 }
Colin Crossb916a382016-07-29 17:28:03 -0700660 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700661 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700662 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700663 }
664 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
665 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700666 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700667 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700668 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
669 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700670 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700671 }
Colin Crossb916a382016-07-29 17:28:03 -0700672 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700673 // These aren't real libraries, but are the stub shared libraries that are included in
674 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700675 return
Dan Albert914449f2016-06-17 16:45:24 -0700676 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700677 if to.Properties.Sdk_version == "" {
678 // NDK code linking to platform code is never okay.
679 ctx.ModuleErrorf("depends on non-NDK-built library %q",
680 ctx.OtherModuleName(to))
681 }
682
683 // All this point we know we have two NDK libraries, but we need to
684 // check that we're not linking against anything built against a higher
685 // API level, as it is only valid to link against older or equivalent
686 // APIs.
687
688 if from.Properties.Sdk_version == "current" {
689 // Current can link against anything.
690 return
691 } else if to.Properties.Sdk_version == "current" {
692 // Current can't be linked against by anything else.
693 ctx.ModuleErrorf("links %q built against newer API version %q",
694 ctx.OtherModuleName(to), "current")
695 }
696
697 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
698 if err != nil {
699 ctx.PropertyErrorf("sdk_version",
700 "Invalid sdk_version value (must be int): %q",
701 from.Properties.Sdk_version)
702 }
703 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
704 if err != nil {
705 ctx.PropertyErrorf("sdk_version",
706 "Invalid sdk_version value (must be int): %q",
707 to.Properties.Sdk_version)
708 }
709
710 if toApi > fromApi {
711 ctx.ModuleErrorf("links %q built against newer API version %q",
712 ctx.OtherModuleName(to), to.Properties.Sdk_version)
713 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700714 }
715
Colin Crossc99deeb2016-04-11 15:06:20 -0700716 ctx.VisitDirectDeps(func(m blueprint.Module) {
717 name := ctx.OtherModuleName(m)
718 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800719
Colin Cross635c3b02016-05-18 15:37:25 -0700720 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700721 if a == nil {
722 ctx.ModuleErrorf("module %q not an android module", name)
723 return
Colin Crossca860ac2016-01-04 14:34:37 -0800724 }
Colin Crossca860ac2016-01-04 14:34:37 -0800725
Dan Willemsena96ff642016-06-07 12:34:45 -0700726 cc, _ := m.(*Module)
727 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700728 switch tag {
Colin Cross635c3b02016-05-18 15:37:25 -0700729 case android.DefaultsDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700730 case genSourceDepTag:
731 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
732 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
733 genRule.GeneratedSourceFiles()...)
734 } else {
735 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
736 }
737 case genHeaderDepTag:
738 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
739 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
740 genRule.GeneratedSourceFiles()...)
Dan Willemsen76f08272016-07-09 00:14:08 -0700741 depPaths.Flags = append(depPaths.Flags,
Colin Cross635c3b02016-05-18 15:37:25 -0700742 includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}))
Dan Willemsenb40aab62016-04-20 14:21:14 -0700743 } else {
744 ctx.ModuleErrorf("module %q is not a genrule", name)
745 }
746 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700747 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800748 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700749 return
750 }
751
752 if !a.Enabled() {
753 ctx.ModuleErrorf("depends on disabled module %q", name)
754 return
755 }
756
Colin Crossa1ad8d12016-06-01 17:09:44 -0700757 if a.Target().Os != ctx.Os() {
758 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
759 return
760 }
761
762 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
763 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700764 return
765 }
766
Dan Willemsena96ff642016-06-07 12:34:45 -0700767 if !cc.outputFile.Valid() {
Colin Crossc99deeb2016-04-11 15:06:20 -0700768 ctx.ModuleErrorf("module %q missing output file", name)
769 return
770 }
771
772 if tag == reuseObjTag {
773 depPaths.ObjFiles = append(depPaths.ObjFiles,
Colin Crossb916a382016-07-29 17:28:03 -0700774 cc.compiler.(libraryInterface).reuseObjs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700775 return
776 }
777
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700778 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700779 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700780 flags := i.exportedFlags()
781 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700782
783 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700784 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700785 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700786 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700787
Dan Albert9e10cd42016-08-03 14:12:14 -0700788 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700789 }
790
Colin Cross635c3b02016-05-18 15:37:25 -0700791 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700792
793 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700794 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700795 depPtr = &depPaths.SharedLibs
Dan Albert914449f2016-06-17 16:45:24 -0700796 case lateSharedDepTag, ndkLateStubDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700797 depPtr = &depPaths.LateSharedLibs
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700798 case staticDepTag, staticExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700799 depPtr = &depPaths.StaticLibs
800 case lateStaticDepTag:
801 depPtr = &depPaths.LateStaticLibs
802 case wholeStaticDepTag:
803 depPtr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -0700804 staticLib, ok := cc.linker.(libraryInterface)
805 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700806 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700807 return
808 }
809
810 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
811 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
812 for i := range missingDeps {
813 missingDeps[i] += postfix
814 }
815 ctx.AddMissingDependencies(missingDeps)
816 }
817 depPaths.WholeStaticLibObjFiles =
Colin Crossc7a38dc2016-07-12 13:13:09 -0700818 append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700819 case objDepTag:
820 depPtr = &depPaths.ObjFiles
821 case crtBeginDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700822 depPaths.CrtBegin = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700823 case crtEndDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700824 depPaths.CrtEnd = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700825 default:
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700826 panic(fmt.Errorf("unknown dependency tag: %s", tag))
Colin Crossc99deeb2016-04-11 15:06:20 -0700827 }
828
829 if depPtr != nil {
Dan Willemsena96ff642016-06-07 12:34:45 -0700830 *depPtr = append(*depPtr, cc.outputFile.Path())
Colin Crossca860ac2016-01-04 14:34:37 -0800831 }
832 })
833
834 return depPaths
835}
836
837func (c *Module) InstallInData() bool {
838 if c.installer == nil {
839 return false
840 }
Colin Cross94610402016-08-29 13:41:32 -0700841 if c.sanitize != nil && c.sanitize.inData() {
842 return true
843 }
Colin Crossca860ac2016-01-04 14:34:37 -0800844 return c.installer.inData()
845}
846
Colin Cross2ba19d92015-05-07 15:44:20 -0700847//
Colin Crosscfad1192015-11-02 16:43:11 -0800848// Defaults
849//
Colin Crossca860ac2016-01-04 14:34:37 -0800850type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700851 android.ModuleBase
852 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -0800853}
854
Colin Cross635c3b02016-05-18 15:37:25 -0700855func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -0800856}
857
Colin Crossca860ac2016-01-04 14:34:37 -0800858func defaultsFactory() (blueprint.Module, []interface{}) {
Colin Crosse1d764e2016-08-18 14:18:32 -0700859 return DefaultsFactory()
860}
861
862func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
Colin Crossca860ac2016-01-04 14:34:37 -0800863 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -0800864
Colin Crosse1d764e2016-08-18 14:18:32 -0700865 props = append(props,
Colin Crossca860ac2016-01-04 14:34:37 -0800866 &BaseProperties{},
867 &BaseCompilerProperties{},
868 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700869 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -0700870 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800871 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700872 &TestProperties{},
873 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800874 &UnusedProperties{},
875 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -0800876 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -0700877 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -0700878 &InstallerProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -0700879 )
Colin Crosscfad1192015-11-02 16:43:11 -0800880
Colin Crosse1d764e2016-08-18 14:18:32 -0700881 _, props = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
882 android.MultilibDefault, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800883
Colin Crosse1d764e2016-08-18 14:18:32 -0700884 return android.InitDefaultsModule(module, module, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800885}
886
Colin Cross74d1ec02015-04-28 13:30:13 -0700887// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
888// modifies the slice contents in place, and returns a subslice of the original slice
889func lastUniqueElements(list []string) []string {
890 totalSkip := 0
891 for i := len(list) - 1; i >= totalSkip; i-- {
892 skip := 0
893 for j := i - 1; j >= totalSkip; j-- {
894 if list[i] == list[j] {
895 skip++
896 } else {
897 list[j+skip] = list[j]
898 }
899 }
900 totalSkip += skip
901 }
902 return list[totalSkip:]
903}
Colin Cross06a931b2015-10-28 17:23:31 -0700904
905var Bool = proptools.Bool