blob: 66c47c1fe6b77961c4c494bb7ba357eb098ef42f [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
Dan Willemsenb3454ab2016-09-28 17:34:58 -070067 ReexportGeneratedHeaders []string
68
Colin Cross97ba0732015-03-23 17:50:24 -070069 CrtBegin, CrtEnd string
Colin Crossc472d572015-03-17 15:06:21 -070070}
71
Colin Crossca860ac2016-01-04 14:34:37 -080072type PathDeps struct {
Colin Cross635c3b02016-05-18 15:37:25 -070073 SharedLibs, LateSharedLibs android.Paths
74 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070075
Colin Cross635c3b02016-05-18 15:37:25 -070076 ObjFiles android.Paths
77 WholeStaticLibObjFiles android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070078
Colin Cross635c3b02016-05-18 15:37:25 -070079 GeneratedSources android.Paths
80 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070081
Dan Willemsen76f08272016-07-09 00:14:08 -070082 Flags, ReexportedFlags []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070083
Colin Cross635c3b02016-05-18 15:37:25 -070084 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -070085}
86
Colin Crossca860ac2016-01-04 14:34:37 -080087type Flags struct {
Colin Cross28344522015-04-22 13:07:53 -070088 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
89 AsFlags []string // Flags that apply to assembly source files
90 CFlags []string // Flags that apply to C and C++ source files
91 ConlyFlags []string // Flags that apply to C source files
92 CppFlags []string // Flags that apply to C++ source files
93 YaccFlags []string // Flags that apply to Yacc source files
94 LdFlags []string // Flags that apply to linker command lines
Colin Cross16b23492016-01-06 14:41:07 -080095 libFlags []string // Flags to add libraries early to the link order
Colin Cross28344522015-04-22 13:07:53 -070096
Colin Crossb98c8b02016-07-29 13:44:28 -070097 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -070098 Clang bool
Colin Crossca860ac2016-01-04 14:34:37 -080099
100 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800101 DynamicLinker string
102
Colin Cross635c3b02016-05-18 15:37:25 -0700103 CFlagsDeps android.Paths // Files depended on by compiler flags
Colin Crossc472d572015-03-17 15:06:21 -0700104}
105
Colin Cross81413472016-04-11 14:37:39 -0700106type ObjectLinkerProperties struct {
107 // names of other cc_object modules to link into this module using partial linking
108 Objs []string `android:"arch_variant"`
109}
110
Colin Crossca860ac2016-01-04 14:34:37 -0800111// Properties used to compile all C or C++ modules
112type BaseProperties struct {
113 // compile module with clang instead of gcc
114 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700115
116 // Minimum sdk version supported when compiling against the ndk
117 Sdk_version string
118
Colin Crossca860ac2016-01-04 14:34:37 -0800119 // don't insert default compiler flags into asflags, cflags,
120 // cppflags, conlyflags, ldflags, or include_dirs
121 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700122
123 AndroidMkSharedLibs []string `blueprint:"mutated"`
Colin Crossbc6fb162016-05-24 15:39:04 -0700124 HideFromMake bool `blueprint:"mutated"`
Colin Crossb0f28952016-09-19 16:46:53 -0700125 PreventInstall bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800126}
127
Colin Crossca860ac2016-01-04 14:34:37 -0800128type UnusedProperties struct {
Colin Cross21b481b2016-04-15 16:27:17 -0700129 Native_coverage *bool
Colin Cross21b481b2016-04-15 16:27:17 -0700130 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800131}
132
Colin Crossca860ac2016-01-04 14:34:37 -0800133type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800134 static() bool
135 staticBinary() bool
136 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700137 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800138 noDefaultCompilerFlags() bool
139 sdk() bool
140 sdkVersion() string
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700141 selectedStl() string
Colin Crossca860ac2016-01-04 14:34:37 -0800142}
143
144type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700145 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800146 ModuleContextIntf
147}
148
149type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700150 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800151 ModuleContextIntf
152}
153
Colin Crossca860ac2016-01-04 14:34:37 -0800154type feature interface {
155 begin(ctx BaseModuleContext)
156 deps(ctx BaseModuleContext, deps Deps) Deps
157 flags(ctx ModuleContext, flags Flags) Flags
158 props() []interface{}
159}
160
161type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700162 compilerInit(ctx BaseModuleContext)
163 compilerDeps(ctx BaseModuleContext, deps Deps) Deps
164 compilerFlags(ctx ModuleContext, flags Flags) Flags
165 compilerProps() []interface{}
166
Colin Cross76fada02016-07-27 10:31:13 -0700167 appendCflags([]string)
168 appendAsflags([]string)
Colin Cross635c3b02016-05-18 15:37:25 -0700169 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800170}
171
172type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700173 linkerInit(ctx BaseModuleContext)
174 linkerDeps(ctx BaseModuleContext, deps Deps) Deps
175 linkerFlags(ctx ModuleContext, flags Flags) Flags
176 linkerProps() []interface{}
177
Colin Cross635c3b02016-05-18 15:37:25 -0700178 link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700179 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800180}
181
182type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700183 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700184 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800185 inData() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700186 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800187}
188
Colin Crossc99deeb2016-04-11 15:06:20 -0700189type dependencyTag struct {
190 blueprint.BaseDependencyTag
191 name string
192 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700193
194 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700195}
196
197var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700198 sharedDepTag = dependencyTag{name: "shared", library: true}
199 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
200 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
201 staticDepTag = dependencyTag{name: "static", library: true}
202 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
203 lateStaticDepTag = dependencyTag{name: "late static", library: true}
204 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
205 genSourceDepTag = dependencyTag{name: "gen source"}
206 genHeaderDepTag = dependencyTag{name: "gen header"}
207 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
208 objDepTag = dependencyTag{name: "obj"}
209 crtBeginDepTag = dependencyTag{name: "crtbegin"}
210 crtEndDepTag = dependencyTag{name: "crtend"}
211 reuseObjTag = dependencyTag{name: "reuse objects"}
212 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
213 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700214)
215
Colin Crossca860ac2016-01-04 14:34:37 -0800216// Module contains the properties and members used by all C/C++ module types, and implements
217// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
218// to construct the output file. Behavior can be customized with a Customizer interface
219type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700220 android.ModuleBase
221 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700222
Colin Crossca860ac2016-01-04 14:34:37 -0800223 Properties BaseProperties
224 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700225
Colin Crossca860ac2016-01-04 14:34:37 -0800226 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700227 hod android.HostOrDeviceSupported
228 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700229
Colin Crossca860ac2016-01-04 14:34:37 -0800230 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700231 features []feature
232 compiler compiler
233 linker linker
234 installer installer
235 stl *stl
236 sanitize *sanitize
Colin Cross16b23492016-01-06 14:41:07 -0800237
238 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700239
Colin Cross635c3b02016-05-18 15:37:25 -0700240 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800241
Colin Crossb98c8b02016-07-29 13:44:28 -0700242 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700243
244 subAndroidMkOnce map[subAndroidMkProvider]bool
Colin Crossc472d572015-03-17 15:06:21 -0700245}
246
Colin Crossca860ac2016-01-04 14:34:37 -0800247func (c *Module) Init() (blueprint.Module, []interface{}) {
248 props := []interface{}{&c.Properties, &c.unused}
Colin Crossca860ac2016-01-04 14:34:37 -0800249 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700250 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800251 }
252 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700253 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800254 }
255 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700256 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800257 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700258 if c.stl != nil {
259 props = append(props, c.stl.props()...)
260 }
Colin Cross16b23492016-01-06 14:41:07 -0800261 if c.sanitize != nil {
262 props = append(props, c.sanitize.props()...)
263 }
Colin Crossca860ac2016-01-04 14:34:37 -0800264 for _, feature := range c.features {
265 props = append(props, feature.props()...)
266 }
Colin Crossc472d572015-03-17 15:06:21 -0700267
Colin Cross635c3b02016-05-18 15:37:25 -0700268 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700269
Colin Cross635c3b02016-05-18 15:37:25 -0700270 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700271}
272
Colin Crossb916a382016-07-29 17:28:03 -0700273// Returns true for dependency roots (binaries)
274// TODO(ccross): also handle dlopenable libraries
275func (c *Module) isDependencyRoot() bool {
276 if root, ok := c.linker.(interface {
277 isDependencyRoot() bool
278 }); ok {
279 return root.isDependencyRoot()
280 }
281 return false
282}
283
Colin Crossca860ac2016-01-04 14:34:37 -0800284type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700285 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800286 moduleContextImpl
287}
288
289type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700290 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800291 moduleContextImpl
292}
293
294type moduleContextImpl struct {
295 mod *Module
296 ctx BaseModuleContext
297}
298
Colin Crossca860ac2016-01-04 14:34:37 -0800299func (ctx *moduleContextImpl) clang() bool {
300 return ctx.mod.clang(ctx.ctx)
301}
302
Colin Crossb98c8b02016-07-29 13:44:28 -0700303func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800304 return ctx.mod.toolchain(ctx.ctx)
305}
306
307func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700308 if static, ok := ctx.mod.linker.(interface {
309 static() bool
310 }); ok {
311 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800312 }
Colin Crossb916a382016-07-29 17:28:03 -0700313 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800314}
315
316func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700317 if static, ok := ctx.mod.linker.(interface {
318 staticBinary() bool
319 }); ok {
320 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800321 }
Colin Crossb916a382016-07-29 17:28:03 -0700322 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
325func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
326 return Bool(ctx.mod.Properties.No_default_compiler_flags)
327}
328
329func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsena96ff642016-06-07 12:34:45 -0700330 if ctx.ctx.Device() {
331 return ctx.mod.Properties.Sdk_version != ""
332 }
333 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800334}
335
336func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700337 if ctx.ctx.Device() {
338 return ctx.mod.Properties.Sdk_version
339 }
340 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800341}
342
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700343func (ctx *moduleContextImpl) selectedStl() string {
344 if stl := ctx.mod.stl; stl != nil {
345 return stl.Properties.SelectedStl
346 }
347 return ""
348}
349
Colin Cross635c3b02016-05-18 15:37:25 -0700350func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800351 return &Module{
352 hod: hod,
353 multilib: multilib,
354 }
355}
356
Colin Cross635c3b02016-05-18 15:37:25 -0700357func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800358 module := newBaseModule(hod, multilib)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700359 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800360 module.sanitize = &sanitize{}
Colin Crossca860ac2016-01-04 14:34:37 -0800361 return module
362}
363
Colin Cross635c3b02016-05-18 15:37:25 -0700364func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800365 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700366 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800367 moduleContextImpl: moduleContextImpl{
368 mod: c,
369 },
370 }
371 ctx.ctx = ctx
372
373 flags := Flags{
374 Toolchain: c.toolchain(ctx),
375 Clang: c.clang(ctx),
376 }
Colin Crossca860ac2016-01-04 14:34:37 -0800377 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700378 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800379 }
380 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700381 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800382 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700383 if c.stl != nil {
384 flags = c.stl.flags(ctx, flags)
385 }
Colin Cross16b23492016-01-06 14:41:07 -0800386 if c.sanitize != nil {
387 flags = c.sanitize.flags(ctx, flags)
388 }
Colin Crossca860ac2016-01-04 14:34:37 -0800389 for _, feature := range c.features {
390 flags = feature.flags(ctx, flags)
391 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800392 if ctx.Failed() {
393 return
394 }
395
Colin Crossb98c8b02016-07-29 13:44:28 -0700396 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
397 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
398 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800399
Colin Crossca860ac2016-01-04 14:34:37 -0800400 // Optimization to reduce size of build.ninja
401 // Replace the long list of flags for each file with a module-local variable
402 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
403 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
404 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
405 flags.CFlags = []string{"$cflags"}
406 flags.CppFlags = []string{"$cppflags"}
407 flags.AsFlags = []string{"$asflags"}
408
Colin Crossc99deeb2016-04-11 15:06:20 -0700409 deps := c.depsToPaths(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800410 if ctx.Failed() {
411 return
412 }
413
Dan Willemsen76f08272016-07-09 00:14:08 -0700414 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Colin Crossed9f8682015-03-18 17:17:35 -0700415
Colin Cross635c3b02016-05-18 15:37:25 -0700416 var objFiles android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800417 if c.compiler != nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700418 objFiles = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800419 if ctx.Failed() {
420 return
421 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800422 }
423
Colin Crossca860ac2016-01-04 14:34:37 -0800424 if c.linker != nil {
425 outputFile := c.linker.link(ctx, flags, deps, objFiles)
426 if ctx.Failed() {
427 return
428 }
Colin Cross635c3b02016-05-18 15:37:25 -0700429 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Cross5049f022015-03-18 13:28:46 -0700430
Colin Crossb0f28952016-09-19 16:46:53 -0700431 if c.installer != nil && !c.Properties.PreventInstall {
Colin Crossca860ac2016-01-04 14:34:37 -0800432 c.installer.install(ctx, outputFile)
433 if ctx.Failed() {
434 return
435 }
436 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700437 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800438}
439
Colin Crossb98c8b02016-07-29 13:44:28 -0700440func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800441 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700442 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800443 }
Colin Crossca860ac2016-01-04 14:34:37 -0800444 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800445}
446
Colin Crossca860ac2016-01-04 14:34:37 -0800447func (c *Module) begin(ctx BaseModuleContext) {
448 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700449 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700450 }
Colin Crossca860ac2016-01-04 14:34:37 -0800451 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700452 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800453 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700454 if c.stl != nil {
455 c.stl.begin(ctx)
456 }
Colin Cross16b23492016-01-06 14:41:07 -0800457 if c.sanitize != nil {
458 c.sanitize.begin(ctx)
459 }
Colin Crossca860ac2016-01-04 14:34:37 -0800460 for _, feature := range c.features {
461 feature.begin(ctx)
462 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700463 if ctx.sdk() {
464 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
465 if err != nil {
466 ctx.PropertyErrorf("sdk_version", err.Error())
467 }
468 c.Properties.Sdk_version = strconv.Itoa(version)
469 }
Colin Crossca860ac2016-01-04 14:34:37 -0800470}
471
Colin Crossc99deeb2016-04-11 15:06:20 -0700472func (c *Module) deps(ctx BaseModuleContext) Deps {
473 deps := Deps{}
474
475 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700476 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700477 }
478 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700479 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700480 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700481 if c.stl != nil {
482 deps = c.stl.deps(ctx, deps)
483 }
Colin Cross16b23492016-01-06 14:41:07 -0800484 if c.sanitize != nil {
485 deps = c.sanitize.deps(ctx, deps)
486 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700487 for _, feature := range c.features {
488 deps = feature.deps(ctx, deps)
489 }
490
491 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
492 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
493 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
494 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
495 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
496
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700497 for _, lib := range deps.ReexportSharedLibHeaders {
498 if !inList(lib, deps.SharedLibs) {
499 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
500 }
501 }
502
503 for _, lib := range deps.ReexportStaticLibHeaders {
504 if !inList(lib, deps.StaticLibs) {
505 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
506 }
507 }
508
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700509 for _, gen := range deps.ReexportGeneratedHeaders {
510 if !inList(gen, deps.GeneratedHeaders) {
511 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
512 }
513 }
514
Colin Crossc99deeb2016-04-11 15:06:20 -0700515 return deps
516}
517
Dan Albert7e9d2952016-08-04 13:02:36 -0700518func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800519 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700520 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800521 moduleContextImpl: moduleContextImpl{
522 mod: c,
523 },
524 }
525 ctx.ctx = ctx
526
Colin Crossca860ac2016-01-04 14:34:37 -0800527 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700528}
529
530func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
531 ctx := &baseModuleContext{
532 BaseContext: actx,
533 moduleContextImpl: moduleContextImpl{
534 mod: c,
535 },
536 }
537 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800538
Colin Crossc99deeb2016-04-11 15:06:20 -0700539 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800540
Colin Crossb5bc4b42016-07-11 16:11:59 -0700541 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
542 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700543
Dan Albert914449f2016-06-17 16:45:24 -0700544 variantNdkLibs := []string{}
545 variantLateNdkLibs := []string{}
Dan Willemsen72d39932016-07-08 23:23:48 -0700546 if ctx.sdk() {
Dan Albert914449f2016-06-17 16:45:24 -0700547 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700548
Dan Albert914449f2016-06-17 16:45:24 -0700549 // Rewrites the names of shared libraries into the names of the NDK
550 // libraries where appropriate. This returns two slices.
551 //
552 // The first is a list of non-variant shared libraries (either rewritten
553 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
554 // because they are not NDK libraries).
555 //
556 // The second is a list of ndk_library modules. These need to be
557 // separated because they are a variation dependency and must be added
558 // in a different manner.
559 rewriteNdkLibs := func(list []string) ([]string, []string) {
560 variantLibs := []string{}
561 nonvariantLibs := []string{}
562 for _, entry := range list {
Dan Willemsen72d39932016-07-08 23:23:48 -0700563 if inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700564 if !inList(entry, ndkMigratedLibs) {
565 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
566 } else {
567 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
568 }
569 } else {
570 nonvariantLibs = append(variantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700571 }
572 }
Dan Albert914449f2016-06-17 16:45:24 -0700573 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700574 }
575
Dan Albert914449f2016-06-17 16:45:24 -0700576 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
577 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700578 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700579
580 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
581 deps.WholeStaticLibs...)
582
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700583 for _, lib := range deps.StaticLibs {
584 depTag := staticDepTag
585 if inList(lib, deps.ReexportStaticLibHeaders) {
586 depTag = staticExportDepTag
587 }
Colin Cross15a0d462016-07-14 14:49:58 -0700588 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700589 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700590
591 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
592 deps.LateStaticLibs...)
593
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700594 for _, lib := range deps.SharedLibs {
595 depTag := sharedDepTag
596 if inList(lib, deps.ReexportSharedLibHeaders) {
597 depTag = sharedExportDepTag
598 }
Colin Cross15a0d462016-07-14 14:49:58 -0700599 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700600 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700601
602 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
603 deps.LateSharedLibs...)
604
Colin Cross68861832016-07-08 10:41:41 -0700605 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700606
607 for _, gen := range deps.GeneratedHeaders {
608 depTag := genHeaderDepTag
609 if inList(gen, deps.ReexportGeneratedHeaders) {
610 depTag = genHeaderExportDepTag
611 }
612 actx.AddDependency(c, depTag, gen)
613 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700614
Colin Cross68861832016-07-08 10:41:41 -0700615 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700616
617 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700618 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800619 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700620 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700621 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700622 }
Dan Albert914449f2016-06-17 16:45:24 -0700623
624 version := ctx.sdkVersion()
625 actx.AddVariationDependencies([]blueprint.Variation{
626 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
627 actx.AddVariationDependencies([]blueprint.Variation{
628 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700629}
Colin Cross21b9a242015-03-24 14:15:58 -0700630
Dan Albert7e9d2952016-08-04 13:02:36 -0700631func beginMutator(ctx android.BottomUpMutatorContext) {
632 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
633 c.beginMutator(ctx)
634 }
635}
636
Colin Cross635c3b02016-05-18 15:37:25 -0700637func depsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3f32f032016-07-11 14:36:48 -0700638 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
Colin Cross6362e272015-10-29 15:25:03 -0700639 c.depsMutator(ctx)
640 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800641}
642
Colin Crossca860ac2016-01-04 14:34:37 -0800643func (c *Module) clang(ctx BaseModuleContext) bool {
644 clang := Bool(c.Properties.Clang)
645
646 if c.Properties.Clang == nil {
647 if ctx.Host() {
648 clang = true
649 }
650
651 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
652 clang = true
653 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800654 }
Colin Cross28344522015-04-22 13:07:53 -0700655
Colin Crossca860ac2016-01-04 14:34:37 -0800656 if !c.toolchain(ctx).ClangSupported() {
657 clang = false
658 }
659
660 return clang
661}
662
Colin Crossc99deeb2016-04-11 15:06:20 -0700663// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700664func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800665 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800666
Dan Willemsena96ff642016-06-07 12:34:45 -0700667 // Whether a module can link to another module, taking into
668 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700669 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700670 if from.Target().Os != android.Android {
671 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700672 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700673 }
674 if from.Properties.Sdk_version == "" {
675 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700676 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700677 }
Colin Crossb916a382016-07-29 17:28:03 -0700678 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700679 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700680 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700681 }
682 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
683 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700684 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700685 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700686 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
687 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700688 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700689 }
Colin Crossb916a382016-07-29 17:28:03 -0700690 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700691 // These aren't real libraries, but are the stub shared libraries that are included in
692 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700693 return
Dan Albert914449f2016-06-17 16:45:24 -0700694 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700695 if to.Properties.Sdk_version == "" {
696 // NDK code linking to platform code is never okay.
697 ctx.ModuleErrorf("depends on non-NDK-built library %q",
698 ctx.OtherModuleName(to))
699 }
700
701 // All this point we know we have two NDK libraries, but we need to
702 // check that we're not linking against anything built against a higher
703 // API level, as it is only valid to link against older or equivalent
704 // APIs.
705
706 if from.Properties.Sdk_version == "current" {
707 // Current can link against anything.
708 return
709 } else if to.Properties.Sdk_version == "current" {
710 // Current can't be linked against by anything else.
711 ctx.ModuleErrorf("links %q built against newer API version %q",
712 ctx.OtherModuleName(to), "current")
713 }
714
715 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
716 if err != nil {
717 ctx.PropertyErrorf("sdk_version",
718 "Invalid sdk_version value (must be int): %q",
719 from.Properties.Sdk_version)
720 }
721 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
722 if err != nil {
723 ctx.PropertyErrorf("sdk_version",
724 "Invalid sdk_version value (must be int): %q",
725 to.Properties.Sdk_version)
726 }
727
728 if toApi > fromApi {
729 ctx.ModuleErrorf("links %q built against newer API version %q",
730 ctx.OtherModuleName(to), to.Properties.Sdk_version)
731 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700732 }
733
Colin Crossc99deeb2016-04-11 15:06:20 -0700734 ctx.VisitDirectDeps(func(m blueprint.Module) {
735 name := ctx.OtherModuleName(m)
736 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800737
Colin Cross635c3b02016-05-18 15:37:25 -0700738 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700739 if a == nil {
740 ctx.ModuleErrorf("module %q not an android module", name)
741 return
Colin Crossca860ac2016-01-04 14:34:37 -0800742 }
Colin Crossca860ac2016-01-04 14:34:37 -0800743
Dan Willemsena96ff642016-06-07 12:34:45 -0700744 cc, _ := m.(*Module)
745 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700746 switch tag {
Colin Cross635c3b02016-05-18 15:37:25 -0700747 case android.DefaultsDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700748 case genSourceDepTag:
749 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
750 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
751 genRule.GeneratedSourceFiles()...)
752 } else {
753 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
754 }
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700755 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700756 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
757 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
758 genRule.GeneratedSourceFiles()...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700759 flags := includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()})
760 depPaths.Flags = append(depPaths.Flags, flags)
761 if tag == genHeaderExportDepTag {
762 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
763 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700764 } else {
765 ctx.ModuleErrorf("module %q is not a genrule", name)
766 }
767 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700768 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800769 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700770 return
771 }
772
773 if !a.Enabled() {
774 ctx.ModuleErrorf("depends on disabled module %q", name)
775 return
776 }
777
Colin Crossa1ad8d12016-06-01 17:09:44 -0700778 if a.Target().Os != ctx.Os() {
779 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
780 return
781 }
782
783 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
784 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700785 return
786 }
787
Dan Willemsena96ff642016-06-07 12:34:45 -0700788 if !cc.outputFile.Valid() {
Colin Crossc99deeb2016-04-11 15:06:20 -0700789 ctx.ModuleErrorf("module %q missing output file", name)
790 return
791 }
792
793 if tag == reuseObjTag {
794 depPaths.ObjFiles = append(depPaths.ObjFiles,
Colin Crossb916a382016-07-29 17:28:03 -0700795 cc.compiler.(libraryInterface).reuseObjs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700796 return
797 }
798
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700799 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700800 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700801 flags := i.exportedFlags()
802 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700803
804 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700805 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700806 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700807 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700808
Dan Albert9e10cd42016-08-03 14:12:14 -0700809 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700810 }
811
Colin Cross635c3b02016-05-18 15:37:25 -0700812 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700813
814 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700815 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700816 depPtr = &depPaths.SharedLibs
Dan Albert914449f2016-06-17 16:45:24 -0700817 case lateSharedDepTag, ndkLateStubDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700818 depPtr = &depPaths.LateSharedLibs
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700819 case staticDepTag, staticExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700820 depPtr = &depPaths.StaticLibs
821 case lateStaticDepTag:
822 depPtr = &depPaths.LateStaticLibs
823 case wholeStaticDepTag:
824 depPtr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -0700825 staticLib, ok := cc.linker.(libraryInterface)
826 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700827 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700828 return
829 }
830
831 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
832 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
833 for i := range missingDeps {
834 missingDeps[i] += postfix
835 }
836 ctx.AddMissingDependencies(missingDeps)
837 }
838 depPaths.WholeStaticLibObjFiles =
Colin Crossc7a38dc2016-07-12 13:13:09 -0700839 append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700840 case objDepTag:
841 depPtr = &depPaths.ObjFiles
842 case crtBeginDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700843 depPaths.CrtBegin = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700844 case crtEndDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700845 depPaths.CrtEnd = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700846 default:
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700847 panic(fmt.Errorf("unknown dependency tag: %s", tag))
Colin Crossc99deeb2016-04-11 15:06:20 -0700848 }
849
850 if depPtr != nil {
Dan Willemsena96ff642016-06-07 12:34:45 -0700851 *depPtr = append(*depPtr, cc.outputFile.Path())
Colin Crossca860ac2016-01-04 14:34:37 -0800852 }
853 })
854
855 return depPaths
856}
857
858func (c *Module) InstallInData() bool {
859 if c.installer == nil {
860 return false
861 }
Colin Cross94610402016-08-29 13:41:32 -0700862 if c.sanitize != nil && c.sanitize.inData() {
863 return true
864 }
Colin Crossca860ac2016-01-04 14:34:37 -0800865 return c.installer.inData()
866}
867
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700868func (c *Module) HostToolPath() android.OptionalPath {
869 if c.installer == nil {
870 return android.OptionalPath{}
871 }
872 return c.installer.hostToolPath()
873}
874
Colin Cross2ba19d92015-05-07 15:44:20 -0700875//
Colin Crosscfad1192015-11-02 16:43:11 -0800876// Defaults
877//
Colin Crossca860ac2016-01-04 14:34:37 -0800878type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700879 android.ModuleBase
880 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -0800881}
882
Colin Cross635c3b02016-05-18 15:37:25 -0700883func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -0800884}
885
Colin Crossca860ac2016-01-04 14:34:37 -0800886func defaultsFactory() (blueprint.Module, []interface{}) {
Colin Crosse1d764e2016-08-18 14:18:32 -0700887 return DefaultsFactory()
888}
889
890func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
Colin Crossca860ac2016-01-04 14:34:37 -0800891 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -0800892
Colin Crosse1d764e2016-08-18 14:18:32 -0700893 props = append(props,
Colin Crossca860ac2016-01-04 14:34:37 -0800894 &BaseProperties{},
895 &BaseCompilerProperties{},
896 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700897 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -0700898 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800899 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700900 &TestProperties{},
901 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800902 &UnusedProperties{},
903 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -0800904 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -0700905 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -0700906 &InstallerProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -0700907 )
Colin Crosscfad1192015-11-02 16:43:11 -0800908
Colin Crosse1d764e2016-08-18 14:18:32 -0700909 _, props = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
910 android.MultilibDefault, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800911
Colin Crosse1d764e2016-08-18 14:18:32 -0700912 return android.InitDefaultsModule(module, module, props...)
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