blob: e61857d8749ac64979a9df4f041cdef04c5802f7 [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 (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090041 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
43 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000059 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
60 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
61
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080062 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
63 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
64
Colin Cross1e676be2016-10-12 14:38:15 -070065 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
66 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080067
Colin Cross6b753602018-06-21 13:03:07 -070068 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090069 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080070
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080071 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080072 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070073
74 ctx.TopDown("lto_deps", ltoDepsMutator)
75 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090076
77 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070078 })
Colin Crossb98c8b02016-07-29 13:44:28 -070079
80 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070081}
82
Colin Crossca860ac2016-01-04 14:34:37 -080083type Deps struct {
84 SharedLibs, LateSharedLibs []string
85 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080086 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080087 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070088
Colin Cross5950f382016-12-13 12:50:57 -080089 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070090
Colin Cross81413472016-04-11 14:37:39 -070091 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070092
Dan Willemsenb40aab62016-04-20 14:21:14 -070093 GeneratedSources []string
94 GeneratedHeaders []string
95
Dan Willemsenb3454ab2016-09-28 17:34:58 -070096 ReexportGeneratedHeaders []string
97
Colin Cross97ba0732015-03-23 17:50:24 -070098 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070099
100 // Used for host bionic
101 LinkerFlagsFile string
102 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700103}
104
Colin Crossca860ac2016-01-04 14:34:37 -0800105type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900107 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700108 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900109 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700111 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700114 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800115 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700116 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700117
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700119 GeneratedSources android.Paths
120 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700121
Dan Willemsen76f08272016-07-09 00:14:08 -0700122 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700123 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700126 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700127
128 // Path to the file container flags to use with the linker
129 LinkerFlagsFile android.OptionalPath
130
131 // Path to the dynamic linker binary
132 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700133}
134
Colin Crossca860ac2016-01-04 14:34:37 -0800135type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700136 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
137 ArFlags []string // Flags that apply to ar
138 AsFlags []string // Flags that apply to assembly source files
139 CFlags []string // Flags that apply to C and C++ source files
140 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
141 ConlyFlags []string // Flags that apply to C source files
142 CppFlags []string // Flags that apply to C++ source files
143 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700144 aidlFlags []string // Flags that apply to aidl source files
145 rsFlags []string // Flags that apply to renderscript source files
146 LdFlags []string // Flags that apply to linker command lines
147 libFlags []string // Flags to add libraries early to the link order
148 TidyFlags []string // Flags that apply to clang-tidy
149 SAbiFlags []string // Flags that apply to header-abi-dumper
150 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700151
Colin Crossc3199482017-03-30 15:03:04 -0700152 // Global include flags that apply to C, C++, and assembly source files
153 // These must be after any module include flags, which will be in GlobalFlags.
154 SystemIncludeFlags []string
155
Colin Crossb98c8b02016-07-29 13:44:28 -0700156 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700157 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800158 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800159 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800160
161 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800162 DynamicLinker string
163
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700164 CFlagsDeps android.Paths // Files depended on by compiler flags
165 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800166
167 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800168
Colin Cross19878da2019-03-28 14:45:07 -0700169 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700170 protoC bool // Whether to use C instead of C++
171 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700172
173 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700174}
175
Colin Cross81413472016-04-11 14:37:39 -0700176type ObjectLinkerProperties struct {
177 // names of other cc_object modules to link into this module using partial linking
178 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700179
180 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800181 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700182}
183
Colin Crossca860ac2016-01-04 14:34:37 -0800184// Properties used to compile all C or C++ modules
185type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700186 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800187 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700188
189 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800190 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700191
Jiyong Parkde866cb2018-12-07 23:08:36 +0900192 AndroidMkSharedLibs []string `blueprint:"mutated"`
193 AndroidMkStaticLibs []string `blueprint:"mutated"`
194 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
195 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
196 HideFromMake bool `blueprint:"mutated"`
197 PreventInstall bool `blueprint:"mutated"`
198 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700199
200 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800201
202 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
203 // file
204 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900205
206 // Make this module available when building for recovery
207 Recovery_available *bool
208
209 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900210
211 // Allows this module to use non-APEX version of libraries. Useful
212 // for building binaries that are started before APEXes are activated.
213 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700214}
215
216type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900217 // whether this module should be allowed to be directly depended by other
218 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
219 // If set to true, two variants will be built separately, one like
220 // normal, and the other limited to the set of libraries and headers
221 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700222 //
223 // The vendor variant may be used with a different (newer) /system,
224 // so it shouldn't have any unversioned runtime dependencies, or
225 // make assumptions about the system that may not be true in the
226 // future.
227 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900228 // If set to false, this module becomes inaccessible from /vendor modules.
229 //
230 // Default value is true when vndk: {enabled: true} or vendor: true.
231 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700232 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
233 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900234
235 // whether this module is capable of being loaded with other instance
236 // (possibly an older version) of the same module in the same process.
237 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
238 // can be double loaded in a vendor process if the library is also a
239 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
240 // explicitly marked as `double_loadable: true` by the owner, or the dependency
241 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
242 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800243}
244
Colin Crossca860ac2016-01-04 14:34:37 -0800245type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800246 static() bool
247 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700248 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700249 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800250 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700251 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800252 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900253 isLlndk(config android.Config) bool
254 isLlndkPublic(config android.Config) bool
255 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900256 isVndk() bool
257 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800258 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900259 inRecovery() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900260 shouldCreateVndkSourceAbiDump(config android.Config) bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700261 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700262 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800263 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800264 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800265 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800266 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900267 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900268 hasStubsVariants() bool
269 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900270 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800271 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700272 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800273}
274
275type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700276 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800277 ModuleContextIntf
278}
279
280type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700281 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800282 ModuleContextIntf
283}
284
Colin Cross37047f12016-12-13 17:06:13 -0800285type DepsContext interface {
286 android.BottomUpMutatorContext
287 ModuleContextIntf
288}
289
Colin Crossca860ac2016-01-04 14:34:37 -0800290type feature interface {
291 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800292 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800293 flags(ctx ModuleContext, flags Flags) Flags
294 props() []interface{}
295}
296
297type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700298 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800299 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800300 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700301 compilerProps() []interface{}
302
Colin Cross76fada02016-07-27 10:31:13 -0700303 appendCflags([]string)
304 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700305 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800306}
307
308type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700309 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800310 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700311 linkerFlags(ctx ModuleContext, flags Flags) Flags
312 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800313 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700314
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700315 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700316 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900317 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700318
319 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800320}
321
322type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700323 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700324 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800325 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700326 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700327 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900328 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800329}
330
Colin Crossc99deeb2016-04-11 15:06:20 -0700331type dependencyTag struct {
332 blueprint.BaseDependencyTag
333 name string
334 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700335
336 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900337
338 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700339}
340
341var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700342 sharedDepTag = dependencyTag{name: "shared", library: true}
343 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900344 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700345 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
346 staticDepTag = dependencyTag{name: "static", library: true}
347 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
348 lateStaticDepTag = dependencyTag{name: "late static", library: true}
349 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800350 headerDepTag = dependencyTag{name: "header", library: true}
351 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700352 genSourceDepTag = dependencyTag{name: "gen source"}
353 genHeaderDepTag = dependencyTag{name: "gen header"}
354 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
355 objDepTag = dependencyTag{name: "obj"}
356 crtBeginDepTag = dependencyTag{name: "crtbegin"}
357 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700358 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
359 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700360 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900361 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700362 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
363 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800364 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800365 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700366)
367
Colin Crossca860ac2016-01-04 14:34:37 -0800368// Module contains the properties and members used by all C/C++ module types, and implements
369// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
370// to construct the output file. Behavior can be customized with a Customizer interface
371type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700372 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700373 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900374 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700375
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700376 Properties BaseProperties
377 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700378
Colin Crossca860ac2016-01-04 14:34:37 -0800379 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700380 hod android.HostOrDeviceSupported
381 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700382
Colin Crossca860ac2016-01-04 14:34:37 -0800383 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700384 features []feature
385 compiler compiler
386 linker linker
387 installer installer
388 stl *stl
389 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800390 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800391 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900392 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700393 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700394 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800395 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800396
397 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700398
Colin Cross635c3b02016-05-18 15:37:25 -0700399 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800400
Colin Crossb98c8b02016-07-29 13:44:28 -0700401 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700402
403 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800404
405 // Flags used to compile this module
406 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700407
408 // 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 -0800409 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700410 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800411 depsInLinkOrder android.Paths
412
413 // only non-nil when this is a shared library that reuses the objects of a static library
414 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900415
416 makeLinkType string
Colin Crossc472d572015-03-17 15:06:21 -0700417}
418
Jiyong Parkc20eee32018-09-05 22:36:17 +0900419func (c *Module) OutputFile() android.OptionalPath {
420 return c.outputFile
421}
422
Jiyong Park719b4462019-01-13 00:39:51 +0900423func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900424 if c.linker != nil {
425 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900426 }
427 return nil
428}
429
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900430func (c *Module) RelativeInstallPath() string {
431 if c.installer != nil {
432 return c.installer.relativeInstallPath()
433 }
434 return ""
435}
436
Colin Cross36242852017-06-23 15:06:31 -0700437func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700438 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800439 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700440 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800441 }
442 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700443 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800444 }
445 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700446 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800447 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700448 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700449 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700450 }
Colin Cross16b23492016-01-06 14:41:07 -0800451 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700452 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800453 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800454 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700455 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800456 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800457 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700458 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800459 }
Justin Yun8effde42017-06-23 19:24:43 +0900460 if c.vndkdep != nil {
461 c.AddProperties(c.vndkdep.props()...)
462 }
Stephen Craneba090d12017-05-09 15:44:35 -0700463 if c.lto != nil {
464 c.AddProperties(c.lto.props()...)
465 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700466 if c.pgo != nil {
467 c.AddProperties(c.pgo.props()...)
468 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800469 if c.xom != nil {
470 c.AddProperties(c.xom.props()...)
471 }
Colin Crossca860ac2016-01-04 14:34:37 -0800472 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700473 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800474 }
Colin Crossc472d572015-03-17 15:06:21 -0700475
Colin Crossa9d8bee2018-10-02 13:59:46 -0700476 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
477 switch class {
478 case android.Device:
479 return ctx.Config().DevicePrefer32BitExecutables()
480 case android.HostCross:
481 // Windows builds always prefer 32-bit
482 return true
483 default:
484 return false
485 }
486 })
Colin Cross36242852017-06-23 15:06:31 -0700487 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700488
Colin Cross1f44a3a2017-07-07 14:33:33 -0700489 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700490
Jiyong Park9d452992018-10-03 00:38:19 +0900491 android.InitApexModule(c)
492
Colin Cross36242852017-06-23 15:06:31 -0700493 return c
Colin Crossc472d572015-03-17 15:06:21 -0700494}
495
Colin Crossb916a382016-07-29 17:28:03 -0700496// Returns true for dependency roots (binaries)
497// TODO(ccross): also handle dlopenable libraries
498func (c *Module) isDependencyRoot() bool {
499 if root, ok := c.linker.(interface {
500 isDependencyRoot() bool
501 }); ok {
502 return root.isDependencyRoot()
503 }
504 return false
505}
506
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700507func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700508 return c.Properties.UseVndk
509}
510
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800511func (c *Module) isCoverageVariant() bool {
512 return c.coverage.Properties.IsCoverageVariant
513}
514
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800515func (c *Module) isNdk() bool {
516 return inList(c.Name(), ndkMigratedLibs)
517}
518
Inseob Kim9516ee92019-05-09 10:56:13 +0900519func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800520 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900521 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800522}
523
Inseob Kim9516ee92019-05-09 10:56:13 +0900524func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800525 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900526 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800527}
528
Inseob Kim9516ee92019-05-09 10:56:13 +0900529func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800530 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900531 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800532}
533
Justin Yun8effde42017-06-23 19:24:43 +0900534func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800535 if vndkdep := c.vndkdep; vndkdep != nil {
536 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900537 }
538 return false
539}
540
Jooyung Han76106d92019-05-20 18:49:10 +0900541func (c *Module) vndkVersion() string {
542 if vndkdep := c.vndkdep; vndkdep != nil {
543 return vndkdep.Properties.Vndk.Version
544 }
545 return ""
546}
547
Yi Kong7e53c572018-02-14 18:16:12 +0800548func (c *Module) isPgoCompile() bool {
549 if pgo := c.pgo; pgo != nil {
550 return pgo.Properties.PgoCompile
551 }
552 return false
553}
554
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800555func (c *Module) isNDKStubLibrary() bool {
556 if _, ok := c.compiler.(*stubDecorator); ok {
557 return true
558 }
559 return false
560}
561
Logan Chienf3511742017-10-31 18:04:35 +0800562func (c *Module) isVndkSp() bool {
563 if vndkdep := c.vndkdep; vndkdep != nil {
564 return vndkdep.isVndkSp()
565 }
566 return false
567}
568
569func (c *Module) isVndkExt() bool {
570 if vndkdep := c.vndkdep; vndkdep != nil {
571 return vndkdep.isVndkExt()
572 }
573 return false
574}
575
Vic Yangefd249e2018-11-12 20:19:56 -0800576func (c *Module) mustUseVendorVariant() bool {
577 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
578}
579
Logan Chienf3511742017-10-31 18:04:35 +0800580func (c *Module) getVndkExtendsModuleName() string {
581 if vndkdep := c.vndkdep; vndkdep != nil {
582 return vndkdep.getVndkExtendsModuleName()
583 }
584 return ""
585}
586
Jiyong Park82e2bf32017-08-16 14:05:54 +0900587// Returns true only when this module is configured to have core and vendor
588// variants.
589func (c *Module) hasVendorVariant() bool {
590 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
591}
592
Jiyong Parkf9332f12018-02-01 00:54:12 +0900593func (c *Module) inRecovery() bool {
594 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
595}
596
597func (c *Module) onlyInRecovery() bool {
598 return c.ModuleBase.InstallInRecovery()
599}
600
Jiyong Park25fc6a92018-11-18 18:02:45 +0900601func (c *Module) IsStubs() bool {
602 if library, ok := c.linker.(*libraryDecorator); ok {
603 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900604 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
605 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900606 }
607 return false
608}
609
610func (c *Module) HasStubsVariants() bool {
611 if library, ok := c.linker.(*libraryDecorator); ok {
612 return len(library.Properties.Stubs.Versions) > 0
613 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700614 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
615 return len(library.Properties.Stubs.Versions) > 0
616 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900617 return false
618}
619
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900620func (c *Module) bootstrap() bool {
621 return Bool(c.Properties.Bootstrap)
622}
623
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700624func (c *Module) nativeCoverage() bool {
625 return c.linker != nil && c.linker.nativeCoverage()
626}
627
Jiyong Parkf1194352019-02-25 11:05:47 +0900628func isBionic(name string) bool {
629 switch name {
630 case "libc", "libm", "libdl", "linker":
631 return true
632 }
633 return false
634}
635
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700636func installToBootstrap(name string, config android.Config) bool {
637 if name == "libclang_rt.hwasan-aarch64-android" {
638 return inList("hwaddress", config.SanitizeDevice())
639 }
640 return isBionic(name)
641}
642
Colin Crossca860ac2016-01-04 14:34:37 -0800643type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700644 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800645 moduleContextImpl
646}
647
Colin Cross37047f12016-12-13 17:06:13 -0800648type depsContext struct {
649 android.BottomUpMutatorContext
650 moduleContextImpl
651}
652
Colin Crossca860ac2016-01-04 14:34:37 -0800653type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700654 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800655 moduleContextImpl
656}
657
Jiyong Park2db76922017-11-08 16:03:48 +0900658func (ctx *moduleContext) SocSpecific() bool {
659 return ctx.ModuleContext.SocSpecific() ||
660 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700661}
662
Colin Crossca860ac2016-01-04 14:34:37 -0800663type moduleContextImpl struct {
664 mod *Module
665 ctx BaseModuleContext
666}
667
Colin Crossb98c8b02016-07-29 13:44:28 -0700668func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800669 return ctx.mod.toolchain(ctx.ctx)
670}
671
672func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000673 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800674}
675
676func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900677 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800678}
679
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700680func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800681 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800682 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700683 }
684 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800685}
686
687func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700688 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700689 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900690 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700691 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900692 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
693 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
694 return "current"
695 }
696 return platform_vndk_ver
697 }
698 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800699 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900700 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700701 }
702 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800703}
704
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700705func (ctx *moduleContextImpl) useVndk() bool {
706 return ctx.mod.useVndk()
707}
Justin Yun8effde42017-06-23 19:24:43 +0900708
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800709func (ctx *moduleContextImpl) isNdk() bool {
710 return ctx.mod.isNdk()
711}
712
Inseob Kim9516ee92019-05-09 10:56:13 +0900713func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
714 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800715}
716
Inseob Kim9516ee92019-05-09 10:56:13 +0900717func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
718 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800719}
720
Inseob Kim9516ee92019-05-09 10:56:13 +0900721func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
722 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800723}
724
Logan Chienf3511742017-10-31 18:04:35 +0800725func (ctx *moduleContextImpl) isVndk() bool {
726 return ctx.mod.isVndk()
727}
728
Yi Kong7e53c572018-02-14 18:16:12 +0800729func (ctx *moduleContextImpl) isPgoCompile() bool {
730 return ctx.mod.isPgoCompile()
731}
732
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800733func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
734 return ctx.mod.isNDKStubLibrary()
735}
736
Justin Yun8effde42017-06-23 19:24:43 +0900737func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800738 return ctx.mod.isVndkSp()
739}
740
741func (ctx *moduleContextImpl) isVndkExt() bool {
742 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900743}
744
Vic Yangefd249e2018-11-12 20:19:56 -0800745func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
746 return ctx.mod.mustUseVendorVariant()
747}
748
Jiyong Parkf9332f12018-02-01 00:54:12 +0900749func (ctx *moduleContextImpl) inRecovery() bool {
750 return ctx.mod.inRecovery()
751}
752
Logan Chien2f2b8902018-07-10 15:01:19 +0800753// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900754func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800755 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
756 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800757 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800758
759 if ctx.ctx.Fuchsia() {
760 return false
761 }
762
Logan Chien2f2b8902018-07-10 15:01:19 +0800763 if sanitize := ctx.mod.sanitize; sanitize != nil {
764 if !sanitize.isVariantOnProductionDevice() {
765 return false
766 }
767 }
768 if !ctx.ctx.Device() {
769 // Host modules do not need ABI dumps.
770 return false
771 }
Logan Chienfa478c02018-12-28 16:25:39 +0800772 if !ctx.mod.IsForPlatform() {
773 // APEX variants do not need ABI dumps.
774 return false
775 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800776 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800777 return true
778 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900779 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800780 return true
781 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900782 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800783 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
784 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800785 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800786 }
787 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800788}
789
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700790func (ctx *moduleContextImpl) selectedStl() string {
791 if stl := ctx.mod.stl; stl != nil {
792 return stl.Properties.SelectedStl
793 }
794 return ""
795}
796
Ivan Lozanobd721262018-11-27 14:33:03 -0800797func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
798 return ctx.mod.linker.useClangLld(actx)
799}
800
Colin Crossce75d2c2016-10-06 16:12:58 -0700801func (ctx *moduleContextImpl) baseModuleName() string {
802 return ctx.mod.ModuleBase.BaseModuleName()
803}
804
Logan Chienf3511742017-10-31 18:04:35 +0800805func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
806 return ctx.mod.getVndkExtendsModuleName()
807}
808
Jiyong Park58e364a2019-01-19 19:24:06 +0900809func (ctx *moduleContextImpl) apexName() string {
810 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900811}
812
Jiyong Parkb0788572018-12-20 22:10:17 +0900813func (ctx *moduleContextImpl) hasStubsVariants() bool {
814 return ctx.mod.HasStubsVariants()
815}
816
817func (ctx *moduleContextImpl) isStubs() bool {
818 return ctx.mod.IsStubs()
819}
820
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900821func (ctx *moduleContextImpl) bootstrap() bool {
822 return ctx.mod.bootstrap()
823}
824
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700825func (ctx *moduleContextImpl) nativeCoverage() bool {
826 return ctx.mod.nativeCoverage()
827}
828
Colin Cross635c3b02016-05-18 15:37:25 -0700829func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800830 return &Module{
831 hod: hod,
832 multilib: multilib,
833 }
834}
835
Colin Cross635c3b02016-05-18 15:37:25 -0700836func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800837 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700838 module.features = []feature{
839 &tidyFeature{},
840 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700841 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800842 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800843 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800844 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900845 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700846 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700847 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800848 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800849 return module
850}
851
Colin Crossce75d2c2016-10-06 16:12:58 -0700852func (c *Module) Prebuilt() *android.Prebuilt {
853 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
854 return p.prebuilt()
855 }
856 return nil
857}
858
859func (c *Module) Name() string {
860 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700861 if p, ok := c.linker.(interface {
862 Name(string) string
863 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700864 name = p.Name(name)
865 }
866 return name
867}
868
Alex Light3d673592019-01-18 14:37:31 -0800869func (c *Module) Symlinks() []string {
870 if p, ok := c.installer.(interface {
871 symlinkList() []string
872 }); ok {
873 return p.symlinkList()
874 }
875 return nil
876}
877
Jeff Gaston294356f2017-09-27 17:05:30 -0700878// orderDeps reorders dependencies into a list such that if module A depends on B, then
879// A will precede B in the resultant list.
880// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800881// Note that directSharedDeps should be the analogous static library for each shared lib dep
882func 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 -0700883 // If A depends on B, then
884 // Every list containing A will also contain B later in the list
885 // So, after concatenating all lists, the final instance of B will have come from the same
886 // original list as the final instance of A
887 // So, the final instance of B will be later in the concatenation than the final A
888 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
889 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800890 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700891 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800892 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
893 }
894 for _, dep := range directSharedDeps {
895 orderedAllDeps = append(orderedAllDeps, dep)
896 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700897 }
898
Colin Crossb6715442017-10-24 11:13:31 -0700899 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700900
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800901 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700902 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800903 // resultant list to only what the caller has chosen to include in directStaticDeps
904 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700905
906 return orderedAllDeps, orderedDeclaredDeps
907}
908
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800909func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
910 // convert Module to Path
911 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
912 staticDepFiles := []android.Path{}
913 for _, dep := range staticDeps {
914 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
915 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700916 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800917 sharedDepFiles := []android.Path{}
918 for _, sharedDep := range sharedDeps {
919 staticAnalogue := sharedDep.staticVariant
920 if staticAnalogue != nil {
921 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
922 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
923 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700924 }
925
926 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800927 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700928
929 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700930}
931
Colin Cross635c3b02016-05-18 15:37:25 -0700932func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jooyung Han38002912019-05-16 04:01:54 +0900933 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900934
Colin Crossca860ac2016-01-04 14:34:37 -0800935 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700936 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800937 moduleContextImpl: moduleContextImpl{
938 mod: c,
939 },
940 }
941 ctx.ctx = ctx
942
Colin Crossf18e1102017-11-16 14:33:08 -0800943 deps := c.depsToPaths(ctx)
944 if ctx.Failed() {
945 return
946 }
947
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700948 if c.Properties.Clang != nil && *c.Properties.Clang == false {
949 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
950 }
951
Colin Crossca860ac2016-01-04 14:34:37 -0800952 flags := Flags{
953 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800954 }
Colin Crossca860ac2016-01-04 14:34:37 -0800955 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800956 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800957 }
958 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700959 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800960 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700961 if c.stl != nil {
962 flags = c.stl.flags(ctx, flags)
963 }
Colin Cross16b23492016-01-06 14:41:07 -0800964 if c.sanitize != nil {
965 flags = c.sanitize.flags(ctx, flags)
966 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800967 if c.coverage != nil {
968 flags = c.coverage.flags(ctx, flags)
969 }
Stephen Craneba090d12017-05-09 15:44:35 -0700970 if c.lto != nil {
971 flags = c.lto.flags(ctx, flags)
972 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700973 if c.pgo != nil {
974 flags = c.pgo.flags(ctx, flags)
975 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800976 if c.xom != nil {
977 flags = c.xom.flags(ctx, flags)
978 }
Colin Crossca860ac2016-01-04 14:34:37 -0800979 for _, feature := range c.features {
980 flags = feature.flags(ctx, flags)
981 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800982 if ctx.Failed() {
983 return
984 }
985
Colin Crossb98c8b02016-07-29 13:44:28 -0700986 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
987 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
988 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800989
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800990 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
991 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700992 // We need access to all the flags seen by a source file.
993 if c.sabi != nil {
994 flags = c.sabi.flags(ctx, flags)
995 }
Colin Crossca860ac2016-01-04 14:34:37 -0800996 // Optimization to reduce size of build.ninja
997 // Replace the long list of flags for each file with a module-local variable
998 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
999 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1000 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1001 flags.CFlags = []string{"$cflags"}
1002 flags.CppFlags = []string{"$cppflags"}
1003 flags.AsFlags = []string{"$asflags"}
1004
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001005 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001006 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001007 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001008 if ctx.Failed() {
1009 return
1010 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001011 }
1012
Colin Crossca860ac2016-01-04 14:34:37 -08001013 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001014 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001015 if ctx.Failed() {
1016 return
1017 }
Colin Cross635c3b02016-05-18 15:37:25 -07001018 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001019
1020 // If a lib is directly included in any of the APEXes, unhide the stubs
1021 // variant having the latest version gets visible to make. In addition,
1022 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1023 // force anything in the make world to link against the stubs library.
1024 // (unless it is explicitly referenced via .bootstrap suffix or the
1025 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001026 if c.HasStubsVariants() &&
1027 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001028 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1029 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001030 c.Properties.HideFromMake = false // unhide
1031 // Note: this is still non-installable
1032 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001033 }
Colin Cross5049f022015-03-18 13:28:46 -07001034
Inseob Kim1f086e22019-05-09 13:29:15 +09001035 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001036 c.installer.install(ctx, c.outputFile.Path())
1037 if ctx.Failed() {
1038 return
Colin Crossca860ac2016-01-04 14:34:37 -08001039 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001040 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001041}
1042
Jiyong Park379de2f2018-12-19 02:47:14 +09001043func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001044 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001045 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001046 }
Colin Crossca860ac2016-01-04 14:34:37 -08001047 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001048}
1049
Colin Crossca860ac2016-01-04 14:34:37 -08001050func (c *Module) begin(ctx BaseModuleContext) {
1051 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001052 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001053 }
Colin Crossca860ac2016-01-04 14:34:37 -08001054 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001055 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001056 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001057 if c.stl != nil {
1058 c.stl.begin(ctx)
1059 }
Colin Cross16b23492016-01-06 14:41:07 -08001060 if c.sanitize != nil {
1061 c.sanitize.begin(ctx)
1062 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001063 if c.coverage != nil {
1064 c.coverage.begin(ctx)
1065 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001066 if c.sabi != nil {
1067 c.sabi.begin(ctx)
1068 }
Justin Yun8effde42017-06-23 19:24:43 +09001069 if c.vndkdep != nil {
1070 c.vndkdep.begin(ctx)
1071 }
Stephen Craneba090d12017-05-09 15:44:35 -07001072 if c.lto != nil {
1073 c.lto.begin(ctx)
1074 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001075 if c.pgo != nil {
1076 c.pgo.begin(ctx)
1077 }
Colin Crossca860ac2016-01-04 14:34:37 -08001078 for _, feature := range c.features {
1079 feature.begin(ctx)
1080 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001081 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001082 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001083 if err != nil {
1084 ctx.PropertyErrorf("sdk_version", err.Error())
1085 }
Nan Zhang0007d812017-11-07 10:57:05 -08001086 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001087 }
Colin Crossca860ac2016-01-04 14:34:37 -08001088}
1089
Colin Cross37047f12016-12-13 17:06:13 -08001090func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001091 deps := Deps{}
1092
1093 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001094 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001095 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001096 // Add the PGO dependency (the clang_rt.profile runtime library), which
1097 // sometimes depends on symbols from libgcc, before libgcc gets added
1098 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001099 if c.pgo != nil {
1100 deps = c.pgo.deps(ctx, deps)
1101 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001102 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001103 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001104 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001105 if c.stl != nil {
1106 deps = c.stl.deps(ctx, deps)
1107 }
Colin Cross16b23492016-01-06 14:41:07 -08001108 if c.sanitize != nil {
1109 deps = c.sanitize.deps(ctx, deps)
1110 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001111 if c.coverage != nil {
1112 deps = c.coverage.deps(ctx, deps)
1113 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001114 if c.sabi != nil {
1115 deps = c.sabi.deps(ctx, deps)
1116 }
Justin Yun8effde42017-06-23 19:24:43 +09001117 if c.vndkdep != nil {
1118 deps = c.vndkdep.deps(ctx, deps)
1119 }
Stephen Craneba090d12017-05-09 15:44:35 -07001120 if c.lto != nil {
1121 deps = c.lto.deps(ctx, deps)
1122 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001123 for _, feature := range c.features {
1124 deps = feature.deps(ctx, deps)
1125 }
1126
Colin Crossb6715442017-10-24 11:13:31 -07001127 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1128 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1129 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1130 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1131 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1132 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001133 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001134
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001135 for _, lib := range deps.ReexportSharedLibHeaders {
1136 if !inList(lib, deps.SharedLibs) {
1137 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1138 }
1139 }
1140
1141 for _, lib := range deps.ReexportStaticLibHeaders {
1142 if !inList(lib, deps.StaticLibs) {
1143 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1144 }
1145 }
1146
Colin Cross5950f382016-12-13 12:50:57 -08001147 for _, lib := range deps.ReexportHeaderLibHeaders {
1148 if !inList(lib, deps.HeaderLibs) {
1149 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1150 }
1151 }
1152
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001153 for _, gen := range deps.ReexportGeneratedHeaders {
1154 if !inList(gen, deps.GeneratedHeaders) {
1155 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1156 }
1157 }
1158
Colin Crossc99deeb2016-04-11 15:06:20 -07001159 return deps
1160}
1161
Dan Albert7e9d2952016-08-04 13:02:36 -07001162func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001163 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001164 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001165 moduleContextImpl: moduleContextImpl{
1166 mod: c,
1167 },
1168 }
1169 ctx.ctx = ctx
1170
Colin Crossca860ac2016-01-04 14:34:37 -08001171 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001172}
1173
Jiyong Park7ed9de32018-10-15 22:25:07 +09001174// Split name#version into name and version
1175func stubsLibNameAndVersion(name string) (string, string) {
1176 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1177 version := name[sharp+1:]
1178 libname := name[:sharp]
1179 return libname, version
1180 }
1181 return name, ""
1182}
1183
Colin Cross1e676be2016-10-12 14:38:15 -07001184func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001185 ctx := &depsContext{
1186 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001187 moduleContextImpl: moduleContextImpl{
1188 mod: c,
1189 },
1190 }
1191 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001192
Colin Crossc99deeb2016-04-11 15:06:20 -07001193 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001194
Dan Albert914449f2016-06-17 16:45:24 -07001195 variantNdkLibs := []string{}
1196 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001197 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001198 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001199
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001200 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1201 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001202 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001203 // 1. Name of an NDK library that refers to a prebuilt module.
1204 // For each of these, it adds the name of the prebuilt module (which will be in
1205 // prebuilts/ndk) to the list of nonvariant libs.
1206 // 2. Name of an NDK library that refers to an ndk_library module.
1207 // For each of these, it adds the name of the ndk_library module to the list of
1208 // variant libs.
1209 // 3. Anything else (so anything that isn't an NDK library).
1210 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001211 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001212 // The caller can then know to add the variantLibs dependencies differently from the
1213 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001214
1215 llndkLibraries := llndkLibraries(actx.Config())
1216 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1218 variantLibs = []string{}
1219 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001220 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001221 // strip #version suffix out
1222 name, _ := stubsLibNameAndVersion(entry)
1223 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1224 if !inList(name, ndkMigratedLibs) {
1225 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001226 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001227 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001228 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001229 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001230 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001231 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001232 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001233 if actx.OtherModuleExists(vendorPublicLib) {
1234 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1235 } else {
1236 // This can happen if vendor_public_library module is defined in a
1237 // namespace that isn't visible to the current module. In that case,
1238 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001239 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001240 }
Dan Albert914449f2016-06-17 16:45:24 -07001241 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001242 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001243 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001244 }
1245 }
Dan Albert914449f2016-06-17 16:45:24 -07001246 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001247 }
1248
Dan Albert914449f2016-06-17 16:45:24 -07001249 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1250 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001251 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001252 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001253
Jiyong Park7e636d02019-01-28 16:16:54 +09001254 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001255 if c.linker != nil {
1256 if library, ok := c.linker.(*libraryDecorator); ok {
1257 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001258 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001259 }
1260 }
1261 }
1262
Colin Cross32ec36c2016-12-15 07:39:51 -08001263 for _, lib := range deps.HeaderLibs {
1264 depTag := headerDepTag
1265 if inList(lib, deps.ReexportHeaderLibHeaders) {
1266 depTag = headerExportDepTag
1267 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001268 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001269 actx.AddFarVariationDependencies([]blueprint.Variation{
1270 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001271 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001272 }, depTag, lib)
1273 } else {
1274 actx.AddVariationDependencies(nil, depTag, lib)
1275 }
1276 }
1277
1278 if buildStubs {
1279 // Stubs lib does not have dependency to other static/shared libraries.
1280 // Don't proceed.
1281 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001282 }
Colin Cross5950f382016-12-13 12:50:57 -08001283
Inseob Kimc0907f12019-02-08 21:00:45 +09001284 syspropImplLibraries := syspropImplLibraries(actx.Config())
1285
Jiyong Park5d1598f2019-02-25 22:14:17 +09001286 for _, lib := range deps.WholeStaticLibs {
1287 depTag := wholeStaticDepTag
1288 if impl, ok := syspropImplLibraries[lib]; ok {
1289 lib = impl
1290 }
1291 actx.AddVariationDependencies([]blueprint.Variation{
1292 {Mutator: "link", Variation: "static"},
1293 }, depTag, lib)
1294 }
1295
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001296 for _, lib := range deps.StaticLibs {
1297 depTag := staticDepTag
1298 if inList(lib, deps.ReexportStaticLibHeaders) {
1299 depTag = staticExportDepTag
1300 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001301
1302 if impl, ok := syspropImplLibraries[lib]; ok {
1303 lib = impl
1304 }
1305
Dan Willemsen59339a22018-07-22 21:18:45 -07001306 actx.AddVariationDependencies([]blueprint.Variation{
1307 {Mutator: "link", Variation: "static"},
1308 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001309 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001310
Dan Willemsen59339a22018-07-22 21:18:45 -07001311 actx.AddVariationDependencies([]blueprint.Variation{
1312 {Mutator: "link", Variation: "static"},
1313 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001314
Jiyong Park25fc6a92018-11-18 18:02:45 +09001315 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1316 var variations []blueprint.Variation
1317 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001318 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001319 if version != "" && versionVariantAvail {
1320 // Version is explicitly specified. i.e. libFoo#30
1321 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1322 depTag.explicitlyVersioned = true
1323 }
1324 actx.AddVariationDependencies(variations, depTag, name)
1325
1326 // If the version is not specified, add dependency to the latest stubs library.
1327 // The stubs library will be used when the depending module is built for APEX and
1328 // the dependent module is not in the same APEX.
1329 latestVersion := latestStubsVersionFor(actx.Config(), name)
1330 if version == "" && latestVersion != "" && versionVariantAvail {
1331 actx.AddVariationDependencies([]blueprint.Variation{
1332 {Mutator: "link", Variation: "shared"},
1333 {Mutator: "version", Variation: latestVersion},
1334 }, depTag, name)
1335 // Note that depTag.explicitlyVersioned is false in this case.
1336 }
1337 }
1338
Jiyong Park7ed9de32018-10-15 22:25:07 +09001339 // shared lib names without the #version suffix
1340 var sharedLibNames []string
1341
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001342 for _, lib := range deps.SharedLibs {
1343 depTag := sharedDepTag
1344 if inList(lib, deps.ReexportSharedLibHeaders) {
1345 depTag = sharedExportDepTag
1346 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001347
1348 if impl, ok := syspropImplLibraries[lib]; ok {
1349 lib = impl
1350 }
1351
1352 name, version := stubsLibNameAndVersion(lib)
1353 sharedLibNames = append(sharedLibNames, name)
1354
Jiyong Park25fc6a92018-11-18 18:02:45 +09001355 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001356 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001357
Jiyong Park7ed9de32018-10-15 22:25:07 +09001358 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001359 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001360 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1361 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1362 // linking against both the stubs lib and the non-stubs lib at the same time.
1363 continue
1364 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001365 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001366 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001367
Dan Willemsen59339a22018-07-22 21:18:45 -07001368 actx.AddVariationDependencies([]blueprint.Variation{
1369 {Mutator: "link", Variation: "shared"},
1370 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001371
Colin Cross68861832016-07-08 10:41:41 -07001372 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001373
1374 for _, gen := range deps.GeneratedHeaders {
1375 depTag := genHeaderDepTag
1376 if inList(gen, deps.ReexportGeneratedHeaders) {
1377 depTag = genHeaderExportDepTag
1378 }
1379 actx.AddDependency(c, depTag, gen)
1380 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001381
Colin Cross42d48b72018-08-29 14:10:52 -07001382 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001383
1384 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001385 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001386 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001387 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001388 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001389 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001390 if deps.LinkerFlagsFile != "" {
1391 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1392 }
1393 if deps.DynamicLinker != "" {
1394 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001395 }
Dan Albert914449f2016-06-17 16:45:24 -07001396
1397 version := ctx.sdkVersion()
1398 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001399 {Mutator: "ndk_api", Variation: version},
1400 {Mutator: "link", Variation: "shared"},
1401 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001402 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001403 {Mutator: "ndk_api", Variation: version},
1404 {Mutator: "link", Variation: "shared"},
1405 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001406
1407 if vndkdep := c.vndkdep; vndkdep != nil {
1408 if vndkdep.isVndkExt() {
1409 baseModuleMode := vendorMode
1410 if actx.DeviceConfig().VndkVersion() == "" {
1411 baseModuleMode = coreMode
1412 }
1413 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001414 {Mutator: "image", Variation: baseModuleMode},
1415 {Mutator: "link", Variation: "shared"},
1416 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001417 }
1418 }
Colin Cross6362e272015-10-29 15:25:03 -07001419}
Colin Cross21b9a242015-03-24 14:15:58 -07001420
Colin Crosse40b4ea2018-10-02 22:25:58 -07001421func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001422 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1423 c.beginMutator(ctx)
1424 }
1425}
1426
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001427// Whether a module can link to another module, taking into
1428// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001429func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001430 if from.Target().Os != android.Android {
1431 // Host code is not restricted
1432 return
1433 }
1434 if from.Properties.UseVndk {
1435 // Though vendor code is limited by the vendor mutator,
1436 // each vendor-available module needs to check
1437 // link-type for VNDK.
1438 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001439 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001440 }
1441 return
1442 }
Nan Zhang0007d812017-11-07 10:57:05 -08001443 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001444 // Platform code can link to anything
1445 return
1446 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001447 if from.inRecovery() {
1448 // Recovery code is not NDK
1449 return
1450 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001451 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1452 // These are always allowed
1453 return
1454 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001455 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1456 // These are allowed, but they don't set sdk_version
1457 return
1458 }
1459 if _, ok := to.linker.(*stubDecorator); ok {
1460 // These aren't real libraries, but are the stub shared libraries that are included in
1461 // the NDK.
1462 return
1463 }
Logan Chien834b9a62019-01-14 15:39:03 +08001464
1465 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1466 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1467 // to link to libc++ (non-NDK and without sdk_version).
1468 return
1469 }
1470
Nan Zhang0007d812017-11-07 10:57:05 -08001471 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001472 // NDK code linking to platform code is never okay.
1473 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1474 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001475 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001476 }
1477
1478 // At this point we know we have two NDK libraries, but we need to
1479 // check that we're not linking against anything built against a higher
1480 // API level, as it is only valid to link against older or equivalent
1481 // APIs.
1482
Inseob Kim01a28722018-04-11 09:48:45 +09001483 // Current can link against anything.
1484 if String(from.Properties.Sdk_version) != "current" {
1485 // Otherwise we need to check.
1486 if String(to.Properties.Sdk_version) == "current" {
1487 // Current can't be linked against by anything else.
1488 ctx.ModuleErrorf("links %q built against newer API version %q",
1489 ctx.OtherModuleName(to), "current")
1490 } else {
1491 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1492 if err != nil {
1493 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001494 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001495 String(from.Properties.Sdk_version))
1496 }
1497 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1498 if err != nil {
1499 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001500 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001501 String(to.Properties.Sdk_version))
1502 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001503
Inseob Kim01a28722018-04-11 09:48:45 +09001504 if toApi > fromApi {
1505 ctx.ModuleErrorf("links %q built against newer API version %q",
1506 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1507 }
1508 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001509 }
Dan Albert202fe492017-12-15 13:56:59 -08001510
1511 // Also check that the two STL choices are compatible.
1512 fromStl := from.stl.Properties.SelectedStl
1513 toStl := to.stl.Properties.SelectedStl
1514 if fromStl == "" || toStl == "" {
1515 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001516 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001517 // We can be permissive with the system "STL" since it is only the C++
1518 // ABI layer, but in the future we should make sure that everyone is
1519 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001520 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001521 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1522 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1523 to.stl.Properties.SelectedStl)
1524 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001525}
1526
Jiyong Park5fb8c102018-04-09 12:03:06 +09001527// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001528// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1529// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001530// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001531func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001532 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001533 check := func(child, parent android.Module) bool {
1534 to, ok := child.(*Module)
1535 if !ok {
1536 // follow thru cc.Defaults, etc.
1537 return true
1538 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001539
Jooyung Hana70f0672019-01-18 15:20:43 +09001540 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1541 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001542 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001543
1544 // if target lib has no vendor variant, keep checking dependency graph
1545 if !to.hasVendorVariant() {
1546 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001547 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001548
Inseob Kim9516ee92019-05-09 10:56:13 +09001549 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001550 return false
1551 }
1552
1553 var stringPath []string
1554 for _, m := range ctx.GetWalkPath() {
1555 stringPath = append(stringPath, m.Name())
1556 }
1557 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1558 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1559 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1560 return false
1561 }
1562 if module, ok := ctx.Module().(*Module); ok {
1563 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001564 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001565 ctx.WalkDeps(check)
1566 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001567 }
1568 }
1569}
1570
Colin Crossc99deeb2016-04-11 15:06:20 -07001571// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001572func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001573 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001574
Jeff Gaston294356f2017-09-27 17:05:30 -07001575 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001576 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001577
Inseob Kim9516ee92019-05-09 10:56:13 +09001578 llndkLibraries := llndkLibraries(ctx.Config())
1579 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1580
Colin Crossd11fcda2017-10-23 17:59:01 -07001581 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001582 depName := ctx.OtherModuleName(dep)
1583 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001584
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001585 ccDep, _ := dep.(*Module)
1586 if ccDep == nil {
1587 // handling for a few module types that aren't cc Module but that are also supported
1588 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001589 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001590 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001591 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1592 genRule.GeneratedSourceFiles()...)
1593 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001594 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001595 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001596 // Support exported headers from a generated_sources dependency
1597 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001598 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001599 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001600 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001601 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001602 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001603 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001604 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001605 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001606 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001607 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001608 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1609 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1610
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001611 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001612 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001613 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001614 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001615 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001616 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001617 files := genRule.GeneratedSourceFiles()
1618 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001619 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001620 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001621 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 -07001622 }
1623 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001624 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001625 }
Colin Crossca860ac2016-01-04 14:34:37 -08001626 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001627 return
1628 }
1629
Colin Crossfe17f6f2019-03-28 19:30:56 -07001630 if depTag == android.ProtoPluginDepTag {
1631 return
1632 }
1633
Colin Crossd11fcda2017-10-23 17:59:01 -07001634 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001635 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1636 return
1637 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001638 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001639 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001640 return
1641 }
1642
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001643 // re-exporting flags
1644 if depTag == reuseObjTag {
1645 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001646 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001647 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001648 depPaths.Objs = depPaths.Objs.Append(objs)
1649 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001650 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001651 return
1652 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001653 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001654
Jiyong Parke4bb9862019-02-01 00:31:10 +09001655 if depTag == staticVariantTag {
1656 if _, ok := ccDep.compiler.(libraryInterface); ok {
1657 c.staticVariant = ccDep
1658 return
1659 }
1660 }
1661
Jiyong Park25fc6a92018-11-18 18:02:45 +09001662 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1663 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1664 // won't be matched to sharedDepTag and lateSharedDepTag.
1665 explicitlyVersioned := false
1666 if t, ok := depTag.(dependencyTag); ok {
1667 explicitlyVersioned = t.explicitlyVersioned
1668 t.explicitlyVersioned = false
1669 depTag = t
1670 }
1671
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001672 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001673 depIsStatic := false
1674 switch depTag {
1675 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1676 depIsStatic = true
1677 }
1678 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001679 depIsStubs := dependentLibrary.buildStubs()
1680 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001681 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001682 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001683
1684 var useThisDep bool
1685 if depIsStubs && explicitlyVersioned {
1686 // Always respect dependency to the versioned stubs (i.e. libX#10)
1687 useThisDep = true
1688 } else if !depHasStubs {
1689 // Use non-stub variant if that is the only choice
1690 // (i.e. depending on a lib without stubs.version property)
1691 useThisDep = true
1692 } else if c.IsForPlatform() {
1693 // If not building for APEX, use stubs only when it is from
1694 // an APEX (and not from platform)
1695 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001696 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001697 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001698 // always link to non-stub variant
1699 useThisDep = !depIsStubs
1700 }
1701 } else {
1702 // If building for APEX, use stubs only when it is not from
1703 // the same APEX
1704 useThisDep = (depInSameApex != depIsStubs)
1705 }
1706
1707 if !useThisDep {
1708 return // stop processing this dep
1709 }
1710 }
1711
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001712 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001713 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001714 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001715 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001716 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001717
1718 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001719 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001720 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001721 // 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 -07001722 // Re-exported shared library headers must be included as well since they can help us with type information
1723 // about template instantiations (instantiated from their headers).
1724 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001725 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001726 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001727
Logan Chienf3511742017-10-31 18:04:35 +08001728 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001729 }
1730
Colin Cross26c34ed2016-09-30 17:10:16 -07001731 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001732 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001733
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001734 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001735 depFile := android.OptionalPath{}
1736
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001737 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001738 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001739 ptr = &depPaths.SharedLibs
1740 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001741 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001742 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001743 case earlySharedDepTag:
1744 ptr = &depPaths.EarlySharedLibs
1745 depPtr = &depPaths.EarlySharedLibsDeps
1746 depFile = ccDep.linker.(libraryInterface).toc()
1747 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001748 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001749 ptr = &depPaths.LateSharedLibs
1750 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001751 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001752 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001753 ptr = nil
1754 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001755 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001756 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001757 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001758 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001759 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001760 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001761 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001762 return
1763 }
1764
1765 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001766 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001767 for i := range missingDeps {
1768 missingDeps[i] += postfix
1769 }
1770 ctx.AddMissingDependencies(missingDeps)
1771 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001772 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001773 case headerDepTag:
1774 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001775 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001776 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001777 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001778 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001779 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001780 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001781 case dynamicLinkerDepTag:
1782 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001783 }
1784
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001785 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001786 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001787 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001788 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001789 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001790 return
1791 }
1792
1793 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001794 // in static libraries act as if they were whole static libraries. The same goes for
1795 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001796 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1797 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001798 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1799 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001800
Dan Willemsen581341d2017-02-09 16:16:31 -08001801 }
1802
Colin Cross26c34ed2016-09-30 17:10:16 -07001803 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001804 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001805 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001806 return
1807 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001808 *ptr = append(*ptr, linkFile.Path())
1809 }
1810
Colin Crossc99deeb2016-04-11 15:06:20 -07001811 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001812 dep := depFile
1813 if !dep.Valid() {
1814 dep = linkFile
1815 }
1816 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001817 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001818
Logan Chien43d34c32017-12-20 01:17:32 +08001819 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001820 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001821 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001822 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001823 isLLndk := inList(libName, *llndkLibraries)
1824 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001825 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001826
1827 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1828 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1829 // core module instead.
1830 return libName
1831 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001832 // The vendor module in Make will have been renamed to not conflict with the core
1833 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001834 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001835 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001836 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001837 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1838 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001839 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001840 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001841 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001842 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001843 }
Logan Chien43d34c32017-12-20 01:17:32 +08001844 }
1845
1846 // Export the shared libs to Make.
1847 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001848 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001849 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001850 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001851 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001852 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001853 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001854 c.Properties.ApexesProvidingSharedLibs = append(
1855 c.Properties.ApexesProvidingSharedLibs, an)
1856 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001857 }
1858 }
1859
Jiyong Park27b188b2017-07-18 13:23:39 +09001860 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001861 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001862 c.Properties.AndroidMkSharedLibs = append(
1863 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001864 case ndkStubDepTag, ndkLateStubDepTag:
1865 ndkStub := ccDep.linker.(*stubDecorator)
1866 c.Properties.AndroidMkSharedLibs = append(
1867 c.Properties.AndroidMkSharedLibs,
1868 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001869 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1870 c.Properties.AndroidMkStaticLibs = append(
1871 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001872 case runtimeDepTag:
1873 c.Properties.AndroidMkRuntimeLibs = append(
1874 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001875 case wholeStaticDepTag:
1876 c.Properties.AndroidMkWholeStaticLibs = append(
1877 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001878 }
Colin Crossca860ac2016-01-04 14:34:37 -08001879 })
1880
Jeff Gaston294356f2017-09-27 17:05:30 -07001881 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001882 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001883
Colin Crossdd84e052017-05-17 13:44:16 -07001884 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001885 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001886 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001887 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001888 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1889
1890 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001891 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001892 }
Colin Crossdd84e052017-05-17 13:44:16 -07001893
Colin Crossca860ac2016-01-04 14:34:37 -08001894 return depPaths
1895}
1896
1897func (c *Module) InstallInData() bool {
1898 if c.installer == nil {
1899 return false
1900 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001901 return c.installer.inData()
1902}
1903
1904func (c *Module) InstallInSanitizerDir() bool {
1905 if c.installer == nil {
1906 return false
1907 }
1908 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001909 return true
1910 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001911 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001912}
1913
Jiyong Parkf9332f12018-02-01 00:54:12 +09001914func (c *Module) InstallInRecovery() bool {
1915 return c.inRecovery()
1916}
1917
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001918func (c *Module) HostToolPath() android.OptionalPath {
1919 if c.installer == nil {
1920 return android.OptionalPath{}
1921 }
1922 return c.installer.hostToolPath()
1923}
1924
Nan Zhangd4e641b2017-07-12 12:55:28 -07001925func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1926 return c.outputFile
1927}
1928
Colin Cross41955e82019-05-29 14:40:35 -07001929func (c *Module) OutputFiles(tag string) (android.Paths, error) {
1930 switch tag {
1931 case "":
1932 if c.outputFile.Valid() {
1933 return android.Paths{c.outputFile.Path()}, nil
1934 }
1935 return android.Paths{}, nil
1936 default:
1937 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001938 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001939}
1940
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001941func (c *Module) static() bool {
1942 if static, ok := c.linker.(interface {
1943 static() bool
1944 }); ok {
1945 return static.static()
1946 }
1947 return false
1948}
1949
Jiyong Park379de2f2018-12-19 02:47:14 +09001950func (c *Module) staticBinary() bool {
1951 if static, ok := c.linker.(interface {
1952 staticBinary() bool
1953 }); ok {
1954 return static.staticBinary()
1955 }
1956 return false
1957}
1958
Jooyung Han38002912019-05-16 04:01:54 +09001959func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
1960 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07001961 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09001962 if lib, ok := c.linker.(*llndkStubDecorator); ok {
1963 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07001964 return "native:vndk"
1965 }
Jooyung Han38002912019-05-16 04:01:54 +09001966 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07001967 }
Jooyung Han38002912019-05-16 04:01:54 +09001968 if c.isVndk() && !c.isVndkExt() {
1969 if Bool(c.VendorProperties.Vendor_available) {
1970 return "native:vndk"
1971 }
1972 return "native:vndk_private"
1973 }
1974 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07001975 } else if c.inRecovery() {
1976 return "native:recovery"
1977 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1978 return "native:ndk:none:none"
1979 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1980 //family, link := getNdkStlFamilyAndLinkType(c)
1981 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09001982 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08001983 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07001984 } else {
1985 return "native:platform"
1986 }
1987}
1988
Jiyong Park9d452992018-10-03 00:38:19 +09001989// Overrides ApexModule.IsInstallabeToApex()
1990// Only shared libraries are installable to APEX.
1991func (c *Module) IsInstallableToApex() bool {
1992 if shared, ok := c.linker.(interface {
1993 shared() bool
1994 }); ok {
1995 return shared.shared()
1996 }
1997 return false
1998}
1999
Inseob Kim1f086e22019-05-09 13:29:15 +09002000func (c *Module) installable() bool {
2001 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2002}
2003
Jiyong Park3b1746a2019-01-29 11:15:04 +09002004func (c *Module) imageVariation() string {
2005 variation := "core"
2006 if c.useVndk() {
2007 variation = "vendor"
2008 } else if c.inRecovery() {
2009 variation = "recovery"
2010 }
2011 return variation
2012}
2013
bralee3f49f4d2019-03-04 06:58:15 +08002014func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002015 outputFiles, err := c.OutputFiles("")
2016 if err != nil {
2017 panic(err)
2018 }
2019 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002020}
2021
Logan Chien41eabe62019-04-10 13:33:58 +08002022func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2023 if c.linker != nil {
2024 if library, ok := c.linker.(*libraryDecorator); ok {
2025 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2026 }
2027 }
2028}
2029
Colin Cross2ba19d92015-05-07 15:44:20 -07002030//
Colin Crosscfad1192015-11-02 16:43:11 -08002031// Defaults
2032//
Colin Crossca860ac2016-01-04 14:34:37 -08002033type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002034 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002035 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002036 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002037}
2038
Colin Cross635c3b02016-05-18 15:37:25 -07002039func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08002040}
2041
Patrice Arrudac249c712019-03-19 17:00:29 -07002042// cc_defaults provides a set of properties that can be inherited by other cc
2043// modules. A module can use the properties from a cc_defaults using
2044// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2045// merged (when possible) by prepending the default module's values to the
2046// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002047func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002048 return DefaultsFactory()
2049}
2050
Colin Cross36242852017-06-23 15:06:31 -07002051func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002052 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002053
Colin Cross36242852017-06-23 15:06:31 -07002054 module.AddProperties(props...)
2055 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002056 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002057 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002058 &BaseCompilerProperties{},
2059 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002060 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002061 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002062 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002063 &TestProperties{},
2064 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002065 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002066 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002067 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002068 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002069 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002070 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002071 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002072 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002073 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002074 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002075 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002076 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002077 )
Colin Crosscfad1192015-11-02 16:43:11 -08002078
Colin Cross1f44a3a2017-07-07 14:33:33 -07002079 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002080 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002081
2082 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002083}
2084
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002085const (
2086 // coreMode is the variant used for framework-private libraries, or
2087 // SDK libraries. (which framework-private libraries can use)
2088 coreMode = "core"
2089
2090 // vendorMode is the variant used for /vendor code that compiles
2091 // against the VNDK.
2092 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002093
2094 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002095)
2096
Jiyong Park6a43f042017-10-12 23:05:00 +09002097func squashVendorSrcs(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.Vendor.Srcs...)
2101
2102 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2103 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2104 }
2105}
2106
Jiyong Parkf9332f12018-02-01 00:54:12 +09002107func squashRecoverySrcs(m *Module) {
2108 if lib, ok := m.compiler.(*libraryDecorator); ok {
2109 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2110 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2111
2112 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2113 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2114 }
2115}
2116
Jiyong Parkda6eb592018-12-19 17:12:36 +09002117func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002118 if mctx.Os() != android.Android {
2119 return
2120 }
2121
Jiyong Park7ed9de32018-10-15 22:25:07 +09002122 if g, ok := mctx.Module().(*genrule.Module); ok {
2123 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002124 var coreVariantNeeded bool = false
2125 var vendorVariantNeeded bool = false
2126 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002127 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002128 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002129 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002130 coreVariantNeeded = true
2131 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002132 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002133 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002134 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002135 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002136 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002137 if Bool(props.Recovery_available) {
2138 recoveryVariantNeeded = true
2139 }
2140
Jiyong Park413cc742018-06-19 01:46:06 +09002141 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002142 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002143 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002144 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002145 recoveryVariantNeeded = false
2146 }
2147 }
2148
Jiyong Park3f736c92018-05-24 13:36:56 +09002149 var variants []string
2150 if coreVariantNeeded {
2151 variants = append(variants, coreMode)
2152 }
2153 if vendorVariantNeeded {
2154 variants = append(variants, vendorMode)
2155 }
2156 if recoveryVariantNeeded {
2157 variants = append(variants, recoveryMode)
2158 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002159 mod := mctx.CreateVariations(variants...)
2160 for i, v := range variants {
2161 if v == recoveryMode {
2162 m := mod[i].(*genrule.Module)
2163 m.Extra.(*GenruleExtraProperties).InRecovery = true
2164 }
2165 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002166 }
2167 }
2168
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002169 m, ok := mctx.Module().(*Module)
2170 if !ok {
2171 return
2172 }
2173
2174 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002175 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002176 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002177
2178 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002179 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002180 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002181 return
2182 }
Logan Chienf3511742017-10-31 18:04:35 +08002183
2184 if vndkdep := m.vndkdep; vndkdep != nil {
2185 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002186 if productSpecific {
2187 mctx.PropertyErrorf("product_specific",
2188 "product_specific must not be true when `vndk: {enabled: true}`")
2189 return
2190 }
Logan Chienf3511742017-10-31 18:04:35 +08002191 if vendorSpecific {
2192 if !vndkdep.isVndkExt() {
2193 mctx.PropertyErrorf("vndk",
2194 "must set `extends: \"...\"` to vndk extension")
2195 return
2196 }
2197 } else {
2198 if vndkdep.isVndkExt() {
2199 mctx.PropertyErrorf("vndk",
2200 "must set `vendor: true` to set `extends: %q`",
2201 m.getVndkExtendsModuleName())
2202 return
2203 }
2204 if m.VendorProperties.Vendor_available == nil {
2205 mctx.PropertyErrorf("vndk",
2206 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2207 return
2208 }
2209 }
2210 } else {
2211 if vndkdep.isVndkSp() {
2212 mctx.PropertyErrorf("vndk",
2213 "must set `enabled: true` to set `support_system_process: true`")
2214 return
2215 }
2216 if vndkdep.isVndkExt() {
2217 mctx.PropertyErrorf("vndk",
2218 "must set `enabled: true` to set `extends: %q`",
2219 m.getVndkExtendsModuleName())
2220 return
2221 }
Justin Yun8effde42017-06-23 19:24:43 +09002222 }
2223 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002224
Jiyong Parkf9332f12018-02-01 00:54:12 +09002225 var coreVariantNeeded bool = false
2226 var vendorVariantNeeded bool = false
2227 var recoveryVariantNeeded bool = false
2228
Justin Yun71549282017-11-17 12:10:28 +09002229 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002230 // If the device isn't compiling against the VNDK, we always
2231 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002232 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002233 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2234 // LL-NDK stubs only exist in the vendor variant, since the
2235 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002236 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002237 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2238 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002239 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002240 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002241 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2242 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002243 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002244 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002245 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002246 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002247 coreVariantNeeded = true
2248 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002249 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002250 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002251 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002252 } else {
2253 // This is either in /system (or similar: /data), or is a
2254 // modules built with the NDK. Modules built with the NDK
2255 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002256 coreVariantNeeded = true
2257 }
2258
2259 if Bool(m.Properties.Recovery_available) {
2260 recoveryVariantNeeded = true
2261 }
2262
2263 if m.ModuleBase.InstallInRecovery() {
2264 recoveryVariantNeeded = true
2265 coreVariantNeeded = false
2266 }
2267
Jiyong Park413cc742018-06-19 01:46:06 +09002268 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002269 primaryArch := mctx.Config().DevicePrimaryArchType()
2270 moduleArch := m.Target().Arch.ArchType
2271 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002272 recoveryVariantNeeded = false
2273 }
2274 }
2275
Jiyong Parkf9332f12018-02-01 00:54:12 +09002276 var variants []string
2277 if coreVariantNeeded {
2278 variants = append(variants, coreMode)
2279 }
2280 if vendorVariantNeeded {
2281 variants = append(variants, vendorMode)
2282 }
2283 if recoveryVariantNeeded {
2284 variants = append(variants, recoveryMode)
2285 }
2286 mod := mctx.CreateVariations(variants...)
2287 for i, v := range variants {
2288 if v == vendorMode {
2289 m := mod[i].(*Module)
2290 m.Properties.UseVndk = true
2291 squashVendorSrcs(m)
2292 } else if v == recoveryMode {
2293 m := mod[i].(*Module)
2294 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002295 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002296 squashRecoverySrcs(m)
2297 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002298 }
2299}
2300
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002301func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002302 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002303 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2304 }
Colin Cross6510f912017-11-29 00:27:14 -08002305 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002306}
2307
Colin Cross06a931b2015-10-28 17:23:31 -07002308var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002309var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002310var BoolPtr = proptools.BoolPtr
2311var String = proptools.String
2312var StringPtr = proptools.StringPtr