blob: 9c3de097ce3fe8a5832ab2b82564699e377361a7 [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
Ivan Lozanoa9255a82018-03-13 10:41:07 -070055 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator())
Ivan Lozano30c5db22018-02-21 15:49:20 -080056
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000057 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080058 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070059
60 ctx.TopDown("lto_deps", ltoDepsMutator)
61 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070062 })
Colin Crossb98c8b02016-07-29 13:44:28 -070063
64 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070065}
66
Colin Crossca860ac2016-01-04 14:34:37 -080067type Deps struct {
68 SharedLibs, LateSharedLibs []string
69 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080070 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080071 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070072
Colin Cross5950f382016-12-13 12:50:57 -080073 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070074
Colin Cross81413472016-04-11 14:37:39 -070075 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070076
Dan Willemsenb40aab62016-04-20 14:21:14 -070077 GeneratedSources []string
78 GeneratedHeaders []string
79
Dan Willemsenb3454ab2016-09-28 17:34:58 -070080 ReexportGeneratedHeaders []string
81
Colin Cross97ba0732015-03-23 17:50:24 -070082 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070083 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070084}
85
Colin Crossca860ac2016-01-04 14:34:37 -080086type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070087 // Paths to .so files
88 SharedLibs, LateSharedLibs android.Paths
89 // Paths to the dependencies to use for .so files (.so.toc files)
90 SharedLibsDeps, LateSharedLibsDeps android.Paths
91 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070092 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070093
Colin Cross26c34ed2016-09-30 17:10:16 -070094 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070095 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080096 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070097 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070098
Colin Cross26c34ed2016-09-30 17:10:16 -070099 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700100 GeneratedSources android.Paths
101 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700102
Dan Willemsen76f08272016-07-09 00:14:08 -0700103 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700104 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700105
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700107 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700108 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700109}
110
Colin Crossca860ac2016-01-04 14:34:37 -0800111type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700112 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
113 ArFlags []string // Flags that apply to ar
114 AsFlags []string // Flags that apply to assembly source files
115 CFlags []string // Flags that apply to C and C++ source files
116 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
117 ConlyFlags []string // Flags that apply to C source files
118 CppFlags []string // Flags that apply to C++ source files
119 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
120 YaccFlags []string // Flags that apply to Yacc source files
121 protoFlags []string // Flags that apply to proto source files
Joe Onorato09e94ab2017-11-18 18:23:14 -0800122 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700123 aidlFlags []string // Flags that apply to aidl source files
124 rsFlags []string // Flags that apply to renderscript source files
125 LdFlags []string // Flags that apply to linker command lines
126 libFlags []string // Flags to add libraries early to the link order
127 TidyFlags []string // Flags that apply to clang-tidy
128 SAbiFlags []string // Flags that apply to header-abi-dumper
129 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700130
Colin Crossc3199482017-03-30 15:03:04 -0700131 // Global include flags that apply to C, C++, and assembly source files
132 // These must be after any module include flags, which will be in GlobalFlags.
133 SystemIncludeFlags []string
134
Colin Crossb98c8b02016-07-29 13:44:28 -0700135 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700136 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700137 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800138 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800139 SAbiDump bool
Dan Willemsenab9f4262018-02-14 13:58:34 -0800140 ProtoRoot bool
Colin Crossca860ac2016-01-04 14:34:37 -0800141
142 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800143 DynamicLinker string
144
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700145 CFlagsDeps android.Paths // Files depended on by compiler flags
146 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800147
148 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800149 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700150}
151
Colin Cross81413472016-04-11 14:37:39 -0700152type ObjectLinkerProperties struct {
153 // names of other cc_object modules to link into this module using partial linking
154 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700155
156 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800157 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700158}
159
Colin Crossca860ac2016-01-04 14:34:37 -0800160// Properties used to compile all C or C++ modules
161type BaseProperties struct {
162 // compile module with clang instead of gcc
163 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700164
165 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800166 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700167
Logan Chien43d34c32017-12-20 01:17:32 +0800168 AndroidMkSharedLibs []string `blueprint:"mutated"`
169 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
170 HideFromMake bool `blueprint:"mutated"`
171 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700172
173 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800174
175 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
176 // file
177 Logtags []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700178}
179
180type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900181 // whether this module should be allowed to be directly depended by other
182 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
183 // If set to true, two variants will be built separately, one like
184 // normal, and the other limited to the set of libraries and headers
185 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700186 //
187 // The vendor variant may be used with a different (newer) /system,
188 // so it shouldn't have any unversioned runtime dependencies, or
189 // make assumptions about the system that may not be true in the
190 // future.
191 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900192 // If set to false, this module becomes inaccessible from /vendor modules.
193 //
194 // Default value is true when vndk: {enabled: true} or vendor: true.
195 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700196 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
197 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900198
199 // whether this module is capable of being loaded with other instance
200 // (possibly an older version) of the same module in the same process.
201 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
202 // can be double loaded in a vendor process if the library is also a
203 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
204 // explicitly marked as `double_loadable: true` by the owner, or the dependency
205 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
206 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800207}
208
Colin Crossca860ac2016-01-04 14:34:37 -0800209type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800210 static() bool
211 staticBinary() bool
212 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700213 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700214 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800215 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700216 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900217 isVndk() bool
218 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800219 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800220 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700221 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700222 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800223 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800224 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800225}
226
227type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700228 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800229 ModuleContextIntf
230}
231
232type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700233 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800234 ModuleContextIntf
235}
236
Colin Cross37047f12016-12-13 17:06:13 -0800237type DepsContext interface {
238 android.BottomUpMutatorContext
239 ModuleContextIntf
240}
241
Colin Crossca860ac2016-01-04 14:34:37 -0800242type feature interface {
243 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800244 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800245 flags(ctx ModuleContext, flags Flags) Flags
246 props() []interface{}
247}
248
249type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700250 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800251 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800252 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700253 compilerProps() []interface{}
254
Colin Cross76fada02016-07-27 10:31:13 -0700255 appendCflags([]string)
256 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700257 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800258}
259
260type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700261 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800262 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700263 linkerFlags(ctx ModuleContext, flags Flags) Flags
264 linkerProps() []interface{}
265
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700266 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700267 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800268}
269
270type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700271 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700272 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800273 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700274 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700275 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800276}
277
Colin Crossc99deeb2016-04-11 15:06:20 -0700278type dependencyTag struct {
279 blueprint.BaseDependencyTag
280 name string
281 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700282
283 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700284}
285
286var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700287 sharedDepTag = dependencyTag{name: "shared", library: true}
288 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
289 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
290 staticDepTag = dependencyTag{name: "static", library: true}
291 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
292 lateStaticDepTag = dependencyTag{name: "late static", library: true}
293 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800294 headerDepTag = dependencyTag{name: "header", library: true}
295 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700296 genSourceDepTag = dependencyTag{name: "gen source"}
297 genHeaderDepTag = dependencyTag{name: "gen header"}
298 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
299 objDepTag = dependencyTag{name: "obj"}
300 crtBeginDepTag = dependencyTag{name: "crtbegin"}
301 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700302 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700303 reuseObjTag = dependencyTag{name: "reuse objects"}
304 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
305 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800306 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800307 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700308)
309
Colin Crossca860ac2016-01-04 14:34:37 -0800310// Module contains the properties and members used by all C/C++ module types, and implements
311// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
312// to construct the output file. Behavior can be customized with a Customizer interface
313type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700314 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700315 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700316
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700317 Properties BaseProperties
318 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700319
Colin Crossca860ac2016-01-04 14:34:37 -0800320 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700321 hod android.HostOrDeviceSupported
322 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700323
Colin Crossca860ac2016-01-04 14:34:37 -0800324 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700325 features []feature
326 compiler compiler
327 linker linker
328 installer installer
329 stl *stl
330 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800331 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800332 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900333 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700334 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700335 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800336
337 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700338
Colin Cross635c3b02016-05-18 15:37:25 -0700339 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800340
Colin Crossb98c8b02016-07-29 13:44:28 -0700341 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700342
343 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800344
345 // Flags used to compile this module
346 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700347
348 // 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 -0800349 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700350 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800351 depsInLinkOrder android.Paths
352
353 // only non-nil when this is a shared library that reuses the objects of a static library
354 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700355}
356
Colin Cross36242852017-06-23 15:06:31 -0700357func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700358 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800359 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700360 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800361 }
362 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700363 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800364 }
365 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700366 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800367 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700368 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700369 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700370 }
Colin Cross16b23492016-01-06 14:41:07 -0800371 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700372 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800373 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800374 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700375 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800376 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800377 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700378 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800379 }
Justin Yun8effde42017-06-23 19:24:43 +0900380 if c.vndkdep != nil {
381 c.AddProperties(c.vndkdep.props()...)
382 }
Stephen Craneba090d12017-05-09 15:44:35 -0700383 if c.lto != nil {
384 c.AddProperties(c.lto.props()...)
385 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700386 if c.pgo != nil {
387 c.AddProperties(c.pgo.props()...)
388 }
Colin Crossca860ac2016-01-04 14:34:37 -0800389 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700390 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800391 }
Colin Crossc472d572015-03-17 15:06:21 -0700392
Colin Cross36242852017-06-23 15:06:31 -0700393 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700394
Colin Cross1f44a3a2017-07-07 14:33:33 -0700395 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700396
397 return c
Colin Crossc472d572015-03-17 15:06:21 -0700398}
399
Colin Crossb916a382016-07-29 17:28:03 -0700400// Returns true for dependency roots (binaries)
401// TODO(ccross): also handle dlopenable libraries
402func (c *Module) isDependencyRoot() bool {
403 if root, ok := c.linker.(interface {
404 isDependencyRoot() bool
405 }); ok {
406 return root.isDependencyRoot()
407 }
408 return false
409}
410
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700411func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700412 return c.Properties.UseVndk
413}
414
Justin Yun8effde42017-06-23 19:24:43 +0900415func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800416 if vndkdep := c.vndkdep; vndkdep != nil {
417 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900418 }
419 return false
420}
421
Yi Kong7e53c572018-02-14 18:16:12 +0800422func (c *Module) isPgoCompile() bool {
423 if pgo := c.pgo; pgo != nil {
424 return pgo.Properties.PgoCompile
425 }
426 return false
427}
428
Logan Chienf3511742017-10-31 18:04:35 +0800429func (c *Module) isVndkSp() bool {
430 if vndkdep := c.vndkdep; vndkdep != nil {
431 return vndkdep.isVndkSp()
432 }
433 return false
434}
435
436func (c *Module) isVndkExt() bool {
437 if vndkdep := c.vndkdep; vndkdep != nil {
438 return vndkdep.isVndkExt()
439 }
440 return false
441}
442
443func (c *Module) getVndkExtendsModuleName() string {
444 if vndkdep := c.vndkdep; vndkdep != nil {
445 return vndkdep.getVndkExtendsModuleName()
446 }
447 return ""
448}
449
Jiyong Park82e2bf32017-08-16 14:05:54 +0900450// Returns true only when this module is configured to have core and vendor
451// variants.
452func (c *Module) hasVendorVariant() bool {
453 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
454}
455
Colin Crossca860ac2016-01-04 14:34:37 -0800456type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700457 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800458 moduleContextImpl
459}
460
Colin Cross37047f12016-12-13 17:06:13 -0800461type depsContext struct {
462 android.BottomUpMutatorContext
463 moduleContextImpl
464}
465
Colin Crossca860ac2016-01-04 14:34:37 -0800466type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700467 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800468 moduleContextImpl
469}
470
Jiyong Park2db76922017-11-08 16:03:48 +0900471func (ctx *moduleContext) SocSpecific() bool {
472 return ctx.ModuleContext.SocSpecific() ||
473 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700474}
475
Colin Crossca860ac2016-01-04 14:34:37 -0800476type moduleContextImpl struct {
477 mod *Module
478 ctx BaseModuleContext
479}
480
Colin Crossca860ac2016-01-04 14:34:37 -0800481func (ctx *moduleContextImpl) clang() bool {
482 return ctx.mod.clang(ctx.ctx)
483}
484
Colin Crossb98c8b02016-07-29 13:44:28 -0700485func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800486 return ctx.mod.toolchain(ctx.ctx)
487}
488
489func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000490 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800491}
492
493func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700494 if static, ok := ctx.mod.linker.(interface {
495 staticBinary() bool
496 }); ok {
497 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800498 }
Colin Crossb916a382016-07-29 17:28:03 -0700499 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800500}
501
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700502func (ctx *moduleContextImpl) useSdk() bool {
503 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800504 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700505 }
506 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800507}
508
509func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700510 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700511 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900512 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700513 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900514 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
515 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
516 return "current"
517 }
518 return platform_vndk_ver
519 }
520 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800521 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900522 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700523 }
524 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800525}
526
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700527func (ctx *moduleContextImpl) useVndk() bool {
528 return ctx.mod.useVndk()
529}
Justin Yun8effde42017-06-23 19:24:43 +0900530
Logan Chienf3511742017-10-31 18:04:35 +0800531func (ctx *moduleContextImpl) isVndk() bool {
532 return ctx.mod.isVndk()
533}
534
Yi Kong7e53c572018-02-14 18:16:12 +0800535func (ctx *moduleContextImpl) isPgoCompile() bool {
536 return ctx.mod.isPgoCompile()
537}
538
Justin Yun8effde42017-06-23 19:24:43 +0900539func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800540 return ctx.mod.isVndkSp()
541}
542
543func (ctx *moduleContextImpl) isVndkExt() bool {
544 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900545}
546
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800547// Create source abi dumps if the module belongs to the list of VndkLibraries.
548func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdharyb391fea2018-01-29 15:01:20 -0800549 skipAbiChecks := ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS")
Jayant Chowdharyb7e08ca2018-05-10 15:29:24 -0700550 isVariantOnProductionDevice := true
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800551 sanitize := ctx.mod.sanitize
552 if sanitize != nil {
Jayant Chowdharyb7e08ca2018-05-10 15:29:24 -0700553 isVariantOnProductionDevice = sanitize.isVariantOnProductionDevice()
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800554 }
Jayant Chowdhary22963cd2018-03-06 14:59:50 -0800555 vendorAvailable := Bool(ctx.mod.VendorProperties.Vendor_available)
Jayant Chowdharyb7e08ca2018-05-10 15:29:24 -0700556 return !skipAbiChecks && isVariantOnProductionDevice && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk() && vendorAvailable) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800557}
558
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700559func (ctx *moduleContextImpl) selectedStl() string {
560 if stl := ctx.mod.stl; stl != nil {
561 return stl.Properties.SelectedStl
562 }
563 return ""
564}
565
Colin Crossce75d2c2016-10-06 16:12:58 -0700566func (ctx *moduleContextImpl) baseModuleName() string {
567 return ctx.mod.ModuleBase.BaseModuleName()
568}
569
Logan Chienf3511742017-10-31 18:04:35 +0800570func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
571 return ctx.mod.getVndkExtendsModuleName()
572}
573
Colin Cross635c3b02016-05-18 15:37:25 -0700574func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800575 return &Module{
576 hod: hod,
577 multilib: multilib,
578 }
579}
580
Colin Cross635c3b02016-05-18 15:37:25 -0700581func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800582 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700583 module.features = []feature{
584 &tidyFeature{},
585 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700586 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800587 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800588 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800589 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900590 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700591 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700592 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800593 return module
594}
595
Colin Crossce75d2c2016-10-06 16:12:58 -0700596func (c *Module) Prebuilt() *android.Prebuilt {
597 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
598 return p.prebuilt()
599 }
600 return nil
601}
602
603func (c *Module) Name() string {
604 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700605 if p, ok := c.linker.(interface {
606 Name(string) string
607 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700608 name = p.Name(name)
609 }
610 return name
611}
612
Jeff Gaston294356f2017-09-27 17:05:30 -0700613// orderDeps reorders dependencies into a list such that if module A depends on B, then
614// A will precede B in the resultant list.
615// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800616// Note that directSharedDeps should be the analogous static library for each shared lib dep
617func 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 -0700618 // If A depends on B, then
619 // Every list containing A will also contain B later in the list
620 // So, after concatenating all lists, the final instance of B will have come from the same
621 // original list as the final instance of A
622 // So, the final instance of B will be later in the concatenation than the final A
623 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
624 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800625 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700626 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800627 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
628 }
629 for _, dep := range directSharedDeps {
630 orderedAllDeps = append(orderedAllDeps, dep)
631 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700632 }
633
Colin Crossb6715442017-10-24 11:13:31 -0700634 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700635
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800636 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700637 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800638 // resultant list to only what the caller has chosen to include in directStaticDeps
639 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700640
641 return orderedAllDeps, orderedDeclaredDeps
642}
643
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800644func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
645 // convert Module to Path
646 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
647 staticDepFiles := []android.Path{}
648 for _, dep := range staticDeps {
649 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
650 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700651 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800652 sharedDepFiles := []android.Path{}
653 for _, sharedDep := range sharedDeps {
654 staticAnalogue := sharedDep.staticVariant
655 if staticAnalogue != nil {
656 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
657 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
658 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700659 }
660
661 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800662 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700663
664 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700665}
666
Colin Cross635c3b02016-05-18 15:37:25 -0700667func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800668 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700669 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800670 moduleContextImpl: moduleContextImpl{
671 mod: c,
672 },
673 }
674 ctx.ctx = ctx
675
Colin Crossf18e1102017-11-16 14:33:08 -0800676 deps := c.depsToPaths(ctx)
677 if ctx.Failed() {
678 return
679 }
680
Colin Crossca860ac2016-01-04 14:34:37 -0800681 flags := Flags{
682 Toolchain: c.toolchain(ctx),
683 Clang: c.clang(ctx),
684 }
Colin Crossca860ac2016-01-04 14:34:37 -0800685 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800686 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800687 }
688 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700689 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800690 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700691 if c.stl != nil {
692 flags = c.stl.flags(ctx, flags)
693 }
Colin Cross16b23492016-01-06 14:41:07 -0800694 if c.sanitize != nil {
695 flags = c.sanitize.flags(ctx, flags)
696 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800697 if c.coverage != nil {
698 flags = c.coverage.flags(ctx, flags)
699 }
Stephen Craneba090d12017-05-09 15:44:35 -0700700 if c.lto != nil {
701 flags = c.lto.flags(ctx, flags)
702 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700703 if c.pgo != nil {
704 flags = c.pgo.flags(ctx, flags)
705 }
Colin Crossca860ac2016-01-04 14:34:37 -0800706 for _, feature := range c.features {
707 flags = feature.flags(ctx, flags)
708 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800709 if ctx.Failed() {
710 return
711 }
712
Colin Crossb98c8b02016-07-29 13:44:28 -0700713 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
714 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
715 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800716
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800717 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
718 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700719 // We need access to all the flags seen by a source file.
720 if c.sabi != nil {
721 flags = c.sabi.flags(ctx, flags)
722 }
Colin Crossca860ac2016-01-04 14:34:37 -0800723 // Optimization to reduce size of build.ninja
724 // Replace the long list of flags for each file with a module-local variable
725 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
726 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
727 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
728 flags.CFlags = []string{"$cflags"}
729 flags.CppFlags = []string{"$cppflags"}
730 flags.AsFlags = []string{"$asflags"}
731
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700732 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800733 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700734 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800735 if ctx.Failed() {
736 return
737 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800738 }
739
Colin Crossca860ac2016-01-04 14:34:37 -0800740 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700741 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800742 if ctx.Failed() {
743 return
744 }
Colin Cross635c3b02016-05-18 15:37:25 -0700745 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700746 }
Colin Cross5049f022015-03-18 13:28:46 -0700747
Colin Crossce75d2c2016-10-06 16:12:58 -0700748 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
749 c.installer.install(ctx, c.outputFile.Path())
750 if ctx.Failed() {
751 return
Colin Crossca860ac2016-01-04 14:34:37 -0800752 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700753 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800754}
755
Colin Crossb98c8b02016-07-29 13:44:28 -0700756func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800757 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700758 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800759 }
Colin Crossca860ac2016-01-04 14:34:37 -0800760 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800761}
762
Colin Crossca860ac2016-01-04 14:34:37 -0800763func (c *Module) begin(ctx BaseModuleContext) {
764 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700765 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700766 }
Colin Crossca860ac2016-01-04 14:34:37 -0800767 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700768 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800769 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700770 if c.stl != nil {
771 c.stl.begin(ctx)
772 }
Colin Cross16b23492016-01-06 14:41:07 -0800773 if c.sanitize != nil {
774 c.sanitize.begin(ctx)
775 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800776 if c.coverage != nil {
777 c.coverage.begin(ctx)
778 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800779 if c.sabi != nil {
780 c.sabi.begin(ctx)
781 }
Justin Yun8effde42017-06-23 19:24:43 +0900782 if c.vndkdep != nil {
783 c.vndkdep.begin(ctx)
784 }
Stephen Craneba090d12017-05-09 15:44:35 -0700785 if c.lto != nil {
786 c.lto.begin(ctx)
787 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700788 if c.pgo != nil {
789 c.pgo.begin(ctx)
790 }
Colin Crossca860ac2016-01-04 14:34:37 -0800791 for _, feature := range c.features {
792 feature.begin(ctx)
793 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700794 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700795 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700796 if err != nil {
797 ctx.PropertyErrorf("sdk_version", err.Error())
798 }
Nan Zhang0007d812017-11-07 10:57:05 -0800799 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700800 }
Colin Crossca860ac2016-01-04 14:34:37 -0800801}
802
Colin Cross37047f12016-12-13 17:06:13 -0800803func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700804 deps := Deps{}
805
806 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700807 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700808 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000809 // Add the PGO dependency (the clang_rt.profile runtime library), which
810 // sometimes depends on symbols from libgcc, before libgcc gets added
811 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700812 if c.pgo != nil {
813 deps = c.pgo.deps(ctx, deps)
814 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700815 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700816 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700817 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700818 if c.stl != nil {
819 deps = c.stl.deps(ctx, deps)
820 }
Colin Cross16b23492016-01-06 14:41:07 -0800821 if c.sanitize != nil {
822 deps = c.sanitize.deps(ctx, deps)
823 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000824 if c.coverage != nil {
825 deps = c.coverage.deps(ctx, deps)
826 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800827 if c.sabi != nil {
828 deps = c.sabi.deps(ctx, deps)
829 }
Justin Yun8effde42017-06-23 19:24:43 +0900830 if c.vndkdep != nil {
831 deps = c.vndkdep.deps(ctx, deps)
832 }
Stephen Craneba090d12017-05-09 15:44:35 -0700833 if c.lto != nil {
834 deps = c.lto.deps(ctx, deps)
835 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700836 for _, feature := range c.features {
837 deps = feature.deps(ctx, deps)
838 }
839
Colin Crossb6715442017-10-24 11:13:31 -0700840 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
841 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
842 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
843 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
844 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
845 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800846 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700847
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700848 for _, lib := range deps.ReexportSharedLibHeaders {
849 if !inList(lib, deps.SharedLibs) {
850 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
851 }
852 }
853
854 for _, lib := range deps.ReexportStaticLibHeaders {
855 if !inList(lib, deps.StaticLibs) {
856 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
857 }
858 }
859
Colin Cross5950f382016-12-13 12:50:57 -0800860 for _, lib := range deps.ReexportHeaderLibHeaders {
861 if !inList(lib, deps.HeaderLibs) {
862 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
863 }
864 }
865
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700866 for _, gen := range deps.ReexportGeneratedHeaders {
867 if !inList(gen, deps.GeneratedHeaders) {
868 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
869 }
870 }
871
Colin Crossc99deeb2016-04-11 15:06:20 -0700872 return deps
873}
874
Dan Albert7e9d2952016-08-04 13:02:36 -0700875func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800876 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700877 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800878 moduleContextImpl: moduleContextImpl{
879 mod: c,
880 },
881 }
882 ctx.ctx = ctx
883
Colin Crossca860ac2016-01-04 14:34:37 -0800884 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700885}
886
Colin Cross1e676be2016-10-12 14:38:15 -0700887func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
888 if !c.Enabled() {
889 return
890 }
891
Colin Cross37047f12016-12-13 17:06:13 -0800892 ctx := &depsContext{
893 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700894 moduleContextImpl: moduleContextImpl{
895 mod: c,
896 },
897 }
898 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800899
Colin Crossc99deeb2016-04-11 15:06:20 -0700900 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800901
Dan Albert914449f2016-06-17 16:45:24 -0700902 variantNdkLibs := []string{}
903 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700904 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700905 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700906
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700907 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
908 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700909 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700910 // 1. Name of an NDK library that refers to a prebuilt module.
911 // For each of these, it adds the name of the prebuilt module (which will be in
912 // prebuilts/ndk) to the list of nonvariant libs.
913 // 2. Name of an NDK library that refers to an ndk_library module.
914 // For each of these, it adds the name of the ndk_library module to the list of
915 // variant libs.
916 // 3. Anything else (so anything that isn't an NDK library).
917 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700918 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700919 // The caller can then know to add the variantLibs dependencies differently from the
920 // nonvariantLibs
921 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
922 variantLibs = []string{}
923 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700924 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700925 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700926 if !inList(entry, ndkMigratedLibs) {
927 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
928 } else {
929 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
930 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700931 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700932 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +0900933 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(entry, vendorPublicLibraries) {
934 vendorPublicLib := entry + vendorPublicLibrarySuffix
935 if actx.OtherModuleExists(vendorPublicLib) {
936 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
937 } else {
938 // This can happen if vendor_public_library module is defined in a
939 // namespace that isn't visible to the current module. In that case,
940 // link to the original library.
941 nonvariantLibs = append(nonvariantLibs, entry)
942 }
Dan Albert914449f2016-06-17 16:45:24 -0700943 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700944 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700945 }
946 }
Dan Albert914449f2016-06-17 16:45:24 -0700947 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700948 }
949
Dan Albert914449f2016-06-17 16:45:24 -0700950 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
951 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900952 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700953 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700954
Colin Cross32ec36c2016-12-15 07:39:51 -0800955 for _, lib := range deps.HeaderLibs {
956 depTag := headerDepTag
957 if inList(lib, deps.ReexportHeaderLibHeaders) {
958 depTag = headerExportDepTag
959 }
960 actx.AddVariationDependencies(nil, depTag, lib)
961 }
Colin Cross5950f382016-12-13 12:50:57 -0800962
Colin Crossc99deeb2016-04-11 15:06:20 -0700963 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
964 deps.WholeStaticLibs...)
965
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700966 for _, lib := range deps.StaticLibs {
967 depTag := staticDepTag
968 if inList(lib, deps.ReexportStaticLibHeaders) {
969 depTag = staticExportDepTag
970 }
Colin Cross15a0d462016-07-14 14:49:58 -0700971 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700972 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700973
974 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
975 deps.LateStaticLibs...)
976
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700977 for _, lib := range deps.SharedLibs {
978 depTag := sharedDepTag
979 if inList(lib, deps.ReexportSharedLibHeaders) {
980 depTag = sharedExportDepTag
981 }
Colin Cross15a0d462016-07-14 14:49:58 -0700982 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700983 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700984
985 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
986 deps.LateSharedLibs...)
987
Logan Chien43d34c32017-12-20 01:17:32 +0800988 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, runtimeDepTag,
989 deps.RuntimeLibs...)
990
Colin Cross68861832016-07-08 10:41:41 -0700991 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700992
993 for _, gen := range deps.GeneratedHeaders {
994 depTag := genHeaderDepTag
995 if inList(gen, deps.ReexportGeneratedHeaders) {
996 depTag = genHeaderExportDepTag
997 }
998 actx.AddDependency(c, depTag, gen)
999 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001000
Colin Cross68861832016-07-08 10:41:41 -07001001 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001002
1003 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -07001004 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001005 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001006 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -07001007 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001008 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001009 if deps.LinkerScript != "" {
1010 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
1011 }
Dan Albert914449f2016-06-17 16:45:24 -07001012
1013 version := ctx.sdkVersion()
1014 actx.AddVariationDependencies([]blueprint.Variation{
1015 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
1016 actx.AddVariationDependencies([]blueprint.Variation{
1017 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001018
1019 if vndkdep := c.vndkdep; vndkdep != nil {
1020 if vndkdep.isVndkExt() {
1021 baseModuleMode := vendorMode
1022 if actx.DeviceConfig().VndkVersion() == "" {
1023 baseModuleMode = coreMode
1024 }
1025 actx.AddVariationDependencies([]blueprint.Variation{
1026 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
1027 vndkdep.getVndkExtendsModuleName())
1028 }
1029 }
Colin Cross6362e272015-10-29 15:25:03 -07001030}
Colin Cross21b9a242015-03-24 14:15:58 -07001031
Dan Albert7e9d2952016-08-04 13:02:36 -07001032func beginMutator(ctx android.BottomUpMutatorContext) {
1033 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1034 c.beginMutator(ctx)
1035 }
1036}
1037
Colin Crossca860ac2016-01-04 14:34:37 -08001038func (c *Module) clang(ctx BaseModuleContext) bool {
1039 clang := Bool(c.Properties.Clang)
1040
1041 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001042 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001043 }
Colin Cross28344522015-04-22 13:07:53 -07001044
Colin Crossca860ac2016-01-04 14:34:37 -08001045 if !c.toolchain(ctx).ClangSupported() {
1046 clang = false
1047 }
1048
1049 return clang
1050}
1051
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001052// Whether a module can link to another module, taking into
1053// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001054func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001055 if from.Target().Os != android.Android {
1056 // Host code is not restricted
1057 return
1058 }
1059 if from.Properties.UseVndk {
1060 // Though vendor code is limited by the vendor mutator,
1061 // each vendor-available module needs to check
1062 // link-type for VNDK.
1063 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001064 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001065 }
1066 return
1067 }
Nan Zhang0007d812017-11-07 10:57:05 -08001068 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001069 // Platform code can link to anything
1070 return
1071 }
1072 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1073 // These are always allowed
1074 return
1075 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001076 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1077 // These are allowed, but they don't set sdk_version
1078 return
1079 }
1080 if _, ok := to.linker.(*stubDecorator); ok {
1081 // These aren't real libraries, but are the stub shared libraries that are included in
1082 // the NDK.
1083 return
1084 }
Nan Zhang0007d812017-11-07 10:57:05 -08001085 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001086 // NDK code linking to platform code is never okay.
1087 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1088 ctx.OtherModuleName(to))
1089 }
1090
1091 // At this point we know we have two NDK libraries, but we need to
1092 // check that we're not linking against anything built against a higher
1093 // API level, as it is only valid to link against older or equivalent
1094 // APIs.
1095
Inseob Kim01a28722018-04-11 09:48:45 +09001096 // Current can link against anything.
1097 if String(from.Properties.Sdk_version) != "current" {
1098 // Otherwise we need to check.
1099 if String(to.Properties.Sdk_version) == "current" {
1100 // Current can't be linked against by anything else.
1101 ctx.ModuleErrorf("links %q built against newer API version %q",
1102 ctx.OtherModuleName(to), "current")
1103 } else {
1104 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1105 if err != nil {
1106 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001107 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001108 String(from.Properties.Sdk_version))
1109 }
1110 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1111 if err != nil {
1112 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001113 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001114 String(to.Properties.Sdk_version))
1115 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001116
Inseob Kim01a28722018-04-11 09:48:45 +09001117 if toApi > fromApi {
1118 ctx.ModuleErrorf("links %q built against newer API version %q",
1119 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1120 }
1121 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001122 }
Dan Albert202fe492017-12-15 13:56:59 -08001123
1124 // Also check that the two STL choices are compatible.
1125 fromStl := from.stl.Properties.SelectedStl
1126 toStl := to.stl.Properties.SelectedStl
1127 if fromStl == "" || toStl == "" {
1128 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001129 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001130 // We can be permissive with the system "STL" since it is only the C++
1131 // ABI layer, but in the future we should make sure that everyone is
1132 // using either libc++ or nothing.
Inseob Kimda2171a2018-04-11 15:41:38 +09001133 } else if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
Dan Albert202fe492017-12-15 13:56:59 -08001134 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1135 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1136 to.stl.Properties.SelectedStl)
1137 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001138}
1139
Jiyong Park5fb8c102018-04-09 12:03:06 +09001140// Tests whether the dependent library is okay to be double loaded inside a single process.
1141// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1142// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1143// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1144func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1145 if _, ok := from.linker.(*libraryDecorator); !ok {
1146 return
1147 }
1148
1149 if inList(ctx.ModuleName(), llndkLibraries) ||
1150 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1151 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1152 depIsVndkSp := false
1153 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1154 depIsVndkSp = true
1155 }
1156 depIsVndk := false
1157 if to.vndkdep != nil && to.vndkdep.isVndk() {
1158 depIsVndk = true
1159 }
1160 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1161 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
1162 ctx.ModuleErrorf("links VNDK library %q that isn't double_loadable.",
1163 ctx.OtherModuleName(to))
1164 }
1165 }
1166}
1167
Colin Crossc99deeb2016-04-11 15:06:20 -07001168// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001169func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001170 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001171
Jeff Gaston294356f2017-09-27 17:05:30 -07001172 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001173 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001174
Colin Crossd11fcda2017-10-23 17:59:01 -07001175 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001176 depName := ctx.OtherModuleName(dep)
1177 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001178
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001179 ccDep, _ := dep.(*Module)
1180 if ccDep == nil {
1181 // handling for a few module types that aren't cc Module but that are also supported
1182 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001183 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001184 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001185 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001186 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001187 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1188 genRule.GeneratedSourceFiles()...)
1189 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001190 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001191 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001192 // Support exported headers from a generated_sources dependency
1193 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001194 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001195 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001196 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001197 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001198 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001199 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001200 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001201 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001202 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001203 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001204 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1205 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1206
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001207 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001208 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001209 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001210 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001211 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001212 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001213 files := genRule.GeneratedSourceFiles()
1214 if len(files) == 1 {
1215 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1216 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001218 }
1219 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001220 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001221 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001222 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001223 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001224 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001225 return
1226 }
1227
Colin Crossd11fcda2017-10-23 17:59:01 -07001228 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001229 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1230 return
1231 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001232 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001233 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001234 return
1235 }
1236
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001237 // re-exporting flags
1238 if depTag == reuseObjTag {
1239 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001240 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001241 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001242 depPaths.Objs = depPaths.Objs.Append(objs)
1243 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001244 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001245 return
1246 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001247 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001248 if t, ok := depTag.(dependencyTag); ok && t.library {
1249 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001250 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001251 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001252 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001253 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001254
1255 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001256 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001257 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001258 // 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 -07001259 // Re-exported shared library headers must be included as well since they can help us with type information
1260 // about template instantiations (instantiated from their headers).
1261 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001262 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001263 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001264
Logan Chienf3511742017-10-31 18:04:35 +08001265 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001266 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001267 }
1268
Colin Cross26c34ed2016-09-30 17:10:16 -07001269 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001270 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001271
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001272 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001273 depFile := android.OptionalPath{}
1274
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001275 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001276 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001277 ptr = &depPaths.SharedLibs
1278 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001279 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001280 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001281 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001282 ptr = &depPaths.LateSharedLibs
1283 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001284 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001285 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001286 ptr = nil
1287 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001288 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001289 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001290 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001291 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001292 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001293 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001294 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001295 return
1296 }
1297
1298 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001299 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001300 for i := range missingDeps {
1301 missingDeps[i] += postfix
1302 }
1303 ctx.AddMissingDependencies(missingDeps)
1304 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001305 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001306 case headerDepTag:
1307 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001308 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001309 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001310 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001311 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001312 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001313 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001314 }
1315
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001316 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001317 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001318 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001319 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001320 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001321 return
1322 }
1323
1324 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001325 // in static libraries act as if they were whole static libraries. The same goes for
1326 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001327 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1328 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001329 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1330 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001331
Dan Willemsen581341d2017-02-09 16:16:31 -08001332 }
1333
Colin Cross26c34ed2016-09-30 17:10:16 -07001334 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001335 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001336 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001337 return
1338 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001339 *ptr = append(*ptr, linkFile.Path())
1340 }
1341
Colin Crossc99deeb2016-04-11 15:06:20 -07001342 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001343 dep := depFile
1344 if !dep.Valid() {
1345 dep = linkFile
1346 }
1347 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001348 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001349
Logan Chien43d34c32017-12-20 01:17:32 +08001350 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001351 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001352 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001353 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001354 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001355 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001356 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1357 if c.useVndk() && bothVendorAndCoreVariantsExist {
1358 // The vendor module in Make will have been renamed to not conflict with the core
1359 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001360 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001361 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001362 return libName + vendorPublicLibrarySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001363 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001364 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001365 }
Logan Chien43d34c32017-12-20 01:17:32 +08001366 }
1367
1368 // Export the shared libs to Make.
1369 switch depTag {
1370 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Park27b188b2017-07-18 13:23:39 +09001371 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001372 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001373 c.Properties.AndroidMkSharedLibs = append(
1374 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
1375 case runtimeDepTag:
1376 c.Properties.AndroidMkRuntimeLibs = append(
1377 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001378 }
Colin Crossca860ac2016-01-04 14:34:37 -08001379 })
1380
Jeff Gaston294356f2017-09-27 17:05:30 -07001381 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001382 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001383
Colin Crossdd84e052017-05-17 13:44:16 -07001384 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001385 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001386 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001387 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001388 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1389
1390 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001391 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001392 }
Colin Crossdd84e052017-05-17 13:44:16 -07001393
Colin Crossca860ac2016-01-04 14:34:37 -08001394 return depPaths
1395}
1396
1397func (c *Module) InstallInData() bool {
1398 if c.installer == nil {
1399 return false
1400 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001401 return c.installer.inData()
1402}
1403
1404func (c *Module) InstallInSanitizerDir() bool {
1405 if c.installer == nil {
1406 return false
1407 }
1408 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001409 return true
1410 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001411 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001412}
1413
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001414func (c *Module) HostToolPath() android.OptionalPath {
1415 if c.installer == nil {
1416 return android.OptionalPath{}
1417 }
1418 return c.installer.hostToolPath()
1419}
1420
Nan Zhangd4e641b2017-07-12 12:55:28 -07001421func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1422 return c.outputFile
1423}
1424
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001425func (c *Module) Srcs() android.Paths {
1426 if c.outputFile.Valid() {
1427 return android.Paths{c.outputFile.Path()}
1428 }
1429 return android.Paths{}
1430}
1431
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001432func (c *Module) static() bool {
1433 if static, ok := c.linker.(interface {
1434 static() bool
1435 }); ok {
1436 return static.static()
1437 }
1438 return false
1439}
1440
Colin Cross2ba19d92015-05-07 15:44:20 -07001441//
Colin Crosscfad1192015-11-02 16:43:11 -08001442// Defaults
1443//
Colin Crossca860ac2016-01-04 14:34:37 -08001444type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001445 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001446 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001447}
1448
Colin Cross635c3b02016-05-18 15:37:25 -07001449func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001450}
1451
Colin Cross1e676be2016-10-12 14:38:15 -07001452func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1453}
1454
Colin Cross36242852017-06-23 15:06:31 -07001455func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001456 return DefaultsFactory()
1457}
1458
Colin Cross36242852017-06-23 15:06:31 -07001459func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001460 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001461
Colin Cross36242852017-06-23 15:06:31 -07001462 module.AddProperties(props...)
1463 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001464 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001465 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001466 &BaseCompilerProperties{},
1467 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001468 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001469 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001470 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001471 &TestProperties{},
1472 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001473 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001474 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001475 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001476 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001477 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001478 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001479 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001480 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001481 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001482 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001483 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001484 )
Colin Crosscfad1192015-11-02 16:43:11 -08001485
Colin Cross1f44a3a2017-07-07 14:33:33 -07001486 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001487
1488 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001489}
1490
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001491const (
1492 // coreMode is the variant used for framework-private libraries, or
1493 // SDK libraries. (which framework-private libraries can use)
1494 coreMode = "core"
1495
1496 // vendorMode is the variant used for /vendor code that compiles
1497 // against the VNDK.
1498 vendorMode = "vendor"
1499)
1500
Jiyong Park6a43f042017-10-12 23:05:00 +09001501func squashVendorSrcs(m *Module) {
1502 if lib, ok := m.compiler.(*libraryDecorator); ok {
1503 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1504 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1505
1506 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1507 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1508 }
1509}
1510
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001511func vendorMutator(mctx android.BottomUpMutatorContext) {
1512 if mctx.Os() != android.Android {
1513 return
1514 }
1515
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001516 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1517 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001518 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001519 mctx.CreateVariations(coreMode)
1520 } else if Bool(props.Vendor_available) {
1521 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001522 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001523 mctx.CreateVariations(vendorMode)
1524 } else {
1525 mctx.CreateVariations(coreMode)
1526 }
1527 }
1528 }
1529
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001530 m, ok := mctx.Module().(*Module)
1531 if !ok {
1532 return
1533 }
1534
1535 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001536 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1537
1538 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001539 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001540 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001541 return
1542 }
Logan Chienf3511742017-10-31 18:04:35 +08001543
1544 if vndkdep := m.vndkdep; vndkdep != nil {
1545 if vndkdep.isVndk() {
1546 if vendorSpecific {
1547 if !vndkdep.isVndkExt() {
1548 mctx.PropertyErrorf("vndk",
1549 "must set `extends: \"...\"` to vndk extension")
1550 return
1551 }
1552 } else {
1553 if vndkdep.isVndkExt() {
1554 mctx.PropertyErrorf("vndk",
1555 "must set `vendor: true` to set `extends: %q`",
1556 m.getVndkExtendsModuleName())
1557 return
1558 }
1559 if m.VendorProperties.Vendor_available == nil {
1560 mctx.PropertyErrorf("vndk",
1561 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1562 return
1563 }
1564 }
1565 } else {
1566 if vndkdep.isVndkSp() {
1567 mctx.PropertyErrorf("vndk",
1568 "must set `enabled: true` to set `support_system_process: true`")
1569 return
1570 }
1571 if vndkdep.isVndkExt() {
1572 mctx.PropertyErrorf("vndk",
1573 "must set `enabled: true` to set `extends: %q`",
1574 m.getVndkExtendsModuleName())
1575 return
1576 }
Justin Yun8effde42017-06-23 19:24:43 +09001577 }
1578 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001579
Justin Yun71549282017-11-17 12:10:28 +09001580 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001581 // If the device isn't compiling against the VNDK, we always
1582 // use the core mode.
1583 mctx.CreateVariations(coreMode)
1584 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1585 // LL-NDK stubs only exist in the vendor variant, since the
1586 // real libraries will be used in the core variant.
1587 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001588 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1589 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001590 mod := mctx.CreateVariations(vendorMode)
1591 vendor := mod[0].(*Module)
1592 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001593 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001594 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1595 // PRODUCT_EXTRA_VNDK_VERSIONS.
1596 mod := mctx.CreateVariations(vendorMode)
1597 vendor := mod[0].(*Module)
1598 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001599 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001600 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001601 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001602 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001603 vendor := mod[1].(*Module)
1604 vendor.Properties.UseVndk = true
1605 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001606 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001607 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001608 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001609 vendor := mod[0].(*Module)
1610 vendor.Properties.UseVndk = true
1611 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001612 } else {
1613 // This is either in /system (or similar: /data), or is a
1614 // modules built with the NDK. Modules built with the NDK
1615 // will be restricted using the existing link type checks.
1616 mctx.CreateVariations(coreMode)
1617 }
1618}
1619
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001620func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001621 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001622 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1623 }
Colin Cross6510f912017-11-29 00:27:14 -08001624 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001625}
1626
Colin Cross06a931b2015-10-28 17:23:31 -07001627var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001628var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001629var BoolPtr = proptools.BoolPtr
1630var String = proptools.String
1631var StringPtr = proptools.StringPtr