blob: 891dccb05d79605cbfea6dc5b9df630ed098ed88 [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 (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Park6a43f042017-10-12 23:05:00 +090037 ctx.BottomUp("image", vendorMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070038 ctx.BottomUp("link", linkageMutator).Parallel()
Jiyong Parkd5b18a52017-08-03 21:22:50 +090039 ctx.BottomUp("vndk", vndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
42 ctx.BottomUp("begin", beginMutator).Parallel()
43 })
Colin Cross16b23492016-01-06 14:41:07 -080044
Colin Cross1e676be2016-10-12 14:38:15 -070045 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
46 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
47 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080048
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000049 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
50 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
51
Colin Cross1e676be2016-10-12 14:38:15 -070052 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
53 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080054
55 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080056 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070057
58 ctx.TopDown("lto_deps", ltoDepsMutator)
59 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070060 })
Colin Crossb98c8b02016-07-29 13:44:28 -070061
62 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070063}
64
Colin Crossca860ac2016-01-04 14:34:37 -080065type Deps struct {
66 SharedLibs, LateSharedLibs []string
67 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080068 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070069
Colin Cross5950f382016-12-13 12:50:57 -080070 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070071
Colin Cross81413472016-04-11 14:37:39 -070072 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070073
Dan Willemsenb40aab62016-04-20 14:21:14 -070074 GeneratedSources []string
75 GeneratedHeaders []string
76
Dan Willemsenb3454ab2016-09-28 17:34:58 -070077 ReexportGeneratedHeaders []string
78
Colin Cross97ba0732015-03-23 17:50:24 -070079 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070080 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070081}
82
Colin Crossca860ac2016-01-04 14:34:37 -080083type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070084 // Paths to .so files
85 SharedLibs, LateSharedLibs android.Paths
86 // Paths to the dependencies to use for .so files (.so.toc files)
87 SharedLibsDeps, LateSharedLibsDeps android.Paths
88 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070089 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070090
Colin Cross26c34ed2016-09-30 17:10:16 -070091 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070092 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080093 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070094 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Colin Cross26c34ed2016-09-30 17:10:16 -070096 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070097 GeneratedSources android.Paths
98 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070099
Dan Willemsen76f08272016-07-09 00:14:08 -0700100 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700101 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700102
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700104 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700105 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700109 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
110 ArFlags []string // Flags that apply to ar
111 AsFlags []string // Flags that apply to assembly source files
112 CFlags []string // Flags that apply to C and C++ source files
113 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
114 ConlyFlags []string // Flags that apply to C source files
115 CppFlags []string // Flags that apply to C++ source files
116 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
117 YaccFlags []string // Flags that apply to Yacc source files
118 protoFlags []string // Flags that apply to proto source files
119 aidlFlags []string // Flags that apply to aidl source files
120 rsFlags []string // Flags that apply to renderscript source files
121 LdFlags []string // Flags that apply to linker command lines
122 libFlags []string // Flags to add libraries early to the link order
123 TidyFlags []string // Flags that apply to clang-tidy
124 SAbiFlags []string // Flags that apply to header-abi-dumper
125 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700126
Colin Crossc3199482017-03-30 15:03:04 -0700127 // Global include flags that apply to C, C++, and assembly source files
128 // These must be after any module include flags, which will be in GlobalFlags.
129 SystemIncludeFlags []string
130
Colin Crossb98c8b02016-07-29 13:44:28 -0700131 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700132 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700133 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800134 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800135 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800136
137 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800138 DynamicLinker string
139
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700140 CFlagsDeps android.Paths // Files depended on by compiler flags
141 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800142
143 GroupStaticLibs bool
Colin Crossc472d572015-03-17 15:06:21 -0700144}
145
Colin Cross81413472016-04-11 14:37:39 -0700146type ObjectLinkerProperties struct {
147 // names of other cc_object modules to link into this module using partial linking
148 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700149
150 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800151 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700152}
153
Colin Crossca860ac2016-01-04 14:34:37 -0800154// Properties used to compile all C or C++ modules
155type BaseProperties struct {
156 // compile module with clang instead of gcc
157 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700158
159 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800160 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700161
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700162 AndroidMkSharedLibs []string `blueprint:"mutated"`
163 HideFromMake bool `blueprint:"mutated"`
164 PreventInstall bool `blueprint:"mutated"`
165
166 UseVndk bool `blueprint:"mutated"`
167}
168
169type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900170 // whether this module should be allowed to be directly depended by other
171 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
172 // If set to true, two variants will be built separately, one like
173 // normal, and the other limited to the set of libraries and headers
174 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700175 //
176 // The vendor variant may be used with a different (newer) /system,
177 // so it shouldn't have any unversioned runtime dependencies, or
178 // make assumptions about the system that may not be true in the
179 // future.
180 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900181 // If set to false, this module becomes inaccessible from /vendor modules.
182 //
183 // Default value is true when vndk: {enabled: true} or vendor: true.
184 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700185 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
186 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800187}
188
Colin Crossca860ac2016-01-04 14:34:37 -0800189type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800190 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800191}
192
Colin Crossca860ac2016-01-04 14:34:37 -0800193type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800194 static() bool
195 staticBinary() bool
196 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700197 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700198 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800199 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700200 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900201 isVndk() bool
202 isVndkSp() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800203 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700204 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700205 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800206}
207
208type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700209 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800210 ModuleContextIntf
211}
212
213type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700214 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800215 ModuleContextIntf
216}
217
Colin Cross37047f12016-12-13 17:06:13 -0800218type DepsContext interface {
219 android.BottomUpMutatorContext
220 ModuleContextIntf
221}
222
Colin Crossca860ac2016-01-04 14:34:37 -0800223type feature interface {
224 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800225 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800226 flags(ctx ModuleContext, flags Flags) Flags
227 props() []interface{}
228}
229
230type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700231 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800232 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800233 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700234 compilerProps() []interface{}
235
Colin Cross76fada02016-07-27 10:31:13 -0700236 appendCflags([]string)
237 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700238 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800239}
240
241type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700242 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800243 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700244 linkerFlags(ctx ModuleContext, flags Flags) Flags
245 linkerProps() []interface{}
246
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700247 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700248 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800249}
250
251type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700252 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700253 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800254 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700255 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700256 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800257}
258
Colin Crossc99deeb2016-04-11 15:06:20 -0700259type dependencyTag struct {
260 blueprint.BaseDependencyTag
261 name string
262 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700263
264 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700265}
266
267var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700268 sharedDepTag = dependencyTag{name: "shared", library: true}
269 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
270 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
271 staticDepTag = dependencyTag{name: "static", library: true}
272 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
273 lateStaticDepTag = dependencyTag{name: "late static", library: true}
274 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800275 headerDepTag = dependencyTag{name: "header", library: true}
276 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700277 genSourceDepTag = dependencyTag{name: "gen source"}
278 genHeaderDepTag = dependencyTag{name: "gen header"}
279 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
280 objDepTag = dependencyTag{name: "obj"}
281 crtBeginDepTag = dependencyTag{name: "crtbegin"}
282 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700283 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700284 reuseObjTag = dependencyTag{name: "reuse objects"}
285 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
286 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700287)
288
Colin Crossca860ac2016-01-04 14:34:37 -0800289// Module contains the properties and members used by all C/C++ module types, and implements
290// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
291// to construct the output file. Behavior can be customized with a Customizer interface
292type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700293 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700294 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700295
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700296 Properties BaseProperties
297 VendorProperties VendorProperties
298 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700299
Colin Crossca860ac2016-01-04 14:34:37 -0800300 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700301 hod android.HostOrDeviceSupported
302 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700303
Colin Crossca860ac2016-01-04 14:34:37 -0800304 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700305 features []feature
306 compiler compiler
307 linker linker
308 installer installer
309 stl *stl
310 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800311 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800312 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900313 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700314 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700315 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800316
317 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700318
Colin Cross635c3b02016-05-18 15:37:25 -0700319 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800320
Colin Crossb98c8b02016-07-29 13:44:28 -0700321 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700322
323 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800324
325 // Flags used to compile this module
326 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700327
328 // When calling a linker, if module A depends on module B, then A must precede B in its command
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800329 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700330 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800331 depsInLinkOrder android.Paths
332
333 // only non-nil when this is a shared library that reuses the objects of a static library
334 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700335}
336
Colin Cross36242852017-06-23 15:06:31 -0700337func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700338 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800339 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700340 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800341 }
342 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700343 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800344 }
345 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700346 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800347 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700348 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700349 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700350 }
Colin Cross16b23492016-01-06 14:41:07 -0800351 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700352 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800353 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800354 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700355 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800356 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800357 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700358 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800359 }
Justin Yun8effde42017-06-23 19:24:43 +0900360 if c.vndkdep != nil {
361 c.AddProperties(c.vndkdep.props()...)
362 }
Stephen Craneba090d12017-05-09 15:44:35 -0700363 if c.lto != nil {
364 c.AddProperties(c.lto.props()...)
365 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700366 if c.pgo != nil {
367 c.AddProperties(c.pgo.props()...)
368 }
Colin Crossca860ac2016-01-04 14:34:37 -0800369 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700370 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800371 }
Colin Crossc472d572015-03-17 15:06:21 -0700372
Colin Cross36242852017-06-23 15:06:31 -0700373 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700374
Colin Cross1f44a3a2017-07-07 14:33:33 -0700375 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700376
377 return c
Colin Crossc472d572015-03-17 15:06:21 -0700378}
379
Colin Crossb916a382016-07-29 17:28:03 -0700380// Returns true for dependency roots (binaries)
381// TODO(ccross): also handle dlopenable libraries
382func (c *Module) isDependencyRoot() bool {
383 if root, ok := c.linker.(interface {
384 isDependencyRoot() bool
385 }); ok {
386 return root.isDependencyRoot()
387 }
388 return false
389}
390
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700391func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700392 return c.Properties.UseVndk
393}
394
Justin Yun8effde42017-06-23 19:24:43 +0900395func (c *Module) isVndk() bool {
396 if c.vndkdep != nil {
397 return c.vndkdep.isVndk()
398 }
399 return false
400}
401
Jiyong Park82e2bf32017-08-16 14:05:54 +0900402// Returns true only when this module is configured to have core and vendor
403// variants.
404func (c *Module) hasVendorVariant() bool {
405 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
406}
407
Colin Crossca860ac2016-01-04 14:34:37 -0800408type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700409 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800410 moduleContextImpl
411}
412
Colin Cross37047f12016-12-13 17:06:13 -0800413type depsContext struct {
414 android.BottomUpMutatorContext
415 moduleContextImpl
416}
417
Colin Crossca860ac2016-01-04 14:34:37 -0800418type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700419 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800420 moduleContextImpl
421}
422
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700423func (ctx *moduleContext) InstallOnVendorPartition() bool {
424 return ctx.ModuleContext.InstallOnVendorPartition() || (ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700425}
426
Colin Crossca860ac2016-01-04 14:34:37 -0800427type moduleContextImpl struct {
428 mod *Module
429 ctx BaseModuleContext
430}
431
Colin Crossca860ac2016-01-04 14:34:37 -0800432func (ctx *moduleContextImpl) clang() bool {
433 return ctx.mod.clang(ctx.ctx)
434}
435
Colin Crossb98c8b02016-07-29 13:44:28 -0700436func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800437 return ctx.mod.toolchain(ctx.ctx)
438}
439
440func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000441 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800442}
443
444func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700445 if static, ok := ctx.mod.linker.(interface {
446 staticBinary() bool
447 }); ok {
448 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800449 }
Colin Crossb916a382016-07-29 17:28:03 -0700450 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800451}
452
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700453func (ctx *moduleContextImpl) useSdk() bool {
454 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800455 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700456 }
457 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800458}
459
460func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700461 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700462 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700463 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800464 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800465 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800466 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700467 }
468 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800469}
470
Justin Yun8effde42017-06-23 19:24:43 +0900471func (ctx *moduleContextImpl) isVndk() bool {
472 return ctx.mod.isVndk()
473}
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700474func (ctx *moduleContextImpl) useVndk() bool {
475 return ctx.mod.useVndk()
476}
Justin Yun8effde42017-06-23 19:24:43 +0900477
478func (ctx *moduleContextImpl) isVndkSp() bool {
479 if vndk := ctx.mod.vndkdep; vndk != nil {
480 return vndk.isVndkSp()
481 }
482 return false
483}
484
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800485// Create source abi dumps if the module belongs to the list of VndkLibraries.
486func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700487 return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800488}
489
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700490func (ctx *moduleContextImpl) selectedStl() string {
491 if stl := ctx.mod.stl; stl != nil {
492 return stl.Properties.SelectedStl
493 }
494 return ""
495}
496
Colin Crossce75d2c2016-10-06 16:12:58 -0700497func (ctx *moduleContextImpl) baseModuleName() string {
498 return ctx.mod.ModuleBase.BaseModuleName()
499}
500
Colin Cross635c3b02016-05-18 15:37:25 -0700501func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800502 return &Module{
503 hod: hod,
504 multilib: multilib,
505 }
506}
507
Colin Cross635c3b02016-05-18 15:37:25 -0700508func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800509 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700510 module.features = []feature{
511 &tidyFeature{},
512 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700513 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800514 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800515 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800516 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900517 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700518 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700519 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800520 return module
521}
522
Colin Crossce75d2c2016-10-06 16:12:58 -0700523func (c *Module) Prebuilt() *android.Prebuilt {
524 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
525 return p.prebuilt()
526 }
527 return nil
528}
529
530func (c *Module) Name() string {
531 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700532 if p, ok := c.linker.(interface {
533 Name(string) string
534 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700535 name = p.Name(name)
536 }
537 return name
538}
539
Jeff Gaston294356f2017-09-27 17:05:30 -0700540// orderDeps reorders dependencies into a list such that if module A depends on B, then
541// A will precede B in the resultant list.
542// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800543// Note that directSharedDeps should be the analogous static library for each shared lib dep
544func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) {
Jeff Gaston294356f2017-09-27 17:05:30 -0700545 // If A depends on B, then
546 // Every list containing A will also contain B later in the list
547 // So, after concatenating all lists, the final instance of B will have come from the same
548 // original list as the final instance of A
549 // So, the final instance of B will be later in the concatenation than the final A
550 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
551 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800552 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700553 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800554 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
555 }
556 for _, dep := range directSharedDeps {
557 orderedAllDeps = append(orderedAllDeps, dep)
558 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700559 }
560
Colin Crossb6715442017-10-24 11:13:31 -0700561 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700562
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800563 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700564 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800565 // resultant list to only what the caller has chosen to include in directStaticDeps
566 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700567
568 return orderedAllDeps, orderedDeclaredDeps
569}
570
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800571func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
572 // convert Module to Path
573 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
574 staticDepFiles := []android.Path{}
575 for _, dep := range staticDeps {
576 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
577 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700578 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800579 sharedDepFiles := []android.Path{}
580 for _, sharedDep := range sharedDeps {
581 staticAnalogue := sharedDep.staticVariant
582 if staticAnalogue != nil {
583 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
584 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
585 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700586 }
587
588 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800589 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700590
591 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700592}
593
Colin Cross635c3b02016-05-18 15:37:25 -0700594func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700595
Colin Crossca860ac2016-01-04 14:34:37 -0800596 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700597 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800598 moduleContextImpl: moduleContextImpl{
599 mod: c,
600 },
601 }
602 ctx.ctx = ctx
603
Colin Crossf18e1102017-11-16 14:33:08 -0800604 deps := c.depsToPaths(ctx)
605 if ctx.Failed() {
606 return
607 }
608
Colin Crossca860ac2016-01-04 14:34:37 -0800609 flags := Flags{
610 Toolchain: c.toolchain(ctx),
611 Clang: c.clang(ctx),
612 }
Colin Crossca860ac2016-01-04 14:34:37 -0800613 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800614 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800615 }
616 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700617 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800618 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700619 if c.stl != nil {
620 flags = c.stl.flags(ctx, flags)
621 }
Colin Cross16b23492016-01-06 14:41:07 -0800622 if c.sanitize != nil {
623 flags = c.sanitize.flags(ctx, flags)
624 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800625 if c.coverage != nil {
626 flags = c.coverage.flags(ctx, flags)
627 }
Stephen Craneba090d12017-05-09 15:44:35 -0700628 if c.lto != nil {
629 flags = c.lto.flags(ctx, flags)
630 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700631 if c.pgo != nil {
632 flags = c.pgo.flags(ctx, flags)
633 }
Colin Crossca860ac2016-01-04 14:34:37 -0800634 for _, feature := range c.features {
635 flags = feature.flags(ctx, flags)
636 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800637 if ctx.Failed() {
638 return
639 }
640
Colin Crossb98c8b02016-07-29 13:44:28 -0700641 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
642 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
643 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800644
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800645 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
646 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700647 // We need access to all the flags seen by a source file.
648 if c.sabi != nil {
649 flags = c.sabi.flags(ctx, flags)
650 }
Colin Crossca860ac2016-01-04 14:34:37 -0800651 // Optimization to reduce size of build.ninja
652 // Replace the long list of flags for each file with a module-local variable
653 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
654 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
655 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
656 flags.CFlags = []string{"$cflags"}
657 flags.CppFlags = []string{"$cppflags"}
658 flags.AsFlags = []string{"$asflags"}
659
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700660 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800661 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700662 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800663 if ctx.Failed() {
664 return
665 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800666 }
667
Colin Crossca860ac2016-01-04 14:34:37 -0800668 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700669 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800670 if ctx.Failed() {
671 return
672 }
Colin Cross635c3b02016-05-18 15:37:25 -0700673 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700674 }
Colin Cross5049f022015-03-18 13:28:46 -0700675
Colin Crossce75d2c2016-10-06 16:12:58 -0700676 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
677 c.installer.install(ctx, c.outputFile.Path())
678 if ctx.Failed() {
679 return
Colin Crossca860ac2016-01-04 14:34:37 -0800680 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700681 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800682}
683
Colin Crossb98c8b02016-07-29 13:44:28 -0700684func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800685 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700686 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800687 }
Colin Crossca860ac2016-01-04 14:34:37 -0800688 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800689}
690
Colin Crossca860ac2016-01-04 14:34:37 -0800691func (c *Module) begin(ctx BaseModuleContext) {
692 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700693 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700694 }
Colin Crossca860ac2016-01-04 14:34:37 -0800695 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700696 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800697 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700698 if c.stl != nil {
699 c.stl.begin(ctx)
700 }
Colin Cross16b23492016-01-06 14:41:07 -0800701 if c.sanitize != nil {
702 c.sanitize.begin(ctx)
703 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800704 if c.coverage != nil {
705 c.coverage.begin(ctx)
706 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800707 if c.sabi != nil {
708 c.sabi.begin(ctx)
709 }
Justin Yun8effde42017-06-23 19:24:43 +0900710 if c.vndkdep != nil {
711 c.vndkdep.begin(ctx)
712 }
Stephen Craneba090d12017-05-09 15:44:35 -0700713 if c.lto != nil {
714 c.lto.begin(ctx)
715 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700716 if c.pgo != nil {
717 c.pgo.begin(ctx)
718 }
Colin Crossca860ac2016-01-04 14:34:37 -0800719 for _, feature := range c.features {
720 feature.begin(ctx)
721 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700722 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700723 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700724 if err != nil {
725 ctx.PropertyErrorf("sdk_version", err.Error())
726 }
Nan Zhang0007d812017-11-07 10:57:05 -0800727 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700728 }
Colin Crossca860ac2016-01-04 14:34:37 -0800729}
730
Colin Cross37047f12016-12-13 17:06:13 -0800731func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700732 deps := Deps{}
733
734 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700735 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700736 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700737 // Add the PGO dependency (the clang_rt.profile runtime library), which
738 // sometimes depends on symbols from libgcc, before libgcc gets added
739 // in linkerDeps().
740 if c.pgo != nil {
741 deps = c.pgo.deps(ctx, deps)
742 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700743 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700744 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700745 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700746 if c.stl != nil {
747 deps = c.stl.deps(ctx, deps)
748 }
Colin Cross16b23492016-01-06 14:41:07 -0800749 if c.sanitize != nil {
750 deps = c.sanitize.deps(ctx, deps)
751 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800752 if c.coverage != nil {
753 deps = c.coverage.deps(ctx, deps)
754 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800755 if c.sabi != nil {
756 deps = c.sabi.deps(ctx, deps)
757 }
Justin Yun8effde42017-06-23 19:24:43 +0900758 if c.vndkdep != nil {
759 deps = c.vndkdep.deps(ctx, deps)
760 }
Stephen Craneba090d12017-05-09 15:44:35 -0700761 if c.lto != nil {
762 deps = c.lto.deps(ctx, deps)
763 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700764 for _, feature := range c.features {
765 deps = feature.deps(ctx, deps)
766 }
767
Colin Crossb6715442017-10-24 11:13:31 -0700768 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
769 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
770 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
771 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
772 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
773 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700774
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700775 for _, lib := range deps.ReexportSharedLibHeaders {
776 if !inList(lib, deps.SharedLibs) {
777 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
778 }
779 }
780
781 for _, lib := range deps.ReexportStaticLibHeaders {
782 if !inList(lib, deps.StaticLibs) {
783 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
784 }
785 }
786
Colin Cross5950f382016-12-13 12:50:57 -0800787 for _, lib := range deps.ReexportHeaderLibHeaders {
788 if !inList(lib, deps.HeaderLibs) {
789 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
790 }
791 }
792
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700793 for _, gen := range deps.ReexportGeneratedHeaders {
794 if !inList(gen, deps.GeneratedHeaders) {
795 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
796 }
797 }
798
Colin Crossc99deeb2016-04-11 15:06:20 -0700799 return deps
800}
801
Dan Albert7e9d2952016-08-04 13:02:36 -0700802func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800803 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700804 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800805 moduleContextImpl: moduleContextImpl{
806 mod: c,
807 },
808 }
809 ctx.ctx = ctx
810
Colin Crossca860ac2016-01-04 14:34:37 -0800811 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700812}
813
Colin Cross1e676be2016-10-12 14:38:15 -0700814func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
815 if !c.Enabled() {
816 return
817 }
818
Colin Cross37047f12016-12-13 17:06:13 -0800819 ctx := &depsContext{
820 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700821 moduleContextImpl: moduleContextImpl{
822 mod: c,
823 },
824 }
825 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800826
Colin Crossc99deeb2016-04-11 15:06:20 -0700827 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800828
Dan Albert914449f2016-06-17 16:45:24 -0700829 variantNdkLibs := []string{}
830 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700831 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700832 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700833
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700834 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
835 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700836 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700837 // 1. Name of an NDK library that refers to a prebuilt module.
838 // For each of these, it adds the name of the prebuilt module (which will be in
839 // prebuilts/ndk) to the list of nonvariant libs.
840 // 2. Name of an NDK library that refers to an ndk_library module.
841 // For each of these, it adds the name of the ndk_library module to the list of
842 // variant libs.
843 // 3. Anything else (so anything that isn't an NDK library).
844 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700845 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700846 // The caller can then know to add the variantLibs dependencies differently from the
847 // nonvariantLibs
848 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
849 variantLibs = []string{}
850 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700851 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700852 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700853 if !inList(entry, ndkMigratedLibs) {
854 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
855 } else {
856 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
857 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700858 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700859 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700860 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700861 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700862 }
863 }
Dan Albert914449f2016-06-17 16:45:24 -0700864 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700865 }
866
Dan Albert914449f2016-06-17 16:45:24 -0700867 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
868 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900869 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700870 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700871
Colin Cross32ec36c2016-12-15 07:39:51 -0800872 for _, lib := range deps.HeaderLibs {
873 depTag := headerDepTag
874 if inList(lib, deps.ReexportHeaderLibHeaders) {
875 depTag = headerExportDepTag
876 }
877 actx.AddVariationDependencies(nil, depTag, lib)
878 }
Colin Cross5950f382016-12-13 12:50:57 -0800879
Colin Crossc99deeb2016-04-11 15:06:20 -0700880 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
881 deps.WholeStaticLibs...)
882
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700883 for _, lib := range deps.StaticLibs {
884 depTag := staticDepTag
885 if inList(lib, deps.ReexportStaticLibHeaders) {
886 depTag = staticExportDepTag
887 }
Colin Cross15a0d462016-07-14 14:49:58 -0700888 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700889 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700890
891 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
892 deps.LateStaticLibs...)
893
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700894 for _, lib := range deps.SharedLibs {
895 depTag := sharedDepTag
896 if inList(lib, deps.ReexportSharedLibHeaders) {
897 depTag = sharedExportDepTag
898 }
Colin Cross15a0d462016-07-14 14:49:58 -0700899 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700900 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700901
902 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
903 deps.LateSharedLibs...)
904
Colin Cross68861832016-07-08 10:41:41 -0700905 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700906
907 for _, gen := range deps.GeneratedHeaders {
908 depTag := genHeaderDepTag
909 if inList(gen, deps.ReexportGeneratedHeaders) {
910 depTag = genHeaderExportDepTag
911 }
912 actx.AddDependency(c, depTag, gen)
913 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700914
Colin Cross68861832016-07-08 10:41:41 -0700915 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700916
917 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700918 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800919 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700920 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700921 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700922 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700923 if deps.LinkerScript != "" {
924 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
925 }
Dan Albert914449f2016-06-17 16:45:24 -0700926
927 version := ctx.sdkVersion()
928 actx.AddVariationDependencies([]blueprint.Variation{
929 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
930 actx.AddVariationDependencies([]blueprint.Variation{
931 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700932}
Colin Cross21b9a242015-03-24 14:15:58 -0700933
Dan Albert7e9d2952016-08-04 13:02:36 -0700934func beginMutator(ctx android.BottomUpMutatorContext) {
935 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
936 c.beginMutator(ctx)
937 }
938}
939
Colin Crossca860ac2016-01-04 14:34:37 -0800940func (c *Module) clang(ctx BaseModuleContext) bool {
941 clang := Bool(c.Properties.Clang)
942
943 if c.Properties.Clang == nil {
944 if ctx.Host() {
945 clang = true
946 }
947
Colin Cross6510f912017-11-29 00:27:14 -0800948 if ctx.Device() && ctx.Config().DeviceUsesClang() {
Colin Crossca860ac2016-01-04 14:34:37 -0800949 clang = true
950 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800951 }
Colin Cross28344522015-04-22 13:07:53 -0700952
Colin Crossca860ac2016-01-04 14:34:37 -0800953 if !c.toolchain(ctx).ClangSupported() {
954 clang = false
955 }
956
957 return clang
958}
959
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700960// Whether a module can link to another module, taking into
961// account NDK linking.
962func checkLinkType(ctx android.ModuleContext, from *Module, to *Module) {
963 if from.Target().Os != android.Android {
964 // Host code is not restricted
965 return
966 }
967 if from.Properties.UseVndk {
968 // Though vendor code is limited by the vendor mutator,
969 // each vendor-available module needs to check
970 // link-type for VNDK.
971 if from.vndkdep != nil {
972 from.vndkdep.vndkCheckLinkType(ctx, to)
973 }
974 return
975 }
Nan Zhang0007d812017-11-07 10:57:05 -0800976 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700977 // Platform code can link to anything
978 return
979 }
980 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
981 // These are always allowed
982 return
983 }
984 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
985 // These are allowed, but they don't set sdk_version
986 return
987 }
988 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
989 // These are allowed, but they don't set sdk_version
990 return
991 }
992 if _, ok := to.linker.(*stubDecorator); ok {
993 // These aren't real libraries, but are the stub shared libraries that are included in
994 // the NDK.
995 return
996 }
Nan Zhang0007d812017-11-07 10:57:05 -0800997 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700998 // NDK code linking to platform code is never okay.
999 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1000 ctx.OtherModuleName(to))
1001 }
1002
1003 // At this point we know we have two NDK libraries, but we need to
1004 // check that we're not linking against anything built against a higher
1005 // API level, as it is only valid to link against older or equivalent
1006 // APIs.
1007
Nan Zhang0007d812017-11-07 10:57:05 -08001008 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001009 // Current can link against anything.
1010 return
Nan Zhang0007d812017-11-07 10:57:05 -08001011 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001012 // Current can't be linked against by anything else.
1013 ctx.ModuleErrorf("links %q built against newer API version %q",
1014 ctx.OtherModuleName(to), "current")
1015 }
1016
Nan Zhang0007d812017-11-07 10:57:05 -08001017 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001018 if err != nil {
1019 ctx.PropertyErrorf("sdk_version",
1020 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001021 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001022 }
Nan Zhang0007d812017-11-07 10:57:05 -08001023 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001024 if err != nil {
1025 ctx.PropertyErrorf("sdk_version",
1026 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001027 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001028 }
1029
1030 if toApi > fromApi {
1031 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001032 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001033 }
1034}
1035
Colin Crossc99deeb2016-04-11 15:06:20 -07001036// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001037func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001038 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001039
Jeff Gaston294356f2017-09-27 17:05:30 -07001040 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001041 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001042
Colin Crossd11fcda2017-10-23 17:59:01 -07001043 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001044 depName := ctx.OtherModuleName(dep)
1045 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001046
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001047 ccDep, _ := dep.(*Module)
1048 if ccDep == nil {
1049 // handling for a few module types that aren't cc Module but that are also supported
1050 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001051 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001052 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001053 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001054 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001055 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1056 genRule.GeneratedSourceFiles()...)
1057 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001058 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001059 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001060 // Support exported headers from a generated_sources dependency
1061 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001062 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001063 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001064 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
1065 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001066 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001067 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001068 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001069 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001070 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
1071 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001072 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1073 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1074
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001075 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001076 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001077 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001078 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001079 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001080 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001081 files := genRule.GeneratedSourceFiles()
1082 if len(files) == 1 {
1083 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1084 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001085 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001086 }
1087 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001088 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001089 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001090 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001091 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001092 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001093 return
1094 }
1095
Colin Crossd11fcda2017-10-23 17:59:01 -07001096 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001097 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1098 return
1099 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001100 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001101 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001102 return
1103 }
1104
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001105 // re-exporting flags
1106 if depTag == reuseObjTag {
1107 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001108 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001109 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001110 depPaths.Objs = depPaths.Objs.Append(objs)
1111 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001112 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001113 return
1114 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001115 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001116 if t, ok := depTag.(dependencyTag); ok && t.library {
1117 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001118 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001119 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001120 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001121 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001122
1123 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001124 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001125 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001126 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jayant Chowdharyaf6eb712017-08-23 16:08:29 -07001127 // Re-exported shared library headers must be included as well since they can help us with type information
1128 // about template instantiations (instantiated from their headers).
1129 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001130 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001131 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001132
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001133 checkLinkType(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001134 }
1135
Colin Cross26c34ed2016-09-30 17:10:16 -07001136 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001137 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001138
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001139 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001140 depFile := android.OptionalPath{}
1141
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001142 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001143 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001144 ptr = &depPaths.SharedLibs
1145 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001146 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001147 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001148 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001149 ptr = &depPaths.LateSharedLibs
1150 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001151 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001152 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001153 ptr = nil
1154 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001155 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001156 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001157 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001158 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001159 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001160 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001161 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001162 return
1163 }
1164
1165 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001166 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001167 for i := range missingDeps {
1168 missingDeps[i] += postfix
1169 }
1170 ctx.AddMissingDependencies(missingDeps)
1171 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001172 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001173 case headerDepTag:
1174 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001175 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001176 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001177 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001178 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001179 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001180 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001181 }
1182
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001183 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001184 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001185 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001186 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001187 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001188 return
1189 }
1190
1191 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001192 // in static libraries act as if they were whole static libraries. The same goes for
1193 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001194 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1195 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001196 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1197 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001198
Dan Willemsen581341d2017-02-09 16:16:31 -08001199 }
1200
Colin Cross26c34ed2016-09-30 17:10:16 -07001201 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001202 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001203 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001204 return
1205 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001206 *ptr = append(*ptr, linkFile.Path())
1207 }
1208
Colin Crossc99deeb2016-04-11 15:06:20 -07001209 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001210 dep := depFile
1211 if !dep.Valid() {
1212 dep = linkFile
1213 }
1214 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001215 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001216
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217 // Export the shared libs to Make.
1218 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001219 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001220 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001221 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001222 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001223 var makeLibName string
1224 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1225 if c.useVndk() && bothVendorAndCoreVariantsExist {
1226 // The vendor module in Make will have been renamed to not conflict with the core
1227 // module, so update the dependency name here accordingly.
1228 makeLibName = libName + vendorSuffix
1229 } else {
1230 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001231 }
1232 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001233 // they merely serve as Make dependencies and do not affect this lib itself.
1234 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001235 }
Colin Crossca860ac2016-01-04 14:34:37 -08001236 })
1237
Jeff Gaston294356f2017-09-27 17:05:30 -07001238 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001239 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001240
Colin Crossdd84e052017-05-17 13:44:16 -07001241 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001242 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001243 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001244 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001245 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1246
1247 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001248 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001249 }
Colin Crossdd84e052017-05-17 13:44:16 -07001250
Colin Crossca860ac2016-01-04 14:34:37 -08001251 return depPaths
1252}
1253
1254func (c *Module) InstallInData() bool {
1255 if c.installer == nil {
1256 return false
1257 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001258 return c.installer.inData()
1259}
1260
1261func (c *Module) InstallInSanitizerDir() bool {
1262 if c.installer == nil {
1263 return false
1264 }
1265 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001266 return true
1267 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001268 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001269}
1270
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001271func (c *Module) HostToolPath() android.OptionalPath {
1272 if c.installer == nil {
1273 return android.OptionalPath{}
1274 }
1275 return c.installer.hostToolPath()
1276}
1277
Nan Zhangd4e641b2017-07-12 12:55:28 -07001278func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1279 return c.outputFile
1280}
1281
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001282func (c *Module) Srcs() android.Paths {
1283 if c.outputFile.Valid() {
1284 return android.Paths{c.outputFile.Path()}
1285 }
1286 return android.Paths{}
1287}
1288
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001289func (c *Module) static() bool {
1290 if static, ok := c.linker.(interface {
1291 static() bool
1292 }); ok {
1293 return static.static()
1294 }
1295 return false
1296}
1297
Colin Cross2ba19d92015-05-07 15:44:20 -07001298//
Colin Crosscfad1192015-11-02 16:43:11 -08001299// Defaults
1300//
Colin Crossca860ac2016-01-04 14:34:37 -08001301type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001302 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001303 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001304}
1305
Colin Cross635c3b02016-05-18 15:37:25 -07001306func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001307}
1308
Colin Cross1e676be2016-10-12 14:38:15 -07001309func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1310}
1311
Colin Cross36242852017-06-23 15:06:31 -07001312func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001313 return DefaultsFactory()
1314}
1315
Colin Cross36242852017-06-23 15:06:31 -07001316func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001317 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001318
Colin Cross36242852017-06-23 15:06:31 -07001319 module.AddProperties(props...)
1320 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001321 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001322 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001323 &BaseCompilerProperties{},
1324 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001325 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001326 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001327 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001328 &TestProperties{},
1329 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001330 &UnusedProperties{},
1331 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001332 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001333 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001334 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001335 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001336 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001337 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001338 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001339 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001340 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001341 )
Colin Crosscfad1192015-11-02 16:43:11 -08001342
Colin Cross1f44a3a2017-07-07 14:33:33 -07001343 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001344
1345 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001346}
1347
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001348const (
1349 // coreMode is the variant used for framework-private libraries, or
1350 // SDK libraries. (which framework-private libraries can use)
1351 coreMode = "core"
1352
1353 // vendorMode is the variant used for /vendor code that compiles
1354 // against the VNDK.
1355 vendorMode = "vendor"
1356)
1357
Jiyong Park6a43f042017-10-12 23:05:00 +09001358func squashVendorSrcs(m *Module) {
1359 if lib, ok := m.compiler.(*libraryDecorator); ok {
1360 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1361 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1362
1363 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1364 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1365 }
1366}
1367
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001368func vendorMutator(mctx android.BottomUpMutatorContext) {
1369 if mctx.Os() != android.Android {
1370 return
1371 }
1372
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001373 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1374 if props, ok := genrule.Extra.(*VendorProperties); ok {
1375 if !mctx.DeviceConfig().CompileVndk() {
1376 mctx.CreateVariations(coreMode)
1377 } else if Bool(props.Vendor_available) {
1378 mctx.CreateVariations(coreMode, vendorMode)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001379 } else if mctx.InstallOnVendorPartition() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001380 mctx.CreateVariations(vendorMode)
1381 } else {
1382 mctx.CreateVariations(coreMode)
1383 }
1384 }
1385 }
1386
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001387 m, ok := mctx.Module().(*Module)
1388 if !ok {
1389 return
1390 }
1391
1392 // Sanity check
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001393 if m.VendorProperties.Vendor_available != nil && mctx.InstallOnVendorPartition() {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001394 mctx.PropertyErrorf("vendor_available",
1395 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1396 return
1397 }
Justin Yun8effde42017-06-23 19:24:43 +09001398 if vndk := m.vndkdep; vndk != nil {
Jiyong Park82e2bf32017-08-16 14:05:54 +09001399 if vndk.isVndk() && m.VendorProperties.Vendor_available == nil {
Justin Yun8effde42017-06-23 19:24:43 +09001400 mctx.PropertyErrorf("vndk",
Jiyong Park82e2bf32017-08-16 14:05:54 +09001401 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Justin Yun8effde42017-06-23 19:24:43 +09001402 return
1403 }
1404 if !vndk.isVndk() && vndk.isVndkSp() {
1405 mctx.PropertyErrorf("vndk",
1406 "must set `enabled: true` to set `support_system_process: true`")
1407 return
1408 }
1409 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001410
1411 if !mctx.DeviceConfig().CompileVndk() {
1412 // If the device isn't compiling against the VNDK, we always
1413 // use the core mode.
1414 mctx.CreateVariations(coreMode)
1415 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1416 // LL-NDK stubs only exist in the vendor variant, since the
1417 // real libraries will be used in the core variant.
1418 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001419 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1420 // ... and LL-NDK headers as well
1421 mctx.CreateVariations(vendorMode)
Jiyong Park82e2bf32017-08-16 14:05:54 +09001422 } else if m.hasVendorVariant() {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001423 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001424 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001425 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001426 vendor := mod[1].(*Module)
1427 vendor.Properties.UseVndk = true
1428 squashVendorSrcs(vendor)
Nan Zhang0007d812017-11-07 10:57:05 -08001429 } else if mctx.InstallOnVendorPartition() && String(m.Properties.Sdk_version) == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001430 // This will be available in /vendor only
1431 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001432 vendor := mod[0].(*Module)
1433 vendor.Properties.UseVndk = true
1434 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001435 } else {
1436 // This is either in /system (or similar: /data), or is a
1437 // modules built with the NDK. Modules built with the NDK
1438 // will be restricted using the existing link type checks.
1439 mctx.CreateVariations(coreMode)
1440 }
1441}
1442
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001443func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001444 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001445 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1446 }
Colin Cross6510f912017-11-29 00:27:14 -08001447 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001448}
1449
Colin Cross06a931b2015-10-28 17:23:31 -07001450var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001451var BoolPtr = proptools.BoolPtr
1452var String = proptools.String
1453var StringPtr = proptools.StringPtr