blob: 5b4dfc6e1a3a415044bfe601d0b97e2263e49a0c [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
184}
185
Colin Crossc99deeb2016-04-11 15:06:20 -0700186type dependencyTag struct {
187 blueprint.BaseDependencyTag
188 name string
189 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700190
191 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700192}
193
194var (
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700195 sharedDepTag = dependencyTag{name: "shared", library: true}
196 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
197 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
198 staticDepTag = dependencyTag{name: "static", library: true}
199 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
200 lateStaticDepTag = dependencyTag{name: "late static", library: true}
201 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
202 genSourceDepTag = dependencyTag{name: "gen source"}
203 genHeaderDepTag = dependencyTag{name: "gen header"}
204 objDepTag = dependencyTag{name: "obj"}
205 crtBeginDepTag = dependencyTag{name: "crtbegin"}
206 crtEndDepTag = dependencyTag{name: "crtend"}
207 reuseObjTag = dependencyTag{name: "reuse objects"}
Dan Albert914449f2016-06-17 16:45:24 -0700208 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
209 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700210)
211
Colin Crossca860ac2016-01-04 14:34:37 -0800212// Module contains the properties and members used by all C/C++ module types, and implements
213// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
214// to construct the output file. Behavior can be customized with a Customizer interface
215type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700216 android.ModuleBase
217 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700218
Colin Crossca860ac2016-01-04 14:34:37 -0800219 Properties BaseProperties
220 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700221
Colin Crossca860ac2016-01-04 14:34:37 -0800222 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700223 hod android.HostOrDeviceSupported
224 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700225
Colin Crossca860ac2016-01-04 14:34:37 -0800226 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700227 features []feature
228 compiler compiler
229 linker linker
230 installer installer
231 stl *stl
232 sanitize *sanitize
Colin Cross16b23492016-01-06 14:41:07 -0800233
234 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700235
Colin Cross635c3b02016-05-18 15:37:25 -0700236 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800237
Colin Crossb98c8b02016-07-29 13:44:28 -0700238 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700239
240 subAndroidMkOnce map[subAndroidMkProvider]bool
Colin Crossc472d572015-03-17 15:06:21 -0700241}
242
Colin Crossca860ac2016-01-04 14:34:37 -0800243func (c *Module) Init() (blueprint.Module, []interface{}) {
244 props := []interface{}{&c.Properties, &c.unused}
Colin Crossca860ac2016-01-04 14:34:37 -0800245 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700246 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800247 }
248 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700249 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800250 }
251 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700252 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800253 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700254 if c.stl != nil {
255 props = append(props, c.stl.props()...)
256 }
Colin Cross16b23492016-01-06 14:41:07 -0800257 if c.sanitize != nil {
258 props = append(props, c.sanitize.props()...)
259 }
Colin Crossca860ac2016-01-04 14:34:37 -0800260 for _, feature := range c.features {
261 props = append(props, feature.props()...)
262 }
Colin Crossc472d572015-03-17 15:06:21 -0700263
Colin Cross635c3b02016-05-18 15:37:25 -0700264 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700265
Colin Cross635c3b02016-05-18 15:37:25 -0700266 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700267}
268
Colin Crossb916a382016-07-29 17:28:03 -0700269// Returns true for dependency roots (binaries)
270// TODO(ccross): also handle dlopenable libraries
271func (c *Module) isDependencyRoot() bool {
272 if root, ok := c.linker.(interface {
273 isDependencyRoot() bool
274 }); ok {
275 return root.isDependencyRoot()
276 }
277 return false
278}
279
Colin Crossca860ac2016-01-04 14:34:37 -0800280type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700281 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800282 moduleContextImpl
283}
284
285type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700286 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800287 moduleContextImpl
288}
289
290type moduleContextImpl struct {
291 mod *Module
292 ctx BaseModuleContext
293}
294
Colin Crossca860ac2016-01-04 14:34:37 -0800295func (ctx *moduleContextImpl) clang() bool {
296 return ctx.mod.clang(ctx.ctx)
297}
298
Colin Crossb98c8b02016-07-29 13:44:28 -0700299func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800300 return ctx.mod.toolchain(ctx.ctx)
301}
302
303func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700304 if static, ok := ctx.mod.linker.(interface {
305 static() bool
306 }); ok {
307 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800308 }
Colin Crossb916a382016-07-29 17:28:03 -0700309 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800310}
311
312func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700313 if static, ok := ctx.mod.linker.(interface {
314 staticBinary() bool
315 }); ok {
316 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800317 }
Colin Crossb916a382016-07-29 17:28:03 -0700318 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800319}
320
321func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
322 return Bool(ctx.mod.Properties.No_default_compiler_flags)
323}
324
325func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsena96ff642016-06-07 12:34:45 -0700326 if ctx.ctx.Device() {
327 return ctx.mod.Properties.Sdk_version != ""
328 }
329 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800330}
331
332func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700333 if ctx.ctx.Device() {
334 return ctx.mod.Properties.Sdk_version
335 }
336 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800337}
338
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700339func (ctx *moduleContextImpl) selectedStl() string {
340 if stl := ctx.mod.stl; stl != nil {
341 return stl.Properties.SelectedStl
342 }
343 return ""
344}
345
Colin Cross635c3b02016-05-18 15:37:25 -0700346func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800347 return &Module{
348 hod: hod,
349 multilib: multilib,
350 }
351}
352
Colin Cross635c3b02016-05-18 15:37:25 -0700353func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800354 module := newBaseModule(hod, multilib)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700355 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800356 module.sanitize = &sanitize{}
Colin Crossca860ac2016-01-04 14:34:37 -0800357 return module
358}
359
Colin Cross635c3b02016-05-18 15:37:25 -0700360func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800361 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700362 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800363 moduleContextImpl: moduleContextImpl{
364 mod: c,
365 },
366 }
367 ctx.ctx = ctx
368
369 flags := Flags{
370 Toolchain: c.toolchain(ctx),
371 Clang: c.clang(ctx),
372 }
Colin Crossca860ac2016-01-04 14:34:37 -0800373 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700374 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800375 }
376 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700377 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800378 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700379 if c.stl != nil {
380 flags = c.stl.flags(ctx, flags)
381 }
Colin Cross16b23492016-01-06 14:41:07 -0800382 if c.sanitize != nil {
383 flags = c.sanitize.flags(ctx, flags)
384 }
Colin Crossca860ac2016-01-04 14:34:37 -0800385 for _, feature := range c.features {
386 flags = feature.flags(ctx, flags)
387 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800388 if ctx.Failed() {
389 return
390 }
391
Colin Crossb98c8b02016-07-29 13:44:28 -0700392 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
393 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
394 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800395
Colin Crossca860ac2016-01-04 14:34:37 -0800396 // Optimization to reduce size of build.ninja
397 // Replace the long list of flags for each file with a module-local variable
398 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
399 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
400 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
401 flags.CFlags = []string{"$cflags"}
402 flags.CppFlags = []string{"$cppflags"}
403 flags.AsFlags = []string{"$asflags"}
404
Colin Crossc99deeb2016-04-11 15:06:20 -0700405 deps := c.depsToPaths(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800406 if ctx.Failed() {
407 return
408 }
409
Dan Willemsen76f08272016-07-09 00:14:08 -0700410 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Colin Crossed9f8682015-03-18 17:17:35 -0700411
Colin Cross635c3b02016-05-18 15:37:25 -0700412 var objFiles android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800413 if c.compiler != nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700414 objFiles = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800415 if ctx.Failed() {
416 return
417 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800418 }
419
Colin Crossca860ac2016-01-04 14:34:37 -0800420 if c.linker != nil {
421 outputFile := c.linker.link(ctx, flags, deps, objFiles)
422 if ctx.Failed() {
423 return
424 }
Colin Cross635c3b02016-05-18 15:37:25 -0700425 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Cross5049f022015-03-18 13:28:46 -0700426
Colin Crossb0f28952016-09-19 16:46:53 -0700427 if c.installer != nil && !c.Properties.PreventInstall {
Colin Crossca860ac2016-01-04 14:34:37 -0800428 c.installer.install(ctx, outputFile)
429 if ctx.Failed() {
430 return
431 }
432 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700433 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800434}
435
Colin Crossb98c8b02016-07-29 13:44:28 -0700436func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800437 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700438 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800439 }
Colin Crossca860ac2016-01-04 14:34:37 -0800440 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800441}
442
Colin Crossca860ac2016-01-04 14:34:37 -0800443func (c *Module) begin(ctx BaseModuleContext) {
444 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700445 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700446 }
Colin Crossca860ac2016-01-04 14:34:37 -0800447 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700448 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800449 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700450 if c.stl != nil {
451 c.stl.begin(ctx)
452 }
Colin Cross16b23492016-01-06 14:41:07 -0800453 if c.sanitize != nil {
454 c.sanitize.begin(ctx)
455 }
Colin Crossca860ac2016-01-04 14:34:37 -0800456 for _, feature := range c.features {
457 feature.begin(ctx)
458 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700459 if ctx.sdk() {
460 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
461 if err != nil {
462 ctx.PropertyErrorf("sdk_version", err.Error())
463 }
464 c.Properties.Sdk_version = strconv.Itoa(version)
465 }
Colin Crossca860ac2016-01-04 14:34:37 -0800466}
467
Colin Crossc99deeb2016-04-11 15:06:20 -0700468func (c *Module) deps(ctx BaseModuleContext) Deps {
469 deps := Deps{}
470
471 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700472 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700473 }
474 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700475 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700476 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700477 if c.stl != nil {
478 deps = c.stl.deps(ctx, deps)
479 }
Colin Cross16b23492016-01-06 14:41:07 -0800480 if c.sanitize != nil {
481 deps = c.sanitize.deps(ctx, deps)
482 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700483 for _, feature := range c.features {
484 deps = feature.deps(ctx, deps)
485 }
486
487 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
488 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
489 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
490 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
491 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
492
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700493 for _, lib := range deps.ReexportSharedLibHeaders {
494 if !inList(lib, deps.SharedLibs) {
495 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
496 }
497 }
498
499 for _, lib := range deps.ReexportStaticLibHeaders {
500 if !inList(lib, deps.StaticLibs) {
501 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
502 }
503 }
504
Colin Crossc99deeb2016-04-11 15:06:20 -0700505 return deps
506}
507
Dan Albert7e9d2952016-08-04 13:02:36 -0700508func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800509 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700510 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800511 moduleContextImpl: moduleContextImpl{
512 mod: c,
513 },
514 }
515 ctx.ctx = ctx
516
Colin Crossca860ac2016-01-04 14:34:37 -0800517 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700518}
519
520func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
521 ctx := &baseModuleContext{
522 BaseContext: actx,
523 moduleContextImpl: moduleContextImpl{
524 mod: c,
525 },
526 }
527 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800528
Colin Crossc99deeb2016-04-11 15:06:20 -0700529 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800530
Colin Crossb5bc4b42016-07-11 16:11:59 -0700531 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
532 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700533
Dan Albert914449f2016-06-17 16:45:24 -0700534 variantNdkLibs := []string{}
535 variantLateNdkLibs := []string{}
Dan Willemsen72d39932016-07-08 23:23:48 -0700536 if ctx.sdk() {
Dan Albert914449f2016-06-17 16:45:24 -0700537 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700538
Dan Albert914449f2016-06-17 16:45:24 -0700539 // Rewrites the names of shared libraries into the names of the NDK
540 // libraries where appropriate. This returns two slices.
541 //
542 // The first is a list of non-variant shared libraries (either rewritten
543 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
544 // because they are not NDK libraries).
545 //
546 // The second is a list of ndk_library modules. These need to be
547 // separated because they are a variation dependency and must be added
548 // in a different manner.
549 rewriteNdkLibs := func(list []string) ([]string, []string) {
550 variantLibs := []string{}
551 nonvariantLibs := []string{}
552 for _, entry := range list {
Dan Willemsen72d39932016-07-08 23:23:48 -0700553 if inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700554 if !inList(entry, ndkMigratedLibs) {
555 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
556 } else {
557 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
558 }
559 } else {
560 nonvariantLibs = append(variantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700561 }
562 }
Dan Albert914449f2016-06-17 16:45:24 -0700563 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700564 }
565
Dan Albert914449f2016-06-17 16:45:24 -0700566 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
567 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700568 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700569
570 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
571 deps.WholeStaticLibs...)
572
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700573 for _, lib := range deps.StaticLibs {
574 depTag := staticDepTag
575 if inList(lib, deps.ReexportStaticLibHeaders) {
576 depTag = staticExportDepTag
577 }
Colin Cross15a0d462016-07-14 14:49:58 -0700578 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700579 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700580
581 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
582 deps.LateStaticLibs...)
583
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700584 for _, lib := range deps.SharedLibs {
585 depTag := sharedDepTag
586 if inList(lib, deps.ReexportSharedLibHeaders) {
587 depTag = sharedExportDepTag
588 }
Colin Cross15a0d462016-07-14 14:49:58 -0700589 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700590 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700591
592 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
593 deps.LateSharedLibs...)
594
Colin Cross68861832016-07-08 10:41:41 -0700595 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
596 actx.AddDependency(c, genHeaderDepTag, deps.GeneratedHeaders...)
Dan Willemsenb40aab62016-04-20 14:21:14 -0700597
Colin Cross68861832016-07-08 10:41:41 -0700598 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700599
600 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700601 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800602 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700603 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700604 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700605 }
Dan Albert914449f2016-06-17 16:45:24 -0700606
607 version := ctx.sdkVersion()
608 actx.AddVariationDependencies([]blueprint.Variation{
609 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
610 actx.AddVariationDependencies([]blueprint.Variation{
611 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700612}
Colin Cross21b9a242015-03-24 14:15:58 -0700613
Dan Albert7e9d2952016-08-04 13:02:36 -0700614func beginMutator(ctx android.BottomUpMutatorContext) {
615 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
616 c.beginMutator(ctx)
617 }
618}
619
Colin Cross635c3b02016-05-18 15:37:25 -0700620func depsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3f32f032016-07-11 14:36:48 -0700621 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
Colin Cross6362e272015-10-29 15:25:03 -0700622 c.depsMutator(ctx)
623 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800624}
625
Colin Crossca860ac2016-01-04 14:34:37 -0800626func (c *Module) clang(ctx BaseModuleContext) bool {
627 clang := Bool(c.Properties.Clang)
628
629 if c.Properties.Clang == nil {
630 if ctx.Host() {
631 clang = true
632 }
633
634 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
635 clang = true
636 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800637 }
Colin Cross28344522015-04-22 13:07:53 -0700638
Colin Crossca860ac2016-01-04 14:34:37 -0800639 if !c.toolchain(ctx).ClangSupported() {
640 clang = false
641 }
642
643 return clang
644}
645
Colin Crossc99deeb2016-04-11 15:06:20 -0700646// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700647func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800648 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800649
Dan Willemsena96ff642016-06-07 12:34:45 -0700650 // Whether a module can link to another module, taking into
651 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700652 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700653 if from.Target().Os != android.Android {
654 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700655 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700656 }
657 if from.Properties.Sdk_version == "" {
658 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700659 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700660 }
Colin Crossb916a382016-07-29 17:28:03 -0700661 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700662 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700663 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700664 }
665 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
666 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700667 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700668 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700669 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
670 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700671 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700672 }
Colin Crossb916a382016-07-29 17:28:03 -0700673 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700674 // These aren't real libraries, but are the stub shared libraries that are included in
675 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700676 return
Dan Albert914449f2016-06-17 16:45:24 -0700677 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700678 if to.Properties.Sdk_version == "" {
679 // NDK code linking to platform code is never okay.
680 ctx.ModuleErrorf("depends on non-NDK-built library %q",
681 ctx.OtherModuleName(to))
682 }
683
684 // All this point we know we have two NDK libraries, but we need to
685 // check that we're not linking against anything built against a higher
686 // API level, as it is only valid to link against older or equivalent
687 // APIs.
688
689 if from.Properties.Sdk_version == "current" {
690 // Current can link against anything.
691 return
692 } else if to.Properties.Sdk_version == "current" {
693 // Current can't be linked against by anything else.
694 ctx.ModuleErrorf("links %q built against newer API version %q",
695 ctx.OtherModuleName(to), "current")
696 }
697
698 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
699 if err != nil {
700 ctx.PropertyErrorf("sdk_version",
701 "Invalid sdk_version value (must be int): %q",
702 from.Properties.Sdk_version)
703 }
704 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
705 if err != nil {
706 ctx.PropertyErrorf("sdk_version",
707 "Invalid sdk_version value (must be int): %q",
708 to.Properties.Sdk_version)
709 }
710
711 if toApi > fromApi {
712 ctx.ModuleErrorf("links %q built against newer API version %q",
713 ctx.OtherModuleName(to), to.Properties.Sdk_version)
714 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700715 }
716
Colin Crossc99deeb2016-04-11 15:06:20 -0700717 ctx.VisitDirectDeps(func(m blueprint.Module) {
718 name := ctx.OtherModuleName(m)
719 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800720
Colin Cross635c3b02016-05-18 15:37:25 -0700721 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700722 if a == nil {
723 ctx.ModuleErrorf("module %q not an android module", name)
724 return
Colin Crossca860ac2016-01-04 14:34:37 -0800725 }
Colin Crossca860ac2016-01-04 14:34:37 -0800726
Dan Willemsena96ff642016-06-07 12:34:45 -0700727 cc, _ := m.(*Module)
728 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700729 switch tag {
Colin Cross635c3b02016-05-18 15:37:25 -0700730 case android.DefaultsDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700731 case genSourceDepTag:
732 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
733 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
734 genRule.GeneratedSourceFiles()...)
735 } else {
736 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
737 }
738 case genHeaderDepTag:
739 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
740 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
741 genRule.GeneratedSourceFiles()...)
Dan Willemsen76f08272016-07-09 00:14:08 -0700742 depPaths.Flags = append(depPaths.Flags,
Colin Cross635c3b02016-05-18 15:37:25 -0700743 includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()}))
Dan Willemsenb40aab62016-04-20 14:21:14 -0700744 } else {
745 ctx.ModuleErrorf("module %q is not a genrule", name)
746 }
747 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700748 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800749 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700750 return
751 }
752
753 if !a.Enabled() {
754 ctx.ModuleErrorf("depends on disabled module %q", name)
755 return
756 }
757
Colin Crossa1ad8d12016-06-01 17:09:44 -0700758 if a.Target().Os != ctx.Os() {
759 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
760 return
761 }
762
763 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
764 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700765 return
766 }
767
Dan Willemsena96ff642016-06-07 12:34:45 -0700768 if !cc.outputFile.Valid() {
Colin Crossc99deeb2016-04-11 15:06:20 -0700769 ctx.ModuleErrorf("module %q missing output file", name)
770 return
771 }
772
773 if tag == reuseObjTag {
774 depPaths.ObjFiles = append(depPaths.ObjFiles,
Colin Crossb916a382016-07-29 17:28:03 -0700775 cc.compiler.(libraryInterface).reuseObjs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700776 return
777 }
778
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700779 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700780 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700781 flags := i.exportedFlags()
782 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700783
784 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700785 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700786 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700787 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700788
Dan Albert9e10cd42016-08-03 14:12:14 -0700789 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700790 }
791
Colin Cross635c3b02016-05-18 15:37:25 -0700792 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700793
794 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700795 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700796 depPtr = &depPaths.SharedLibs
Dan Albert914449f2016-06-17 16:45:24 -0700797 case lateSharedDepTag, ndkLateStubDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700798 depPtr = &depPaths.LateSharedLibs
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700799 case staticDepTag, staticExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700800 depPtr = &depPaths.StaticLibs
801 case lateStaticDepTag:
802 depPtr = &depPaths.LateStaticLibs
803 case wholeStaticDepTag:
804 depPtr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -0700805 staticLib, ok := cc.linker.(libraryInterface)
806 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700807 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700808 return
809 }
810
811 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
812 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
813 for i := range missingDeps {
814 missingDeps[i] += postfix
815 }
816 ctx.AddMissingDependencies(missingDeps)
817 }
818 depPaths.WholeStaticLibObjFiles =
Colin Crossc7a38dc2016-07-12 13:13:09 -0700819 append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700820 case objDepTag:
821 depPtr = &depPaths.ObjFiles
822 case crtBeginDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700823 depPaths.CrtBegin = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700824 case crtEndDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700825 depPaths.CrtEnd = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700826 default:
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700827 panic(fmt.Errorf("unknown dependency tag: %s", tag))
Colin Crossc99deeb2016-04-11 15:06:20 -0700828 }
829
830 if depPtr != nil {
Dan Willemsena96ff642016-06-07 12:34:45 -0700831 *depPtr = append(*depPtr, cc.outputFile.Path())
Colin Crossca860ac2016-01-04 14:34:37 -0800832 }
833 })
834
835 return depPaths
836}
837
838func (c *Module) InstallInData() bool {
839 if c.installer == nil {
840 return false
841 }
Colin Cross94610402016-08-29 13:41:32 -0700842 if c.sanitize != nil && c.sanitize.inData() {
843 return true
844 }
Colin Crossca860ac2016-01-04 14:34:37 -0800845 return c.installer.inData()
846}
847
Colin Cross2ba19d92015-05-07 15:44:20 -0700848//
Colin Crosscfad1192015-11-02 16:43:11 -0800849// Defaults
850//
Colin Crossca860ac2016-01-04 14:34:37 -0800851type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700852 android.ModuleBase
853 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -0800854}
855
Colin Cross635c3b02016-05-18 15:37:25 -0700856func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -0800857}
858
Colin Crossca860ac2016-01-04 14:34:37 -0800859func defaultsFactory() (blueprint.Module, []interface{}) {
Colin Crosse1d764e2016-08-18 14:18:32 -0700860 return DefaultsFactory()
861}
862
863func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
Colin Crossca860ac2016-01-04 14:34:37 -0800864 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -0800865
Colin Crosse1d764e2016-08-18 14:18:32 -0700866 props = append(props,
Colin Crossca860ac2016-01-04 14:34:37 -0800867 &BaseProperties{},
868 &BaseCompilerProperties{},
869 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700870 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -0700871 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800872 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700873 &TestProperties{},
874 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800875 &UnusedProperties{},
876 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -0800877 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -0700878 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -0700879 &InstallerProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -0700880 )
Colin Crosscfad1192015-11-02 16:43:11 -0800881
Colin Crosse1d764e2016-08-18 14:18:32 -0700882 _, props = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
883 android.MultilibDefault, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800884
Colin Crosse1d764e2016-08-18 14:18:32 -0700885 return android.InitDefaultsModule(module, module, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800886}
887
Colin Cross74d1ec02015-04-28 13:30:13 -0700888// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
889// modifies the slice contents in place, and returns a subslice of the original slice
890func lastUniqueElements(list []string) []string {
891 totalSkip := 0
892 for i := len(list) - 1; i >= totalSkip; i-- {
893 skip := 0
894 for j := i - 1; j >= totalSkip; j-- {
895 if list[i] == list[j] {
896 skip++
897 } else {
898 list[j+skip] = list[j]
899 }
900 }
901 totalSkip += skip
902 }
903 return list[totalSkip:]
904}
Colin Cross06a931b2015-10-28 17:23:31 -0700905
906var Bool = proptools.Bool