blob: 02c4879022f8bf63d50a226ae5c3d60f9f8faabf [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() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070051 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090052 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090053 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
54 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070055 })
Colin Cross16b23492016-01-06 14:41:07 -080056
Paul Duffin036e7002019-12-19 19:16:28 +000057 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070058 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
59 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080060
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070061 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
62 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
63
Mitch Phillipsbfeade62019-05-01 14:42:05 -070064 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
65 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
66
Jiyong Park1d1119f2019-07-29 21:27:18 +090067 // cfi mutator shouldn't run before sanitizers that return true for
68 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000069 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
70 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
71
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080072 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
73 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
74
Colin Cross1e676be2016-10-12 14:38:15 -070075 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
76 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080077
Colin Cross0b908332019-06-19 23:00:20 -070078 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090079 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080080
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080081 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080082 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070083
84 ctx.TopDown("lto_deps", ltoDepsMutator)
85 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090086
87 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070088 })
Colin Crossb98c8b02016-07-29 13:44:28 -070089
Sasha Smundak2a4549e2018-11-05 16:49:08 -080090 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070091}
92
Colin Crossca860ac2016-01-04 14:34:37 -080093type Deps struct {
94 SharedLibs, LateSharedLibs []string
95 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080096 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080097 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070098
Peter Collingbournedc4f9862020-02-12 17:13:25 -080099 StaticUnwinderIfLegacy bool
100
Colin Cross5950f382016-12-13 12:50:57 -0800101 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700102
Colin Cross81413472016-04-11 14:37:39 -0700103 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Dan Willemsenb40aab62016-04-20 14:21:14 -0700105 GeneratedSources []string
106 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900107 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700108
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700109 ReexportGeneratedHeaders []string
110
Colin Cross97ba0732015-03-23 17:50:24 -0700111 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700112
113 // Used for host bionic
114 LinkerFlagsFile string
115 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700116}
117
Colin Crossca860ac2016-01-04 14:34:37 -0800118type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700119 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900120 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900122 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700123 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700124 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700127 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800128 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700129 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700130
Colin Cross26c34ed2016-09-30 17:10:16 -0700131 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700132 GeneratedSources android.Paths
133 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900134 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700135
Inseob Kimd110f872019-12-06 13:15:38 +0900136 Flags []string
137 IncludeDirs android.Paths
138 SystemIncludeDirs android.Paths
139 ReexportedDirs android.Paths
140 ReexportedSystemDirs android.Paths
141 ReexportedFlags []string
142 ReexportedGeneratedHeaders android.Paths
143 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700144
Colin Cross26c34ed2016-09-30 17:10:16 -0700145 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700146 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700147
148 // Path to the file container flags to use with the linker
149 LinkerFlagsFile android.OptionalPath
150
151 // Path to the dynamic linker binary
152 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700153}
154
Colin Cross4af21ed2019-11-04 09:37:55 -0800155// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
156// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
157// command line so they can be overridden by the local module flags).
158type LocalOrGlobalFlags struct {
159 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700160 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800161 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700162 CFlags []string // Flags that apply to C and C++ source files
163 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
164 ConlyFlags []string // Flags that apply to C source files
165 CppFlags []string // Flags that apply to C++ source files
166 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700167 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800168}
169
170type Flags struct {
171 Local LocalOrGlobalFlags
172 Global LocalOrGlobalFlags
173
174 aidlFlags []string // Flags that apply to aidl source files
175 rsFlags []string // Flags that apply to renderscript source files
176 libFlags []string // Flags to add libraries early to the link order
177 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
178 TidyFlags []string // Flags that apply to clang-tidy
179 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700180
Colin Crossc3199482017-03-30 15:03:04 -0700181 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800182 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700183 SystemIncludeFlags []string
184
Oliver Nguyen04526782020-04-21 12:40:27 -0700185 Toolchain config.Toolchain
186 Tidy bool
187 GcovCoverage bool
188 SAbiDump bool
189 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800190
191 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800192 DynamicLinker string
193
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700194 CFlagsDeps android.Paths // Files depended on by compiler flags
195 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800196
Dan Willemsen98ab3112019-08-27 21:20:40 -0700197 AssemblerWithCpp bool
198 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800199
Colin Cross19878da2019-03-28 14:45:07 -0700200 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700201 protoC bool // Whether to use C instead of C++
202 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700203
204 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700205}
206
Colin Crossca860ac2016-01-04 14:34:37 -0800207// Properties used to compile all C or C++ modules
208type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700209 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800210 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700211
Colin Crossc511bc52020-04-07 16:50:32 +0000212 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
213 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800214 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700215
Jooyung Han379660c2020-04-21 15:24:00 +0900216 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
217 Min_sdk_version *string
218
Colin Crossc511bc52020-04-07 16:50:32 +0000219 // If true, always create an sdk variant and don't create a platform variant.
220 Sdk_variant_only *bool
221
Jiyong Parkde866cb2018-12-07 23:08:36 +0900222 AndroidMkSharedLibs []string `blueprint:"mutated"`
223 AndroidMkStaticLibs []string `blueprint:"mutated"`
224 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
225 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700226 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900227 HideFromMake bool `blueprint:"mutated"`
228 PreventInstall bool `blueprint:"mutated"`
229 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700230
Justin Yun5f7f7e82019-11-18 19:52:14 +0900231 ImageVariationPrefix string `blueprint:"mutated"`
232 VndkVersion string `blueprint:"mutated"`
233 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800234
235 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
236 // file
237 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900238
Yifan Hong1b3348d2020-01-21 15:53:22 -0800239 // Make this module available when building for ramdisk
240 Ramdisk_available *bool
241
Jiyong Parkf9332f12018-02-01 00:54:12 +0900242 // Make this module available when building for recovery
243 Recovery_available *bool
244
Colin Crossae6c5202019-11-20 13:35:50 -0800245 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800246 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800247 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800248 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900249 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900250
251 // Allows this module to use non-APEX version of libraries. Useful
252 // for building binaries that are started before APEXes are activated.
253 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900254
255 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
256 // see soong/cc/config/vndk.go
257 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900258
259 // Used by vendor snapshot to record dependencies from snapshot modules.
260 SnapshotSharedLibs []string `blueprint:"mutated"`
261 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000262
263 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000264
265 // Set by factories of module types that can only be referenced from variants compiled against
266 // the SDK.
267 AlwaysSdk bool `blueprint:"mutated"`
268
269 // Variant is an SDK variant created by sdkMutator
270 IsSdkVariant bool `blueprint:"mutated"`
271 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
272 // variant to have a ".sdk" suffix.
273 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700274}
275
276type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900277 // whether this module should be allowed to be directly depended by other
278 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900279 // In addition, this module should be allowed to be directly depended by
280 // product modules with `product_specific: true`.
281 // If set to true, three variants will be built separately, one like
282 // normal, another limited to the set of libraries and headers
283 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700284 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900285 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700286 // so it shouldn't have any unversioned runtime dependencies, or
287 // make assumptions about the system that may not be true in the
288 // future.
289 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900290 // If set to false, this module becomes inaccessible from /vendor or /product
291 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900292 //
293 // Default value is true when vndk: {enabled: true} or vendor: true.
294 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700295 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900296 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700297 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900298
299 // whether this module is capable of being loaded with other instance
300 // (possibly an older version) of the same module in the same process.
301 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
302 // can be double loaded in a vendor process if the library is also a
303 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
304 // explicitly marked as `double_loadable: true` by the owner, or the dependency
305 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
306 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800307}
308
Colin Crossca860ac2016-01-04 14:34:37 -0800309type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800310 static() bool
311 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900312 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700313 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900314 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700315 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800316 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700317 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800318 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900319 isLlndk(config android.Config) bool
320 isLlndkPublic(config android.Config) bool
321 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900322 isVndk() bool
323 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800324 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900325 inProduct() bool
326 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800327 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900328 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800329 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700330 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700331 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800332 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800333 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800334 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800335 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800336 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900337 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900338 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900339 hasStubsVariants() bool
340 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900341 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800342 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700343 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800344}
345
346type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700347 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800348 ModuleContextIntf
349}
350
351type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700352 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800353 ModuleContextIntf
354}
355
Colin Cross37047f12016-12-13 17:06:13 -0800356type DepsContext interface {
357 android.BottomUpMutatorContext
358 ModuleContextIntf
359}
360
Colin Crossca860ac2016-01-04 14:34:37 -0800361type feature interface {
362 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800363 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800364 flags(ctx ModuleContext, flags Flags) Flags
365 props() []interface{}
366}
367
368type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700369 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800370 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800371 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700372 compilerProps() []interface{}
373
Colin Cross76fada02016-07-27 10:31:13 -0700374 appendCflags([]string)
375 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700376 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800377}
378
379type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700380 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800381 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700382 linkerFlags(ctx ModuleContext, flags Flags) Flags
383 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800384 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700385
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700386 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700387 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900388 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700389
390 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900391 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000392
393 // Get the deps that have been explicitly specified in the properties.
394 // Only updates the
395 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
396}
397
398type specifiedDeps struct {
399 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000400 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800401}
402
403type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700404 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700405 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000406 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800407 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700408 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700409 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900410 relativeInstallPath() string
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100411 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800412}
413
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800414type xref interface {
415 XrefCcFiles() android.Paths
416}
417
Colin Crossc99deeb2016-04-11 15:06:20 -0700418var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700419 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
420 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
421 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
422 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
423 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800424 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700425 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
426 headerDepTag = DependencyTag{Name: "header", Library: true}
427 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
428 genSourceDepTag = DependencyTag{Name: "gen source"}
429 genHeaderDepTag = DependencyTag{Name: "gen header"}
430 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
431 objDepTag = DependencyTag{Name: "obj"}
432 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
433 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
434 reuseObjTag = DependencyTag{Name: "reuse objects"}
435 staticVariantTag = DependencyTag{Name: "static variant"}
436 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
437 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
438 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
439 runtimeDepTag = DependencyTag{Name: "runtime lib"}
Ivan Lozano183a3212019-10-18 14:18:45 -0700440 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700441)
442
Roland Levillainf89cd092019-07-29 16:22:59 +0100443func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700444 ccDepTag, ok := depTag.(DependencyTag)
445 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100446}
447
448func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700449 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100450 return ok && ccDepTag == runtimeDepTag
451}
452
453func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700454 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100455 return ok && ccDepTag == testPerSrcDepTag
456}
457
Colin Crossca860ac2016-01-04 14:34:37 -0800458// Module contains the properties and members used by all C/C++ module types, and implements
459// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
460// to construct the output file. Behavior can be customized with a Customizer interface
461type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700462 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700463 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900464 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900465 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700466
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700467 Properties BaseProperties
468 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700469
Colin Crossca860ac2016-01-04 14:34:37 -0800470 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700471 hod android.HostOrDeviceSupported
472 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700473
Paul Duffina0843f62019-12-13 19:50:38 +0000474 // Allowable SdkMemberTypes of this module type.
475 sdkMemberTypes []android.SdkMemberType
476
Colin Crossca860ac2016-01-04 14:34:37 -0800477 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700478 features []feature
479 compiler compiler
480 linker linker
481 installer installer
482 stl *stl
483 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800484 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800485 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900486 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700487 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700488 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800489
Colin Cross635c3b02016-05-18 15:37:25 -0700490 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800491
Colin Crossb98c8b02016-07-29 13:44:28 -0700492 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700493
494 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800495
496 // Flags used to compile this module
497 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700498
499 // 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 -0800500 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700501 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800502 depsInLinkOrder android.Paths
503
504 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700505 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900506
507 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800508 // Kythe (source file indexer) paths for this compilation module
509 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900510
511 // For apex variants, this is set as apex.min_sdk_version
512 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700513}
514
Ivan Lozano52767be2019-10-18 14:49:46 -0700515func (c *Module) Toc() android.OptionalPath {
516 if c.linker != nil {
517 if library, ok := c.linker.(libraryInterface); ok {
518 return library.toc()
519 }
520 }
521 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
522}
523
524func (c *Module) ApiLevel() string {
525 if c.linker != nil {
526 if stub, ok := c.linker.(*stubDecorator); ok {
527 return stub.properties.ApiLevel
528 }
529 }
530 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
531}
532
533func (c *Module) Static() bool {
534 if c.linker != nil {
535 if library, ok := c.linker.(libraryInterface); ok {
536 return library.static()
537 }
538 }
539 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
540}
541
542func (c *Module) Shared() bool {
543 if c.linker != nil {
544 if library, ok := c.linker.(libraryInterface); ok {
545 return library.shared()
546 }
547 }
548 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
549}
550
551func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000552 if c.stl != nil {
553 return c.stl.Properties.SelectedStl
554 }
555 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700556}
557
558func (c *Module) ToolchainLibrary() bool {
559 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
560 return true
561 }
562 return false
563}
564
565func (c *Module) NdkPrebuiltStl() bool {
566 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
567 return true
568 }
569 return false
570}
571
572func (c *Module) StubDecorator() bool {
573 if _, ok := c.linker.(*stubDecorator); ok {
574 return true
575 }
576 return false
577}
578
579func (c *Module) SdkVersion() string {
580 return String(c.Properties.Sdk_version)
581}
582
Artur Satayev480e25b2020-04-27 18:53:18 +0100583func (c *Module) MinSdkVersion() string {
584 return String(c.Properties.Min_sdk_version)
585}
586
Colin Crossc511bc52020-04-07 16:50:32 +0000587func (c *Module) AlwaysSdk() bool {
588 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
589}
590
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800591func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700592 if c.linker != nil {
593 if library, ok := c.linker.(exportedFlagsProducer); ok {
594 return library.exportedDirs()
595 }
596 }
597 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
598}
599
600func (c *Module) HasStaticVariant() bool {
601 if c.staticVariant != nil {
602 return true
603 }
604 return false
605}
606
607func (c *Module) GetStaticVariant() LinkableInterface {
608 return c.staticVariant
609}
610
611func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
612 c.depsInLinkOrder = depsInLinkOrder
613}
614
615func (c *Module) GetDepsInLinkOrder() []android.Path {
616 return c.depsInLinkOrder
617}
618
619func (c *Module) StubsVersions() []string {
620 if c.linker != nil {
621 if library, ok := c.linker.(*libraryDecorator); ok {
622 return library.Properties.Stubs.Versions
623 }
624 }
625 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
626}
627
628func (c *Module) CcLibrary() bool {
629 if c.linker != nil {
630 if _, ok := c.linker.(*libraryDecorator); ok {
631 return true
632 }
633 }
634 return false
635}
636
637func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700638 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700639 return true
640 }
641 return false
642}
643
Ivan Lozano2b262972019-11-21 12:30:50 -0800644func (c *Module) NonCcVariants() bool {
645 return false
646}
647
Ivan Lozano183a3212019-10-18 14:18:45 -0700648func (c *Module) SetBuildStubs() {
649 if c.linker != nil {
650 if library, ok := c.linker.(*libraryDecorator); ok {
651 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700652 c.Properties.HideFromMake = true
653 c.sanitize = nil
654 c.stl = nil
655 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700656 return
657 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000658 if _, ok := c.linker.(*llndkStubDecorator); ok {
659 c.Properties.HideFromMake = true
660 return
661 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700662 }
663 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
664}
665
Ivan Lozano52767be2019-10-18 14:49:46 -0700666func (c *Module) BuildStubs() bool {
667 if c.linker != nil {
668 if library, ok := c.linker.(*libraryDecorator); ok {
669 return library.buildStubs()
670 }
671 }
672 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
673}
674
Ivan Lozano183a3212019-10-18 14:18:45 -0700675func (c *Module) SetStubsVersions(version string) {
676 if c.linker != nil {
677 if library, ok := c.linker.(*libraryDecorator); ok {
678 library.MutatedProperties.StubsVersion = version
679 return
680 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000681 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
682 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
683 return
684 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700685 }
686 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
687}
688
Jooyung Han03b51852020-02-26 22:45:42 +0900689func (c *Module) StubsVersion() string {
690 if c.linker != nil {
691 if library, ok := c.linker.(*libraryDecorator); ok {
692 return library.MutatedProperties.StubsVersion
693 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000694 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
695 return llndk.libraryDecorator.MutatedProperties.StubsVersion
696 }
Jooyung Han03b51852020-02-26 22:45:42 +0900697 }
698 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
699}
700
Ivan Lozano183a3212019-10-18 14:18:45 -0700701func (c *Module) SetStatic() {
702 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700703 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700704 library.setStatic()
705 return
706 }
707 }
708 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
709}
710
711func (c *Module) SetShared() {
712 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700713 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700714 library.setShared()
715 return
716 }
717 }
718 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
719}
720
721func (c *Module) BuildStaticVariant() bool {
722 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700723 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700724 return library.buildStatic()
725 }
726 }
727 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
728}
729
730func (c *Module) BuildSharedVariant() bool {
731 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700732 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700733 return library.buildShared()
734 }
735 }
736 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
737}
738
739func (c *Module) Module() android.Module {
740 return c
741}
742
Jiyong Parkc20eee32018-09-05 22:36:17 +0900743func (c *Module) OutputFile() android.OptionalPath {
744 return c.outputFile
745}
746
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400747func (c *Module) CoverageFiles() android.Paths {
748 if c.linker != nil {
749 if library, ok := c.linker.(libraryInterface); ok {
750 return library.objs().coverageFiles
751 }
752 }
753 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
754}
755
Ivan Lozano183a3212019-10-18 14:18:45 -0700756var _ LinkableInterface = (*Module)(nil)
757
Jiyong Park719b4462019-01-13 00:39:51 +0900758func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900759 if c.linker != nil {
760 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900761 }
762 return nil
763}
764
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900765func (c *Module) CoverageOutputFile() android.OptionalPath {
766 if c.linker != nil {
767 return c.linker.coverageOutputFilePath()
768 }
769 return android.OptionalPath{}
770}
771
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900772func (c *Module) RelativeInstallPath() string {
773 if c.installer != nil {
774 return c.installer.relativeInstallPath()
775 }
776 return ""
777}
778
Jooyung Han344d5432019-08-23 11:17:39 +0900779func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900780 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900781}
782
Colin Cross36242852017-06-23 15:06:31 -0700783func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700784 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800785 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700786 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800787 }
788 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700789 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800790 }
791 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700792 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800793 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700794 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700795 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700796 }
Colin Cross16b23492016-01-06 14:41:07 -0800797 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700798 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800799 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800800 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700801 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800802 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800803 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700804 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800805 }
Justin Yun8effde42017-06-23 19:24:43 +0900806 if c.vndkdep != nil {
807 c.AddProperties(c.vndkdep.props()...)
808 }
Stephen Craneba090d12017-05-09 15:44:35 -0700809 if c.lto != nil {
810 c.AddProperties(c.lto.props()...)
811 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700812 if c.pgo != nil {
813 c.AddProperties(c.pgo.props()...)
814 }
Colin Crossca860ac2016-01-04 14:34:37 -0800815 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700816 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800817 }
Colin Crossc472d572015-03-17 15:06:21 -0700818
Colin Crossa9d8bee2018-10-02 13:59:46 -0700819 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
820 switch class {
821 case android.Device:
822 return ctx.Config().DevicePrefer32BitExecutables()
823 case android.HostCross:
824 // Windows builds always prefer 32-bit
825 return true
826 default:
827 return false
828 }
829 })
Colin Cross36242852017-06-23 15:06:31 -0700830 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900831 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900832 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900833 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900834
Colin Cross36242852017-06-23 15:06:31 -0700835 return c
Colin Crossc472d572015-03-17 15:06:21 -0700836}
837
Colin Crossb916a382016-07-29 17:28:03 -0700838// Returns true for dependency roots (binaries)
839// TODO(ccross): also handle dlopenable libraries
840func (c *Module) isDependencyRoot() bool {
841 if root, ok := c.linker.(interface {
842 isDependencyRoot() bool
843 }); ok {
844 return root.isDependencyRoot()
845 }
846 return false
847}
848
Justin Yun5f7f7e82019-11-18 19:52:14 +0900849// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
850// "product" and "vendor" variant modules return true for this function.
851// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
852// "soc_specific: true" and more vendor installed modules are included here.
853// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
854// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700855func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900856 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700857}
858
Colin Crossc511bc52020-04-07 16:50:32 +0000859func (c *Module) canUseSdk() bool {
860 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
861}
862
863func (c *Module) UseSdk() bool {
864 if c.canUseSdk() {
865 return String(c.Properties.Sdk_version) != ""
866 }
867 return false
868}
869
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800870func (c *Module) isCoverageVariant() bool {
871 return c.coverage.Properties.IsCoverageVariant
872}
873
Peter Collingbournead84f972019-12-17 16:46:18 -0800874func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800875 return inList(c.Name(), ndkMigratedLibs)
876}
877
Inseob Kim9516ee92019-05-09 10:56:13 +0900878func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800879 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900880 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800881}
882
Inseob Kim9516ee92019-05-09 10:56:13 +0900883func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800884 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900885 name := c.BaseModuleName()
886 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800887}
888
Inseob Kim9516ee92019-05-09 10:56:13 +0900889func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800890 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900891 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800892}
893
Ivan Lozano52767be2019-10-18 14:49:46 -0700894func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800895 if vndkdep := c.vndkdep; vndkdep != nil {
896 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900897 }
898 return false
899}
900
Yi Kong7e53c572018-02-14 18:16:12 +0800901func (c *Module) isPgoCompile() bool {
902 if pgo := c.pgo; pgo != nil {
903 return pgo.Properties.PgoCompile
904 }
905 return false
906}
907
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800908func (c *Module) isNDKStubLibrary() bool {
909 if _, ok := c.compiler.(*stubDecorator); ok {
910 return true
911 }
912 return false
913}
914
Logan Chienf3511742017-10-31 18:04:35 +0800915func (c *Module) isVndkSp() bool {
916 if vndkdep := c.vndkdep; vndkdep != nil {
917 return vndkdep.isVndkSp()
918 }
919 return false
920}
921
922func (c *Module) isVndkExt() bool {
923 if vndkdep := c.vndkdep; vndkdep != nil {
924 return vndkdep.isVndkExt()
925 }
926 return false
927}
928
Ivan Lozano52767be2019-10-18 14:49:46 -0700929func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900930 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800931}
932
Logan Chienf3511742017-10-31 18:04:35 +0800933func (c *Module) getVndkExtendsModuleName() string {
934 if vndkdep := c.vndkdep; vndkdep != nil {
935 return vndkdep.getVndkExtendsModuleName()
936 }
937 return ""
938}
939
Justin Yun5f7f7e82019-11-18 19:52:14 +0900940// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900941// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700942func (c *Module) HasVendorVariant() bool {
943 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900944}
945
Justin Yun5f7f7e82019-11-18 19:52:14 +0900946const (
947 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
948 // against the VNDK.
949 VendorVariationPrefix = "vendor."
950
951 // ProductVariationPrefix is the variant prefix used for /product code that compiles
952 // against the VNDK.
953 ProductVariationPrefix = "product."
954)
955
956// Returns true if the module is "product" variant. Usually these modules are installed in /product
957func (c *Module) inProduct() bool {
958 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
959}
960
961// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
962func (c *Module) inVendor() bool {
963 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
964}
965
Yifan Hong1b3348d2020-01-21 15:53:22 -0800966func (c *Module) InRamdisk() bool {
967 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
968}
969
Ivan Lozano52767be2019-10-18 14:49:46 -0700970func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800971 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900972}
973
Yifan Hong1b3348d2020-01-21 15:53:22 -0800974func (c *Module) OnlyInRamdisk() bool {
975 return c.ModuleBase.InstallInRamdisk()
976}
977
Ivan Lozano52767be2019-10-18 14:49:46 -0700978func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900979 return c.ModuleBase.InstallInRecovery()
980}
981
Jiyong Park25fc6a92018-11-18 18:02:45 +0900982func (c *Module) IsStubs() bool {
983 if library, ok := c.linker.(*libraryDecorator); ok {
984 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900985 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
986 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900987 }
988 return false
989}
990
991func (c *Module) HasStubsVariants() bool {
992 if library, ok := c.linker.(*libraryDecorator); ok {
993 return len(library.Properties.Stubs.Versions) > 0
994 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700995 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
996 return len(library.Properties.Stubs.Versions) > 0
997 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900998 return false
999}
1000
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001001func (c *Module) bootstrap() bool {
1002 return Bool(c.Properties.Bootstrap)
1003}
1004
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001005func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001006 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1007 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1008 return false
1009 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001010 return c.linker != nil && c.linker.nativeCoverage()
1011}
1012
Inseob Kim8471cda2019-11-15 09:59:12 +09001013func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +09001014 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1015 return true
1016 }
1017 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
1018 return true
1019 }
1020 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
1021 return true
1022 }
1023 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001024}
1025
Jiyong Park73c54ee2019-10-22 20:31:18 +09001026func (c *Module) ExportedIncludeDirs() android.Paths {
1027 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1028 return flagsProducer.exportedDirs()
1029 }
Jiyong Park232e7852019-11-04 12:23:40 +09001030 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001031}
1032
1033func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1034 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1035 return flagsProducer.exportedSystemDirs()
1036 }
Jiyong Park232e7852019-11-04 12:23:40 +09001037 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001038}
1039
1040func (c *Module) ExportedFlags() []string {
1041 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1042 return flagsProducer.exportedFlags()
1043 }
Jiyong Park232e7852019-11-04 12:23:40 +09001044 return nil
1045}
1046
1047func (c *Module) ExportedDeps() android.Paths {
1048 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1049 return flagsProducer.exportedDeps()
1050 }
1051 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001052}
1053
Inseob Kimd110f872019-12-06 13:15:38 +09001054func (c *Module) ExportedGeneratedHeaders() android.Paths {
1055 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1056 return flagsProducer.exportedGeneratedHeaders()
1057 }
1058 return nil
1059}
1060
Jiyong Parkf1194352019-02-25 11:05:47 +09001061func isBionic(name string) bool {
1062 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001063 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001064 return true
1065 }
1066 return false
1067}
1068
Martin Stjernholm279de572019-09-10 23:18:20 +01001069func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001070 if name == "libclang_rt.hwasan-aarch64-android" {
1071 return inList("hwaddress", config.SanitizeDevice())
1072 }
1073 return isBionic(name)
1074}
1075
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001076func (c *Module) XrefCcFiles() android.Paths {
1077 return c.kytheFiles
1078}
1079
Colin Crossca860ac2016-01-04 14:34:37 -08001080type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001081 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001082 moduleContextImpl
1083}
1084
Colin Cross37047f12016-12-13 17:06:13 -08001085type depsContext struct {
1086 android.BottomUpMutatorContext
1087 moduleContextImpl
1088}
1089
Colin Crossca860ac2016-01-04 14:34:37 -08001090type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001091 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001092 moduleContextImpl
1093}
1094
Justin Yun5f7f7e82019-11-18 19:52:14 +09001095func (ctx *moduleContext) ProductSpecific() bool {
1096 return ctx.ModuleContext.ProductSpecific() ||
1097 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1098}
1099
Jiyong Park2db76922017-11-08 16:03:48 +09001100func (ctx *moduleContext) SocSpecific() bool {
1101 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001102 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001103}
1104
Colin Crossca860ac2016-01-04 14:34:37 -08001105type moduleContextImpl struct {
1106 mod *Module
1107 ctx BaseModuleContext
1108}
1109
Colin Crossb98c8b02016-07-29 13:44:28 -07001110func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001111 return ctx.mod.toolchain(ctx.ctx)
1112}
1113
1114func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001115 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001116}
1117
1118func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001119 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001120}
1121
Jiyong Park1d1119f2019-07-29 21:27:18 +09001122func (ctx *moduleContextImpl) header() bool {
1123 return ctx.mod.header()
1124}
1125
Jooyung Hanccce2f22020-03-07 03:45:53 +09001126func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001127 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001128}
1129
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001130func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001131 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001132}
1133
1134func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001135 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001136 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001137 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001138 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001139 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001140 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001141 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001142 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001143 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001144 }
1145 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001146}
1147
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001148func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001149 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001150}
Justin Yun8effde42017-06-23 19:24:43 +09001151
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001152func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001153 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001154}
1155
Inseob Kim9516ee92019-05-09 10:56:13 +09001156func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1157 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001158}
1159
Inseob Kim9516ee92019-05-09 10:56:13 +09001160func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1161 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001162}
1163
Inseob Kim9516ee92019-05-09 10:56:13 +09001164func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1165 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001166}
1167
Logan Chienf3511742017-10-31 18:04:35 +08001168func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001169 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001170}
1171
Yi Kong7e53c572018-02-14 18:16:12 +08001172func (ctx *moduleContextImpl) isPgoCompile() bool {
1173 return ctx.mod.isPgoCompile()
1174}
1175
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001176func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1177 return ctx.mod.isNDKStubLibrary()
1178}
1179
Justin Yun8effde42017-06-23 19:24:43 +09001180func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001181 return ctx.mod.isVndkSp()
1182}
1183
1184func (ctx *moduleContextImpl) isVndkExt() bool {
1185 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001186}
1187
Vic Yangefd249e2018-11-12 20:19:56 -08001188func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001189 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001190}
1191
Justin Yun5f7f7e82019-11-18 19:52:14 +09001192func (ctx *moduleContextImpl) inProduct() bool {
1193 return ctx.mod.inProduct()
1194}
1195
1196func (ctx *moduleContextImpl) inVendor() bool {
1197 return ctx.mod.inVendor()
1198}
1199
Yifan Hong1b3348d2020-01-21 15:53:22 -08001200func (ctx *moduleContextImpl) inRamdisk() bool {
1201 return ctx.mod.InRamdisk()
1202}
1203
Jiyong Parkf9332f12018-02-01 00:54:12 +09001204func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001205 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001206}
1207
Logan Chien2f2b8902018-07-10 15:01:19 +08001208// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001209func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001210 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1211 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001212 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001213
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001214 // Coverage builds have extra symbols.
1215 if ctx.mod.isCoverageVariant() {
1216 return false
1217 }
1218
Doug Hornc32c6b02019-01-17 14:44:05 -08001219 if ctx.ctx.Fuchsia() {
1220 return false
1221 }
1222
Logan Chien2f2b8902018-07-10 15:01:19 +08001223 if sanitize := ctx.mod.sanitize; sanitize != nil {
1224 if !sanitize.isVariantOnProductionDevice() {
1225 return false
1226 }
1227 }
1228 if !ctx.ctx.Device() {
1229 // Host modules do not need ABI dumps.
1230 return false
1231 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001232 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001233 // Stubs do not need ABI dumps.
1234 return false
1235 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001236 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001237}
1238
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001239func (ctx *moduleContextImpl) selectedStl() string {
1240 if stl := ctx.mod.stl; stl != nil {
1241 return stl.Properties.SelectedStl
1242 }
1243 return ""
1244}
1245
Ivan Lozanobd721262018-11-27 14:33:03 -08001246func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1247 return ctx.mod.linker.useClangLld(actx)
1248}
1249
Colin Crossce75d2c2016-10-06 16:12:58 -07001250func (ctx *moduleContextImpl) baseModuleName() string {
1251 return ctx.mod.ModuleBase.BaseModuleName()
1252}
1253
Logan Chienf3511742017-10-31 18:04:35 +08001254func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1255 return ctx.mod.getVndkExtendsModuleName()
1256}
1257
Logan Chiene274fc92019-12-03 11:18:32 -08001258func (ctx *moduleContextImpl) isForPlatform() bool {
1259 return ctx.mod.IsForPlatform()
1260}
1261
Jiyong Park58e364a2019-01-19 19:24:06 +09001262func (ctx *moduleContextImpl) apexName() string {
1263 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001264}
1265
Jooyung Hanccce2f22020-03-07 03:45:53 +09001266func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001267 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001268}
1269
Jiyong Parkb0788572018-12-20 22:10:17 +09001270func (ctx *moduleContextImpl) hasStubsVariants() bool {
1271 return ctx.mod.HasStubsVariants()
1272}
1273
1274func (ctx *moduleContextImpl) isStubs() bool {
1275 return ctx.mod.IsStubs()
1276}
1277
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001278func (ctx *moduleContextImpl) bootstrap() bool {
1279 return ctx.mod.bootstrap()
1280}
1281
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001282func (ctx *moduleContextImpl) nativeCoverage() bool {
1283 return ctx.mod.nativeCoverage()
1284}
1285
Colin Cross635c3b02016-05-18 15:37:25 -07001286func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001287 return &Module{
1288 hod: hod,
1289 multilib: multilib,
1290 }
1291}
1292
Colin Cross635c3b02016-05-18 15:37:25 -07001293func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001294 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001295 module.features = []feature{
1296 &tidyFeature{},
1297 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001298 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001299 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001300 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001301 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001302 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001303 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001304 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001305 return module
1306}
1307
Colin Crossce75d2c2016-10-06 16:12:58 -07001308func (c *Module) Prebuilt() *android.Prebuilt {
1309 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1310 return p.prebuilt()
1311 }
1312 return nil
1313}
1314
1315func (c *Module) Name() string {
1316 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001317 if p, ok := c.linker.(interface {
1318 Name(string) string
1319 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001320 name = p.Name(name)
1321 }
1322 return name
1323}
1324
Alex Light3d673592019-01-18 14:37:31 -08001325func (c *Module) Symlinks() []string {
1326 if p, ok := c.installer.(interface {
1327 symlinkList() []string
1328 }); ok {
1329 return p.symlinkList()
1330 }
1331 return nil
1332}
1333
Jeff Gaston294356f2017-09-27 17:05:30 -07001334// orderDeps reorders dependencies into a list such that if module A depends on B, then
1335// A will precede B in the resultant list.
1336// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001337// Note that directSharedDeps should be the analogous static library for each shared lib dep
1338func 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 -07001339 // If A depends on B, then
1340 // Every list containing A will also contain B later in the list
1341 // So, after concatenating all lists, the final instance of B will have come from the same
1342 // original list as the final instance of A
1343 // So, the final instance of B will be later in the concatenation than the final A
1344 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1345 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001346 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001347 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001348 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1349 }
1350 for _, dep := range directSharedDeps {
1351 orderedAllDeps = append(orderedAllDeps, dep)
1352 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001353 }
1354
Colin Crossb6715442017-10-24 11:13:31 -07001355 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001356
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001357 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001358 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001359 // resultant list to only what the caller has chosen to include in directStaticDeps
1360 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001361
1362 return orderedAllDeps, orderedDeclaredDeps
1363}
1364
Ivan Lozano183a3212019-10-18 14:18:45 -07001365func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001366 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001367 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001368 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1369 staticDepFiles := []android.Path{}
1370 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001371 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1372 if dep.OutputFile().Valid() {
1373 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1374 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1375 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001376 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001377 sharedDepFiles := []android.Path{}
1378 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001379 if sharedDep.HasStaticVariant() {
1380 staticAnalogue := sharedDep.GetStaticVariant()
1381 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1382 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001383 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001384 }
1385
1386 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001387 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1388 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001389
1390 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001391}
1392
Roland Levillainf89cd092019-07-29 16:22:59 +01001393func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1394 test, ok := c.linker.(testPerSrc)
1395 return ok && test.isAllTestsVariation()
1396}
1397
Justin Yun5f7f7e82019-11-18 19:52:14 +09001398func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1399 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1400 // "current", it will append the VNDK version to the name suffix.
1401 var vndkVersion string
1402 var nameSuffix string
1403 if c.inProduct() {
1404 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1405 nameSuffix = productSuffix
1406 } else {
1407 vndkVersion = ctx.DeviceConfig().VndkVersion()
1408 nameSuffix = vendorSuffix
1409 }
1410 if vndkVersion == "current" {
1411 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1412 }
1413 if c.Properties.VndkVersion != vndkVersion {
1414 // add version suffix only if the module is using different vndk version than the
1415 // version in product or vendor partition.
1416 nameSuffix += "." + c.Properties.VndkVersion
1417 }
1418 return nameSuffix
1419}
1420
Colin Cross635c3b02016-05-18 15:37:25 -07001421func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001422 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001423 //
1424 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1425 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1426 // module and return early, as this module does not produce an output file per se.
1427 if c.IsTestPerSrcAllTestsVariation() {
1428 c.outputFile = android.OptionalPath{}
1429 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001430 }
1431
Jooyung Han38002912019-05-16 04:01:54 +09001432 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001433
Inseob Kim64c43952019-08-26 16:52:35 +09001434 c.Properties.SubName = ""
1435
1436 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1437 c.Properties.SubName += nativeBridgeSuffix
1438 }
1439
Justin Yun5f7f7e82019-11-18 19:52:14 +09001440 _, llndk := c.linker.(*llndkStubDecorator)
1441 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1442 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1443 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1444 // added for product variant only when we have vendor and product variants with core
1445 // variant. The suffix is not added for vendor-only or product-only module.
1446 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1447 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001448 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1449 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1450 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001451 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1452 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001453 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001454 c.Properties.SubName += recoverySuffix
Colin Crossc511bc52020-04-07 16:50:32 +00001455 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1456 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001457 }
1458
Colin Crossca860ac2016-01-04 14:34:37 -08001459 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001460 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001461 moduleContextImpl: moduleContextImpl{
1462 mod: c,
1463 },
1464 }
1465 ctx.ctx = ctx
1466
Colin Crossf18e1102017-11-16 14:33:08 -08001467 deps := c.depsToPaths(ctx)
1468 if ctx.Failed() {
1469 return
1470 }
1471
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001472 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1473 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1474 }
1475
Colin Crossca860ac2016-01-04 14:34:37 -08001476 flags := Flags{
1477 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001478 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001479 }
Colin Crossca860ac2016-01-04 14:34:37 -08001480 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001481 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001482 }
1483 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001484 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001485 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001486 if c.stl != nil {
1487 flags = c.stl.flags(ctx, flags)
1488 }
Colin Cross16b23492016-01-06 14:41:07 -08001489 if c.sanitize != nil {
1490 flags = c.sanitize.flags(ctx, flags)
1491 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001492 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001493 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001494 }
Stephen Craneba090d12017-05-09 15:44:35 -07001495 if c.lto != nil {
1496 flags = c.lto.flags(ctx, flags)
1497 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001498 if c.pgo != nil {
1499 flags = c.pgo.flags(ctx, flags)
1500 }
Colin Crossca860ac2016-01-04 14:34:37 -08001501 for _, feature := range c.features {
1502 flags = feature.flags(ctx, flags)
1503 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001504 if ctx.Failed() {
1505 return
1506 }
1507
Colin Cross4af21ed2019-11-04 09:37:55 -08001508 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1509 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1510 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001511
Colin Cross4af21ed2019-11-04 09:37:55 -08001512 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001513
1514 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001515 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001516 }
1517 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001518 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001519 }
1520
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001521 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001522 // We need access to all the flags seen by a source file.
1523 if c.sabi != nil {
1524 flags = c.sabi.flags(ctx, flags)
1525 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001526
Colin Cross4af21ed2019-11-04 09:37:55 -08001527 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001528
Colin Crossca860ac2016-01-04 14:34:37 -08001529 // Optimization to reduce size of build.ninja
1530 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001531 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1532 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1533 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1534 flags.Local.CFlags = []string{"$cflags"}
1535 flags.Local.CppFlags = []string{"$cppflags"}
1536 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001537
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001538 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001539 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001540 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001541 if ctx.Failed() {
1542 return
1543 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001544 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001545 }
1546
Colin Crossca860ac2016-01-04 14:34:37 -08001547 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001548 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001549 if ctx.Failed() {
1550 return
1551 }
Colin Cross635c3b02016-05-18 15:37:25 -07001552 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001553
1554 // If a lib is directly included in any of the APEXes, unhide the stubs
1555 // variant having the latest version gets visible to make. In addition,
1556 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1557 // force anything in the make world to link against the stubs library.
1558 // (unless it is explicitly referenced via .bootstrap suffix or the
1559 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001560 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001561 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001562 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001563 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001564 c.Properties.HideFromMake = false // unhide
1565 // Note: this is still non-installable
1566 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001567
1568 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1569 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1570 if isSnapshotAware(ctx, c) {
1571 i.collectHeadersForSnapshot(ctx)
1572 }
1573 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001574 }
Colin Cross5049f022015-03-18 13:28:46 -07001575
Inseob Kim1f086e22019-05-09 13:29:15 +09001576 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001577 c.installer.install(ctx, c.outputFile.Path())
1578 if ctx.Failed() {
1579 return
Colin Crossca860ac2016-01-04 14:34:37 -08001580 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001581 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1582 // If the module has been specifically configure to not be installed then
1583 // skip the installation as otherwise it will break when running inside make
1584 // as the output path to install will not be specified. Not all uninstallable
1585 // modules can skip installation as some are needed for resolving make side
1586 // dependencies.
1587 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001588 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001589}
1590
Colin Cross0ea8ba82019-06-06 14:33:29 -07001591func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001592 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001593 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001594 }
Colin Crossca860ac2016-01-04 14:34:37 -08001595 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001596}
1597
Colin Crossca860ac2016-01-04 14:34:37 -08001598func (c *Module) begin(ctx BaseModuleContext) {
1599 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001600 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001601 }
Colin Crossca860ac2016-01-04 14:34:37 -08001602 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001603 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001604 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001605 if c.stl != nil {
1606 c.stl.begin(ctx)
1607 }
Colin Cross16b23492016-01-06 14:41:07 -08001608 if c.sanitize != nil {
1609 c.sanitize.begin(ctx)
1610 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001611 if c.coverage != nil {
1612 c.coverage.begin(ctx)
1613 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001614 if c.sabi != nil {
1615 c.sabi.begin(ctx)
1616 }
Justin Yun8effde42017-06-23 19:24:43 +09001617 if c.vndkdep != nil {
1618 c.vndkdep.begin(ctx)
1619 }
Stephen Craneba090d12017-05-09 15:44:35 -07001620 if c.lto != nil {
1621 c.lto.begin(ctx)
1622 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001623 if c.pgo != nil {
1624 c.pgo.begin(ctx)
1625 }
Colin Crossca860ac2016-01-04 14:34:37 -08001626 for _, feature := range c.features {
1627 feature.begin(ctx)
1628 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001629 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001630 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001631 if err != nil {
1632 ctx.PropertyErrorf("sdk_version", err.Error())
1633 }
Nan Zhang0007d812017-11-07 10:57:05 -08001634 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001635 }
Colin Crossca860ac2016-01-04 14:34:37 -08001636}
1637
Colin Cross37047f12016-12-13 17:06:13 -08001638func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001639 deps := Deps{}
1640
1641 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001642 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001643 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001644 // Add the PGO dependency (the clang_rt.profile runtime library), which
1645 // sometimes depends on symbols from libgcc, before libgcc gets added
1646 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001647 if c.pgo != nil {
1648 deps = c.pgo.deps(ctx, deps)
1649 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001650 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001651 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001652 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001653 if c.stl != nil {
1654 deps = c.stl.deps(ctx, deps)
1655 }
Colin Cross16b23492016-01-06 14:41:07 -08001656 if c.sanitize != nil {
1657 deps = c.sanitize.deps(ctx, deps)
1658 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001659 if c.coverage != nil {
1660 deps = c.coverage.deps(ctx, deps)
1661 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001662 if c.sabi != nil {
1663 deps = c.sabi.deps(ctx, deps)
1664 }
Justin Yun8effde42017-06-23 19:24:43 +09001665 if c.vndkdep != nil {
1666 deps = c.vndkdep.deps(ctx, deps)
1667 }
Stephen Craneba090d12017-05-09 15:44:35 -07001668 if c.lto != nil {
1669 deps = c.lto.deps(ctx, deps)
1670 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001671 for _, feature := range c.features {
1672 deps = feature.deps(ctx, deps)
1673 }
1674
Colin Crossb6715442017-10-24 11:13:31 -07001675 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1676 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1677 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1678 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1679 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1680 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001681 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001682
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001683 for _, lib := range deps.ReexportSharedLibHeaders {
1684 if !inList(lib, deps.SharedLibs) {
1685 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1686 }
1687 }
1688
1689 for _, lib := range deps.ReexportStaticLibHeaders {
1690 if !inList(lib, deps.StaticLibs) {
1691 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1692 }
1693 }
1694
Colin Cross5950f382016-12-13 12:50:57 -08001695 for _, lib := range deps.ReexportHeaderLibHeaders {
1696 if !inList(lib, deps.HeaderLibs) {
1697 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1698 }
1699 }
1700
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001701 for _, gen := range deps.ReexportGeneratedHeaders {
1702 if !inList(gen, deps.GeneratedHeaders) {
1703 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1704 }
1705 }
1706
Colin Crossc99deeb2016-04-11 15:06:20 -07001707 return deps
1708}
1709
Dan Albert7e9d2952016-08-04 13:02:36 -07001710func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001711 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001712 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001713 moduleContextImpl: moduleContextImpl{
1714 mod: c,
1715 },
1716 }
1717 ctx.ctx = ctx
1718
Colin Crossca860ac2016-01-04 14:34:37 -08001719 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001720}
1721
Jiyong Park7ed9de32018-10-15 22:25:07 +09001722// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001723func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001724 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1725 version := name[sharp+1:]
1726 libname := name[:sharp]
1727 return libname, version
1728 }
1729 return name, ""
1730}
1731
Colin Cross1e676be2016-10-12 14:38:15 -07001732func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001733 if !c.Enabled() {
1734 return
1735 }
1736
Colin Cross37047f12016-12-13 17:06:13 -08001737 ctx := &depsContext{
1738 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001739 moduleContextImpl: moduleContextImpl{
1740 mod: c,
1741 },
1742 }
1743 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001744
Colin Crossc99deeb2016-04-11 15:06:20 -07001745 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001746
Dan Albert914449f2016-06-17 16:45:24 -07001747 variantNdkLibs := []string{}
1748 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001749 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001750 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001751
Inseob Kimeec88e12020-01-22 11:11:29 +09001752 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001753 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001754 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001755 // 1. Name of an NDK library that refers to a prebuilt module.
1756 // For each of these, it adds the name of the prebuilt module (which will be in
1757 // prebuilts/ndk) to the list of nonvariant libs.
1758 // 2. Name of an NDK library that refers to an ndk_library module.
1759 // For each of these, it adds the name of the ndk_library module to the list of
1760 // variant libs.
1761 // 3. Anything else (so anything that isn't an NDK library).
1762 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001763 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001764 // The caller can then know to add the variantLibs dependencies differently from the
1765 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001766
Inseob Kim9516ee92019-05-09 10:56:13 +09001767 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001768 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1769
1770 rewriteVendorLibs := func(lib string) string {
1771 if isLlndkLibrary(lib, ctx.Config()) {
1772 return lib + llndkLibrarySuffix
1773 }
1774
1775 // only modules with BOARD_VNDK_VERSION uses snapshot.
1776 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1777 return lib
1778 }
1779
1780 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1781 return snapshot
1782 }
1783
1784 return lib
1785 }
1786
1787 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001788 variantLibs = []string{}
1789 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001790 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001791 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001792 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001793 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1794 if !inList(name, ndkMigratedLibs) {
1795 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001796 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001797 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001798 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001799 } else if ctx.useVndk() {
1800 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001801 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001802 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001803 if actx.OtherModuleExists(vendorPublicLib) {
1804 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1805 } else {
1806 // This can happen if vendor_public_library module is defined in a
1807 // namespace that isn't visible to the current module. In that case,
1808 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001809 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001810 }
Dan Albert914449f2016-06-17 16:45:24 -07001811 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001812 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001813 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001814 }
1815 }
Dan Albert914449f2016-06-17 16:45:24 -07001816 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001817 }
1818
Inseob Kimeec88e12020-01-22 11:11:29 +09001819 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1820 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1821 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1822 if ctx.useVndk() {
1823 for idx, lib := range deps.RuntimeLibs {
1824 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1825 }
1826 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001827 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001828
Jiyong Park7e636d02019-01-28 16:16:54 +09001829 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001830 if c.linker != nil {
1831 if library, ok := c.linker.(*libraryDecorator); ok {
1832 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001833 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001834 }
1835 }
1836 }
1837
Inseob Kimeec88e12020-01-22 11:11:29 +09001838 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1839 // only modules with BOARD_VNDK_VERSION uses snapshot.
1840 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1841 return lib
1842 }
1843
1844 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1845 return snapshot
1846 }
1847
1848 return lib
1849 }
1850
1851 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001852 for _, lib := range deps.HeaderLibs {
1853 depTag := headerDepTag
1854 if inList(lib, deps.ReexportHeaderLibHeaders) {
1855 depTag = headerExportDepTag
1856 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001857
1858 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1859
Jiyong Park7e636d02019-01-28 16:16:54 +09001860 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001861 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001862 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001863 } else {
1864 actx.AddVariationDependencies(nil, depTag, lib)
1865 }
1866 }
1867
1868 if buildStubs {
1869 // Stubs lib does not have dependency to other static/shared libraries.
1870 // Don't proceed.
1871 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001872 }
Colin Cross5950f382016-12-13 12:50:57 -08001873
Inseob Kimc0907f12019-02-08 21:00:45 +09001874 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001875 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001876
Jiyong Park5d1598f2019-02-25 22:14:17 +09001877 for _, lib := range deps.WholeStaticLibs {
1878 depTag := wholeStaticDepTag
1879 if impl, ok := syspropImplLibraries[lib]; ok {
1880 lib = impl
1881 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001882
1883 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1884
Jiyong Park5d1598f2019-02-25 22:14:17 +09001885 actx.AddVariationDependencies([]blueprint.Variation{
1886 {Mutator: "link", Variation: "static"},
1887 }, depTag, lib)
1888 }
1889
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001890 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001891 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001892 if inList(lib, deps.ReexportStaticLibHeaders) {
1893 depTag = staticExportDepTag
1894 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001895
1896 if impl, ok := syspropImplLibraries[lib]; ok {
1897 lib = impl
1898 }
1899
Inseob Kimeec88e12020-01-22 11:11:29 +09001900 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1901
Dan Willemsen59339a22018-07-22 21:18:45 -07001902 actx.AddVariationDependencies([]blueprint.Variation{
1903 {Mutator: "link", Variation: "static"},
1904 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001905 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001906
Jooyung Han75568392020-03-20 04:29:24 +09001907 // staticUnwinderDep is treated as staticDep for Q apexes
1908 // so that native libraries/binaries are linked with static unwinder
1909 // because Q libc doesn't have unwinder APIs
1910 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001911 actx.AddVariationDependencies([]blueprint.Variation{
1912 {Mutator: "link", Variation: "static"},
1913 }, staticUnwinderDepTag, staticUnwinder(actx))
1914 }
1915
Inseob Kimeec88e12020-01-22 11:11:29 +09001916 for _, lib := range deps.LateStaticLibs {
1917 actx.AddVariationDependencies([]blueprint.Variation{
1918 {Mutator: "link", Variation: "static"},
1919 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1920 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001921
Ivan Lozano183a3212019-10-18 14:18:45 -07001922 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001923 var variations []blueprint.Variation
1924 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001925 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001926 // Version is explicitly specified. i.e. libFoo#30
1927 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001928 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001929 }
1930 actx.AddVariationDependencies(variations, depTag, name)
1931
Jooyung Han03b51852020-02-26 22:45:42 +09001932 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001933 // The stubs library will be used when the depending module is built for APEX and
1934 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09001935 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09001936 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1937 // Note that depTag.ExplicitlyVersioned is false in this case.
1938 actx.AddVariationDependencies([]blueprint.Variation{
1939 {Mutator: "link", Variation: "shared"},
1940 {Mutator: "version", Variation: ver},
1941 }, depTag, name)
1942 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001943 }
1944 }
1945
Jiyong Park7ed9de32018-10-15 22:25:07 +09001946 // shared lib names without the #version suffix
1947 var sharedLibNames []string
1948
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001949 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001950 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001951 if c.static() {
1952 depTag = SharedFromStaticDepTag
1953 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001954 if inList(lib, deps.ReexportSharedLibHeaders) {
1955 depTag = sharedExportDepTag
1956 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001957
1958 if impl, ok := syspropImplLibraries[lib]; ok {
1959 lib = impl
1960 }
1961
Jiyong Park73c54ee2019-10-22 20:31:18 +09001962 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001963 sharedLibNames = append(sharedLibNames, name)
1964
Jiyong Park25fc6a92018-11-18 18:02:45 +09001965 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001966 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001967
Jiyong Park7ed9de32018-10-15 22:25:07 +09001968 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001969 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001970 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1971 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1972 // linking against both the stubs lib and the non-stubs lib at the same time.
1973 continue
1974 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001975 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001976 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001977
Dan Willemsen59339a22018-07-22 21:18:45 -07001978 actx.AddVariationDependencies([]blueprint.Variation{
1979 {Mutator: "link", Variation: "shared"},
1980 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001981
Colin Cross68861832016-07-08 10:41:41 -07001982 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001983
1984 for _, gen := range deps.GeneratedHeaders {
1985 depTag := genHeaderDepTag
1986 if inList(gen, deps.ReexportGeneratedHeaders) {
1987 depTag = genHeaderExportDepTag
1988 }
1989 actx.AddDependency(c, depTag, gen)
1990 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001991
Colin Cross42d48b72018-08-29 14:10:52 -07001992 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001993
1994 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001995 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001996 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001997 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001998 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001999 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002000 if deps.LinkerFlagsFile != "" {
2001 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2002 }
2003 if deps.DynamicLinker != "" {
2004 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002005 }
Dan Albert914449f2016-06-17 16:45:24 -07002006
2007 version := ctx.sdkVersion()
2008 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002009 {Mutator: "ndk_api", Variation: version},
2010 {Mutator: "link", Variation: "shared"},
2011 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07002012 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002013 {Mutator: "ndk_api", Variation: version},
2014 {Mutator: "link", Variation: "shared"},
2015 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002016
2017 if vndkdep := c.vndkdep; vndkdep != nil {
2018 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002019 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002020 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002021 {Mutator: "link", Variation: "shared"},
2022 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002023 }
2024 }
Colin Cross6362e272015-10-29 15:25:03 -07002025}
Colin Cross21b9a242015-03-24 14:15:58 -07002026
Colin Crosse40b4ea2018-10-02 22:25:58 -07002027func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002028 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2029 c.beginMutator(ctx)
2030 }
2031}
2032
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002033// Whether a module can link to another module, taking into
2034// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07002035func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
2036 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002037 // Host code is not restricted
2038 return
2039 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002040
2041 // VNDK is cc.Module supported only for now.
2042 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002043 // Though vendor code is limited by the vendor mutator,
2044 // each vendor-available module needs to check
2045 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002046 if ccTo, ok := to.(*Module); ok {
2047 if ccFrom.vndkdep != nil {
2048 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2049 }
2050 } else {
2051 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002052 }
2053 return
2054 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002055 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002056 // Platform code can link to anything
2057 return
2058 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002059 if from.InRamdisk() {
2060 // Ramdisk code is not NDK
2061 return
2062 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002063 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002064 // Recovery code is not NDK
2065 return
2066 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002067 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002068 // These are always allowed
2069 return
2070 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002071 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002072 // These are allowed, but they don't set sdk_version
2073 return
2074 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002075 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002076 // These aren't real libraries, but are the stub shared libraries that are included in
2077 // the NDK.
2078 return
2079 }
Logan Chien834b9a62019-01-14 15:39:03 +08002080
Ivan Lozano52767be2019-10-18 14:49:46 -07002081 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002082 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2083 // to link to libc++ (non-NDK and without sdk_version).
2084 return
2085 }
2086
Ivan Lozano52767be2019-10-18 14:49:46 -07002087 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002088 // NDK code linking to platform code is never okay.
2089 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002090 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002091 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002092 }
2093
2094 // At this point we know we have two NDK libraries, but we need to
2095 // check that we're not linking against anything built against a higher
2096 // API level, as it is only valid to link against older or equivalent
2097 // APIs.
2098
Inseob Kim01a28722018-04-11 09:48:45 +09002099 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002100 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002101 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002102 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002103 // Current can't be linked against by anything else.
2104 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002105 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002106 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002107 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002108 if err != nil {
2109 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002110 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002111 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002112 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002113 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002114 if err != nil {
2115 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002116 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002117 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002118 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002119
Inseob Kim01a28722018-04-11 09:48:45 +09002120 if toApi > fromApi {
2121 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002122 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002123 }
2124 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002125 }
Dan Albert202fe492017-12-15 13:56:59 -08002126
2127 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002128 fromStl := from.SelectedStl()
2129 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002130 if fromStl == "" || toStl == "" {
2131 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002132 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002133 // We can be permissive with the system "STL" since it is only the C++
2134 // ABI layer, but in the future we should make sure that everyone is
2135 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002136 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002137 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002138 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2139 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002140 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002141}
2142
Jiyong Park5fb8c102018-04-09 12:03:06 +09002143// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002144// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2145// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002146// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002147func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2148 check := func(child, parent android.Module) bool {
2149 to, ok := child.(*Module)
2150 if !ok {
2151 // follow thru cc.Defaults, etc.
2152 return true
2153 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002154
Jooyung Hana70f0672019-01-18 15:20:43 +09002155 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2156 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002157 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002158
2159 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002160 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002161 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002162 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002163
Jooyung Han0302a842019-10-30 18:43:49 +09002164 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002165 return false
2166 }
2167
2168 var stringPath []string
2169 for _, m := range ctx.GetWalkPath() {
2170 stringPath = append(stringPath, m.Name())
2171 }
2172 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2173 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2174 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2175 return false
2176 }
2177 if module, ok := ctx.Module().(*Module); ok {
2178 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002179 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002180 ctx.WalkDeps(check)
2181 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002182 }
2183 }
2184}
2185
Colin Crossc99deeb2016-04-11 15:06:20 -07002186// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002187func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002188 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002189
Ivan Lozano183a3212019-10-18 14:18:45 -07002190 directStaticDeps := []LinkableInterface{}
2191 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002192
Inseob Kim9516ee92019-05-09 10:56:13 +09002193 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2194
Inseob Kim69378442019-06-03 19:10:47 +09002195 reexportExporter := func(exporter exportedFlagsProducer) {
2196 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2197 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2198 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2199 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002200 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002201 }
2202
Colin Crossd11fcda2017-10-23 17:59:01 -07002203 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002204 depName := ctx.OtherModuleName(dep)
2205 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002206
Ivan Lozano52767be2019-10-18 14:49:46 -07002207 ccDep, ok := dep.(LinkableInterface)
2208 if !ok {
2209
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002210 // handling for a few module types that aren't cc Module but that are also supported
2211 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002212 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002213 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002214 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2215 genRule.GeneratedSourceFiles()...)
2216 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002217 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002218 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002219 // Support exported headers from a generated_sources dependency
2220 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002221 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002222 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002223 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002224 genRule.GeneratedSourceFiles()...)
2225 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002226 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002227 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002228 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002229 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002230 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002231 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2232 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002233 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002234 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jiyong Park74955042019-10-22 20:19:51 +09002235 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002236
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002237 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002238 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002239 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002240 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002241 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002242 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002243 files := genRule.GeneratedSourceFiles()
2244 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002245 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002246 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002247 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 -07002248 }
2249 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002250 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002251 }
Colin Crossca860ac2016-01-04 14:34:37 -08002252 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002253 return
2254 }
2255
Colin Crossfe17f6f2019-03-28 19:30:56 -07002256 if depTag == android.ProtoPluginDepTag {
2257 return
2258 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002259 if depTag == llndkImplDep {
2260 return
2261 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002262
Colin Crossd11fcda2017-10-23 17:59:01 -07002263 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002264 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2265 return
2266 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002267 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002268 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2269 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002270 return
2271 }
2272
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002273 // re-exporting flags
2274 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002275 // reusing objects only make sense for cc.Modules.
2276 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002277 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002278 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002279 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002280 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002281 return
2282 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002283 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002284
Jiyong Parke4bb9862019-02-01 00:31:10 +09002285 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002286 // staticVariants are a cc.Module specific concept.
2287 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002288 c.staticVariant = ccDep
2289 return
2290 }
2291 }
2292
Jooyung Han75568392020-03-20 04:29:24 +09002293 // For the dependency from platform to apex, use the latest stubs
2294 c.apexSdkVersion = android.FutureApiLevel
2295 if !c.IsForPlatform() {
2296 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2297 }
2298
2299 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2300 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2301 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2302 // (b/144430859)
2303 c.apexSdkVersion = android.FutureApiLevel
2304 }
2305
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002306 if depTag == staticUnwinderDepTag {
Jooyung Han75568392020-03-20 04:29:24 +09002307 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2308 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002309 depTag = StaticDepTag
2310 } else {
2311 return
2312 }
2313 }
2314
Ivan Lozano183a3212019-10-18 14:18:45 -07002315 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2316 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2317 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002318 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002319 if t, ok := depTag.(DependencyTag); ok {
2320 explicitlyVersioned = t.ExplicitlyVersioned
2321 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002322 depTag = t
2323 }
2324
Ivan Lozano183a3212019-10-18 14:18:45 -07002325 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002326 depIsStatic := false
2327 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002328 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002329 depIsStatic = true
2330 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002331 if ccDep.CcLibrary() && !depIsStatic {
2332 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002333 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002334 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002335 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002336
2337 var useThisDep bool
2338 if depIsStubs && explicitlyVersioned {
2339 // Always respect dependency to the versioned stubs (i.e. libX#10)
2340 useThisDep = true
2341 } else if !depHasStubs {
2342 // Use non-stub variant if that is the only choice
2343 // (i.e. depending on a lib without stubs.version property)
2344 useThisDep = true
2345 } else if c.IsForPlatform() {
2346 // If not building for APEX, use stubs only when it is from
2347 // an APEX (and not from platform)
2348 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002349 if c.bootstrap() {
2350 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002351 // always link to non-stub variant
2352 useThisDep = !depIsStubs
2353 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002354 for _, testFor := range c.TestFor() {
2355 // Another exception: if this module is bundled with an APEX, then
2356 // it is linked with the non-stub variant of a module in the APEX
2357 // as if this is part of the APEX.
2358 if android.DirectlyInApex(testFor, depName) {
2359 useThisDep = !depIsStubs
2360 break
2361 }
2362 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002363 } else {
2364 // If building for APEX, use stubs only when it is not from
2365 // the same APEX
2366 useThisDep = (depInSameApex != depIsStubs)
2367 }
2368
Jooyung Han03b51852020-02-26 22:45:42 +09002369 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2370 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002371 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002372 if err != nil {
2373 ctx.OtherModuleErrorf(dep, err.Error())
2374 return
2375 }
2376 if versionToUse != ccDep.StubsVersion() {
2377 useThisDep = false
2378 }
2379 }
2380
Jiyong Park25fc6a92018-11-18 18:02:45 +09002381 if !useThisDep {
2382 return // stop processing this dep
2383 }
2384 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002385 if c.UseVndk() {
2386 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2387 // by default, use current version of LLNDK
2388 versionToUse := ""
2389 versions := stubsVersionsFor(ctx.Config())[depName]
2390 if c.ApexName() != "" && len(versions) > 0 {
2391 // if this is for use_vendor apex && dep has stubsVersions
2392 // apply the same rule of apex sdk enforcement to choose right version
2393 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002394 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002395 if err != nil {
2396 ctx.OtherModuleErrorf(dep, err.Error())
2397 return
2398 }
2399 }
2400 if versionToUse != ccDep.StubsVersion() {
2401 return
2402 }
2403 }
2404 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002405
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002406 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2407
Ivan Lozano52767be2019-10-18 14:49:46 -07002408 // Exporting flags only makes sense for cc.Modules
2409 if _, ok := ccDep.(*Module); ok {
2410 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002411 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002412 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2413 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002414 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002415
Ivan Lozano52767be2019-10-18 14:49:46 -07002416 if t.ReexportFlags {
2417 reexportExporter(i)
2418 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2419 // Re-exported shared library headers must be included as well since they can help us with type information
2420 // about template instantiations (instantiated from their headers).
2421 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2422 // scripts.
2423 c.sabi.Properties.ReexportedIncludes = append(
2424 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2425 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002426 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002427 }
Logan Chienf3511742017-10-31 18:04:35 +08002428 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002429 }
2430
Colin Cross26c34ed2016-09-30 17:10:16 -07002431 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002432 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002433
Ivan Lozano52767be2019-10-18 14:49:46 -07002434 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002435 depFile := android.OptionalPath{}
2436
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002437 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002438 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002439 ptr = &depPaths.SharedLibs
2440 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002441 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002442 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002443
Jiyong Park64a44f22019-01-18 14:37:08 +09002444 case earlySharedDepTag:
2445 ptr = &depPaths.EarlySharedLibs
2446 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002447 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002448 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002449 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002450 ptr = &depPaths.LateSharedLibs
2451 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002452 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002453 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002454 ptr = nil
2455 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002456 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002457 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002458 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002459 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002460 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002461 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002462 return
2463 }
2464
Ivan Lozano52767be2019-10-18 14:49:46 -07002465 // Because the static library objects are included, this only makes sense
2466 // in the context of proper cc.Modules.
2467 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2468 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2469 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2470 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2471 for i := range missingDeps {
2472 missingDeps[i] += postfix
2473 }
2474 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002475 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002476 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2477 } else {
2478 ctx.ModuleErrorf(
2479 "non-cc.Modules cannot be included as whole static libraries.", depName)
2480 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002481 }
Colin Cross5950f382016-12-13 12:50:57 -08002482 case headerDepTag:
2483 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002484 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002485 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002486 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002487 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002488 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002489 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002490 case dynamicLinkerDepTag:
2491 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002492 }
2493
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002494 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002495 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002496 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002497 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002498 return
2499 }
2500
2501 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002502 // in static libraries act as if they were whole static libraries. The same goes for
2503 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002504 if c, ok := ccDep.(*Module); ok {
2505 staticLib := c.linker.(libraryInterface)
2506 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2507 staticLib.objs().coverageFiles...)
2508 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2509 staticLib.objs().sAbiDumpFiles...)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002510 } else if c, ok := ccDep.(LinkableInterface); ok {
2511 // Handle non-CC modules here
2512 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2513 c.CoverageFiles()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002514 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002515 }
2516
Colin Cross26c34ed2016-09-30 17:10:16 -07002517 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002518 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002519 if !ctx.Config().AllowMissingDependencies() {
2520 ctx.ModuleErrorf("module %q missing output file", depName)
2521 } else {
2522 ctx.AddMissingDependencies([]string{depName})
2523 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002524 return
2525 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002526 *ptr = append(*ptr, linkFile.Path())
2527 }
2528
Colin Crossc99deeb2016-04-11 15:06:20 -07002529 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002530 dep := depFile
2531 if !dep.Valid() {
2532 dep = linkFile
2533 }
2534 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002535 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002536
Inseob Kimeec88e12020-01-22 11:11:29 +09002537 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2538
2539 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002540 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002541 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002542 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002543 return libName
2544 }
2545
2546 makeLibName := func(depName string) string {
2547 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002548 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002549 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002550 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002551
Inseob Kimeec88e12020-01-22 11:11:29 +09002552 if c, ok := ccDep.(*Module); ok {
2553 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim752edec2020-03-14 01:30:34 +09002554 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002555 baseName := c.BaseModuleName()
Inseob Kim752edec2020-03-14 01:30:34 +09002556
2557 if c.IsVndk() {
2558 return baseName + ".vendor"
2559 }
2560
Inseob Kimeec88e12020-01-22 11:11:29 +09002561 if vendorSuffixModules[baseName] {
2562 return baseName + ".vendor"
2563 } else {
2564 return baseName
2565 }
2566 }
2567 }
2568
Yifan Hong1b3348d2020-01-21 15:53:22 -08002569 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002570 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2571 // core module instead.
2572 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002573 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002574 // The vendor module in Make will have been renamed to not conflict with the core
2575 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002576 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002577 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002578 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002579 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2580 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002581 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002582 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002583 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002584 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002585 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002586 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002587 }
Logan Chien43d34c32017-12-20 01:17:32 +08002588 }
2589
2590 // Export the shared libs to Make.
2591 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002592 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002593 if ccDep.CcLibrary() {
2594 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002595 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002596 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002597 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002598 c.Properties.ApexesProvidingSharedLibs = append(
2599 c.Properties.ApexesProvidingSharedLibs, an)
2600 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002601 }
2602 }
2603
Jiyong Park27b188b2017-07-18 13:23:39 +09002604 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002605 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002606 c.Properties.AndroidMkSharedLibs = append(
2607 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002608 // Record baseLibName for snapshots.
2609 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002610 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002611 c.Properties.AndroidMkSharedLibs = append(
2612 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002613 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002614 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002615 c.Properties.AndroidMkStaticLibs = append(
2616 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002617 case runtimeDepTag:
2618 c.Properties.AndroidMkRuntimeLibs = append(
2619 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002620 // Record baseLibName for snapshots.
2621 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002622 case wholeStaticDepTag:
2623 c.Properties.AndroidMkWholeStaticLibs = append(
2624 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Bill Peckhama46de702020-04-21 17:23:37 -07002625 case headerDepTag:
2626 c.Properties.AndroidMkHeaderLibs = append(
2627 c.Properties.AndroidMkHeaderLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002628 }
Colin Crossca860ac2016-01-04 14:34:37 -08002629 })
2630
Jeff Gaston294356f2017-09-27 17:05:30 -07002631 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002632 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002633
Colin Crossdd84e052017-05-17 13:44:16 -07002634 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002635 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002636 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2637 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002638 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002639 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002640 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2641 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002642 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002643 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002644 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002645
2646 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002647 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002648 }
Colin Crossdd84e052017-05-17 13:44:16 -07002649
Colin Crossca860ac2016-01-04 14:34:37 -08002650 return depPaths
2651}
2652
2653func (c *Module) InstallInData() bool {
2654 if c.installer == nil {
2655 return false
2656 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002657 return c.installer.inData()
2658}
2659
2660func (c *Module) InstallInSanitizerDir() bool {
2661 if c.installer == nil {
2662 return false
2663 }
2664 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002665 return true
2666 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002667 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002668}
2669
Yifan Hong1b3348d2020-01-21 15:53:22 -08002670func (c *Module) InstallInRamdisk() bool {
2671 return c.InRamdisk()
2672}
2673
Jiyong Parkf9332f12018-02-01 00:54:12 +09002674func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002675 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002676}
2677
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002678func (c *Module) SkipInstall() {
2679 if c.installer == nil {
2680 c.ModuleBase.SkipInstall()
2681 return
2682 }
2683 c.installer.skipInstall(c)
2684}
2685
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002686func (c *Module) HostToolPath() android.OptionalPath {
2687 if c.installer == nil {
2688 return android.OptionalPath{}
2689 }
2690 return c.installer.hostToolPath()
2691}
2692
Nan Zhangd4e641b2017-07-12 12:55:28 -07002693func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2694 return c.outputFile
2695}
2696
Colin Cross41955e82019-05-29 14:40:35 -07002697func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2698 switch tag {
2699 case "":
2700 if c.outputFile.Valid() {
2701 return android.Paths{c.outputFile.Path()}, nil
2702 }
2703 return android.Paths{}, nil
2704 default:
2705 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002706 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002707}
2708
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002709func (c *Module) static() bool {
2710 if static, ok := c.linker.(interface {
2711 static() bool
2712 }); ok {
2713 return static.static()
2714 }
2715 return false
2716}
2717
Jiyong Park379de2f2018-12-19 02:47:14 +09002718func (c *Module) staticBinary() bool {
2719 if static, ok := c.linker.(interface {
2720 staticBinary() bool
2721 }); ok {
2722 return static.staticBinary()
2723 }
2724 return false
2725}
2726
Jiyong Park1d1119f2019-07-29 21:27:18 +09002727func (c *Module) header() bool {
2728 if h, ok := c.linker.(interface {
2729 header() bool
2730 }); ok {
2731 return h.header()
2732 }
2733 return false
2734}
2735
Jooyung Han38002912019-05-16 04:01:54 +09002736func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002737 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002738 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2739 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002740 return "native:vndk"
2741 }
Jooyung Han38002912019-05-16 04:01:54 +09002742 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002743 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002744 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002745 if Bool(c.VendorProperties.Vendor_available) {
2746 return "native:vndk"
2747 }
2748 return "native:vndk_private"
2749 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002750 if c.inProduct() {
2751 return "native:product"
2752 }
Jooyung Han38002912019-05-16 04:01:54 +09002753 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002754 } else if c.InRamdisk() {
2755 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002756 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002757 return "native:recovery"
2758 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2759 return "native:ndk:none:none"
2760 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2761 //family, link := getNdkStlFamilyAndLinkType(c)
2762 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002763 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002764 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002765 } else {
2766 return "native:platform"
2767 }
2768}
2769
Jiyong Park9d452992018-10-03 00:38:19 +09002770// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002771// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002772func (c *Module) IsInstallableToApex() bool {
2773 if shared, ok := c.linker.(interface {
2774 shared() bool
2775 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002776 // Stub libs and prebuilt libs in a versioned SDK are not
2777 // installable to APEX even though they are shared libs.
2778 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002779 } else if _, ok := c.linker.(testPerSrc); ok {
2780 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002781 }
2782 return false
2783}
2784
Jiyong Parka90ca002019-10-07 15:47:24 +09002785func (c *Module) AvailableFor(what string) bool {
2786 if linker, ok := c.linker.(interface {
2787 availableFor(string) bool
2788 }); ok {
2789 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2790 } else {
2791 return c.ApexModuleBase.AvailableFor(what)
2792 }
2793}
2794
Jiyong Park62304bb2020-04-13 16:19:48 +09002795func (c *Module) TestFor() []string {
2796 if test, ok := c.linker.(interface {
2797 testFor() []string
2798 }); ok {
2799 return test.testFor()
2800 } else {
2801 return c.ApexModuleBase.TestFor()
2802 }
2803}
2804
Paul Duffin0cb37b92020-03-04 14:52:46 +00002805// Return true if the module is ever installable.
2806func (c *Module) EverInstallable() bool {
2807 return c.installer != nil &&
2808 // Check to see whether the module is actually ever installable.
2809 c.installer.everInstallable()
2810}
2811
Inseob Kim1f086e22019-05-09 13:29:15 +09002812func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002813 ret := c.EverInstallable() &&
2814 // Check to see whether the module has been configured to not be installed.
2815 proptools.BoolDefault(c.Properties.Installable, true) &&
2816 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002817
2818 // The platform variant doesn't need further condition. Apex variants however might not
2819 // be installable because it will likely to be included in the APEX and won't appear
2820 // in the system partition.
2821 if c.IsForPlatform() {
2822 return ret
2823 }
2824
2825 // Special case for modules that are configured to be installed to /data, which includes
2826 // test modules. For these modules, both APEX and non-APEX variants are considered as
2827 // installable. This is because even the APEX variants won't be included in the APEX, but
2828 // will anyway be installed to /data/*.
2829 // See b/146995717
2830 if c.InstallInData() {
2831 return ret
2832 }
2833
2834 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002835}
2836
Logan Chien41eabe62019-04-10 13:33:58 +08002837func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2838 if c.linker != nil {
2839 if library, ok := c.linker.(*libraryDecorator); ok {
2840 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2841 }
2842 }
2843}
2844
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002845func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002846 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002847 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002848 if cc.HasStubsVariants() {
2849 if depTag.Shared && depTag.Library {
2850 // dynamic dep to a stubs lib crosses APEX boundary
2851 return false
2852 }
2853 if IsRuntimeDepTag(depTag) {
2854 // runtime dep to a stubs lib also crosses APEX boundary
2855 return false
2856 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002857 }
2858 if depTag.FromStatic {
2859 // shared_lib dependency from a static lib is considered as crossing
2860 // the APEX boundary because the dependency doesn't actually is
2861 // linked; the dependency is used only during the compilation phase.
2862 return false
2863 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002864 }
2865 }
2866 return true
2867}
2868
Colin Cross2ba19d92015-05-07 15:44:20 -07002869//
Colin Crosscfad1192015-11-02 16:43:11 -08002870// Defaults
2871//
Colin Crossca860ac2016-01-04 14:34:37 -08002872type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002873 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002874 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002875 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002876}
2877
Patrice Arrudac249c712019-03-19 17:00:29 -07002878// cc_defaults provides a set of properties that can be inherited by other cc
2879// modules. A module can use the properties from a cc_defaults using
2880// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2881// merged (when possible) by prepending the default module's values to the
2882// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002883func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002884 return DefaultsFactory()
2885}
2886
Colin Cross36242852017-06-23 15:06:31 -07002887func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002888 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002889
Colin Cross36242852017-06-23 15:06:31 -07002890 module.AddProperties(props...)
2891 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002892 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002893 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002894 &BaseCompilerProperties{},
2895 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002896 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002897 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002898 &StaticProperties{},
2899 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002900 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002901 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002902 &TestProperties{},
2903 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002904 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002905 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002906 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002907 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002908 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002909 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002910 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002911 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002912 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002913 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002914 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002915 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002916 )
Colin Crosscfad1192015-11-02 16:43:11 -08002917
Jooyung Hancc372c52019-09-25 15:18:44 +09002918 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002919
2920 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002921}
2922
Jiyong Park6a43f042017-10-12 23:05:00 +09002923func squashVendorSrcs(m *Module) {
2924 if lib, ok := m.compiler.(*libraryDecorator); ok {
2925 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2926 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2927
2928 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2929 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2930 }
2931}
2932
Jiyong Parkf9332f12018-02-01 00:54:12 +09002933func squashRecoverySrcs(m *Module) {
2934 if lib, ok := m.compiler.(*libraryDecorator); ok {
2935 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2936 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2937
2938 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2939 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2940 }
2941}
2942
Colin Cross7228ecd2019-11-18 16:00:16 -08002943var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002944
Colin Cross7228ecd2019-11-18 16:00:16 -08002945func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002946 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002947 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002948 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002949
2950 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002951 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002952 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002953 }
Logan Chienf3511742017-10-31 18:04:35 +08002954
2955 if vndkdep := m.vndkdep; vndkdep != nil {
2956 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09002957 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002958 if !vndkdep.isVndkExt() {
2959 mctx.PropertyErrorf("vndk",
2960 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09002961 } else if m.VendorProperties.Vendor_available != nil {
2962 mctx.PropertyErrorf("vendor_available",
2963 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002964 }
2965 } else {
2966 if vndkdep.isVndkExt() {
2967 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09002968 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002969 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002970 }
2971 if m.VendorProperties.Vendor_available == nil {
2972 mctx.PropertyErrorf("vndk",
2973 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002974 }
2975 }
2976 } else {
2977 if vndkdep.isVndkSp() {
2978 mctx.PropertyErrorf("vndk",
2979 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002980 }
2981 if vndkdep.isVndkExt() {
2982 mctx.PropertyErrorf("vndk",
2983 "must set `enabled: true` to set `extends: %q`",
2984 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002985 }
Justin Yun8effde42017-06-23 19:24:43 +09002986 }
2987 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002988
Jiyong Parkf9332f12018-02-01 00:54:12 +09002989 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002990 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002991 var recoveryVariantNeeded bool = false
2992
Inseob Kim64c43952019-08-26 16:52:35 +09002993 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002994 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002995
2996 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002997 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2998 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2999 if boardVndkVersion == "current" {
3000 boardVndkVersion = platformVndkVersion
3001 }
3002 if productVndkVersion == "current" {
3003 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09003004 }
3005
Justin Yun5f7f7e82019-11-18 19:52:14 +09003006 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003007 // If the device isn't compiling against the VNDK, we always
3008 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003009 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003010 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003011 // LL-NDK stubs only exist in the vendor and product variants,
3012 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09003013 vendorVariants = append(vendorVariants,
3014 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003015 boardVndkVersion,
3016 )
3017 productVariants = append(productVariants,
3018 platformVndkVersion,
3019 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003020 )
Jiyong Park2a454122017-10-19 15:59:33 +09003021 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
3022 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09003023 vendorVariants = append(vendorVariants,
3024 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003025 boardVndkVersion,
3026 )
3027 productVariants = append(productVariants,
3028 platformVndkVersion,
3029 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003030 )
Inseob Kimeec88e12020-01-22 11:11:29 +09003031 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09003032 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
3033 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09003034 if snapshot, ok := m.linker.(interface {
3035 version() string
3036 }); ok {
3037 vendorVariants = append(vendorVariants, snapshot.version())
3038 } else {
3039 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
3040 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09003041 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003042 // This will be available in /system, /vendor and /product
3043 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003044 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09003045 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09003046 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09003047 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
3048 // code is PLATFORM_VNDK_VERSION.
3049 // On the other hand, vendor_available modules which are not VNDK should
3050 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09003051 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09003052 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003053 vendorVariants = append(vendorVariants, boardVndkVersion)
3054 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09003055 }
Logan Chienf3511742017-10-31 18:04:35 +08003056 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09003057 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09003058 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003059 } else {
3060 // This is either in /system (or similar: /data), or is a
3061 // modules built with the NDK. Modules built with the NDK
3062 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003063 coreVariantNeeded = true
3064 }
3065
Justin Yun5f7f7e82019-11-18 19:52:14 +09003066 if boardVndkVersion != "" && productVndkVersion != "" {
3067 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
3068 // The module has "product_specific: true" that does not create core variant.
3069 coreVariantNeeded = false
3070 productVariants = append(productVariants, productVndkVersion)
3071 }
3072 } else {
3073 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
3074 // restriction to use system libs.
3075 // No product variants defined in this case.
3076 productVariants = []string{}
3077 }
3078
Yifan Hong1b3348d2020-01-21 15:53:22 -08003079 if Bool(m.Properties.Ramdisk_available) {
3080 ramdiskVariantNeeded = true
3081 }
3082
3083 if m.ModuleBase.InstallInRamdisk() {
3084 ramdiskVariantNeeded = true
3085 coreVariantNeeded = false
3086 }
3087
Jiyong Parkf9332f12018-02-01 00:54:12 +09003088 if Bool(m.Properties.Recovery_available) {
3089 recoveryVariantNeeded = true
3090 }
3091
3092 if m.ModuleBase.InstallInRecovery() {
3093 recoveryVariantNeeded = true
3094 coreVariantNeeded = false
3095 }
3096
Inseob Kim64c43952019-08-26 16:52:35 +09003097 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003098 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3099 }
3100
3101 for _, variant := range android.FirstUniqueStrings(productVariants) {
3102 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003103 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003104
Yifan Hong1b3348d2020-01-21 15:53:22 -08003105 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003106 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3107 m.Properties.CoreVariantNeeded = coreVariantNeeded
3108}
3109
3110func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3111 return c.Properties.CoreVariantNeeded
3112}
3113
Yifan Hong1b3348d2020-01-21 15:53:22 -08003114func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3115 return c.Properties.RamdiskVariantNeeded
3116}
3117
Colin Cross7228ecd2019-11-18 16:00:16 -08003118func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3119 return c.Properties.RecoveryVariantNeeded
3120}
3121
3122func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003123 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003124}
3125
3126func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3127 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003128 if variant == android.RamdiskVariation {
3129 m.MakeAsPlatform()
3130 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003131 m.MakeAsPlatform()
3132 squashRecoverySrcs(m)
3133 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003134 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003135 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3136 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003137
3138 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3139 // Hide other vendor variants to avoid collision.
3140 vndkVersion := ctx.DeviceConfig().VndkVersion()
3141 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3142 m.Properties.HideFromMake = true
3143 m.SkipInstall()
3144 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003145 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3146 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3147 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3148 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003149 }
3150}
3151
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003152func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003153 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003154 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3155 }
Colin Cross6510f912017-11-29 00:27:14 -08003156 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003157}
3158
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003159func kytheExtractAllFactory() android.Singleton {
3160 return &kytheExtractAllSingleton{}
3161}
3162
3163type kytheExtractAllSingleton struct {
3164}
3165
3166func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3167 var xrefTargets android.Paths
3168 ctx.VisitAllModules(func(module android.Module) {
3169 if ccModule, ok := module.(xref); ok {
3170 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3171 }
3172 })
3173 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3174 if len(xrefTargets) > 0 {
3175 ctx.Build(pctx, android.BuildParams{
3176 Rule: blueprint.Phony,
3177 Output: android.PathForPhony(ctx, "xref_cxx"),
3178 Inputs: xrefTargets,
3179 //Default: true,
3180 })
3181 }
3182}
3183
Colin Cross06a931b2015-10-28 17:23:31 -07003184var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003185var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003186var BoolPtr = proptools.BoolPtr
3187var String = proptools.String
3188var StringPtr = proptools.StringPtr