blob: 09496fc74d8d7fa99fafbc83c726b7149d90e7d9 [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 (
Logan Chien41eabe62019-04-10 13:33:58 +080022 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070023 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080024 "strings"
25
Colin Cross97ba0732015-03-23 17:50:24 -070026 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070027 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070028
Colin Cross635c3b02016-05-18 15:37:25 -070029 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070030 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070031 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080032)
33
Colin Cross463a90e2015-06-17 14:20:06 -070034func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070035 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070036
Colin Cross1e676be2016-10-12 14:38:15 -070037 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090038 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070039 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090040 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070041 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
42 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090043 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070044 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090045 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070046 })
Colin Cross16b23492016-01-06 14:41:07 -080047
Colin Cross1e676be2016-10-12 14:38:15 -070048 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
49 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
50 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080051
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070052 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
53 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
54
Mitch Phillipsbfeade62019-05-01 14:42:05 -070055 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
56 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
57
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000058 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
59 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
60
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080061 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
62 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
63
Colin Cross1e676be2016-10-12 14:38:15 -070064 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
65 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080066
Colin Cross6b753602018-06-21 13:03:07 -070067 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090068 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080069
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080070 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080071 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070072
73 ctx.TopDown("lto_deps", ltoDepsMutator)
74 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090075
76 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070077 })
Colin Crossb98c8b02016-07-29 13:44:28 -070078
79 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070080}
81
Colin Crossca860ac2016-01-04 14:34:37 -080082type Deps struct {
83 SharedLibs, LateSharedLibs []string
84 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080085 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080086 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070087
Colin Cross5950f382016-12-13 12:50:57 -080088 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070089
Colin Cross81413472016-04-11 14:37:39 -070090 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070091
Dan Willemsenb40aab62016-04-20 14:21:14 -070092 GeneratedSources []string
93 GeneratedHeaders []string
94
Dan Willemsenb3454ab2016-09-28 17:34:58 -070095 ReexportGeneratedHeaders []string
96
Colin Cross97ba0732015-03-23 17:50:24 -070097 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070098
99 // Used for host bionic
100 LinkerFlagsFile string
101 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700102}
103
Colin Crossca860ac2016-01-04 14:34:37 -0800104type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900106 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700107 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900108 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700110 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700111
Colin Cross26c34ed2016-09-30 17:10:16 -0700112 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700113 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800114 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700115 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116
Colin Cross26c34ed2016-09-30 17:10:16 -0700117 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700118 GeneratedSources android.Paths
119 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700120
Dan Willemsen76f08272016-07-09 00:14:08 -0700121 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700122 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700123
Colin Cross26c34ed2016-09-30 17:10:16 -0700124 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700125 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700126
127 // Path to the file container flags to use with the linker
128 LinkerFlagsFile android.OptionalPath
129
130 // Path to the dynamic linker binary
131 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132}
133
Colin Crossca860ac2016-01-04 14:34:37 -0800134type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700135 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
136 ArFlags []string // Flags that apply to ar
137 AsFlags []string // Flags that apply to assembly source files
138 CFlags []string // Flags that apply to C and C++ source files
139 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
140 ConlyFlags []string // Flags that apply to C source files
141 CppFlags []string // Flags that apply to C++ source files
142 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700143 aidlFlags []string // Flags that apply to aidl source files
144 rsFlags []string // Flags that apply to renderscript source files
145 LdFlags []string // Flags that apply to linker command lines
146 libFlags []string // Flags to add libraries early to the link order
147 TidyFlags []string // Flags that apply to clang-tidy
148 SAbiFlags []string // Flags that apply to header-abi-dumper
149 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700150
Colin Crossc3199482017-03-30 15:03:04 -0700151 // Global include flags that apply to C, C++, and assembly source files
152 // These must be after any module include flags, which will be in GlobalFlags.
153 SystemIncludeFlags []string
154
Colin Crossb98c8b02016-07-29 13:44:28 -0700155 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700156 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800157 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800158 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800159
160 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800161 DynamicLinker string
162
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700163 CFlagsDeps android.Paths // Files depended on by compiler flags
164 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800165
166 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800167
Colin Cross19878da2019-03-28 14:45:07 -0700168 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700169 protoC bool // Whether to use C instead of C++
170 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700171
172 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700173}
174
Colin Cross81413472016-04-11 14:37:39 -0700175type ObjectLinkerProperties struct {
176 // names of other cc_object modules to link into this module using partial linking
177 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700178
179 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800180 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700181}
182
Colin Crossca860ac2016-01-04 14:34:37 -0800183// Properties used to compile all C or C++ modules
184type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700185 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800186 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700187
188 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800189 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700190
Jiyong Parkde866cb2018-12-07 23:08:36 +0900191 AndroidMkSharedLibs []string `blueprint:"mutated"`
192 AndroidMkStaticLibs []string `blueprint:"mutated"`
193 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
194 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
195 HideFromMake bool `blueprint:"mutated"`
196 PreventInstall bool `blueprint:"mutated"`
197 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700198
199 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800200
201 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
202 // file
203 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900204
205 // Make this module available when building for recovery
206 Recovery_available *bool
207
208 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900209
210 // Allows this module to use non-APEX version of libraries. Useful
211 // for building binaries that are started before APEXes are activated.
212 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700213}
214
215type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900216 // whether this module should be allowed to be directly depended by other
217 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
218 // If set to true, two variants will be built separately, one like
219 // normal, and the other limited to the set of libraries and headers
220 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700221 //
222 // The vendor variant may be used with a different (newer) /system,
223 // so it shouldn't have any unversioned runtime dependencies, or
224 // make assumptions about the system that may not be true in the
225 // future.
226 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900227 // If set to false, this module becomes inaccessible from /vendor modules.
228 //
229 // Default value is true when vndk: {enabled: true} or vendor: true.
230 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700231 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
232 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900233
234 // whether this module is capable of being loaded with other instance
235 // (possibly an older version) of the same module in the same process.
236 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
237 // can be double loaded in a vendor process if the library is also a
238 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
239 // explicitly marked as `double_loadable: true` by the owner, or the dependency
240 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
241 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800242}
243
Colin Crossca860ac2016-01-04 14:34:37 -0800244type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800245 static() bool
246 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700247 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700248 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800249 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700250 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800251 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900252 isLlndk(config android.Config) bool
253 isLlndkPublic(config android.Config) bool
254 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900255 isVndk() bool
256 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800257 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900258 inRecovery() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900259 shouldCreateVndkSourceAbiDump(config android.Config) bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700260 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700261 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800262 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800263 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800264 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800265 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900266 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900267 hasStubsVariants() bool
268 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900269 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800270 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700271 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800272}
273
274type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700275 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800276 ModuleContextIntf
277}
278
279type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700280 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800281 ModuleContextIntf
282}
283
Colin Cross37047f12016-12-13 17:06:13 -0800284type DepsContext interface {
285 android.BottomUpMutatorContext
286 ModuleContextIntf
287}
288
Colin Crossca860ac2016-01-04 14:34:37 -0800289type feature interface {
290 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800291 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800292 flags(ctx ModuleContext, flags Flags) Flags
293 props() []interface{}
294}
295
296type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700297 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800298 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800299 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700300 compilerProps() []interface{}
301
Colin Cross76fada02016-07-27 10:31:13 -0700302 appendCflags([]string)
303 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700304 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800305}
306
307type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700308 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800309 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700310 linkerFlags(ctx ModuleContext, flags Flags) Flags
311 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800312 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700313
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700314 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700315 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900316 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700317
318 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800319}
320
321type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700322 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700323 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800324 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700325 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700326 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900327 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800328}
329
Colin Crossc99deeb2016-04-11 15:06:20 -0700330type dependencyTag struct {
331 blueprint.BaseDependencyTag
332 name string
333 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700334
335 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900336
337 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700338}
339
340var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700341 sharedDepTag = dependencyTag{name: "shared", library: true}
342 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900343 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700344 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
345 staticDepTag = dependencyTag{name: "static", library: true}
346 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
347 lateStaticDepTag = dependencyTag{name: "late static", library: true}
348 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800349 headerDepTag = dependencyTag{name: "header", library: true}
350 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700351 genSourceDepTag = dependencyTag{name: "gen source"}
352 genHeaderDepTag = dependencyTag{name: "gen header"}
353 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
354 objDepTag = dependencyTag{name: "obj"}
355 crtBeginDepTag = dependencyTag{name: "crtbegin"}
356 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700357 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
358 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700359 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900360 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700361 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
362 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800363 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800364 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700365)
366
Colin Crossca860ac2016-01-04 14:34:37 -0800367// Module contains the properties and members used by all C/C++ module types, and implements
368// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
369// to construct the output file. Behavior can be customized with a Customizer interface
370type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700371 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700372 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900373 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700374
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700375 Properties BaseProperties
376 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700377
Colin Crossca860ac2016-01-04 14:34:37 -0800378 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700379 hod android.HostOrDeviceSupported
380 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700381
Colin Crossca860ac2016-01-04 14:34:37 -0800382 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700383 features []feature
384 compiler compiler
385 linker linker
386 installer installer
387 stl *stl
388 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800389 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800390 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900391 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700392 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700393 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800394 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800395
396 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700397
Colin Cross635c3b02016-05-18 15:37:25 -0700398 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800399
Colin Crossb98c8b02016-07-29 13:44:28 -0700400 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700401
402 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800403
404 // Flags used to compile this module
405 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700406
407 // 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 -0800408 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700409 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800410 depsInLinkOrder android.Paths
411
412 // only non-nil when this is a shared library that reuses the objects of a static library
413 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900414
415 makeLinkType string
Colin Crossc472d572015-03-17 15:06:21 -0700416}
417
Jiyong Parkc20eee32018-09-05 22:36:17 +0900418func (c *Module) OutputFile() android.OptionalPath {
419 return c.outputFile
420}
421
Jiyong Park719b4462019-01-13 00:39:51 +0900422func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900423 if c.linker != nil {
424 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900425 }
426 return nil
427}
428
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900429func (c *Module) RelativeInstallPath() string {
430 if c.installer != nil {
431 return c.installer.relativeInstallPath()
432 }
433 return ""
434}
435
Colin Cross36242852017-06-23 15:06:31 -0700436func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700437 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800438 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700439 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800440 }
441 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700442 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800443 }
444 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700445 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800446 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700447 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700448 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700449 }
Colin Cross16b23492016-01-06 14:41:07 -0800450 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700451 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800452 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800453 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700454 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800455 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800456 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700457 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800458 }
Justin Yun8effde42017-06-23 19:24:43 +0900459 if c.vndkdep != nil {
460 c.AddProperties(c.vndkdep.props()...)
461 }
Stephen Craneba090d12017-05-09 15:44:35 -0700462 if c.lto != nil {
463 c.AddProperties(c.lto.props()...)
464 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700465 if c.pgo != nil {
466 c.AddProperties(c.pgo.props()...)
467 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800468 if c.xom != nil {
469 c.AddProperties(c.xom.props()...)
470 }
Colin Crossca860ac2016-01-04 14:34:37 -0800471 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700472 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800473 }
Colin Crossc472d572015-03-17 15:06:21 -0700474
Colin Crossa9d8bee2018-10-02 13:59:46 -0700475 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
476 switch class {
477 case android.Device:
478 return ctx.Config().DevicePrefer32BitExecutables()
479 case android.HostCross:
480 // Windows builds always prefer 32-bit
481 return true
482 default:
483 return false
484 }
485 })
Colin Cross36242852017-06-23 15:06:31 -0700486 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700487
Colin Cross1f44a3a2017-07-07 14:33:33 -0700488 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700489
Jiyong Park9d452992018-10-03 00:38:19 +0900490 android.InitApexModule(c)
491
Colin Cross36242852017-06-23 15:06:31 -0700492 return c
Colin Crossc472d572015-03-17 15:06:21 -0700493}
494
Colin Crossb916a382016-07-29 17:28:03 -0700495// Returns true for dependency roots (binaries)
496// TODO(ccross): also handle dlopenable libraries
497func (c *Module) isDependencyRoot() bool {
498 if root, ok := c.linker.(interface {
499 isDependencyRoot() bool
500 }); ok {
501 return root.isDependencyRoot()
502 }
503 return false
504}
505
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700506func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700507 return c.Properties.UseVndk
508}
509
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800510func (c *Module) isCoverageVariant() bool {
511 return c.coverage.Properties.IsCoverageVariant
512}
513
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800514func (c *Module) isNdk() bool {
515 return inList(c.Name(), ndkMigratedLibs)
516}
517
Inseob Kim9516ee92019-05-09 10:56:13 +0900518func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800519 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900520 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800521}
522
Inseob Kim9516ee92019-05-09 10:56:13 +0900523func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800524 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900525 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800526}
527
Inseob Kim9516ee92019-05-09 10:56:13 +0900528func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800529 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900530 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800531}
532
Justin Yun8effde42017-06-23 19:24:43 +0900533func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800534 if vndkdep := c.vndkdep; vndkdep != nil {
535 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900536 }
537 return false
538}
539
Jooyung Han76106d92019-05-20 18:49:10 +0900540func (c *Module) vndkVersion() string {
541 if vndkdep := c.vndkdep; vndkdep != nil {
542 return vndkdep.Properties.Vndk.Version
543 }
544 return ""
545}
546
Yi Kong7e53c572018-02-14 18:16:12 +0800547func (c *Module) isPgoCompile() bool {
548 if pgo := c.pgo; pgo != nil {
549 return pgo.Properties.PgoCompile
550 }
551 return false
552}
553
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800554func (c *Module) isNDKStubLibrary() bool {
555 if _, ok := c.compiler.(*stubDecorator); ok {
556 return true
557 }
558 return false
559}
560
Logan Chienf3511742017-10-31 18:04:35 +0800561func (c *Module) isVndkSp() bool {
562 if vndkdep := c.vndkdep; vndkdep != nil {
563 return vndkdep.isVndkSp()
564 }
565 return false
566}
567
568func (c *Module) isVndkExt() bool {
569 if vndkdep := c.vndkdep; vndkdep != nil {
570 return vndkdep.isVndkExt()
571 }
572 return false
573}
574
Vic Yangefd249e2018-11-12 20:19:56 -0800575func (c *Module) mustUseVendorVariant() bool {
576 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
577}
578
Logan Chienf3511742017-10-31 18:04:35 +0800579func (c *Module) getVndkExtendsModuleName() string {
580 if vndkdep := c.vndkdep; vndkdep != nil {
581 return vndkdep.getVndkExtendsModuleName()
582 }
583 return ""
584}
585
Jiyong Park82e2bf32017-08-16 14:05:54 +0900586// Returns true only when this module is configured to have core and vendor
587// variants.
588func (c *Module) hasVendorVariant() bool {
589 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
590}
591
Jiyong Parkf9332f12018-02-01 00:54:12 +0900592func (c *Module) inRecovery() bool {
593 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
594}
595
596func (c *Module) onlyInRecovery() bool {
597 return c.ModuleBase.InstallInRecovery()
598}
599
Jiyong Park25fc6a92018-11-18 18:02:45 +0900600func (c *Module) IsStubs() bool {
601 if library, ok := c.linker.(*libraryDecorator); ok {
602 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900603 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
604 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900605 }
606 return false
607}
608
609func (c *Module) HasStubsVariants() bool {
610 if library, ok := c.linker.(*libraryDecorator); ok {
611 return len(library.Properties.Stubs.Versions) > 0
612 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700613 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
614 return len(library.Properties.Stubs.Versions) > 0
615 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900616 return false
617}
618
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900619func (c *Module) bootstrap() bool {
620 return Bool(c.Properties.Bootstrap)
621}
622
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700623func (c *Module) nativeCoverage() bool {
624 return c.linker != nil && c.linker.nativeCoverage()
625}
626
Jiyong Parkf1194352019-02-25 11:05:47 +0900627func isBionic(name string) bool {
628 switch name {
629 case "libc", "libm", "libdl", "linker":
630 return true
631 }
632 return false
633}
634
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700635func installToBootstrap(name string, config android.Config) bool {
636 if name == "libclang_rt.hwasan-aarch64-android" {
637 return inList("hwaddress", config.SanitizeDevice())
638 }
639 return isBionic(name)
640}
641
Colin Crossca860ac2016-01-04 14:34:37 -0800642type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700643 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800644 moduleContextImpl
645}
646
Colin Cross37047f12016-12-13 17:06:13 -0800647type depsContext struct {
648 android.BottomUpMutatorContext
649 moduleContextImpl
650}
651
Colin Crossca860ac2016-01-04 14:34:37 -0800652type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700653 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800654 moduleContextImpl
655}
656
Jiyong Park2db76922017-11-08 16:03:48 +0900657func (ctx *moduleContext) SocSpecific() bool {
658 return ctx.ModuleContext.SocSpecific() ||
659 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700660}
661
Colin Crossca860ac2016-01-04 14:34:37 -0800662type moduleContextImpl struct {
663 mod *Module
664 ctx BaseModuleContext
665}
666
Colin Crossb98c8b02016-07-29 13:44:28 -0700667func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800668 return ctx.mod.toolchain(ctx.ctx)
669}
670
671func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000672 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800673}
674
675func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900676 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800677}
678
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700679func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800680 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800681 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700682 }
683 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800684}
685
686func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700687 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700688 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900689 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700690 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900691 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
692 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
693 return "current"
694 }
695 return platform_vndk_ver
696 }
697 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800698 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900699 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700700 }
701 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800702}
703
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700704func (ctx *moduleContextImpl) useVndk() bool {
705 return ctx.mod.useVndk()
706}
Justin Yun8effde42017-06-23 19:24:43 +0900707
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800708func (ctx *moduleContextImpl) isNdk() bool {
709 return ctx.mod.isNdk()
710}
711
Inseob Kim9516ee92019-05-09 10:56:13 +0900712func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
713 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800714}
715
Inseob Kim9516ee92019-05-09 10:56:13 +0900716func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
717 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800718}
719
Inseob Kim9516ee92019-05-09 10:56:13 +0900720func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
721 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800722}
723
Logan Chienf3511742017-10-31 18:04:35 +0800724func (ctx *moduleContextImpl) isVndk() bool {
725 return ctx.mod.isVndk()
726}
727
Yi Kong7e53c572018-02-14 18:16:12 +0800728func (ctx *moduleContextImpl) isPgoCompile() bool {
729 return ctx.mod.isPgoCompile()
730}
731
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800732func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
733 return ctx.mod.isNDKStubLibrary()
734}
735
Justin Yun8effde42017-06-23 19:24:43 +0900736func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800737 return ctx.mod.isVndkSp()
738}
739
740func (ctx *moduleContextImpl) isVndkExt() bool {
741 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900742}
743
Vic Yangefd249e2018-11-12 20:19:56 -0800744func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
745 return ctx.mod.mustUseVendorVariant()
746}
747
Jiyong Parkf9332f12018-02-01 00:54:12 +0900748func (ctx *moduleContextImpl) inRecovery() bool {
749 return ctx.mod.inRecovery()
750}
751
Logan Chien2f2b8902018-07-10 15:01:19 +0800752// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900753func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800754 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
755 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800756 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800757
758 if ctx.ctx.Fuchsia() {
759 return false
760 }
761
Logan Chien2f2b8902018-07-10 15:01:19 +0800762 if sanitize := ctx.mod.sanitize; sanitize != nil {
763 if !sanitize.isVariantOnProductionDevice() {
764 return false
765 }
766 }
767 if !ctx.ctx.Device() {
768 // Host modules do not need ABI dumps.
769 return false
770 }
Logan Chienfa478c02018-12-28 16:25:39 +0800771 if !ctx.mod.IsForPlatform() {
772 // APEX variants do not need ABI dumps.
773 return false
774 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800775 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800776 return true
777 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900778 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800779 return true
780 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900781 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800782 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
783 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800784 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800785 }
786 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800787}
788
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700789func (ctx *moduleContextImpl) selectedStl() string {
790 if stl := ctx.mod.stl; stl != nil {
791 return stl.Properties.SelectedStl
792 }
793 return ""
794}
795
Ivan Lozanobd721262018-11-27 14:33:03 -0800796func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
797 return ctx.mod.linker.useClangLld(actx)
798}
799
Colin Crossce75d2c2016-10-06 16:12:58 -0700800func (ctx *moduleContextImpl) baseModuleName() string {
801 return ctx.mod.ModuleBase.BaseModuleName()
802}
803
Logan Chienf3511742017-10-31 18:04:35 +0800804func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
805 return ctx.mod.getVndkExtendsModuleName()
806}
807
Jiyong Park58e364a2019-01-19 19:24:06 +0900808func (ctx *moduleContextImpl) apexName() string {
809 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900810}
811
Jiyong Parkb0788572018-12-20 22:10:17 +0900812func (ctx *moduleContextImpl) hasStubsVariants() bool {
813 return ctx.mod.HasStubsVariants()
814}
815
816func (ctx *moduleContextImpl) isStubs() bool {
817 return ctx.mod.IsStubs()
818}
819
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900820func (ctx *moduleContextImpl) bootstrap() bool {
821 return ctx.mod.bootstrap()
822}
823
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700824func (ctx *moduleContextImpl) nativeCoverage() bool {
825 return ctx.mod.nativeCoverage()
826}
827
Colin Cross635c3b02016-05-18 15:37:25 -0700828func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800829 return &Module{
830 hod: hod,
831 multilib: multilib,
832 }
833}
834
Colin Cross635c3b02016-05-18 15:37:25 -0700835func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800836 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700837 module.features = []feature{
838 &tidyFeature{},
839 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700840 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800841 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800842 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800843 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900844 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700845 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700846 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800847 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800848 return module
849}
850
Colin Crossce75d2c2016-10-06 16:12:58 -0700851func (c *Module) Prebuilt() *android.Prebuilt {
852 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
853 return p.prebuilt()
854 }
855 return nil
856}
857
858func (c *Module) Name() string {
859 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700860 if p, ok := c.linker.(interface {
861 Name(string) string
862 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700863 name = p.Name(name)
864 }
865 return name
866}
867
Alex Light3d673592019-01-18 14:37:31 -0800868func (c *Module) Symlinks() []string {
869 if p, ok := c.installer.(interface {
870 symlinkList() []string
871 }); ok {
872 return p.symlinkList()
873 }
874 return nil
875}
876
Jeff Gaston294356f2017-09-27 17:05:30 -0700877// orderDeps reorders dependencies into a list such that if module A depends on B, then
878// A will precede B in the resultant list.
879// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800880// Note that directSharedDeps should be the analogous static library for each shared lib dep
881func 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 -0700882 // If A depends on B, then
883 // Every list containing A will also contain B later in the list
884 // So, after concatenating all lists, the final instance of B will have come from the same
885 // original list as the final instance of A
886 // So, the final instance of B will be later in the concatenation than the final A
887 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
888 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800889 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700890 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800891 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
892 }
893 for _, dep := range directSharedDeps {
894 orderedAllDeps = append(orderedAllDeps, dep)
895 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700896 }
897
Colin Crossb6715442017-10-24 11:13:31 -0700898 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700899
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800900 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700901 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800902 // resultant list to only what the caller has chosen to include in directStaticDeps
903 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700904
905 return orderedAllDeps, orderedDeclaredDeps
906}
907
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800908func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
909 // convert Module to Path
910 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
911 staticDepFiles := []android.Path{}
912 for _, dep := range staticDeps {
913 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
914 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700915 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800916 sharedDepFiles := []android.Path{}
917 for _, sharedDep := range sharedDeps {
918 staticAnalogue := sharedDep.staticVariant
919 if staticAnalogue != nil {
920 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
921 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
922 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700923 }
924
925 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800926 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700927
928 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700929}
930
Colin Cross635c3b02016-05-18 15:37:25 -0700931func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jooyung Han38002912019-05-16 04:01:54 +0900932 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900933
Colin Crossca860ac2016-01-04 14:34:37 -0800934 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700935 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800936 moduleContextImpl: moduleContextImpl{
937 mod: c,
938 },
939 }
940 ctx.ctx = ctx
941
Colin Crossf18e1102017-11-16 14:33:08 -0800942 deps := c.depsToPaths(ctx)
943 if ctx.Failed() {
944 return
945 }
946
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700947 if c.Properties.Clang != nil && *c.Properties.Clang == false {
948 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
949 }
950
Colin Crossca860ac2016-01-04 14:34:37 -0800951 flags := Flags{
952 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800953 }
Colin Crossca860ac2016-01-04 14:34:37 -0800954 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800955 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800956 }
957 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700958 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800959 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700960 if c.stl != nil {
961 flags = c.stl.flags(ctx, flags)
962 }
Colin Cross16b23492016-01-06 14:41:07 -0800963 if c.sanitize != nil {
964 flags = c.sanitize.flags(ctx, flags)
965 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800966 if c.coverage != nil {
967 flags = c.coverage.flags(ctx, flags)
968 }
Stephen Craneba090d12017-05-09 15:44:35 -0700969 if c.lto != nil {
970 flags = c.lto.flags(ctx, flags)
971 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700972 if c.pgo != nil {
973 flags = c.pgo.flags(ctx, flags)
974 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800975 if c.xom != nil {
976 flags = c.xom.flags(ctx, flags)
977 }
Colin Crossca860ac2016-01-04 14:34:37 -0800978 for _, feature := range c.features {
979 flags = feature.flags(ctx, flags)
980 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800981 if ctx.Failed() {
982 return
983 }
984
Colin Crossb98c8b02016-07-29 13:44:28 -0700985 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
986 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
987 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800988
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800989 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
990 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700991 // We need access to all the flags seen by a source file.
992 if c.sabi != nil {
993 flags = c.sabi.flags(ctx, flags)
994 }
Colin Crossca860ac2016-01-04 14:34:37 -0800995 // Optimization to reduce size of build.ninja
996 // Replace the long list of flags for each file with a module-local variable
997 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
998 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
999 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1000 flags.CFlags = []string{"$cflags"}
1001 flags.CppFlags = []string{"$cppflags"}
1002 flags.AsFlags = []string{"$asflags"}
1003
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001004 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001005 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001006 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001007 if ctx.Failed() {
1008 return
1009 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001010 }
1011
Colin Crossca860ac2016-01-04 14:34:37 -08001012 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001013 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001014 if ctx.Failed() {
1015 return
1016 }
Colin Cross635c3b02016-05-18 15:37:25 -07001017 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001018
1019 // If a lib is directly included in any of the APEXes, unhide the stubs
1020 // variant having the latest version gets visible to make. In addition,
1021 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1022 // force anything in the make world to link against the stubs library.
1023 // (unless it is explicitly referenced via .bootstrap suffix or the
1024 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001025 if c.HasStubsVariants() &&
1026 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001027 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1028 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001029 c.Properties.HideFromMake = false // unhide
1030 // Note: this is still non-installable
1031 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001032 }
Colin Cross5049f022015-03-18 13:28:46 -07001033
Inseob Kim1f086e22019-05-09 13:29:15 +09001034 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001035 c.installer.install(ctx, c.outputFile.Path())
1036 if ctx.Failed() {
1037 return
Colin Crossca860ac2016-01-04 14:34:37 -08001038 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001039 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001040}
1041
Jiyong Park379de2f2018-12-19 02:47:14 +09001042func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001043 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001044 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001045 }
Colin Crossca860ac2016-01-04 14:34:37 -08001046 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001047}
1048
Colin Crossca860ac2016-01-04 14:34:37 -08001049func (c *Module) begin(ctx BaseModuleContext) {
1050 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001051 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001052 }
Colin Crossca860ac2016-01-04 14:34:37 -08001053 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001054 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001055 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001056 if c.stl != nil {
1057 c.stl.begin(ctx)
1058 }
Colin Cross16b23492016-01-06 14:41:07 -08001059 if c.sanitize != nil {
1060 c.sanitize.begin(ctx)
1061 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001062 if c.coverage != nil {
1063 c.coverage.begin(ctx)
1064 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001065 if c.sabi != nil {
1066 c.sabi.begin(ctx)
1067 }
Justin Yun8effde42017-06-23 19:24:43 +09001068 if c.vndkdep != nil {
1069 c.vndkdep.begin(ctx)
1070 }
Stephen Craneba090d12017-05-09 15:44:35 -07001071 if c.lto != nil {
1072 c.lto.begin(ctx)
1073 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001074 if c.pgo != nil {
1075 c.pgo.begin(ctx)
1076 }
Colin Crossca860ac2016-01-04 14:34:37 -08001077 for _, feature := range c.features {
1078 feature.begin(ctx)
1079 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001080 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001081 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001082 if err != nil {
1083 ctx.PropertyErrorf("sdk_version", err.Error())
1084 }
Nan Zhang0007d812017-11-07 10:57:05 -08001085 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001086 }
Colin Crossca860ac2016-01-04 14:34:37 -08001087}
1088
Colin Cross37047f12016-12-13 17:06:13 -08001089func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001090 deps := Deps{}
1091
1092 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001093 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001094 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001095 // Add the PGO dependency (the clang_rt.profile runtime library), which
1096 // sometimes depends on symbols from libgcc, before libgcc gets added
1097 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001098 if c.pgo != nil {
1099 deps = c.pgo.deps(ctx, deps)
1100 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001101 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001102 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001103 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001104 if c.stl != nil {
1105 deps = c.stl.deps(ctx, deps)
1106 }
Colin Cross16b23492016-01-06 14:41:07 -08001107 if c.sanitize != nil {
1108 deps = c.sanitize.deps(ctx, deps)
1109 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001110 if c.coverage != nil {
1111 deps = c.coverage.deps(ctx, deps)
1112 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001113 if c.sabi != nil {
1114 deps = c.sabi.deps(ctx, deps)
1115 }
Justin Yun8effde42017-06-23 19:24:43 +09001116 if c.vndkdep != nil {
1117 deps = c.vndkdep.deps(ctx, deps)
1118 }
Stephen Craneba090d12017-05-09 15:44:35 -07001119 if c.lto != nil {
1120 deps = c.lto.deps(ctx, deps)
1121 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001122 for _, feature := range c.features {
1123 deps = feature.deps(ctx, deps)
1124 }
1125
Colin Crossb6715442017-10-24 11:13:31 -07001126 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1127 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1128 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1129 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1130 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1131 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001132 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001133
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001134 for _, lib := range deps.ReexportSharedLibHeaders {
1135 if !inList(lib, deps.SharedLibs) {
1136 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1137 }
1138 }
1139
1140 for _, lib := range deps.ReexportStaticLibHeaders {
1141 if !inList(lib, deps.StaticLibs) {
1142 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1143 }
1144 }
1145
Colin Cross5950f382016-12-13 12:50:57 -08001146 for _, lib := range deps.ReexportHeaderLibHeaders {
1147 if !inList(lib, deps.HeaderLibs) {
1148 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1149 }
1150 }
1151
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001152 for _, gen := range deps.ReexportGeneratedHeaders {
1153 if !inList(gen, deps.GeneratedHeaders) {
1154 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1155 }
1156 }
1157
Colin Crossc99deeb2016-04-11 15:06:20 -07001158 return deps
1159}
1160
Dan Albert7e9d2952016-08-04 13:02:36 -07001161func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001162 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001163 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001164 moduleContextImpl: moduleContextImpl{
1165 mod: c,
1166 },
1167 }
1168 ctx.ctx = ctx
1169
Colin Crossca860ac2016-01-04 14:34:37 -08001170 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001171}
1172
Jiyong Park7ed9de32018-10-15 22:25:07 +09001173// Split name#version into name and version
1174func stubsLibNameAndVersion(name string) (string, string) {
1175 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1176 version := name[sharp+1:]
1177 libname := name[:sharp]
1178 return libname, version
1179 }
1180 return name, ""
1181}
1182
Colin Cross1e676be2016-10-12 14:38:15 -07001183func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001184 ctx := &depsContext{
1185 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001186 moduleContextImpl: moduleContextImpl{
1187 mod: c,
1188 },
1189 }
1190 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001191
Colin Crossc99deeb2016-04-11 15:06:20 -07001192 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001193
Dan Albert914449f2016-06-17 16:45:24 -07001194 variantNdkLibs := []string{}
1195 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001196 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001197 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001198
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001199 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1200 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001201 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001202 // 1. Name of an NDK library that refers to a prebuilt module.
1203 // For each of these, it adds the name of the prebuilt module (which will be in
1204 // prebuilts/ndk) to the list of nonvariant libs.
1205 // 2. Name of an NDK library that refers to an ndk_library module.
1206 // For each of these, it adds the name of the ndk_library module to the list of
1207 // variant libs.
1208 // 3. Anything else (so anything that isn't an NDK library).
1209 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001210 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001211 // The caller can then know to add the variantLibs dependencies differently from the
1212 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001213
1214 llndkLibraries := llndkLibraries(actx.Config())
1215 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001216 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1217 variantLibs = []string{}
1218 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001219 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001220 // strip #version suffix out
1221 name, _ := stubsLibNameAndVersion(entry)
1222 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1223 if !inList(name, ndkMigratedLibs) {
1224 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001225 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001226 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001227 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001228 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001229 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001230 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001231 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001232 if actx.OtherModuleExists(vendorPublicLib) {
1233 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1234 } else {
1235 // This can happen if vendor_public_library module is defined in a
1236 // namespace that isn't visible to the current module. In that case,
1237 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001238 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001239 }
Dan Albert914449f2016-06-17 16:45:24 -07001240 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001241 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001242 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001243 }
1244 }
Dan Albert914449f2016-06-17 16:45:24 -07001245 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001246 }
1247
Dan Albert914449f2016-06-17 16:45:24 -07001248 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1249 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001250 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001251 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001252
Jiyong Park7e636d02019-01-28 16:16:54 +09001253 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001254 if c.linker != nil {
1255 if library, ok := c.linker.(*libraryDecorator); ok {
1256 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001257 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001258 }
1259 }
1260 }
1261
Colin Cross32ec36c2016-12-15 07:39:51 -08001262 for _, lib := range deps.HeaderLibs {
1263 depTag := headerDepTag
1264 if inList(lib, deps.ReexportHeaderLibHeaders) {
1265 depTag = headerExportDepTag
1266 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001267 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001268 actx.AddFarVariationDependencies([]blueprint.Variation{
1269 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001270 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001271 }, depTag, lib)
1272 } else {
1273 actx.AddVariationDependencies(nil, depTag, lib)
1274 }
1275 }
1276
1277 if buildStubs {
1278 // Stubs lib does not have dependency to other static/shared libraries.
1279 // Don't proceed.
1280 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001281 }
Colin Cross5950f382016-12-13 12:50:57 -08001282
Inseob Kimc0907f12019-02-08 21:00:45 +09001283 syspropImplLibraries := syspropImplLibraries(actx.Config())
1284
Jiyong Park5d1598f2019-02-25 22:14:17 +09001285 for _, lib := range deps.WholeStaticLibs {
1286 depTag := wholeStaticDepTag
1287 if impl, ok := syspropImplLibraries[lib]; ok {
1288 lib = impl
1289 }
1290 actx.AddVariationDependencies([]blueprint.Variation{
1291 {Mutator: "link", Variation: "static"},
1292 }, depTag, lib)
1293 }
1294
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001295 for _, lib := range deps.StaticLibs {
1296 depTag := staticDepTag
1297 if inList(lib, deps.ReexportStaticLibHeaders) {
1298 depTag = staticExportDepTag
1299 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001300
1301 if impl, ok := syspropImplLibraries[lib]; ok {
1302 lib = impl
1303 }
1304
Dan Willemsen59339a22018-07-22 21:18:45 -07001305 actx.AddVariationDependencies([]blueprint.Variation{
1306 {Mutator: "link", Variation: "static"},
1307 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001308 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001309
Dan Willemsen59339a22018-07-22 21:18:45 -07001310 actx.AddVariationDependencies([]blueprint.Variation{
1311 {Mutator: "link", Variation: "static"},
1312 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001313
Jiyong Park25fc6a92018-11-18 18:02:45 +09001314 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1315 var variations []blueprint.Variation
1316 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001317 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001318 if version != "" && versionVariantAvail {
1319 // Version is explicitly specified. i.e. libFoo#30
1320 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1321 depTag.explicitlyVersioned = true
1322 }
1323 actx.AddVariationDependencies(variations, depTag, name)
1324
1325 // If the version is not specified, add dependency to the latest stubs library.
1326 // The stubs library will be used when the depending module is built for APEX and
1327 // the dependent module is not in the same APEX.
1328 latestVersion := latestStubsVersionFor(actx.Config(), name)
1329 if version == "" && latestVersion != "" && versionVariantAvail {
1330 actx.AddVariationDependencies([]blueprint.Variation{
1331 {Mutator: "link", Variation: "shared"},
1332 {Mutator: "version", Variation: latestVersion},
1333 }, depTag, name)
1334 // Note that depTag.explicitlyVersioned is false in this case.
1335 }
1336 }
1337
Jiyong Park7ed9de32018-10-15 22:25:07 +09001338 // shared lib names without the #version suffix
1339 var sharedLibNames []string
1340
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001341 for _, lib := range deps.SharedLibs {
1342 depTag := sharedDepTag
1343 if inList(lib, deps.ReexportSharedLibHeaders) {
1344 depTag = sharedExportDepTag
1345 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001346
1347 if impl, ok := syspropImplLibraries[lib]; ok {
1348 lib = impl
1349 }
1350
1351 name, version := stubsLibNameAndVersion(lib)
1352 sharedLibNames = append(sharedLibNames, name)
1353
Jiyong Park25fc6a92018-11-18 18:02:45 +09001354 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001355 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001356
Jiyong Park7ed9de32018-10-15 22:25:07 +09001357 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001358 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001359 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1360 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1361 // linking against both the stubs lib and the non-stubs lib at the same time.
1362 continue
1363 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001364 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001365 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001366
Dan Willemsen59339a22018-07-22 21:18:45 -07001367 actx.AddVariationDependencies([]blueprint.Variation{
1368 {Mutator: "link", Variation: "shared"},
1369 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001370
Colin Cross68861832016-07-08 10:41:41 -07001371 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001372
1373 for _, gen := range deps.GeneratedHeaders {
1374 depTag := genHeaderDepTag
1375 if inList(gen, deps.ReexportGeneratedHeaders) {
1376 depTag = genHeaderExportDepTag
1377 }
1378 actx.AddDependency(c, depTag, gen)
1379 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001380
Colin Cross42d48b72018-08-29 14:10:52 -07001381 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001382
1383 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001384 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001385 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001386 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001387 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001388 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001389 if deps.LinkerFlagsFile != "" {
1390 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1391 }
1392 if deps.DynamicLinker != "" {
1393 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001394 }
Dan Albert914449f2016-06-17 16:45:24 -07001395
1396 version := ctx.sdkVersion()
1397 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001398 {Mutator: "ndk_api", Variation: version},
1399 {Mutator: "link", Variation: "shared"},
1400 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001401 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001402 {Mutator: "ndk_api", Variation: version},
1403 {Mutator: "link", Variation: "shared"},
1404 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001405
1406 if vndkdep := c.vndkdep; vndkdep != nil {
1407 if vndkdep.isVndkExt() {
1408 baseModuleMode := vendorMode
1409 if actx.DeviceConfig().VndkVersion() == "" {
1410 baseModuleMode = coreMode
1411 }
1412 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001413 {Mutator: "image", Variation: baseModuleMode},
1414 {Mutator: "link", Variation: "shared"},
1415 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001416 }
1417 }
Colin Cross6362e272015-10-29 15:25:03 -07001418}
Colin Cross21b9a242015-03-24 14:15:58 -07001419
Colin Crosse40b4ea2018-10-02 22:25:58 -07001420func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001421 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1422 c.beginMutator(ctx)
1423 }
1424}
1425
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001426// Whether a module can link to another module, taking into
1427// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001428func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001429 if from.Target().Os != android.Android {
1430 // Host code is not restricted
1431 return
1432 }
1433 if from.Properties.UseVndk {
1434 // Though vendor code is limited by the vendor mutator,
1435 // each vendor-available module needs to check
1436 // link-type for VNDK.
1437 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001438 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001439 }
1440 return
1441 }
Nan Zhang0007d812017-11-07 10:57:05 -08001442 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001443 // Platform code can link to anything
1444 return
1445 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001446 if from.inRecovery() {
1447 // Recovery code is not NDK
1448 return
1449 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001450 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1451 // These are always allowed
1452 return
1453 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001454 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1455 // These are allowed, but they don't set sdk_version
1456 return
1457 }
1458 if _, ok := to.linker.(*stubDecorator); ok {
1459 // These aren't real libraries, but are the stub shared libraries that are included in
1460 // the NDK.
1461 return
1462 }
Logan Chien834b9a62019-01-14 15:39:03 +08001463
1464 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1465 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1466 // to link to libc++ (non-NDK and without sdk_version).
1467 return
1468 }
1469
Nan Zhang0007d812017-11-07 10:57:05 -08001470 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001471 // NDK code linking to platform code is never okay.
1472 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1473 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001474 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001475 }
1476
1477 // At this point we know we have two NDK libraries, but we need to
1478 // check that we're not linking against anything built against a higher
1479 // API level, as it is only valid to link against older or equivalent
1480 // APIs.
1481
Inseob Kim01a28722018-04-11 09:48:45 +09001482 // Current can link against anything.
1483 if String(from.Properties.Sdk_version) != "current" {
1484 // Otherwise we need to check.
1485 if String(to.Properties.Sdk_version) == "current" {
1486 // Current can't be linked against by anything else.
1487 ctx.ModuleErrorf("links %q built against newer API version %q",
1488 ctx.OtherModuleName(to), "current")
1489 } else {
1490 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1491 if err != nil {
1492 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001493 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001494 String(from.Properties.Sdk_version))
1495 }
1496 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1497 if err != nil {
1498 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001499 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001500 String(to.Properties.Sdk_version))
1501 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001502
Inseob Kim01a28722018-04-11 09:48:45 +09001503 if toApi > fromApi {
1504 ctx.ModuleErrorf("links %q built against newer API version %q",
1505 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1506 }
1507 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001508 }
Dan Albert202fe492017-12-15 13:56:59 -08001509
1510 // Also check that the two STL choices are compatible.
1511 fromStl := from.stl.Properties.SelectedStl
1512 toStl := to.stl.Properties.SelectedStl
1513 if fromStl == "" || toStl == "" {
1514 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001515 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001516 // We can be permissive with the system "STL" since it is only the C++
1517 // ABI layer, but in the future we should make sure that everyone is
1518 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001519 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001520 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1521 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1522 to.stl.Properties.SelectedStl)
1523 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001524}
1525
Jiyong Park5fb8c102018-04-09 12:03:06 +09001526// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001527// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1528// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001529// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001530func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001531 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001532 check := func(child, parent android.Module) bool {
1533 to, ok := child.(*Module)
1534 if !ok {
1535 // follow thru cc.Defaults, etc.
1536 return true
1537 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001538
Jooyung Hana70f0672019-01-18 15:20:43 +09001539 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1540 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001541 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001542
1543 // if target lib has no vendor variant, keep checking dependency graph
1544 if !to.hasVendorVariant() {
1545 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001546 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001547
Inseob Kim9516ee92019-05-09 10:56:13 +09001548 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001549 return false
1550 }
1551
1552 var stringPath []string
1553 for _, m := range ctx.GetWalkPath() {
1554 stringPath = append(stringPath, m.Name())
1555 }
1556 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1557 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1558 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1559 return false
1560 }
1561 if module, ok := ctx.Module().(*Module); ok {
1562 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001563 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001564 ctx.WalkDeps(check)
1565 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001566 }
1567 }
1568}
1569
Colin Crossc99deeb2016-04-11 15:06:20 -07001570// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001571func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001572 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001573
Jeff Gaston294356f2017-09-27 17:05:30 -07001574 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001575 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001576
Inseob Kim9516ee92019-05-09 10:56:13 +09001577 llndkLibraries := llndkLibraries(ctx.Config())
1578 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1579
Colin Crossd11fcda2017-10-23 17:59:01 -07001580 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001581 depName := ctx.OtherModuleName(dep)
1582 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001583
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001584 ccDep, _ := dep.(*Module)
1585 if ccDep == nil {
1586 // handling for a few module types that aren't cc Module but that are also supported
1587 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001588 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001589 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001590 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1591 genRule.GeneratedSourceFiles()...)
1592 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001593 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001594 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001595 // Support exported headers from a generated_sources dependency
1596 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001597 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001598 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001599 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001600 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001601 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001602 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001603 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001604 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001605 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001606 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001607 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1608 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1609
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001610 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001611 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001612 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001613 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001614 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001615 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001616 files := genRule.GeneratedSourceFiles()
1617 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001618 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001619 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001620 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker flag file", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001621 }
1622 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001623 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001624 }
Colin Crossca860ac2016-01-04 14:34:37 -08001625 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001626 return
1627 }
1628
Colin Crossfe17f6f2019-03-28 19:30:56 -07001629 if depTag == android.ProtoPluginDepTag {
1630 return
1631 }
1632
Colin Crossd11fcda2017-10-23 17:59:01 -07001633 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001634 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1635 return
1636 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001637 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001638 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001639 return
1640 }
1641
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001642 // re-exporting flags
1643 if depTag == reuseObjTag {
1644 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001645 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001646 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001647 depPaths.Objs = depPaths.Objs.Append(objs)
1648 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001649 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001650 return
1651 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001652 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001653
Jiyong Parke4bb9862019-02-01 00:31:10 +09001654 if depTag == staticVariantTag {
1655 if _, ok := ccDep.compiler.(libraryInterface); ok {
1656 c.staticVariant = ccDep
1657 return
1658 }
1659 }
1660
Jiyong Park25fc6a92018-11-18 18:02:45 +09001661 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1662 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1663 // won't be matched to sharedDepTag and lateSharedDepTag.
1664 explicitlyVersioned := false
1665 if t, ok := depTag.(dependencyTag); ok {
1666 explicitlyVersioned = t.explicitlyVersioned
1667 t.explicitlyVersioned = false
1668 depTag = t
1669 }
1670
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001671 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001672 depIsStatic := false
1673 switch depTag {
1674 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1675 depIsStatic = true
1676 }
1677 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001678 depIsStubs := dependentLibrary.buildStubs()
1679 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001680 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001681 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001682
1683 var useThisDep bool
1684 if depIsStubs && explicitlyVersioned {
1685 // Always respect dependency to the versioned stubs (i.e. libX#10)
1686 useThisDep = true
1687 } else if !depHasStubs {
1688 // Use non-stub variant if that is the only choice
1689 // (i.e. depending on a lib without stubs.version property)
1690 useThisDep = true
1691 } else if c.IsForPlatform() {
1692 // If not building for APEX, use stubs only when it is from
1693 // an APEX (and not from platform)
1694 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001695 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001696 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001697 // always link to non-stub variant
1698 useThisDep = !depIsStubs
1699 }
1700 } else {
1701 // If building for APEX, use stubs only when it is not from
1702 // the same APEX
1703 useThisDep = (depInSameApex != depIsStubs)
1704 }
1705
1706 if !useThisDep {
1707 return // stop processing this dep
1708 }
1709 }
1710
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001711 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001712 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001713 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001714 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001715 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001716
1717 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001718 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001719 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001720 // 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 -07001721 // Re-exported shared library headers must be included as well since they can help us with type information
1722 // about template instantiations (instantiated from their headers).
1723 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001724 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001725 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001726
Logan Chienf3511742017-10-31 18:04:35 +08001727 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001728 }
1729
Colin Cross26c34ed2016-09-30 17:10:16 -07001730 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001731 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001732
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001733 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001734 depFile := android.OptionalPath{}
1735
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001736 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001737 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001738 ptr = &depPaths.SharedLibs
1739 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001740 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001741 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001742 case earlySharedDepTag:
1743 ptr = &depPaths.EarlySharedLibs
1744 depPtr = &depPaths.EarlySharedLibsDeps
1745 depFile = ccDep.linker.(libraryInterface).toc()
1746 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001747 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001748 ptr = &depPaths.LateSharedLibs
1749 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001750 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001751 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001752 ptr = nil
1753 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001754 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001755 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001756 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001757 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001758 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001759 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001760 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001761 return
1762 }
1763
1764 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001765 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001766 for i := range missingDeps {
1767 missingDeps[i] += postfix
1768 }
1769 ctx.AddMissingDependencies(missingDeps)
1770 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001771 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001772 case headerDepTag:
1773 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001774 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001775 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001776 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001777 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001778 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001779 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001780 case dynamicLinkerDepTag:
1781 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001782 }
1783
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001784 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001785 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001786 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001787 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001788 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001789 return
1790 }
1791
1792 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001793 // in static libraries act as if they were whole static libraries. The same goes for
1794 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001795 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1796 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001797 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1798 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001799
Dan Willemsen581341d2017-02-09 16:16:31 -08001800 }
1801
Colin Cross26c34ed2016-09-30 17:10:16 -07001802 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001803 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001804 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001805 return
1806 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001807 *ptr = append(*ptr, linkFile.Path())
1808 }
1809
Colin Crossc99deeb2016-04-11 15:06:20 -07001810 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001811 dep := depFile
1812 if !dep.Valid() {
1813 dep = linkFile
1814 }
1815 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001816 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001817
Logan Chien43d34c32017-12-20 01:17:32 +08001818 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001819 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001820 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001821 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001822 isLLndk := inList(libName, *llndkLibraries)
1823 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001824 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001825
1826 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1827 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1828 // core module instead.
1829 return libName
1830 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001831 // The vendor module in Make will have been renamed to not conflict with the core
1832 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001833 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001834 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001835 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001836 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1837 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001838 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001839 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001840 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001841 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001842 }
Logan Chien43d34c32017-12-20 01:17:32 +08001843 }
1844
1845 // Export the shared libs to Make.
1846 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001847 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001848 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001849 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001850 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001851 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001852 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001853 c.Properties.ApexesProvidingSharedLibs = append(
1854 c.Properties.ApexesProvidingSharedLibs, an)
1855 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001856 }
1857 }
1858
Jiyong Park27b188b2017-07-18 13:23:39 +09001859 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001860 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001861 c.Properties.AndroidMkSharedLibs = append(
1862 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001863 case ndkStubDepTag, ndkLateStubDepTag:
1864 ndkStub := ccDep.linker.(*stubDecorator)
1865 c.Properties.AndroidMkSharedLibs = append(
1866 c.Properties.AndroidMkSharedLibs,
1867 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001868 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1869 c.Properties.AndroidMkStaticLibs = append(
1870 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001871 case runtimeDepTag:
1872 c.Properties.AndroidMkRuntimeLibs = append(
1873 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001874 case wholeStaticDepTag:
1875 c.Properties.AndroidMkWholeStaticLibs = append(
1876 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001877 }
Colin Crossca860ac2016-01-04 14:34:37 -08001878 })
1879
Jeff Gaston294356f2017-09-27 17:05:30 -07001880 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001881 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001882
Colin Crossdd84e052017-05-17 13:44:16 -07001883 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001884 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001885 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001886 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001887 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1888
1889 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001890 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001891 }
Colin Crossdd84e052017-05-17 13:44:16 -07001892
Colin Crossca860ac2016-01-04 14:34:37 -08001893 return depPaths
1894}
1895
1896func (c *Module) InstallInData() bool {
1897 if c.installer == nil {
1898 return false
1899 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001900 return c.installer.inData()
1901}
1902
1903func (c *Module) InstallInSanitizerDir() bool {
1904 if c.installer == nil {
1905 return false
1906 }
1907 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001908 return true
1909 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001910 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001911}
1912
Jiyong Parkf9332f12018-02-01 00:54:12 +09001913func (c *Module) InstallInRecovery() bool {
1914 return c.inRecovery()
1915}
1916
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001917func (c *Module) HostToolPath() android.OptionalPath {
1918 if c.installer == nil {
1919 return android.OptionalPath{}
1920 }
1921 return c.installer.hostToolPath()
1922}
1923
Nan Zhangd4e641b2017-07-12 12:55:28 -07001924func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1925 return c.outputFile
1926}
1927
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001928func (c *Module) Srcs() android.Paths {
1929 if c.outputFile.Valid() {
1930 return android.Paths{c.outputFile.Path()}
1931 }
1932 return android.Paths{}
1933}
1934
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001935func (c *Module) static() bool {
1936 if static, ok := c.linker.(interface {
1937 static() bool
1938 }); ok {
1939 return static.static()
1940 }
1941 return false
1942}
1943
Jiyong Park379de2f2018-12-19 02:47:14 +09001944func (c *Module) staticBinary() bool {
1945 if static, ok := c.linker.(interface {
1946 staticBinary() bool
1947 }); ok {
1948 return static.staticBinary()
1949 }
1950 return false
1951}
1952
Jooyung Han38002912019-05-16 04:01:54 +09001953func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
1954 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07001955 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09001956 if lib, ok := c.linker.(*llndkStubDecorator); ok {
1957 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07001958 return "native:vndk"
1959 }
Jooyung Han38002912019-05-16 04:01:54 +09001960 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07001961 }
Jooyung Han38002912019-05-16 04:01:54 +09001962 if c.isVndk() && !c.isVndkExt() {
1963 if Bool(c.VendorProperties.Vendor_available) {
1964 return "native:vndk"
1965 }
1966 return "native:vndk_private"
1967 }
1968 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07001969 } else if c.inRecovery() {
1970 return "native:recovery"
1971 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1972 return "native:ndk:none:none"
1973 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1974 //family, link := getNdkStlFamilyAndLinkType(c)
1975 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09001976 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08001977 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07001978 } else {
1979 return "native:platform"
1980 }
1981}
1982
Jiyong Park9d452992018-10-03 00:38:19 +09001983// Overrides ApexModule.IsInstallabeToApex()
1984// Only shared libraries are installable to APEX.
1985func (c *Module) IsInstallableToApex() bool {
1986 if shared, ok := c.linker.(interface {
1987 shared() bool
1988 }); ok {
1989 return shared.shared()
1990 }
1991 return false
1992}
1993
Inseob Kim1f086e22019-05-09 13:29:15 +09001994func (c *Module) installable() bool {
1995 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
1996}
1997
Jiyong Park3b1746a2019-01-29 11:15:04 +09001998func (c *Module) imageVariation() string {
1999 variation := "core"
2000 if c.useVndk() {
2001 variation = "vendor"
2002 } else if c.inRecovery() {
2003 variation = "recovery"
2004 }
2005 return variation
2006}
2007
bralee3f49f4d2019-03-04 06:58:15 +08002008func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
2009 dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
2010}
2011
Logan Chien41eabe62019-04-10 13:33:58 +08002012func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2013 if c.linker != nil {
2014 if library, ok := c.linker.(*libraryDecorator); ok {
2015 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2016 }
2017 }
2018}
2019
Colin Cross2ba19d92015-05-07 15:44:20 -07002020//
Colin Crosscfad1192015-11-02 16:43:11 -08002021// Defaults
2022//
Colin Crossca860ac2016-01-04 14:34:37 -08002023type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002024 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002025 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002026 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002027}
2028
Colin Cross635c3b02016-05-18 15:37:25 -07002029func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08002030}
2031
Patrice Arrudac249c712019-03-19 17:00:29 -07002032// cc_defaults provides a set of properties that can be inherited by other cc
2033// modules. A module can use the properties from a cc_defaults using
2034// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2035// merged (when possible) by prepending the default module's values to the
2036// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002037func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002038 return DefaultsFactory()
2039}
2040
Colin Cross36242852017-06-23 15:06:31 -07002041func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002042 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002043
Colin Cross36242852017-06-23 15:06:31 -07002044 module.AddProperties(props...)
2045 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002046 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002047 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002048 &BaseCompilerProperties{},
2049 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002050 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002051 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002052 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002053 &TestProperties{},
2054 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002055 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002056 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002057 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002058 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002059 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002060 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002061 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002062 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002063 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002064 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002065 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002066 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002067 )
Colin Crosscfad1192015-11-02 16:43:11 -08002068
Colin Cross1f44a3a2017-07-07 14:33:33 -07002069 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002070 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002071
2072 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002073}
2074
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002075const (
2076 // coreMode is the variant used for framework-private libraries, or
2077 // SDK libraries. (which framework-private libraries can use)
2078 coreMode = "core"
2079
2080 // vendorMode is the variant used for /vendor code that compiles
2081 // against the VNDK.
2082 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002083
2084 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002085)
2086
Jiyong Park6a43f042017-10-12 23:05:00 +09002087func squashVendorSrcs(m *Module) {
2088 if lib, ok := m.compiler.(*libraryDecorator); ok {
2089 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2090 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2091
2092 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2093 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2094 }
2095}
2096
Jiyong Parkf9332f12018-02-01 00:54:12 +09002097func squashRecoverySrcs(m *Module) {
2098 if lib, ok := m.compiler.(*libraryDecorator); ok {
2099 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2100 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2101
2102 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2103 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2104 }
2105}
2106
Jiyong Parkda6eb592018-12-19 17:12:36 +09002107func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002108 if mctx.Os() != android.Android {
2109 return
2110 }
2111
Jiyong Park7ed9de32018-10-15 22:25:07 +09002112 if g, ok := mctx.Module().(*genrule.Module); ok {
2113 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002114 var coreVariantNeeded bool = false
2115 var vendorVariantNeeded bool = false
2116 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002117 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002118 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002119 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002120 coreVariantNeeded = true
2121 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002122 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002123 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002124 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002125 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002126 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002127 if Bool(props.Recovery_available) {
2128 recoveryVariantNeeded = true
2129 }
2130
Jiyong Park413cc742018-06-19 01:46:06 +09002131 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002132 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002133 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002134 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002135 recoveryVariantNeeded = false
2136 }
2137 }
2138
Jiyong Park3f736c92018-05-24 13:36:56 +09002139 var variants []string
2140 if coreVariantNeeded {
2141 variants = append(variants, coreMode)
2142 }
2143 if vendorVariantNeeded {
2144 variants = append(variants, vendorMode)
2145 }
2146 if recoveryVariantNeeded {
2147 variants = append(variants, recoveryMode)
2148 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002149 mod := mctx.CreateVariations(variants...)
2150 for i, v := range variants {
2151 if v == recoveryMode {
2152 m := mod[i].(*genrule.Module)
2153 m.Extra.(*GenruleExtraProperties).InRecovery = true
2154 }
2155 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002156 }
2157 }
2158
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002159 m, ok := mctx.Module().(*Module)
2160 if !ok {
2161 return
2162 }
2163
2164 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002165 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002166 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002167
2168 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002169 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002170 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002171 return
2172 }
Logan Chienf3511742017-10-31 18:04:35 +08002173
2174 if vndkdep := m.vndkdep; vndkdep != nil {
2175 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002176 if productSpecific {
2177 mctx.PropertyErrorf("product_specific",
2178 "product_specific must not be true when `vndk: {enabled: true}`")
2179 return
2180 }
Logan Chienf3511742017-10-31 18:04:35 +08002181 if vendorSpecific {
2182 if !vndkdep.isVndkExt() {
2183 mctx.PropertyErrorf("vndk",
2184 "must set `extends: \"...\"` to vndk extension")
2185 return
2186 }
2187 } else {
2188 if vndkdep.isVndkExt() {
2189 mctx.PropertyErrorf("vndk",
2190 "must set `vendor: true` to set `extends: %q`",
2191 m.getVndkExtendsModuleName())
2192 return
2193 }
2194 if m.VendorProperties.Vendor_available == nil {
2195 mctx.PropertyErrorf("vndk",
2196 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2197 return
2198 }
2199 }
2200 } else {
2201 if vndkdep.isVndkSp() {
2202 mctx.PropertyErrorf("vndk",
2203 "must set `enabled: true` to set `support_system_process: true`")
2204 return
2205 }
2206 if vndkdep.isVndkExt() {
2207 mctx.PropertyErrorf("vndk",
2208 "must set `enabled: true` to set `extends: %q`",
2209 m.getVndkExtendsModuleName())
2210 return
2211 }
Justin Yun8effde42017-06-23 19:24:43 +09002212 }
2213 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002214
Jiyong Parkf9332f12018-02-01 00:54:12 +09002215 var coreVariantNeeded bool = false
2216 var vendorVariantNeeded bool = false
2217 var recoveryVariantNeeded bool = false
2218
Justin Yun71549282017-11-17 12:10:28 +09002219 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002220 // If the device isn't compiling against the VNDK, we always
2221 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002222 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002223 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2224 // LL-NDK stubs only exist in the vendor variant, since the
2225 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002226 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002227 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2228 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002229 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002230 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002231 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2232 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002233 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002234 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002235 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002236 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002237 coreVariantNeeded = true
2238 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002239 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002240 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002241 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002242 } else {
2243 // This is either in /system (or similar: /data), or is a
2244 // modules built with the NDK. Modules built with the NDK
2245 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002246 coreVariantNeeded = true
2247 }
2248
2249 if Bool(m.Properties.Recovery_available) {
2250 recoveryVariantNeeded = true
2251 }
2252
2253 if m.ModuleBase.InstallInRecovery() {
2254 recoveryVariantNeeded = true
2255 coreVariantNeeded = false
2256 }
2257
Jiyong Park413cc742018-06-19 01:46:06 +09002258 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002259 primaryArch := mctx.Config().DevicePrimaryArchType()
2260 moduleArch := m.Target().Arch.ArchType
2261 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002262 recoveryVariantNeeded = false
2263 }
2264 }
2265
Jiyong Parkf9332f12018-02-01 00:54:12 +09002266 var variants []string
2267 if coreVariantNeeded {
2268 variants = append(variants, coreMode)
2269 }
2270 if vendorVariantNeeded {
2271 variants = append(variants, vendorMode)
2272 }
2273 if recoveryVariantNeeded {
2274 variants = append(variants, recoveryMode)
2275 }
2276 mod := mctx.CreateVariations(variants...)
2277 for i, v := range variants {
2278 if v == vendorMode {
2279 m := mod[i].(*Module)
2280 m.Properties.UseVndk = true
2281 squashVendorSrcs(m)
2282 } else if v == recoveryMode {
2283 m := mod[i].(*Module)
2284 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002285 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002286 squashRecoverySrcs(m)
2287 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002288 }
2289}
2290
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002291func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002292 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002293 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2294 }
Colin Cross6510f912017-11-29 00:27:14 -08002295 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002296}
2297
Colin Cross06a931b2015-10-28 17:23:31 -07002298var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002299var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002300var BoolPtr = proptools.BoolPtr
2301var String = proptools.String
2302var StringPtr = proptools.StringPtr