blob: d04f8433123b32bdedcc251c0f8a822ed8524415 [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 Crossb0f28952016-09-19 16:46:53 -0700123 PreventInstall bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800124}
125
Colin Crossca860ac2016-01-04 14:34:37 -0800126type UnusedProperties struct {
Colin Cross21b481b2016-04-15 16:27:17 -0700127 Native_coverage *bool
Colin Cross21b481b2016-04-15 16:27:17 -0700128 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800129}
130
Colin Crossca860ac2016-01-04 14:34:37 -0800131type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800132 static() bool
133 staticBinary() bool
134 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700135 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800136 noDefaultCompilerFlags() bool
137 sdk() bool
138 sdkVersion() string
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700139 selectedStl() string
Colin Crossca860ac2016-01-04 14:34:37 -0800140}
141
142type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700143 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800144 ModuleContextIntf
145}
146
147type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700148 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800149 ModuleContextIntf
150}
151
Colin Crossca860ac2016-01-04 14:34:37 -0800152type feature interface {
153 begin(ctx BaseModuleContext)
154 deps(ctx BaseModuleContext, deps Deps) Deps
155 flags(ctx ModuleContext, flags Flags) Flags
156 props() []interface{}
157}
158
159type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700160 compilerInit(ctx BaseModuleContext)
161 compilerDeps(ctx BaseModuleContext, deps Deps) Deps
162 compilerFlags(ctx ModuleContext, flags Flags) Flags
163 compilerProps() []interface{}
164
Colin Cross76fada02016-07-27 10:31:13 -0700165 appendCflags([]string)
166 appendAsflags([]string)
Colin Cross635c3b02016-05-18 15:37:25 -0700167 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800168}
169
170type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700171 linkerInit(ctx BaseModuleContext)
172 linkerDeps(ctx BaseModuleContext, deps Deps) Deps
173 linkerFlags(ctx ModuleContext, flags Flags) Flags
174 linkerProps() []interface{}
175
Colin Cross635c3b02016-05-18 15:37:25 -0700176 link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700177 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800178}
179
180type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700181 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700182 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800183 inData() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700184 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800185}
186
Colin Crossc99deeb2016-04-11 15:06:20 -0700187type dependencyTag struct {
188 blueprint.BaseDependencyTag
189 name string
190 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700191
192 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700193}
194
195var (
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700196 sharedDepTag = dependencyTag{name: "shared", library: true}
197 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
198 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
199 staticDepTag = dependencyTag{name: "static", library: true}
200 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
201 lateStaticDepTag = dependencyTag{name: "late static", library: true}
202 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
203 genSourceDepTag = dependencyTag{name: "gen source"}
204 genHeaderDepTag = dependencyTag{name: "gen header"}
205 objDepTag = dependencyTag{name: "obj"}
206 crtBeginDepTag = dependencyTag{name: "crtbegin"}
207 crtEndDepTag = dependencyTag{name: "crtend"}
208 reuseObjTag = dependencyTag{name: "reuse objects"}
Dan Albert914449f2016-06-17 16:45:24 -0700209 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
210 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700211)
212
Colin Crossca860ac2016-01-04 14:34:37 -0800213// Module contains the properties and members used by all C/C++ module types, and implements
214// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
215// to construct the output file. Behavior can be customized with a Customizer interface
216type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700217 android.ModuleBase
218 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700219
Colin Crossca860ac2016-01-04 14:34:37 -0800220 Properties BaseProperties
221 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700222
Colin Crossca860ac2016-01-04 14:34:37 -0800223 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700224 hod android.HostOrDeviceSupported
225 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700226
Colin Crossca860ac2016-01-04 14:34:37 -0800227 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700228 features []feature
229 compiler compiler
230 linker linker
231 installer installer
232 stl *stl
233 sanitize *sanitize
Colin Cross16b23492016-01-06 14:41:07 -0800234
235 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700236
Colin Cross635c3b02016-05-18 15:37:25 -0700237 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800238
Colin Crossb98c8b02016-07-29 13:44:28 -0700239 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700240
241 subAndroidMkOnce map[subAndroidMkProvider]bool
Colin Crossc472d572015-03-17 15:06:21 -0700242}
243
Colin Crossca860ac2016-01-04 14:34:37 -0800244func (c *Module) Init() (blueprint.Module, []interface{}) {
245 props := []interface{}{&c.Properties, &c.unused}
Colin Crossca860ac2016-01-04 14:34:37 -0800246 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700247 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800248 }
249 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700250 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800251 }
252 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700253 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800254 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700255 if c.stl != nil {
256 props = append(props, c.stl.props()...)
257 }
Colin Cross16b23492016-01-06 14:41:07 -0800258 if c.sanitize != nil {
259 props = append(props, c.sanitize.props()...)
260 }
Colin Crossca860ac2016-01-04 14:34:37 -0800261 for _, feature := range c.features {
262 props = append(props, feature.props()...)
263 }
Colin Crossc472d572015-03-17 15:06:21 -0700264
Colin Cross635c3b02016-05-18 15:37:25 -0700265 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700266
Colin Cross635c3b02016-05-18 15:37:25 -0700267 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700268}
269
Colin Crossb916a382016-07-29 17:28:03 -0700270// Returns true for dependency roots (binaries)
271// TODO(ccross): also handle dlopenable libraries
272func (c *Module) isDependencyRoot() bool {
273 if root, ok := c.linker.(interface {
274 isDependencyRoot() bool
275 }); ok {
276 return root.isDependencyRoot()
277 }
278 return false
279}
280
Colin Crossca860ac2016-01-04 14:34:37 -0800281type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700282 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800283 moduleContextImpl
284}
285
286type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700287 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800288 moduleContextImpl
289}
290
291type moduleContextImpl struct {
292 mod *Module
293 ctx BaseModuleContext
294}
295
Colin Crossca860ac2016-01-04 14:34:37 -0800296func (ctx *moduleContextImpl) clang() bool {
297 return ctx.mod.clang(ctx.ctx)
298}
299
Colin Crossb98c8b02016-07-29 13:44:28 -0700300func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800301 return ctx.mod.toolchain(ctx.ctx)
302}
303
304func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700305 if static, ok := ctx.mod.linker.(interface {
306 static() bool
307 }); ok {
308 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800309 }
Colin Crossb916a382016-07-29 17:28:03 -0700310 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800311}
312
313func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700314 if static, ok := ctx.mod.linker.(interface {
315 staticBinary() bool
316 }); ok {
317 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800318 }
Colin Crossb916a382016-07-29 17:28:03 -0700319 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800320}
321
322func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
323 return Bool(ctx.mod.Properties.No_default_compiler_flags)
324}
325
326func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsena96ff642016-06-07 12:34:45 -0700327 if ctx.ctx.Device() {
328 return ctx.mod.Properties.Sdk_version != ""
329 }
330 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800331}
332
333func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700334 if ctx.ctx.Device() {
335 return ctx.mod.Properties.Sdk_version
336 }
337 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800338}
339
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700340func (ctx *moduleContextImpl) selectedStl() string {
341 if stl := ctx.mod.stl; stl != nil {
342 return stl.Properties.SelectedStl
343 }
344 return ""
345}
346
Colin Cross635c3b02016-05-18 15:37:25 -0700347func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800348 return &Module{
349 hod: hod,
350 multilib: multilib,
351 }
352}
353
Colin Cross635c3b02016-05-18 15:37:25 -0700354func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800355 module := newBaseModule(hod, multilib)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700356 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800357 module.sanitize = &sanitize{}
Colin Crossca860ac2016-01-04 14:34:37 -0800358 return module
359}
360
Colin Cross635c3b02016-05-18 15:37:25 -0700361func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800362 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700363 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800364 moduleContextImpl: moduleContextImpl{
365 mod: c,
366 },
367 }
368 ctx.ctx = ctx
369
370 flags := Flags{
371 Toolchain: c.toolchain(ctx),
372 Clang: c.clang(ctx),
373 }
Colin Crossca860ac2016-01-04 14:34:37 -0800374 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700375 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800376 }
377 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700378 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800379 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700380 if c.stl != nil {
381 flags = c.stl.flags(ctx, flags)
382 }
Colin Cross16b23492016-01-06 14:41:07 -0800383 if c.sanitize != nil {
384 flags = c.sanitize.flags(ctx, flags)
385 }
Colin Crossca860ac2016-01-04 14:34:37 -0800386 for _, feature := range c.features {
387 flags = feature.flags(ctx, flags)
388 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800389 if ctx.Failed() {
390 return
391 }
392
Colin Crossb98c8b02016-07-29 13:44:28 -0700393 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
394 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
395 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800396
Colin Crossca860ac2016-01-04 14:34:37 -0800397 // Optimization to reduce size of build.ninja
398 // Replace the long list of flags for each file with a module-local variable
399 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
400 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
401 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
402 flags.CFlags = []string{"$cflags"}
403 flags.CppFlags = []string{"$cppflags"}
404 flags.AsFlags = []string{"$asflags"}
405
Colin Crossc99deeb2016-04-11 15:06:20 -0700406 deps := c.depsToPaths(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800407 if ctx.Failed() {
408 return
409 }
410
Dan Willemsen76f08272016-07-09 00:14:08 -0700411 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Colin Crossed9f8682015-03-18 17:17:35 -0700412
Colin Cross635c3b02016-05-18 15:37:25 -0700413 var objFiles android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800414 if c.compiler != nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700415 objFiles = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800416 if ctx.Failed() {
417 return
418 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800419 }
420
Colin Crossca860ac2016-01-04 14:34:37 -0800421 if c.linker != nil {
422 outputFile := c.linker.link(ctx, flags, deps, objFiles)
423 if ctx.Failed() {
424 return
425 }
Colin Cross635c3b02016-05-18 15:37:25 -0700426 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Cross5049f022015-03-18 13:28:46 -0700427
Colin Crossb0f28952016-09-19 16:46:53 -0700428 if c.installer != nil && !c.Properties.PreventInstall {
Colin Crossca860ac2016-01-04 14:34:37 -0800429 c.installer.install(ctx, outputFile)
430 if ctx.Failed() {
431 return
432 }
433 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700434 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800435}
436
Colin Crossb98c8b02016-07-29 13:44:28 -0700437func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800438 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700439 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800440 }
Colin Crossca860ac2016-01-04 14:34:37 -0800441 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800442}
443
Colin Crossca860ac2016-01-04 14:34:37 -0800444func (c *Module) begin(ctx BaseModuleContext) {
445 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700446 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700447 }
Colin Crossca860ac2016-01-04 14:34:37 -0800448 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700449 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800450 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700451 if c.stl != nil {
452 c.stl.begin(ctx)
453 }
Colin Cross16b23492016-01-06 14:41:07 -0800454 if c.sanitize != nil {
455 c.sanitize.begin(ctx)
456 }
Colin Crossca860ac2016-01-04 14:34:37 -0800457 for _, feature := range c.features {
458 feature.begin(ctx)
459 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700460 if ctx.sdk() {
461 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
462 if err != nil {
463 ctx.PropertyErrorf("sdk_version", err.Error())
464 }
465 c.Properties.Sdk_version = strconv.Itoa(version)
466 }
Colin Crossca860ac2016-01-04 14:34:37 -0800467}
468
Colin Crossc99deeb2016-04-11 15:06:20 -0700469func (c *Module) deps(ctx BaseModuleContext) Deps {
470 deps := Deps{}
471
472 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700473 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700474 }
475 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700476 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700477 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700478 if c.stl != nil {
479 deps = c.stl.deps(ctx, deps)
480 }
Colin Cross16b23492016-01-06 14:41:07 -0800481 if c.sanitize != nil {
482 deps = c.sanitize.deps(ctx, deps)
483 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700484 for _, feature := range c.features {
485 deps = feature.deps(ctx, deps)
486 }
487
488 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
489 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
490 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
491 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
492 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
493
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700494 for _, lib := range deps.ReexportSharedLibHeaders {
495 if !inList(lib, deps.SharedLibs) {
496 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
497 }
498 }
499
500 for _, lib := range deps.ReexportStaticLibHeaders {
501 if !inList(lib, deps.StaticLibs) {
502 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
503 }
504 }
505
Colin Crossc99deeb2016-04-11 15:06:20 -0700506 return deps
507}
508
Dan Albert7e9d2952016-08-04 13:02:36 -0700509func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800510 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700511 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800512 moduleContextImpl: moduleContextImpl{
513 mod: c,
514 },
515 }
516 ctx.ctx = ctx
517
Colin Crossca860ac2016-01-04 14:34:37 -0800518 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700519}
520
521func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
522 ctx := &baseModuleContext{
523 BaseContext: actx,
524 moduleContextImpl: moduleContextImpl{
525 mod: c,
526 },
527 }
528 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800529
Colin Crossc99deeb2016-04-11 15:06:20 -0700530 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800531
Colin Crossb5bc4b42016-07-11 16:11:59 -0700532 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
533 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700534
Dan Albert914449f2016-06-17 16:45:24 -0700535 variantNdkLibs := []string{}
536 variantLateNdkLibs := []string{}
Dan Willemsen72d39932016-07-08 23:23:48 -0700537 if ctx.sdk() {
Dan Albert914449f2016-06-17 16:45:24 -0700538 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700539
Dan Albert914449f2016-06-17 16:45:24 -0700540 // Rewrites the names of shared libraries into the names of the NDK
541 // libraries where appropriate. This returns two slices.
542 //
543 // The first is a list of non-variant shared libraries (either rewritten
544 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
545 // because they are not NDK libraries).
546 //
547 // The second is a list of ndk_library modules. These need to be
548 // separated because they are a variation dependency and must be added
549 // in a different manner.
550 rewriteNdkLibs := func(list []string) ([]string, []string) {
551 variantLibs := []string{}
552 nonvariantLibs := []string{}
553 for _, entry := range list {
Dan Willemsen72d39932016-07-08 23:23:48 -0700554 if inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700555 if !inList(entry, ndkMigratedLibs) {
556 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
557 } else {
558 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
559 }
560 } else {
561 nonvariantLibs = append(variantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700562 }
563 }
Dan Albert914449f2016-06-17 16:45:24 -0700564 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700565 }
566
Dan Albert914449f2016-06-17 16:45:24 -0700567 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
568 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700569 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700570
571 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
572 deps.WholeStaticLibs...)
573
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700574 for _, lib := range deps.StaticLibs {
575 depTag := staticDepTag
576 if inList(lib, deps.ReexportStaticLibHeaders) {
577 depTag = staticExportDepTag
578 }
Colin Cross15a0d462016-07-14 14:49:58 -0700579 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700580 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700581
582 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
583 deps.LateStaticLibs...)
584
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700585 for _, lib := range deps.SharedLibs {
586 depTag := sharedDepTag
587 if inList(lib, deps.ReexportSharedLibHeaders) {
588 depTag = sharedExportDepTag
589 }
Colin Cross15a0d462016-07-14 14:49:58 -0700590 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700591 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700592
593 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
594 deps.LateSharedLibs...)
595
Colin Cross68861832016-07-08 10:41:41 -0700596 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
597 actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
Dan Willemsenb40aab62016-04-20 14:21:14 -0700598
Colin Cross68861832016-07-08 10:41:41 -0700599 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700600
601 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700602 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800603 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700604 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700605 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700606 }
Dan Albert914449f2016-06-17 16:45:24 -0700607
608 version := ctx.sdkVersion()
609 actx.AddVariationDependencies([]blueprint.Variation{
610 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
611 actx.AddVariationDependencies([]blueprint.Variation{
612 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700613}
Colin Cross21b9a242015-03-24 14:15:58 -0700614
Dan Albert7e9d2952016-08-04 13:02:36 -0700615func beginMutator(ctx android.BottomUpMutatorContext) {
616 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
617 c.beginMutator(ctx)
618 }
619}
620
Colin Cross635c3b02016-05-18 15:37:25 -0700621func depsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3f32f032016-07-11 14:36:48 -0700622 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
Colin Cross6362e272015-10-29 15:25:03 -0700623 c.depsMutator(ctx)
624 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800625}
626
Colin Crossca860ac2016-01-04 14:34:37 -0800627func (c *Module) clang(ctx BaseModuleContext) bool {
628 clang := Bool(c.Properties.Clang)
629
630 if c.Properties.Clang == nil {
631 if ctx.Host() {
632 clang = true
633 }
634
635 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
636 clang = true
637 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800638 }
Colin Cross28344522015-04-22 13:07:53 -0700639
Colin Crossca860ac2016-01-04 14:34:37 -0800640 if !c.toolchain(ctx).ClangSupported() {
641 clang = false
642 }
643
644 return clang
645}
646
Colin Crossc99deeb2016-04-11 15:06:20 -0700647// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700648func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800649 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800650
Dan Willemsena96ff642016-06-07 12:34:45 -0700651 // Whether a module can link to another module, taking into
652 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700653 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700654 if from.Target().Os != android.Android {
655 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700656 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700657 }
658 if from.Properties.Sdk_version == "" {
659 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700660 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700661 }
Colin Crossb916a382016-07-29 17:28:03 -0700662 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700663 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700664 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700665 }
666 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
667 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700668 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700669 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700670 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
671 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700672 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700673 }
Colin Crossb916a382016-07-29 17:28:03 -0700674 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700675 // These aren't real libraries, but are the stub shared libraries that are included in
676 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700677 return
Dan Albert914449f2016-06-17 16:45:24 -0700678 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700679 if to.Properties.Sdk_version == "" {
680 // NDK code linking to platform code is never okay.
681 ctx.ModuleErrorf("depends on non-NDK-built library %q",
682 ctx.OtherModuleName(to))
683 }
684
685 // All this point we know we have two NDK libraries, but we need to
686 // check that we're not linking against anything built against a higher
687 // API level, as it is only valid to link against older or equivalent
688 // APIs.
689
690 if from.Properties.Sdk_version == "current" {
691 // Current can link against anything.
692 return
693 } else if to.Properties.Sdk_version == "current" {
694 // Current can't be linked against by anything else.
695 ctx.ModuleErrorf("links %q built against newer API version %q",
696 ctx.OtherModuleName(to), "current")
697 }
698
699 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
700 if err != nil {
701 ctx.PropertyErrorf("sdk_version",
702 "Invalid sdk_version value (must be int): %q",
703 from.Properties.Sdk_version)
704 }
705 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
706 if err != nil {
707 ctx.PropertyErrorf("sdk_version",
708 "Invalid sdk_version value (must be int): %q",
709 to.Properties.Sdk_version)
710 }
711
712 if toApi > fromApi {
713 ctx.ModuleErrorf("links %q built against newer API version %q",
714 ctx.OtherModuleName(to), to.Properties.Sdk_version)
715 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700716 }
717
Colin Crossc99deeb2016-04-11 15:06:20 -0700718 ctx.VisitDirectDeps(func(m blueprint.Module) {
719 name := ctx.OtherModuleName(m)
720 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800721
Colin Cross635c3b02016-05-18 15:37:25 -0700722 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700723 if a == nil {
724 ctx.ModuleErrorf("module %q not an android module", name)
725 return
Colin Crossca860ac2016-01-04 14:34:37 -0800726 }
Colin Crossca860ac2016-01-04 14:34:37 -0800727
Dan Willemsena96ff642016-06-07 12:34:45 -0700728 cc, _ := m.(*Module)
729 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700730 switch tag {
Colin Cross635c3b02016-05-18 15:37:25 -0700731 case android.DefaultsDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700732 case genSourceDepTag:
733 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
734 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
735 genRule.GeneratedSourceFiles()...)
736 } else {
737 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
738 }
739 case genHeaderDepTag:
740 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
741 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
742 genRule.GeneratedSourceFiles()...)
Dan Willemsen76f08272016-07-09 00:14:08 -0700743 depPaths.Flags = append(depPaths.Flags,
Colin Cross635c3b02016-05-18 15:37:25 -0700744 includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}))
Dan Willemsenb40aab62016-04-20 14:21:14 -0700745 } else {
746 ctx.ModuleErrorf("module %q is not a genrule", name)
747 }
748 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700749 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800750 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700751 return
752 }
753
754 if !a.Enabled() {
755 ctx.ModuleErrorf("depends on disabled module %q", name)
756 return
757 }
758
Colin Crossa1ad8d12016-06-01 17:09:44 -0700759 if a.Target().Os != ctx.Os() {
760 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
761 return
762 }
763
764 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
765 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700766 return
767 }
768
Dan Willemsena96ff642016-06-07 12:34:45 -0700769 if !cc.outputFile.Valid() {
Colin Crossc99deeb2016-04-11 15:06:20 -0700770 ctx.ModuleErrorf("module %q missing output file", name)
771 return
772 }
773
774 if tag == reuseObjTag {
775 depPaths.ObjFiles = append(depPaths.ObjFiles,
Colin Crossb916a382016-07-29 17:28:03 -0700776 cc.compiler.(libraryInterface).reuseObjs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700777 return
778 }
779
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700780 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700781 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700782 flags := i.exportedFlags()
783 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700784
785 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700786 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700787 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700788 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700789
Dan Albert9e10cd42016-08-03 14:12:14 -0700790 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700791 }
792
Colin Cross635c3b02016-05-18 15:37:25 -0700793 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700794
795 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700796 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700797 depPtr = &depPaths.SharedLibs
Dan Albert914449f2016-06-17 16:45:24 -0700798 case lateSharedDepTag, ndkLateStubDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700799 depPtr = &depPaths.LateSharedLibs
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700800 case staticDepTag, staticExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700801 depPtr = &depPaths.StaticLibs
802 case lateStaticDepTag:
803 depPtr = &depPaths.LateStaticLibs
804 case wholeStaticDepTag:
805 depPtr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -0700806 staticLib, ok := cc.linker.(libraryInterface)
807 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700808 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700809 return
810 }
811
812 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
813 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
814 for i := range missingDeps {
815 missingDeps[i] += postfix
816 }
817 ctx.AddMissingDependencies(missingDeps)
818 }
819 depPaths.WholeStaticLibObjFiles =
Colin Crossc7a38dc2016-07-12 13:13:09 -0700820 append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700821 case objDepTag:
822 depPtr = &depPaths.ObjFiles
823 case crtBeginDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700824 depPaths.CrtBegin = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700825 case crtEndDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700826 depPaths.CrtEnd = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700827 default:
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700828 panic(fmt.Errorf("unknown dependency tag: %s", tag))
Colin Crossc99deeb2016-04-11 15:06:20 -0700829 }
830
831 if depPtr != nil {
Dan Willemsena96ff642016-06-07 12:34:45 -0700832 *depPtr = append(*depPtr, cc.outputFile.Path())
Colin Crossca860ac2016-01-04 14:34:37 -0800833 }
834 })
835
836 return depPaths
837}
838
839func (c *Module) InstallInData() bool {
840 if c.installer == nil {
841 return false
842 }
Colin Cross94610402016-08-29 13:41:32 -0700843 if c.sanitize != nil && c.sanitize.inData() {
844 return true
845 }
Colin Crossca860ac2016-01-04 14:34:37 -0800846 return c.installer.inData()
847}
848
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700849func (c *Module) HostToolPath() android.OptionalPath {
850 if c.installer == nil {
851 return android.OptionalPath{}
852 }
853 return c.installer.hostToolPath()
854}
855
Colin Cross2ba19d92015-05-07 15:44:20 -0700856//
Colin Crosscfad1192015-11-02 16:43:11 -0800857// Defaults
858//
Colin Crossca860ac2016-01-04 14:34:37 -0800859type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700860 android.ModuleBase
861 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -0800862}
863
Colin Cross635c3b02016-05-18 15:37:25 -0700864func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -0800865}
866
Colin Crossca860ac2016-01-04 14:34:37 -0800867func defaultsFactory() (blueprint.Module, []interface{}) {
Colin Crosse1d764e2016-08-18 14:18:32 -0700868 return DefaultsFactory()
869}
870
871func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
Colin Crossca860ac2016-01-04 14:34:37 -0800872 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -0800873
Colin Crosse1d764e2016-08-18 14:18:32 -0700874 props = append(props,
Colin Crossca860ac2016-01-04 14:34:37 -0800875 &BaseProperties{},
876 &BaseCompilerProperties{},
877 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700878 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -0700879 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800880 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700881 &TestProperties{},
882 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800883 &UnusedProperties{},
884 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -0800885 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -0700886 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -0700887 &InstallerProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -0700888 )
Colin Crosscfad1192015-11-02 16:43:11 -0800889
Colin Crosse1d764e2016-08-18 14:18:32 -0700890 _, props = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
891 android.MultilibDefault, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800892
Colin Crosse1d764e2016-08-18 14:18:32 -0700893 return android.InitDefaultsModule(module, module, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800894}
895
Colin Cross74d1ec02015-04-28 13:30:13 -0700896// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
897// modifies the slice contents in place, and returns a subslice of the original slice
898func lastUniqueElements(list []string) []string {
899 totalSkip := 0
900 for i := len(list) - 1; i >= totalSkip; i-- {
901 skip := 0
902 for j := i - 1; j >= totalSkip; j-- {
903 if list[i] == list[j] {
904 skip++
905 } else {
906 list[j+skip] = list[j]
907 }
908 }
909 totalSkip += skip
910 }
911 return list[totalSkip:]
912}
Colin Cross06a931b2015-10-28 17:23:31 -0700913
914var Bool = proptools.Bool