blob: 76e6645c3e19cc4a955635fa9ba52b34ac3b5350 [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 UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800210 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800211}
212
Colin Crossca860ac2016-01-04 14:34:37 -0800213type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800214 static() bool
215 staticBinary() bool
216 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700217 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700218 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800219 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700220 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900221 isVndk() bool
222 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800223 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800224 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700225 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700226 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800227 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800228 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800229}
230
231type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700232 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800233 ModuleContextIntf
234}
235
236type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700237 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800238 ModuleContextIntf
239}
240
Colin Cross37047f12016-12-13 17:06:13 -0800241type DepsContext interface {
242 android.BottomUpMutatorContext
243 ModuleContextIntf
244}
245
Colin Crossca860ac2016-01-04 14:34:37 -0800246type feature interface {
247 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800248 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800249 flags(ctx ModuleContext, flags Flags) Flags
250 props() []interface{}
251}
252
253type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700254 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800255 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800256 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700257 compilerProps() []interface{}
258
Colin Cross76fada02016-07-27 10:31:13 -0700259 appendCflags([]string)
260 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700261 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800262}
263
264type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700265 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800266 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700267 linkerFlags(ctx ModuleContext, flags Flags) Flags
268 linkerProps() []interface{}
269
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700270 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700271 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800272}
273
274type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700275 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700276 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800277 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700278 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700279 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800280}
281
Colin Crossc99deeb2016-04-11 15:06:20 -0700282type dependencyTag struct {
283 blueprint.BaseDependencyTag
284 name string
285 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700286
287 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700288}
289
290var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700291 sharedDepTag = dependencyTag{name: "shared", library: true}
292 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
293 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
294 staticDepTag = dependencyTag{name: "static", library: true}
295 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
296 lateStaticDepTag = dependencyTag{name: "late static", library: true}
297 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800298 headerDepTag = dependencyTag{name: "header", library: true}
299 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700300 genSourceDepTag = dependencyTag{name: "gen source"}
301 genHeaderDepTag = dependencyTag{name: "gen header"}
302 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
303 objDepTag = dependencyTag{name: "obj"}
304 crtBeginDepTag = dependencyTag{name: "crtbegin"}
305 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700306 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700307 reuseObjTag = dependencyTag{name: "reuse objects"}
308 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
309 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800310 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800311 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700312)
313
Colin Crossca860ac2016-01-04 14:34:37 -0800314// Module contains the properties and members used by all C/C++ module types, and implements
315// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
316// to construct the output file. Behavior can be customized with a Customizer interface
317type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700318 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700319 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700320
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700321 Properties BaseProperties
322 VendorProperties VendorProperties
323 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700324
Colin Crossca860ac2016-01-04 14:34:37 -0800325 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700326 hod android.HostOrDeviceSupported
327 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700328
Colin Crossca860ac2016-01-04 14:34:37 -0800329 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700330 features []feature
331 compiler compiler
332 linker linker
333 installer installer
334 stl *stl
335 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800336 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800337 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900338 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700339 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700340 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800341
342 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700343
Colin Cross635c3b02016-05-18 15:37:25 -0700344 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800345
Colin Crossb98c8b02016-07-29 13:44:28 -0700346 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700347
348 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800349
350 // Flags used to compile this module
351 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700352
353 // 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 -0800354 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700355 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800356 depsInLinkOrder android.Paths
357
358 // only non-nil when this is a shared library that reuses the objects of a static library
359 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700360}
361
Colin Cross36242852017-06-23 15:06:31 -0700362func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700363 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800364 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700365 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800366 }
367 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700368 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800369 }
370 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700371 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800372 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700373 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700374 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700375 }
Colin Cross16b23492016-01-06 14:41:07 -0800376 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700377 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800378 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800379 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700380 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800381 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800382 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700383 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800384 }
Justin Yun8effde42017-06-23 19:24:43 +0900385 if c.vndkdep != nil {
386 c.AddProperties(c.vndkdep.props()...)
387 }
Stephen Craneba090d12017-05-09 15:44:35 -0700388 if c.lto != nil {
389 c.AddProperties(c.lto.props()...)
390 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700391 if c.pgo != nil {
392 c.AddProperties(c.pgo.props()...)
393 }
Colin Crossca860ac2016-01-04 14:34:37 -0800394 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700395 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800396 }
Colin Crossc472d572015-03-17 15:06:21 -0700397
Colin Cross36242852017-06-23 15:06:31 -0700398 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700399
Colin Cross1f44a3a2017-07-07 14:33:33 -0700400 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700401
402 return c
Colin Crossc472d572015-03-17 15:06:21 -0700403}
404
Colin Crossb916a382016-07-29 17:28:03 -0700405// Returns true for dependency roots (binaries)
406// TODO(ccross): also handle dlopenable libraries
407func (c *Module) isDependencyRoot() bool {
408 if root, ok := c.linker.(interface {
409 isDependencyRoot() bool
410 }); ok {
411 return root.isDependencyRoot()
412 }
413 return false
414}
415
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700416func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700417 return c.Properties.UseVndk
418}
419
Justin Yun8effde42017-06-23 19:24:43 +0900420func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800421 if vndkdep := c.vndkdep; vndkdep != nil {
422 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900423 }
424 return false
425}
426
Yi Kong7e53c572018-02-14 18:16:12 +0800427func (c *Module) isPgoCompile() bool {
428 if pgo := c.pgo; pgo != nil {
429 return pgo.Properties.PgoCompile
430 }
431 return false
432}
433
Logan Chienf3511742017-10-31 18:04:35 +0800434func (c *Module) isVndkSp() bool {
435 if vndkdep := c.vndkdep; vndkdep != nil {
436 return vndkdep.isVndkSp()
437 }
438 return false
439}
440
441func (c *Module) isVndkExt() bool {
442 if vndkdep := c.vndkdep; vndkdep != nil {
443 return vndkdep.isVndkExt()
444 }
445 return false
446}
447
448func (c *Module) getVndkExtendsModuleName() string {
449 if vndkdep := c.vndkdep; vndkdep != nil {
450 return vndkdep.getVndkExtendsModuleName()
451 }
452 return ""
453}
454
Jiyong Park82e2bf32017-08-16 14:05:54 +0900455// Returns true only when this module is configured to have core and vendor
456// variants.
457func (c *Module) hasVendorVariant() bool {
458 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
459}
460
Colin Crossca860ac2016-01-04 14:34:37 -0800461type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700462 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800463 moduleContextImpl
464}
465
Colin Cross37047f12016-12-13 17:06:13 -0800466type depsContext struct {
467 android.BottomUpMutatorContext
468 moduleContextImpl
469}
470
Colin Crossca860ac2016-01-04 14:34:37 -0800471type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700472 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800473 moduleContextImpl
474}
475
Jiyong Park2db76922017-11-08 16:03:48 +0900476func (ctx *moduleContext) SocSpecific() bool {
477 return ctx.ModuleContext.SocSpecific() ||
478 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700479}
480
Colin Crossca860ac2016-01-04 14:34:37 -0800481type moduleContextImpl struct {
482 mod *Module
483 ctx BaseModuleContext
484}
485
Colin Crossca860ac2016-01-04 14:34:37 -0800486func (ctx *moduleContextImpl) clang() bool {
487 return ctx.mod.clang(ctx.ctx)
488}
489
Colin Crossb98c8b02016-07-29 13:44:28 -0700490func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800491 return ctx.mod.toolchain(ctx.ctx)
492}
493
494func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000495 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800496}
497
498func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700499 if static, ok := ctx.mod.linker.(interface {
500 staticBinary() bool
501 }); ok {
502 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800503 }
Colin Crossb916a382016-07-29 17:28:03 -0700504 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800505}
506
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700507func (ctx *moduleContextImpl) useSdk() bool {
508 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800509 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700510 }
511 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800512}
513
514func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700515 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700516 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900517 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700518 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900519 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
520 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
521 return "current"
522 }
523 return platform_vndk_ver
524 }
525 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800526 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900527 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700528 }
529 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800530}
531
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700532func (ctx *moduleContextImpl) useVndk() bool {
533 return ctx.mod.useVndk()
534}
Justin Yun8effde42017-06-23 19:24:43 +0900535
Logan Chienf3511742017-10-31 18:04:35 +0800536func (ctx *moduleContextImpl) isVndk() bool {
537 return ctx.mod.isVndk()
538}
539
Yi Kong7e53c572018-02-14 18:16:12 +0800540func (ctx *moduleContextImpl) isPgoCompile() bool {
541 return ctx.mod.isPgoCompile()
542}
543
Justin Yun8effde42017-06-23 19:24:43 +0900544func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800545 return ctx.mod.isVndkSp()
546}
547
548func (ctx *moduleContextImpl) isVndkExt() bool {
549 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900550}
551
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800552// Create source abi dumps if the module belongs to the list of VndkLibraries.
553func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdharyb391fea2018-01-29 15:01:20 -0800554 skipAbiChecks := ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS")
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800555 isUnsanitizedVariant := true
556 sanitize := ctx.mod.sanitize
557 if sanitize != nil {
558 isUnsanitizedVariant = sanitize.isUnsanitizedVariant()
559 }
Jayant Chowdhary22963cd2018-03-06 14:59:50 -0800560 vendorAvailable := Bool(ctx.mod.VendorProperties.Vendor_available)
Jayant Chowdharyb391fea2018-01-29 15:01:20 -0800561 return !skipAbiChecks && isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk() && vendorAvailable) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800562}
563
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700564func (ctx *moduleContextImpl) selectedStl() string {
565 if stl := ctx.mod.stl; stl != nil {
566 return stl.Properties.SelectedStl
567 }
568 return ""
569}
570
Colin Crossce75d2c2016-10-06 16:12:58 -0700571func (ctx *moduleContextImpl) baseModuleName() string {
572 return ctx.mod.ModuleBase.BaseModuleName()
573}
574
Logan Chienf3511742017-10-31 18:04:35 +0800575func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
576 return ctx.mod.getVndkExtendsModuleName()
577}
578
Colin Cross635c3b02016-05-18 15:37:25 -0700579func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800580 return &Module{
581 hod: hod,
582 multilib: multilib,
583 }
584}
585
Colin Cross635c3b02016-05-18 15:37:25 -0700586func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800587 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700588 module.features = []feature{
589 &tidyFeature{},
590 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700591 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800592 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800593 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800594 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900595 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700596 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700597 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800598 return module
599}
600
Colin Crossce75d2c2016-10-06 16:12:58 -0700601func (c *Module) Prebuilt() *android.Prebuilt {
602 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
603 return p.prebuilt()
604 }
605 return nil
606}
607
608func (c *Module) Name() string {
609 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700610 if p, ok := c.linker.(interface {
611 Name(string) string
612 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700613 name = p.Name(name)
614 }
615 return name
616}
617
Jeff Gaston294356f2017-09-27 17:05:30 -0700618// orderDeps reorders dependencies into a list such that if module A depends on B, then
619// A will precede B in the resultant list.
620// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800621// Note that directSharedDeps should be the analogous static library for each shared lib dep
622func 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 -0700623 // If A depends on B, then
624 // Every list containing A will also contain B later in the list
625 // So, after concatenating all lists, the final instance of B will have come from the same
626 // original list as the final instance of A
627 // So, the final instance of B will be later in the concatenation than the final A
628 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
629 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800630 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700631 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800632 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
633 }
634 for _, dep := range directSharedDeps {
635 orderedAllDeps = append(orderedAllDeps, dep)
636 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700637 }
638
Colin Crossb6715442017-10-24 11:13:31 -0700639 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700640
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800641 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700642 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800643 // resultant list to only what the caller has chosen to include in directStaticDeps
644 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700645
646 return orderedAllDeps, orderedDeclaredDeps
647}
648
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800649func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
650 // convert Module to Path
651 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
652 staticDepFiles := []android.Path{}
653 for _, dep := range staticDeps {
654 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
655 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700656 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800657 sharedDepFiles := []android.Path{}
658 for _, sharedDep := range sharedDeps {
659 staticAnalogue := sharedDep.staticVariant
660 if staticAnalogue != nil {
661 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
662 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
663 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700664 }
665
666 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800667 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700668
669 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700670}
671
Colin Cross635c3b02016-05-18 15:37:25 -0700672func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800673 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700674 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800675 moduleContextImpl: moduleContextImpl{
676 mod: c,
677 },
678 }
679 ctx.ctx = ctx
680
Colin Crossf18e1102017-11-16 14:33:08 -0800681 deps := c.depsToPaths(ctx)
682 if ctx.Failed() {
683 return
684 }
685
Colin Crossca860ac2016-01-04 14:34:37 -0800686 flags := Flags{
687 Toolchain: c.toolchain(ctx),
688 Clang: c.clang(ctx),
689 }
Colin Crossca860ac2016-01-04 14:34:37 -0800690 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800691 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800692 }
693 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700694 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800695 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700696 if c.stl != nil {
697 flags = c.stl.flags(ctx, flags)
698 }
Colin Cross16b23492016-01-06 14:41:07 -0800699 if c.sanitize != nil {
700 flags = c.sanitize.flags(ctx, flags)
701 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800702 if c.coverage != nil {
703 flags = c.coverage.flags(ctx, flags)
704 }
Stephen Craneba090d12017-05-09 15:44:35 -0700705 if c.lto != nil {
706 flags = c.lto.flags(ctx, flags)
707 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700708 if c.pgo != nil {
709 flags = c.pgo.flags(ctx, flags)
710 }
Colin Crossca860ac2016-01-04 14:34:37 -0800711 for _, feature := range c.features {
712 flags = feature.flags(ctx, flags)
713 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800714 if ctx.Failed() {
715 return
716 }
717
Colin Crossb98c8b02016-07-29 13:44:28 -0700718 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
719 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
720 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800721
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800722 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
723 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700724 // We need access to all the flags seen by a source file.
725 if c.sabi != nil {
726 flags = c.sabi.flags(ctx, flags)
727 }
Colin Crossca860ac2016-01-04 14:34:37 -0800728 // Optimization to reduce size of build.ninja
729 // Replace the long list of flags for each file with a module-local variable
730 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
731 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
732 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
733 flags.CFlags = []string{"$cflags"}
734 flags.CppFlags = []string{"$cppflags"}
735 flags.AsFlags = []string{"$asflags"}
736
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700737 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800738 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700739 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800740 if ctx.Failed() {
741 return
742 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800743 }
744
Colin Crossca860ac2016-01-04 14:34:37 -0800745 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700746 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800747 if ctx.Failed() {
748 return
749 }
Colin Cross635c3b02016-05-18 15:37:25 -0700750 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700751 }
Colin Cross5049f022015-03-18 13:28:46 -0700752
Colin Crossce75d2c2016-10-06 16:12:58 -0700753 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
754 c.installer.install(ctx, c.outputFile.Path())
755 if ctx.Failed() {
756 return
Colin Crossca860ac2016-01-04 14:34:37 -0800757 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700758 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800759}
760
Colin Crossb98c8b02016-07-29 13:44:28 -0700761func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800762 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700763 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800764 }
Colin Crossca860ac2016-01-04 14:34:37 -0800765 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800766}
767
Colin Crossca860ac2016-01-04 14:34:37 -0800768func (c *Module) begin(ctx BaseModuleContext) {
769 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700770 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700771 }
Colin Crossca860ac2016-01-04 14:34:37 -0800772 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700773 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800774 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700775 if c.stl != nil {
776 c.stl.begin(ctx)
777 }
Colin Cross16b23492016-01-06 14:41:07 -0800778 if c.sanitize != nil {
779 c.sanitize.begin(ctx)
780 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800781 if c.coverage != nil {
782 c.coverage.begin(ctx)
783 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800784 if c.sabi != nil {
785 c.sabi.begin(ctx)
786 }
Justin Yun8effde42017-06-23 19:24:43 +0900787 if c.vndkdep != nil {
788 c.vndkdep.begin(ctx)
789 }
Stephen Craneba090d12017-05-09 15:44:35 -0700790 if c.lto != nil {
791 c.lto.begin(ctx)
792 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700793 if c.pgo != nil {
794 c.pgo.begin(ctx)
795 }
Colin Crossca860ac2016-01-04 14:34:37 -0800796 for _, feature := range c.features {
797 feature.begin(ctx)
798 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700799 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700800 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700801 if err != nil {
802 ctx.PropertyErrorf("sdk_version", err.Error())
803 }
Nan Zhang0007d812017-11-07 10:57:05 -0800804 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700805 }
Colin Crossca860ac2016-01-04 14:34:37 -0800806}
807
Colin Cross37047f12016-12-13 17:06:13 -0800808func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700809 deps := Deps{}
810
811 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700812 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700813 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000814 // Add the PGO dependency (the clang_rt.profile runtime library), which
815 // sometimes depends on symbols from libgcc, before libgcc gets added
816 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700817 if c.pgo != nil {
818 deps = c.pgo.deps(ctx, deps)
819 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700820 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700821 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700822 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700823 if c.stl != nil {
824 deps = c.stl.deps(ctx, deps)
825 }
Colin Cross16b23492016-01-06 14:41:07 -0800826 if c.sanitize != nil {
827 deps = c.sanitize.deps(ctx, deps)
828 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000829 if c.coverage != nil {
830 deps = c.coverage.deps(ctx, deps)
831 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800832 if c.sabi != nil {
833 deps = c.sabi.deps(ctx, deps)
834 }
Justin Yun8effde42017-06-23 19:24:43 +0900835 if c.vndkdep != nil {
836 deps = c.vndkdep.deps(ctx, deps)
837 }
Stephen Craneba090d12017-05-09 15:44:35 -0700838 if c.lto != nil {
839 deps = c.lto.deps(ctx, deps)
840 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700841 for _, feature := range c.features {
842 deps = feature.deps(ctx, deps)
843 }
844
Colin Crossb6715442017-10-24 11:13:31 -0700845 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
846 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
847 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
848 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
849 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
850 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800851 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700852
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700853 for _, lib := range deps.ReexportSharedLibHeaders {
854 if !inList(lib, deps.SharedLibs) {
855 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
856 }
857 }
858
859 for _, lib := range deps.ReexportStaticLibHeaders {
860 if !inList(lib, deps.StaticLibs) {
861 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
862 }
863 }
864
Colin Cross5950f382016-12-13 12:50:57 -0800865 for _, lib := range deps.ReexportHeaderLibHeaders {
866 if !inList(lib, deps.HeaderLibs) {
867 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
868 }
869 }
870
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700871 for _, gen := range deps.ReexportGeneratedHeaders {
872 if !inList(gen, deps.GeneratedHeaders) {
873 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
874 }
875 }
876
Colin Crossc99deeb2016-04-11 15:06:20 -0700877 return deps
878}
879
Dan Albert7e9d2952016-08-04 13:02:36 -0700880func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800881 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700882 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800883 moduleContextImpl: moduleContextImpl{
884 mod: c,
885 },
886 }
887 ctx.ctx = ctx
888
Colin Crossca860ac2016-01-04 14:34:37 -0800889 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700890}
891
Colin Cross1e676be2016-10-12 14:38:15 -0700892func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
893 if !c.Enabled() {
894 return
895 }
896
Colin Cross37047f12016-12-13 17:06:13 -0800897 ctx := &depsContext{
898 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700899 moduleContextImpl: moduleContextImpl{
900 mod: c,
901 },
902 }
903 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800904
Colin Crossc99deeb2016-04-11 15:06:20 -0700905 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800906
Dan Albert914449f2016-06-17 16:45:24 -0700907 variantNdkLibs := []string{}
908 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700909 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700910 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700911
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700912 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
913 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700914 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700915 // 1. Name of an NDK library that refers to a prebuilt module.
916 // For each of these, it adds the name of the prebuilt module (which will be in
917 // prebuilts/ndk) to the list of nonvariant libs.
918 // 2. Name of an NDK library that refers to an ndk_library module.
919 // For each of these, it adds the name of the ndk_library module to the list of
920 // variant libs.
921 // 3. Anything else (so anything that isn't an NDK library).
922 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700923 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700924 // The caller can then know to add the variantLibs dependencies differently from the
925 // nonvariantLibs
926 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
927 variantLibs = []string{}
928 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700929 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700930 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700931 if !inList(entry, ndkMigratedLibs) {
932 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
933 } else {
934 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
935 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700936 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700937 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +0900938 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(entry, vendorPublicLibraries) {
939 vendorPublicLib := entry + vendorPublicLibrarySuffix
940 if actx.OtherModuleExists(vendorPublicLib) {
941 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
942 } else {
943 // This can happen if vendor_public_library module is defined in a
944 // namespace that isn't visible to the current module. In that case,
945 // link to the original library.
946 nonvariantLibs = append(nonvariantLibs, entry)
947 }
Dan Albert914449f2016-06-17 16:45:24 -0700948 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700949 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700950 }
951 }
Dan Albert914449f2016-06-17 16:45:24 -0700952 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700953 }
954
Dan Albert914449f2016-06-17 16:45:24 -0700955 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
956 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900957 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700958 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700959
Colin Cross32ec36c2016-12-15 07:39:51 -0800960 for _, lib := range deps.HeaderLibs {
961 depTag := headerDepTag
962 if inList(lib, deps.ReexportHeaderLibHeaders) {
963 depTag = headerExportDepTag
964 }
965 actx.AddVariationDependencies(nil, depTag, lib)
966 }
Colin Cross5950f382016-12-13 12:50:57 -0800967
Colin Crossc99deeb2016-04-11 15:06:20 -0700968 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
969 deps.WholeStaticLibs...)
970
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700971 for _, lib := range deps.StaticLibs {
972 depTag := staticDepTag
973 if inList(lib, deps.ReexportStaticLibHeaders) {
974 depTag = staticExportDepTag
975 }
Colin Cross15a0d462016-07-14 14:49:58 -0700976 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700977 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700978
979 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
980 deps.LateStaticLibs...)
981
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700982 for _, lib := range deps.SharedLibs {
983 depTag := sharedDepTag
984 if inList(lib, deps.ReexportSharedLibHeaders) {
985 depTag = sharedExportDepTag
986 }
Colin Cross15a0d462016-07-14 14:49:58 -0700987 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700988 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700989
990 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
991 deps.LateSharedLibs...)
992
Logan Chien43d34c32017-12-20 01:17:32 +0800993 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, runtimeDepTag,
994 deps.RuntimeLibs...)
995
Colin Cross68861832016-07-08 10:41:41 -0700996 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700997
998 for _, gen := range deps.GeneratedHeaders {
999 depTag := genHeaderDepTag
1000 if inList(gen, deps.ReexportGeneratedHeaders) {
1001 depTag = genHeaderExportDepTag
1002 }
1003 actx.AddDependency(c, depTag, gen)
1004 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001005
Colin Cross68861832016-07-08 10:41:41 -07001006 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001007
1008 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -07001009 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001010 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001011 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -07001012 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001013 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001014 if deps.LinkerScript != "" {
1015 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
1016 }
Dan Albert914449f2016-06-17 16:45:24 -07001017
1018 version := ctx.sdkVersion()
1019 actx.AddVariationDependencies([]blueprint.Variation{
1020 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
1021 actx.AddVariationDependencies([]blueprint.Variation{
1022 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001023
1024 if vndkdep := c.vndkdep; vndkdep != nil {
1025 if vndkdep.isVndkExt() {
1026 baseModuleMode := vendorMode
1027 if actx.DeviceConfig().VndkVersion() == "" {
1028 baseModuleMode = coreMode
1029 }
1030 actx.AddVariationDependencies([]blueprint.Variation{
1031 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
1032 vndkdep.getVndkExtendsModuleName())
1033 }
1034 }
Colin Cross6362e272015-10-29 15:25:03 -07001035}
Colin Cross21b9a242015-03-24 14:15:58 -07001036
Dan Albert7e9d2952016-08-04 13:02:36 -07001037func beginMutator(ctx android.BottomUpMutatorContext) {
1038 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1039 c.beginMutator(ctx)
1040 }
1041}
1042
Colin Crossca860ac2016-01-04 14:34:37 -08001043func (c *Module) clang(ctx BaseModuleContext) bool {
1044 clang := Bool(c.Properties.Clang)
1045
1046 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001047 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001048 }
Colin Cross28344522015-04-22 13:07:53 -07001049
Colin Crossca860ac2016-01-04 14:34:37 -08001050 if !c.toolchain(ctx).ClangSupported() {
1051 clang = false
1052 }
1053
1054 return clang
1055}
1056
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001057// Whether a module can link to another module, taking into
1058// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001059func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001060 if from.Target().Os != android.Android {
1061 // Host code is not restricted
1062 return
1063 }
1064 if from.Properties.UseVndk {
1065 // Though vendor code is limited by the vendor mutator,
1066 // each vendor-available module needs to check
1067 // link-type for VNDK.
1068 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001069 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001070 }
1071 return
1072 }
Nan Zhang0007d812017-11-07 10:57:05 -08001073 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001074 // Platform code can link to anything
1075 return
1076 }
1077 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1078 // These are always allowed
1079 return
1080 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001081 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1082 // These are allowed, but they don't set sdk_version
1083 return
1084 }
1085 if _, ok := to.linker.(*stubDecorator); ok {
1086 // These aren't real libraries, but are the stub shared libraries that are included in
1087 // the NDK.
1088 return
1089 }
Nan Zhang0007d812017-11-07 10:57:05 -08001090 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001091 // NDK code linking to platform code is never okay.
1092 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1093 ctx.OtherModuleName(to))
1094 }
1095
1096 // At this point we know we have two NDK libraries, but we need to
1097 // check that we're not linking against anything built against a higher
1098 // API level, as it is only valid to link against older or equivalent
1099 // APIs.
1100
Inseob Kim01a28722018-04-11 09:48:45 +09001101 // Current can link against anything.
1102 if String(from.Properties.Sdk_version) != "current" {
1103 // Otherwise we need to check.
1104 if String(to.Properties.Sdk_version) == "current" {
1105 // Current can't be linked against by anything else.
1106 ctx.ModuleErrorf("links %q built against newer API version %q",
1107 ctx.OtherModuleName(to), "current")
1108 } else {
1109 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1110 if err != nil {
1111 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001112 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001113 String(from.Properties.Sdk_version))
1114 }
1115 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1116 if err != nil {
1117 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001118 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001119 String(to.Properties.Sdk_version))
1120 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001121
Inseob Kim01a28722018-04-11 09:48:45 +09001122 if toApi > fromApi {
1123 ctx.ModuleErrorf("links %q built against newer API version %q",
1124 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1125 }
1126 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001127 }
Dan Albert202fe492017-12-15 13:56:59 -08001128
1129 // Also check that the two STL choices are compatible.
1130 fromStl := from.stl.Properties.SelectedStl
1131 toStl := to.stl.Properties.SelectedStl
1132 if fromStl == "" || toStl == "" {
1133 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001134 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001135 // We can be permissive with the system "STL" since it is only the C++
1136 // ABI layer, but in the future we should make sure that everyone is
1137 // using either libc++ or nothing.
Inseob Kimda2171a2018-04-11 15:41:38 +09001138 } else if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
Dan Albert202fe492017-12-15 13:56:59 -08001139 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1140 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1141 to.stl.Properties.SelectedStl)
1142 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001143}
1144
Jiyong Park5fb8c102018-04-09 12:03:06 +09001145// Tests whether the dependent library is okay to be double loaded inside a single process.
1146// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1147// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1148// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1149func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1150 if _, ok := from.linker.(*libraryDecorator); !ok {
1151 return
1152 }
1153
1154 if inList(ctx.ModuleName(), llndkLibraries) ||
1155 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1156 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1157 depIsVndkSp := false
1158 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1159 depIsVndkSp = true
1160 }
1161 depIsVndk := false
1162 if to.vndkdep != nil && to.vndkdep.isVndk() {
1163 depIsVndk = true
1164 }
1165 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1166 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
1167 ctx.ModuleErrorf("links VNDK library %q that isn't double_loadable.",
1168 ctx.OtherModuleName(to))
1169 }
1170 }
1171}
1172
Colin Crossc99deeb2016-04-11 15:06:20 -07001173// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001174func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001175 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001176
Jeff Gaston294356f2017-09-27 17:05:30 -07001177 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001178 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001179
Colin Crossd11fcda2017-10-23 17:59:01 -07001180 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001181 depName := ctx.OtherModuleName(dep)
1182 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001183
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001184 ccDep, _ := dep.(*Module)
1185 if ccDep == nil {
1186 // handling for a few module types that aren't cc Module but that are also supported
1187 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001188 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001189 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001190 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001191 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001192 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1193 genRule.GeneratedSourceFiles()...)
1194 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001195 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001196 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001197 // Support exported headers from a generated_sources dependency
1198 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001199 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001200 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001201 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001202 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001203 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001204 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001205 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001206 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001207 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001208 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001209 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1210 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1211
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001212 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001213 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001214 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001215 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001216 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001218 files := genRule.GeneratedSourceFiles()
1219 if len(files) == 1 {
1220 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1221 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001222 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001223 }
1224 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001225 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001226 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001227 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001228 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001229 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001230 return
1231 }
1232
Colin Crossd11fcda2017-10-23 17:59:01 -07001233 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001234 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1235 return
1236 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001237 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001238 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001239 return
1240 }
1241
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001242 // re-exporting flags
1243 if depTag == reuseObjTag {
1244 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001245 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001246 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001247 depPaths.Objs = depPaths.Objs.Append(objs)
1248 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001249 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001250 return
1251 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001252 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001253 if t, ok := depTag.(dependencyTag); ok && t.library {
1254 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001255 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001256 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001257 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001258 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001259
1260 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001261 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001262 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001263 // 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 -07001264 // Re-exported shared library headers must be included as well since they can help us with type information
1265 // about template instantiations (instantiated from their headers).
1266 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001267 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001268 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001269
Logan Chienf3511742017-10-31 18:04:35 +08001270 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001271 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001272 }
1273
Colin Cross26c34ed2016-09-30 17:10:16 -07001274 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001275 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001276
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001277 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001278 depFile := android.OptionalPath{}
1279
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001280 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001281 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001282 ptr = &depPaths.SharedLibs
1283 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001284 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001285 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001286 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001287 ptr = &depPaths.LateSharedLibs
1288 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001289 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001290 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001291 ptr = nil
1292 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001293 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001294 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001295 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001296 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001297 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001298 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001299 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001300 return
1301 }
1302
1303 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001304 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001305 for i := range missingDeps {
1306 missingDeps[i] += postfix
1307 }
1308 ctx.AddMissingDependencies(missingDeps)
1309 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001310 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001311 case headerDepTag:
1312 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001313 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001314 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001315 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001316 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001317 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001318 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001319 }
1320
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001321 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001322 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001323 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001324 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001325 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001326 return
1327 }
1328
1329 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001330 // in static libraries act as if they were whole static libraries. The same goes for
1331 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001332 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1333 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001334 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1335 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001336
Dan Willemsen581341d2017-02-09 16:16:31 -08001337 }
1338
Colin Cross26c34ed2016-09-30 17:10:16 -07001339 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001340 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001341 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001342 return
1343 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001344 *ptr = append(*ptr, linkFile.Path())
1345 }
1346
Colin Crossc99deeb2016-04-11 15:06:20 -07001347 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001348 dep := depFile
1349 if !dep.Valid() {
1350 dep = linkFile
1351 }
1352 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001353 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001354
Logan Chien43d34c32017-12-20 01:17:32 +08001355 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001356 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001357 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001358 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001359 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001360 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001361 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1362 if c.useVndk() && bothVendorAndCoreVariantsExist {
1363 // The vendor module in Make will have been renamed to not conflict with the core
1364 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001365 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001366 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001367 return libName + vendorPublicLibrarySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001368 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001369 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001370 }
Logan Chien43d34c32017-12-20 01:17:32 +08001371 }
1372
1373 // Export the shared libs to Make.
1374 switch depTag {
1375 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Park27b188b2017-07-18 13:23:39 +09001376 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001377 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001378 c.Properties.AndroidMkSharedLibs = append(
1379 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
1380 case runtimeDepTag:
1381 c.Properties.AndroidMkRuntimeLibs = append(
1382 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001383 }
Colin Crossca860ac2016-01-04 14:34:37 -08001384 })
1385
Jeff Gaston294356f2017-09-27 17:05:30 -07001386 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001387 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001388
Colin Crossdd84e052017-05-17 13:44:16 -07001389 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001390 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001391 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001392 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001393 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1394
1395 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001396 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001397 }
Colin Crossdd84e052017-05-17 13:44:16 -07001398
Colin Crossca860ac2016-01-04 14:34:37 -08001399 return depPaths
1400}
1401
1402func (c *Module) InstallInData() bool {
1403 if c.installer == nil {
1404 return false
1405 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001406 return c.installer.inData()
1407}
1408
1409func (c *Module) InstallInSanitizerDir() bool {
1410 if c.installer == nil {
1411 return false
1412 }
1413 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001414 return true
1415 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001416 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001417}
1418
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001419func (c *Module) HostToolPath() android.OptionalPath {
1420 if c.installer == nil {
1421 return android.OptionalPath{}
1422 }
1423 return c.installer.hostToolPath()
1424}
1425
Nan Zhangd4e641b2017-07-12 12:55:28 -07001426func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1427 return c.outputFile
1428}
1429
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001430func (c *Module) Srcs() android.Paths {
1431 if c.outputFile.Valid() {
1432 return android.Paths{c.outputFile.Path()}
1433 }
1434 return android.Paths{}
1435}
1436
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001437func (c *Module) static() bool {
1438 if static, ok := c.linker.(interface {
1439 static() bool
1440 }); ok {
1441 return static.static()
1442 }
1443 return false
1444}
1445
Colin Cross2ba19d92015-05-07 15:44:20 -07001446//
Colin Crosscfad1192015-11-02 16:43:11 -08001447// Defaults
1448//
Colin Crossca860ac2016-01-04 14:34:37 -08001449type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001450 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001451 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001452}
1453
Colin Cross635c3b02016-05-18 15:37:25 -07001454func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001455}
1456
Colin Cross1e676be2016-10-12 14:38:15 -07001457func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1458}
1459
Colin Cross36242852017-06-23 15:06:31 -07001460func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001461 return DefaultsFactory()
1462}
1463
Colin Cross36242852017-06-23 15:06:31 -07001464func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001465 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001466
Colin Cross36242852017-06-23 15:06:31 -07001467 module.AddProperties(props...)
1468 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001469 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001470 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001471 &BaseCompilerProperties{},
1472 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001473 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001474 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001475 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001476 &TestProperties{},
1477 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001478 &UnusedProperties{},
1479 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001480 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001481 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001482 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001483 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001484 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001485 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001486 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001487 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001488 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001489 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001490 )
Colin Crosscfad1192015-11-02 16:43:11 -08001491
Colin Cross1f44a3a2017-07-07 14:33:33 -07001492 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001493
1494 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001495}
1496
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001497const (
1498 // coreMode is the variant used for framework-private libraries, or
1499 // SDK libraries. (which framework-private libraries can use)
1500 coreMode = "core"
1501
1502 // vendorMode is the variant used for /vendor code that compiles
1503 // against the VNDK.
1504 vendorMode = "vendor"
1505)
1506
Jiyong Park6a43f042017-10-12 23:05:00 +09001507func squashVendorSrcs(m *Module) {
1508 if lib, ok := m.compiler.(*libraryDecorator); ok {
1509 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1510 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1511
1512 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1513 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1514 }
1515}
1516
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001517func vendorMutator(mctx android.BottomUpMutatorContext) {
1518 if mctx.Os() != android.Android {
1519 return
1520 }
1521
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001522 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1523 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001524 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001525 mctx.CreateVariations(coreMode)
1526 } else if Bool(props.Vendor_available) {
1527 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001528 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001529 mctx.CreateVariations(vendorMode)
1530 } else {
1531 mctx.CreateVariations(coreMode)
1532 }
1533 }
1534 }
1535
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001536 m, ok := mctx.Module().(*Module)
1537 if !ok {
1538 return
1539 }
1540
1541 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001542 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1543
1544 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001545 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001546 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001547 return
1548 }
Logan Chienf3511742017-10-31 18:04:35 +08001549
1550 if vndkdep := m.vndkdep; vndkdep != nil {
1551 if vndkdep.isVndk() {
1552 if vendorSpecific {
1553 if !vndkdep.isVndkExt() {
1554 mctx.PropertyErrorf("vndk",
1555 "must set `extends: \"...\"` to vndk extension")
1556 return
1557 }
1558 } else {
1559 if vndkdep.isVndkExt() {
1560 mctx.PropertyErrorf("vndk",
1561 "must set `vendor: true` to set `extends: %q`",
1562 m.getVndkExtendsModuleName())
1563 return
1564 }
1565 if m.VendorProperties.Vendor_available == nil {
1566 mctx.PropertyErrorf("vndk",
1567 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1568 return
1569 }
1570 }
1571 } else {
1572 if vndkdep.isVndkSp() {
1573 mctx.PropertyErrorf("vndk",
1574 "must set `enabled: true` to set `support_system_process: true`")
1575 return
1576 }
1577 if vndkdep.isVndkExt() {
1578 mctx.PropertyErrorf("vndk",
1579 "must set `enabled: true` to set `extends: %q`",
1580 m.getVndkExtendsModuleName())
1581 return
1582 }
Justin Yun8effde42017-06-23 19:24:43 +09001583 }
1584 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001585
Justin Yun71549282017-11-17 12:10:28 +09001586 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001587 // If the device isn't compiling against the VNDK, we always
1588 // use the core mode.
1589 mctx.CreateVariations(coreMode)
1590 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1591 // LL-NDK stubs only exist in the vendor variant, since the
1592 // real libraries will be used in the core variant.
1593 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001594 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1595 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001596 mod := mctx.CreateVariations(vendorMode)
1597 vendor := mod[0].(*Module)
1598 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001599 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001600 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1601 // PRODUCT_EXTRA_VNDK_VERSIONS.
1602 mod := mctx.CreateVariations(vendorMode)
1603 vendor := mod[0].(*Module)
1604 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001605 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001606 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001607 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001608 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001609 vendor := mod[1].(*Module)
1610 vendor.Properties.UseVndk = true
1611 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001612 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001613 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001614 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001615 vendor := mod[0].(*Module)
1616 vendor.Properties.UseVndk = true
1617 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001618 } else {
1619 // This is either in /system (or similar: /data), or is a
1620 // modules built with the NDK. Modules built with the NDK
1621 // will be restricted using the existing link type checks.
1622 mctx.CreateVariations(coreMode)
1623 }
1624}
1625
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001626func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001627 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001628 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1629 }
Colin Cross6510f912017-11-29 00:27:14 -08001630 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001631}
1632
Colin Cross06a931b2015-10-28 17:23:31 -07001633var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001634var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001635var BoolPtr = proptools.BoolPtr
1636var String = proptools.String
1637var StringPtr = proptools.StringPtr