blob: 752046f2c75af4c257c85e6223a9e10b0c16aa78 [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
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 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700494 if ctx.sdk() {
495 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
496 if err != nil {
497 ctx.PropertyErrorf("sdk_version", err.Error())
498 }
499 c.Properties.Sdk_version = strconv.Itoa(version)
500 }
Colin Crossca860ac2016-01-04 14:34:37 -0800501}
502
Colin Crossc99deeb2016-04-11 15:06:20 -0700503func (c *Module) deps(ctx BaseModuleContext) Deps {
504 deps := Deps{}
505
506 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700507 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700508 }
509 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700510 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700511 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700512 if c.stl != nil {
513 deps = c.stl.deps(ctx, deps)
514 }
Colin Cross16b23492016-01-06 14:41:07 -0800515 if c.sanitize != nil {
516 deps = c.sanitize.deps(ctx, deps)
517 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700518 for _, feature := range c.features {
519 deps = feature.deps(ctx, deps)
520 }
521
522 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
523 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
524 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
525 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
526 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
527
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700528 for _, lib := range deps.ReexportSharedLibHeaders {
529 if !inList(lib, deps.SharedLibs) {
530 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
531 }
532 }
533
534 for _, lib := range deps.ReexportStaticLibHeaders {
535 if !inList(lib, deps.StaticLibs) {
536 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
537 }
538 }
539
Colin Crossc99deeb2016-04-11 15:06:20 -0700540 return deps
541}
542
Dan Albert7e9d2952016-08-04 13:02:36 -0700543func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800544 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700545 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800546 moduleContextImpl: moduleContextImpl{
547 mod: c,
548 },
549 }
550 ctx.ctx = ctx
551
Colin Crossca860ac2016-01-04 14:34:37 -0800552 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700553}
554
555func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
556 ctx := &baseModuleContext{
557 BaseContext: actx,
558 moduleContextImpl: moduleContextImpl{
559 mod: c,
560 },
561 }
562 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800563
Colin Crossc99deeb2016-04-11 15:06:20 -0700564 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800565
Colin Crossb5bc4b42016-07-11 16:11:59 -0700566 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
567 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700568
Dan Albert914449f2016-06-17 16:45:24 -0700569 variantNdkLibs := []string{}
570 variantLateNdkLibs := []string{}
Dan Willemsen72d39932016-07-08 23:23:48 -0700571 if ctx.sdk() {
Dan Albert914449f2016-06-17 16:45:24 -0700572 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700573
Dan Albert914449f2016-06-17 16:45:24 -0700574 // Rewrites the names of shared libraries into the names of the NDK
575 // libraries where appropriate. This returns two slices.
576 //
577 // The first is a list of non-variant shared libraries (either rewritten
578 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
579 // because they are not NDK libraries).
580 //
581 // The second is a list of ndk_library modules. These need to be
582 // separated because they are a variation dependency and must be added
583 // in a different manner.
584 rewriteNdkLibs := func(list []string) ([]string, []string) {
585 variantLibs := []string{}
586 nonvariantLibs := []string{}
587 for _, entry := range list {
Dan Willemsen72d39932016-07-08 23:23:48 -0700588 if inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700589 if !inList(entry, ndkMigratedLibs) {
590 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
591 } else {
592 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
593 }
594 } else {
595 nonvariantLibs = append(variantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700596 }
597 }
Dan Albert914449f2016-06-17 16:45:24 -0700598 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700599 }
600
Dan Albert914449f2016-06-17 16:45:24 -0700601 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
602 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700603 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700604
605 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
606 deps.WholeStaticLibs...)
607
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700608 for _, lib := range deps.StaticLibs {
609 depTag := staticDepTag
610 if inList(lib, deps.ReexportStaticLibHeaders) {
611 depTag = staticExportDepTag
612 }
Colin Cross15a0d462016-07-14 14:49:58 -0700613 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700614 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700615
616 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
617 deps.LateStaticLibs...)
618
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700619 for _, lib := range deps.SharedLibs {
620 depTag := sharedDepTag
621 if inList(lib, deps.ReexportSharedLibHeaders) {
622 depTag = sharedExportDepTag
623 }
Colin Cross15a0d462016-07-14 14:49:58 -0700624 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700625 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700626
627 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
628 deps.LateSharedLibs...)
629
Colin Cross68861832016-07-08 10:41:41 -0700630 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
631 actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
Dan Willemsenb40aab62016-04-20 14:21:14 -0700632
Colin Cross68861832016-07-08 10:41:41 -0700633 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700634
635 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700636 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800637 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700638 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700639 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700640 }
Dan Albert914449f2016-06-17 16:45:24 -0700641
642 version := ctx.sdkVersion()
643 actx.AddVariationDependencies([]blueprint.Variation{
644 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
645 actx.AddVariationDependencies([]blueprint.Variation{
646 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700647}
Colin Cross21b9a242015-03-24 14:15:58 -0700648
Dan Albert7e9d2952016-08-04 13:02:36 -0700649func beginMutator(ctx android.BottomUpMutatorContext) {
650 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
651 c.beginMutator(ctx)
652 }
653}
654
Colin Cross635c3b02016-05-18 15:37:25 -0700655func depsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3f32f032016-07-11 14:36:48 -0700656 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
Colin Cross6362e272015-10-29 15:25:03 -0700657 c.depsMutator(ctx)
658 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800659}
660
Colin Crossca860ac2016-01-04 14:34:37 -0800661func (c *Module) clang(ctx BaseModuleContext) bool {
662 clang := Bool(c.Properties.Clang)
663
664 if c.Properties.Clang == nil {
665 if ctx.Host() {
666 clang = true
667 }
668
669 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
670 clang = true
671 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800672 }
Colin Cross28344522015-04-22 13:07:53 -0700673
Colin Crossca860ac2016-01-04 14:34:37 -0800674 if !c.toolchain(ctx).ClangSupported() {
675 clang = false
676 }
677
678 return clang
679}
680
Colin Crossc99deeb2016-04-11 15:06:20 -0700681// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700682func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800683 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800684
Dan Willemsena96ff642016-06-07 12:34:45 -0700685 // Whether a module can link to another module, taking into
686 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700687 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700688 if from.Target().Os != android.Android {
689 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700690 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700691 }
692 if from.Properties.Sdk_version == "" {
693 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700694 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700695 }
Colin Crossb916a382016-07-29 17:28:03 -0700696 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700697 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700698 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700699 }
700 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
701 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700702 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700703 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700704 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
705 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700706 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700707 }
Colin Crossb916a382016-07-29 17:28:03 -0700708 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700709 // These aren't real libraries, but are the stub shared libraries that are included in
710 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700711 return
Dan Albert914449f2016-06-17 16:45:24 -0700712 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700713 if to.Properties.Sdk_version == "" {
714 // NDK code linking to platform code is never okay.
715 ctx.ModuleErrorf("depends on non-NDK-built library %q",
716 ctx.OtherModuleName(to))
717 }
718
719 // All this point we know we have two NDK libraries, but we need to
720 // check that we're not linking against anything built against a higher
721 // API level, as it is only valid to link against older or equivalent
722 // APIs.
723
724 if from.Properties.Sdk_version == "current" {
725 // Current can link against anything.
726 return
727 } else if to.Properties.Sdk_version == "current" {
728 // Current can't be linked against by anything else.
729 ctx.ModuleErrorf("links %q built against newer API version %q",
730 ctx.OtherModuleName(to), "current")
731 }
732
733 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
734 if err != nil {
735 ctx.PropertyErrorf("sdk_version",
736 "Invalid sdk_version value (must be int): %q",
737 from.Properties.Sdk_version)
738 }
739 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
740 if err != nil {
741 ctx.PropertyErrorf("sdk_version",
742 "Invalid sdk_version value (must be int): %q",
743 to.Properties.Sdk_version)
744 }
745
746 if toApi > fromApi {
747 ctx.ModuleErrorf("links %q built against newer API version %q",
748 ctx.OtherModuleName(to), to.Properties.Sdk_version)
749 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700750 }
751
Colin Crossc99deeb2016-04-11 15:06:20 -0700752 ctx.VisitDirectDeps(func(m blueprint.Module) {
753 name := ctx.OtherModuleName(m)
754 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800755
Colin Cross635c3b02016-05-18 15:37:25 -0700756 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700757 if a == nil {
758 ctx.ModuleErrorf("module %q not an android module", name)
759 return
Colin Crossca860ac2016-01-04 14:34:37 -0800760 }
Colin Crossca860ac2016-01-04 14:34:37 -0800761
Dan Willemsena96ff642016-06-07 12:34:45 -0700762 cc, _ := m.(*Module)
763 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700764 switch tag {
Colin Cross635c3b02016-05-18 15:37:25 -0700765 case android.DefaultsDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700766 case genSourceDepTag:
767 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
768 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
769 genRule.GeneratedSourceFiles()...)
770 } else {
771 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
772 }
773 case genHeaderDepTag:
774 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
775 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
776 genRule.GeneratedSourceFiles()...)
Dan Willemsen76f08272016-07-09 00:14:08 -0700777 depPaths.Flags = append(depPaths.Flags,
Colin Cross635c3b02016-05-18 15:37:25 -0700778 includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}))
Dan Willemsenb40aab62016-04-20 14:21:14 -0700779 } else {
780 ctx.ModuleErrorf("module %q is not a genrule", name)
781 }
782 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700783 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800784 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700785 return
786 }
787
788 if !a.Enabled() {
789 ctx.ModuleErrorf("depends on disabled module %q", name)
790 return
791 }
792
Colin Crossa1ad8d12016-06-01 17:09:44 -0700793 if a.Target().Os != ctx.Os() {
794 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
795 return
796 }
797
798 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
799 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700800 return
801 }
802
Dan Willemsena96ff642016-06-07 12:34:45 -0700803 if !cc.outputFile.Valid() {
Colin Crossc99deeb2016-04-11 15:06:20 -0700804 ctx.ModuleErrorf("module %q missing output file", name)
805 return
806 }
807
808 if tag == reuseObjTag {
809 depPaths.ObjFiles = append(depPaths.ObjFiles,
Colin Crossb916a382016-07-29 17:28:03 -0700810 cc.compiler.(libraryInterface).reuseObjs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700811 return
812 }
813
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700814 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700815 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700816 flags := i.exportedFlags()
817 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700818
819 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700820 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700821 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700822 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700823
Dan Albert9e10cd42016-08-03 14:12:14 -0700824 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700825 }
826
Colin Cross635c3b02016-05-18 15:37:25 -0700827 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700828
829 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700830 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700831 depPtr = &depPaths.SharedLibs
Dan Albert914449f2016-06-17 16:45:24 -0700832 case lateSharedDepTag, ndkLateStubDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700833 depPtr = &depPaths.LateSharedLibs
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700834 case staticDepTag, staticExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700835 depPtr = &depPaths.StaticLibs
836 case lateStaticDepTag:
837 depPtr = &depPaths.LateStaticLibs
838 case wholeStaticDepTag:
839 depPtr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -0700840 staticLib, ok := cc.linker.(libraryInterface)
841 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700842 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700843 return
844 }
845
846 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
847 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
848 for i := range missingDeps {
849 missingDeps[i] += postfix
850 }
851 ctx.AddMissingDependencies(missingDeps)
852 }
853 depPaths.WholeStaticLibObjFiles =
Colin Crossc7a38dc2016-07-12 13:13:09 -0700854 append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700855 case objDepTag:
856 depPtr = &depPaths.ObjFiles
857 case crtBeginDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700858 depPaths.CrtBegin = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700859 case crtEndDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700860 depPaths.CrtEnd = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700861 default:
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700862 panic(fmt.Errorf("unknown dependency tag: %s", tag))
Colin Crossc99deeb2016-04-11 15:06:20 -0700863 }
864
865 if depPtr != nil {
Dan Willemsena96ff642016-06-07 12:34:45 -0700866 *depPtr = append(*depPtr, cc.outputFile.Path())
Colin Crossca860ac2016-01-04 14:34:37 -0800867 }
868 })
869
870 return depPaths
871}
872
873func (c *Module) InstallInData() bool {
874 if c.installer == nil {
875 return false
876 }
877 return c.installer.inData()
878}
879
Colin Cross2ba19d92015-05-07 15:44:20 -0700880//
Colin Crosscfad1192015-11-02 16:43:11 -0800881// Defaults
882//
Colin Crossca860ac2016-01-04 14:34:37 -0800883type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700884 android.ModuleBase
885 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -0800886}
887
Colin Cross635c3b02016-05-18 15:37:25 -0700888func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -0800889}
890
Colin Crossca860ac2016-01-04 14:34:37 -0800891func defaultsFactory() (blueprint.Module, []interface{}) {
892 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -0800893
894 propertyStructs := []interface{}{
Colin Crossca860ac2016-01-04 14:34:37 -0800895 &BaseProperties{},
896 &BaseCompilerProperties{},
897 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700898 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -0700899 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800900 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700901 &TestProperties{},
902 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800903 &UnusedProperties{},
904 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -0800905 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -0700906 &StripProperties{},
Colin Crosscfad1192015-11-02 16:43:11 -0800907 }
908
Colin Cross635c3b02016-05-18 15:37:25 -0700909 _, propertyStructs = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
910 android.MultilibDefault, propertyStructs...)
Colin Crosscfad1192015-11-02 16:43:11 -0800911
Colin Cross635c3b02016-05-18 15:37:25 -0700912 return android.InitDefaultsModule(module, module, propertyStructs...)
Colin Crosscfad1192015-11-02 16:43:11 -0800913}
914
Colin Cross74d1ec02015-04-28 13:30:13 -0700915// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
916// modifies the slice contents in place, and returns a subslice of the original slice
917func lastUniqueElements(list []string) []string {
918 totalSkip := 0
919 for i := len(list) - 1; i >= totalSkip; i-- {
920 skip := 0
921 for j := i - 1; j >= totalSkip; j-- {
922 if list[i] == list[j] {
923 skip++
924 } else {
925 list[j+skip] = list[j]
926 }
927 }
928 totalSkip += skip
929 }
930 return list[totalSkip:]
931}
Colin Cross06a931b2015-10-28 17:23:31 -0700932
933var Bool = proptools.Bool