blob: 9196d47bac40c77b3b01ef718afe42f0a24343d8 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070051 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090052 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090053 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
54 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070055 })
Colin Cross16b23492016-01-06 14:41:07 -080056
Paul Duffin036e7002019-12-19 19:16:28 +000057 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070058 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
59 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080060
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070061 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
62 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
63
Mitch Phillipsbfeade62019-05-01 14:42:05 -070064 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
65 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
66
Jiyong Park1d1119f2019-07-29 21:27:18 +090067 // cfi mutator shouldn't run before sanitizers that return true for
68 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000069 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
70 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
71
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080072 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
73 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
74
Colin Cross1e676be2016-10-12 14:38:15 -070075 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
76 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080077
Colin Cross0b908332019-06-19 23:00:20 -070078 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090079 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080080
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080081 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080082 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070083
84 ctx.TopDown("lto_deps", ltoDepsMutator)
85 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090086
87 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070088 })
Colin Crossb98c8b02016-07-29 13:44:28 -070089
Sasha Smundak2a4549e2018-11-05 16:49:08 -080090 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070091}
92
Colin Crossca860ac2016-01-04 14:34:37 -080093type Deps struct {
94 SharedLibs, LateSharedLibs []string
95 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080096 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080097 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070098
Chris Parsons79d66a52020-06-05 17:26:16 -040099 // Used for data dependencies adjacent to tests
100 DataLibs []string
101
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800102 StaticUnwinderIfLegacy bool
103
Colin Cross5950f382016-12-13 12:50:57 -0800104 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700105
Colin Cross81413472016-04-11 14:37:39 -0700106 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700107
Dan Willemsenb40aab62016-04-20 14:21:14 -0700108 GeneratedSources []string
109 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900110 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700111
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700112 ReexportGeneratedHeaders []string
113
Colin Cross97ba0732015-03-23 17:50:24 -0700114 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700115
116 // Used for host bionic
117 LinkerFlagsFile string
118 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700119}
120
Colin Crossca860ac2016-01-04 14:34:37 -0800121type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900123 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700124 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900125 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700127 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700128
Colin Cross26c34ed2016-09-30 17:10:16 -0700129 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100130 Objs Objects
131 // Paths to .o files in dependencies that provide them. Note that these lists
132 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800133 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700134 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700135
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100136 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
137 // the libs from all whole_static_lib dependencies.
138 WholeStaticLibsFromPrebuilts android.Paths
139
Colin Cross26c34ed2016-09-30 17:10:16 -0700140 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700141 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900142 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700143
Inseob Kimd110f872019-12-06 13:15:38 +0900144 Flags []string
145 IncludeDirs android.Paths
146 SystemIncludeDirs android.Paths
147 ReexportedDirs android.Paths
148 ReexportedSystemDirs android.Paths
149 ReexportedFlags []string
150 ReexportedGeneratedHeaders android.Paths
151 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152
Colin Cross26c34ed2016-09-30 17:10:16 -0700153 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700154 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700155
156 // Path to the file container flags to use with the linker
157 LinkerFlagsFile android.OptionalPath
158
159 // Path to the dynamic linker binary
160 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700161}
162
Colin Cross4af21ed2019-11-04 09:37:55 -0800163// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
164// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
165// command line so they can be overridden by the local module flags).
166type LocalOrGlobalFlags struct {
167 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700168 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800169 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700170 CFlags []string // Flags that apply to C and C++ source files
171 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
172 ConlyFlags []string // Flags that apply to C source files
173 CppFlags []string // Flags that apply to C++ source files
174 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700175 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800176}
177
178type Flags struct {
179 Local LocalOrGlobalFlags
180 Global LocalOrGlobalFlags
181
182 aidlFlags []string // Flags that apply to aidl source files
183 rsFlags []string // Flags that apply to renderscript source files
184 libFlags []string // Flags to add libraries early to the link order
185 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
186 TidyFlags []string // Flags that apply to clang-tidy
187 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700188
Colin Crossc3199482017-03-30 15:03:04 -0700189 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800190 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700191 SystemIncludeFlags []string
192
Oliver Nguyen04526782020-04-21 12:40:27 -0700193 Toolchain config.Toolchain
194 Tidy bool
195 GcovCoverage bool
196 SAbiDump bool
197 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800198
199 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800200 DynamicLinker string
201
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700202 CFlagsDeps android.Paths // Files depended on by compiler flags
203 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800204
Dan Willemsen98ab3112019-08-27 21:20:40 -0700205 AssemblerWithCpp bool
206 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800207
Colin Cross19878da2019-03-28 14:45:07 -0700208 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700209 protoC bool // Whether to use C instead of C++
210 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700211
212 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200213 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700214}
215
Colin Crossca860ac2016-01-04 14:34:37 -0800216// Properties used to compile all C or C++ modules
217type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700218 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800219 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700220
Colin Crossc511bc52020-04-07 16:50:32 +0000221 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
222 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800223 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700224
Jooyung Han379660c2020-04-21 15:24:00 +0900225 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
226 Min_sdk_version *string
227
Colin Crossc511bc52020-04-07 16:50:32 +0000228 // If true, always create an sdk variant and don't create a platform variant.
229 Sdk_variant_only *bool
230
Jiyong Parkde866cb2018-12-07 23:08:36 +0900231 AndroidMkSharedLibs []string `blueprint:"mutated"`
232 AndroidMkStaticLibs []string `blueprint:"mutated"`
233 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
234 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700235 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900236 HideFromMake bool `blueprint:"mutated"`
237 PreventInstall bool `blueprint:"mutated"`
238 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700239
Justin Yun5f7f7e82019-11-18 19:52:14 +0900240 ImageVariationPrefix string `blueprint:"mutated"`
241 VndkVersion string `blueprint:"mutated"`
242 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800243
244 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
245 // file
246 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900247
Yifan Hong1b3348d2020-01-21 15:53:22 -0800248 // Make this module available when building for ramdisk
249 Ramdisk_available *bool
250
Jiyong Parkf9332f12018-02-01 00:54:12 +0900251 // Make this module available when building for recovery
252 Recovery_available *bool
253
Colin Crossae6c5202019-11-20 13:35:50 -0800254 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800255 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800256 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800257 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900258 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900259
260 // Allows this module to use non-APEX version of libraries. Useful
261 // for building binaries that are started before APEXes are activated.
262 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900263
264 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
265 // see soong/cc/config/vndk.go
266 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900267
268 // Used by vendor snapshot to record dependencies from snapshot modules.
269 SnapshotSharedLibs []string `blueprint:"mutated"`
270 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000271
272 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000273
274 // Set by factories of module types that can only be referenced from variants compiled against
275 // the SDK.
276 AlwaysSdk bool `blueprint:"mutated"`
277
278 // Variant is an SDK variant created by sdkMutator
279 IsSdkVariant bool `blueprint:"mutated"`
280 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
281 // variant to have a ".sdk" suffix.
282 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700283}
284
285type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900286 // whether this module should be allowed to be directly depended by other
287 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900288 // In addition, this module should be allowed to be directly depended by
289 // product modules with `product_specific: true`.
290 // If set to true, three variants will be built separately, one like
291 // normal, another limited to the set of libraries and headers
292 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700293 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900294 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700295 // so it shouldn't have any unversioned runtime dependencies, or
296 // make assumptions about the system that may not be true in the
297 // future.
298 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900299 // If set to false, this module becomes inaccessible from /vendor or /product
300 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900301 //
302 // Default value is true when vndk: {enabled: true} or vendor: true.
303 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700304 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900305 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700306 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900307
308 // whether this module is capable of being loaded with other instance
309 // (possibly an older version) of the same module in the same process.
310 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
311 // can be double loaded in a vendor process if the library is also a
312 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
313 // explicitly marked as `double_loadable: true` by the owner, or the dependency
314 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
315 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800316}
317
Colin Crossca860ac2016-01-04 14:34:37 -0800318type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800319 static() bool
320 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900321 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900322 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900323 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700324 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900325 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700326 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800327 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700328 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800329 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900330 isLlndk(config android.Config) bool
331 isLlndkPublic(config android.Config) bool
332 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900333 isVndk() bool
334 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800335 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900336 inProduct() bool
337 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800338 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900339 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800340 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700341 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700342 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800343 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800344 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800345 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800346 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800347 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700348 apexVariationName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900349 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900350 hasStubsVariants() bool
351 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900352 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800353 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700354 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800355}
356
357type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700358 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800359 ModuleContextIntf
360}
361
362type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700363 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800364 ModuleContextIntf
365}
366
Colin Cross37047f12016-12-13 17:06:13 -0800367type DepsContext interface {
368 android.BottomUpMutatorContext
369 ModuleContextIntf
370}
371
Colin Crossca860ac2016-01-04 14:34:37 -0800372type feature interface {
373 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800374 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800375 flags(ctx ModuleContext, flags Flags) Flags
376 props() []interface{}
377}
378
379type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700380 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800381 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800382 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700383 compilerProps() []interface{}
384
Colin Cross76fada02016-07-27 10:31:13 -0700385 appendCflags([]string)
386 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700387 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800388}
389
390type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700391 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800392 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700393 linkerFlags(ctx ModuleContext, flags Flags) Flags
394 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800395 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700396
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700397 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700398 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900399 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700400
401 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900402 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000403
404 // Get the deps that have been explicitly specified in the properties.
405 // Only updates the
406 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
407}
408
409type specifiedDeps struct {
410 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000411 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800412}
413
414type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700415 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700416 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000417 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800418 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700419 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700420 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900421 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100422 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800423}
424
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800425type xref interface {
426 XrefCcFiles() android.Paths
427}
428
Colin Cross6e511a92020-07-27 21:26:48 -0700429type libraryDependencyKind int
430
431const (
432 headerLibraryDependency = iota
433 sharedLibraryDependency
434 staticLibraryDependency
435)
436
437func (k libraryDependencyKind) String() string {
438 switch k {
439 case headerLibraryDependency:
440 return "headerLibraryDependency"
441 case sharedLibraryDependency:
442 return "sharedLibraryDependency"
443 case staticLibraryDependency:
444 return "staticLibraryDependency"
445 default:
446 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
447 }
448}
449
450type libraryDependencyOrder int
451
452const (
453 earlyLibraryDependency = -1
454 normalLibraryDependency = 0
455 lateLibraryDependency = 1
456)
457
458func (o libraryDependencyOrder) String() string {
459 switch o {
460 case earlyLibraryDependency:
461 return "earlyLibraryDependency"
462 case normalLibraryDependency:
463 return "normalLibraryDependency"
464 case lateLibraryDependency:
465 return "lateLibraryDependency"
466 default:
467 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
468 }
469}
470
471// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
472// tags that have a set of predefined tag objects that are reused for each dependency, a
473// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
474// That means that comparing a libraryDependencyTag for equality will only be equal if all
475// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
476// then check individual metadata fields instead.
477type libraryDependencyTag struct {
478 blueprint.BaseDependencyTag
479
480 // These are exported so that fmt.Printf("%#v") can call their String methods.
481 Kind libraryDependencyKind
482 Order libraryDependencyOrder
483
484 wholeStatic bool
485
486 reexportFlags bool
487 explicitlyVersioned bool
488 dataLib bool
489 ndk bool
490
491 staticUnwinder bool
492
493 makeSuffix string
494}
495
496// header returns true if the libraryDependencyTag is tagging a header lib dependency.
497func (d libraryDependencyTag) header() bool {
498 return d.Kind == headerLibraryDependency
499}
500
501// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
502func (d libraryDependencyTag) shared() bool {
503 return d.Kind == sharedLibraryDependency
504}
505
506// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
507func (d libraryDependencyTag) static() bool {
508 return d.Kind == staticLibraryDependency
509}
510
511// dependencyTag is used for tagging miscellanous dependency types that don't fit into
512// libraryDependencyTag. Each tag object is created globally and reused for multiple
513// dependencies (although since the object contains no references, assigning a tag to a
514// variable and modifying it will not modify the original). Users can compare the tag
515// returned by ctx.OtherModuleDependencyTag against the global original
516type dependencyTag struct {
517 blueprint.BaseDependencyTag
518 name string
519}
520
Colin Crossc99deeb2016-04-11 15:06:20 -0700521var (
Colin Cross6e511a92020-07-27 21:26:48 -0700522 genSourceDepTag = dependencyTag{name: "gen source"}
523 genHeaderDepTag = dependencyTag{name: "gen header"}
524 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
525 objDepTag = dependencyTag{name: "obj"}
526 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
527 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
528 reuseObjTag = dependencyTag{name: "reuse objects"}
529 staticVariantTag = dependencyTag{name: "static variant"}
530 vndkExtDepTag = dependencyTag{name: "vndk extends"}
531 dataLibDepTag = dependencyTag{name: "data lib"}
532 runtimeDepTag = dependencyTag{name: "runtime lib"}
533 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700534)
535
Roland Levillainf89cd092019-07-29 16:22:59 +0100536func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700537 ccLibDepTag, ok := depTag.(libraryDependencyTag)
538 return ok && ccLibDepTag.shared()
539}
540
541func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
542 ccLibDepTag, ok := depTag.(libraryDependencyTag)
543 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100544}
545
546func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700547 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100548 return ok && ccDepTag == runtimeDepTag
549}
550
551func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700552 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100553 return ok && ccDepTag == testPerSrcDepTag
554}
555
Colin Crossca860ac2016-01-04 14:34:37 -0800556// Module contains the properties and members used by all C/C++ module types, and implements
557// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
558// to construct the output file. Behavior can be customized with a Customizer interface
559type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700560 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700561 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900562 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900563 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700564
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700565 Properties BaseProperties
566 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700567
Colin Crossca860ac2016-01-04 14:34:37 -0800568 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700569 hod android.HostOrDeviceSupported
570 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700571
Paul Duffina0843f62019-12-13 19:50:38 +0000572 // Allowable SdkMemberTypes of this module type.
573 sdkMemberTypes []android.SdkMemberType
574
Colin Crossca860ac2016-01-04 14:34:37 -0800575 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700576 features []feature
577 compiler compiler
578 linker linker
579 installer installer
580 stl *stl
581 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800582 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800583 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900584 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700585 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700586 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800587
Colin Cross635c3b02016-05-18 15:37:25 -0700588 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800589
Colin Crossb98c8b02016-07-29 13:44:28 -0700590 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700591
592 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800593
594 // Flags used to compile this module
595 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700596
597 // 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 -0800598 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700599 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800600 depsInLinkOrder android.Paths
601
602 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700603 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900604
605 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800606 // Kythe (source file indexer) paths for this compilation module
607 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900608
609 // For apex variants, this is set as apex.min_sdk_version
610 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700611}
612
Ivan Lozano52767be2019-10-18 14:49:46 -0700613func (c *Module) Toc() android.OptionalPath {
614 if c.linker != nil {
615 if library, ok := c.linker.(libraryInterface); ok {
616 return library.toc()
617 }
618 }
619 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
620}
621
622func (c *Module) ApiLevel() string {
623 if c.linker != nil {
624 if stub, ok := c.linker.(*stubDecorator); ok {
625 return stub.properties.ApiLevel
626 }
627 }
628 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
629}
630
631func (c *Module) Static() bool {
632 if c.linker != nil {
633 if library, ok := c.linker.(libraryInterface); ok {
634 return library.static()
635 }
636 }
637 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
638}
639
640func (c *Module) Shared() bool {
641 if c.linker != nil {
642 if library, ok := c.linker.(libraryInterface); ok {
643 return library.shared()
644 }
645 }
646 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
647}
648
649func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000650 if c.stl != nil {
651 return c.stl.Properties.SelectedStl
652 }
653 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700654}
655
656func (c *Module) ToolchainLibrary() bool {
657 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
658 return true
659 }
660 return false
661}
662
663func (c *Module) NdkPrebuiltStl() bool {
664 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
665 return true
666 }
667 return false
668}
669
670func (c *Module) StubDecorator() bool {
671 if _, ok := c.linker.(*stubDecorator); ok {
672 return true
673 }
674 return false
675}
676
677func (c *Module) SdkVersion() string {
678 return String(c.Properties.Sdk_version)
679}
680
Artur Satayev480e25b2020-04-27 18:53:18 +0100681func (c *Module) MinSdkVersion() string {
682 return String(c.Properties.Min_sdk_version)
683}
684
Dan Albert92fe7402020-07-15 13:33:30 -0700685func (c *Module) SplitPerApiLevel() bool {
686 if linker, ok := c.linker.(*objectLinker); ok {
687 return linker.isCrt()
688 }
689 return false
690}
691
Colin Crossc511bc52020-04-07 16:50:32 +0000692func (c *Module) AlwaysSdk() bool {
693 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
694}
695
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800696func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700697 if c.linker != nil {
698 if library, ok := c.linker.(exportedFlagsProducer); ok {
699 return library.exportedDirs()
700 }
701 }
702 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
703}
704
705func (c *Module) HasStaticVariant() bool {
706 if c.staticVariant != nil {
707 return true
708 }
709 return false
710}
711
712func (c *Module) GetStaticVariant() LinkableInterface {
713 return c.staticVariant
714}
715
716func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
717 c.depsInLinkOrder = depsInLinkOrder
718}
719
720func (c *Module) GetDepsInLinkOrder() []android.Path {
721 return c.depsInLinkOrder
722}
723
724func (c *Module) StubsVersions() []string {
725 if c.linker != nil {
726 if library, ok := c.linker.(*libraryDecorator); ok {
727 return library.Properties.Stubs.Versions
728 }
729 }
730 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
731}
732
733func (c *Module) CcLibrary() bool {
734 if c.linker != nil {
735 if _, ok := c.linker.(*libraryDecorator); ok {
736 return true
737 }
738 }
739 return false
740}
741
742func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700743 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700744 return true
745 }
746 return false
747}
748
Ivan Lozano2b262972019-11-21 12:30:50 -0800749func (c *Module) NonCcVariants() bool {
750 return false
751}
752
Ivan Lozano183a3212019-10-18 14:18:45 -0700753func (c *Module) SetBuildStubs() {
754 if c.linker != nil {
755 if library, ok := c.linker.(*libraryDecorator); ok {
756 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700757 c.Properties.HideFromMake = true
758 c.sanitize = nil
759 c.stl = nil
760 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700761 return
762 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000763 if _, ok := c.linker.(*llndkStubDecorator); ok {
764 c.Properties.HideFromMake = true
765 return
766 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700767 }
768 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
769}
770
Ivan Lozano52767be2019-10-18 14:49:46 -0700771func (c *Module) BuildStubs() bool {
772 if c.linker != nil {
773 if library, ok := c.linker.(*libraryDecorator); ok {
774 return library.buildStubs()
775 }
776 }
777 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
778}
779
Ivan Lozano183a3212019-10-18 14:18:45 -0700780func (c *Module) SetStubsVersions(version string) {
781 if c.linker != nil {
782 if library, ok := c.linker.(*libraryDecorator); ok {
783 library.MutatedProperties.StubsVersion = version
784 return
785 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000786 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
787 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
788 return
789 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700790 }
791 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
792}
793
Jooyung Han03b51852020-02-26 22:45:42 +0900794func (c *Module) StubsVersion() string {
795 if c.linker != nil {
796 if library, ok := c.linker.(*libraryDecorator); ok {
797 return library.MutatedProperties.StubsVersion
798 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000799 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
800 return llndk.libraryDecorator.MutatedProperties.StubsVersion
801 }
Jooyung Han03b51852020-02-26 22:45:42 +0900802 }
803 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
804}
805
Ivan Lozano183a3212019-10-18 14:18:45 -0700806func (c *Module) SetStatic() {
807 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700808 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700809 library.setStatic()
810 return
811 }
812 }
813 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
814}
815
816func (c *Module) SetShared() {
817 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700818 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700819 library.setShared()
820 return
821 }
822 }
823 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
824}
825
826func (c *Module) BuildStaticVariant() bool {
827 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700828 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700829 return library.buildStatic()
830 }
831 }
832 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
833}
834
835func (c *Module) BuildSharedVariant() bool {
836 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700837 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700838 return library.buildShared()
839 }
840 }
841 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
842}
843
844func (c *Module) Module() android.Module {
845 return c
846}
847
Jiyong Parkc20eee32018-09-05 22:36:17 +0900848func (c *Module) OutputFile() android.OptionalPath {
849 return c.outputFile
850}
851
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400852func (c *Module) CoverageFiles() android.Paths {
853 if c.linker != nil {
854 if library, ok := c.linker.(libraryInterface); ok {
855 return library.objs().coverageFiles
856 }
857 }
858 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
859}
860
Ivan Lozano183a3212019-10-18 14:18:45 -0700861var _ LinkableInterface = (*Module)(nil)
862
Jiyong Park719b4462019-01-13 00:39:51 +0900863func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900864 if c.linker != nil {
865 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900866 }
867 return nil
868}
869
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900870func (c *Module) CoverageOutputFile() android.OptionalPath {
871 if c.linker != nil {
872 return c.linker.coverageOutputFilePath()
873 }
874 return android.OptionalPath{}
875}
876
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900877func (c *Module) RelativeInstallPath() string {
878 if c.installer != nil {
879 return c.installer.relativeInstallPath()
880 }
881 return ""
882}
883
Jooyung Han344d5432019-08-23 11:17:39 +0900884func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900885 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900886}
887
Colin Cross36242852017-06-23 15:06:31 -0700888func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700889 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800890 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700891 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800892 }
893 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700894 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800895 }
896 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700897 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800898 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700899 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700900 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700901 }
Colin Cross16b23492016-01-06 14:41:07 -0800902 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700903 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800904 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800905 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700906 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800907 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800908 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700909 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800910 }
Justin Yun8effde42017-06-23 19:24:43 +0900911 if c.vndkdep != nil {
912 c.AddProperties(c.vndkdep.props()...)
913 }
Stephen Craneba090d12017-05-09 15:44:35 -0700914 if c.lto != nil {
915 c.AddProperties(c.lto.props()...)
916 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700917 if c.pgo != nil {
918 c.AddProperties(c.pgo.props()...)
919 }
Colin Crossca860ac2016-01-04 14:34:37 -0800920 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700921 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800922 }
Colin Crossc472d572015-03-17 15:06:21 -0700923
Colin Crossa9d8bee2018-10-02 13:59:46 -0700924 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700925 // Windows builds always prefer 32-bit
926 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700927 })
Colin Cross36242852017-06-23 15:06:31 -0700928 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900929 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900930 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900931 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900932
Colin Cross36242852017-06-23 15:06:31 -0700933 return c
Colin Crossc472d572015-03-17 15:06:21 -0700934}
935
Colin Crossb916a382016-07-29 17:28:03 -0700936// Returns true for dependency roots (binaries)
937// TODO(ccross): also handle dlopenable libraries
938func (c *Module) isDependencyRoot() bool {
939 if root, ok := c.linker.(interface {
940 isDependencyRoot() bool
941 }); ok {
942 return root.isDependencyRoot()
943 }
944 return false
945}
946
Justin Yun5f7f7e82019-11-18 19:52:14 +0900947// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
948// "product" and "vendor" variant modules return true for this function.
949// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
950// "soc_specific: true" and more vendor installed modules are included here.
951// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
952// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700953func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900954 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700955}
956
Colin Crossc511bc52020-04-07 16:50:32 +0000957func (c *Module) canUseSdk() bool {
958 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
959}
960
961func (c *Module) UseSdk() bool {
962 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -0700963 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +0000964 }
965 return false
966}
967
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800968func (c *Module) isCoverageVariant() bool {
969 return c.coverage.Properties.IsCoverageVariant
970}
971
Peter Collingbournead84f972019-12-17 16:46:18 -0800972func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -0700973 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800974}
975
Inseob Kim9516ee92019-05-09 10:56:13 +0900976func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800977 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900978 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800979}
980
Inseob Kim9516ee92019-05-09 10:56:13 +0900981func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800982 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900983 name := c.BaseModuleName()
984 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800985}
986
Inseob Kim9516ee92019-05-09 10:56:13 +0900987func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800988 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900989 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800990}
991
Ivan Lozano52767be2019-10-18 14:49:46 -0700992func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800993 if vndkdep := c.vndkdep; vndkdep != nil {
994 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900995 }
996 return false
997}
998
Yi Kong7e53c572018-02-14 18:16:12 +0800999func (c *Module) isPgoCompile() bool {
1000 if pgo := c.pgo; pgo != nil {
1001 return pgo.Properties.PgoCompile
1002 }
1003 return false
1004}
1005
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001006func (c *Module) isNDKStubLibrary() bool {
1007 if _, ok := c.compiler.(*stubDecorator); ok {
1008 return true
1009 }
1010 return false
1011}
1012
Logan Chienf3511742017-10-31 18:04:35 +08001013func (c *Module) isVndkSp() bool {
1014 if vndkdep := c.vndkdep; vndkdep != nil {
1015 return vndkdep.isVndkSp()
1016 }
1017 return false
1018}
1019
1020func (c *Module) isVndkExt() bool {
1021 if vndkdep := c.vndkdep; vndkdep != nil {
1022 return vndkdep.isVndkExt()
1023 }
1024 return false
1025}
1026
Ivan Lozano52767be2019-10-18 14:49:46 -07001027func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001028 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001029}
1030
Logan Chienf3511742017-10-31 18:04:35 +08001031func (c *Module) getVndkExtendsModuleName() string {
1032 if vndkdep := c.vndkdep; vndkdep != nil {
1033 return vndkdep.getVndkExtendsModuleName()
1034 }
1035 return ""
1036}
1037
Jiyong Park25fc6a92018-11-18 18:02:45 +09001038func (c *Module) IsStubs() bool {
1039 if library, ok := c.linker.(*libraryDecorator); ok {
1040 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001041 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1042 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001043 }
1044 return false
1045}
1046
1047func (c *Module) HasStubsVariants() bool {
1048 if library, ok := c.linker.(*libraryDecorator); ok {
1049 return len(library.Properties.Stubs.Versions) > 0
1050 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001051 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1052 return len(library.Properties.Stubs.Versions) > 0
1053 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001054 return false
1055}
1056
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001057func (c *Module) bootstrap() bool {
1058 return Bool(c.Properties.Bootstrap)
1059}
1060
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001061func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001062 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1063 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1064 return false
1065 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001066 return c.linker != nil && c.linker.nativeCoverage()
1067}
1068
Inseob Kim8471cda2019-11-15 09:59:12 +09001069func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001070 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1071 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001072 }
1073 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001074}
1075
Jiyong Park73c54ee2019-10-22 20:31:18 +09001076func (c *Module) ExportedIncludeDirs() android.Paths {
1077 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1078 return flagsProducer.exportedDirs()
1079 }
Jiyong Park232e7852019-11-04 12:23:40 +09001080 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001081}
1082
1083func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1084 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1085 return flagsProducer.exportedSystemDirs()
1086 }
Jiyong Park232e7852019-11-04 12:23:40 +09001087 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001088}
1089
1090func (c *Module) ExportedFlags() []string {
1091 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1092 return flagsProducer.exportedFlags()
1093 }
Jiyong Park232e7852019-11-04 12:23:40 +09001094 return nil
1095}
1096
1097func (c *Module) ExportedDeps() android.Paths {
1098 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1099 return flagsProducer.exportedDeps()
1100 }
1101 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001102}
1103
Inseob Kimd110f872019-12-06 13:15:38 +09001104func (c *Module) ExportedGeneratedHeaders() android.Paths {
1105 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1106 return flagsProducer.exportedGeneratedHeaders()
1107 }
1108 return nil
1109}
1110
Jiyong Parkf1194352019-02-25 11:05:47 +09001111func isBionic(name string) bool {
1112 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001113 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001114 return true
1115 }
1116 return false
1117}
1118
Martin Stjernholm279de572019-09-10 23:18:20 +01001119func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001120 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001121 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001122 }
1123 return isBionic(name)
1124}
1125
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001126func (c *Module) XrefCcFiles() android.Paths {
1127 return c.kytheFiles
1128}
1129
Colin Crossca860ac2016-01-04 14:34:37 -08001130type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001131 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001132 moduleContextImpl
1133}
1134
Colin Cross37047f12016-12-13 17:06:13 -08001135type depsContext struct {
1136 android.BottomUpMutatorContext
1137 moduleContextImpl
1138}
1139
Colin Crossca860ac2016-01-04 14:34:37 -08001140type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001141 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001142 moduleContextImpl
1143}
1144
1145type moduleContextImpl struct {
1146 mod *Module
1147 ctx BaseModuleContext
1148}
1149
Colin Crossb98c8b02016-07-29 13:44:28 -07001150func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001151 return ctx.mod.toolchain(ctx.ctx)
1152}
1153
1154func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001155 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001156}
1157
1158func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001159 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001160}
1161
Jiyong Park1d1119f2019-07-29 21:27:18 +09001162func (ctx *moduleContextImpl) header() bool {
1163 return ctx.mod.header()
1164}
1165
Inseob Kim7f283f42020-06-01 21:53:49 +09001166func (ctx *moduleContextImpl) binary() bool {
1167 return ctx.mod.binary()
1168}
1169
Inseob Kim1042d292020-06-01 23:23:05 +09001170func (ctx *moduleContextImpl) object() bool {
1171 return ctx.mod.object()
1172}
1173
Jooyung Hanccce2f22020-03-07 03:45:53 +09001174func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001175 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001176}
1177
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001179 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001180}
1181
1182func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001183 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001184 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001185 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001186 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001187 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001188 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001189 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001190 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001191 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001192 }
1193 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001194}
1195
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001196func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001197 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001198}
Justin Yun8effde42017-06-23 19:24:43 +09001199
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001200func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001201 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001202}
1203
Inseob Kim9516ee92019-05-09 10:56:13 +09001204func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1205 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001206}
1207
Inseob Kim9516ee92019-05-09 10:56:13 +09001208func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1209 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001210}
1211
Inseob Kim9516ee92019-05-09 10:56:13 +09001212func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1213 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001214}
1215
Logan Chienf3511742017-10-31 18:04:35 +08001216func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001217 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001218}
1219
Yi Kong7e53c572018-02-14 18:16:12 +08001220func (ctx *moduleContextImpl) isPgoCompile() bool {
1221 return ctx.mod.isPgoCompile()
1222}
1223
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001224func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1225 return ctx.mod.isNDKStubLibrary()
1226}
1227
Justin Yun8effde42017-06-23 19:24:43 +09001228func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001229 return ctx.mod.isVndkSp()
1230}
1231
1232func (ctx *moduleContextImpl) isVndkExt() bool {
1233 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001234}
1235
Vic Yangefd249e2018-11-12 20:19:56 -08001236func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001237 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001238}
1239
Logan Chien2f2b8902018-07-10 15:01:19 +08001240// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001241func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001242 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1243 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001244 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001245
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001246 // Coverage builds have extra symbols.
1247 if ctx.mod.isCoverageVariant() {
1248 return false
1249 }
1250
Doug Hornc32c6b02019-01-17 14:44:05 -08001251 if ctx.ctx.Fuchsia() {
1252 return false
1253 }
1254
Logan Chien2f2b8902018-07-10 15:01:19 +08001255 if sanitize := ctx.mod.sanitize; sanitize != nil {
1256 if !sanitize.isVariantOnProductionDevice() {
1257 return false
1258 }
1259 }
1260 if !ctx.ctx.Device() {
1261 // Host modules do not need ABI dumps.
1262 return false
1263 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001264 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001265 // Stubs do not need ABI dumps.
1266 return false
1267 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001268 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001269}
1270
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001271func (ctx *moduleContextImpl) selectedStl() string {
1272 if stl := ctx.mod.stl; stl != nil {
1273 return stl.Properties.SelectedStl
1274 }
1275 return ""
1276}
1277
Ivan Lozanobd721262018-11-27 14:33:03 -08001278func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1279 return ctx.mod.linker.useClangLld(actx)
1280}
1281
Colin Crossce75d2c2016-10-06 16:12:58 -07001282func (ctx *moduleContextImpl) baseModuleName() string {
1283 return ctx.mod.ModuleBase.BaseModuleName()
1284}
1285
Logan Chienf3511742017-10-31 18:04:35 +08001286func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1287 return ctx.mod.getVndkExtendsModuleName()
1288}
1289
Logan Chiene274fc92019-12-03 11:18:32 -08001290func (ctx *moduleContextImpl) isForPlatform() bool {
1291 return ctx.mod.IsForPlatform()
1292}
1293
Colin Crosse07f2312020-08-13 11:24:56 -07001294func (ctx *moduleContextImpl) apexVariationName() string {
1295 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001296}
1297
Jooyung Hanccce2f22020-03-07 03:45:53 +09001298func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001299 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001300}
1301
Jiyong Parkb0788572018-12-20 22:10:17 +09001302func (ctx *moduleContextImpl) hasStubsVariants() bool {
1303 return ctx.mod.HasStubsVariants()
1304}
1305
1306func (ctx *moduleContextImpl) isStubs() bool {
1307 return ctx.mod.IsStubs()
1308}
1309
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001310func (ctx *moduleContextImpl) bootstrap() bool {
1311 return ctx.mod.bootstrap()
1312}
1313
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001314func (ctx *moduleContextImpl) nativeCoverage() bool {
1315 return ctx.mod.nativeCoverage()
1316}
1317
Colin Cross635c3b02016-05-18 15:37:25 -07001318func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001319 return &Module{
1320 hod: hod,
1321 multilib: multilib,
1322 }
1323}
1324
Colin Cross635c3b02016-05-18 15:37:25 -07001325func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001326 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001327 module.features = []feature{
1328 &tidyFeature{},
1329 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001330 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001331 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001332 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001333 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001334 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001335 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001336 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001337 return module
1338}
1339
Colin Crossce75d2c2016-10-06 16:12:58 -07001340func (c *Module) Prebuilt() *android.Prebuilt {
1341 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1342 return p.prebuilt()
1343 }
1344 return nil
1345}
1346
1347func (c *Module) Name() string {
1348 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001349 if p, ok := c.linker.(interface {
1350 Name(string) string
1351 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001352 name = p.Name(name)
1353 }
1354 return name
1355}
1356
Alex Light3d673592019-01-18 14:37:31 -08001357func (c *Module) Symlinks() []string {
1358 if p, ok := c.installer.(interface {
1359 symlinkList() []string
1360 }); ok {
1361 return p.symlinkList()
1362 }
1363 return nil
1364}
1365
Jeff Gaston294356f2017-09-27 17:05:30 -07001366// orderDeps reorders dependencies into a list such that if module A depends on B, then
1367// A will precede B in the resultant list.
1368// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001369// Note that directSharedDeps should be the analogous static library for each shared lib dep
1370func 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 -07001371 // If A depends on B, then
1372 // Every list containing A will also contain B later in the list
1373 // So, after concatenating all lists, the final instance of B will have come from the same
1374 // original list as the final instance of A
1375 // So, the final instance of B will be later in the concatenation than the final A
1376 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1377 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001378 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001379 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001380 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1381 }
1382 for _, dep := range directSharedDeps {
1383 orderedAllDeps = append(orderedAllDeps, dep)
1384 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001385 }
1386
Colin Crossb6715442017-10-24 11:13:31 -07001387 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001388
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001389 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001390 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001391 // resultant list to only what the caller has chosen to include in directStaticDeps
1392 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001393
1394 return orderedAllDeps, orderedDeclaredDeps
1395}
1396
Ivan Lozano183a3212019-10-18 14:18:45 -07001397func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001398 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001399 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001400 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1401 staticDepFiles := []android.Path{}
1402 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001403 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1404 if dep.OutputFile().Valid() {
1405 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1406 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1407 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001408 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001409 sharedDepFiles := []android.Path{}
1410 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001411 if sharedDep.HasStaticVariant() {
1412 staticAnalogue := sharedDep.GetStaticVariant()
1413 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1414 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001415 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001416 }
1417
1418 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001419 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1420 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001421
1422 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001423}
1424
Roland Levillainf89cd092019-07-29 16:22:59 +01001425func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1426 test, ok := c.linker.(testPerSrc)
1427 return ok && test.isAllTestsVariation()
1428}
1429
Chris Parsons216e10a2020-07-09 17:12:52 -04001430func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001431 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001432 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001433 }); ok {
1434 return p.dataPaths()
1435 }
1436 return nil
1437}
1438
Justin Yun5f7f7e82019-11-18 19:52:14 +09001439func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1440 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1441 // "current", it will append the VNDK version to the name suffix.
1442 var vndkVersion string
1443 var nameSuffix string
1444 if c.inProduct() {
1445 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1446 nameSuffix = productSuffix
1447 } else {
1448 vndkVersion = ctx.DeviceConfig().VndkVersion()
1449 nameSuffix = vendorSuffix
1450 }
1451 if vndkVersion == "current" {
1452 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1453 }
1454 if c.Properties.VndkVersion != vndkVersion {
1455 // add version suffix only if the module is using different vndk version than the
1456 // version in product or vendor partition.
1457 nameSuffix += "." + c.Properties.VndkVersion
1458 }
1459 return nameSuffix
1460}
1461
Colin Cross635c3b02016-05-18 15:37:25 -07001462func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001463 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001464 //
1465 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1466 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1467 // module and return early, as this module does not produce an output file per se.
1468 if c.IsTestPerSrcAllTestsVariation() {
1469 c.outputFile = android.OptionalPath{}
1470 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001471 }
1472
Jooyung Han38002912019-05-16 04:01:54 +09001473 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001474
Inseob Kim64c43952019-08-26 16:52:35 +09001475 c.Properties.SubName = ""
1476
1477 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1478 c.Properties.SubName += nativeBridgeSuffix
1479 }
1480
Justin Yun5f7f7e82019-11-18 19:52:14 +09001481 _, llndk := c.linker.(*llndkStubDecorator)
1482 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1483 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1484 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1485 // added for product variant only when we have vendor and product variants with core
1486 // variant. The suffix is not added for vendor-only or product-only module.
1487 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1488 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001489 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1490 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1491 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001492 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1493 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001494 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001495 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001496 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001497 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001498 if c.SplitPerApiLevel() {
1499 c.Properties.SubName += "." + c.SdkVersion()
1500 }
Inseob Kim64c43952019-08-26 16:52:35 +09001501 }
1502
Colin Crossca860ac2016-01-04 14:34:37 -08001503 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001504 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001505 moduleContextImpl: moduleContextImpl{
1506 mod: c,
1507 },
1508 }
1509 ctx.ctx = ctx
1510
Colin Crossf18e1102017-11-16 14:33:08 -08001511 deps := c.depsToPaths(ctx)
1512 if ctx.Failed() {
1513 return
1514 }
1515
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001516 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1517 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1518 }
1519
Colin Crossca860ac2016-01-04 14:34:37 -08001520 flags := Flags{
1521 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001522 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001523 }
Colin Crossca860ac2016-01-04 14:34:37 -08001524 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001525 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001526 }
1527 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001528 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001529 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001530 if c.stl != nil {
1531 flags = c.stl.flags(ctx, flags)
1532 }
Colin Cross16b23492016-01-06 14:41:07 -08001533 if c.sanitize != nil {
1534 flags = c.sanitize.flags(ctx, flags)
1535 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001536 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001537 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001538 }
Stephen Craneba090d12017-05-09 15:44:35 -07001539 if c.lto != nil {
1540 flags = c.lto.flags(ctx, flags)
1541 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001542 if c.pgo != nil {
1543 flags = c.pgo.flags(ctx, flags)
1544 }
Colin Crossca860ac2016-01-04 14:34:37 -08001545 for _, feature := range c.features {
1546 flags = feature.flags(ctx, flags)
1547 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001548 if ctx.Failed() {
1549 return
1550 }
1551
Colin Cross4af21ed2019-11-04 09:37:55 -08001552 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1553 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1554 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001555
Colin Cross4af21ed2019-11-04 09:37:55 -08001556 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001557
1558 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001559 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001560 }
1561 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001562 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001563 }
1564
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001565 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001566 // We need access to all the flags seen by a source file.
1567 if c.sabi != nil {
1568 flags = c.sabi.flags(ctx, flags)
1569 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001570
Colin Cross4af21ed2019-11-04 09:37:55 -08001571 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001572
Colin Crossca860ac2016-01-04 14:34:37 -08001573 // Optimization to reduce size of build.ninja
1574 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001575 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1576 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1577 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1578 flags.Local.CFlags = []string{"$cflags"}
1579 flags.Local.CppFlags = []string{"$cppflags"}
1580 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001581
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001582 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001583 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001584 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001585 if ctx.Failed() {
1586 return
1587 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001588 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001589 }
1590
Colin Crossca860ac2016-01-04 14:34:37 -08001591 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001592 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001593 if ctx.Failed() {
1594 return
1595 }
Colin Cross635c3b02016-05-18 15:37:25 -07001596 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001597
1598 // If a lib is directly included in any of the APEXes, unhide the stubs
1599 // variant having the latest version gets visible to make. In addition,
1600 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1601 // force anything in the make world to link against the stubs library.
1602 // (unless it is explicitly referenced via .bootstrap suffix or the
1603 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001604 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001605 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001606 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001607 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001608 c.Properties.HideFromMake = false // unhide
1609 // Note: this is still non-installable
1610 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001611
1612 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1613 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1614 if isSnapshotAware(ctx, c) {
1615 i.collectHeadersForSnapshot(ctx)
1616 }
1617 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001618 }
Colin Cross5049f022015-03-18 13:28:46 -07001619
Inseob Kim1f086e22019-05-09 13:29:15 +09001620 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001621 c.installer.install(ctx, c.outputFile.Path())
1622 if ctx.Failed() {
1623 return
Colin Crossca860ac2016-01-04 14:34:37 -08001624 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001625 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1626 // If the module has been specifically configure to not be installed then
1627 // skip the installation as otherwise it will break when running inside make
1628 // as the output path to install will not be specified. Not all uninstallable
1629 // modules can skip installation as some are needed for resolving make side
1630 // dependencies.
1631 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001632 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001633}
1634
Colin Cross0ea8ba82019-06-06 14:33:29 -07001635func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001636 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001637 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001638 }
Colin Crossca860ac2016-01-04 14:34:37 -08001639 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001640}
1641
Colin Crossca860ac2016-01-04 14:34:37 -08001642func (c *Module) begin(ctx BaseModuleContext) {
1643 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001644 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001645 }
Colin Crossca860ac2016-01-04 14:34:37 -08001646 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001647 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001648 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001649 if c.stl != nil {
1650 c.stl.begin(ctx)
1651 }
Colin Cross16b23492016-01-06 14:41:07 -08001652 if c.sanitize != nil {
1653 c.sanitize.begin(ctx)
1654 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001655 if c.coverage != nil {
1656 c.coverage.begin(ctx)
1657 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001658 if c.sabi != nil {
1659 c.sabi.begin(ctx)
1660 }
Justin Yun8effde42017-06-23 19:24:43 +09001661 if c.vndkdep != nil {
1662 c.vndkdep.begin(ctx)
1663 }
Stephen Craneba090d12017-05-09 15:44:35 -07001664 if c.lto != nil {
1665 c.lto.begin(ctx)
1666 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001667 if c.pgo != nil {
1668 c.pgo.begin(ctx)
1669 }
Colin Crossca860ac2016-01-04 14:34:37 -08001670 for _, feature := range c.features {
1671 feature.begin(ctx)
1672 }
Dan Albert92fe7402020-07-15 13:33:30 -07001673 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albertf5415d72017-08-17 16:19:59 -07001674 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001675 if err != nil {
1676 ctx.PropertyErrorf("sdk_version", err.Error())
1677 }
Nan Zhang0007d812017-11-07 10:57:05 -08001678 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001679 }
Colin Crossca860ac2016-01-04 14:34:37 -08001680}
1681
Colin Cross37047f12016-12-13 17:06:13 -08001682func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001683 deps := Deps{}
1684
1685 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001686 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001687 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001688 // Add the PGO dependency (the clang_rt.profile runtime library), which
1689 // sometimes depends on symbols from libgcc, before libgcc gets added
1690 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001691 if c.pgo != nil {
1692 deps = c.pgo.deps(ctx, deps)
1693 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001694 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001695 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001696 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001697 if c.stl != nil {
1698 deps = c.stl.deps(ctx, deps)
1699 }
Colin Cross16b23492016-01-06 14:41:07 -08001700 if c.sanitize != nil {
1701 deps = c.sanitize.deps(ctx, deps)
1702 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001703 if c.coverage != nil {
1704 deps = c.coverage.deps(ctx, deps)
1705 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001706 if c.sabi != nil {
1707 deps = c.sabi.deps(ctx, deps)
1708 }
Justin Yun8effde42017-06-23 19:24:43 +09001709 if c.vndkdep != nil {
1710 deps = c.vndkdep.deps(ctx, deps)
1711 }
Stephen Craneba090d12017-05-09 15:44:35 -07001712 if c.lto != nil {
1713 deps = c.lto.deps(ctx, deps)
1714 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001715 for _, feature := range c.features {
1716 deps = feature.deps(ctx, deps)
1717 }
1718
Colin Crossb6715442017-10-24 11:13:31 -07001719 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1720 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1721 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1722 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1723 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1724 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001725 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001726
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001727 for _, lib := range deps.ReexportSharedLibHeaders {
1728 if !inList(lib, deps.SharedLibs) {
1729 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1730 }
1731 }
1732
1733 for _, lib := range deps.ReexportStaticLibHeaders {
1734 if !inList(lib, deps.StaticLibs) {
1735 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1736 }
1737 }
1738
Colin Cross5950f382016-12-13 12:50:57 -08001739 for _, lib := range deps.ReexportHeaderLibHeaders {
1740 if !inList(lib, deps.HeaderLibs) {
1741 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1742 }
1743 }
1744
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001745 for _, gen := range deps.ReexportGeneratedHeaders {
1746 if !inList(gen, deps.GeneratedHeaders) {
1747 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1748 }
1749 }
1750
Colin Crossc99deeb2016-04-11 15:06:20 -07001751 return deps
1752}
1753
Dan Albert7e9d2952016-08-04 13:02:36 -07001754func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001755 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001756 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001757 moduleContextImpl: moduleContextImpl{
1758 mod: c,
1759 },
1760 }
1761 ctx.ctx = ctx
1762
Colin Crossca860ac2016-01-04 14:34:37 -08001763 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001764}
1765
Jiyong Park7ed9de32018-10-15 22:25:07 +09001766// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001767func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001768 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1769 version := name[sharp+1:]
1770 libname := name[:sharp]
1771 return libname, version
1772 }
1773 return name, ""
1774}
1775
Dan Albert92fe7402020-07-15 13:33:30 -07001776func GetCrtVariations(ctx android.BottomUpMutatorContext,
1777 m LinkableInterface) []blueprint.Variation {
1778 if ctx.Os() != android.Android {
1779 return nil
1780 }
1781 if m.UseSdk() {
1782 return []blueprint.Variation{
1783 {Mutator: "sdk", Variation: "sdk"},
1784 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1785 }
1786 }
1787 return []blueprint.Variation{
1788 {Mutator: "sdk", Variation: ""},
1789 }
1790}
1791
Colin Cross1e676be2016-10-12 14:38:15 -07001792func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001793 if !c.Enabled() {
1794 return
1795 }
1796
Colin Cross37047f12016-12-13 17:06:13 -08001797 ctx := &depsContext{
1798 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001799 moduleContextImpl: moduleContextImpl{
1800 mod: c,
1801 },
1802 }
1803 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001804
Colin Crossc99deeb2016-04-11 15:06:20 -07001805 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001806
Dan Albert914449f2016-06-17 16:45:24 -07001807 variantNdkLibs := []string{}
1808 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001809 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001810 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001811 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001812 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001813 // 1. Name of an NDK library that refers to a prebuilt module.
1814 // For each of these, it adds the name of the prebuilt module (which will be in
1815 // prebuilts/ndk) to the list of nonvariant libs.
1816 // 2. Name of an NDK library that refers to an ndk_library module.
1817 // For each of these, it adds the name of the ndk_library module to the list of
1818 // variant libs.
1819 // 3. Anything else (so anything that isn't an NDK library).
1820 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001821 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001822 // The caller can then know to add the variantLibs dependencies differently from the
1823 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001824
Inseob Kim9516ee92019-05-09 10:56:13 +09001825 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001826 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1827
1828 rewriteVendorLibs := func(lib string) string {
1829 if isLlndkLibrary(lib, ctx.Config()) {
1830 return lib + llndkLibrarySuffix
1831 }
1832
1833 // only modules with BOARD_VNDK_VERSION uses snapshot.
1834 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1835 return lib
1836 }
1837
1838 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1839 return snapshot
1840 }
1841
1842 return lib
1843 }
1844
1845 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001846 variantLibs = []string{}
1847 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001848 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001849 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001850 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001851 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1852 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001853 } else if ctx.useVndk() {
1854 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001855 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001856 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001857 if actx.OtherModuleExists(vendorPublicLib) {
1858 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1859 } else {
1860 // This can happen if vendor_public_library module is defined in a
1861 // namespace that isn't visible to the current module. In that case,
1862 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001863 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001864 }
Dan Albert914449f2016-06-17 16:45:24 -07001865 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001866 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001867 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001868 }
1869 }
Dan Albert914449f2016-06-17 16:45:24 -07001870 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001871 }
1872
Inseob Kimeec88e12020-01-22 11:11:29 +09001873 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1874 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1875 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1876 if ctx.useVndk() {
1877 for idx, lib := range deps.RuntimeLibs {
1878 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1879 }
1880 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001881 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001882
Jiyong Park7e636d02019-01-28 16:16:54 +09001883 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001884 if c.linker != nil {
1885 if library, ok := c.linker.(*libraryDecorator); ok {
1886 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001887 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001888 }
1889 }
1890 }
1891
Inseob Kimeec88e12020-01-22 11:11:29 +09001892 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1893 // only modules with BOARD_VNDK_VERSION uses snapshot.
1894 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1895 return lib
1896 }
1897
1898 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1899 return snapshot
1900 }
1901
1902 return lib
1903 }
1904
1905 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001906 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001907 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001908 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001909 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001910 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001911
1912 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1913
Jiyong Park7e636d02019-01-28 16:16:54 +09001914 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001915 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001916 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001917 } else {
1918 actx.AddVariationDependencies(nil, depTag, lib)
1919 }
1920 }
1921
1922 if buildStubs {
1923 // Stubs lib does not have dependency to other static/shared libraries.
1924 // Don't proceed.
1925 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001926 }
Colin Cross5950f382016-12-13 12:50:57 -08001927
Inseob Kimc0907f12019-02-08 21:00:45 +09001928 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001929 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001930
Jiyong Park5d1598f2019-02-25 22:14:17 +09001931 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001932 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001933 if impl, ok := syspropImplLibraries[lib]; ok {
1934 lib = impl
1935 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001936
1937 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1938
Jiyong Park5d1598f2019-02-25 22:14:17 +09001939 actx.AddVariationDependencies([]blueprint.Variation{
1940 {Mutator: "link", Variation: "static"},
1941 }, depTag, lib)
1942 }
1943
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001944 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001945 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001946 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001947 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001948 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001949
1950 if impl, ok := syspropImplLibraries[lib]; ok {
1951 lib = impl
1952 }
1953
Inseob Kimeec88e12020-01-22 11:11:29 +09001954 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1955
Dan Willemsen59339a22018-07-22 21:18:45 -07001956 actx.AddVariationDependencies([]blueprint.Variation{
1957 {Mutator: "link", Variation: "static"},
1958 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001959 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001960
Jooyung Han75568392020-03-20 04:29:24 +09001961 // staticUnwinderDep is treated as staticDep for Q apexes
1962 // so that native libraries/binaries are linked with static unwinder
1963 // because Q libc doesn't have unwinder APIs
1964 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001965 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001966 actx.AddVariationDependencies([]blueprint.Variation{
1967 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001968 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001969 }
1970
Inseob Kimeec88e12020-01-22 11:11:29 +09001971 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001972 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001973 actx.AddVariationDependencies([]blueprint.Variation{
1974 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001975 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001976 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001977
Colin Cross6e511a92020-07-27 21:26:48 -07001978 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001979 var variations []blueprint.Variation
1980 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001981 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001982 // Version is explicitly specified. i.e. libFoo#30
1983 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07001984 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001985 }
1986 actx.AddVariationDependencies(variations, depTag, name)
1987
Jooyung Han03b51852020-02-26 22:45:42 +09001988 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001989 // The stubs library will be used when the depending module is built for APEX and
1990 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09001991 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09001992 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1993 // Note that depTag.ExplicitlyVersioned is false in this case.
1994 actx.AddVariationDependencies([]blueprint.Variation{
1995 {Mutator: "link", Variation: "shared"},
1996 {Mutator: "version", Variation: ver},
1997 }, depTag, name)
1998 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001999 }
2000 }
2001
Jiyong Park7ed9de32018-10-15 22:25:07 +09002002 // shared lib names without the #version suffix
2003 var sharedLibNames []string
2004
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002005 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002006 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002007 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002008 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002009 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002010
2011 if impl, ok := syspropImplLibraries[lib]; ok {
2012 lib = impl
2013 }
2014
Jiyong Park73c54ee2019-10-22 20:31:18 +09002015 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002016 sharedLibNames = append(sharedLibNames, name)
2017
Jiyong Park25fc6a92018-11-18 18:02:45 +09002018 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002019 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002020
Jiyong Park7ed9de32018-10-15 22:25:07 +09002021 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002022 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002023 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2024 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2025 // linking against both the stubs lib and the non-stubs lib at the same time.
2026 continue
2027 }
Colin Cross6e511a92020-07-27 21:26:48 -07002028 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2029 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002030 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002031
Dan Willemsen59339a22018-07-22 21:18:45 -07002032 actx.AddVariationDependencies([]blueprint.Variation{
2033 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002034 }, dataLibDepTag, deps.DataLibs...)
2035
2036 actx.AddVariationDependencies([]blueprint.Variation{
2037 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002038 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002039
Colin Cross68861832016-07-08 10:41:41 -07002040 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002041
2042 for _, gen := range deps.GeneratedHeaders {
2043 depTag := genHeaderDepTag
2044 if inList(gen, deps.ReexportGeneratedHeaders) {
2045 depTag = genHeaderExportDepTag
2046 }
2047 actx.AddDependency(c, depTag, gen)
2048 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002049
Colin Cross42d48b72018-08-29 14:10:52 -07002050 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002051
Inseob Kim1042d292020-06-01 23:23:05 +09002052 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2053
Dan Albert92fe7402020-07-15 13:33:30 -07002054 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002055 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002056 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2057 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002058 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002059 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002060 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2061 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002062 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002063 if deps.LinkerFlagsFile != "" {
2064 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2065 }
2066 if deps.DynamicLinker != "" {
2067 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002068 }
Dan Albert914449f2016-06-17 16:45:24 -07002069
2070 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002071
2072 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002073 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002074 {Mutator: "ndk_api", Variation: version},
2075 {Mutator: "link", Variation: "shared"},
2076 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002077
2078 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002079 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002080 {Mutator: "ndk_api", Variation: version},
2081 {Mutator: "link", Variation: "shared"},
2082 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002083
2084 if vndkdep := c.vndkdep; vndkdep != nil {
2085 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002086 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002087 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002088 {Mutator: "link", Variation: "shared"},
2089 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002090 }
2091 }
Colin Cross6362e272015-10-29 15:25:03 -07002092}
Colin Cross21b9a242015-03-24 14:15:58 -07002093
Colin Crosse40b4ea2018-10-02 22:25:58 -07002094func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002095 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2096 c.beginMutator(ctx)
2097 }
2098}
2099
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002100// Whether a module can link to another module, taking into
2101// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002102func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2103 tag blueprint.DependencyTag) {
2104
2105 switch t := tag.(type) {
2106 case dependencyTag:
2107 if t != vndkExtDepTag {
2108 return
2109 }
2110 case libraryDependencyTag:
2111 default:
2112 return
2113 }
2114
Ivan Lozano52767be2019-10-18 14:49:46 -07002115 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002116 // Host code is not restricted
2117 return
2118 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002119
2120 // VNDK is cc.Module supported only for now.
2121 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002122 // Though vendor code is limited by the vendor mutator,
2123 // each vendor-available module needs to check
2124 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002125 if ccTo, ok := to.(*Module); ok {
2126 if ccFrom.vndkdep != nil {
2127 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2128 }
2129 } else {
2130 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002131 }
2132 return
2133 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002134 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002135 // Platform code can link to anything
2136 return
2137 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002138 if from.InRamdisk() {
2139 // Ramdisk code is not NDK
2140 return
2141 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002142 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002143 // Recovery code is not NDK
2144 return
2145 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002146 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002147 // These are always allowed
2148 return
2149 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002150 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 // These are allowed, but they don't set sdk_version
2152 return
2153 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002154 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002155 // These aren't real libraries, but are the stub shared libraries that are included in
2156 // the NDK.
2157 return
2158 }
Logan Chien834b9a62019-01-14 15:39:03 +08002159
Ivan Lozano52767be2019-10-18 14:49:46 -07002160 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002161 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2162 // to link to libc++ (non-NDK and without sdk_version).
2163 return
2164 }
2165
Ivan Lozano52767be2019-10-18 14:49:46 -07002166 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002167 // NDK code linking to platform code is never okay.
2168 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002169 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002170 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002171 }
2172
2173 // At this point we know we have two NDK libraries, but we need to
2174 // check that we're not linking against anything built against a higher
2175 // API level, as it is only valid to link against older or equivalent
2176 // APIs.
2177
Inseob Kim01a28722018-04-11 09:48:45 +09002178 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002179 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002180 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002181 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002182 // Current can't be linked against by anything else.
2183 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002184 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002185 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002186 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002187 if err != nil {
2188 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002189 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002190 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002191 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002192 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002193 if err != nil {
2194 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002195 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002196 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002197 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002198
Inseob Kim01a28722018-04-11 09:48:45 +09002199 if toApi > fromApi {
2200 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002201 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002202 }
2203 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002204 }
Dan Albert202fe492017-12-15 13:56:59 -08002205
2206 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002207 fromStl := from.SelectedStl()
2208 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002209 if fromStl == "" || toStl == "" {
2210 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002211 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002212 // We can be permissive with the system "STL" since it is only the C++
2213 // ABI layer, but in the future we should make sure that everyone is
2214 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002215 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002216 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002217 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2218 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002219 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002220}
2221
Jiyong Park5fb8c102018-04-09 12:03:06 +09002222// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002223// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2224// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002225// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002226func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2227 check := func(child, parent android.Module) bool {
2228 to, ok := child.(*Module)
2229 if !ok {
2230 // follow thru cc.Defaults, etc.
2231 return true
2232 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002233
Jooyung Hana70f0672019-01-18 15:20:43 +09002234 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2235 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002236 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002237
2238 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002239 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002240 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002241 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002242
Jooyung Han0302a842019-10-30 18:43:49 +09002243 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002244 return false
2245 }
2246
2247 var stringPath []string
2248 for _, m := range ctx.GetWalkPath() {
2249 stringPath = append(stringPath, m.Name())
2250 }
2251 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2252 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2253 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2254 return false
2255 }
2256 if module, ok := ctx.Module().(*Module); ok {
2257 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002258 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002259 ctx.WalkDeps(check)
2260 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002261 }
2262 }
2263}
2264
Colin Crossc99deeb2016-04-11 15:06:20 -07002265// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002266func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002267 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002268
Ivan Lozano183a3212019-10-18 14:18:45 -07002269 directStaticDeps := []LinkableInterface{}
2270 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002271
Inseob Kim69378442019-06-03 19:10:47 +09002272 reexportExporter := func(exporter exportedFlagsProducer) {
2273 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2274 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2275 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2276 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002277 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002278 }
2279
Jooyung Hande34d232020-07-23 13:04:15 +09002280 // For the dependency from platform to apex, use the latest stubs
2281 c.apexSdkVersion = android.FutureApiLevel
2282 if !c.IsForPlatform() {
2283 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2284 }
2285
2286 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2287 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2288 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2289 // (b/144430859)
2290 c.apexSdkVersion = android.FutureApiLevel
2291 }
2292
Colin Crossd11fcda2017-10-23 17:59:01 -07002293 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002294 depName := ctx.OtherModuleName(dep)
2295 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002296
Ivan Lozano52767be2019-10-18 14:49:46 -07002297 ccDep, ok := dep.(LinkableInterface)
2298 if !ok {
2299
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002300 // handling for a few module types that aren't cc Module but that are also supported
2301 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002302 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002303 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002304 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2305 genRule.GeneratedSourceFiles()...)
2306 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002307 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002308 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002309 // Support exported headers from a generated_sources dependency
2310 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002311 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002312 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002313 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002314 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002315 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002316 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002317 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002318 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002319 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2320 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002321 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002322 // 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 +09002323 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002324
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002325 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002326 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002327 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002328 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002329 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002330 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002331 files := genRule.GeneratedSourceFiles()
2332 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002333 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002334 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002335 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 -07002336 }
2337 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002338 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002339 }
Colin Crossca860ac2016-01-04 14:34:37 -08002340 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002341 return
2342 }
2343
Colin Crossfe17f6f2019-03-28 19:30:56 -07002344 if depTag == android.ProtoPluginDepTag {
2345 return
2346 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002347 if depTag == llndkImplDep {
2348 return
2349 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002350
Colin Crossd11fcda2017-10-23 17:59:01 -07002351 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002352 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2353 return
2354 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002355 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002356 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2357 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002358 return
2359 }
2360
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002361 // re-exporting flags
2362 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002363 // reusing objects only make sense for cc.Modules.
2364 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002365 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002366 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002367 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002368 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002369 return
2370 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002371 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002372
Jiyong Parke4bb9862019-02-01 00:31:10 +09002373 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002374 // staticVariants are a cc.Module specific concept.
2375 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002376 c.staticVariant = ccDep
2377 return
2378 }
2379 }
2380
Colin Cross6e511a92020-07-27 21:26:48 -07002381 checkLinkType(ctx, c, ccDep, depTag)
2382
2383 linkFile := ccDep.OutputFile()
2384
2385 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2386 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2387 if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002388 return
2389 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002390
Colin Cross6e511a92020-07-27 21:26:48 -07002391 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002392 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002393 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002394 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002395 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002396
2397 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002398 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002399 // Always respect dependency to the versioned stubs (i.e. libX#10)
2400 useThisDep = true
2401 } else if !depHasStubs {
2402 // Use non-stub variant if that is the only choice
2403 // (i.e. depending on a lib without stubs.version property)
2404 useThisDep = true
2405 } else if c.IsForPlatform() {
2406 // If not building for APEX, use stubs only when it is from
2407 // an APEX (and not from platform)
2408 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002409 if c.bootstrap() {
2410 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002411 // always link to non-stub variant
2412 useThisDep = !depIsStubs
2413 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002414 for _, testFor := range c.TestFor() {
2415 // Another exception: if this module is bundled with an APEX, then
2416 // it is linked with the non-stub variant of a module in the APEX
2417 // as if this is part of the APEX.
2418 if android.DirectlyInApex(testFor, depName) {
2419 useThisDep = !depIsStubs
2420 break
2421 }
2422 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002423 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002424 // If building for APEX, use stubs when the parent is in any APEX that
2425 // the child is not in.
2426 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002427 }
2428
Jooyung Han03b51852020-02-26 22:45:42 +09002429 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002430 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002431 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002432 if err != nil {
2433 ctx.OtherModuleErrorf(dep, err.Error())
2434 return
2435 }
2436 if versionToUse != ccDep.StubsVersion() {
2437 useThisDep = false
2438 }
2439 }
2440
Jiyong Park25fc6a92018-11-18 18:02:45 +09002441 if !useThisDep {
2442 return // stop processing this dep
2443 }
2444 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002445 if c.UseVndk() {
2446 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2447 // by default, use current version of LLNDK
2448 versionToUse := ""
2449 versions := stubsVersionsFor(ctx.Config())[depName]
Colin Crosse07f2312020-08-13 11:24:56 -07002450 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002451 // if this is for use_vendor apex && dep has stubsVersions
2452 // apply the same rule of apex sdk enforcement to choose right version
2453 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002454 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002455 if err != nil {
2456 ctx.OtherModuleErrorf(dep, err.Error())
2457 return
2458 }
2459 }
2460 if versionToUse != ccDep.StubsVersion() {
2461 return
2462 }
2463 }
2464 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002465
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002466 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2467
Ivan Lozano52767be2019-10-18 14:49:46 -07002468 // Exporting flags only makes sense for cc.Modules
2469 if _, ok := ccDep.(*Module); ok {
2470 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002471 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002472 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002473 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002474
Colin Cross6e511a92020-07-27 21:26:48 -07002475 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002476 reexportExporter(i)
2477 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2478 // Re-exported shared library headers must be included as well since they can help us with type information
2479 // about template instantiations (instantiated from their headers).
2480 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2481 // scripts.
2482 c.sabi.Properties.ReexportedIncludes = append(
2483 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2484 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002485 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002486 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002487
Colin Cross6e511a92020-07-27 21:26:48 -07002488 var ptr *android.Paths
2489 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002490
Colin Cross6e511a92020-07-27 21:26:48 -07002491 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002492
Colin Cross6e511a92020-07-27 21:26:48 -07002493 switch {
2494 case libDepTag.header():
2495 // nothing
2496 case libDepTag.shared():
2497 ptr = &depPaths.SharedLibs
2498 switch libDepTag.Order {
2499 case earlyLibraryDependency:
2500 ptr = &depPaths.EarlySharedLibs
2501 depPtr = &depPaths.EarlySharedLibsDeps
2502 case normalLibraryDependency:
2503 ptr = &depPaths.SharedLibs
2504 depPtr = &depPaths.SharedLibsDeps
2505 directSharedDeps = append(directSharedDeps, ccDep)
2506 case lateLibraryDependency:
2507 ptr = &depPaths.LateSharedLibs
2508 depPtr = &depPaths.LateSharedLibsDeps
2509 default:
2510 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002511 }
Colin Cross6e511a92020-07-27 21:26:48 -07002512 depFile = ccDep.Toc()
2513 case libDepTag.static():
2514 if libDepTag.wholeStatic {
2515 ptr = &depPaths.WholeStaticLibs
2516 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2517 ctx.ModuleErrorf("module %q not a static library", depName)
2518 return
Inseob Kim752edec2020-03-14 01:30:34 +09002519 }
2520
Colin Cross6e511a92020-07-27 21:26:48 -07002521 // Because the static library objects are included, this only makes sense
2522 // in the context of proper cc.Modules.
2523 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2524 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2525 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2526 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2527 for i := range missingDeps {
2528 missingDeps[i] += postfix
2529 }
2530 ctx.AddMissingDependencies(missingDeps)
2531 }
2532 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2533 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2534 } else {
2535 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2536 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002537 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002538 ctx.ModuleErrorf(
2539 "non-cc.Modules cannot be included as whole static libraries.", depName)
2540 return
2541 }
2542
2543 } else {
2544 switch libDepTag.Order {
2545 case earlyLibraryDependency:
2546 panic(fmt.Errorf("early static libs not suppported"))
2547 case normalLibraryDependency:
2548 // static dependencies will be handled separately so they can be ordered
2549 // using transitive dependencies.
2550 ptr = nil
2551 directStaticDeps = append(directStaticDeps, ccDep)
2552 case lateLibraryDependency:
2553 ptr = &depPaths.LateStaticLibs
2554 default:
2555 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002556 }
2557 }
2558 }
2559
Colin Cross6e511a92020-07-27 21:26:48 -07002560 if libDepTag.static() && !libDepTag.wholeStatic {
2561 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2562 ctx.ModuleErrorf("module %q not a static library", depName)
2563 return
2564 }
Logan Chien43d34c32017-12-20 01:17:32 +08002565
Colin Cross6e511a92020-07-27 21:26:48 -07002566 // When combining coverage files for shared libraries and executables, coverage files
2567 // in static libraries act as if they were whole static libraries. The same goes for
2568 // source based Abi dump files.
2569 if c, ok := ccDep.(*Module); ok {
2570 staticLib := c.linker.(libraryInterface)
2571 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2572 staticLib.objs().coverageFiles...)
2573 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2574 staticLib.objs().sAbiDumpFiles...)
2575 } else if c, ok := ccDep.(LinkableInterface); ok {
2576 // Handle non-CC modules here
2577 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2578 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002579 }
2580 }
2581
Colin Cross6e511a92020-07-27 21:26:48 -07002582 if ptr != nil {
2583 if !linkFile.Valid() {
2584 if !ctx.Config().AllowMissingDependencies() {
2585 ctx.ModuleErrorf("module %q missing output file", depName)
2586 } else {
2587 ctx.AddMissingDependencies([]string{depName})
2588 }
2589 return
2590 }
2591 *ptr = append(*ptr, linkFile.Path())
2592 }
2593
2594 if depPtr != nil {
2595 dep := depFile
2596 if !dep.Valid() {
2597 dep = linkFile
2598 }
2599 *depPtr = append(*depPtr, dep.Path())
2600 }
2601
2602 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2603 switch {
2604 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002605 c.Properties.AndroidMkHeaderLibs = append(
2606 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002607 case libDepTag.shared():
2608 if ccDep.CcLibrary() {
2609 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2610 // Add the dependency to the APEX(es) providing the library so that
2611 // m <module> can trigger building the APEXes as well.
2612 for _, an := range android.GetApexesForModule(depName) {
2613 c.Properties.ApexesProvidingSharedLibs = append(
2614 c.Properties.ApexesProvidingSharedLibs, an)
2615 }
2616 }
2617 }
2618
2619 // Note: the order of libs in this list is not important because
2620 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002621 c.Properties.AndroidMkSharedLibs = append(
2622 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002623 // Record baseLibName for snapshots.
2624 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2625 case libDepTag.static():
2626 if libDepTag.wholeStatic {
2627 c.Properties.AndroidMkWholeStaticLibs = append(
2628 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2629 } else {
2630 c.Properties.AndroidMkStaticLibs = append(
2631 c.Properties.AndroidMkStaticLibs, makeLibName)
2632 }
2633 }
2634 } else {
2635 switch depTag {
2636 case runtimeDepTag:
2637 c.Properties.AndroidMkRuntimeLibs = append(
2638 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2639 // Record baseLibName for snapshots.
2640 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2641 case objDepTag:
2642 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2643 case CrtBeginDepTag:
2644 depPaths.CrtBegin = linkFile
2645 case CrtEndDepTag:
2646 depPaths.CrtEnd = linkFile
2647 case dynamicLinkerDepTag:
2648 depPaths.DynamicLinker = linkFile
2649 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002650 }
Colin Crossca860ac2016-01-04 14:34:37 -08002651 })
2652
Jeff Gaston294356f2017-09-27 17:05:30 -07002653 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002654 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002655
Colin Crossdd84e052017-05-17 13:44:16 -07002656 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002657 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002658 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2659 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002660 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002661 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2662 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002663 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002664 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002665 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002666
2667 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002668 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002669 }
Colin Crossdd84e052017-05-17 13:44:16 -07002670
Colin Crossca860ac2016-01-04 14:34:37 -08002671 return depPaths
2672}
2673
Colin Cross6e511a92020-07-27 21:26:48 -07002674// baseLibName trims known prefixes and suffixes
2675func baseLibName(depName string) string {
2676 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2677 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2678 libName = strings.TrimPrefix(libName, "prebuilt_")
2679 return libName
2680}
2681
2682func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2683 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2684 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2685
2686 libName := baseLibName(depName)
2687 isLLndk := isLlndkLibrary(libName, ctx.Config())
2688 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2689 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2690
2691 if c, ok := ccDep.(*Module); ok {
2692 // Use base module name for snapshots when exporting to Makefile.
2693 if c.isSnapshotPrebuilt() {
2694 baseName := c.BaseModuleName()
2695
2696 if c.IsVndk() {
2697 return baseName + ".vendor"
2698 }
2699
2700 if vendorSuffixModules[baseName] {
2701 return baseName + ".vendor"
2702 } else {
2703 return baseName
2704 }
2705 }
2706 }
2707
2708 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2709 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2710 // core module instead.
2711 return libName
2712 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2713 // The vendor module in Make will have been renamed to not conflict with the core
2714 // module, so update the dependency name here accordingly.
2715 return libName + c.getNameSuffixWithVndkVersion(ctx)
2716 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2717 return libName + vendorPublicLibrarySuffix
2718 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2719 return libName + ramdiskSuffix
2720 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2721 return libName + recoverySuffix
2722 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2723 return libName + nativeBridgeSuffix
2724 } else {
2725 return libName
2726 }
2727}
2728
Colin Crossca860ac2016-01-04 14:34:37 -08002729func (c *Module) InstallInData() bool {
2730 if c.installer == nil {
2731 return false
2732 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002733 return c.installer.inData()
2734}
2735
2736func (c *Module) InstallInSanitizerDir() bool {
2737 if c.installer == nil {
2738 return false
2739 }
2740 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002741 return true
2742 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002743 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002744}
2745
Yifan Hong1b3348d2020-01-21 15:53:22 -08002746func (c *Module) InstallInRamdisk() bool {
2747 return c.InRamdisk()
2748}
2749
Jiyong Parkf9332f12018-02-01 00:54:12 +09002750func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002751 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002752}
2753
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002754func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002755 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002756 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002757 return
2758 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002759 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002760}
2761
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002762func (c *Module) HostToolPath() android.OptionalPath {
2763 if c.installer == nil {
2764 return android.OptionalPath{}
2765 }
2766 return c.installer.hostToolPath()
2767}
2768
Nan Zhangd4e641b2017-07-12 12:55:28 -07002769func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2770 return c.outputFile
2771}
2772
Colin Cross41955e82019-05-29 14:40:35 -07002773func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2774 switch tag {
2775 case "":
2776 if c.outputFile.Valid() {
2777 return android.Paths{c.outputFile.Path()}, nil
2778 }
2779 return android.Paths{}, nil
2780 default:
2781 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002782 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002783}
2784
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002785func (c *Module) static() bool {
2786 if static, ok := c.linker.(interface {
2787 static() bool
2788 }); ok {
2789 return static.static()
2790 }
2791 return false
2792}
2793
Jiyong Park379de2f2018-12-19 02:47:14 +09002794func (c *Module) staticBinary() bool {
2795 if static, ok := c.linker.(interface {
2796 staticBinary() bool
2797 }); ok {
2798 return static.staticBinary()
2799 }
2800 return false
2801}
2802
Jiyong Park1d1119f2019-07-29 21:27:18 +09002803func (c *Module) header() bool {
2804 if h, ok := c.linker.(interface {
2805 header() bool
2806 }); ok {
2807 return h.header()
2808 }
2809 return false
2810}
2811
Inseob Kim7f283f42020-06-01 21:53:49 +09002812func (c *Module) binary() bool {
2813 if b, ok := c.linker.(interface {
2814 binary() bool
2815 }); ok {
2816 return b.binary()
2817 }
2818 return false
2819}
2820
Inseob Kim1042d292020-06-01 23:23:05 +09002821func (c *Module) object() bool {
2822 if o, ok := c.linker.(interface {
2823 object() bool
2824 }); ok {
2825 return o.object()
2826 }
2827 return false
2828}
2829
Jooyung Han38002912019-05-16 04:01:54 +09002830func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002831 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002832 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2833 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002834 return "native:vndk"
2835 }
Jooyung Han38002912019-05-16 04:01:54 +09002836 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002837 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002838 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002839 if Bool(c.VendorProperties.Vendor_available) {
2840 return "native:vndk"
2841 }
2842 return "native:vndk_private"
2843 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002844 if c.inProduct() {
2845 return "native:product"
2846 }
Jooyung Han38002912019-05-16 04:01:54 +09002847 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002848 } else if c.InRamdisk() {
2849 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002850 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002851 return "native:recovery"
2852 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2853 return "native:ndk:none:none"
2854 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2855 //family, link := getNdkStlFamilyAndLinkType(c)
2856 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002857 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002858 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002859 } else {
2860 return "native:platform"
2861 }
2862}
2863
Jiyong Park9d452992018-10-03 00:38:19 +09002864// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002865// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002866func (c *Module) IsInstallableToApex() bool {
2867 if shared, ok := c.linker.(interface {
2868 shared() bool
2869 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002870 // Stub libs and prebuilt libs in a versioned SDK are not
2871 // installable to APEX even though they are shared libs.
2872 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002873 } else if _, ok := c.linker.(testPerSrc); ok {
2874 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002875 }
2876 return false
2877}
2878
Jiyong Parka90ca002019-10-07 15:47:24 +09002879func (c *Module) AvailableFor(what string) bool {
2880 if linker, ok := c.linker.(interface {
2881 availableFor(string) bool
2882 }); ok {
2883 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2884 } else {
2885 return c.ApexModuleBase.AvailableFor(what)
2886 }
2887}
2888
Jiyong Park62304bb2020-04-13 16:19:48 +09002889func (c *Module) TestFor() []string {
2890 if test, ok := c.linker.(interface {
2891 testFor() []string
2892 }); ok {
2893 return test.testFor()
2894 } else {
2895 return c.ApexModuleBase.TestFor()
2896 }
2897}
2898
Colin Crossaede88c2020-08-11 12:17:01 -07002899func (c *Module) UniqueApexVariations() bool {
2900 if u, ok := c.compiler.(interface {
2901 uniqueApexVariations() bool
2902 }); ok {
2903 return u.uniqueApexVariations()
2904 } else {
2905 return false
2906 }
2907}
2908
Paul Duffin0cb37b92020-03-04 14:52:46 +00002909// Return true if the module is ever installable.
2910func (c *Module) EverInstallable() bool {
2911 return c.installer != nil &&
2912 // Check to see whether the module is actually ever installable.
2913 c.installer.everInstallable()
2914}
2915
Inseob Kim1f086e22019-05-09 13:29:15 +09002916func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002917 ret := c.EverInstallable() &&
2918 // Check to see whether the module has been configured to not be installed.
2919 proptools.BoolDefault(c.Properties.Installable, true) &&
2920 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002921
2922 // The platform variant doesn't need further condition. Apex variants however might not
2923 // be installable because it will likely to be included in the APEX and won't appear
2924 // in the system partition.
2925 if c.IsForPlatform() {
2926 return ret
2927 }
2928
2929 // Special case for modules that are configured to be installed to /data, which includes
2930 // test modules. For these modules, both APEX and non-APEX variants are considered as
2931 // installable. This is because even the APEX variants won't be included in the APEX, but
2932 // will anyway be installed to /data/*.
2933 // See b/146995717
2934 if c.InstallInData() {
2935 return ret
2936 }
2937
2938 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002939}
2940
Logan Chien41eabe62019-04-10 13:33:58 +08002941func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2942 if c.linker != nil {
2943 if library, ok := c.linker.(*libraryDecorator); ok {
2944 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2945 }
2946 }
2947}
2948
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002949func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002950 depTag := ctx.OtherModuleDependencyTag(dep)
2951 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2952
2953 if cc, ok := dep.(*Module); ok {
2954 if cc.HasStubsVariants() {
2955 if isLibDepTag && libDepTag.shared() {
2956 // dynamic dep to a stubs lib crosses APEX boundary
2957 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002958 }
Colin Cross6e511a92020-07-27 21:26:48 -07002959 if IsRuntimeDepTag(depTag) {
2960 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002961 return false
2962 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002963 }
Colin Crossaac32222020-07-29 12:51:56 -07002964 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002965 // shared_lib dependency from a static lib is considered as crossing
2966 // the APEX boundary because the dependency doesn't actually is
2967 // linked; the dependency is used only during the compilation phase.
2968 return false
2969 }
2970 }
2971 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09002972 // We don't track beyond LLNDK
2973 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002974 }
2975 return true
2976}
2977
Jooyung Han749dc692020-04-15 11:03:39 +09002978// b/154667674: refactor this to handle "current" in a consistent way
2979func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
2980 if versionString == "" {
2981 return 0, fmt.Errorf("not specified")
2982 }
2983 if versionString == "current" {
2984 if ctx.Config().PlatformSdkCodename() == "REL" {
2985 return ctx.Config().PlatformSdkVersionInt(), nil
2986 }
2987 return android.FutureApiLevel, nil
2988 }
2989 return android.ApiStrToNum(ctx, versionString)
2990}
2991
2992func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
2993 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
2994 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
2995 return nil
2996 }
2997 // b/154569636: set min_sdk_version correctly for toolchain_libraries
2998 if c.ToolchainLibrary() {
2999 return nil
3000 }
3001 // We don't check for prebuilt modules
3002 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3003 return nil
3004 }
3005 minSdkVersion := c.MinSdkVersion()
3006 if minSdkVersion == "apex_inherit" {
3007 return nil
3008 }
3009 if minSdkVersion == "" {
3010 // JNI libs within APK-in-APEX fall into here
3011 // Those are okay to set sdk_version instead
3012 // We don't have to check if this is a SDK variant because
3013 // non-SDK variant resets sdk_version, which works too.
3014 minSdkVersion = c.SdkVersion()
3015 }
3016 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
3017 if err != nil {
3018 return err
3019 }
3020 if ver > sdkVersion {
3021 return fmt.Errorf("newer SDK(%v)", ver)
3022 }
3023 return nil
3024}
3025
Colin Cross2ba19d92015-05-07 15:44:20 -07003026//
Colin Crosscfad1192015-11-02 16:43:11 -08003027// Defaults
3028//
Colin Crossca860ac2016-01-04 14:34:37 -08003029type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003030 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003031 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003032 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003033}
3034
Patrice Arrudac249c712019-03-19 17:00:29 -07003035// cc_defaults provides a set of properties that can be inherited by other cc
3036// modules. A module can use the properties from a cc_defaults using
3037// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3038// merged (when possible) by prepending the default module's values to the
3039// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003040func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003041 return DefaultsFactory()
3042}
3043
Colin Cross36242852017-06-23 15:06:31 -07003044func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003045 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003046
Colin Cross36242852017-06-23 15:06:31 -07003047 module.AddProperties(props...)
3048 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003049 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003050 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003051 &BaseCompilerProperties{},
3052 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003053 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003054 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003055 &StaticProperties{},
3056 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003057 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003058 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003059 &TestProperties{},
3060 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003061 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003062 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003063 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003064 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003065 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003066 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003067 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003068 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003069 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003070 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003071 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003072 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003073 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003074 )
Colin Crosscfad1192015-11-02 16:43:11 -08003075
Jooyung Hancc372c52019-09-25 15:18:44 +09003076 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003077
3078 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003079}
3080
Jiyong Park6a43f042017-10-12 23:05:00 +09003081func squashVendorSrcs(m *Module) {
3082 if lib, ok := m.compiler.(*libraryDecorator); ok {
3083 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3084 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3085
3086 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3087 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003088
3089 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3090 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003091 }
3092}
3093
Jiyong Parkf9332f12018-02-01 00:54:12 +09003094func squashRecoverySrcs(m *Module) {
3095 if lib, ok := m.compiler.(*libraryDecorator); ok {
3096 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3097 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3098
3099 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3100 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003101
3102 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3103 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003104 }
3105}
3106
Jiyong Park2286afd2020-06-16 21:58:53 +09003107func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003108 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003109}
3110
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003111func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003112 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003113 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3114 }
Colin Cross6510f912017-11-29 00:27:14 -08003115 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003116}
3117
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003118func kytheExtractAllFactory() android.Singleton {
3119 return &kytheExtractAllSingleton{}
3120}
3121
3122type kytheExtractAllSingleton struct {
3123}
3124
3125func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3126 var xrefTargets android.Paths
3127 ctx.VisitAllModules(func(module android.Module) {
3128 if ccModule, ok := module.(xref); ok {
3129 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3130 }
3131 })
3132 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3133 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003134 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003135 }
3136}
3137
Colin Cross06a931b2015-10-28 17:23:31 -07003138var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003139var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003140var BoolPtr = proptools.BoolPtr
3141var String = proptools.String
3142var StringPtr = proptools.StringPtr