blob: b381897a6ee1f53246df93c4e83411457474f40e [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 Cross635c3b02016-05-18 15:37:25 -070041 android.RegisterBottomUpMutator("link", linkageMutator)
Dan Albert914449f2016-06-17 16:45:24 -070042 android.RegisterBottomUpMutator("ndk_api", ndkApiMutator)
Colin Cross635c3b02016-05-18 15:37:25 -070043 android.RegisterBottomUpMutator("test_per_src", testPerSrcMutator)
Dan Albert7e9d2952016-08-04 13:02:36 -070044 android.RegisterBottomUpMutator("begin", beginMutator)
Colin Cross635c3b02016-05-18 15:37:25 -070045 android.RegisterBottomUpMutator("deps", depsMutator)
Colin Cross16b23492016-01-06 14:41:07 -080046
Colin Cross635c3b02016-05-18 15:37:25 -070047 android.RegisterTopDownMutator("asan_deps", sanitizerDepsMutator(asan))
48 android.RegisterBottomUpMutator("asan", sanitizerMutator(asan))
Colin Cross16b23492016-01-06 14:41:07 -080049
Colin Cross635c3b02016-05-18 15:37:25 -070050 android.RegisterTopDownMutator("tsan_deps", sanitizerDepsMutator(tsan))
51 android.RegisterBottomUpMutator("tsan", sanitizerMutator(tsan))
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
127 Required []string
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 Cross76fada02016-07-27 10:31:13 -0700152type CustomizerFlagsContext interface {
153 BaseModuleContext
154 AppendCflags(...string)
155 AppendLdflags(...string)
156 AppendAsflags(...string)
157}
158
Colin Crossca860ac2016-01-04 14:34:37 -0800159type Customizer interface {
Colin Cross76fada02016-07-27 10:31:13 -0700160 Flags(CustomizerFlagsContext)
Colin Crossca860ac2016-01-04 14:34:37 -0800161 Properties() []interface{}
162}
163
164type feature interface {
165 begin(ctx BaseModuleContext)
166 deps(ctx BaseModuleContext, deps Deps) Deps
167 flags(ctx ModuleContext, flags Flags) Flags
168 props() []interface{}
169}
170
171type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700172 compilerInit(ctx BaseModuleContext)
173 compilerDeps(ctx BaseModuleContext, deps Deps) Deps
174 compilerFlags(ctx ModuleContext, flags Flags) Flags
175 compilerProps() []interface{}
176
Colin Cross76fada02016-07-27 10:31:13 -0700177 appendCflags([]string)
178 appendAsflags([]string)
Colin Cross635c3b02016-05-18 15:37:25 -0700179 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800180}
181
182type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700183 linkerInit(ctx BaseModuleContext)
184 linkerDeps(ctx BaseModuleContext, deps Deps) Deps
185 linkerFlags(ctx ModuleContext, flags Flags) Flags
186 linkerProps() []interface{}
187
Colin Cross635c3b02016-05-18 15:37:25 -0700188 link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700189 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800190}
191
192type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700193 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700194 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800195 inData() bool
196}
197
Colin Crossc99deeb2016-04-11 15:06:20 -0700198type dependencyTag struct {
199 blueprint.BaseDependencyTag
200 name string
201 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700202
203 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700204}
205
206var (
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700207 sharedDepTag = dependencyTag{name: "shared", library: true}
208 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
209 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
210 staticDepTag = dependencyTag{name: "static", library: true}
211 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
212 lateStaticDepTag = dependencyTag{name: "late static", library: true}
213 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
214 genSourceDepTag = dependencyTag{name: "gen source"}
215 genHeaderDepTag = dependencyTag{name: "gen header"}
216 objDepTag = dependencyTag{name: "obj"}
217 crtBeginDepTag = dependencyTag{name: "crtbegin"}
218 crtEndDepTag = dependencyTag{name: "crtend"}
219 reuseObjTag = dependencyTag{name: "reuse objects"}
Dan Albert914449f2016-06-17 16:45:24 -0700220 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
221 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700222)
223
Colin Crossca860ac2016-01-04 14:34:37 -0800224// Module contains the properties and members used by all C/C++ module types, and implements
225// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
226// to construct the output file. Behavior can be customized with a Customizer interface
227type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700228 android.ModuleBase
229 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700230
Colin Crossca860ac2016-01-04 14:34:37 -0800231 Properties BaseProperties
232 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700233
Colin Crossca860ac2016-01-04 14:34:37 -0800234 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700235 hod android.HostOrDeviceSupported
236 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700237
Colin Crossca860ac2016-01-04 14:34:37 -0800238 // delegates, initialize before calling Init
Colin Cross76fada02016-07-27 10:31:13 -0700239 Customizer Customizer
Colin Crossca860ac2016-01-04 14:34:37 -0800240 features []feature
241 compiler compiler
242 linker linker
243 installer installer
Colin Crossa8e07cc2016-04-04 15:07:06 -0700244 stl *stl
Colin Cross16b23492016-01-06 14:41:07 -0800245 sanitize *sanitize
246
247 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700248
Colin Cross635c3b02016-05-18 15:37:25 -0700249 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800250
Colin Crossb98c8b02016-07-29 13:44:28 -0700251 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700252
253 subAndroidMkOnce map[subAndroidMkProvider]bool
Colin Crossc472d572015-03-17 15:06:21 -0700254}
255
Colin Crossca860ac2016-01-04 14:34:37 -0800256func (c *Module) Init() (blueprint.Module, []interface{}) {
257 props := []interface{}{&c.Properties, &c.unused}
Colin Cross76fada02016-07-27 10:31:13 -0700258 if c.Customizer != nil {
259 props = append(props, c.Customizer.Properties()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800260 }
261 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700262 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800263 }
264 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700265 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800266 }
267 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700268 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800269 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700270 if c.stl != nil {
271 props = append(props, c.stl.props()...)
272 }
Colin Cross16b23492016-01-06 14:41:07 -0800273 if c.sanitize != nil {
274 props = append(props, c.sanitize.props()...)
275 }
Colin Crossca860ac2016-01-04 14:34:37 -0800276 for _, feature := range c.features {
277 props = append(props, feature.props()...)
278 }
Colin Crossc472d572015-03-17 15:06:21 -0700279
Colin Cross635c3b02016-05-18 15:37:25 -0700280 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700281
Colin Cross635c3b02016-05-18 15:37:25 -0700282 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700283}
284
Colin Crossb916a382016-07-29 17:28:03 -0700285// Returns true for dependency roots (binaries)
286// TODO(ccross): also handle dlopenable libraries
287func (c *Module) isDependencyRoot() bool {
288 if root, ok := c.linker.(interface {
289 isDependencyRoot() bool
290 }); ok {
291 return root.isDependencyRoot()
292 }
293 return false
294}
295
Colin Crossca860ac2016-01-04 14:34:37 -0800296type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700297 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800298 moduleContextImpl
299}
300
301type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700302 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800303 moduleContextImpl
304}
305
306type moduleContextImpl struct {
307 mod *Module
308 ctx BaseModuleContext
309}
310
Colin Cross76fada02016-07-27 10:31:13 -0700311func (ctx *moduleContextImpl) AppendCflags(flags ...string) {
312 CheckBadCompilerFlags(ctx.ctx, "", flags)
313 ctx.mod.compiler.appendCflags(flags)
314}
315
316func (ctx *moduleContextImpl) AppendAsflags(flags ...string) {
317 CheckBadCompilerFlags(ctx.ctx, "", flags)
318 ctx.mod.compiler.appendAsflags(flags)
319}
320
321func (ctx *moduleContextImpl) AppendLdflags(flags ...string) {
322 CheckBadLinkerFlags(ctx.ctx, "", flags)
323 ctx.mod.linker.appendLdflags(flags)
324}
325
Colin Crossca860ac2016-01-04 14:34:37 -0800326func (ctx *moduleContextImpl) clang() bool {
327 return ctx.mod.clang(ctx.ctx)
328}
329
Colin Crossb98c8b02016-07-29 13:44:28 -0700330func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800331 return ctx.mod.toolchain(ctx.ctx)
332}
333
334func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700335 if static, ok := ctx.mod.linker.(interface {
336 static() bool
337 }); ok {
338 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800339 }
Colin Crossb916a382016-07-29 17:28:03 -0700340 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800341}
342
343func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700344 if static, ok := ctx.mod.linker.(interface {
345 staticBinary() bool
346 }); ok {
347 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800348 }
Colin Crossb916a382016-07-29 17:28:03 -0700349 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800350}
351
352func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
353 return Bool(ctx.mod.Properties.No_default_compiler_flags)
354}
355
356func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsena96ff642016-06-07 12:34:45 -0700357 if ctx.ctx.Device() {
358 return ctx.mod.Properties.Sdk_version != ""
359 }
360 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800361}
362
363func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700364 if ctx.ctx.Device() {
365 return ctx.mod.Properties.Sdk_version
366 }
367 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800368}
369
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700370func (ctx *moduleContextImpl) selectedStl() string {
371 if stl := ctx.mod.stl; stl != nil {
372 return stl.Properties.SelectedStl
373 }
374 return ""
375}
376
Colin Cross635c3b02016-05-18 15:37:25 -0700377func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800378 return &Module{
379 hod: hod,
380 multilib: multilib,
381 }
382}
383
Colin Cross635c3b02016-05-18 15:37:25 -0700384func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800385 module := newBaseModule(hod, multilib)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700386 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800387 module.sanitize = &sanitize{}
Colin Crossca860ac2016-01-04 14:34:37 -0800388 return module
389}
390
Colin Cross635c3b02016-05-18 15:37:25 -0700391func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800392 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700393 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800394 moduleContextImpl: moduleContextImpl{
395 mod: c,
396 },
397 }
398 ctx.ctx = ctx
399
Colin Cross76fada02016-07-27 10:31:13 -0700400 if c.Customizer != nil {
401 c.Customizer.Flags(ctx)
402 }
403
Colin Crossca860ac2016-01-04 14:34:37 -0800404 flags := Flags{
405 Toolchain: c.toolchain(ctx),
406 Clang: c.clang(ctx),
407 }
Colin Crossca860ac2016-01-04 14:34:37 -0800408 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700409 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800410 }
411 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700412 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800413 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700414 if c.stl != nil {
415 flags = c.stl.flags(ctx, flags)
416 }
Colin Cross16b23492016-01-06 14:41:07 -0800417 if c.sanitize != nil {
418 flags = c.sanitize.flags(ctx, flags)
419 }
Colin Crossca860ac2016-01-04 14:34:37 -0800420 for _, feature := range c.features {
421 flags = feature.flags(ctx, flags)
422 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800423 if ctx.Failed() {
424 return
425 }
426
Colin Crossb98c8b02016-07-29 13:44:28 -0700427 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
428 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
429 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800430
Colin Crossca860ac2016-01-04 14:34:37 -0800431 // Optimization to reduce size of build.ninja
432 // Replace the long list of flags for each file with a module-local variable
433 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
434 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
435 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
436 flags.CFlags = []string{"$cflags"}
437 flags.CppFlags = []string{"$cppflags"}
438 flags.AsFlags = []string{"$asflags"}
439
Colin Crossc99deeb2016-04-11 15:06:20 -0700440 deps := c.depsToPaths(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800441 if ctx.Failed() {
442 return
443 }
444
Dan Willemsen76f08272016-07-09 00:14:08 -0700445 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Colin Crossed9f8682015-03-18 17:17:35 -0700446
Colin Cross635c3b02016-05-18 15:37:25 -0700447 var objFiles android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800448 if c.compiler != nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700449 objFiles = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800450 if ctx.Failed() {
451 return
452 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800453 }
454
Colin Crossca860ac2016-01-04 14:34:37 -0800455 if c.linker != nil {
456 outputFile := c.linker.link(ctx, flags, deps, objFiles)
457 if ctx.Failed() {
458 return
459 }
Colin Cross635c3b02016-05-18 15:37:25 -0700460 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Cross5049f022015-03-18 13:28:46 -0700461
Colin Crossb916a382016-07-29 17:28:03 -0700462 if c.installer != nil {
Colin Crossca860ac2016-01-04 14:34:37 -0800463 c.installer.install(ctx, outputFile)
464 if ctx.Failed() {
465 return
466 }
467 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700468 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800469}
470
Colin Crossb98c8b02016-07-29 13:44:28 -0700471func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800472 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700473 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800474 }
Colin Crossca860ac2016-01-04 14:34:37 -0800475 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800476}
477
Colin Crossca860ac2016-01-04 14:34:37 -0800478func (c *Module) begin(ctx BaseModuleContext) {
479 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700480 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700481 }
Colin Crossca860ac2016-01-04 14:34:37 -0800482 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700483 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800484 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700485 if c.stl != nil {
486 c.stl.begin(ctx)
487 }
Colin Cross16b23492016-01-06 14:41:07 -0800488 if c.sanitize != nil {
489 c.sanitize.begin(ctx)
490 }
Colin Crossca860ac2016-01-04 14:34:37 -0800491 for _, feature := range c.features {
492 feature.begin(ctx)
493 }
494}
495
Colin Crossc99deeb2016-04-11 15:06:20 -0700496func (c *Module) deps(ctx BaseModuleContext) Deps {
497 deps := Deps{}
498
499 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700500 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700501 }
502 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700503 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700504 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700505 if c.stl != nil {
506 deps = c.stl.deps(ctx, deps)
507 }
Colin Cross16b23492016-01-06 14:41:07 -0800508 if c.sanitize != nil {
509 deps = c.sanitize.deps(ctx, deps)
510 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700511 for _, feature := range c.features {
512 deps = feature.deps(ctx, deps)
513 }
514
515 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
516 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
517 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
518 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
519 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
520
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700521 for _, lib := range deps.ReexportSharedLibHeaders {
522 if !inList(lib, deps.SharedLibs) {
523 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
524 }
525 }
526
527 for _, lib := range deps.ReexportStaticLibHeaders {
528 if !inList(lib, deps.StaticLibs) {
529 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
530 }
531 }
532
Colin Crossc99deeb2016-04-11 15:06:20 -0700533 return deps
534}
535
Dan Albert7e9d2952016-08-04 13:02:36 -0700536func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800537 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700538 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800539 moduleContextImpl: moduleContextImpl{
540 mod: c,
541 },
542 }
543 ctx.ctx = ctx
544
Colin Crossca860ac2016-01-04 14:34:37 -0800545 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700546}
547
548func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
549 ctx := &baseModuleContext{
550 BaseContext: actx,
551 moduleContextImpl: moduleContextImpl{
552 mod: c,
553 },
554 }
555 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800556
Colin Crossc99deeb2016-04-11 15:06:20 -0700557 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800558
Colin Crossb5bc4b42016-07-11 16:11:59 -0700559 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
560 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700561
Dan Albert914449f2016-06-17 16:45:24 -0700562 variantNdkLibs := []string{}
563 variantLateNdkLibs := []string{}
Dan Willemsen72d39932016-07-08 23:23:48 -0700564 if ctx.sdk() {
Dan Albert914449f2016-06-17 16:45:24 -0700565 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700566
Dan Albert914449f2016-06-17 16:45:24 -0700567 // Rewrites the names of shared libraries into the names of the NDK
568 // libraries where appropriate. This returns two slices.
569 //
570 // The first is a list of non-variant shared libraries (either rewritten
571 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
572 // because they are not NDK libraries).
573 //
574 // The second is a list of ndk_library modules. These need to be
575 // separated because they are a variation dependency and must be added
576 // in a different manner.
577 rewriteNdkLibs := func(list []string) ([]string, []string) {
578 variantLibs := []string{}
579 nonvariantLibs := []string{}
580 for _, entry := range list {
Dan Willemsen72d39932016-07-08 23:23:48 -0700581 if inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700582 if !inList(entry, ndkMigratedLibs) {
583 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
584 } else {
585 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
586 }
587 } else {
588 nonvariantLibs = append(variantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700589 }
590 }
Dan Albert914449f2016-06-17 16:45:24 -0700591 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700592 }
593
Dan Albert914449f2016-06-17 16:45:24 -0700594 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
595 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700596 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700597
598 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
599 deps.WholeStaticLibs...)
600
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700601 for _, lib := range deps.StaticLibs {
602 depTag := staticDepTag
603 if inList(lib, deps.ReexportStaticLibHeaders) {
604 depTag = staticExportDepTag
605 }
Colin Cross15a0d462016-07-14 14:49:58 -0700606 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700607 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700608
609 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
610 deps.LateStaticLibs...)
611
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700612 for _, lib := range deps.SharedLibs {
613 depTag := sharedDepTag
614 if inList(lib, deps.ReexportSharedLibHeaders) {
615 depTag = sharedExportDepTag
616 }
Colin Cross15a0d462016-07-14 14:49:58 -0700617 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700618 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700619
620 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
621 deps.LateSharedLibs...)
622
Colin Cross68861832016-07-08 10:41:41 -0700623 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
624 actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
Dan Willemsenb40aab62016-04-20 14:21:14 -0700625
Colin Cross68861832016-07-08 10:41:41 -0700626 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700627
628 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700629 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800630 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700631 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700632 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700633 }
Dan Albert914449f2016-06-17 16:45:24 -0700634
635 version := ctx.sdkVersion()
636 actx.AddVariationDependencies([]blueprint.Variation{
637 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
638 actx.AddVariationDependencies([]blueprint.Variation{
639 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700640}
Colin Cross21b9a242015-03-24 14:15:58 -0700641
Dan Albert7e9d2952016-08-04 13:02:36 -0700642func beginMutator(ctx android.BottomUpMutatorContext) {
643 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
644 c.beginMutator(ctx)
645 }
646}
647
Colin Cross635c3b02016-05-18 15:37:25 -0700648func depsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3f32f032016-07-11 14:36:48 -0700649 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
Colin Cross6362e272015-10-29 15:25:03 -0700650 c.depsMutator(ctx)
651 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800652}
653
Colin Crossca860ac2016-01-04 14:34:37 -0800654func (c *Module) clang(ctx BaseModuleContext) bool {
655 clang := Bool(c.Properties.Clang)
656
657 if c.Properties.Clang == nil {
658 if ctx.Host() {
659 clang = true
660 }
661
662 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
663 clang = true
664 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800665 }
Colin Cross28344522015-04-22 13:07:53 -0700666
Colin Crossca860ac2016-01-04 14:34:37 -0800667 if !c.toolchain(ctx).ClangSupported() {
668 clang = false
669 }
670
671 return clang
672}
673
Colin Crossc99deeb2016-04-11 15:06:20 -0700674// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700675func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800676 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800677
Dan Willemsena96ff642016-06-07 12:34:45 -0700678 // Whether a module can link to another module, taking into
679 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700680 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700681 if from.Target().Os != android.Android {
682 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700683 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700684 }
685 if from.Properties.Sdk_version == "" {
686 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700687 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700688 }
Colin Crossb916a382016-07-29 17:28:03 -0700689 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700690 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700691 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700692 }
693 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
694 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700695 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700696 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700697 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
698 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700699 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700700 }
Colin Crossb916a382016-07-29 17:28:03 -0700701 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700702 // These aren't real libraries, but are the stub shared libraries that are included in
703 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700704 return
Dan Albert914449f2016-06-17 16:45:24 -0700705 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700706 if to.Properties.Sdk_version == "" {
707 // NDK code linking to platform code is never okay.
708 ctx.ModuleErrorf("depends on non-NDK-built library %q",
709 ctx.OtherModuleName(to))
710 }
711
712 // All this point we know we have two NDK libraries, but we need to
713 // check that we're not linking against anything built against a higher
714 // API level, as it is only valid to link against older or equivalent
715 // APIs.
716
717 if from.Properties.Sdk_version == "current" {
718 // Current can link against anything.
719 return
720 } else if to.Properties.Sdk_version == "current" {
721 // Current can't be linked against by anything else.
722 ctx.ModuleErrorf("links %q built against newer API version %q",
723 ctx.OtherModuleName(to), "current")
724 }
725
726 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
727 if err != nil {
728 ctx.PropertyErrorf("sdk_version",
729 "Invalid sdk_version value (must be int): %q",
730 from.Properties.Sdk_version)
731 }
732 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
733 if err != nil {
734 ctx.PropertyErrorf("sdk_version",
735 "Invalid sdk_version value (must be int): %q",
736 to.Properties.Sdk_version)
737 }
738
739 if toApi > fromApi {
740 ctx.ModuleErrorf("links %q built against newer API version %q",
741 ctx.OtherModuleName(to), to.Properties.Sdk_version)
742 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700743 }
744
Colin Crossc99deeb2016-04-11 15:06:20 -0700745 ctx.VisitDirectDeps(func(m blueprint.Module) {
746 name := ctx.OtherModuleName(m)
747 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800748
Colin Cross635c3b02016-05-18 15:37:25 -0700749 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700750 if a == nil {
751 ctx.ModuleErrorf("module %q not an android module", name)
752 return
Colin Crossca860ac2016-01-04 14:34:37 -0800753 }
Colin Crossca860ac2016-01-04 14:34:37 -0800754
Dan Willemsena96ff642016-06-07 12:34:45 -0700755 cc, _ := m.(*Module)
756 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700757 switch tag {
Colin Cross635c3b02016-05-18 15:37:25 -0700758 case android.DefaultsDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700759 case genSourceDepTag:
760 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
761 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
762 genRule.GeneratedSourceFiles()...)
763 } else {
764 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
765 }
766 case genHeaderDepTag:
767 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
768 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
769 genRule.GeneratedSourceFiles()...)
Dan Willemsen76f08272016-07-09 00:14:08 -0700770 depPaths.Flags = append(depPaths.Flags,
Colin Cross635c3b02016-05-18 15:37:25 -0700771 includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}))
Dan Willemsenb40aab62016-04-20 14:21:14 -0700772 } else {
773 ctx.ModuleErrorf("module %q is not a genrule", name)
774 }
775 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700776 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800777 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700778 return
779 }
780
781 if !a.Enabled() {
782 ctx.ModuleErrorf("depends on disabled module %q", name)
783 return
784 }
785
Colin Crossa1ad8d12016-06-01 17:09:44 -0700786 if a.Target().Os != ctx.Os() {
787 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
788 return
789 }
790
791 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
792 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700793 return
794 }
795
Dan Willemsena96ff642016-06-07 12:34:45 -0700796 if !cc.outputFile.Valid() {
Colin Crossc99deeb2016-04-11 15:06:20 -0700797 ctx.ModuleErrorf("module %q missing output file", name)
798 return
799 }
800
801 if tag == reuseObjTag {
802 depPaths.ObjFiles = append(depPaths.ObjFiles,
Colin Crossb916a382016-07-29 17:28:03 -0700803 cc.compiler.(libraryInterface).reuseObjs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700804 return
805 }
806
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700807 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700808 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700809 flags := i.exportedFlags()
810 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700811
812 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700813 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700814 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700815 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700816
Dan Albert9e10cd42016-08-03 14:12:14 -0700817 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700818 }
819
Colin Cross635c3b02016-05-18 15:37:25 -0700820 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700821
822 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700823 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700824 depPtr = &depPaths.SharedLibs
Dan Albert914449f2016-06-17 16:45:24 -0700825 case lateSharedDepTag, ndkLateStubDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700826 depPtr = &depPaths.LateSharedLibs
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700827 case staticDepTag, staticExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700828 depPtr = &depPaths.StaticLibs
829 case lateStaticDepTag:
830 depPtr = &depPaths.LateStaticLibs
831 case wholeStaticDepTag:
832 depPtr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -0700833 staticLib, ok := cc.linker.(libraryInterface)
834 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700835 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700836 return
837 }
838
839 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
840 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
841 for i := range missingDeps {
842 missingDeps[i] += postfix
843 }
844 ctx.AddMissingDependencies(missingDeps)
845 }
846 depPaths.WholeStaticLibObjFiles =
Colin Crossc7a38dc2016-07-12 13:13:09 -0700847 append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700848 case objDepTag:
849 depPtr = &depPaths.ObjFiles
850 case crtBeginDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700851 depPaths.CrtBegin = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700852 case crtEndDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700853 depPaths.CrtEnd = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700854 default:
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700855 panic(fmt.Errorf("unknown dependency tag: %s", tag))
Colin Crossc99deeb2016-04-11 15:06:20 -0700856 }
857
858 if depPtr != nil {
Dan Willemsena96ff642016-06-07 12:34:45 -0700859 *depPtr = append(*depPtr, cc.outputFile.Path())
Colin Crossca860ac2016-01-04 14:34:37 -0800860 }
861 })
862
863 return depPaths
864}
865
866func (c *Module) InstallInData() bool {
867 if c.installer == nil {
868 return false
869 }
870 return c.installer.inData()
871}
872
Colin Cross2ba19d92015-05-07 15:44:20 -0700873//
Colin Crosscfad1192015-11-02 16:43:11 -0800874// Defaults
875//
Colin Crossca860ac2016-01-04 14:34:37 -0800876type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700877 android.ModuleBase
878 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -0800879}
880
Colin Cross635c3b02016-05-18 15:37:25 -0700881func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -0800882}
883
Colin Crossca860ac2016-01-04 14:34:37 -0800884func defaultsFactory() (blueprint.Module, []interface{}) {
885 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -0800886
887 propertyStructs := []interface{}{
Colin Crossca860ac2016-01-04 14:34:37 -0800888 &BaseProperties{},
889 &BaseCompilerProperties{},
890 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700891 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -0700892 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800893 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700894 &TestProperties{},
895 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800896 &UnusedProperties{},
897 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -0800898 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -0700899 &StripProperties{},
Colin Crosscfad1192015-11-02 16:43:11 -0800900 }
901
Colin Cross635c3b02016-05-18 15:37:25 -0700902 _, propertyStructs = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
903 android.MultilibDefault, propertyStructs...)
Colin Crosscfad1192015-11-02 16:43:11 -0800904
Colin Cross635c3b02016-05-18 15:37:25 -0700905 return android.InitDefaultsModule(module, module, propertyStructs...)
Colin Crosscfad1192015-11-02 16:43:11 -0800906}
907
Colin Cross74d1ec02015-04-28 13:30:13 -0700908// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
909// modifies the slice contents in place, and returns a subslice of the original slice
910func lastUniqueElements(list []string) []string {
911 totalSkip := 0
912 for i := len(list) - 1; i >= totalSkip; i-- {
913 skip := 0
914 for j := i - 1; j >= totalSkip; j-- {
915 if list[i] == list[j] {
916 skip++
917 } else {
918 list[j+skip] = list[j]
919 }
920 }
921 totalSkip += skip
922 }
923 return list[totalSkip:]
924}
Colin Cross06a931b2015-10-28 17:23:31 -0700925
926var Bool = proptools.Bool