blob: 49fefe965dd7cc5e0d59e2b1ae1934065f16cc5a [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
Joe Onorato09e94ab2017-11-18 18:23:14 -0800119 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700120 aidlFlags []string // Flags that apply to aidl source files
121 rsFlags []string // Flags that apply to renderscript source files
122 LdFlags []string // Flags that apply to linker command lines
123 libFlags []string // Flags to add libraries early to the link order
124 TidyFlags []string // Flags that apply to clang-tidy
125 SAbiFlags []string // Flags that apply to header-abi-dumper
126 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700127
Colin Crossc3199482017-03-30 15:03:04 -0700128 // Global include flags that apply to C, C++, and assembly source files
129 // These must be after any module include flags, which will be in GlobalFlags.
130 SystemIncludeFlags []string
131
Colin Crossb98c8b02016-07-29 13:44:28 -0700132 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700133 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700134 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800135 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800136 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800137
138 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800139 DynamicLinker string
140
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700141 CFlagsDeps android.Paths // Files depended on by compiler flags
142 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800143
144 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800145 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700146}
147
Colin Cross81413472016-04-11 14:37:39 -0700148type ObjectLinkerProperties struct {
149 // names of other cc_object modules to link into this module using partial linking
150 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700151
152 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800153 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700154}
155
Colin Crossca860ac2016-01-04 14:34:37 -0800156// Properties used to compile all C or C++ modules
157type BaseProperties struct {
158 // compile module with clang instead of gcc
159 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700160
161 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800162 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700163
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700164 AndroidMkSharedLibs []string `blueprint:"mutated"`
165 HideFromMake bool `blueprint:"mutated"`
166 PreventInstall bool `blueprint:"mutated"`
167
168 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800169
170 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
171 // file
172 Logtags []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700173}
174
175type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900176 // whether this module should be allowed to be directly depended by other
177 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
178 // If set to true, two variants will be built separately, one like
179 // normal, and the other limited to the set of libraries and headers
180 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700181 //
182 // The vendor variant may be used with a different (newer) /system,
183 // so it shouldn't have any unversioned runtime dependencies, or
184 // make assumptions about the system that may not be true in the
185 // future.
186 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900187 // If set to false, this module becomes inaccessible from /vendor modules.
188 //
189 // Default value is true when vndk: {enabled: true} or vendor: true.
190 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700191 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
192 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800193}
194
Colin Crossca860ac2016-01-04 14:34:37 -0800195type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800196 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800197}
198
Colin Crossca860ac2016-01-04 14:34:37 -0800199type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800200 static() bool
201 staticBinary() bool
202 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700203 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700204 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800205 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700206 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900207 isVndk() bool
208 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800209 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800210 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700211 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700212 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800213 getVndkExtendsModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800214}
215
216type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700217 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800218 ModuleContextIntf
219}
220
221type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700222 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800223 ModuleContextIntf
224}
225
Colin Cross37047f12016-12-13 17:06:13 -0800226type DepsContext interface {
227 android.BottomUpMutatorContext
228 ModuleContextIntf
229}
230
Colin Crossca860ac2016-01-04 14:34:37 -0800231type feature interface {
232 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800233 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800234 flags(ctx ModuleContext, flags Flags) Flags
235 props() []interface{}
236}
237
238type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700239 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800240 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800241 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700242 compilerProps() []interface{}
243
Colin Cross76fada02016-07-27 10:31:13 -0700244 appendCflags([]string)
245 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700246 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800247}
248
249type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700250 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800251 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700252 linkerFlags(ctx ModuleContext, flags Flags) Flags
253 linkerProps() []interface{}
254
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700255 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700256 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800257}
258
259type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700260 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700261 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800262 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700263 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700264 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800265}
266
Colin Crossc99deeb2016-04-11 15:06:20 -0700267type dependencyTag struct {
268 blueprint.BaseDependencyTag
269 name string
270 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700271
272 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700273}
274
275var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700276 sharedDepTag = dependencyTag{name: "shared", library: true}
277 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
278 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
279 staticDepTag = dependencyTag{name: "static", library: true}
280 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
281 lateStaticDepTag = dependencyTag{name: "late static", library: true}
282 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800283 headerDepTag = dependencyTag{name: "header", library: true}
284 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700285 genSourceDepTag = dependencyTag{name: "gen source"}
286 genHeaderDepTag = dependencyTag{name: "gen header"}
287 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
288 objDepTag = dependencyTag{name: "obj"}
289 crtBeginDepTag = dependencyTag{name: "crtbegin"}
290 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700291 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700292 reuseObjTag = dependencyTag{name: "reuse objects"}
293 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
294 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800295 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700296)
297
Colin Crossca860ac2016-01-04 14:34:37 -0800298// Module contains the properties and members used by all C/C++ module types, and implements
299// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
300// to construct the output file. Behavior can be customized with a Customizer interface
301type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700302 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700303 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700304
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700305 Properties BaseProperties
306 VendorProperties VendorProperties
307 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700308
Colin Crossca860ac2016-01-04 14:34:37 -0800309 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700310 hod android.HostOrDeviceSupported
311 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700312
Colin Crossca860ac2016-01-04 14:34:37 -0800313 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700314 features []feature
315 compiler compiler
316 linker linker
317 installer installer
318 stl *stl
319 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800320 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800321 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900322 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700323 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700324 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800325
326 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700327
Colin Cross635c3b02016-05-18 15:37:25 -0700328 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800329
Colin Crossb98c8b02016-07-29 13:44:28 -0700330 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700331
332 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800333
334 // Flags used to compile this module
335 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700336
337 // 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 -0800338 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700339 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800340 depsInLinkOrder android.Paths
341
342 // only non-nil when this is a shared library that reuses the objects of a static library
343 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700344}
345
Colin Cross36242852017-06-23 15:06:31 -0700346func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700347 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800348 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700349 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800350 }
351 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700352 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800353 }
354 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700355 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800356 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700357 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700358 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700359 }
Colin Cross16b23492016-01-06 14:41:07 -0800360 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700361 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800362 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800363 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700364 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800365 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800366 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700367 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800368 }
Justin Yun8effde42017-06-23 19:24:43 +0900369 if c.vndkdep != nil {
370 c.AddProperties(c.vndkdep.props()...)
371 }
Stephen Craneba090d12017-05-09 15:44:35 -0700372 if c.lto != nil {
373 c.AddProperties(c.lto.props()...)
374 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700375 if c.pgo != nil {
376 c.AddProperties(c.pgo.props()...)
377 }
Colin Crossca860ac2016-01-04 14:34:37 -0800378 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700379 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800380 }
Colin Crossc472d572015-03-17 15:06:21 -0700381
Colin Cross36242852017-06-23 15:06:31 -0700382 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700383
Colin Cross1f44a3a2017-07-07 14:33:33 -0700384 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700385
386 return c
Colin Crossc472d572015-03-17 15:06:21 -0700387}
388
Colin Crossb916a382016-07-29 17:28:03 -0700389// Returns true for dependency roots (binaries)
390// TODO(ccross): also handle dlopenable libraries
391func (c *Module) isDependencyRoot() bool {
392 if root, ok := c.linker.(interface {
393 isDependencyRoot() bool
394 }); ok {
395 return root.isDependencyRoot()
396 }
397 return false
398}
399
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700400func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700401 return c.Properties.UseVndk
402}
403
Justin Yun8effde42017-06-23 19:24:43 +0900404func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800405 if vndkdep := c.vndkdep; vndkdep != nil {
406 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900407 }
408 return false
409}
410
Logan Chienf3511742017-10-31 18:04:35 +0800411func (c *Module) isVndkSp() bool {
412 if vndkdep := c.vndkdep; vndkdep != nil {
413 return vndkdep.isVndkSp()
414 }
415 return false
416}
417
418func (c *Module) isVndkExt() bool {
419 if vndkdep := c.vndkdep; vndkdep != nil {
420 return vndkdep.isVndkExt()
421 }
422 return false
423}
424
425func (c *Module) getVndkExtendsModuleName() string {
426 if vndkdep := c.vndkdep; vndkdep != nil {
427 return vndkdep.getVndkExtendsModuleName()
428 }
429 return ""
430}
431
Jiyong Park82e2bf32017-08-16 14:05:54 +0900432// Returns true only when this module is configured to have core and vendor
433// variants.
434func (c *Module) hasVendorVariant() bool {
435 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
436}
437
Colin Crossca860ac2016-01-04 14:34:37 -0800438type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700439 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800440 moduleContextImpl
441}
442
Colin Cross37047f12016-12-13 17:06:13 -0800443type depsContext struct {
444 android.BottomUpMutatorContext
445 moduleContextImpl
446}
447
Colin Crossca860ac2016-01-04 14:34:37 -0800448type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700449 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800450 moduleContextImpl
451}
452
Jiyong Park2db76922017-11-08 16:03:48 +0900453func (ctx *moduleContext) SocSpecific() bool {
454 return ctx.ModuleContext.SocSpecific() ||
455 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700456}
457
Colin Crossca860ac2016-01-04 14:34:37 -0800458type moduleContextImpl struct {
459 mod *Module
460 ctx BaseModuleContext
461}
462
Colin Crossca860ac2016-01-04 14:34:37 -0800463func (ctx *moduleContextImpl) clang() bool {
464 return ctx.mod.clang(ctx.ctx)
465}
466
Colin Crossb98c8b02016-07-29 13:44:28 -0700467func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800468 return ctx.mod.toolchain(ctx.ctx)
469}
470
471func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000472 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800473}
474
475func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700476 if static, ok := ctx.mod.linker.(interface {
477 staticBinary() bool
478 }); ok {
479 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800480 }
Colin Crossb916a382016-07-29 17:28:03 -0700481 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800482}
483
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700484func (ctx *moduleContextImpl) useSdk() bool {
485 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800486 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700487 }
488 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800489}
490
491func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700492 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700493 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700494 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800495 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800496 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800497 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700498 }
499 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800500}
501
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700502func (ctx *moduleContextImpl) useVndk() bool {
503 return ctx.mod.useVndk()
504}
Justin Yun8effde42017-06-23 19:24:43 +0900505
Logan Chienf3511742017-10-31 18:04:35 +0800506func (ctx *moduleContextImpl) isVndk() bool {
507 return ctx.mod.isVndk()
508}
509
Justin Yun8effde42017-06-23 19:24:43 +0900510func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800511 return ctx.mod.isVndkSp()
512}
513
514func (ctx *moduleContextImpl) isVndkExt() bool {
515 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900516}
517
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800518// Create source abi dumps if the module belongs to the list of VndkLibraries.
519func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700520 return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800521}
522
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700523func (ctx *moduleContextImpl) selectedStl() string {
524 if stl := ctx.mod.stl; stl != nil {
525 return stl.Properties.SelectedStl
526 }
527 return ""
528}
529
Colin Crossce75d2c2016-10-06 16:12:58 -0700530func (ctx *moduleContextImpl) baseModuleName() string {
531 return ctx.mod.ModuleBase.BaseModuleName()
532}
533
Logan Chienf3511742017-10-31 18:04:35 +0800534func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
535 return ctx.mod.getVndkExtendsModuleName()
536}
537
Colin Cross635c3b02016-05-18 15:37:25 -0700538func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800539 return &Module{
540 hod: hod,
541 multilib: multilib,
542 }
543}
544
Colin Cross635c3b02016-05-18 15:37:25 -0700545func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800546 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700547 module.features = []feature{
548 &tidyFeature{},
549 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700550 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800551 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800552 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800553 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900554 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700555 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700556 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800557 return module
558}
559
Colin Crossce75d2c2016-10-06 16:12:58 -0700560func (c *Module) Prebuilt() *android.Prebuilt {
561 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
562 return p.prebuilt()
563 }
564 return nil
565}
566
567func (c *Module) Name() string {
568 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700569 if p, ok := c.linker.(interface {
570 Name(string) string
571 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700572 name = p.Name(name)
573 }
574 return name
575}
576
Jeff Gaston294356f2017-09-27 17:05:30 -0700577// orderDeps reorders dependencies into a list such that if module A depends on B, then
578// A will precede B in the resultant list.
579// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800580// Note that directSharedDeps should be the analogous static library for each shared lib dep
581func 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 -0700582 // If A depends on B, then
583 // Every list containing A will also contain B later in the list
584 // So, after concatenating all lists, the final instance of B will have come from the same
585 // original list as the final instance of A
586 // So, the final instance of B will be later in the concatenation than the final A
587 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
588 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800589 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700590 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800591 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
592 }
593 for _, dep := range directSharedDeps {
594 orderedAllDeps = append(orderedAllDeps, dep)
595 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700596 }
597
Colin Crossb6715442017-10-24 11:13:31 -0700598 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700599
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800600 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700601 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800602 // resultant list to only what the caller has chosen to include in directStaticDeps
603 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700604
605 return orderedAllDeps, orderedDeclaredDeps
606}
607
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800608func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
609 // convert Module to Path
610 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
611 staticDepFiles := []android.Path{}
612 for _, dep := range staticDeps {
613 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
614 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700615 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800616 sharedDepFiles := []android.Path{}
617 for _, sharedDep := range sharedDeps {
618 staticAnalogue := sharedDep.staticVariant
619 if staticAnalogue != nil {
620 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
621 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
622 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700623 }
624
625 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800626 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700627
628 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700629}
630
Colin Cross635c3b02016-05-18 15:37:25 -0700631func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700632
Colin Crossca860ac2016-01-04 14:34:37 -0800633 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700634 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800635 moduleContextImpl: moduleContextImpl{
636 mod: c,
637 },
638 }
639 ctx.ctx = ctx
640
Colin Crossf18e1102017-11-16 14:33:08 -0800641 deps := c.depsToPaths(ctx)
642 if ctx.Failed() {
643 return
644 }
645
Colin Crossca860ac2016-01-04 14:34:37 -0800646 flags := Flags{
647 Toolchain: c.toolchain(ctx),
648 Clang: c.clang(ctx),
649 }
Colin Crossca860ac2016-01-04 14:34:37 -0800650 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800651 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800652 }
653 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700654 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800655 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700656 if c.stl != nil {
657 flags = c.stl.flags(ctx, flags)
658 }
Colin Cross16b23492016-01-06 14:41:07 -0800659 if c.sanitize != nil {
660 flags = c.sanitize.flags(ctx, flags)
661 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800662 if c.coverage != nil {
663 flags = c.coverage.flags(ctx, flags)
664 }
Stephen Craneba090d12017-05-09 15:44:35 -0700665 if c.lto != nil {
666 flags = c.lto.flags(ctx, flags)
667 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700668 if c.pgo != nil {
669 flags = c.pgo.flags(ctx, flags)
670 }
Colin Crossca860ac2016-01-04 14:34:37 -0800671 for _, feature := range c.features {
672 flags = feature.flags(ctx, flags)
673 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800674 if ctx.Failed() {
675 return
676 }
677
Colin Crossb98c8b02016-07-29 13:44:28 -0700678 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
679 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
680 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800681
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800682 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
683 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700684 // We need access to all the flags seen by a source file.
685 if c.sabi != nil {
686 flags = c.sabi.flags(ctx, flags)
687 }
Colin Crossca860ac2016-01-04 14:34:37 -0800688 // Optimization to reduce size of build.ninja
689 // Replace the long list of flags for each file with a module-local variable
690 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
691 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
692 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
693 flags.CFlags = []string{"$cflags"}
694 flags.CppFlags = []string{"$cppflags"}
695 flags.AsFlags = []string{"$asflags"}
696
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700697 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800698 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700699 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800700 if ctx.Failed() {
701 return
702 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800703 }
704
Colin Crossca860ac2016-01-04 14:34:37 -0800705 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700706 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800707 if ctx.Failed() {
708 return
709 }
Colin Cross635c3b02016-05-18 15:37:25 -0700710 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700711 }
Colin Cross5049f022015-03-18 13:28:46 -0700712
Colin Crossce75d2c2016-10-06 16:12:58 -0700713 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
714 c.installer.install(ctx, c.outputFile.Path())
715 if ctx.Failed() {
716 return
Colin Crossca860ac2016-01-04 14:34:37 -0800717 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700718 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800719}
720
Colin Crossb98c8b02016-07-29 13:44:28 -0700721func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800722 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700723 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800724 }
Colin Crossca860ac2016-01-04 14:34:37 -0800725 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800726}
727
Colin Crossca860ac2016-01-04 14:34:37 -0800728func (c *Module) begin(ctx BaseModuleContext) {
729 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700730 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700731 }
Colin Crossca860ac2016-01-04 14:34:37 -0800732 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700733 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800734 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700735 if c.stl != nil {
736 c.stl.begin(ctx)
737 }
Colin Cross16b23492016-01-06 14:41:07 -0800738 if c.sanitize != nil {
739 c.sanitize.begin(ctx)
740 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800741 if c.coverage != nil {
742 c.coverage.begin(ctx)
743 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800744 if c.sabi != nil {
745 c.sabi.begin(ctx)
746 }
Justin Yun8effde42017-06-23 19:24:43 +0900747 if c.vndkdep != nil {
748 c.vndkdep.begin(ctx)
749 }
Stephen Craneba090d12017-05-09 15:44:35 -0700750 if c.lto != nil {
751 c.lto.begin(ctx)
752 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700753 if c.pgo != nil {
754 c.pgo.begin(ctx)
755 }
Colin Crossca860ac2016-01-04 14:34:37 -0800756 for _, feature := range c.features {
757 feature.begin(ctx)
758 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700759 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700760 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700761 if err != nil {
762 ctx.PropertyErrorf("sdk_version", err.Error())
763 }
Nan Zhang0007d812017-11-07 10:57:05 -0800764 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700765 }
Colin Crossca860ac2016-01-04 14:34:37 -0800766}
767
Colin Cross37047f12016-12-13 17:06:13 -0800768func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700769 deps := Deps{}
770
771 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700772 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700773 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700774 // Add the PGO dependency (the clang_rt.profile runtime library), which
775 // sometimes depends on symbols from libgcc, before libgcc gets added
776 // in linkerDeps().
777 if c.pgo != nil {
778 deps = c.pgo.deps(ctx, deps)
779 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700780 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700781 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700782 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700783 if c.stl != nil {
784 deps = c.stl.deps(ctx, deps)
785 }
Colin Cross16b23492016-01-06 14:41:07 -0800786 if c.sanitize != nil {
787 deps = c.sanitize.deps(ctx, deps)
788 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800789 if c.coverage != nil {
790 deps = c.coverage.deps(ctx, deps)
791 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800792 if c.sabi != nil {
793 deps = c.sabi.deps(ctx, deps)
794 }
Justin Yun8effde42017-06-23 19:24:43 +0900795 if c.vndkdep != nil {
796 deps = c.vndkdep.deps(ctx, deps)
797 }
Stephen Craneba090d12017-05-09 15:44:35 -0700798 if c.lto != nil {
799 deps = c.lto.deps(ctx, deps)
800 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700801 for _, feature := range c.features {
802 deps = feature.deps(ctx, deps)
803 }
804
Colin Crossb6715442017-10-24 11:13:31 -0700805 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
806 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
807 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
808 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
809 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
810 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700811
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700812 for _, lib := range deps.ReexportSharedLibHeaders {
813 if !inList(lib, deps.SharedLibs) {
814 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
815 }
816 }
817
818 for _, lib := range deps.ReexportStaticLibHeaders {
819 if !inList(lib, deps.StaticLibs) {
820 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
821 }
822 }
823
Colin Cross5950f382016-12-13 12:50:57 -0800824 for _, lib := range deps.ReexportHeaderLibHeaders {
825 if !inList(lib, deps.HeaderLibs) {
826 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
827 }
828 }
829
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700830 for _, gen := range deps.ReexportGeneratedHeaders {
831 if !inList(gen, deps.GeneratedHeaders) {
832 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
833 }
834 }
835
Colin Crossc99deeb2016-04-11 15:06:20 -0700836 return deps
837}
838
Dan Albert7e9d2952016-08-04 13:02:36 -0700839func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800840 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700841 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800842 moduleContextImpl: moduleContextImpl{
843 mod: c,
844 },
845 }
846 ctx.ctx = ctx
847
Colin Crossca860ac2016-01-04 14:34:37 -0800848 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700849}
850
Colin Cross1e676be2016-10-12 14:38:15 -0700851func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
852 if !c.Enabled() {
853 return
854 }
855
Colin Cross37047f12016-12-13 17:06:13 -0800856 ctx := &depsContext{
857 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700858 moduleContextImpl: moduleContextImpl{
859 mod: c,
860 },
861 }
862 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800863
Colin Crossc99deeb2016-04-11 15:06:20 -0700864 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800865
Dan Albert914449f2016-06-17 16:45:24 -0700866 variantNdkLibs := []string{}
867 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700868 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700869 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700870
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700871 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
872 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700873 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700874 // 1. Name of an NDK library that refers to a prebuilt module.
875 // For each of these, it adds the name of the prebuilt module (which will be in
876 // prebuilts/ndk) to the list of nonvariant libs.
877 // 2. Name of an NDK library that refers to an ndk_library module.
878 // For each of these, it adds the name of the ndk_library module to the list of
879 // variant libs.
880 // 3. Anything else (so anything that isn't an NDK library).
881 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700882 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700883 // The caller can then know to add the variantLibs dependencies differently from the
884 // nonvariantLibs
885 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
886 variantLibs = []string{}
887 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700888 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700889 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700890 if !inList(entry, ndkMigratedLibs) {
891 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
892 } else {
893 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
894 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700895 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700896 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700897 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700898 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700899 }
900 }
Dan Albert914449f2016-06-17 16:45:24 -0700901 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700902 }
903
Dan Albert914449f2016-06-17 16:45:24 -0700904 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
905 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900906 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700907 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700908
Colin Cross32ec36c2016-12-15 07:39:51 -0800909 for _, lib := range deps.HeaderLibs {
910 depTag := headerDepTag
911 if inList(lib, deps.ReexportHeaderLibHeaders) {
912 depTag = headerExportDepTag
913 }
914 actx.AddVariationDependencies(nil, depTag, lib)
915 }
Colin Cross5950f382016-12-13 12:50:57 -0800916
Colin Crossc99deeb2016-04-11 15:06:20 -0700917 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
918 deps.WholeStaticLibs...)
919
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700920 for _, lib := range deps.StaticLibs {
921 depTag := staticDepTag
922 if inList(lib, deps.ReexportStaticLibHeaders) {
923 depTag = staticExportDepTag
924 }
Colin Cross15a0d462016-07-14 14:49:58 -0700925 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700926 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700927
928 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
929 deps.LateStaticLibs...)
930
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700931 for _, lib := range deps.SharedLibs {
932 depTag := sharedDepTag
933 if inList(lib, deps.ReexportSharedLibHeaders) {
934 depTag = sharedExportDepTag
935 }
Colin Cross15a0d462016-07-14 14:49:58 -0700936 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700937 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700938
939 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
940 deps.LateSharedLibs...)
941
Colin Cross68861832016-07-08 10:41:41 -0700942 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700943
944 for _, gen := range deps.GeneratedHeaders {
945 depTag := genHeaderDepTag
946 if inList(gen, deps.ReexportGeneratedHeaders) {
947 depTag = genHeaderExportDepTag
948 }
949 actx.AddDependency(c, depTag, gen)
950 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700951
Colin Cross68861832016-07-08 10:41:41 -0700952 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700953
954 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700955 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800956 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700957 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700958 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700959 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700960 if deps.LinkerScript != "" {
961 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
962 }
Dan Albert914449f2016-06-17 16:45:24 -0700963
964 version := ctx.sdkVersion()
965 actx.AddVariationDependencies([]blueprint.Variation{
966 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
967 actx.AddVariationDependencies([]blueprint.Variation{
968 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +0800969
970 if vndkdep := c.vndkdep; vndkdep != nil {
971 if vndkdep.isVndkExt() {
972 baseModuleMode := vendorMode
973 if actx.DeviceConfig().VndkVersion() == "" {
974 baseModuleMode = coreMode
975 }
976 actx.AddVariationDependencies([]blueprint.Variation{
977 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
978 vndkdep.getVndkExtendsModuleName())
979 }
980 }
Colin Cross6362e272015-10-29 15:25:03 -0700981}
Colin Cross21b9a242015-03-24 14:15:58 -0700982
Dan Albert7e9d2952016-08-04 13:02:36 -0700983func beginMutator(ctx android.BottomUpMutatorContext) {
984 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
985 c.beginMutator(ctx)
986 }
987}
988
Colin Crossca860ac2016-01-04 14:34:37 -0800989func (c *Module) clang(ctx BaseModuleContext) bool {
990 clang := Bool(c.Properties.Clang)
991
992 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -0800993 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800994 }
Colin Cross28344522015-04-22 13:07:53 -0700995
Colin Crossca860ac2016-01-04 14:34:37 -0800996 if !c.toolchain(ctx).ClangSupported() {
997 clang = false
998 }
999
1000 return clang
1001}
1002
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001003// Whether a module can link to another module, taking into
1004// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001005func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001006 if from.Target().Os != android.Android {
1007 // Host code is not restricted
1008 return
1009 }
1010 if from.Properties.UseVndk {
1011 // Though vendor code is limited by the vendor mutator,
1012 // each vendor-available module needs to check
1013 // link-type for VNDK.
1014 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001015 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001016 }
1017 return
1018 }
Nan Zhang0007d812017-11-07 10:57:05 -08001019 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001020 // Platform code can link to anything
1021 return
1022 }
1023 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1024 // These are always allowed
1025 return
1026 }
1027 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
1028 // These are allowed, but they don't set sdk_version
1029 return
1030 }
1031 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1032 // These are allowed, but they don't set sdk_version
1033 return
1034 }
1035 if _, ok := to.linker.(*stubDecorator); ok {
1036 // These aren't real libraries, but are the stub shared libraries that are included in
1037 // the NDK.
1038 return
1039 }
Nan Zhang0007d812017-11-07 10:57:05 -08001040 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001041 // NDK code linking to platform code is never okay.
1042 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1043 ctx.OtherModuleName(to))
1044 }
1045
1046 // At this point we know we have two NDK libraries, but we need to
1047 // check that we're not linking against anything built against a higher
1048 // API level, as it is only valid to link against older or equivalent
1049 // APIs.
1050
Nan Zhang0007d812017-11-07 10:57:05 -08001051 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001052 // Current can link against anything.
1053 return
Nan Zhang0007d812017-11-07 10:57:05 -08001054 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001055 // Current can't be linked against by anything else.
1056 ctx.ModuleErrorf("links %q built against newer API version %q",
1057 ctx.OtherModuleName(to), "current")
1058 }
1059
Nan Zhang0007d812017-11-07 10:57:05 -08001060 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001061 if err != nil {
1062 ctx.PropertyErrorf("sdk_version",
1063 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001064 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001065 }
Nan Zhang0007d812017-11-07 10:57:05 -08001066 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001067 if err != nil {
1068 ctx.PropertyErrorf("sdk_version",
1069 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001070 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001071 }
1072
1073 if toApi > fromApi {
1074 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001075 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001076 }
Dan Albert202fe492017-12-15 13:56:59 -08001077
1078 // Also check that the two STL choices are compatible.
1079 fromStl := from.stl.Properties.SelectedStl
1080 toStl := to.stl.Properties.SelectedStl
1081 if fromStl == "" || toStl == "" {
1082 // Libraries that don't use the STL are unrestricted.
1083 return
1084 }
1085
1086 if fromStl == "ndk_system" || toStl == "ndk_system" {
1087 // We can be permissive with the system "STL" since it is only the C++
1088 // ABI layer, but in the future we should make sure that everyone is
1089 // using either libc++ or nothing.
1090 return
1091 }
1092
1093 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1094 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1095 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1096 to.stl.Properties.SelectedStl)
1097 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001098}
1099
Colin Crossc99deeb2016-04-11 15:06:20 -07001100// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001101func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001102 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001103
Jeff Gaston294356f2017-09-27 17:05:30 -07001104 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001105 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001106
Colin Crossd11fcda2017-10-23 17:59:01 -07001107 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001108 depName := ctx.OtherModuleName(dep)
1109 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001110
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001111 ccDep, _ := dep.(*Module)
1112 if ccDep == nil {
1113 // handling for a few module types that aren't cc Module but that are also supported
1114 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001115 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001116 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001117 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001118 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001119 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1120 genRule.GeneratedSourceFiles()...)
1121 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001122 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001123 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001124 // Support exported headers from a generated_sources dependency
1125 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001126 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001127 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001128 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
1129 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001130 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001131 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001132 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001133 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001134 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
1135 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001136 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1137 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1138
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001139 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001140 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001141 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001142 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001143 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001144 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001145 files := genRule.GeneratedSourceFiles()
1146 if len(files) == 1 {
1147 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1148 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001149 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001150 }
1151 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001152 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001153 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001154 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001155 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001156 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001157 return
1158 }
1159
Colin Crossd11fcda2017-10-23 17:59:01 -07001160 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001161 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1162 return
1163 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001164 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001165 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001166 return
1167 }
1168
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001169 // re-exporting flags
1170 if depTag == reuseObjTag {
1171 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001172 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001173 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001174 depPaths.Objs = depPaths.Objs.Append(objs)
1175 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001176 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001177 return
1178 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001179 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001180 if t, ok := depTag.(dependencyTag); ok && t.library {
1181 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001182 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001183 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001184 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001185 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001186
1187 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001188 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001189 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001190 // 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 -07001191 // Re-exported shared library headers must be included as well since they can help us with type information
1192 // about template instantiations (instantiated from their headers).
1193 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001194 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001195 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001196
Logan Chienf3511742017-10-31 18:04:35 +08001197 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001198 }
1199
Colin Cross26c34ed2016-09-30 17:10:16 -07001200 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001201 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001202
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001203 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001204 depFile := android.OptionalPath{}
1205
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001206 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001207 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001208 ptr = &depPaths.SharedLibs
1209 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001210 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001211 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001212 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001213 ptr = &depPaths.LateSharedLibs
1214 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001215 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001216 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001217 ptr = nil
1218 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001219 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001220 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001221 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001222 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001223 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001224 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001225 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001226 return
1227 }
1228
1229 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001230 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001231 for i := range missingDeps {
1232 missingDeps[i] += postfix
1233 }
1234 ctx.AddMissingDependencies(missingDeps)
1235 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001236 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001237 case headerDepTag:
1238 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001239 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001240 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001241 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001242 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001243 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001244 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001245 }
1246
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001247 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001248 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001249 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001250 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001251 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001252 return
1253 }
1254
1255 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001256 // in static libraries act as if they were whole static libraries. The same goes for
1257 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001258 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1259 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001260 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1261 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001262
Dan Willemsen581341d2017-02-09 16:16:31 -08001263 }
1264
Colin Cross26c34ed2016-09-30 17:10:16 -07001265 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001266 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001267 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001268 return
1269 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001270 *ptr = append(*ptr, linkFile.Path())
1271 }
1272
Colin Crossc99deeb2016-04-11 15:06:20 -07001273 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001274 dep := depFile
1275 if !dep.Valid() {
1276 dep = linkFile
1277 }
1278 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001279 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001280
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001281 // Export the shared libs to Make.
1282 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001283 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001284 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001285 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001286 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001287 var makeLibName string
1288 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1289 if c.useVndk() && bothVendorAndCoreVariantsExist {
1290 // The vendor module in Make will have been renamed to not conflict with the core
1291 // module, so update the dependency name here accordingly.
1292 makeLibName = libName + vendorSuffix
1293 } else {
1294 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001295 }
1296 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001297 // they merely serve as Make dependencies and do not affect this lib itself.
1298 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001299 }
Colin Crossca860ac2016-01-04 14:34:37 -08001300 })
1301
Jeff Gaston294356f2017-09-27 17:05:30 -07001302 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001303 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001304
Colin Crossdd84e052017-05-17 13:44:16 -07001305 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001306 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001307 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001308 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001309 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1310
1311 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001312 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001313 }
Colin Crossdd84e052017-05-17 13:44:16 -07001314
Colin Crossca860ac2016-01-04 14:34:37 -08001315 return depPaths
1316}
1317
1318func (c *Module) InstallInData() bool {
1319 if c.installer == nil {
1320 return false
1321 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001322 return c.installer.inData()
1323}
1324
1325func (c *Module) InstallInSanitizerDir() bool {
1326 if c.installer == nil {
1327 return false
1328 }
1329 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001330 return true
1331 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001332 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001333}
1334
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001335func (c *Module) HostToolPath() android.OptionalPath {
1336 if c.installer == nil {
1337 return android.OptionalPath{}
1338 }
1339 return c.installer.hostToolPath()
1340}
1341
Nan Zhangd4e641b2017-07-12 12:55:28 -07001342func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1343 return c.outputFile
1344}
1345
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001346func (c *Module) Srcs() android.Paths {
1347 if c.outputFile.Valid() {
1348 return android.Paths{c.outputFile.Path()}
1349 }
1350 return android.Paths{}
1351}
1352
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001353func (c *Module) static() bool {
1354 if static, ok := c.linker.(interface {
1355 static() bool
1356 }); ok {
1357 return static.static()
1358 }
1359 return false
1360}
1361
Colin Cross2ba19d92015-05-07 15:44:20 -07001362//
Colin Crosscfad1192015-11-02 16:43:11 -08001363// Defaults
1364//
Colin Crossca860ac2016-01-04 14:34:37 -08001365type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001366 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001367 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001368}
1369
Colin Cross635c3b02016-05-18 15:37:25 -07001370func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001371}
1372
Colin Cross1e676be2016-10-12 14:38:15 -07001373func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1374}
1375
Colin Cross36242852017-06-23 15:06:31 -07001376func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001377 return DefaultsFactory()
1378}
1379
Colin Cross36242852017-06-23 15:06:31 -07001380func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001381 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001382
Colin Cross36242852017-06-23 15:06:31 -07001383 module.AddProperties(props...)
1384 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001385 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001386 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001387 &BaseCompilerProperties{},
1388 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001389 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001390 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001391 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001392 &TestProperties{},
1393 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001394 &UnusedProperties{},
1395 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001396 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001397 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001398 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001399 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001400 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001401 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001402 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001403 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001404 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001405 )
Colin Crosscfad1192015-11-02 16:43:11 -08001406
Colin Cross1f44a3a2017-07-07 14:33:33 -07001407 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001408
1409 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001410}
1411
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001412const (
1413 // coreMode is the variant used for framework-private libraries, or
1414 // SDK libraries. (which framework-private libraries can use)
1415 coreMode = "core"
1416
1417 // vendorMode is the variant used for /vendor code that compiles
1418 // against the VNDK.
1419 vendorMode = "vendor"
1420)
1421
Jiyong Park6a43f042017-10-12 23:05:00 +09001422func squashVendorSrcs(m *Module) {
1423 if lib, ok := m.compiler.(*libraryDecorator); ok {
1424 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1425 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1426
1427 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1428 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1429 }
1430}
1431
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001432func vendorMutator(mctx android.BottomUpMutatorContext) {
1433 if mctx.Os() != android.Android {
1434 return
1435 }
1436
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001437 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1438 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001439 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001440 mctx.CreateVariations(coreMode)
1441 } else if Bool(props.Vendor_available) {
1442 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001443 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001444 mctx.CreateVariations(vendorMode)
1445 } else {
1446 mctx.CreateVariations(coreMode)
1447 }
1448 }
1449 }
1450
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001451 m, ok := mctx.Module().(*Module)
1452 if !ok {
1453 return
1454 }
1455
1456 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001457 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1458
1459 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001460 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001461 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001462 return
1463 }
Logan Chienf3511742017-10-31 18:04:35 +08001464
1465 if vndkdep := m.vndkdep; vndkdep != nil {
1466 if vndkdep.isVndk() {
1467 if vendorSpecific {
1468 if !vndkdep.isVndkExt() {
1469 mctx.PropertyErrorf("vndk",
1470 "must set `extends: \"...\"` to vndk extension")
1471 return
1472 }
1473 } else {
1474 if vndkdep.isVndkExt() {
1475 mctx.PropertyErrorf("vndk",
1476 "must set `vendor: true` to set `extends: %q`",
1477 m.getVndkExtendsModuleName())
1478 return
1479 }
1480 if m.VendorProperties.Vendor_available == nil {
1481 mctx.PropertyErrorf("vndk",
1482 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1483 return
1484 }
1485 }
1486 } else {
1487 if vndkdep.isVndkSp() {
1488 mctx.PropertyErrorf("vndk",
1489 "must set `enabled: true` to set `support_system_process: true`")
1490 return
1491 }
1492 if vndkdep.isVndkExt() {
1493 mctx.PropertyErrorf("vndk",
1494 "must set `enabled: true` to set `extends: %q`",
1495 m.getVndkExtendsModuleName())
1496 return
1497 }
Justin Yun8effde42017-06-23 19:24:43 +09001498 }
1499 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001500
Justin Yun71549282017-11-17 12:10:28 +09001501 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001502 // If the device isn't compiling against the VNDK, we always
1503 // use the core mode.
1504 mctx.CreateVariations(coreMode)
1505 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1506 // LL-NDK stubs only exist in the vendor variant, since the
1507 // real libraries will be used in the core variant.
1508 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001509 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1510 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001511 mod := mctx.CreateVariations(vendorMode)
1512 vendor := mod[0].(*Module)
1513 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001514 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001515 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1516 // PRODUCT_EXTRA_VNDK_VERSIONS.
1517 mod := mctx.CreateVariations(vendorMode)
1518 vendor := mod[0].(*Module)
1519 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001520 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001521 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001522 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001523 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001524 vendor := mod[1].(*Module)
1525 vendor.Properties.UseVndk = true
1526 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001527 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001528 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001529 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001530 vendor := mod[0].(*Module)
1531 vendor.Properties.UseVndk = true
1532 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001533 } else {
1534 // This is either in /system (or similar: /data), or is a
1535 // modules built with the NDK. Modules built with the NDK
1536 // will be restricted using the existing link type checks.
1537 mctx.CreateVariations(coreMode)
1538 }
1539}
1540
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001541func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001542 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001543 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1544 }
Colin Cross6510f912017-11-29 00:27:14 -08001545 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001546}
1547
Colin Cross06a931b2015-10-28 17:23:31 -07001548var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001549var BoolPtr = proptools.BoolPtr
1550var String = proptools.String
1551var StringPtr = proptools.StringPtr