blob: 9a1981279d4da64fb79e1a6e402896d226e6f129 [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 Willemsen847dcc72016-09-29 12:13:36 -070083 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070084
Colin Cross635c3b02016-05-18 15:37:25 -070085 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -070086}
87
Colin Crossca860ac2016-01-04 14:34:37 -080088type Flags struct {
Colin Cross28344522015-04-22 13:07:53 -070089 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
90 AsFlags []string // Flags that apply to assembly source files
91 CFlags []string // Flags that apply to C and C++ source files
92 ConlyFlags []string // Flags that apply to C source files
93 CppFlags []string // Flags that apply to C++ source files
94 YaccFlags []string // Flags that apply to Yacc source files
95 LdFlags []string // Flags that apply to linker command lines
Colin Cross16b23492016-01-06 14:41:07 -080096 libFlags []string // Flags to add libraries early to the link order
Colin Cross28344522015-04-22 13:07:53 -070097
Colin Crossb98c8b02016-07-29 13:44:28 -070098 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -070099 Clang bool
Colin Crossca860ac2016-01-04 14:34:37 -0800100
101 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800102 DynamicLinker string
103
Colin Cross635c3b02016-05-18 15:37:25 -0700104 CFlagsDeps android.Paths // Files depended on by compiler flags
Colin Crossc472d572015-03-17 15:06:21 -0700105}
106
Colin Cross81413472016-04-11 14:37:39 -0700107type ObjectLinkerProperties struct {
108 // names of other cc_object modules to link into this module using partial linking
109 Objs []string `android:"arch_variant"`
110}
111
Colin Crossca860ac2016-01-04 14:34:37 -0800112// Properties used to compile all C or C++ modules
113type BaseProperties struct {
114 // compile module with clang instead of gcc
115 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700116
117 // Minimum sdk version supported when compiling against the ndk
118 Sdk_version string
119
Colin Crossca860ac2016-01-04 14:34:37 -0800120 // don't insert default compiler flags into asflags, cflags,
121 // cppflags, conlyflags, ldflags, or include_dirs
122 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700123
124 AndroidMkSharedLibs []string `blueprint:"mutated"`
Colin Crossbc6fb162016-05-24 15:39:04 -0700125 HideFromMake bool `blueprint:"mutated"`
Colin Crossb0f28952016-09-19 16:46:53 -0700126 PreventInstall bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800127}
128
Colin Crossca860ac2016-01-04 14:34:37 -0800129type UnusedProperties struct {
Colin Cross21b481b2016-04-15 16:27:17 -0700130 Native_coverage *bool
Colin Cross21b481b2016-04-15 16:27:17 -0700131 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800132}
133
Colin Crossca860ac2016-01-04 14:34:37 -0800134type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800135 static() bool
136 staticBinary() bool
137 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700138 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800139 noDefaultCompilerFlags() bool
140 sdk() bool
141 sdkVersion() string
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700142 selectedStl() string
Colin Crossca860ac2016-01-04 14:34:37 -0800143}
144
145type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700146 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800147 ModuleContextIntf
148}
149
150type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700151 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800152 ModuleContextIntf
153}
154
Colin Crossca860ac2016-01-04 14:34:37 -0800155type feature interface {
156 begin(ctx BaseModuleContext)
157 deps(ctx BaseModuleContext, deps Deps) Deps
158 flags(ctx ModuleContext, flags Flags) Flags
159 props() []interface{}
160}
161
162type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700163 compilerInit(ctx BaseModuleContext)
164 compilerDeps(ctx BaseModuleContext, deps Deps) Deps
165 compilerFlags(ctx ModuleContext, flags Flags) Flags
166 compilerProps() []interface{}
167
Colin Cross76fada02016-07-27 10:31:13 -0700168 appendCflags([]string)
169 appendAsflags([]string)
Colin Cross635c3b02016-05-18 15:37:25 -0700170 compile(ctx ModuleContext, flags Flags, deps PathDeps) android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800171}
172
173type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700174 linkerInit(ctx BaseModuleContext)
175 linkerDeps(ctx BaseModuleContext, deps Deps) Deps
176 linkerFlags(ctx ModuleContext, flags Flags) Flags
177 linkerProps() []interface{}
178
Colin Cross635c3b02016-05-18 15:37:25 -0700179 link(ctx ModuleContext, flags Flags, deps PathDeps, objFiles android.Paths) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700180 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800181}
182
183type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700184 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700185 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800186 inData() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700187 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800188}
189
Colin Crossc99deeb2016-04-11 15:06:20 -0700190type dependencyTag struct {
191 blueprint.BaseDependencyTag
192 name string
193 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700194
195 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700196}
197
198var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700199 sharedDepTag = dependencyTag{name: "shared", library: true}
200 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
201 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
202 staticDepTag = dependencyTag{name: "static", library: true}
203 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
204 lateStaticDepTag = dependencyTag{name: "late static", library: true}
205 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
206 genSourceDepTag = dependencyTag{name: "gen source"}
207 genHeaderDepTag = dependencyTag{name: "gen header"}
208 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
209 objDepTag = dependencyTag{name: "obj"}
210 crtBeginDepTag = dependencyTag{name: "crtbegin"}
211 crtEndDepTag = dependencyTag{name: "crtend"}
212 reuseObjTag = dependencyTag{name: "reuse objects"}
213 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
214 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700215)
216
Colin Crossca860ac2016-01-04 14:34:37 -0800217// Module contains the properties and members used by all C/C++ module types, and implements
218// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
219// to construct the output file. Behavior can be customized with a Customizer interface
220type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700221 android.ModuleBase
222 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700223
Colin Crossca860ac2016-01-04 14:34:37 -0800224 Properties BaseProperties
225 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700226
Colin Crossca860ac2016-01-04 14:34:37 -0800227 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700228 hod android.HostOrDeviceSupported
229 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700230
Colin Crossca860ac2016-01-04 14:34:37 -0800231 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700232 features []feature
233 compiler compiler
234 linker linker
235 installer installer
236 stl *stl
237 sanitize *sanitize
Colin Cross16b23492016-01-06 14:41:07 -0800238
239 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700240
Colin Cross635c3b02016-05-18 15:37:25 -0700241 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800242
Colin Crossb98c8b02016-07-29 13:44:28 -0700243 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700244
245 subAndroidMkOnce map[subAndroidMkProvider]bool
Colin Crossc472d572015-03-17 15:06:21 -0700246}
247
Colin Crossca860ac2016-01-04 14:34:37 -0800248func (c *Module) Init() (blueprint.Module, []interface{}) {
249 props := []interface{}{&c.Properties, &c.unused}
Colin Crossca860ac2016-01-04 14:34:37 -0800250 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700251 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800252 }
253 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700254 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800255 }
256 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700257 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800258 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700259 if c.stl != nil {
260 props = append(props, c.stl.props()...)
261 }
Colin Cross16b23492016-01-06 14:41:07 -0800262 if c.sanitize != nil {
263 props = append(props, c.sanitize.props()...)
264 }
Colin Crossca860ac2016-01-04 14:34:37 -0800265 for _, feature := range c.features {
266 props = append(props, feature.props()...)
267 }
Colin Crossc472d572015-03-17 15:06:21 -0700268
Colin Cross635c3b02016-05-18 15:37:25 -0700269 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700270
Colin Cross635c3b02016-05-18 15:37:25 -0700271 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700272}
273
Colin Crossb916a382016-07-29 17:28:03 -0700274// Returns true for dependency roots (binaries)
275// TODO(ccross): also handle dlopenable libraries
276func (c *Module) isDependencyRoot() bool {
277 if root, ok := c.linker.(interface {
278 isDependencyRoot() bool
279 }); ok {
280 return root.isDependencyRoot()
281 }
282 return false
283}
284
Colin Crossca860ac2016-01-04 14:34:37 -0800285type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700286 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800287 moduleContextImpl
288}
289
290type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700291 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800292 moduleContextImpl
293}
294
295type moduleContextImpl struct {
296 mod *Module
297 ctx BaseModuleContext
298}
299
Colin Crossca860ac2016-01-04 14:34:37 -0800300func (ctx *moduleContextImpl) clang() bool {
301 return ctx.mod.clang(ctx.ctx)
302}
303
Colin Crossb98c8b02016-07-29 13:44:28 -0700304func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800305 return ctx.mod.toolchain(ctx.ctx)
306}
307
308func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700309 if static, ok := ctx.mod.linker.(interface {
310 static() bool
311 }); ok {
312 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800313 }
Colin Crossb916a382016-07-29 17:28:03 -0700314 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800315}
316
317func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700318 if static, ok := ctx.mod.linker.(interface {
319 staticBinary() bool
320 }); ok {
321 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800322 }
Colin Crossb916a382016-07-29 17:28:03 -0700323 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800324}
325
326func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
327 return Bool(ctx.mod.Properties.No_default_compiler_flags)
328}
329
330func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsena96ff642016-06-07 12:34:45 -0700331 if ctx.ctx.Device() {
332 return ctx.mod.Properties.Sdk_version != ""
333 }
334 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800335}
336
337func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700338 if ctx.ctx.Device() {
339 return ctx.mod.Properties.Sdk_version
340 }
341 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800342}
343
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700344func (ctx *moduleContextImpl) selectedStl() string {
345 if stl := ctx.mod.stl; stl != nil {
346 return stl.Properties.SelectedStl
347 }
348 return ""
349}
350
Colin Cross635c3b02016-05-18 15:37:25 -0700351func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800352 return &Module{
353 hod: hod,
354 multilib: multilib,
355 }
356}
357
Colin Cross635c3b02016-05-18 15:37:25 -0700358func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800359 module := newBaseModule(hod, multilib)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700360 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800361 module.sanitize = &sanitize{}
Colin Crossca860ac2016-01-04 14:34:37 -0800362 return module
363}
364
Colin Cross635c3b02016-05-18 15:37:25 -0700365func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800366 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700367 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800368 moduleContextImpl: moduleContextImpl{
369 mod: c,
370 },
371 }
372 ctx.ctx = ctx
373
374 flags := Flags{
375 Toolchain: c.toolchain(ctx),
376 Clang: c.clang(ctx),
377 }
Colin Crossca860ac2016-01-04 14:34:37 -0800378 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700379 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800380 }
381 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700382 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800383 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700384 if c.stl != nil {
385 flags = c.stl.flags(ctx, flags)
386 }
Colin Cross16b23492016-01-06 14:41:07 -0800387 if c.sanitize != nil {
388 flags = c.sanitize.flags(ctx, flags)
389 }
Colin Crossca860ac2016-01-04 14:34:37 -0800390 for _, feature := range c.features {
391 flags = feature.flags(ctx, flags)
392 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800393 if ctx.Failed() {
394 return
395 }
396
Colin Crossb98c8b02016-07-29 13:44:28 -0700397 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
398 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
399 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800400
Colin Crossca860ac2016-01-04 14:34:37 -0800401 // Optimization to reduce size of build.ninja
402 // Replace the long list of flags for each file with a module-local variable
403 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
404 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
405 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
406 flags.CFlags = []string{"$cflags"}
407 flags.CppFlags = []string{"$cppflags"}
408 flags.AsFlags = []string{"$asflags"}
409
Colin Crossc99deeb2016-04-11 15:06:20 -0700410 deps := c.depsToPaths(ctx)
Colin Cross3f40fa42015-01-30 17:27:36 -0800411 if ctx.Failed() {
412 return
413 }
414
Dan Willemsen76f08272016-07-09 00:14:08 -0700415 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Colin Crossed9f8682015-03-18 17:17:35 -0700416
Colin Cross635c3b02016-05-18 15:37:25 -0700417 var objFiles android.Paths
Colin Crossca860ac2016-01-04 14:34:37 -0800418 if c.compiler != nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700419 objFiles = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800420 if ctx.Failed() {
421 return
422 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800423 }
424
Colin Crossca860ac2016-01-04 14:34:37 -0800425 if c.linker != nil {
426 outputFile := c.linker.link(ctx, flags, deps, objFiles)
427 if ctx.Failed() {
428 return
429 }
Colin Cross635c3b02016-05-18 15:37:25 -0700430 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Cross5049f022015-03-18 13:28:46 -0700431
Colin Crossb0f28952016-09-19 16:46:53 -0700432 if c.installer != nil && !c.Properties.PreventInstall {
Colin Crossca860ac2016-01-04 14:34:37 -0800433 c.installer.install(ctx, outputFile)
434 if ctx.Failed() {
435 return
436 }
437 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700438 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800439}
440
Colin Crossb98c8b02016-07-29 13:44:28 -0700441func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800442 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700443 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800444 }
Colin Crossca860ac2016-01-04 14:34:37 -0800445 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800446}
447
Colin Crossca860ac2016-01-04 14:34:37 -0800448func (c *Module) begin(ctx BaseModuleContext) {
449 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700450 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700451 }
Colin Crossca860ac2016-01-04 14:34:37 -0800452 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700453 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800454 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700455 if c.stl != nil {
456 c.stl.begin(ctx)
457 }
Colin Cross16b23492016-01-06 14:41:07 -0800458 if c.sanitize != nil {
459 c.sanitize.begin(ctx)
460 }
Colin Crossca860ac2016-01-04 14:34:37 -0800461 for _, feature := range c.features {
462 feature.begin(ctx)
463 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700464 if ctx.sdk() {
465 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
466 if err != nil {
467 ctx.PropertyErrorf("sdk_version", err.Error())
468 }
469 c.Properties.Sdk_version = strconv.Itoa(version)
470 }
Colin Crossca860ac2016-01-04 14:34:37 -0800471}
472
Colin Crossc99deeb2016-04-11 15:06:20 -0700473func (c *Module) deps(ctx BaseModuleContext) Deps {
474 deps := Deps{}
475
476 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700477 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700478 }
479 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700480 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700481 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700482 if c.stl != nil {
483 deps = c.stl.deps(ctx, deps)
484 }
Colin Cross16b23492016-01-06 14:41:07 -0800485 if c.sanitize != nil {
486 deps = c.sanitize.deps(ctx, deps)
487 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700488 for _, feature := range c.features {
489 deps = feature.deps(ctx, deps)
490 }
491
492 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
493 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
494 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
495 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
496 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
497
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700498 for _, lib := range deps.ReexportSharedLibHeaders {
499 if !inList(lib, deps.SharedLibs) {
500 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
501 }
502 }
503
504 for _, lib := range deps.ReexportStaticLibHeaders {
505 if !inList(lib, deps.StaticLibs) {
506 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
507 }
508 }
509
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700510 for _, gen := range deps.ReexportGeneratedHeaders {
511 if !inList(gen, deps.GeneratedHeaders) {
512 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
513 }
514 }
515
Colin Crossc99deeb2016-04-11 15:06:20 -0700516 return deps
517}
518
Dan Albert7e9d2952016-08-04 13:02:36 -0700519func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800520 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700521 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800522 moduleContextImpl: moduleContextImpl{
523 mod: c,
524 },
525 }
526 ctx.ctx = ctx
527
Colin Crossca860ac2016-01-04 14:34:37 -0800528 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700529}
530
531func (c *Module) depsMutator(actx android.BottomUpMutatorContext) {
532 ctx := &baseModuleContext{
533 BaseContext: actx,
534 moduleContextImpl: moduleContextImpl{
535 mod: c,
536 },
537 }
538 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800539
Colin Crossc99deeb2016-04-11 15:06:20 -0700540 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800541
Colin Crossb5bc4b42016-07-11 16:11:59 -0700542 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
543 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700544
Dan Albert914449f2016-06-17 16:45:24 -0700545 variantNdkLibs := []string{}
546 variantLateNdkLibs := []string{}
Dan Willemsen72d39932016-07-08 23:23:48 -0700547 if ctx.sdk() {
Dan Albert914449f2016-06-17 16:45:24 -0700548 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700549
Dan Albert914449f2016-06-17 16:45:24 -0700550 // Rewrites the names of shared libraries into the names of the NDK
551 // libraries where appropriate. This returns two slices.
552 //
553 // The first is a list of non-variant shared libraries (either rewritten
554 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
555 // because they are not NDK libraries).
556 //
557 // The second is a list of ndk_library modules. These need to be
558 // separated because they are a variation dependency and must be added
559 // in a different manner.
560 rewriteNdkLibs := func(list []string) ([]string, []string) {
561 variantLibs := []string{}
562 nonvariantLibs := []string{}
563 for _, entry := range list {
Dan Willemsen72d39932016-07-08 23:23:48 -0700564 if inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700565 if !inList(entry, ndkMigratedLibs) {
566 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
567 } else {
568 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
569 }
570 } else {
571 nonvariantLibs = append(variantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700572 }
573 }
Dan Albert914449f2016-06-17 16:45:24 -0700574 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700575 }
576
Dan Albert914449f2016-06-17 16:45:24 -0700577 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
578 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700579 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700580
581 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
582 deps.WholeStaticLibs...)
583
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700584 for _, lib := range deps.StaticLibs {
585 depTag := staticDepTag
586 if inList(lib, deps.ReexportStaticLibHeaders) {
587 depTag = staticExportDepTag
588 }
Colin Cross15a0d462016-07-14 14:49:58 -0700589 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700590 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700591
592 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
593 deps.LateStaticLibs...)
594
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700595 for _, lib := range deps.SharedLibs {
596 depTag := sharedDepTag
597 if inList(lib, deps.ReexportSharedLibHeaders) {
598 depTag = sharedExportDepTag
599 }
Colin Cross15a0d462016-07-14 14:49:58 -0700600 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700601 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700602
603 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
604 deps.LateSharedLibs...)
605
Colin Cross68861832016-07-08 10:41:41 -0700606 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700607
608 for _, gen := range deps.GeneratedHeaders {
609 depTag := genHeaderDepTag
610 if inList(gen, deps.ReexportGeneratedHeaders) {
611 depTag = genHeaderExportDepTag
612 }
613 actx.AddDependency(c, depTag, gen)
614 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700615
Colin Cross68861832016-07-08 10:41:41 -0700616 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700617
618 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700619 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800620 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700621 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700622 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700623 }
Dan Albert914449f2016-06-17 16:45:24 -0700624
625 version := ctx.sdkVersion()
626 actx.AddVariationDependencies([]blueprint.Variation{
627 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
628 actx.AddVariationDependencies([]blueprint.Variation{
629 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700630}
Colin Cross21b9a242015-03-24 14:15:58 -0700631
Dan Albert7e9d2952016-08-04 13:02:36 -0700632func beginMutator(ctx android.BottomUpMutatorContext) {
633 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
634 c.beginMutator(ctx)
635 }
636}
637
Colin Cross635c3b02016-05-18 15:37:25 -0700638func depsMutator(ctx android.BottomUpMutatorContext) {
Dan Willemsen3f32f032016-07-11 14:36:48 -0700639 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
Colin Cross6362e272015-10-29 15:25:03 -0700640 c.depsMutator(ctx)
641 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800642}
643
Colin Crossca860ac2016-01-04 14:34:37 -0800644func (c *Module) clang(ctx BaseModuleContext) bool {
645 clang := Bool(c.Properties.Clang)
646
647 if c.Properties.Clang == nil {
648 if ctx.Host() {
649 clang = true
650 }
651
652 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
653 clang = true
654 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800655 }
Colin Cross28344522015-04-22 13:07:53 -0700656
Colin Crossca860ac2016-01-04 14:34:37 -0800657 if !c.toolchain(ctx).ClangSupported() {
658 clang = false
659 }
660
661 return clang
662}
663
Colin Crossc99deeb2016-04-11 15:06:20 -0700664// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700665func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800666 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800667
Dan Willemsena96ff642016-06-07 12:34:45 -0700668 // Whether a module can link to another module, taking into
669 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700670 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700671 if from.Target().Os != android.Android {
672 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700673 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700674 }
675 if from.Properties.Sdk_version == "" {
676 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700677 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700678 }
Colin Crossb916a382016-07-29 17:28:03 -0700679 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700680 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700681 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700682 }
683 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
684 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700685 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700686 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700687 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
688 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700689 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700690 }
Colin Crossb916a382016-07-29 17:28:03 -0700691 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700692 // These aren't real libraries, but are the stub shared libraries that are included in
693 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700694 return
Dan Albert914449f2016-06-17 16:45:24 -0700695 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700696 if to.Properties.Sdk_version == "" {
697 // NDK code linking to platform code is never okay.
698 ctx.ModuleErrorf("depends on non-NDK-built library %q",
699 ctx.OtherModuleName(to))
700 }
701
702 // All this point we know we have two NDK libraries, but we need to
703 // check that we're not linking against anything built against a higher
704 // API level, as it is only valid to link against older or equivalent
705 // APIs.
706
707 if from.Properties.Sdk_version == "current" {
708 // Current can link against anything.
709 return
710 } else if to.Properties.Sdk_version == "current" {
711 // Current can't be linked against by anything else.
712 ctx.ModuleErrorf("links %q built against newer API version %q",
713 ctx.OtherModuleName(to), "current")
714 }
715
716 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
717 if err != nil {
718 ctx.PropertyErrorf("sdk_version",
719 "Invalid sdk_version value (must be int): %q",
720 from.Properties.Sdk_version)
721 }
722 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
723 if err != nil {
724 ctx.PropertyErrorf("sdk_version",
725 "Invalid sdk_version value (must be int): %q",
726 to.Properties.Sdk_version)
727 }
728
729 if toApi > fromApi {
730 ctx.ModuleErrorf("links %q built against newer API version %q",
731 ctx.OtherModuleName(to), to.Properties.Sdk_version)
732 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700733 }
734
Colin Crossc99deeb2016-04-11 15:06:20 -0700735 ctx.VisitDirectDeps(func(m blueprint.Module) {
736 name := ctx.OtherModuleName(m)
737 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800738
Colin Cross635c3b02016-05-18 15:37:25 -0700739 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700740 if a == nil {
741 ctx.ModuleErrorf("module %q not an android module", name)
742 return
Colin Crossca860ac2016-01-04 14:34:37 -0800743 }
Colin Crossca860ac2016-01-04 14:34:37 -0800744
Dan Willemsena96ff642016-06-07 12:34:45 -0700745 cc, _ := m.(*Module)
746 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700747 switch tag {
Colin Cross635c3b02016-05-18 15:37:25 -0700748 case android.DefaultsDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700749 case genSourceDepTag:
750 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
751 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
752 genRule.GeneratedSourceFiles()...)
753 } else {
754 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
755 }
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700756 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700757 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
758 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
759 genRule.GeneratedSourceFiles()...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700760 flags := includeDirsToFlags(android.Paths{genRule.GeneratedHeaderDir()})
761 depPaths.Flags = append(depPaths.Flags, flags)
762 if tag == genHeaderExportDepTag {
763 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700764 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
765 genRule.GeneratedSourceFiles()...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700766 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700767 } else {
768 ctx.ModuleErrorf("module %q is not a genrule", name)
769 }
770 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700771 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800772 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700773 return
774 }
775
776 if !a.Enabled() {
777 ctx.ModuleErrorf("depends on disabled module %q", name)
778 return
779 }
780
Colin Crossa1ad8d12016-06-01 17:09:44 -0700781 if a.Target().Os != ctx.Os() {
782 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
783 return
784 }
785
786 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
787 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700788 return
789 }
790
Dan Willemsena96ff642016-06-07 12:34:45 -0700791 if !cc.outputFile.Valid() {
Colin Crossc99deeb2016-04-11 15:06:20 -0700792 ctx.ModuleErrorf("module %q missing output file", name)
793 return
794 }
795
796 if tag == reuseObjTag {
797 depPaths.ObjFiles = append(depPaths.ObjFiles,
Colin Crossb916a382016-07-29 17:28:03 -0700798 cc.compiler.(libraryInterface).reuseObjs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700799 return
800 }
801
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700802 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700803 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700804 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -0700805 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -0700806 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700807 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700808
809 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700810 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700811 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700812 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700813 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700814
Dan Albert9e10cd42016-08-03 14:12:14 -0700815 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700816 }
817
Colin Cross635c3b02016-05-18 15:37:25 -0700818 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700819
820 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700821 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700822 depPtr = &depPaths.SharedLibs
Dan Albert914449f2016-06-17 16:45:24 -0700823 case lateSharedDepTag, ndkLateStubDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700824 depPtr = &depPaths.LateSharedLibs
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700825 case staticDepTag, staticExportDepTag:
Colin Crossc99deeb2016-04-11 15:06:20 -0700826 depPtr = &depPaths.StaticLibs
827 case lateStaticDepTag:
828 depPtr = &depPaths.LateStaticLibs
829 case wholeStaticDepTag:
830 depPtr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -0700831 staticLib, ok := cc.linker.(libraryInterface)
832 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700833 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700834 return
835 }
836
837 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
838 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
839 for i := range missingDeps {
840 missingDeps[i] += postfix
841 }
842 ctx.AddMissingDependencies(missingDeps)
843 }
844 depPaths.WholeStaticLibObjFiles =
Colin Crossc7a38dc2016-07-12 13:13:09 -0700845 append(depPaths.WholeStaticLibObjFiles, staticLib.objs()...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700846 case objDepTag:
847 depPtr = &depPaths.ObjFiles
848 case crtBeginDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700849 depPaths.CrtBegin = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700850 case crtEndDepTag:
Dan Willemsena96ff642016-06-07 12:34:45 -0700851 depPaths.CrtEnd = cc.outputFile
Colin Crossc99deeb2016-04-11 15:06:20 -0700852 default:
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700853 panic(fmt.Errorf("unknown dependency tag: %s", tag))
Colin Crossc99deeb2016-04-11 15:06:20 -0700854 }
855
856 if depPtr != nil {
Dan Willemsena96ff642016-06-07 12:34:45 -0700857 *depPtr = append(*depPtr, cc.outputFile.Path())
Colin Crossca860ac2016-01-04 14:34:37 -0800858 }
859 })
860
861 return depPaths
862}
863
864func (c *Module) InstallInData() bool {
865 if c.installer == nil {
866 return false
867 }
Colin Cross94610402016-08-29 13:41:32 -0700868 if c.sanitize != nil && c.sanitize.inData() {
869 return true
870 }
Colin Crossca860ac2016-01-04 14:34:37 -0800871 return c.installer.inData()
872}
873
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700874func (c *Module) HostToolPath() android.OptionalPath {
875 if c.installer == nil {
876 return android.OptionalPath{}
877 }
878 return c.installer.hostToolPath()
879}
880
Colin Cross2ba19d92015-05-07 15:44:20 -0700881//
Colin Crosscfad1192015-11-02 16:43:11 -0800882// Defaults
883//
Colin Crossca860ac2016-01-04 14:34:37 -0800884type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700885 android.ModuleBase
886 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -0800887}
888
Colin Cross635c3b02016-05-18 15:37:25 -0700889func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -0800890}
891
Colin Crossca860ac2016-01-04 14:34:37 -0800892func defaultsFactory() (blueprint.Module, []interface{}) {
Colin Crosse1d764e2016-08-18 14:18:32 -0700893 return DefaultsFactory()
894}
895
896func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
Colin Crossca860ac2016-01-04 14:34:37 -0800897 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -0800898
Colin Crosse1d764e2016-08-18 14:18:32 -0700899 props = append(props,
Colin Crossca860ac2016-01-04 14:34:37 -0800900 &BaseProperties{},
901 &BaseCompilerProperties{},
902 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700903 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -0700904 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800905 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -0700906 &TestProperties{},
907 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -0800908 &UnusedProperties{},
909 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -0800910 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -0700911 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -0700912 &InstallerProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -0700913 )
Colin Crosscfad1192015-11-02 16:43:11 -0800914
Colin Crosse1d764e2016-08-18 14:18:32 -0700915 _, props = android.InitAndroidArchModule(module, android.HostAndDeviceDefault,
916 android.MultilibDefault, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800917
Colin Crosse1d764e2016-08-18 14:18:32 -0700918 return android.InitDefaultsModule(module, module, props...)
Colin Crosscfad1192015-11-02 16:43:11 -0800919}
920
Colin Cross74d1ec02015-04-28 13:30:13 -0700921// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
922// modifies the slice contents in place, and returns a subslice of the original slice
923func lastUniqueElements(list []string) []string {
924 totalSkip := 0
925 for i := len(list) - 1; i >= totalSkip; i-- {
926 skip := 0
927 for j := i - 1; j >= totalSkip; j-- {
928 if list[i] == list[j] {
929 skip++
930 } else {
931 list[j+skip] = list[j]
932 }
933 }
934 totalSkip += skip
935 }
936 return list[totalSkip:]
937}
Colin Cross06a931b2015-10-28 17:23:31 -0700938
939var Bool = proptools.Bool