blob: 31b381a9d96a527abab23be27d0707a356e2028e [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 Cross01fd7cc2020-02-19 16:54:04 -080045 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 Nguyen6f641c12020-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 Cross01fd7cc2020-02-19 16:54:04 -0800212 // 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 Hanba118122020-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 Cross01fd7cc2020-02-19 16:54:04 -0800219 // 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"`
226 HideFromMake bool `blueprint:"mutated"`
227 PreventInstall bool `blueprint:"mutated"`
228 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700229
Justin Yun5f7f7e82019-11-18 19:52:14 +0900230 ImageVariationPrefix string `blueprint:"mutated"`
231 VndkVersion string `blueprint:"mutated"`
232 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800233
234 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
235 // file
236 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900237
Yifan Hong1b3348d2020-01-21 15:53:22 -0800238 // Make this module available when building for ramdisk
239 Ramdisk_available *bool
240
Jiyong Parkf9332f12018-02-01 00:54:12 +0900241 // Make this module available when building for recovery
242 Recovery_available *bool
243
Colin Crossae6c5202019-11-20 13:35:50 -0800244 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800245 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800246 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800247 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900248 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900249
250 // Allows this module to use non-APEX version of libraries. Useful
251 // for building binaries that are started before APEXes are activated.
252 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900253
254 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
255 // see soong/cc/config/vndk.go
256 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900257
258 // Used by vendor snapshot to record dependencies from snapshot modules.
259 SnapshotSharedLibs []string `blueprint:"mutated"`
260 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffinf51768a2020-03-04 14:52:46 +0000261
262 Installable *bool
Colin Cross01fd7cc2020-02-19 16:54:04 -0800263
264 // Set by factories of module types that can only be referenced from variants compiled against
265 // the SDK.
266 AlwaysSdk bool `blueprint:"mutated"`
267
268 // Variant is an SDK variant created by sdkMutator
269 IsSdkVariant bool `blueprint:"mutated"`
270 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
271 // variant to have a ".sdk" suffix.
272 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700273}
274
275type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900276 // whether this module should be allowed to be directly depended by other
277 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900278 // In addition, this module should be allowed to be directly depended by
279 // product modules with `product_specific: true`.
280 // If set to true, three variants will be built separately, one like
281 // normal, another limited to the set of libraries and headers
282 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700283 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900284 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700285 // so it shouldn't have any unversioned runtime dependencies, or
286 // make assumptions about the system that may not be true in the
287 // future.
288 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900289 // If set to false, this module becomes inaccessible from /vendor or /product
290 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900291 //
292 // Default value is true when vndk: {enabled: true} or vendor: true.
293 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700294 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900295 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700296 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900297
298 // whether this module is capable of being loaded with other instance
299 // (possibly an older version) of the same module in the same process.
300 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
301 // can be double loaded in a vendor process if the library is also a
302 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
303 // explicitly marked as `double_loadable: true` by the owner, or the dependency
304 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
305 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800306}
307
Colin Crossca860ac2016-01-04 14:34:37 -0800308type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800309 static() bool
310 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900311 header() bool
Inseob Kim4d8d8fe2020-06-01 21:53:49 +0900312 binary() bool
Inseob Kim502679e2020-06-01 23:23:05 +0900313 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700314 toolchain() config.Toolchain
Jooyung Han61c41542020-03-07 03:45:53 +0900315 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700316 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800317 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700318 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800319 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900320 isLlndk(config android.Config) bool
321 isLlndkPublic(config android.Config) bool
322 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900323 isVndk() bool
324 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800325 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900326 inProduct() bool
327 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800328 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900329 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800330 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700331 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700332 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800333 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800334 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800335 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800336 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800337 isForPlatform() bool
Colin Cross74385712020-08-13 11:24:56 -0700338 apexVariationName() string
Jooyung Han61c41542020-03-07 03:45:53 +0900339 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900340 hasStubsVariants() bool
341 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900342 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800343 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700344 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800345}
346
347type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700348 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800349 ModuleContextIntf
350}
351
352type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700353 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800354 ModuleContextIntf
355}
356
Colin Cross37047f12016-12-13 17:06:13 -0800357type DepsContext interface {
358 android.BottomUpMutatorContext
359 ModuleContextIntf
360}
361
Colin Crossca860ac2016-01-04 14:34:37 -0800362type feature interface {
363 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800364 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800365 flags(ctx ModuleContext, flags Flags) Flags
366 props() []interface{}
367}
368
369type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700370 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800371 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800372 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700373 compilerProps() []interface{}
374
Colin Cross76fada02016-07-27 10:31:13 -0700375 appendCflags([]string)
376 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700377 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800378}
379
380type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700381 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800382 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700383 linkerFlags(ctx ModuleContext, flags Flags) Flags
384 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800385 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700386
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700387 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700388 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900389 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700390
391 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900392 coverageOutputFilePath() android.OptionalPath
Paul Duffin206433a2020-03-06 12:30:43 +0000393
394 // Get the deps that have been explicitly specified in the properties.
395 // Only updates the
396 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
397}
398
399type specifiedDeps struct {
400 sharedLibs []string
Martin Stjernholmbddfbc42020-03-24 01:19:52 +0000401 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800402}
403
404type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700405 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700406 install(ctx ModuleContext, path android.Path)
Paul Duffinf51768a2020-03-04 14:52:46 +0000407 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800408 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700409 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700410 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900411 relativeInstallPath() string
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +0100412 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800413}
414
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800415type xref interface {
416 XrefCcFiles() android.Paths
417}
418
Colin Crossc99deeb2016-04-11 15:06:20 -0700419var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700420 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
421 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
422 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
423 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
424 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800425 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700426 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
427 headerDepTag = DependencyTag{Name: "header", Library: true}
428 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
429 genSourceDepTag = DependencyTag{Name: "gen source"}
430 genHeaderDepTag = DependencyTag{Name: "gen header"}
431 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
432 objDepTag = DependencyTag{Name: "obj"}
433 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
434 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
435 reuseObjTag = DependencyTag{Name: "reuse objects"}
436 staticVariantTag = DependencyTag{Name: "static variant"}
437 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
438 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
439 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
440 runtimeDepTag = DependencyTag{Name: "runtime lib"}
441 coverageDepTag = DependencyTag{Name: "coverage"}
442 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700443)
444
Roland Levillainf89cd092019-07-29 16:22:59 +0100445func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700446 ccDepTag, ok := depTag.(DependencyTag)
447 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100448}
449
450func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700451 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100452 return ok && ccDepTag == runtimeDepTag
453}
454
455func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700456 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100457 return ok && ccDepTag == testPerSrcDepTag
458}
459
Colin Crossca860ac2016-01-04 14:34:37 -0800460// Module contains the properties and members used by all C/C++ module types, and implements
461// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
462// to construct the output file. Behavior can be customized with a Customizer interface
463type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700464 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700465 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900466 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900467 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700468
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700469 Properties BaseProperties
470 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700471
Colin Crossca860ac2016-01-04 14:34:37 -0800472 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700473 hod android.HostOrDeviceSupported
474 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700475
Paul Duffina0843f62019-12-13 19:50:38 +0000476 // Allowable SdkMemberTypes of this module type.
477 sdkMemberTypes []android.SdkMemberType
478
Colin Crossca860ac2016-01-04 14:34:37 -0800479 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700480 features []feature
481 compiler compiler
482 linker linker
483 installer installer
484 stl *stl
485 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800486 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800487 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900488 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700489 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700490 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800491
Colin Cross635c3b02016-05-18 15:37:25 -0700492 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800493
Colin Crossb98c8b02016-07-29 13:44:28 -0700494 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700495
496 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800497
498 // Flags used to compile this module
499 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700500
501 // 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 -0800502 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700503 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800504 depsInLinkOrder android.Paths
505
506 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700507 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900508
509 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800510 // Kythe (source file indexer) paths for this compilation module
511 kytheFiles android.Paths
Jooyung Han74066602020-03-20 04:29:24 +0900512
513 // For apex variants, this is set as apex.min_sdk_version
514 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700515}
516
Ivan Lozano52767be2019-10-18 14:49:46 -0700517func (c *Module) Toc() android.OptionalPath {
518 if c.linker != nil {
519 if library, ok := c.linker.(libraryInterface); ok {
520 return library.toc()
521 }
522 }
523 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
524}
525
526func (c *Module) ApiLevel() string {
527 if c.linker != nil {
528 if stub, ok := c.linker.(*stubDecorator); ok {
529 return stub.properties.ApiLevel
530 }
531 }
532 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
533}
534
535func (c *Module) Static() bool {
536 if c.linker != nil {
537 if library, ok := c.linker.(libraryInterface); ok {
538 return library.static()
539 }
540 }
541 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
542}
543
544func (c *Module) Shared() bool {
545 if c.linker != nil {
546 if library, ok := c.linker.(libraryInterface); ok {
547 return library.shared()
548 }
549 }
550 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
551}
552
553func (c *Module) SelectedStl() string {
Colin Cross01fd7cc2020-02-19 16:54:04 -0800554 if c.stl != nil {
555 return c.stl.Properties.SelectedStl
556 }
557 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700558}
559
560func (c *Module) ToolchainLibrary() bool {
561 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
562 return true
563 }
564 return false
565}
566
567func (c *Module) NdkPrebuiltStl() bool {
568 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
569 return true
570 }
571 return false
572}
573
574func (c *Module) StubDecorator() bool {
575 if _, ok := c.linker.(*stubDecorator); ok {
576 return true
577 }
578 return false
579}
580
581func (c *Module) SdkVersion() string {
582 return String(c.Properties.Sdk_version)
583}
584
Artur Satayev388d39b2020-04-27 18:53:18 +0100585func (c *Module) MinSdkVersion() string {
586 return String(c.Properties.Min_sdk_version)
587}
588
Colin Cross01fd7cc2020-02-19 16:54:04 -0800589func (c *Module) AlwaysSdk() bool {
590 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
591}
592
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800593func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700594 if c.linker != nil {
595 if library, ok := c.linker.(exportedFlagsProducer); ok {
596 return library.exportedDirs()
597 }
598 }
599 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
600}
601
602func (c *Module) HasStaticVariant() bool {
603 if c.staticVariant != nil {
604 return true
605 }
606 return false
607}
608
609func (c *Module) GetStaticVariant() LinkableInterface {
610 return c.staticVariant
611}
612
613func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
614 c.depsInLinkOrder = depsInLinkOrder
615}
616
617func (c *Module) GetDepsInLinkOrder() []android.Path {
618 return c.depsInLinkOrder
619}
620
621func (c *Module) StubsVersions() []string {
622 if c.linker != nil {
623 if library, ok := c.linker.(*libraryDecorator); ok {
624 return library.Properties.Stubs.Versions
625 }
626 }
627 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
628}
629
630func (c *Module) CcLibrary() bool {
631 if c.linker != nil {
632 if _, ok := c.linker.(*libraryDecorator); ok {
633 return true
634 }
635 }
636 return false
637}
638
639func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700640 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700641 return true
642 }
643 return false
644}
645
Ivan Lozano2b262972019-11-21 12:30:50 -0800646func (c *Module) NonCcVariants() bool {
647 return false
648}
649
Ivan Lozano183a3212019-10-18 14:18:45 -0700650func (c *Module) SetBuildStubs() {
651 if c.linker != nil {
652 if library, ok := c.linker.(*libraryDecorator); ok {
653 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700654 c.Properties.HideFromMake = true
655 c.sanitize = nil
656 c.stl = nil
657 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700658 return
659 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900660 if _, ok := c.linker.(*llndkStubDecorator); ok {
661 c.Properties.HideFromMake = true
662 return
663 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700664 }
665 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
666}
667
Ivan Lozano52767be2019-10-18 14:49:46 -0700668func (c *Module) BuildStubs() bool {
669 if c.linker != nil {
670 if library, ok := c.linker.(*libraryDecorator); ok {
671 return library.buildStubs()
672 }
673 }
674 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
675}
676
Ivan Lozano183a3212019-10-18 14:18:45 -0700677func (c *Module) SetStubsVersions(version string) {
678 if c.linker != nil {
679 if library, ok := c.linker.(*libraryDecorator); ok {
680 library.MutatedProperties.StubsVersion = version
681 return
682 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900683 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
684 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
685 return
686 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700687 }
688 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
689}
690
Jooyung Han0c4e0162020-02-26 22:45:42 +0900691func (c *Module) StubsVersion() string {
692 if c.linker != nil {
693 if library, ok := c.linker.(*libraryDecorator); ok {
694 return library.MutatedProperties.StubsVersion
695 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900696 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
697 return llndk.libraryDecorator.MutatedProperties.StubsVersion
698 }
Jooyung Han0c4e0162020-02-26 22:45:42 +0900699 }
700 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
701}
702
Ivan Lozano183a3212019-10-18 14:18:45 -0700703func (c *Module) SetStatic() {
704 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700705 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700706 library.setStatic()
707 return
708 }
709 }
710 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
711}
712
713func (c *Module) SetShared() {
714 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700715 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700716 library.setShared()
717 return
718 }
719 }
720 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
721}
722
723func (c *Module) BuildStaticVariant() bool {
724 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700725 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700726 return library.buildStatic()
727 }
728 }
729 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
730}
731
732func (c *Module) BuildSharedVariant() bool {
733 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700734 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700735 return library.buildShared()
736 }
737 }
738 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
739}
740
741func (c *Module) Module() android.Module {
742 return c
743}
744
Jiyong Parkc20eee32018-09-05 22:36:17 +0900745func (c *Module) OutputFile() android.OptionalPath {
746 return c.outputFile
747}
748
Ivan Lozano183a3212019-10-18 14:18:45 -0700749var _ LinkableInterface = (*Module)(nil)
750
Jiyong Park719b4462019-01-13 00:39:51 +0900751func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900752 if c.linker != nil {
753 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900754 }
755 return nil
756}
757
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900758func (c *Module) CoverageOutputFile() android.OptionalPath {
759 if c.linker != nil {
760 return c.linker.coverageOutputFilePath()
761 }
762 return android.OptionalPath{}
763}
764
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900765func (c *Module) RelativeInstallPath() string {
766 if c.installer != nil {
767 return c.installer.relativeInstallPath()
768 }
769 return ""
770}
771
Jooyung Han344d5432019-08-23 11:17:39 +0900772func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900773 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900774}
775
Colin Cross36242852017-06-23 15:06:31 -0700776func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700777 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800778 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700779 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800780 }
781 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700782 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800783 }
784 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700785 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800786 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700787 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700788 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700789 }
Colin Cross16b23492016-01-06 14:41:07 -0800790 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700791 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800792 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800793 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700794 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800795 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800796 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700797 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800798 }
Justin Yun8effde42017-06-23 19:24:43 +0900799 if c.vndkdep != nil {
800 c.AddProperties(c.vndkdep.props()...)
801 }
Stephen Craneba090d12017-05-09 15:44:35 -0700802 if c.lto != nil {
803 c.AddProperties(c.lto.props()...)
804 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700805 if c.pgo != nil {
806 c.AddProperties(c.pgo.props()...)
807 }
Colin Crossca860ac2016-01-04 14:34:37 -0800808 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700809 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800810 }
Colin Crossc472d572015-03-17 15:06:21 -0700811
Colin Crossa9d8bee2018-10-02 13:59:46 -0700812 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
813 switch class {
814 case android.Device:
815 return ctx.Config().DevicePrefer32BitExecutables()
816 case android.HostCross:
817 // Windows builds always prefer 32-bit
818 return true
819 default:
820 return false
821 }
822 })
Colin Cross36242852017-06-23 15:06:31 -0700823 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900824 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900825 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900826 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900827
Colin Cross36242852017-06-23 15:06:31 -0700828 return c
Colin Crossc472d572015-03-17 15:06:21 -0700829}
830
Colin Crossb916a382016-07-29 17:28:03 -0700831// Returns true for dependency roots (binaries)
832// TODO(ccross): also handle dlopenable libraries
833func (c *Module) isDependencyRoot() bool {
834 if root, ok := c.linker.(interface {
835 isDependencyRoot() bool
836 }); ok {
837 return root.isDependencyRoot()
838 }
839 return false
840}
841
Justin Yun5f7f7e82019-11-18 19:52:14 +0900842// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
843// "product" and "vendor" variant modules return true for this function.
844// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
845// "soc_specific: true" and more vendor installed modules are included here.
846// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
847// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700848func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900849 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700850}
851
Colin Cross01fd7cc2020-02-19 16:54:04 -0800852func (c *Module) canUseSdk() bool {
853 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
854}
855
856func (c *Module) UseSdk() bool {
857 if c.canUseSdk() {
858 return String(c.Properties.Sdk_version) != ""
859 }
860 return false
861}
862
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800863func (c *Module) isCoverageVariant() bool {
864 return c.coverage.Properties.IsCoverageVariant
865}
866
Peter Collingbournead84f972019-12-17 16:46:18 -0800867func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800868 return inList(c.Name(), ndkMigratedLibs)
869}
870
Inseob Kim9516ee92019-05-09 10:56:13 +0900871func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800872 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900873 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800874}
875
Inseob Kim9516ee92019-05-09 10:56:13 +0900876func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800877 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900878 name := c.BaseModuleName()
879 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800880}
881
Inseob Kim9516ee92019-05-09 10:56:13 +0900882func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800883 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900884 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800885}
886
Ivan Lozano52767be2019-10-18 14:49:46 -0700887func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800888 if vndkdep := c.vndkdep; vndkdep != nil {
889 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900890 }
891 return false
892}
893
Yi Kong7e53c572018-02-14 18:16:12 +0800894func (c *Module) isPgoCompile() bool {
895 if pgo := c.pgo; pgo != nil {
896 return pgo.Properties.PgoCompile
897 }
898 return false
899}
900
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800901func (c *Module) isNDKStubLibrary() bool {
902 if _, ok := c.compiler.(*stubDecorator); ok {
903 return true
904 }
905 return false
906}
907
Logan Chienf3511742017-10-31 18:04:35 +0800908func (c *Module) isVndkSp() bool {
909 if vndkdep := c.vndkdep; vndkdep != nil {
910 return vndkdep.isVndkSp()
911 }
912 return false
913}
914
915func (c *Module) isVndkExt() bool {
916 if vndkdep := c.vndkdep; vndkdep != nil {
917 return vndkdep.isVndkExt()
918 }
919 return false
920}
921
Ivan Lozano52767be2019-10-18 14:49:46 -0700922func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900923 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800924}
925
Logan Chienf3511742017-10-31 18:04:35 +0800926func (c *Module) getVndkExtendsModuleName() string {
927 if vndkdep := c.vndkdep; vndkdep != nil {
928 return vndkdep.getVndkExtendsModuleName()
929 }
930 return ""
931}
932
Justin Yun5f7f7e82019-11-18 19:52:14 +0900933// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900934// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700935func (c *Module) HasVendorVariant() bool {
936 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900937}
938
Justin Yun5f7f7e82019-11-18 19:52:14 +0900939const (
940 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
941 // against the VNDK.
942 VendorVariationPrefix = "vendor."
943
944 // ProductVariationPrefix is the variant prefix used for /product code that compiles
945 // against the VNDK.
946 ProductVariationPrefix = "product."
947)
948
949// Returns true if the module is "product" variant. Usually these modules are installed in /product
950func (c *Module) inProduct() bool {
951 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
952}
953
954// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
955func (c *Module) inVendor() bool {
956 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
957}
958
Yifan Hong1b3348d2020-01-21 15:53:22 -0800959func (c *Module) InRamdisk() bool {
960 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
961}
962
Ivan Lozano52767be2019-10-18 14:49:46 -0700963func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800964 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900965}
966
Yifan Hong1b3348d2020-01-21 15:53:22 -0800967func (c *Module) OnlyInRamdisk() bool {
968 return c.ModuleBase.InstallInRamdisk()
969}
970
Ivan Lozano52767be2019-10-18 14:49:46 -0700971func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900972 return c.ModuleBase.InstallInRecovery()
973}
974
Jiyong Park25fc6a92018-11-18 18:02:45 +0900975func (c *Module) IsStubs() bool {
976 if library, ok := c.linker.(*libraryDecorator); ok {
977 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900978 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
979 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900980 }
981 return false
982}
983
984func (c *Module) HasStubsVariants() bool {
985 if library, ok := c.linker.(*libraryDecorator); ok {
986 return len(library.Properties.Stubs.Versions) > 0
987 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700988 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
989 return len(library.Properties.Stubs.Versions) > 0
990 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900991 return false
992}
993
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900994func (c *Module) bootstrap() bool {
995 return Bool(c.Properties.Bootstrap)
996}
997
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700998func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700999 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1000 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1001 return false
1002 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001003 return c.linker != nil && c.linker.nativeCoverage()
1004}
1005
Inseob Kim8471cda2019-11-15 09:59:12 +09001006func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim502679e2020-06-01 23:23:05 +09001007 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1008 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001009 }
1010 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001011}
1012
Jiyong Park73c54ee2019-10-22 20:31:18 +09001013func (c *Module) ExportedIncludeDirs() android.Paths {
1014 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1015 return flagsProducer.exportedDirs()
1016 }
Jiyong Park232e7852019-11-04 12:23:40 +09001017 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001018}
1019
1020func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1021 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1022 return flagsProducer.exportedSystemDirs()
1023 }
Jiyong Park232e7852019-11-04 12:23:40 +09001024 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001025}
1026
1027func (c *Module) ExportedFlags() []string {
1028 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1029 return flagsProducer.exportedFlags()
1030 }
Jiyong Park232e7852019-11-04 12:23:40 +09001031 return nil
1032}
1033
1034func (c *Module) ExportedDeps() android.Paths {
1035 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1036 return flagsProducer.exportedDeps()
1037 }
1038 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001039}
1040
Inseob Kimd110f872019-12-06 13:15:38 +09001041func (c *Module) ExportedGeneratedHeaders() android.Paths {
1042 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1043 return flagsProducer.exportedGeneratedHeaders()
1044 }
1045 return nil
1046}
1047
Jiyong Parkf1194352019-02-25 11:05:47 +09001048func isBionic(name string) bool {
1049 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001050 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001051 return true
1052 }
1053 return false
1054}
1055
Martin Stjernholm279de572019-09-10 23:18:20 +01001056func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001057 if name == "libclang_rt.hwasan-aarch64-android" {
1058 return inList("hwaddress", config.SanitizeDevice())
1059 }
1060 return isBionic(name)
1061}
1062
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001063func (c *Module) XrefCcFiles() android.Paths {
1064 return c.kytheFiles
1065}
1066
Colin Crossca860ac2016-01-04 14:34:37 -08001067type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001068 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001069 moduleContextImpl
1070}
1071
Colin Cross37047f12016-12-13 17:06:13 -08001072type depsContext struct {
1073 android.BottomUpMutatorContext
1074 moduleContextImpl
1075}
1076
Colin Crossca860ac2016-01-04 14:34:37 -08001077type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001078 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001079 moduleContextImpl
1080}
1081
Justin Yun5f7f7e82019-11-18 19:52:14 +09001082func (ctx *moduleContext) ProductSpecific() bool {
1083 return ctx.ModuleContext.ProductSpecific() ||
1084 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1085}
1086
Jiyong Park2db76922017-11-08 16:03:48 +09001087func (ctx *moduleContext) SocSpecific() bool {
1088 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001089 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001090}
1091
Colin Crossca860ac2016-01-04 14:34:37 -08001092type moduleContextImpl struct {
1093 mod *Module
1094 ctx BaseModuleContext
1095}
1096
Colin Crossb98c8b02016-07-29 13:44:28 -07001097func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001098 return ctx.mod.toolchain(ctx.ctx)
1099}
1100
1101func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001102 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001103}
1104
1105func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001106 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001107}
1108
Jiyong Park1d1119f2019-07-29 21:27:18 +09001109func (ctx *moduleContextImpl) header() bool {
1110 return ctx.mod.header()
1111}
1112
Inseob Kim4d8d8fe2020-06-01 21:53:49 +09001113func (ctx *moduleContextImpl) binary() bool {
1114 return ctx.mod.binary()
1115}
1116
Inseob Kim502679e2020-06-01 23:23:05 +09001117func (ctx *moduleContextImpl) object() bool {
1118 return ctx.mod.object()
1119}
1120
Jooyung Han61c41542020-03-07 03:45:53 +09001121func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Cross01fd7cc2020-02-19 16:54:04 -08001122 return ctx.mod.canUseSdk()
Jooyung Han61c41542020-03-07 03:45:53 +09001123}
1124
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001125func (ctx *moduleContextImpl) useSdk() bool {
Colin Cross01fd7cc2020-02-19 16:54:04 -08001126 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001127}
1128
1129func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001130 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001131 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001132 vndkVer := ctx.mod.VndkVersion()
Jooyung Han424175d2020-04-08 09:22:26 +09001133 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001134 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001135 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001136 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001137 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001138 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001139 }
1140 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001141}
1142
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001143func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001144 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001145}
Justin Yun8effde42017-06-23 19:24:43 +09001146
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001147func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001148 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001149}
1150
Inseob Kim9516ee92019-05-09 10:56:13 +09001151func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1152 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001153}
1154
Inseob Kim9516ee92019-05-09 10:56:13 +09001155func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1156 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001157}
1158
Inseob Kim9516ee92019-05-09 10:56:13 +09001159func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1160 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001161}
1162
Logan Chienf3511742017-10-31 18:04:35 +08001163func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001164 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001165}
1166
Yi Kong7e53c572018-02-14 18:16:12 +08001167func (ctx *moduleContextImpl) isPgoCompile() bool {
1168 return ctx.mod.isPgoCompile()
1169}
1170
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001171func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1172 return ctx.mod.isNDKStubLibrary()
1173}
1174
Justin Yun8effde42017-06-23 19:24:43 +09001175func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001176 return ctx.mod.isVndkSp()
1177}
1178
1179func (ctx *moduleContextImpl) isVndkExt() bool {
1180 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001181}
1182
Vic Yangefd249e2018-11-12 20:19:56 -08001183func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001184 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001185}
1186
Justin Yun5f7f7e82019-11-18 19:52:14 +09001187func (ctx *moduleContextImpl) inProduct() bool {
1188 return ctx.mod.inProduct()
1189}
1190
1191func (ctx *moduleContextImpl) inVendor() bool {
1192 return ctx.mod.inVendor()
1193}
1194
Yifan Hong1b3348d2020-01-21 15:53:22 -08001195func (ctx *moduleContextImpl) inRamdisk() bool {
1196 return ctx.mod.InRamdisk()
1197}
1198
Jiyong Parkf9332f12018-02-01 00:54:12 +09001199func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001200 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001201}
1202
Logan Chien2f2b8902018-07-10 15:01:19 +08001203// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001204func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001205 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1206 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001207 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001208
1209 if ctx.ctx.Fuchsia() {
1210 return false
1211 }
1212
Logan Chien2f2b8902018-07-10 15:01:19 +08001213 if sanitize := ctx.mod.sanitize; sanitize != nil {
1214 if !sanitize.isVariantOnProductionDevice() {
1215 return false
1216 }
1217 }
1218 if !ctx.ctx.Device() {
1219 // Host modules do not need ABI dumps.
1220 return false
1221 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001222 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001223 // Stubs do not need ABI dumps.
1224 return false
1225 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001226 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001227}
1228
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001229func (ctx *moduleContextImpl) selectedStl() string {
1230 if stl := ctx.mod.stl; stl != nil {
1231 return stl.Properties.SelectedStl
1232 }
1233 return ""
1234}
1235
Ivan Lozanobd721262018-11-27 14:33:03 -08001236func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1237 return ctx.mod.linker.useClangLld(actx)
1238}
1239
Colin Crossce75d2c2016-10-06 16:12:58 -07001240func (ctx *moduleContextImpl) baseModuleName() string {
1241 return ctx.mod.ModuleBase.BaseModuleName()
1242}
1243
Logan Chienf3511742017-10-31 18:04:35 +08001244func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1245 return ctx.mod.getVndkExtendsModuleName()
1246}
1247
Logan Chiene274fc92019-12-03 11:18:32 -08001248func (ctx *moduleContextImpl) isForPlatform() bool {
1249 return ctx.mod.IsForPlatform()
1250}
1251
Colin Cross74385712020-08-13 11:24:56 -07001252func (ctx *moduleContextImpl) apexVariationName() string {
1253 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001254}
1255
Jooyung Han61c41542020-03-07 03:45:53 +09001256func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han74066602020-03-20 04:29:24 +09001257 return ctx.mod.apexSdkVersion
Jooyung Han61c41542020-03-07 03:45:53 +09001258}
1259
Jiyong Parkb0788572018-12-20 22:10:17 +09001260func (ctx *moduleContextImpl) hasStubsVariants() bool {
1261 return ctx.mod.HasStubsVariants()
1262}
1263
1264func (ctx *moduleContextImpl) isStubs() bool {
1265 return ctx.mod.IsStubs()
1266}
1267
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001268func (ctx *moduleContextImpl) bootstrap() bool {
1269 return ctx.mod.bootstrap()
1270}
1271
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001272func (ctx *moduleContextImpl) nativeCoverage() bool {
1273 return ctx.mod.nativeCoverage()
1274}
1275
Colin Cross635c3b02016-05-18 15:37:25 -07001276func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001277 return &Module{
1278 hod: hod,
1279 multilib: multilib,
1280 }
1281}
1282
Colin Cross635c3b02016-05-18 15:37:25 -07001283func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001284 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001285 module.features = []feature{
1286 &tidyFeature{},
1287 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001288 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001289 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001290 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001291 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001292 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001293 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001294 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001295 return module
1296}
1297
Colin Crossce75d2c2016-10-06 16:12:58 -07001298func (c *Module) Prebuilt() *android.Prebuilt {
1299 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1300 return p.prebuilt()
1301 }
1302 return nil
1303}
1304
1305func (c *Module) Name() string {
1306 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001307 if p, ok := c.linker.(interface {
1308 Name(string) string
1309 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001310 name = p.Name(name)
1311 }
1312 return name
1313}
1314
Alex Light3d673592019-01-18 14:37:31 -08001315func (c *Module) Symlinks() []string {
1316 if p, ok := c.installer.(interface {
1317 symlinkList() []string
1318 }); ok {
1319 return p.symlinkList()
1320 }
1321 return nil
1322}
1323
Jeff Gaston294356f2017-09-27 17:05:30 -07001324// orderDeps reorders dependencies into a list such that if module A depends on B, then
1325// A will precede B in the resultant list.
1326// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001327// Note that directSharedDeps should be the analogous static library for each shared lib dep
1328func 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 -07001329 // If A depends on B, then
1330 // Every list containing A will also contain B later in the list
1331 // So, after concatenating all lists, the final instance of B will have come from the same
1332 // original list as the final instance of A
1333 // So, the final instance of B will be later in the concatenation than the final A
1334 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1335 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001336 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001337 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001338 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1339 }
1340 for _, dep := range directSharedDeps {
1341 orderedAllDeps = append(orderedAllDeps, dep)
1342 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001343 }
1344
Colin Crossb6715442017-10-24 11:13:31 -07001345 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001346
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001347 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001348 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001349 // resultant list to only what the caller has chosen to include in directStaticDeps
1350 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001351
1352 return orderedAllDeps, orderedDeclaredDeps
1353}
1354
Ivan Lozano183a3212019-10-18 14:18:45 -07001355func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001356 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001357 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001358 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1359 staticDepFiles := []android.Path{}
1360 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001361 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1362 if dep.OutputFile().Valid() {
1363 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1364 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1365 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001366 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001367 sharedDepFiles := []android.Path{}
1368 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001369 if sharedDep.HasStaticVariant() {
1370 staticAnalogue := sharedDep.GetStaticVariant()
1371 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1372 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001373 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001374 }
1375
1376 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001377 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1378 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001379
1380 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001381}
1382
Roland Levillainf89cd092019-07-29 16:22:59 +01001383func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1384 test, ok := c.linker.(testPerSrc)
1385 return ok && test.isAllTestsVariation()
1386}
1387
Justin Yun5f7f7e82019-11-18 19:52:14 +09001388func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1389 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1390 // "current", it will append the VNDK version to the name suffix.
1391 var vndkVersion string
1392 var nameSuffix string
1393 if c.inProduct() {
1394 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1395 nameSuffix = productSuffix
1396 } else {
1397 vndkVersion = ctx.DeviceConfig().VndkVersion()
1398 nameSuffix = vendorSuffix
1399 }
1400 if vndkVersion == "current" {
1401 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1402 }
1403 if c.Properties.VndkVersion != vndkVersion {
1404 // add version suffix only if the module is using different vndk version than the
1405 // version in product or vendor partition.
1406 nameSuffix += "." + c.Properties.VndkVersion
1407 }
1408 return nameSuffix
1409}
1410
Colin Cross635c3b02016-05-18 15:37:25 -07001411func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001412 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001413 //
1414 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1415 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1416 // module and return early, as this module does not produce an output file per se.
1417 if c.IsTestPerSrcAllTestsVariation() {
1418 c.outputFile = android.OptionalPath{}
1419 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001420 }
1421
Jooyung Han38002912019-05-16 04:01:54 +09001422 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001423
Inseob Kim64c43952019-08-26 16:52:35 +09001424 c.Properties.SubName = ""
1425
1426 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1427 c.Properties.SubName += nativeBridgeSuffix
1428 }
1429
Justin Yun5f7f7e82019-11-18 19:52:14 +09001430 _, llndk := c.linker.(*llndkStubDecorator)
1431 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1432 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1433 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1434 // added for product variant only when we have vendor and product variants with core
1435 // variant. The suffix is not added for vendor-only or product-only module.
1436 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1437 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001438 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1439 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1440 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001441 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1442 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001443 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001444 c.Properties.SubName += recoverySuffix
Colin Cross01fd7cc2020-02-19 16:54:04 -08001445 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1446 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001447 }
1448
Colin Crossca860ac2016-01-04 14:34:37 -08001449 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001450 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001451 moduleContextImpl: moduleContextImpl{
1452 mod: c,
1453 },
1454 }
1455 ctx.ctx = ctx
1456
Colin Crossf18e1102017-11-16 14:33:08 -08001457 deps := c.depsToPaths(ctx)
1458 if ctx.Failed() {
1459 return
1460 }
1461
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001462 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1463 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1464 }
1465
Colin Crossca860ac2016-01-04 14:34:37 -08001466 flags := Flags{
1467 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001468 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001469 }
Colin Crossca860ac2016-01-04 14:34:37 -08001470 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001471 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001472 }
1473 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001474 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001475 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001476 if c.stl != nil {
1477 flags = c.stl.flags(ctx, flags)
1478 }
Colin Cross16b23492016-01-06 14:41:07 -08001479 if c.sanitize != nil {
1480 flags = c.sanitize.flags(ctx, flags)
1481 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001482 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001483 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001484 }
Stephen Craneba090d12017-05-09 15:44:35 -07001485 if c.lto != nil {
1486 flags = c.lto.flags(ctx, flags)
1487 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001488 if c.pgo != nil {
1489 flags = c.pgo.flags(ctx, flags)
1490 }
Colin Crossca860ac2016-01-04 14:34:37 -08001491 for _, feature := range c.features {
1492 flags = feature.flags(ctx, flags)
1493 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001494 if ctx.Failed() {
1495 return
1496 }
1497
Colin Cross4af21ed2019-11-04 09:37:55 -08001498 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1499 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1500 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001501
Colin Cross4af21ed2019-11-04 09:37:55 -08001502 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001503
1504 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001505 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001506 }
1507 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001508 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001509 }
1510
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001511 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001512 // We need access to all the flags seen by a source file.
1513 if c.sabi != nil {
1514 flags = c.sabi.flags(ctx, flags)
1515 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001516
Colin Cross4af21ed2019-11-04 09:37:55 -08001517 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001518
Colin Crossca860ac2016-01-04 14:34:37 -08001519 // Optimization to reduce size of build.ninja
1520 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001521 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1522 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1523 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1524 flags.Local.CFlags = []string{"$cflags"}
1525 flags.Local.CppFlags = []string{"$cppflags"}
1526 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001527
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001528 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001529 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001530 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001531 if ctx.Failed() {
1532 return
1533 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001534 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001535 }
1536
Colin Crossca860ac2016-01-04 14:34:37 -08001537 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001538 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001539 if ctx.Failed() {
1540 return
1541 }
Colin Cross635c3b02016-05-18 15:37:25 -07001542 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001543
1544 // If a lib is directly included in any of the APEXes, unhide the stubs
1545 // variant having the latest version gets visible to make. In addition,
1546 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1547 // force anything in the make world to link against the stubs library.
1548 // (unless it is explicitly referenced via .bootstrap suffix or the
1549 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001550 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001551 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001552 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001553 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001554 c.Properties.HideFromMake = false // unhide
1555 // Note: this is still non-installable
1556 }
Inseob Kimac775b22020-03-03 22:06:32 +09001557
1558 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1559 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1560 if isSnapshotAware(ctx, c) {
1561 i.collectHeadersForSnapshot(ctx)
1562 }
1563 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001564 }
Colin Cross5049f022015-03-18 13:28:46 -07001565
Inseob Kim1f086e22019-05-09 13:29:15 +09001566 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001567 c.installer.install(ctx, c.outputFile.Path())
1568 if ctx.Failed() {
1569 return
Colin Crossca860ac2016-01-04 14:34:37 -08001570 }
Paul Duffinf51768a2020-03-04 14:52:46 +00001571 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1572 // If the module has been specifically configure to not be installed then
1573 // skip the installation as otherwise it will break when running inside make
1574 // as the output path to install will not be specified. Not all uninstallable
1575 // modules can skip installation as some are needed for resolving make side
1576 // dependencies.
1577 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001578 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001579}
1580
Colin Cross0ea8ba82019-06-06 14:33:29 -07001581func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001582 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001583 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001584 }
Colin Crossca860ac2016-01-04 14:34:37 -08001585 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001586}
1587
Colin Crossca860ac2016-01-04 14:34:37 -08001588func (c *Module) begin(ctx BaseModuleContext) {
1589 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001590 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001591 }
Colin Crossca860ac2016-01-04 14:34:37 -08001592 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001593 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001594 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001595 if c.stl != nil {
1596 c.stl.begin(ctx)
1597 }
Colin Cross16b23492016-01-06 14:41:07 -08001598 if c.sanitize != nil {
1599 c.sanitize.begin(ctx)
1600 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001601 if c.coverage != nil {
1602 c.coverage.begin(ctx)
1603 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001604 if c.sabi != nil {
1605 c.sabi.begin(ctx)
1606 }
Justin Yun8effde42017-06-23 19:24:43 +09001607 if c.vndkdep != nil {
1608 c.vndkdep.begin(ctx)
1609 }
Stephen Craneba090d12017-05-09 15:44:35 -07001610 if c.lto != nil {
1611 c.lto.begin(ctx)
1612 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001613 if c.pgo != nil {
1614 c.pgo.begin(ctx)
1615 }
Colin Crossca860ac2016-01-04 14:34:37 -08001616 for _, feature := range c.features {
1617 feature.begin(ctx)
1618 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001619 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001620 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001621 if err != nil {
1622 ctx.PropertyErrorf("sdk_version", err.Error())
1623 }
Nan Zhang0007d812017-11-07 10:57:05 -08001624 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001625 }
Colin Crossca860ac2016-01-04 14:34:37 -08001626}
1627
Colin Cross37047f12016-12-13 17:06:13 -08001628func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001629 deps := Deps{}
1630
1631 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001632 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001633 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001634 // Add the PGO dependency (the clang_rt.profile runtime library), which
1635 // sometimes depends on symbols from libgcc, before libgcc gets added
1636 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001637 if c.pgo != nil {
1638 deps = c.pgo.deps(ctx, deps)
1639 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001640 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001641 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001642 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001643 if c.stl != nil {
1644 deps = c.stl.deps(ctx, deps)
1645 }
Colin Cross16b23492016-01-06 14:41:07 -08001646 if c.sanitize != nil {
1647 deps = c.sanitize.deps(ctx, deps)
1648 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001649 if c.coverage != nil {
1650 deps = c.coverage.deps(ctx, deps)
1651 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001652 if c.sabi != nil {
1653 deps = c.sabi.deps(ctx, deps)
1654 }
Justin Yun8effde42017-06-23 19:24:43 +09001655 if c.vndkdep != nil {
1656 deps = c.vndkdep.deps(ctx, deps)
1657 }
Stephen Craneba090d12017-05-09 15:44:35 -07001658 if c.lto != nil {
1659 deps = c.lto.deps(ctx, deps)
1660 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001661 for _, feature := range c.features {
1662 deps = feature.deps(ctx, deps)
1663 }
1664
Colin Crossb6715442017-10-24 11:13:31 -07001665 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1666 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1667 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1668 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1669 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1670 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001671 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001672
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001673 for _, lib := range deps.ReexportSharedLibHeaders {
1674 if !inList(lib, deps.SharedLibs) {
1675 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1676 }
1677 }
1678
1679 for _, lib := range deps.ReexportStaticLibHeaders {
1680 if !inList(lib, deps.StaticLibs) {
1681 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1682 }
1683 }
1684
Colin Cross5950f382016-12-13 12:50:57 -08001685 for _, lib := range deps.ReexportHeaderLibHeaders {
1686 if !inList(lib, deps.HeaderLibs) {
1687 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1688 }
1689 }
1690
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001691 for _, gen := range deps.ReexportGeneratedHeaders {
1692 if !inList(gen, deps.GeneratedHeaders) {
1693 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1694 }
1695 }
1696
Colin Crossc99deeb2016-04-11 15:06:20 -07001697 return deps
1698}
1699
Dan Albert7e9d2952016-08-04 13:02:36 -07001700func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001701 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001702 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001703 moduleContextImpl: moduleContextImpl{
1704 mod: c,
1705 },
1706 }
1707 ctx.ctx = ctx
1708
Colin Crossca860ac2016-01-04 14:34:37 -08001709 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001710}
1711
Jiyong Park7ed9de32018-10-15 22:25:07 +09001712// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001713func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001714 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1715 version := name[sharp+1:]
1716 libname := name[:sharp]
1717 return libname, version
1718 }
1719 return name, ""
1720}
1721
Colin Cross1e676be2016-10-12 14:38:15 -07001722func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001723 if !c.Enabled() {
1724 return
1725 }
1726
Colin Cross37047f12016-12-13 17:06:13 -08001727 ctx := &depsContext{
1728 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001729 moduleContextImpl: moduleContextImpl{
1730 mod: c,
1731 },
1732 }
1733 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001734
Colin Crossc99deeb2016-04-11 15:06:20 -07001735 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001736
Dan Albert914449f2016-06-17 16:45:24 -07001737 variantNdkLibs := []string{}
1738 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001739 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001740 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001741
Inseob Kimeec88e12020-01-22 11:11:29 +09001742 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001743 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001744 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001745 // 1. Name of an NDK library that refers to a prebuilt module.
1746 // For each of these, it adds the name of the prebuilt module (which will be in
1747 // prebuilts/ndk) to the list of nonvariant libs.
1748 // 2. Name of an NDK library that refers to an ndk_library module.
1749 // For each of these, it adds the name of the ndk_library module to the list of
1750 // variant libs.
1751 // 3. Anything else (so anything that isn't an NDK library).
1752 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001753 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001754 // The caller can then know to add the variantLibs dependencies differently from the
1755 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001756
Inseob Kim9516ee92019-05-09 10:56:13 +09001757 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001758 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1759
1760 rewriteVendorLibs := func(lib string) string {
1761 if isLlndkLibrary(lib, ctx.Config()) {
1762 return lib + llndkLibrarySuffix
1763 }
1764
1765 // only modules with BOARD_VNDK_VERSION uses snapshot.
1766 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1767 return lib
1768 }
1769
1770 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1771 return snapshot
1772 }
1773
1774 return lib
1775 }
1776
1777 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001778 variantLibs = []string{}
1779 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001780 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001781 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001782 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001783 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1784 if !inList(name, ndkMigratedLibs) {
1785 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001786 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001787 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001788 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001789 } else if ctx.useVndk() {
1790 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001791 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001792 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001793 if actx.OtherModuleExists(vendorPublicLib) {
1794 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1795 } else {
1796 // This can happen if vendor_public_library module is defined in a
1797 // namespace that isn't visible to the current module. In that case,
1798 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001799 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001800 }
Dan Albert914449f2016-06-17 16:45:24 -07001801 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001802 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001803 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001804 }
1805 }
Dan Albert914449f2016-06-17 16:45:24 -07001806 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001807 }
1808
Inseob Kimeec88e12020-01-22 11:11:29 +09001809 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1810 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1811 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1812 if ctx.useVndk() {
1813 for idx, lib := range deps.RuntimeLibs {
1814 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1815 }
1816 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001817 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001818
Jiyong Park7e636d02019-01-28 16:16:54 +09001819 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001820 if c.linker != nil {
1821 if library, ok := c.linker.(*libraryDecorator); ok {
1822 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001823 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001824 }
1825 }
1826 }
1827
Inseob Kimeec88e12020-01-22 11:11:29 +09001828 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1829 // only modules with BOARD_VNDK_VERSION uses snapshot.
1830 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1831 return lib
1832 }
1833
1834 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1835 return snapshot
1836 }
1837
1838 return lib
1839 }
1840
1841 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001842 for _, lib := range deps.HeaderLibs {
1843 depTag := headerDepTag
1844 if inList(lib, deps.ReexportHeaderLibHeaders) {
1845 depTag = headerExportDepTag
1846 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001847
1848 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1849
Jiyong Park7e636d02019-01-28 16:16:54 +09001850 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001851 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001852 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001853 } else {
1854 actx.AddVariationDependencies(nil, depTag, lib)
1855 }
1856 }
1857
1858 if buildStubs {
1859 // Stubs lib does not have dependency to other static/shared libraries.
1860 // Don't proceed.
1861 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001862 }
Colin Cross5950f382016-12-13 12:50:57 -08001863
Inseob Kimc0907f12019-02-08 21:00:45 +09001864 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001865 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001866
Jiyong Park5d1598f2019-02-25 22:14:17 +09001867 for _, lib := range deps.WholeStaticLibs {
1868 depTag := wholeStaticDepTag
1869 if impl, ok := syspropImplLibraries[lib]; ok {
1870 lib = impl
1871 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001872
1873 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1874
Jiyong Park5d1598f2019-02-25 22:14:17 +09001875 actx.AddVariationDependencies([]blueprint.Variation{
1876 {Mutator: "link", Variation: "static"},
1877 }, depTag, lib)
1878 }
1879
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001880 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001881 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001882 if inList(lib, deps.ReexportStaticLibHeaders) {
1883 depTag = staticExportDepTag
1884 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001885
1886 if impl, ok := syspropImplLibraries[lib]; ok {
1887 lib = impl
1888 }
1889
Inseob Kimeec88e12020-01-22 11:11:29 +09001890 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1891
Dan Willemsen59339a22018-07-22 21:18:45 -07001892 actx.AddVariationDependencies([]blueprint.Variation{
1893 {Mutator: "link", Variation: "static"},
1894 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001895 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001896
Jooyung Han74066602020-03-20 04:29:24 +09001897 // staticUnwinderDep is treated as staticDep for Q apexes
1898 // so that native libraries/binaries are linked with static unwinder
1899 // because Q libc doesn't have unwinder APIs
1900 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001901 actx.AddVariationDependencies([]blueprint.Variation{
1902 {Mutator: "link", Variation: "static"},
Inseob Kim4d8d8fe2020-06-01 21:53:49 +09001903 }, staticUnwinderDepTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001904 }
1905
Inseob Kimeec88e12020-01-22 11:11:29 +09001906 for _, lib := range deps.LateStaticLibs {
1907 actx.AddVariationDependencies([]blueprint.Variation{
1908 {Mutator: "link", Variation: "static"},
1909 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1910 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001911
Ivan Lozano183a3212019-10-18 14:18:45 -07001912 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001913 var variations []blueprint.Variation
1914 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Hanc40b5192020-04-10 12:57:24 +09001915 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001916 // Version is explicitly specified. i.e. libFoo#30
1917 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001918 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001919 }
1920 actx.AddVariationDependencies(variations, depTag, name)
1921
Jooyung Han0c4e0162020-02-26 22:45:42 +09001922 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001923 // The stubs library will be used when the depending module is built for APEX and
1924 // the dependent module is not in the same APEX.
Jooyung Hanc40b5192020-04-10 12:57:24 +09001925 if version == "" && VersionVariantAvailable(c) {
Jooyung Han0c4e0162020-02-26 22:45:42 +09001926 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1927 // Note that depTag.ExplicitlyVersioned is false in this case.
1928 actx.AddVariationDependencies([]blueprint.Variation{
1929 {Mutator: "link", Variation: "shared"},
1930 {Mutator: "version", Variation: ver},
1931 }, depTag, name)
1932 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001933 }
1934 }
1935
Jiyong Park7ed9de32018-10-15 22:25:07 +09001936 // shared lib names without the #version suffix
1937 var sharedLibNames []string
1938
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001939 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001940 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001941 if c.static() {
1942 depTag = SharedFromStaticDepTag
1943 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001944 if inList(lib, deps.ReexportSharedLibHeaders) {
1945 depTag = sharedExportDepTag
1946 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001947
1948 if impl, ok := syspropImplLibraries[lib]; ok {
1949 lib = impl
1950 }
1951
Jiyong Park73c54ee2019-10-22 20:31:18 +09001952 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001953 sharedLibNames = append(sharedLibNames, name)
1954
Jiyong Park25fc6a92018-11-18 18:02:45 +09001955 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001956 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001957
Jiyong Park7ed9de32018-10-15 22:25:07 +09001958 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001959 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001960 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1961 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1962 // linking against both the stubs lib and the non-stubs lib at the same time.
1963 continue
1964 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001965 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001966 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001967
Dan Willemsen59339a22018-07-22 21:18:45 -07001968 actx.AddVariationDependencies([]blueprint.Variation{
1969 {Mutator: "link", Variation: "shared"},
1970 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001971
Colin Cross68861832016-07-08 10:41:41 -07001972 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001973
1974 for _, gen := range deps.GeneratedHeaders {
1975 depTag := genHeaderDepTag
1976 if inList(gen, deps.ReexportGeneratedHeaders) {
1977 depTag = genHeaderExportDepTag
1978 }
1979 actx.AddDependency(c, depTag, gen)
1980 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001981
Colin Cross42d48b72018-08-29 14:10:52 -07001982 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001983
Inseob Kim502679e2020-06-01 23:23:05 +09001984 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
1985
Colin Crossc99deeb2016-04-11 15:06:20 -07001986 if deps.CrtBegin != "" {
Inseob Kim502679e2020-06-01 23:23:05 +09001987 actx.AddVariationDependencies(nil, CrtBeginDepTag, rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08001988 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001989 if deps.CrtEnd != "" {
Inseob Kim502679e2020-06-01 23:23:05 +09001990 actx.AddVariationDependencies(nil, CrtEndDepTag, rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07001991 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001992 if deps.LinkerFlagsFile != "" {
1993 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1994 }
1995 if deps.DynamicLinker != "" {
1996 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001997 }
Dan Albert914449f2016-06-17 16:45:24 -07001998
1999 version := ctx.sdkVersion()
2000 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002001 {Mutator: "ndk_api", Variation: version},
2002 {Mutator: "link", Variation: "shared"},
2003 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07002004 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002005 {Mutator: "ndk_api", Variation: version},
2006 {Mutator: "link", Variation: "shared"},
2007 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002008
2009 if vndkdep := c.vndkdep; vndkdep != nil {
2010 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002011 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002012 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002013 {Mutator: "link", Variation: "shared"},
2014 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002015 }
2016 }
Colin Cross6362e272015-10-29 15:25:03 -07002017}
Colin Cross21b9a242015-03-24 14:15:58 -07002018
Colin Crosse40b4ea2018-10-02 22:25:58 -07002019func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002020 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2021 c.beginMutator(ctx)
2022 }
2023}
2024
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002025// Whether a module can link to another module, taking into
2026// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07002027func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
2028 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002029 // Host code is not restricted
2030 return
2031 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002032
2033 // VNDK is cc.Module supported only for now.
2034 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002035 // Though vendor code is limited by the vendor mutator,
2036 // each vendor-available module needs to check
2037 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002038 if ccTo, ok := to.(*Module); ok {
2039 if ccFrom.vndkdep != nil {
2040 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2041 }
2042 } else {
2043 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002044 }
2045 return
2046 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002047 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002048 // Platform code can link to anything
2049 return
2050 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002051 if from.InRamdisk() {
2052 // Ramdisk code is not NDK
2053 return
2054 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002055 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002056 // Recovery code is not NDK
2057 return
2058 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002059 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002060 // These are always allowed
2061 return
2062 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002063 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002064 // These are allowed, but they don't set sdk_version
2065 return
2066 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002067 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002068 // These aren't real libraries, but are the stub shared libraries that are included in
2069 // the NDK.
2070 return
2071 }
Logan Chien834b9a62019-01-14 15:39:03 +08002072
Ivan Lozano52767be2019-10-18 14:49:46 -07002073 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002074 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2075 // to link to libc++ (non-NDK and without sdk_version).
2076 return
2077 }
2078
Ivan Lozano52767be2019-10-18 14:49:46 -07002079 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002080 // NDK code linking to platform code is never okay.
2081 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002082 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002083 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002084 }
2085
2086 // At this point we know we have two NDK libraries, but we need to
2087 // check that we're not linking against anything built against a higher
2088 // API level, as it is only valid to link against older or equivalent
2089 // APIs.
2090
Inseob Kim01a28722018-04-11 09:48:45 +09002091 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002092 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002093 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002094 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002095 // Current can't be linked against by anything else.
2096 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002097 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002098 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002099 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002100 if err != nil {
2101 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002102 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002103 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002104 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002105 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002106 if err != nil {
2107 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002108 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002109 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002110 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002111
Inseob Kim01a28722018-04-11 09:48:45 +09002112 if toApi > fromApi {
2113 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002114 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002115 }
2116 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002117 }
Dan Albert202fe492017-12-15 13:56:59 -08002118
2119 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002120 fromStl := from.SelectedStl()
2121 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002122 if fromStl == "" || toStl == "" {
2123 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002124 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002125 // We can be permissive with the system "STL" since it is only the C++
2126 // ABI layer, but in the future we should make sure that everyone is
2127 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002128 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002129 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002130 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2131 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002132 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002133}
2134
Jiyong Park5fb8c102018-04-09 12:03:06 +09002135// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002136// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2137// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002138// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002139func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2140 check := func(child, parent android.Module) bool {
2141 to, ok := child.(*Module)
2142 if !ok {
2143 // follow thru cc.Defaults, etc.
2144 return true
2145 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002146
Jooyung Hana70f0672019-01-18 15:20:43 +09002147 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2148 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002149 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002150
2151 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002152 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002153 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002154 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002155
Jooyung Han0302a842019-10-30 18:43:49 +09002156 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002157 return false
2158 }
2159
2160 var stringPath []string
2161 for _, m := range ctx.GetWalkPath() {
2162 stringPath = append(stringPath, m.Name())
2163 }
2164 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2165 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2166 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2167 return false
2168 }
2169 if module, ok := ctx.Module().(*Module); ok {
2170 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002171 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002172 ctx.WalkDeps(check)
2173 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002174 }
2175 }
2176}
2177
Colin Crossc99deeb2016-04-11 15:06:20 -07002178// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002179func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002180 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002181
Ivan Lozano183a3212019-10-18 14:18:45 -07002182 directStaticDeps := []LinkableInterface{}
2183 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002184
Inseob Kim9516ee92019-05-09 10:56:13 +09002185 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2186
Inseob Kim69378442019-06-03 19:10:47 +09002187 reexportExporter := func(exporter exportedFlagsProducer) {
2188 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2189 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2190 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2191 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002192 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002193 }
2194
Colin Crossd11fcda2017-10-23 17:59:01 -07002195 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002196 depName := ctx.OtherModuleName(dep)
2197 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002198
Ivan Lozano52767be2019-10-18 14:49:46 -07002199 ccDep, ok := dep.(LinkableInterface)
2200 if !ok {
2201
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002202 // handling for a few module types that aren't cc Module but that are also supported
2203 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002204 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002205 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002206 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2207 genRule.GeneratedSourceFiles()...)
2208 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002209 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002210 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002211 // Support exported headers from a generated_sources dependency
2212 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002213 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002214 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002215 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002216 genRule.GeneratedSourceFiles()...)
2217 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002218 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002219 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002220 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002221 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002222 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002223 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2224 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002225 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002226 // 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 +09002227 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002228
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002229 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002230 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002231 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002232 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002233 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002234 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002235 files := genRule.GeneratedSourceFiles()
2236 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002237 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002238 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002239 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 -07002240 }
2241 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002242 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002243 }
Colin Crossca860ac2016-01-04 14:34:37 -08002244 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002245 return
2246 }
2247
Colin Crossfe17f6f2019-03-28 19:30:56 -07002248 if depTag == android.ProtoPluginDepTag {
2249 return
2250 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002251 if depTag == llndkImplDep {
2252 return
2253 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002254
Colin Crossd11fcda2017-10-23 17:59:01 -07002255 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002256 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2257 return
2258 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002259 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002260 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2261 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002262 return
2263 }
2264
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002265 // re-exporting flags
2266 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002267 // reusing objects only make sense for cc.Modules.
2268 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002269 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002270 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002271 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002272 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002273 return
2274 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002275 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002276
Jiyong Parke4bb9862019-02-01 00:31:10 +09002277 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002278 // staticVariants are a cc.Module specific concept.
2279 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002280 c.staticVariant = ccDep
2281 return
2282 }
2283 }
2284
Jooyung Han74066602020-03-20 04:29:24 +09002285 // For the dependency from platform to apex, use the latest stubs
2286 c.apexSdkVersion = android.FutureApiLevel
2287 if !c.IsForPlatform() {
2288 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2289 }
2290
2291 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2292 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2293 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2294 // (b/144430859)
2295 c.apexSdkVersion = android.FutureApiLevel
2296 }
2297
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002298 if depTag == staticUnwinderDepTag {
Jooyung Han74066602020-03-20 04:29:24 +09002299 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2300 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002301 depTag = StaticDepTag
2302 } else {
2303 return
2304 }
2305 }
2306
Ivan Lozano183a3212019-10-18 14:18:45 -07002307 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2308 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2309 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002310 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002311 if t, ok := depTag.(DependencyTag); ok {
2312 explicitlyVersioned = t.ExplicitlyVersioned
2313 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002314 depTag = t
2315 }
2316
Ivan Lozano183a3212019-10-18 14:18:45 -07002317 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002318 depIsStatic := false
2319 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002320 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002321 depIsStatic = true
2322 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002323 if ccDep.CcLibrary() && !depIsStatic {
2324 depIsStubs := ccDep.BuildStubs()
Jooyung Hanc40b5192020-04-10 12:57:24 +09002325 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Cross274a72d2020-08-11 12:17:01 -07002326 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002327 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002328
2329 var useThisDep bool
2330 if depIsStubs && explicitlyVersioned {
2331 // Always respect dependency to the versioned stubs (i.e. libX#10)
2332 useThisDep = true
2333 } else if !depHasStubs {
2334 // Use non-stub variant if that is the only choice
2335 // (i.e. depending on a lib without stubs.version property)
2336 useThisDep = true
2337 } else if c.IsForPlatform() {
2338 // If not building for APEX, use stubs only when it is from
2339 // an APEX (and not from platform)
2340 useThisDep = (depInPlatform != depIsStubs)
Jooyung Hanc40b5192020-04-10 12:57:24 +09002341 if c.bootstrap() {
2342 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002343 // always link to non-stub variant
2344 useThisDep = !depIsStubs
2345 }
Jiyong Parkf0d01b72020-04-13 16:19:48 +09002346 for _, testFor := range c.TestFor() {
2347 // Another exception: if this module is bundled with an APEX, then
2348 // it is linked with the non-stub variant of a module in the APEX
2349 // as if this is part of the APEX.
2350 if android.DirectlyInApex(testFor, depName) {
2351 useThisDep = !depIsStubs
2352 break
2353 }
2354 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002355 } else {
Colin Cross274a72d2020-08-11 12:17:01 -07002356 // If building for APEX, use stubs when the parent is in any APEX that
2357 // the child is not in.
2358 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002359 }
2360
Jooyung Han0c4e0162020-02-26 22:45:42 +09002361 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2362 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han74066602020-03-20 04:29:24 +09002363 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han0c4e0162020-02-26 22:45:42 +09002364 if err != nil {
2365 ctx.OtherModuleErrorf(dep, err.Error())
2366 return
2367 }
2368 if versionToUse != ccDep.StubsVersion() {
2369 useThisDep = false
2370 }
2371 }
2372
Jiyong Park25fc6a92018-11-18 18:02:45 +09002373 if !useThisDep {
2374 return // stop processing this dep
2375 }
2376 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002377 if c.UseVndk() {
2378 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2379 // by default, use current version of LLNDK
2380 versionToUse := ""
2381 versions := stubsVersionsFor(ctx.Config())[depName]
Colin Cross74385712020-08-13 11:24:56 -07002382 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002383 // if this is for use_vendor apex && dep has stubsVersions
2384 // apply the same rule of apex sdk enforcement to choose right version
2385 var err error
Jooyung Han74066602020-03-20 04:29:24 +09002386 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han67a96cd2020-03-13 15:23:36 +09002387 if err != nil {
2388 ctx.OtherModuleErrorf(dep, err.Error())
2389 return
2390 }
2391 }
2392 if versionToUse != ccDep.StubsVersion() {
2393 return
2394 }
2395 }
2396 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002397
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002398 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2399
Ivan Lozano52767be2019-10-18 14:49:46 -07002400 // Exporting flags only makes sense for cc.Modules
2401 if _, ok := ccDep.(*Module); ok {
2402 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002403 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002404 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2405 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002406 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002407
Ivan Lozano52767be2019-10-18 14:49:46 -07002408 if t.ReexportFlags {
2409 reexportExporter(i)
2410 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2411 // Re-exported shared library headers must be included as well since they can help us with type information
2412 // about template instantiations (instantiated from their headers).
2413 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2414 // scripts.
2415 c.sabi.Properties.ReexportedIncludes = append(
2416 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2417 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002418 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002419 }
Logan Chienf3511742017-10-31 18:04:35 +08002420 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002421 }
2422
Colin Cross26c34ed2016-09-30 17:10:16 -07002423 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002424 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002425
Ivan Lozano52767be2019-10-18 14:49:46 -07002426 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002427 depFile := android.OptionalPath{}
2428
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002429 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002430 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002431 ptr = &depPaths.SharedLibs
2432 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002433 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002434 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002435
Jiyong Park64a44f22019-01-18 14:37:08 +09002436 case earlySharedDepTag:
2437 ptr = &depPaths.EarlySharedLibs
2438 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002439 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002440 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002441 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002442 ptr = &depPaths.LateSharedLibs
2443 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002444 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002445 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002446 ptr = nil
2447 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002448 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002449 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002450 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002451 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002452 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002453 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002454 return
2455 }
2456
Ivan Lozano52767be2019-10-18 14:49:46 -07002457 // Because the static library objects are included, this only makes sense
2458 // in the context of proper cc.Modules.
2459 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2460 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2461 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2462 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2463 for i := range missingDeps {
2464 missingDeps[i] += postfix
2465 }
2466 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002467 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002468 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2469 } else {
2470 ctx.ModuleErrorf(
2471 "non-cc.Modules cannot be included as whole static libraries.", depName)
2472 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002473 }
Colin Cross5950f382016-12-13 12:50:57 -08002474 case headerDepTag:
2475 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002476 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002477 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002478 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002479 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002480 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002481 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002482 case dynamicLinkerDepTag:
2483 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002484 }
2485
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002486 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002487 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002488 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002489 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002490 return
2491 }
2492
2493 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002494 // in static libraries act as if they were whole static libraries. The same goes for
2495 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002496 // This should only be done for cc.Modules
2497 if c, ok := ccDep.(*Module); ok {
2498 staticLib := c.linker.(libraryInterface)
2499 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2500 staticLib.objs().coverageFiles...)
2501 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2502 staticLib.objs().sAbiDumpFiles...)
2503 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002504 }
2505
Colin Cross26c34ed2016-09-30 17:10:16 -07002506 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002507 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002508 if !ctx.Config().AllowMissingDependencies() {
2509 ctx.ModuleErrorf("module %q missing output file", depName)
2510 } else {
2511 ctx.AddMissingDependencies([]string{depName})
2512 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002513 return
2514 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002515 *ptr = append(*ptr, linkFile.Path())
2516 }
2517
Colin Crossc99deeb2016-04-11 15:06:20 -07002518 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002519 dep := depFile
2520 if !dep.Valid() {
2521 dep = linkFile
2522 }
2523 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002524 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002525
Inseob Kimeec88e12020-01-22 11:11:29 +09002526 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2527
2528 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002529 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002530 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002531 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002532 return libName
2533 }
2534
2535 makeLibName := func(depName string) string {
2536 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002537 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002538 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002539 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002540
Inseob Kimeec88e12020-01-22 11:11:29 +09002541 if c, ok := ccDep.(*Module); ok {
2542 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002543 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002544 baseName := c.BaseModuleName()
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002545
2546 if c.IsVndk() {
2547 return baseName + ".vendor"
2548 }
2549
Inseob Kimeec88e12020-01-22 11:11:29 +09002550 if vendorSuffixModules[baseName] {
2551 return baseName + ".vendor"
2552 } else {
2553 return baseName
2554 }
2555 }
2556 }
2557
Yifan Hong1b3348d2020-01-21 15:53:22 -08002558 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002559 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2560 // core module instead.
2561 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002562 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002563 // The vendor module in Make will have been renamed to not conflict with the core
2564 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002565 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002566 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002567 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002568 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2569 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002570 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002571 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002572 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002573 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002574 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002575 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002576 }
Logan Chien43d34c32017-12-20 01:17:32 +08002577 }
2578
2579 // Export the shared libs to Make.
2580 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002581 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002582 if ccDep.CcLibrary() {
2583 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002584 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002585 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002586 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002587 c.Properties.ApexesProvidingSharedLibs = append(
2588 c.Properties.ApexesProvidingSharedLibs, an)
2589 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002590 }
2591 }
2592
Jiyong Park27b188b2017-07-18 13:23:39 +09002593 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002594 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002595 c.Properties.AndroidMkSharedLibs = append(
2596 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002597 // Record baseLibName for snapshots.
2598 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002599 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002600 c.Properties.AndroidMkSharedLibs = append(
2601 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002602 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002603 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002604 c.Properties.AndroidMkStaticLibs = append(
2605 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002606 case runtimeDepTag:
2607 c.Properties.AndroidMkRuntimeLibs = append(
2608 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002609 // Record baseLibName for snapshots.
2610 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002611 case wholeStaticDepTag:
2612 c.Properties.AndroidMkWholeStaticLibs = append(
2613 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002614 }
Colin Crossca860ac2016-01-04 14:34:37 -08002615 })
2616
Jeff Gaston294356f2017-09-27 17:05:30 -07002617 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002618 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002619
Colin Crossdd84e052017-05-17 13:44:16 -07002620 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002621 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002622 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2623 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002624 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002625 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002626 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2627 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002628 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002629 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002630 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002631
2632 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002633 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002634 }
Colin Crossdd84e052017-05-17 13:44:16 -07002635
Colin Crossca860ac2016-01-04 14:34:37 -08002636 return depPaths
2637}
2638
2639func (c *Module) InstallInData() bool {
2640 if c.installer == nil {
2641 return false
2642 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002643 return c.installer.inData()
2644}
2645
2646func (c *Module) InstallInSanitizerDir() bool {
2647 if c.installer == nil {
2648 return false
2649 }
2650 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002651 return true
2652 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002653 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002654}
2655
Yifan Hong1b3348d2020-01-21 15:53:22 -08002656func (c *Module) InstallInRamdisk() bool {
2657 return c.InRamdisk()
2658}
2659
Jiyong Parkf9332f12018-02-01 00:54:12 +09002660func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002661 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002662}
2663
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +01002664func (c *Module) SkipInstall() {
2665 if c.installer == nil {
2666 c.ModuleBase.SkipInstall()
2667 return
2668 }
2669 c.installer.skipInstall(c)
2670}
2671
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002672func (c *Module) HostToolPath() android.OptionalPath {
2673 if c.installer == nil {
2674 return android.OptionalPath{}
2675 }
2676 return c.installer.hostToolPath()
2677}
2678
Nan Zhangd4e641b2017-07-12 12:55:28 -07002679func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2680 return c.outputFile
2681}
2682
Colin Cross41955e82019-05-29 14:40:35 -07002683func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2684 switch tag {
2685 case "":
2686 if c.outputFile.Valid() {
2687 return android.Paths{c.outputFile.Path()}, nil
2688 }
2689 return android.Paths{}, nil
2690 default:
2691 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002692 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002693}
2694
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002695func (c *Module) static() bool {
2696 if static, ok := c.linker.(interface {
2697 static() bool
2698 }); ok {
2699 return static.static()
2700 }
2701 return false
2702}
2703
Jiyong Park379de2f2018-12-19 02:47:14 +09002704func (c *Module) staticBinary() bool {
2705 if static, ok := c.linker.(interface {
2706 staticBinary() bool
2707 }); ok {
2708 return static.staticBinary()
2709 }
2710 return false
2711}
2712
Jiyong Park1d1119f2019-07-29 21:27:18 +09002713func (c *Module) header() bool {
2714 if h, ok := c.linker.(interface {
2715 header() bool
2716 }); ok {
2717 return h.header()
2718 }
2719 return false
2720}
2721
Inseob Kim4d8d8fe2020-06-01 21:53:49 +09002722func (c *Module) binary() bool {
2723 if b, ok := c.linker.(interface {
2724 binary() bool
2725 }); ok {
2726 return b.binary()
2727 }
2728 return false
2729}
2730
Inseob Kim502679e2020-06-01 23:23:05 +09002731func (c *Module) object() bool {
2732 if o, ok := c.linker.(interface {
2733 object() bool
2734 }); ok {
2735 return o.object()
2736 }
2737 return false
2738}
2739
Jooyung Han38002912019-05-16 04:01:54 +09002740func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002741 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002742 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2743 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002744 return "native:vndk"
2745 }
Jooyung Han38002912019-05-16 04:01:54 +09002746 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002747 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002748 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002749 if Bool(c.VendorProperties.Vendor_available) {
2750 return "native:vndk"
2751 }
2752 return "native:vndk_private"
2753 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002754 if c.inProduct() {
2755 return "native:product"
2756 }
Jooyung Han38002912019-05-16 04:01:54 +09002757 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002758 } else if c.InRamdisk() {
2759 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002760 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002761 return "native:recovery"
2762 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2763 return "native:ndk:none:none"
2764 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2765 //family, link := getNdkStlFamilyAndLinkType(c)
2766 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002767 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002768 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002769 } else {
2770 return "native:platform"
2771 }
2772}
2773
Jiyong Park9d452992018-10-03 00:38:19 +09002774// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002775// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002776func (c *Module) IsInstallableToApex() bool {
2777 if shared, ok := c.linker.(interface {
2778 shared() bool
2779 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002780 // Stub libs and prebuilt libs in a versioned SDK are not
2781 // installable to APEX even though they are shared libs.
2782 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002783 } else if _, ok := c.linker.(testPerSrc); ok {
2784 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002785 }
2786 return false
2787}
2788
Jiyong Parka90ca002019-10-07 15:47:24 +09002789func (c *Module) AvailableFor(what string) bool {
2790 if linker, ok := c.linker.(interface {
2791 availableFor(string) bool
2792 }); ok {
2793 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2794 } else {
2795 return c.ApexModuleBase.AvailableFor(what)
2796 }
2797}
2798
Jiyong Parkf0d01b72020-04-13 16:19:48 +09002799func (c *Module) TestFor() []string {
2800 if test, ok := c.linker.(interface {
2801 testFor() []string
2802 }); ok {
2803 return test.testFor()
2804 } else {
2805 return c.ApexModuleBase.TestFor()
2806 }
2807}
2808
Colin Cross274a72d2020-08-11 12:17:01 -07002809func (c *Module) UniqueApexVariations() bool {
2810 if u, ok := c.compiler.(interface {
2811 uniqueApexVariations() bool
2812 }); ok {
2813 return u.uniqueApexVariations()
2814 } else {
2815 return false
2816 }
2817}
2818
Paul Duffinf51768a2020-03-04 14:52:46 +00002819// Return true if the module is ever installable.
2820func (c *Module) EverInstallable() bool {
2821 return c.installer != nil &&
2822 // Check to see whether the module is actually ever installable.
2823 c.installer.everInstallable()
2824}
2825
Inseob Kim1f086e22019-05-09 13:29:15 +09002826func (c *Module) installable() bool {
Paul Duffinf51768a2020-03-04 14:52:46 +00002827 ret := c.EverInstallable() &&
2828 // Check to see whether the module has been configured to not be installed.
2829 proptools.BoolDefault(c.Properties.Installable, true) &&
2830 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002831
2832 // The platform variant doesn't need further condition. Apex variants however might not
2833 // be installable because it will likely to be included in the APEX and won't appear
2834 // in the system partition.
2835 if c.IsForPlatform() {
2836 return ret
2837 }
2838
2839 // Special case for modules that are configured to be installed to /data, which includes
2840 // test modules. For these modules, both APEX and non-APEX variants are considered as
2841 // installable. This is because even the APEX variants won't be included in the APEX, but
2842 // will anyway be installed to /data/*.
2843 // See b/146995717
2844 if c.InstallInData() {
2845 return ret
2846 }
2847
2848 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002849}
2850
Logan Chien41eabe62019-04-10 13:33:58 +08002851func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2852 if c.linker != nil {
2853 if library, ok := c.linker.(*libraryDecorator); ok {
2854 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2855 }
2856 }
2857}
2858
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002859func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002860 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002861 if cc, ok := dep.(*Module); ok {
Jiyong Park9f14b9b2020-03-01 17:29:06 +09002862 if cc.HasStubsVariants() {
2863 if depTag.Shared && depTag.Library {
2864 // dynamic dep to a stubs lib crosses APEX boundary
2865 return false
2866 }
2867 if IsRuntimeDepTag(depTag) {
2868 // runtime dep to a stubs lib also crosses APEX boundary
2869 return false
2870 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002871 }
2872 if depTag.FromStatic {
2873 // shared_lib dependency from a static lib is considered as crossing
2874 // the APEX boundary because the dependency doesn't actually is
2875 // linked; the dependency is used only during the compilation phase.
2876 return false
2877 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002878 }
2879 }
2880 return true
2881}
2882
Colin Cross2ba19d92015-05-07 15:44:20 -07002883//
Colin Crosscfad1192015-11-02 16:43:11 -08002884// Defaults
2885//
Colin Crossca860ac2016-01-04 14:34:37 -08002886type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002887 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002888 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002889 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002890}
2891
Patrice Arrudac249c712019-03-19 17:00:29 -07002892// cc_defaults provides a set of properties that can be inherited by other cc
2893// modules. A module can use the properties from a cc_defaults using
2894// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2895// merged (when possible) by prepending the default module's values to the
2896// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002897func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002898 return DefaultsFactory()
2899}
2900
Colin Cross36242852017-06-23 15:06:31 -07002901func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002902 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002903
Colin Cross36242852017-06-23 15:06:31 -07002904 module.AddProperties(props...)
2905 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002906 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002907 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002908 &BaseCompilerProperties{},
2909 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002910 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002911 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002912 &StaticProperties{},
2913 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002914 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002915 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002916 &TestProperties{},
2917 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002918 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002919 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002920 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002921 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002922 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002923 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002924 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002925 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002926 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002927 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002928 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002929 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002930 )
Colin Crosscfad1192015-11-02 16:43:11 -08002931
Jooyung Hancc372c52019-09-25 15:18:44 +09002932 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002933
2934 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002935}
2936
Jiyong Park6a43f042017-10-12 23:05:00 +09002937func squashVendorSrcs(m *Module) {
2938 if lib, ok := m.compiler.(*libraryDecorator); ok {
2939 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2940 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2941
2942 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2943 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2944 }
2945}
2946
Jiyong Parkf9332f12018-02-01 00:54:12 +09002947func squashRecoverySrcs(m *Module) {
2948 if lib, ok := m.compiler.(*libraryDecorator); ok {
2949 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2950 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2951
2952 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2953 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2954 }
2955}
2956
Colin Cross7228ecd2019-11-18 16:00:16 -08002957var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002958
Colin Cross7228ecd2019-11-18 16:00:16 -08002959func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002960 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002961 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002962 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002963
2964 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002965 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002966 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002967 }
Logan Chienf3511742017-10-31 18:04:35 +08002968
2969 if vndkdep := m.vndkdep; vndkdep != nil {
2970 if vndkdep.isVndk() {
Justin Yun98df0d12020-02-28 15:07:59 +09002971 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002972 if !vndkdep.isVndkExt() {
2973 mctx.PropertyErrorf("vndk",
2974 "must set `extends: \"...\"` to vndk extension")
Justin Yun98df0d12020-02-28 15:07:59 +09002975 } else if m.VendorProperties.Vendor_available != nil {
2976 mctx.PropertyErrorf("vendor_available",
2977 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002978 }
2979 } else {
2980 if vndkdep.isVndkExt() {
2981 mctx.PropertyErrorf("vndk",
Justin Yun98df0d12020-02-28 15:07:59 +09002982 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002983 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002984 }
2985 if m.VendorProperties.Vendor_available == nil {
2986 mctx.PropertyErrorf("vndk",
2987 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002988 }
2989 }
2990 } else {
2991 if vndkdep.isVndkSp() {
2992 mctx.PropertyErrorf("vndk",
2993 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002994 }
2995 if vndkdep.isVndkExt() {
2996 mctx.PropertyErrorf("vndk",
2997 "must set `enabled: true` to set `extends: %q`",
2998 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002999 }
Justin Yun8effde42017-06-23 19:24:43 +09003000 }
3001 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003002
Jiyong Parkf9332f12018-02-01 00:54:12 +09003003 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08003004 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09003005 var recoveryVariantNeeded bool = false
3006
Inseob Kim64c43952019-08-26 16:52:35 +09003007 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09003008 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09003009
3010 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09003011 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
3012 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
3013 if boardVndkVersion == "current" {
3014 boardVndkVersion = platformVndkVersion
3015 }
3016 if productVndkVersion == "current" {
3017 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09003018 }
3019
Justin Yun5f7f7e82019-11-18 19:52:14 +09003020 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003021 // If the device isn't compiling against the VNDK, we always
3022 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003023 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003024 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003025 // LL-NDK stubs only exist in the vendor and product variants,
3026 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09003027 vendorVariants = append(vendorVariants,
3028 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003029 boardVndkVersion,
3030 )
3031 productVariants = append(productVariants,
3032 platformVndkVersion,
3033 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003034 )
Jiyong Park2a454122017-10-19 15:59:33 +09003035 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
3036 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09003037 vendorVariants = append(vendorVariants,
3038 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003039 boardVndkVersion,
3040 )
3041 productVariants = append(productVariants,
3042 platformVndkVersion,
3043 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003044 )
Inseob Kimeec88e12020-01-22 11:11:29 +09003045 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09003046 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
3047 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09003048 if snapshot, ok := m.linker.(interface {
3049 version() string
3050 }); ok {
3051 vendorVariants = append(vendorVariants, snapshot.version())
3052 } else {
3053 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
3054 }
Justin Yun98df0d12020-02-28 15:07:59 +09003055 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003056 // This will be available in /system, /vendor and /product
3057 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003058 coreVariantNeeded = true
Inseob Kimaf578ff2020-06-02 00:06:15 +09003059
3060 // We assume that modules under proprietary paths are compatible for
3061 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
3062 // PLATFORM_VNDK_VERSION.
3063 if isVendorProprietaryPath(mctx.ModuleDir()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003064 vendorVariants = append(vendorVariants, boardVndkVersion)
Inseob Kimaf578ff2020-06-02 00:06:15 +09003065 } else {
3066 vendorVariants = append(vendorVariants, platformVndkVersion)
3067 }
3068
3069 // vendor_available modules are also available to /product.
3070 productVariants = append(productVariants, platformVndkVersion)
3071 // VNDK is always PLATFORM_VNDK_VERSION
3072 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003073 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09003074 }
Logan Chienf3511742017-10-31 18:04:35 +08003075 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09003076 // This will be available in /vendor (or /odm) only
Inseob Kimaf578ff2020-06-02 00:06:15 +09003077 // We assume that modules under proprietary paths are compatible for
3078 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
3079 // PLATFORM_VNDK_VERSION.
3080 if isVendorProprietaryPath(mctx.ModuleDir()) {
3081 vendorVariants = append(vendorVariants, boardVndkVersion)
3082 } else {
3083 vendorVariants = append(vendorVariants, platformVndkVersion)
3084 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003085 } else {
3086 // This is either in /system (or similar: /data), or is a
3087 // modules built with the NDK. Modules built with the NDK
3088 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003089 coreVariantNeeded = true
3090 }
3091
Justin Yun5f7f7e82019-11-18 19:52:14 +09003092 if boardVndkVersion != "" && productVndkVersion != "" {
3093 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
3094 // The module has "product_specific: true" that does not create core variant.
3095 coreVariantNeeded = false
3096 productVariants = append(productVariants, productVndkVersion)
3097 }
3098 } else {
3099 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
3100 // restriction to use system libs.
3101 // No product variants defined in this case.
3102 productVariants = []string{}
3103 }
3104
Yifan Hong1b3348d2020-01-21 15:53:22 -08003105 if Bool(m.Properties.Ramdisk_available) {
3106 ramdiskVariantNeeded = true
3107 }
3108
3109 if m.ModuleBase.InstallInRamdisk() {
3110 ramdiskVariantNeeded = true
3111 coreVariantNeeded = false
3112 }
3113
Jiyong Parkf9332f12018-02-01 00:54:12 +09003114 if Bool(m.Properties.Recovery_available) {
3115 recoveryVariantNeeded = true
3116 }
3117
3118 if m.ModuleBase.InstallInRecovery() {
3119 recoveryVariantNeeded = true
3120 coreVariantNeeded = false
3121 }
3122
Inseob Kim64c43952019-08-26 16:52:35 +09003123 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003124 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3125 }
3126
3127 for _, variant := range android.FirstUniqueStrings(productVariants) {
3128 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003129 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003130
Yifan Hong1b3348d2020-01-21 15:53:22 -08003131 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003132 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3133 m.Properties.CoreVariantNeeded = coreVariantNeeded
3134}
3135
3136func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3137 return c.Properties.CoreVariantNeeded
3138}
3139
Yifan Hong1b3348d2020-01-21 15:53:22 -08003140func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3141 return c.Properties.RamdiskVariantNeeded
3142}
3143
Colin Cross7228ecd2019-11-18 16:00:16 -08003144func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3145 return c.Properties.RecoveryVariantNeeded
3146}
3147
3148func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003149 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003150}
3151
3152func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3153 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003154 if variant == android.RamdiskVariation {
3155 m.MakeAsPlatform()
3156 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003157 m.MakeAsPlatform()
3158 squashRecoverySrcs(m)
3159 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003160 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003161 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3162 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003163
3164 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3165 // Hide other vendor variants to avoid collision.
3166 vndkVersion := ctx.DeviceConfig().VndkVersion()
3167 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3168 m.Properties.HideFromMake = true
3169 m.SkipInstall()
3170 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003171 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3172 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3173 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3174 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003175 }
3176}
3177
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003178func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003179 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003180 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3181 }
Colin Cross6510f912017-11-29 00:27:14 -08003182 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003183}
3184
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003185func kytheExtractAllFactory() android.Singleton {
3186 return &kytheExtractAllSingleton{}
3187}
3188
3189type kytheExtractAllSingleton struct {
3190}
3191
3192func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3193 var xrefTargets android.Paths
3194 ctx.VisitAllModules(func(module android.Module) {
3195 if ccModule, ok := module.(xref); ok {
3196 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3197 }
3198 })
3199 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3200 if len(xrefTargets) > 0 {
Colin Cross98552072020-06-04 13:25:17 -07003201 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003202 }
3203}
3204
Colin Cross06a931b2015-10-28 17:23:31 -07003205var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003206var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003207var BoolPtr = proptools.BoolPtr
3208var String = proptools.String
3209var StringPtr = proptools.StringPtr