blob: 1e313c0b7d5944eb14e357f0f63cca1bd2fab458 [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()
Pirama Arumuga Nainar358056c2018-04-14 01:03:35 -070043 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070044 })
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross1e676be2016-10-12 14:38:15 -070046 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
48 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000050 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
51 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
52
Colin Cross1e676be2016-10-12 14:38:15 -070053 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
54 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080055
Ivan Lozanoa9255a82018-03-13 10:41:07 -070056 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator())
Ivan Lozano30c5db22018-02-21 15:49:20 -080057
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
Colin Crossc472d572015-03-17 15:06:21 -070071
Colin Cross5950f382016-12-13 12:50:57 -080072 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070073
Colin Cross81413472016-04-11 14:37:39 -070074 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070075
Dan Willemsenb40aab62016-04-20 14:21:14 -070076 GeneratedSources []string
77 GeneratedHeaders []string
78
Dan Willemsenb3454ab2016-09-28 17:34:58 -070079 ReexportGeneratedHeaders []string
80
Colin Cross97ba0732015-03-23 17:50:24 -070081 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070082 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070083}
84
Colin Crossca860ac2016-01-04 14:34:37 -080085type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070086 // Paths to .so files
87 SharedLibs, LateSharedLibs android.Paths
88 // Paths to the dependencies to use for .so files (.so.toc files)
89 SharedLibsDeps, LateSharedLibsDeps android.Paths
90 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070091 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070092
Colin Cross26c34ed2016-09-30 17:10:16 -070093 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070094 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080095 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070096 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070097
Colin Cross26c34ed2016-09-30 17:10:16 -070098 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070099 GeneratedSources android.Paths
100 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700101
Dan Willemsen76f08272016-07-09 00:14:08 -0700102 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700103 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700106 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700107 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108}
109
Colin Crossca860ac2016-01-04 14:34:37 -0800110type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700111 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
112 ArFlags []string // Flags that apply to ar
113 AsFlags []string // Flags that apply to assembly source files
114 CFlags []string // Flags that apply to C and C++ source files
115 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
116 ConlyFlags []string // Flags that apply to C source files
117 CppFlags []string // Flags that apply to C++ source files
118 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
119 YaccFlags []string // Flags that apply to Yacc source files
120 protoFlags []string // Flags that apply to proto source files
Joe Onorato09e94ab2017-11-18 18:23:14 -0800121 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700122 aidlFlags []string // Flags that apply to aidl source files
123 rsFlags []string // Flags that apply to renderscript source files
124 LdFlags []string // Flags that apply to linker command lines
125 libFlags []string // Flags to add libraries early to the link order
126 TidyFlags []string // Flags that apply to clang-tidy
127 SAbiFlags []string // Flags that apply to header-abi-dumper
128 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700129
Colin Crossc3199482017-03-30 15:03:04 -0700130 // Global include flags that apply to C, C++, and assembly source files
131 // These must be after any module include flags, which will be in GlobalFlags.
132 SystemIncludeFlags []string
133
Colin Crossb98c8b02016-07-29 13:44:28 -0700134 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700135 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700136 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800137 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800138 SAbiDump bool
Dan Willemsenab9f4262018-02-14 13:58:34 -0800139 ProtoRoot bool
Colin Crossca860ac2016-01-04 14:34:37 -0800140
141 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800142 DynamicLinker string
143
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700144 CFlagsDeps android.Paths // Files depended on by compiler flags
145 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800146
147 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800148 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700149}
150
Colin Cross81413472016-04-11 14:37:39 -0700151type ObjectLinkerProperties struct {
152 // names of other cc_object modules to link into this module using partial linking
153 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700154
155 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800156 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700157}
158
Colin Crossca860ac2016-01-04 14:34:37 -0800159// Properties used to compile all C or C++ modules
160type BaseProperties struct {
161 // compile module with clang instead of gcc
162 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700163
164 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800165 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700166
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700167 AndroidMkSharedLibs []string `blueprint:"mutated"`
168 HideFromMake bool `blueprint:"mutated"`
169 PreventInstall bool `blueprint:"mutated"`
170
171 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800172
173 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
174 // file
175 Logtags []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700176}
177
178type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900179 // whether this module should be allowed to be directly depended by other
180 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
181 // If set to true, two variants will be built separately, one like
182 // normal, and the other limited to the set of libraries and headers
183 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700184 //
185 // The vendor variant may be used with a different (newer) /system,
186 // so it shouldn't have any unversioned runtime dependencies, or
187 // make assumptions about the system that may not be true in the
188 // future.
189 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900190 // If set to false, this module becomes inaccessible from /vendor modules.
191 //
192 // Default value is true when vndk: {enabled: true} or vendor: true.
193 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700194 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
195 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900196
197 // whether this module is capable of being loaded with other instance
198 // (possibly an older version) of the same module in the same process.
199 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
200 // can be double loaded in a vendor process if the library is also a
201 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
202 // explicitly marked as `double_loadable: true` by the owner, or the dependency
203 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
204 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800205}
206
Colin Crossca860ac2016-01-04 14:34:37 -0800207type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800208 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800209}
210
Colin Crossca860ac2016-01-04 14:34:37 -0800211type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800212 static() bool
213 staticBinary() bool
214 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700215 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700216 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800217 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700218 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900219 isVndk() bool
220 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800221 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800222 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700223 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700224 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800225 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800226 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800227}
228
229type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700230 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800231 ModuleContextIntf
232}
233
234type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700235 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800236 ModuleContextIntf
237}
238
Colin Cross37047f12016-12-13 17:06:13 -0800239type DepsContext interface {
240 android.BottomUpMutatorContext
241 ModuleContextIntf
242}
243
Colin Crossca860ac2016-01-04 14:34:37 -0800244type feature interface {
245 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800246 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800247 flags(ctx ModuleContext, flags Flags) Flags
248 props() []interface{}
249}
250
251type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700252 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800253 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800254 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700255 compilerProps() []interface{}
256
Colin Cross76fada02016-07-27 10:31:13 -0700257 appendCflags([]string)
258 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700259 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800260}
261
262type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700263 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800264 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700265 linkerFlags(ctx ModuleContext, flags Flags) Flags
266 linkerProps() []interface{}
267
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700268 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700269 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800270}
271
272type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700273 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700274 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800275 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700276 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700277 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800278}
279
Colin Crossc99deeb2016-04-11 15:06:20 -0700280type dependencyTag struct {
281 blueprint.BaseDependencyTag
282 name string
283 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700284
285 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700286}
287
288var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700289 sharedDepTag = dependencyTag{name: "shared", library: true}
290 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
291 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
292 staticDepTag = dependencyTag{name: "static", library: true}
293 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
294 lateStaticDepTag = dependencyTag{name: "late static", library: true}
295 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800296 headerDepTag = dependencyTag{name: "header", library: true}
297 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700298 genSourceDepTag = dependencyTag{name: "gen source"}
299 genHeaderDepTag = dependencyTag{name: "gen header"}
300 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
301 objDepTag = dependencyTag{name: "obj"}
302 crtBeginDepTag = dependencyTag{name: "crtbegin"}
303 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700304 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700305 reuseObjTag = dependencyTag{name: "reuse objects"}
306 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
307 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800308 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700309)
310
Colin Crossca860ac2016-01-04 14:34:37 -0800311// Module contains the properties and members used by all C/C++ module types, and implements
312// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
313// to construct the output file. Behavior can be customized with a Customizer interface
314type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700315 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700316 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700317
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700318 Properties BaseProperties
319 VendorProperties VendorProperties
320 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700321
Colin Crossca860ac2016-01-04 14:34:37 -0800322 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700323 hod android.HostOrDeviceSupported
324 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700325
Colin Crossca860ac2016-01-04 14:34:37 -0800326 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700327 features []feature
328 compiler compiler
329 linker linker
330 installer installer
331 stl *stl
332 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800333 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800334 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900335 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700336 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700337 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800338
339 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700340
Colin Cross635c3b02016-05-18 15:37:25 -0700341 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800342
Colin Crossb98c8b02016-07-29 13:44:28 -0700343 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700344
345 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800346
347 // Flags used to compile this module
348 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700349
350 // 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 -0800351 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700352 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800353 depsInLinkOrder android.Paths
354
355 // only non-nil when this is a shared library that reuses the objects of a static library
356 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700357}
358
Colin Cross36242852017-06-23 15:06:31 -0700359func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700360 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800361 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700362 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800363 }
364 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700365 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800366 }
367 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700368 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800369 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700370 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700371 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700372 }
Colin Cross16b23492016-01-06 14:41:07 -0800373 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700374 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800375 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800376 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700377 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800378 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800379 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700380 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800381 }
Justin Yun8effde42017-06-23 19:24:43 +0900382 if c.vndkdep != nil {
383 c.AddProperties(c.vndkdep.props()...)
384 }
Stephen Craneba090d12017-05-09 15:44:35 -0700385 if c.lto != nil {
386 c.AddProperties(c.lto.props()...)
387 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700388 if c.pgo != nil {
389 c.AddProperties(c.pgo.props()...)
390 }
Colin Crossca860ac2016-01-04 14:34:37 -0800391 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700392 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800393 }
Colin Crossc472d572015-03-17 15:06:21 -0700394
Colin Cross36242852017-06-23 15:06:31 -0700395 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700396
Colin Cross1f44a3a2017-07-07 14:33:33 -0700397 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700398
399 return c
Colin Crossc472d572015-03-17 15:06:21 -0700400}
401
Colin Crossb916a382016-07-29 17:28:03 -0700402// Returns true for dependency roots (binaries)
403// TODO(ccross): also handle dlopenable libraries
404func (c *Module) isDependencyRoot() bool {
405 if root, ok := c.linker.(interface {
406 isDependencyRoot() bool
407 }); ok {
408 return root.isDependencyRoot()
409 }
410 return false
411}
412
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700413func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700414 return c.Properties.UseVndk
415}
416
Justin Yun8effde42017-06-23 19:24:43 +0900417func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800418 if vndkdep := c.vndkdep; vndkdep != nil {
419 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900420 }
421 return false
422}
423
Yi Kong7e53c572018-02-14 18:16:12 +0800424func (c *Module) isPgoCompile() bool {
425 if pgo := c.pgo; pgo != nil {
426 return pgo.Properties.PgoCompile
427 }
428 return false
429}
430
Logan Chienf3511742017-10-31 18:04:35 +0800431func (c *Module) isVndkSp() bool {
432 if vndkdep := c.vndkdep; vndkdep != nil {
433 return vndkdep.isVndkSp()
434 }
435 return false
436}
437
438func (c *Module) isVndkExt() bool {
439 if vndkdep := c.vndkdep; vndkdep != nil {
440 return vndkdep.isVndkExt()
441 }
442 return false
443}
444
445func (c *Module) getVndkExtendsModuleName() string {
446 if vndkdep := c.vndkdep; vndkdep != nil {
447 return vndkdep.getVndkExtendsModuleName()
448 }
449 return ""
450}
451
Jiyong Park82e2bf32017-08-16 14:05:54 +0900452// Returns true only when this module is configured to have core and vendor
453// variants.
454func (c *Module) hasVendorVariant() bool {
455 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
456}
457
Colin Crossca860ac2016-01-04 14:34:37 -0800458type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700459 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800460 moduleContextImpl
461}
462
Colin Cross37047f12016-12-13 17:06:13 -0800463type depsContext struct {
464 android.BottomUpMutatorContext
465 moduleContextImpl
466}
467
Colin Crossca860ac2016-01-04 14:34:37 -0800468type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700469 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800470 moduleContextImpl
471}
472
Jiyong Park2db76922017-11-08 16:03:48 +0900473func (ctx *moduleContext) SocSpecific() bool {
474 return ctx.ModuleContext.SocSpecific() ||
475 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700476}
477
Colin Crossca860ac2016-01-04 14:34:37 -0800478type moduleContextImpl struct {
479 mod *Module
480 ctx BaseModuleContext
481}
482
Colin Crossca860ac2016-01-04 14:34:37 -0800483func (ctx *moduleContextImpl) clang() bool {
484 return ctx.mod.clang(ctx.ctx)
485}
486
Colin Crossb98c8b02016-07-29 13:44:28 -0700487func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800488 return ctx.mod.toolchain(ctx.ctx)
489}
490
491func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000492 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800493}
494
495func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700496 if static, ok := ctx.mod.linker.(interface {
497 staticBinary() bool
498 }); ok {
499 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800500 }
Colin Crossb916a382016-07-29 17:28:03 -0700501 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800502}
503
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700504func (ctx *moduleContextImpl) useSdk() bool {
505 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800506 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700507 }
508 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800509}
510
511func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700512 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700513 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900514 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700515 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900516 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
517 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
518 return "current"
519 }
520 return platform_vndk_ver
521 }
522 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800523 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900524 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700525 }
526 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800527}
528
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700529func (ctx *moduleContextImpl) useVndk() bool {
530 return ctx.mod.useVndk()
531}
Justin Yun8effde42017-06-23 19:24:43 +0900532
Logan Chienf3511742017-10-31 18:04:35 +0800533func (ctx *moduleContextImpl) isVndk() bool {
534 return ctx.mod.isVndk()
535}
536
Yi Kong7e53c572018-02-14 18:16:12 +0800537func (ctx *moduleContextImpl) isPgoCompile() bool {
538 return ctx.mod.isPgoCompile()
539}
540
Justin Yun8effde42017-06-23 19:24:43 +0900541func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800542 return ctx.mod.isVndkSp()
543}
544
545func (ctx *moduleContextImpl) isVndkExt() bool {
546 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900547}
548
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800549// Create source abi dumps if the module belongs to the list of VndkLibraries.
550func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdharyb391fea2018-01-29 15:01:20 -0800551 skipAbiChecks := ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS")
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800552 isUnsanitizedVariant := true
553 sanitize := ctx.mod.sanitize
554 if sanitize != nil {
555 isUnsanitizedVariant = sanitize.isUnsanitizedVariant()
556 }
Jayant Chowdhary22963cd2018-03-06 14:59:50 -0800557 vendorAvailable := Bool(ctx.mod.VendorProperties.Vendor_available)
Jayant Chowdharyb391fea2018-01-29 15:01:20 -0800558 return !skipAbiChecks && isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk() && vendorAvailable) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800559}
560
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700561func (ctx *moduleContextImpl) selectedStl() string {
562 if stl := ctx.mod.stl; stl != nil {
563 return stl.Properties.SelectedStl
564 }
565 return ""
566}
567
Colin Crossce75d2c2016-10-06 16:12:58 -0700568func (ctx *moduleContextImpl) baseModuleName() string {
569 return ctx.mod.ModuleBase.BaseModuleName()
570}
571
Logan Chienf3511742017-10-31 18:04:35 +0800572func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
573 return ctx.mod.getVndkExtendsModuleName()
574}
575
Colin Cross635c3b02016-05-18 15:37:25 -0700576func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800577 return &Module{
578 hod: hod,
579 multilib: multilib,
580 }
581}
582
Colin Cross635c3b02016-05-18 15:37:25 -0700583func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800584 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700585 module.features = []feature{
586 &tidyFeature{},
587 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700588 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800589 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800590 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800591 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900592 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700593 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700594 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800595 return module
596}
597
Colin Crossce75d2c2016-10-06 16:12:58 -0700598func (c *Module) Prebuilt() *android.Prebuilt {
599 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
600 return p.prebuilt()
601 }
602 return nil
603}
604
605func (c *Module) Name() string {
606 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700607 if p, ok := c.linker.(interface {
608 Name(string) string
609 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700610 name = p.Name(name)
611 }
612 return name
613}
614
Jeff Gaston294356f2017-09-27 17:05:30 -0700615// orderDeps reorders dependencies into a list such that if module A depends on B, then
616// A will precede B in the resultant list.
617// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800618// Note that directSharedDeps should be the analogous static library for each shared lib dep
619func 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 -0700620 // If A depends on B, then
621 // Every list containing A will also contain B later in the list
622 // So, after concatenating all lists, the final instance of B will have come from the same
623 // original list as the final instance of A
624 // So, the final instance of B will be later in the concatenation than the final A
625 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
626 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800627 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700628 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800629 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
630 }
631 for _, dep := range directSharedDeps {
632 orderedAllDeps = append(orderedAllDeps, dep)
633 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700634 }
635
Colin Crossb6715442017-10-24 11:13:31 -0700636 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700637
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800638 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700639 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800640 // resultant list to only what the caller has chosen to include in directStaticDeps
641 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700642
643 return orderedAllDeps, orderedDeclaredDeps
644}
645
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800646func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
647 // convert Module to Path
648 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
649 staticDepFiles := []android.Path{}
650 for _, dep := range staticDeps {
651 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
652 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700653 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800654 sharedDepFiles := []android.Path{}
655 for _, sharedDep := range sharedDeps {
656 staticAnalogue := sharedDep.staticVariant
657 if staticAnalogue != nil {
658 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
659 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
660 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700661 }
662
663 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800664 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700665
666 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700667}
668
Colin Cross635c3b02016-05-18 15:37:25 -0700669func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700670
Colin Crossca860ac2016-01-04 14:34:37 -0800671 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700672 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800673 moduleContextImpl: moduleContextImpl{
674 mod: c,
675 },
676 }
677 ctx.ctx = ctx
678
Colin Crossf18e1102017-11-16 14:33:08 -0800679 deps := c.depsToPaths(ctx)
680 if ctx.Failed() {
681 return
682 }
683
Colin Crossca860ac2016-01-04 14:34:37 -0800684 flags := Flags{
685 Toolchain: c.toolchain(ctx),
686 Clang: c.clang(ctx),
687 }
Colin Crossca860ac2016-01-04 14:34:37 -0800688 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800689 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800690 }
691 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700692 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800693 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700694 if c.stl != nil {
695 flags = c.stl.flags(ctx, flags)
696 }
Colin Cross16b23492016-01-06 14:41:07 -0800697 if c.sanitize != nil {
698 flags = c.sanitize.flags(ctx, flags)
699 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800700 if c.coverage != nil {
701 flags = c.coverage.flags(ctx, flags)
702 }
Stephen Craneba090d12017-05-09 15:44:35 -0700703 if c.lto != nil {
704 flags = c.lto.flags(ctx, flags)
705 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700706 if c.pgo != nil {
707 flags = c.pgo.flags(ctx, flags)
708 }
Colin Crossca860ac2016-01-04 14:34:37 -0800709 for _, feature := range c.features {
710 flags = feature.flags(ctx, flags)
711 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800712 if ctx.Failed() {
713 return
714 }
715
Colin Crossb98c8b02016-07-29 13:44:28 -0700716 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
717 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
718 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800719
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800720 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
721 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700722 // We need access to all the flags seen by a source file.
723 if c.sabi != nil {
724 flags = c.sabi.flags(ctx, flags)
725 }
Colin Crossca860ac2016-01-04 14:34:37 -0800726 // Optimization to reduce size of build.ninja
727 // Replace the long list of flags for each file with a module-local variable
728 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
729 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
730 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
731 flags.CFlags = []string{"$cflags"}
732 flags.CppFlags = []string{"$cppflags"}
733 flags.AsFlags = []string{"$asflags"}
734
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700735 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800736 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700737 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800738 if ctx.Failed() {
739 return
740 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800741 }
742
Colin Crossca860ac2016-01-04 14:34:37 -0800743 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700744 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800745 if ctx.Failed() {
746 return
747 }
Colin Cross635c3b02016-05-18 15:37:25 -0700748 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700749 }
Colin Cross5049f022015-03-18 13:28:46 -0700750
Colin Crossce75d2c2016-10-06 16:12:58 -0700751 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
752 c.installer.install(ctx, c.outputFile.Path())
753 if ctx.Failed() {
754 return
Colin Crossca860ac2016-01-04 14:34:37 -0800755 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700756 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800757}
758
Colin Crossb98c8b02016-07-29 13:44:28 -0700759func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800760 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700761 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800762 }
Colin Crossca860ac2016-01-04 14:34:37 -0800763 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800764}
765
Colin Crossca860ac2016-01-04 14:34:37 -0800766func (c *Module) begin(ctx BaseModuleContext) {
767 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700768 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700769 }
Colin Crossca860ac2016-01-04 14:34:37 -0800770 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700771 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800772 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700773 if c.stl != nil {
774 c.stl.begin(ctx)
775 }
Colin Cross16b23492016-01-06 14:41:07 -0800776 if c.sanitize != nil {
777 c.sanitize.begin(ctx)
778 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800779 if c.coverage != nil {
780 c.coverage.begin(ctx)
781 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800782 if c.sabi != nil {
783 c.sabi.begin(ctx)
784 }
Justin Yun8effde42017-06-23 19:24:43 +0900785 if c.vndkdep != nil {
786 c.vndkdep.begin(ctx)
787 }
Stephen Craneba090d12017-05-09 15:44:35 -0700788 if c.lto != nil {
789 c.lto.begin(ctx)
790 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700791 if c.pgo != nil {
792 c.pgo.begin(ctx)
793 }
Colin Crossca860ac2016-01-04 14:34:37 -0800794 for _, feature := range c.features {
795 feature.begin(ctx)
796 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700797 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700798 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700799 if err != nil {
800 ctx.PropertyErrorf("sdk_version", err.Error())
801 }
Nan Zhang0007d812017-11-07 10:57:05 -0800802 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700803 }
Colin Crossca860ac2016-01-04 14:34:37 -0800804}
805
Colin Cross37047f12016-12-13 17:06:13 -0800806func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700807 deps := Deps{}
808
809 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700810 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700811 }
Pirama Arumuga Nainar358056c2018-04-14 01:03:35 -0700812 // clang_rt.profile runtime libraries necessary for PGO and coverage
813 // depend on symbols from libgcc. Add the runtime library dependency
814 // before libgcc gets added in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700815 if c.pgo != nil {
816 deps = c.pgo.deps(ctx, deps)
817 }
Pirama Arumuga Nainar358056c2018-04-14 01:03:35 -0700818 if c.coverage != nil {
819 deps = c.coverage.deps(ctx, deps)
820 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700821 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700822 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700823 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700824 if c.stl != nil {
825 deps = c.stl.deps(ctx, deps)
826 }
Colin Cross16b23492016-01-06 14:41:07 -0800827 if c.sanitize != nil {
828 deps = c.sanitize.deps(ctx, deps)
829 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800830 if c.sabi != nil {
831 deps = c.sabi.deps(ctx, deps)
832 }
Justin Yun8effde42017-06-23 19:24:43 +0900833 if c.vndkdep != nil {
834 deps = c.vndkdep.deps(ctx, deps)
835 }
Stephen Craneba090d12017-05-09 15:44:35 -0700836 if c.lto != nil {
837 deps = c.lto.deps(ctx, deps)
838 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700839 for _, feature := range c.features {
840 deps = feature.deps(ctx, deps)
841 }
842
Colin Crossb6715442017-10-24 11:13:31 -0700843 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
844 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
845 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
846 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
847 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
848 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700849
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700850 for _, lib := range deps.ReexportSharedLibHeaders {
851 if !inList(lib, deps.SharedLibs) {
852 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
853 }
854 }
855
856 for _, lib := range deps.ReexportStaticLibHeaders {
857 if !inList(lib, deps.StaticLibs) {
858 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
859 }
860 }
861
Colin Cross5950f382016-12-13 12:50:57 -0800862 for _, lib := range deps.ReexportHeaderLibHeaders {
863 if !inList(lib, deps.HeaderLibs) {
864 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
865 }
866 }
867
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700868 for _, gen := range deps.ReexportGeneratedHeaders {
869 if !inList(gen, deps.GeneratedHeaders) {
870 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
871 }
872 }
873
Colin Crossc99deeb2016-04-11 15:06:20 -0700874 return deps
875}
876
Dan Albert7e9d2952016-08-04 13:02:36 -0700877func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800878 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700879 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800880 moduleContextImpl: moduleContextImpl{
881 mod: c,
882 },
883 }
884 ctx.ctx = ctx
885
Colin Crossca860ac2016-01-04 14:34:37 -0800886 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700887}
888
Colin Cross1e676be2016-10-12 14:38:15 -0700889func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
890 if !c.Enabled() {
891 return
892 }
893
Colin Cross37047f12016-12-13 17:06:13 -0800894 ctx := &depsContext{
895 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700896 moduleContextImpl: moduleContextImpl{
897 mod: c,
898 },
899 }
900 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800901
Colin Crossc99deeb2016-04-11 15:06:20 -0700902 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800903
Dan Albert914449f2016-06-17 16:45:24 -0700904 variantNdkLibs := []string{}
905 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700906 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700907 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700908
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700909 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
910 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700911 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700912 // 1. Name of an NDK library that refers to a prebuilt module.
913 // For each of these, it adds the name of the prebuilt module (which will be in
914 // prebuilts/ndk) to the list of nonvariant libs.
915 // 2. Name of an NDK library that refers to an ndk_library module.
916 // For each of these, it adds the name of the ndk_library module to the list of
917 // variant libs.
918 // 3. Anything else (so anything that isn't an NDK library).
919 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700920 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700921 // The caller can then know to add the variantLibs dependencies differently from the
922 // nonvariantLibs
923 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
924 variantLibs = []string{}
925 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700926 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700927 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700928 if !inList(entry, ndkMigratedLibs) {
929 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
930 } else {
931 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
932 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700933 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700934 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +0900935 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(entry, vendorPublicLibraries) {
936 vendorPublicLib := entry + vendorPublicLibrarySuffix
937 if actx.OtherModuleExists(vendorPublicLib) {
938 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
939 } else {
940 // This can happen if vendor_public_library module is defined in a
941 // namespace that isn't visible to the current module. In that case,
942 // link to the original library.
943 nonvariantLibs = append(nonvariantLibs, entry)
944 }
Dan Albert914449f2016-06-17 16:45:24 -0700945 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700946 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700947 }
948 }
Dan Albert914449f2016-06-17 16:45:24 -0700949 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700950 }
951
Dan Albert914449f2016-06-17 16:45:24 -0700952 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
953 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900954 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700955 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700956
Colin Cross32ec36c2016-12-15 07:39:51 -0800957 for _, lib := range deps.HeaderLibs {
958 depTag := headerDepTag
959 if inList(lib, deps.ReexportHeaderLibHeaders) {
960 depTag = headerExportDepTag
961 }
962 actx.AddVariationDependencies(nil, depTag, lib)
963 }
Colin Cross5950f382016-12-13 12:50:57 -0800964
Colin Crossc99deeb2016-04-11 15:06:20 -0700965 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
966 deps.WholeStaticLibs...)
967
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700968 for _, lib := range deps.StaticLibs {
969 depTag := staticDepTag
970 if inList(lib, deps.ReexportStaticLibHeaders) {
971 depTag = staticExportDepTag
972 }
Colin Cross15a0d462016-07-14 14:49:58 -0700973 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700974 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700975
976 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
977 deps.LateStaticLibs...)
978
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700979 for _, lib := range deps.SharedLibs {
980 depTag := sharedDepTag
981 if inList(lib, deps.ReexportSharedLibHeaders) {
982 depTag = sharedExportDepTag
983 }
Colin Cross15a0d462016-07-14 14:49:58 -0700984 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700985 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700986
987 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
988 deps.LateSharedLibs...)
989
Colin Cross68861832016-07-08 10:41:41 -0700990 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700991
992 for _, gen := range deps.GeneratedHeaders {
993 depTag := genHeaderDepTag
994 if inList(gen, deps.ReexportGeneratedHeaders) {
995 depTag = genHeaderExportDepTag
996 }
997 actx.AddDependency(c, depTag, gen)
998 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700999
Colin Cross68861832016-07-08 10:41:41 -07001000 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001001
1002 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -07001003 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001004 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001005 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -07001006 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001007 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001008 if deps.LinkerScript != "" {
1009 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
1010 }
Dan Albert914449f2016-06-17 16:45:24 -07001011
1012 version := ctx.sdkVersion()
1013 actx.AddVariationDependencies([]blueprint.Variation{
1014 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
1015 actx.AddVariationDependencies([]blueprint.Variation{
1016 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001017
1018 if vndkdep := c.vndkdep; vndkdep != nil {
1019 if vndkdep.isVndkExt() {
1020 baseModuleMode := vendorMode
1021 if actx.DeviceConfig().VndkVersion() == "" {
1022 baseModuleMode = coreMode
1023 }
1024 actx.AddVariationDependencies([]blueprint.Variation{
1025 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
1026 vndkdep.getVndkExtendsModuleName())
1027 }
1028 }
Colin Cross6362e272015-10-29 15:25:03 -07001029}
Colin Cross21b9a242015-03-24 14:15:58 -07001030
Dan Albert7e9d2952016-08-04 13:02:36 -07001031func beginMutator(ctx android.BottomUpMutatorContext) {
1032 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1033 c.beginMutator(ctx)
1034 }
1035}
1036
Colin Crossca860ac2016-01-04 14:34:37 -08001037func (c *Module) clang(ctx BaseModuleContext) bool {
1038 clang := Bool(c.Properties.Clang)
1039
1040 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001041 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001042 }
Colin Cross28344522015-04-22 13:07:53 -07001043
Colin Crossca860ac2016-01-04 14:34:37 -08001044 if !c.toolchain(ctx).ClangSupported() {
1045 clang = false
1046 }
1047
1048 return clang
1049}
1050
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001051// Whether a module can link to another module, taking into
1052// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001053func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001054 if from.Target().Os != android.Android {
1055 // Host code is not restricted
1056 return
1057 }
1058 if from.Properties.UseVndk {
1059 // Though vendor code is limited by the vendor mutator,
1060 // each vendor-available module needs to check
1061 // link-type for VNDK.
1062 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001063 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001064 }
1065 return
1066 }
Nan Zhang0007d812017-11-07 10:57:05 -08001067 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001068 // Platform code can link to anything
1069 return
1070 }
1071 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1072 // These are always allowed
1073 return
1074 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001075 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1076 // These are allowed, but they don't set sdk_version
1077 return
1078 }
1079 if _, ok := to.linker.(*stubDecorator); ok {
1080 // These aren't real libraries, but are the stub shared libraries that are included in
1081 // the NDK.
1082 return
1083 }
Nan Zhang0007d812017-11-07 10:57:05 -08001084 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001085 // NDK code linking to platform code is never okay.
1086 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1087 ctx.OtherModuleName(to))
1088 }
1089
1090 // At this point we know we have two NDK libraries, but we need to
1091 // check that we're not linking against anything built against a higher
1092 // API level, as it is only valid to link against older or equivalent
1093 // APIs.
1094
Inseob Kim01a28722018-04-11 09:48:45 +09001095 // Current can link against anything.
1096 if String(from.Properties.Sdk_version) != "current" {
1097 // Otherwise we need to check.
1098 if String(to.Properties.Sdk_version) == "current" {
1099 // Current can't be linked against by anything else.
1100 ctx.ModuleErrorf("links %q built against newer API version %q",
1101 ctx.OtherModuleName(to), "current")
1102 } else {
1103 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1104 if err != nil {
1105 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001106 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001107 String(from.Properties.Sdk_version))
1108 }
1109 toApi, err := strconv.Atoi(String(to.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(to.Properties.Sdk_version))
1114 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001115
Inseob Kim01a28722018-04-11 09:48:45 +09001116 if toApi > fromApi {
1117 ctx.ModuleErrorf("links %q built against newer API version %q",
1118 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1119 }
1120 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001121 }
Dan Albert202fe492017-12-15 13:56:59 -08001122
1123 // Also check that the two STL choices are compatible.
1124 fromStl := from.stl.Properties.SelectedStl
1125 toStl := to.stl.Properties.SelectedStl
1126 if fromStl == "" || toStl == "" {
1127 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001128 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001129 // We can be permissive with the system "STL" since it is only the C++
1130 // ABI layer, but in the future we should make sure that everyone is
1131 // using either libc++ or nothing.
Inseob Kimda2171a2018-04-11 15:41:38 +09001132 } else if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
Dan Albert202fe492017-12-15 13:56:59 -08001133 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1134 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1135 to.stl.Properties.SelectedStl)
1136 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001137}
1138
Jiyong Park5fb8c102018-04-09 12:03:06 +09001139// Tests whether the dependent library is okay to be double loaded inside a single process.
1140// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1141// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1142// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1143func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1144 if _, ok := from.linker.(*libraryDecorator); !ok {
1145 return
1146 }
1147
1148 if inList(ctx.ModuleName(), llndkLibraries) ||
1149 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1150 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1151 depIsVndkSp := false
1152 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1153 depIsVndkSp = true
1154 }
1155 depIsVndk := false
1156 if to.vndkdep != nil && to.vndkdep.isVndk() {
1157 depIsVndk = true
1158 }
1159 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1160 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
1161 ctx.ModuleErrorf("links VNDK library %q that isn't double_loadable.",
1162 ctx.OtherModuleName(to))
1163 }
1164 }
1165}
1166
Colin Crossc99deeb2016-04-11 15:06:20 -07001167// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001168func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001169 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001170
Jeff Gaston294356f2017-09-27 17:05:30 -07001171 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001172 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001173
Colin Crossd11fcda2017-10-23 17:59:01 -07001174 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001175 depName := ctx.OtherModuleName(dep)
1176 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001177
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178 ccDep, _ := dep.(*Module)
1179 if ccDep == nil {
1180 // handling for a few module types that aren't cc Module but that are also supported
1181 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001182 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001183 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001184 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001185 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001186 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1187 genRule.GeneratedSourceFiles()...)
1188 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001190 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001191 // Support exported headers from a generated_sources dependency
1192 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001193 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001194 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001195 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001196 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001197 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001198 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001199 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001200 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001201 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001202 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001203 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1204 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1205
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001206 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001207 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001208 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001209 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001210 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001211 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001212 files := genRule.GeneratedSourceFiles()
1213 if len(files) == 1 {
1214 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1215 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001216 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001217 }
1218 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001219 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001220 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001221 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001222 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001223 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001224 return
1225 }
1226
Colin Crossd11fcda2017-10-23 17:59:01 -07001227 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001228 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1229 return
1230 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001231 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001232 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001233 return
1234 }
1235
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001236 // re-exporting flags
1237 if depTag == reuseObjTag {
1238 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001239 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001240 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001241 depPaths.Objs = depPaths.Objs.Append(objs)
1242 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001243 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001244 return
1245 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001246 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001247 if t, ok := depTag.(dependencyTag); ok && t.library {
1248 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001249 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001250 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001251 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001252 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001253
1254 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001255 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001256 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001257 // 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 -07001258 // Re-exported shared library headers must be included as well since they can help us with type information
1259 // about template instantiations (instantiated from their headers).
1260 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001261 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001262 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001263
Logan Chienf3511742017-10-31 18:04:35 +08001264 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001265 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001266 }
1267
Colin Cross26c34ed2016-09-30 17:10:16 -07001268 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001269 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001270
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001271 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001272 depFile := android.OptionalPath{}
1273
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001274 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001275 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001276 ptr = &depPaths.SharedLibs
1277 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001278 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001279 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001280 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001281 ptr = &depPaths.LateSharedLibs
1282 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001283 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001284 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001285 ptr = nil
1286 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001287 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001288 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001289 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001290 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001291 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001292 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001293 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001294 return
1295 }
1296
1297 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001298 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001299 for i := range missingDeps {
1300 missingDeps[i] += postfix
1301 }
1302 ctx.AddMissingDependencies(missingDeps)
1303 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001304 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001305 case headerDepTag:
1306 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001307 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001308 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001309 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001310 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001311 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001312 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001313 }
1314
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001315 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001316 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001317 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001318 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001319 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001320 return
1321 }
1322
1323 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001324 // in static libraries act as if they were whole static libraries. The same goes for
1325 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001326 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1327 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001328 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1329 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001330
Dan Willemsen581341d2017-02-09 16:16:31 -08001331 }
1332
Colin Cross26c34ed2016-09-30 17:10:16 -07001333 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001334 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001335 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001336 return
1337 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001338 *ptr = append(*ptr, linkFile.Path())
1339 }
1340
Colin Crossc99deeb2016-04-11 15:06:20 -07001341 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001342 dep := depFile
1343 if !dep.Valid() {
1344 dep = linkFile
1345 }
1346 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001347 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001348
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001349 // Export the shared libs to Make.
1350 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001351 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001352 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001353 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001354 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001355 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001356 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001357 var makeLibName string
1358 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1359 if c.useVndk() && bothVendorAndCoreVariantsExist {
1360 // The vendor module in Make will have been renamed to not conflict with the core
1361 // module, so update the dependency name here accordingly.
1362 makeLibName = libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001363 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
1364 makeLibName = libName + vendorPublicLibrarySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001365 } else {
1366 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001367 }
1368 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001369 // they merely serve as Make dependencies and do not affect this lib itself.
1370 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001371 }
Colin Crossca860ac2016-01-04 14:34:37 -08001372 })
1373
Jeff Gaston294356f2017-09-27 17:05:30 -07001374 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001375 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001376
Colin Crossdd84e052017-05-17 13:44:16 -07001377 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001378 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001379 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001380 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001381 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1382
1383 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001384 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001385 }
Colin Crossdd84e052017-05-17 13:44:16 -07001386
Colin Crossca860ac2016-01-04 14:34:37 -08001387 return depPaths
1388}
1389
1390func (c *Module) InstallInData() bool {
1391 if c.installer == nil {
1392 return false
1393 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001394 return c.installer.inData()
1395}
1396
1397func (c *Module) InstallInSanitizerDir() bool {
1398 if c.installer == nil {
1399 return false
1400 }
1401 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001402 return true
1403 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001404 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001405}
1406
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001407func (c *Module) HostToolPath() android.OptionalPath {
1408 if c.installer == nil {
1409 return android.OptionalPath{}
1410 }
1411 return c.installer.hostToolPath()
1412}
1413
Nan Zhangd4e641b2017-07-12 12:55:28 -07001414func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1415 return c.outputFile
1416}
1417
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001418func (c *Module) Srcs() android.Paths {
1419 if c.outputFile.Valid() {
1420 return android.Paths{c.outputFile.Path()}
1421 }
1422 return android.Paths{}
1423}
1424
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001425func (c *Module) static() bool {
1426 if static, ok := c.linker.(interface {
1427 static() bool
1428 }); ok {
1429 return static.static()
1430 }
1431 return false
1432}
1433
Colin Cross2ba19d92015-05-07 15:44:20 -07001434//
Colin Crosscfad1192015-11-02 16:43:11 -08001435// Defaults
1436//
Colin Crossca860ac2016-01-04 14:34:37 -08001437type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001438 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001439 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001440}
1441
Colin Cross635c3b02016-05-18 15:37:25 -07001442func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001443}
1444
Colin Cross1e676be2016-10-12 14:38:15 -07001445func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1446}
1447
Colin Cross36242852017-06-23 15:06:31 -07001448func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001449 return DefaultsFactory()
1450}
1451
Colin Cross36242852017-06-23 15:06:31 -07001452func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001453 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001454
Colin Cross36242852017-06-23 15:06:31 -07001455 module.AddProperties(props...)
1456 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001457 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001458 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001459 &BaseCompilerProperties{},
1460 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001461 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001462 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001463 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001464 &TestProperties{},
1465 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001466 &UnusedProperties{},
1467 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001468 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001469 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001470 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001471 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001472 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001473 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001474 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001475 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001476 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001477 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001478 )
Colin Crosscfad1192015-11-02 16:43:11 -08001479
Colin Cross1f44a3a2017-07-07 14:33:33 -07001480 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001481
1482 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001483}
1484
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001485const (
1486 // coreMode is the variant used for framework-private libraries, or
1487 // SDK libraries. (which framework-private libraries can use)
1488 coreMode = "core"
1489
1490 // vendorMode is the variant used for /vendor code that compiles
1491 // against the VNDK.
1492 vendorMode = "vendor"
1493)
1494
Jiyong Park6a43f042017-10-12 23:05:00 +09001495func squashVendorSrcs(m *Module) {
1496 if lib, ok := m.compiler.(*libraryDecorator); ok {
1497 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1498 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1499
1500 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1501 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1502 }
1503}
1504
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001505func vendorMutator(mctx android.BottomUpMutatorContext) {
1506 if mctx.Os() != android.Android {
1507 return
1508 }
1509
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001510 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1511 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001512 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001513 mctx.CreateVariations(coreMode)
1514 } else if Bool(props.Vendor_available) {
1515 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001516 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001517 mctx.CreateVariations(vendorMode)
1518 } else {
1519 mctx.CreateVariations(coreMode)
1520 }
1521 }
1522 }
1523
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001524 m, ok := mctx.Module().(*Module)
1525 if !ok {
1526 return
1527 }
1528
1529 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001530 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1531
1532 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001533 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001534 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001535 return
1536 }
Logan Chienf3511742017-10-31 18:04:35 +08001537
1538 if vndkdep := m.vndkdep; vndkdep != nil {
1539 if vndkdep.isVndk() {
1540 if vendorSpecific {
1541 if !vndkdep.isVndkExt() {
1542 mctx.PropertyErrorf("vndk",
1543 "must set `extends: \"...\"` to vndk extension")
1544 return
1545 }
1546 } else {
1547 if vndkdep.isVndkExt() {
1548 mctx.PropertyErrorf("vndk",
1549 "must set `vendor: true` to set `extends: %q`",
1550 m.getVndkExtendsModuleName())
1551 return
1552 }
1553 if m.VendorProperties.Vendor_available == nil {
1554 mctx.PropertyErrorf("vndk",
1555 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1556 return
1557 }
1558 }
1559 } else {
1560 if vndkdep.isVndkSp() {
1561 mctx.PropertyErrorf("vndk",
1562 "must set `enabled: true` to set `support_system_process: true`")
1563 return
1564 }
1565 if vndkdep.isVndkExt() {
1566 mctx.PropertyErrorf("vndk",
1567 "must set `enabled: true` to set `extends: %q`",
1568 m.getVndkExtendsModuleName())
1569 return
1570 }
Justin Yun8effde42017-06-23 19:24:43 +09001571 }
1572 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001573
Justin Yun71549282017-11-17 12:10:28 +09001574 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001575 // If the device isn't compiling against the VNDK, we always
1576 // use the core mode.
1577 mctx.CreateVariations(coreMode)
1578 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1579 // LL-NDK stubs only exist in the vendor variant, since the
1580 // real libraries will be used in the core variant.
1581 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001582 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1583 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001584 mod := mctx.CreateVariations(vendorMode)
1585 vendor := mod[0].(*Module)
1586 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001587 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001588 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1589 // PRODUCT_EXTRA_VNDK_VERSIONS.
1590 mod := mctx.CreateVariations(vendorMode)
1591 vendor := mod[0].(*Module)
1592 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001593 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001594 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001595 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001596 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001597 vendor := mod[1].(*Module)
1598 vendor.Properties.UseVndk = true
1599 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001600 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001601 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001602 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001603 vendor := mod[0].(*Module)
1604 vendor.Properties.UseVndk = true
1605 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001606 } else {
1607 // This is either in /system (or similar: /data), or is a
1608 // modules built with the NDK. Modules built with the NDK
1609 // will be restricted using the existing link type checks.
1610 mctx.CreateVariations(coreMode)
1611 }
1612}
1613
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001614func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001615 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001616 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1617 }
Colin Cross6510f912017-11-29 00:27:14 -08001618 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001619}
1620
Colin Cross06a931b2015-10-28 17:23:31 -07001621var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001622var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001623var BoolPtr = proptools.BoolPtr
1624var String = proptools.String
1625var StringPtr = proptools.StringPtr