blob: 70229be5a90979744ff024e93332b1e325511556 [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"`
Bill Peckham945441c2020-08-31 16:07:58 -0700283
284 // Normally Soong uses the directory structure to decide which modules
285 // should be included (framework) or excluded (non-framework) from the
286 // vendor snapshot, but this property allows a partner to exclude a
287 // module normally thought of as a framework module from the vendor
288 // snapshot.
289 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700290}
291
292type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900293 // whether this module should be allowed to be directly depended by other
294 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900295 // In addition, this module should be allowed to be directly depended by
296 // product modules with `product_specific: true`.
297 // If set to true, three variants will be built separately, one like
298 // normal, another limited to the set of libraries and headers
299 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700300 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900301 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700302 // so it shouldn't have any unversioned runtime dependencies, or
303 // make assumptions about the system that may not be true in the
304 // future.
305 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900306 // If set to false, this module becomes inaccessible from /vendor or /product
307 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900308 //
309 // Default value is true when vndk: {enabled: true} or vendor: true.
310 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700311 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900312 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700313 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900314
315 // whether this module is capable of being loaded with other instance
316 // (possibly an older version) of the same module in the same process.
317 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
318 // can be double loaded in a vendor process if the library is also a
319 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
320 // explicitly marked as `double_loadable: true` by the owner, or the dependency
321 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
322 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
Colin Crossca860ac2016-01-04 14:34:37 -0800325type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800326 static() bool
327 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900328 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900329 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900330 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700331 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900332 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700333 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800334 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700335 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800336 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900337 isLlndk(config android.Config) bool
338 isLlndkPublic(config android.Config) bool
339 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900340 isVndk() bool
341 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800342 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900343 inProduct() bool
344 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800345 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900346 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800347 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700348 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700349 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800350 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800351 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800352 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800353 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800354 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700355 apexVariationName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900356 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900357 hasStubsVariants() bool
358 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900359 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800360 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700361 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800362}
363
364type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700365 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800366 ModuleContextIntf
367}
368
369type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700370 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800371 ModuleContextIntf
372}
373
Colin Cross37047f12016-12-13 17:06:13 -0800374type DepsContext interface {
375 android.BottomUpMutatorContext
376 ModuleContextIntf
377}
378
Colin Crossca860ac2016-01-04 14:34:37 -0800379type feature interface {
380 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800381 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800382 flags(ctx ModuleContext, flags Flags) Flags
383 props() []interface{}
384}
385
386type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700387 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800388 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800389 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700390 compilerProps() []interface{}
391
Colin Cross76fada02016-07-27 10:31:13 -0700392 appendCflags([]string)
393 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700394 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800395}
396
397type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700398 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800399 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700400 linkerFlags(ctx ModuleContext, flags Flags) Flags
401 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800402 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700403
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700404 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700405 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900406 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700407
408 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900409 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000410
411 // Get the deps that have been explicitly specified in the properties.
412 // Only updates the
413 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
414}
415
416type specifiedDeps struct {
417 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000418 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800419}
420
421type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700422 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700423 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000424 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800425 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700426 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700427 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900428 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100429 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800430}
431
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800432type xref interface {
433 XrefCcFiles() android.Paths
434}
435
Colin Cross6e511a92020-07-27 21:26:48 -0700436type libraryDependencyKind int
437
438const (
439 headerLibraryDependency = iota
440 sharedLibraryDependency
441 staticLibraryDependency
442)
443
444func (k libraryDependencyKind) String() string {
445 switch k {
446 case headerLibraryDependency:
447 return "headerLibraryDependency"
448 case sharedLibraryDependency:
449 return "sharedLibraryDependency"
450 case staticLibraryDependency:
451 return "staticLibraryDependency"
452 default:
453 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
454 }
455}
456
457type libraryDependencyOrder int
458
459const (
460 earlyLibraryDependency = -1
461 normalLibraryDependency = 0
462 lateLibraryDependency = 1
463)
464
465func (o libraryDependencyOrder) String() string {
466 switch o {
467 case earlyLibraryDependency:
468 return "earlyLibraryDependency"
469 case normalLibraryDependency:
470 return "normalLibraryDependency"
471 case lateLibraryDependency:
472 return "lateLibraryDependency"
473 default:
474 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
475 }
476}
477
478// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
479// tags that have a set of predefined tag objects that are reused for each dependency, a
480// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
481// That means that comparing a libraryDependencyTag for equality will only be equal if all
482// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
483// then check individual metadata fields instead.
484type libraryDependencyTag struct {
485 blueprint.BaseDependencyTag
486
487 // These are exported so that fmt.Printf("%#v") can call their String methods.
488 Kind libraryDependencyKind
489 Order libraryDependencyOrder
490
491 wholeStatic bool
492
493 reexportFlags bool
494 explicitlyVersioned bool
495 dataLib bool
496 ndk bool
497
498 staticUnwinder bool
499
500 makeSuffix string
501}
502
503// header returns true if the libraryDependencyTag is tagging a header lib dependency.
504func (d libraryDependencyTag) header() bool {
505 return d.Kind == headerLibraryDependency
506}
507
508// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
509func (d libraryDependencyTag) shared() bool {
510 return d.Kind == sharedLibraryDependency
511}
512
513// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
514func (d libraryDependencyTag) static() bool {
515 return d.Kind == staticLibraryDependency
516}
517
518// dependencyTag is used for tagging miscellanous dependency types that don't fit into
519// libraryDependencyTag. Each tag object is created globally and reused for multiple
520// dependencies (although since the object contains no references, assigning a tag to a
521// variable and modifying it will not modify the original). Users can compare the tag
522// returned by ctx.OtherModuleDependencyTag against the global original
523type dependencyTag struct {
524 blueprint.BaseDependencyTag
525 name string
526}
527
Colin Crossc99deeb2016-04-11 15:06:20 -0700528var (
Colin Cross6e511a92020-07-27 21:26:48 -0700529 genSourceDepTag = dependencyTag{name: "gen source"}
530 genHeaderDepTag = dependencyTag{name: "gen header"}
531 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
532 objDepTag = dependencyTag{name: "obj"}
533 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
534 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
535 reuseObjTag = dependencyTag{name: "reuse objects"}
536 staticVariantTag = dependencyTag{name: "static variant"}
537 vndkExtDepTag = dependencyTag{name: "vndk extends"}
538 dataLibDepTag = dependencyTag{name: "data lib"}
539 runtimeDepTag = dependencyTag{name: "runtime lib"}
540 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700541)
542
Roland Levillainf89cd092019-07-29 16:22:59 +0100543func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700544 ccLibDepTag, ok := depTag.(libraryDependencyTag)
545 return ok && ccLibDepTag.shared()
546}
547
548func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
549 ccLibDepTag, ok := depTag.(libraryDependencyTag)
550 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100551}
552
553func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700554 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100555 return ok && ccDepTag == runtimeDepTag
556}
557
558func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700559 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100560 return ok && ccDepTag == testPerSrcDepTag
561}
562
Colin Crossca860ac2016-01-04 14:34:37 -0800563// Module contains the properties and members used by all C/C++ module types, and implements
564// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
565// to construct the output file. Behavior can be customized with a Customizer interface
566type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700567 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700568 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900569 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900570 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700571
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700572 Properties BaseProperties
573 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700574
Colin Crossca860ac2016-01-04 14:34:37 -0800575 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700576 hod android.HostOrDeviceSupported
577 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700578
Paul Duffina0843f62019-12-13 19:50:38 +0000579 // Allowable SdkMemberTypes of this module type.
580 sdkMemberTypes []android.SdkMemberType
581
Colin Crossca860ac2016-01-04 14:34:37 -0800582 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700583 features []feature
584 compiler compiler
585 linker linker
586 installer installer
587 stl *stl
588 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800589 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800590 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900591 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700592 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700593 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800594
Colin Cross635c3b02016-05-18 15:37:25 -0700595 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800596
Colin Crossb98c8b02016-07-29 13:44:28 -0700597 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700598
599 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800600
601 // Flags used to compile this module
602 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700603
604 // 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 -0800605 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700606 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800607 depsInLinkOrder android.Paths
608
609 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700610 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900611
612 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800613 // Kythe (source file indexer) paths for this compilation module
614 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900615
616 // For apex variants, this is set as apex.min_sdk_version
617 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700618}
619
Ivan Lozano52767be2019-10-18 14:49:46 -0700620func (c *Module) Toc() android.OptionalPath {
621 if c.linker != nil {
622 if library, ok := c.linker.(libraryInterface); ok {
623 return library.toc()
624 }
625 }
626 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
627}
628
629func (c *Module) ApiLevel() string {
630 if c.linker != nil {
631 if stub, ok := c.linker.(*stubDecorator); ok {
632 return stub.properties.ApiLevel
633 }
634 }
635 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
636}
637
638func (c *Module) Static() bool {
639 if c.linker != nil {
640 if library, ok := c.linker.(libraryInterface); ok {
641 return library.static()
642 }
643 }
644 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
645}
646
647func (c *Module) Shared() bool {
648 if c.linker != nil {
649 if library, ok := c.linker.(libraryInterface); ok {
650 return library.shared()
651 }
652 }
653 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
654}
655
656func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000657 if c.stl != nil {
658 return c.stl.Properties.SelectedStl
659 }
660 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700661}
662
663func (c *Module) ToolchainLibrary() bool {
664 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
665 return true
666 }
667 return false
668}
669
670func (c *Module) NdkPrebuiltStl() bool {
671 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
672 return true
673 }
674 return false
675}
676
677func (c *Module) StubDecorator() bool {
678 if _, ok := c.linker.(*stubDecorator); ok {
679 return true
680 }
681 return false
682}
683
684func (c *Module) SdkVersion() string {
685 return String(c.Properties.Sdk_version)
686}
687
Artur Satayev480e25b2020-04-27 18:53:18 +0100688func (c *Module) MinSdkVersion() string {
689 return String(c.Properties.Min_sdk_version)
690}
691
Dan Albert92fe7402020-07-15 13:33:30 -0700692func (c *Module) SplitPerApiLevel() bool {
693 if linker, ok := c.linker.(*objectLinker); ok {
694 return linker.isCrt()
695 }
696 return false
697}
698
Colin Crossc511bc52020-04-07 16:50:32 +0000699func (c *Module) AlwaysSdk() bool {
700 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
701}
702
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800703func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700704 if c.linker != nil {
705 if library, ok := c.linker.(exportedFlagsProducer); ok {
706 return library.exportedDirs()
707 }
708 }
709 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
710}
711
712func (c *Module) HasStaticVariant() bool {
713 if c.staticVariant != nil {
714 return true
715 }
716 return false
717}
718
719func (c *Module) GetStaticVariant() LinkableInterface {
720 return c.staticVariant
721}
722
723func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
724 c.depsInLinkOrder = depsInLinkOrder
725}
726
727func (c *Module) GetDepsInLinkOrder() []android.Path {
728 return c.depsInLinkOrder
729}
730
731func (c *Module) StubsVersions() []string {
732 if c.linker != nil {
733 if library, ok := c.linker.(*libraryDecorator); ok {
734 return library.Properties.Stubs.Versions
735 }
736 }
737 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
738}
739
740func (c *Module) CcLibrary() bool {
741 if c.linker != nil {
742 if _, ok := c.linker.(*libraryDecorator); ok {
743 return true
744 }
745 }
746 return false
747}
748
749func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700750 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700751 return true
752 }
753 return false
754}
755
Ivan Lozano2b262972019-11-21 12:30:50 -0800756func (c *Module) NonCcVariants() bool {
757 return false
758}
759
Ivan Lozano183a3212019-10-18 14:18:45 -0700760func (c *Module) SetBuildStubs() {
761 if c.linker != nil {
762 if library, ok := c.linker.(*libraryDecorator); ok {
763 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700764 c.Properties.HideFromMake = true
765 c.sanitize = nil
766 c.stl = nil
767 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700768 return
769 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000770 if _, ok := c.linker.(*llndkStubDecorator); ok {
771 c.Properties.HideFromMake = true
772 return
773 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700774 }
775 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
776}
777
Ivan Lozano52767be2019-10-18 14:49:46 -0700778func (c *Module) BuildStubs() bool {
779 if c.linker != nil {
780 if library, ok := c.linker.(*libraryDecorator); ok {
781 return library.buildStubs()
782 }
783 }
784 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
785}
786
Ivan Lozano183a3212019-10-18 14:18:45 -0700787func (c *Module) SetStubsVersions(version string) {
788 if c.linker != nil {
789 if library, ok := c.linker.(*libraryDecorator); ok {
790 library.MutatedProperties.StubsVersion = version
791 return
792 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000793 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
794 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
795 return
796 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700797 }
798 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
799}
800
Jooyung Han03b51852020-02-26 22:45:42 +0900801func (c *Module) StubsVersion() string {
802 if c.linker != nil {
803 if library, ok := c.linker.(*libraryDecorator); ok {
804 return library.MutatedProperties.StubsVersion
805 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000806 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
807 return llndk.libraryDecorator.MutatedProperties.StubsVersion
808 }
Jooyung Han03b51852020-02-26 22:45:42 +0900809 }
810 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
811}
812
Ivan Lozano183a3212019-10-18 14:18:45 -0700813func (c *Module) SetStatic() {
814 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700815 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700816 library.setStatic()
817 return
818 }
819 }
820 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
821}
822
823func (c *Module) SetShared() {
824 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700825 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700826 library.setShared()
827 return
828 }
829 }
830 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
831}
832
833func (c *Module) BuildStaticVariant() bool {
834 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700835 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700836 return library.buildStatic()
837 }
838 }
839 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
840}
841
842func (c *Module) BuildSharedVariant() bool {
843 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700844 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700845 return library.buildShared()
846 }
847 }
848 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
849}
850
851func (c *Module) Module() android.Module {
852 return c
853}
854
Jiyong Parkc20eee32018-09-05 22:36:17 +0900855func (c *Module) OutputFile() android.OptionalPath {
856 return c.outputFile
857}
858
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400859func (c *Module) CoverageFiles() android.Paths {
860 if c.linker != nil {
861 if library, ok := c.linker.(libraryInterface); ok {
862 return library.objs().coverageFiles
863 }
864 }
865 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
866}
867
Ivan Lozano183a3212019-10-18 14:18:45 -0700868var _ LinkableInterface = (*Module)(nil)
869
Jiyong Park719b4462019-01-13 00:39:51 +0900870func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900871 if c.linker != nil {
872 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900873 }
874 return nil
875}
876
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900877func (c *Module) CoverageOutputFile() android.OptionalPath {
878 if c.linker != nil {
879 return c.linker.coverageOutputFilePath()
880 }
881 return android.OptionalPath{}
882}
883
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900884func (c *Module) RelativeInstallPath() string {
885 if c.installer != nil {
886 return c.installer.relativeInstallPath()
887 }
888 return ""
889}
890
Jooyung Han344d5432019-08-23 11:17:39 +0900891func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900892 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900893}
894
Colin Cross36242852017-06-23 15:06:31 -0700895func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700896 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800897 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700898 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800899 }
900 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700901 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800902 }
903 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700904 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800905 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700906 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700907 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700908 }
Colin Cross16b23492016-01-06 14:41:07 -0800909 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700910 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800911 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800912 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700913 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800914 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800915 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700916 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800917 }
Justin Yun8effde42017-06-23 19:24:43 +0900918 if c.vndkdep != nil {
919 c.AddProperties(c.vndkdep.props()...)
920 }
Stephen Craneba090d12017-05-09 15:44:35 -0700921 if c.lto != nil {
922 c.AddProperties(c.lto.props()...)
923 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700924 if c.pgo != nil {
925 c.AddProperties(c.pgo.props()...)
926 }
Colin Crossca860ac2016-01-04 14:34:37 -0800927 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700928 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800929 }
Colin Crossc472d572015-03-17 15:06:21 -0700930
Colin Crossa9d8bee2018-10-02 13:59:46 -0700931 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700932 // Windows builds always prefer 32-bit
933 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700934 })
Colin Cross36242852017-06-23 15:06:31 -0700935 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900936 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900937 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900938 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900939
Colin Cross36242852017-06-23 15:06:31 -0700940 return c
Colin Crossc472d572015-03-17 15:06:21 -0700941}
942
Colin Crossb916a382016-07-29 17:28:03 -0700943// Returns true for dependency roots (binaries)
944// TODO(ccross): also handle dlopenable libraries
945func (c *Module) isDependencyRoot() bool {
946 if root, ok := c.linker.(interface {
947 isDependencyRoot() bool
948 }); ok {
949 return root.isDependencyRoot()
950 }
951 return false
952}
953
Justin Yun5f7f7e82019-11-18 19:52:14 +0900954// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
955// "product" and "vendor" variant modules return true for this function.
956// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
957// "soc_specific: true" and more vendor installed modules are included here.
958// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
959// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700960func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900961 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700962}
963
Colin Crossc511bc52020-04-07 16:50:32 +0000964func (c *Module) canUseSdk() bool {
965 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
966}
967
968func (c *Module) UseSdk() bool {
969 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -0700970 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +0000971 }
972 return false
973}
974
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800975func (c *Module) isCoverageVariant() bool {
976 return c.coverage.Properties.IsCoverageVariant
977}
978
Peter Collingbournead84f972019-12-17 16:46:18 -0800979func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -0700980 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800981}
982
Inseob Kim9516ee92019-05-09 10:56:13 +0900983func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800984 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900985 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800986}
987
Inseob Kim9516ee92019-05-09 10:56:13 +0900988func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800989 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900990 name := c.BaseModuleName()
991 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800992}
993
Inseob Kim9516ee92019-05-09 10:56:13 +0900994func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800995 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900996 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800997}
998
Ivan Lozano52767be2019-10-18 14:49:46 -0700999func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001000 if vndkdep := c.vndkdep; vndkdep != nil {
1001 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001002 }
1003 return false
1004}
1005
Yi Kong7e53c572018-02-14 18:16:12 +08001006func (c *Module) isPgoCompile() bool {
1007 if pgo := c.pgo; pgo != nil {
1008 return pgo.Properties.PgoCompile
1009 }
1010 return false
1011}
1012
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001013func (c *Module) isNDKStubLibrary() bool {
1014 if _, ok := c.compiler.(*stubDecorator); ok {
1015 return true
1016 }
1017 return false
1018}
1019
Logan Chienf3511742017-10-31 18:04:35 +08001020func (c *Module) isVndkSp() bool {
1021 if vndkdep := c.vndkdep; vndkdep != nil {
1022 return vndkdep.isVndkSp()
1023 }
1024 return false
1025}
1026
1027func (c *Module) isVndkExt() bool {
1028 if vndkdep := c.vndkdep; vndkdep != nil {
1029 return vndkdep.isVndkExt()
1030 }
1031 return false
1032}
1033
Ivan Lozano52767be2019-10-18 14:49:46 -07001034func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001035 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001036}
1037
Logan Chienf3511742017-10-31 18:04:35 +08001038func (c *Module) getVndkExtendsModuleName() string {
1039 if vndkdep := c.vndkdep; vndkdep != nil {
1040 return vndkdep.getVndkExtendsModuleName()
1041 }
1042 return ""
1043}
1044
Jiyong Park25fc6a92018-11-18 18:02:45 +09001045func (c *Module) IsStubs() bool {
1046 if library, ok := c.linker.(*libraryDecorator); ok {
1047 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001048 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1049 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001050 }
1051 return false
1052}
1053
1054func (c *Module) HasStubsVariants() bool {
1055 if library, ok := c.linker.(*libraryDecorator); ok {
1056 return len(library.Properties.Stubs.Versions) > 0
1057 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001058 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1059 return len(library.Properties.Stubs.Versions) > 0
1060 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001061 return false
1062}
1063
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001064func (c *Module) bootstrap() bool {
1065 return Bool(c.Properties.Bootstrap)
1066}
1067
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001068func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001069 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1070 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1071 return false
1072 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001073 return c.linker != nil && c.linker.nativeCoverage()
1074}
1075
Inseob Kim8471cda2019-11-15 09:59:12 +09001076func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001077 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1078 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001079 }
1080 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001081}
1082
Jiyong Park73c54ee2019-10-22 20:31:18 +09001083func (c *Module) ExportedIncludeDirs() android.Paths {
1084 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1085 return flagsProducer.exportedDirs()
1086 }
Jiyong Park232e7852019-11-04 12:23:40 +09001087 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001088}
1089
1090func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1091 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1092 return flagsProducer.exportedSystemDirs()
1093 }
Jiyong Park232e7852019-11-04 12:23:40 +09001094 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001095}
1096
1097func (c *Module) ExportedFlags() []string {
1098 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1099 return flagsProducer.exportedFlags()
1100 }
Jiyong Park232e7852019-11-04 12:23:40 +09001101 return nil
1102}
1103
1104func (c *Module) ExportedDeps() android.Paths {
1105 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1106 return flagsProducer.exportedDeps()
1107 }
1108 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001109}
1110
Inseob Kimd110f872019-12-06 13:15:38 +09001111func (c *Module) ExportedGeneratedHeaders() android.Paths {
1112 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1113 return flagsProducer.exportedGeneratedHeaders()
1114 }
1115 return nil
1116}
1117
Bill Peckham945441c2020-08-31 16:07:58 -07001118func (c *Module) ExcludeFromVendorSnapshot() bool {
1119 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1120}
1121
Jiyong Parkf1194352019-02-25 11:05:47 +09001122func isBionic(name string) bool {
1123 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001124 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001125 return true
1126 }
1127 return false
1128}
1129
Martin Stjernholm279de572019-09-10 23:18:20 +01001130func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001131 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001132 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001133 }
1134 return isBionic(name)
1135}
1136
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001137func (c *Module) XrefCcFiles() android.Paths {
1138 return c.kytheFiles
1139}
1140
Colin Crossca860ac2016-01-04 14:34:37 -08001141type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001142 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001143 moduleContextImpl
1144}
1145
Colin Cross37047f12016-12-13 17:06:13 -08001146type depsContext struct {
1147 android.BottomUpMutatorContext
1148 moduleContextImpl
1149}
1150
Colin Crossca860ac2016-01-04 14:34:37 -08001151type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001152 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001153 moduleContextImpl
1154}
1155
1156type moduleContextImpl struct {
1157 mod *Module
1158 ctx BaseModuleContext
1159}
1160
Colin Crossb98c8b02016-07-29 13:44:28 -07001161func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001162 return ctx.mod.toolchain(ctx.ctx)
1163}
1164
1165func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001166 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001167}
1168
1169func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001170 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001171}
1172
Jiyong Park1d1119f2019-07-29 21:27:18 +09001173func (ctx *moduleContextImpl) header() bool {
1174 return ctx.mod.header()
1175}
1176
Inseob Kim7f283f42020-06-01 21:53:49 +09001177func (ctx *moduleContextImpl) binary() bool {
1178 return ctx.mod.binary()
1179}
1180
Inseob Kim1042d292020-06-01 23:23:05 +09001181func (ctx *moduleContextImpl) object() bool {
1182 return ctx.mod.object()
1183}
1184
Jooyung Hanccce2f22020-03-07 03:45:53 +09001185func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001186 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001187}
1188
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001190 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001191}
1192
1193func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001194 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001195 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001196 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001197 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001198 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001199 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001200 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001201 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001202 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001203 }
1204 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001205}
1206
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001207func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001208 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001209}
Justin Yun8effde42017-06-23 19:24:43 +09001210
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001211func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001212 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001213}
1214
Inseob Kim9516ee92019-05-09 10:56:13 +09001215func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1216 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001217}
1218
Inseob Kim9516ee92019-05-09 10:56:13 +09001219func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1220 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001221}
1222
Inseob Kim9516ee92019-05-09 10:56:13 +09001223func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1224 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001225}
1226
Logan Chienf3511742017-10-31 18:04:35 +08001227func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001228 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001229}
1230
Yi Kong7e53c572018-02-14 18:16:12 +08001231func (ctx *moduleContextImpl) isPgoCompile() bool {
1232 return ctx.mod.isPgoCompile()
1233}
1234
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001235func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1236 return ctx.mod.isNDKStubLibrary()
1237}
1238
Justin Yun8effde42017-06-23 19:24:43 +09001239func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001240 return ctx.mod.isVndkSp()
1241}
1242
1243func (ctx *moduleContextImpl) isVndkExt() bool {
1244 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001245}
1246
Vic Yangefd249e2018-11-12 20:19:56 -08001247func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001248 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001249}
1250
Logan Chien2f2b8902018-07-10 15:01:19 +08001251// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001252func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001253 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1254 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001255 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001256
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001257 // Coverage builds have extra symbols.
1258 if ctx.mod.isCoverageVariant() {
1259 return false
1260 }
1261
Doug Hornc32c6b02019-01-17 14:44:05 -08001262 if ctx.ctx.Fuchsia() {
1263 return false
1264 }
1265
Logan Chien2f2b8902018-07-10 15:01:19 +08001266 if sanitize := ctx.mod.sanitize; sanitize != nil {
1267 if !sanitize.isVariantOnProductionDevice() {
1268 return false
1269 }
1270 }
1271 if !ctx.ctx.Device() {
1272 // Host modules do not need ABI dumps.
1273 return false
1274 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001275 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001276 // Stubs do not need ABI dumps.
1277 return false
1278 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001279 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001280}
1281
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001282func (ctx *moduleContextImpl) selectedStl() string {
1283 if stl := ctx.mod.stl; stl != nil {
1284 return stl.Properties.SelectedStl
1285 }
1286 return ""
1287}
1288
Ivan Lozanobd721262018-11-27 14:33:03 -08001289func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1290 return ctx.mod.linker.useClangLld(actx)
1291}
1292
Colin Crossce75d2c2016-10-06 16:12:58 -07001293func (ctx *moduleContextImpl) baseModuleName() string {
1294 return ctx.mod.ModuleBase.BaseModuleName()
1295}
1296
Logan Chienf3511742017-10-31 18:04:35 +08001297func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1298 return ctx.mod.getVndkExtendsModuleName()
1299}
1300
Logan Chiene274fc92019-12-03 11:18:32 -08001301func (ctx *moduleContextImpl) isForPlatform() bool {
1302 return ctx.mod.IsForPlatform()
1303}
1304
Colin Crosse07f2312020-08-13 11:24:56 -07001305func (ctx *moduleContextImpl) apexVariationName() string {
1306 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001307}
1308
Jooyung Hanccce2f22020-03-07 03:45:53 +09001309func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001310 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001311}
1312
Jiyong Parkb0788572018-12-20 22:10:17 +09001313func (ctx *moduleContextImpl) hasStubsVariants() bool {
1314 return ctx.mod.HasStubsVariants()
1315}
1316
1317func (ctx *moduleContextImpl) isStubs() bool {
1318 return ctx.mod.IsStubs()
1319}
1320
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001321func (ctx *moduleContextImpl) bootstrap() bool {
1322 return ctx.mod.bootstrap()
1323}
1324
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001325func (ctx *moduleContextImpl) nativeCoverage() bool {
1326 return ctx.mod.nativeCoverage()
1327}
1328
Colin Cross635c3b02016-05-18 15:37:25 -07001329func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001330 return &Module{
1331 hod: hod,
1332 multilib: multilib,
1333 }
1334}
1335
Colin Cross635c3b02016-05-18 15:37:25 -07001336func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001337 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001338 module.features = []feature{
1339 &tidyFeature{},
1340 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001341 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001342 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001343 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001344 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001345 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001346 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001347 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001348 return module
1349}
1350
Colin Crossce75d2c2016-10-06 16:12:58 -07001351func (c *Module) Prebuilt() *android.Prebuilt {
1352 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1353 return p.prebuilt()
1354 }
1355 return nil
1356}
1357
1358func (c *Module) Name() string {
1359 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001360 if p, ok := c.linker.(interface {
1361 Name(string) string
1362 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001363 name = p.Name(name)
1364 }
1365 return name
1366}
1367
Alex Light3d673592019-01-18 14:37:31 -08001368func (c *Module) Symlinks() []string {
1369 if p, ok := c.installer.(interface {
1370 symlinkList() []string
1371 }); ok {
1372 return p.symlinkList()
1373 }
1374 return nil
1375}
1376
Jeff Gaston294356f2017-09-27 17:05:30 -07001377// orderDeps reorders dependencies into a list such that if module A depends on B, then
1378// A will precede B in the resultant list.
1379// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001380// Note that directSharedDeps should be the analogous static library for each shared lib dep
1381func 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 -07001382 // If A depends on B, then
1383 // Every list containing A will also contain B later in the list
1384 // So, after concatenating all lists, the final instance of B will have come from the same
1385 // original list as the final instance of A
1386 // So, the final instance of B will be later in the concatenation than the final A
1387 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1388 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001389 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001390 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001391 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1392 }
1393 for _, dep := range directSharedDeps {
1394 orderedAllDeps = append(orderedAllDeps, dep)
1395 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001396 }
1397
Colin Crossb6715442017-10-24 11:13:31 -07001398 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001399
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001400 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001401 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001402 // resultant list to only what the caller has chosen to include in directStaticDeps
1403 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001404
1405 return orderedAllDeps, orderedDeclaredDeps
1406}
1407
Ivan Lozano183a3212019-10-18 14:18:45 -07001408func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001409 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001410 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001411 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1412 staticDepFiles := []android.Path{}
1413 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001414 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1415 if dep.OutputFile().Valid() {
1416 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1417 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1418 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001419 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001420 sharedDepFiles := []android.Path{}
1421 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001422 if sharedDep.HasStaticVariant() {
1423 staticAnalogue := sharedDep.GetStaticVariant()
1424 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1425 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001426 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001427 }
1428
1429 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001430 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1431 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001432
1433 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001434}
1435
Roland Levillainf89cd092019-07-29 16:22:59 +01001436func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1437 test, ok := c.linker.(testPerSrc)
1438 return ok && test.isAllTestsVariation()
1439}
1440
Chris Parsons216e10a2020-07-09 17:12:52 -04001441func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001442 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001443 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001444 }); ok {
1445 return p.dataPaths()
1446 }
1447 return nil
1448}
1449
Justin Yun5f7f7e82019-11-18 19:52:14 +09001450func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1451 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1452 // "current", it will append the VNDK version to the name suffix.
1453 var vndkVersion string
1454 var nameSuffix string
1455 if c.inProduct() {
1456 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1457 nameSuffix = productSuffix
1458 } else {
1459 vndkVersion = ctx.DeviceConfig().VndkVersion()
1460 nameSuffix = vendorSuffix
1461 }
1462 if vndkVersion == "current" {
1463 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1464 }
1465 if c.Properties.VndkVersion != vndkVersion {
1466 // add version suffix only if the module is using different vndk version than the
1467 // version in product or vendor partition.
1468 nameSuffix += "." + c.Properties.VndkVersion
1469 }
1470 return nameSuffix
1471}
1472
Colin Cross635c3b02016-05-18 15:37:25 -07001473func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001474 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001475 //
1476 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1477 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1478 // module and return early, as this module does not produce an output file per se.
1479 if c.IsTestPerSrcAllTestsVariation() {
1480 c.outputFile = android.OptionalPath{}
1481 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001482 }
1483
Jooyung Han38002912019-05-16 04:01:54 +09001484 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001485
Inseob Kim64c43952019-08-26 16:52:35 +09001486 c.Properties.SubName = ""
1487
1488 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1489 c.Properties.SubName += nativeBridgeSuffix
1490 }
1491
Justin Yun5f7f7e82019-11-18 19:52:14 +09001492 _, llndk := c.linker.(*llndkStubDecorator)
1493 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1494 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1495 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1496 // added for product variant only when we have vendor and product variants with core
1497 // variant. The suffix is not added for vendor-only or product-only module.
1498 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1499 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001500 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1501 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1502 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001503 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1504 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001505 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001506 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001507 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001508 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001509 if c.SplitPerApiLevel() {
1510 c.Properties.SubName += "." + c.SdkVersion()
1511 }
Inseob Kim64c43952019-08-26 16:52:35 +09001512 }
1513
Colin Crossca860ac2016-01-04 14:34:37 -08001514 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001515 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001516 moduleContextImpl: moduleContextImpl{
1517 mod: c,
1518 },
1519 }
1520 ctx.ctx = ctx
1521
Colin Crossf18e1102017-11-16 14:33:08 -08001522 deps := c.depsToPaths(ctx)
1523 if ctx.Failed() {
1524 return
1525 }
1526
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001527 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1528 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1529 }
1530
Colin Crossca860ac2016-01-04 14:34:37 -08001531 flags := Flags{
1532 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001533 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001534 }
Colin Crossca860ac2016-01-04 14:34:37 -08001535 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001536 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001537 }
1538 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001539 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001540 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001541 if c.stl != nil {
1542 flags = c.stl.flags(ctx, flags)
1543 }
Colin Cross16b23492016-01-06 14:41:07 -08001544 if c.sanitize != nil {
1545 flags = c.sanitize.flags(ctx, flags)
1546 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001547 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001548 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001549 }
Stephen Craneba090d12017-05-09 15:44:35 -07001550 if c.lto != nil {
1551 flags = c.lto.flags(ctx, flags)
1552 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001553 if c.pgo != nil {
1554 flags = c.pgo.flags(ctx, flags)
1555 }
Colin Crossca860ac2016-01-04 14:34:37 -08001556 for _, feature := range c.features {
1557 flags = feature.flags(ctx, flags)
1558 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001559 if ctx.Failed() {
1560 return
1561 }
1562
Colin Cross4af21ed2019-11-04 09:37:55 -08001563 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1564 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1565 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001566
Colin Cross4af21ed2019-11-04 09:37:55 -08001567 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001568
1569 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001570 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001571 }
1572 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001573 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001574 }
1575
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001576 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001577 // We need access to all the flags seen by a source file.
1578 if c.sabi != nil {
1579 flags = c.sabi.flags(ctx, flags)
1580 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001581
Colin Cross4af21ed2019-11-04 09:37:55 -08001582 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001583
Colin Crossca860ac2016-01-04 14:34:37 -08001584 // Optimization to reduce size of build.ninja
1585 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001586 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1587 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1588 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1589 flags.Local.CFlags = []string{"$cflags"}
1590 flags.Local.CppFlags = []string{"$cppflags"}
1591 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001592
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001593 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001594 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001595 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001596 if ctx.Failed() {
1597 return
1598 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001599 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001600 }
1601
Colin Crossca860ac2016-01-04 14:34:37 -08001602 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001603 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001604 if ctx.Failed() {
1605 return
1606 }
Colin Cross635c3b02016-05-18 15:37:25 -07001607 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001608
1609 // If a lib is directly included in any of the APEXes, unhide the stubs
1610 // variant having the latest version gets visible to make. In addition,
1611 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1612 // force anything in the make world to link against the stubs library.
1613 // (unless it is explicitly referenced via .bootstrap suffix or the
1614 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001615 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001616 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001617 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001618 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001619 c.Properties.HideFromMake = false // unhide
1620 // Note: this is still non-installable
1621 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001622
1623 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1624 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1625 if isSnapshotAware(ctx, c) {
1626 i.collectHeadersForSnapshot(ctx)
1627 }
1628 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001629 }
Colin Cross5049f022015-03-18 13:28:46 -07001630
Inseob Kim1f086e22019-05-09 13:29:15 +09001631 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001632 c.installer.install(ctx, c.outputFile.Path())
1633 if ctx.Failed() {
1634 return
Colin Crossca860ac2016-01-04 14:34:37 -08001635 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001636 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1637 // If the module has been specifically configure to not be installed then
1638 // skip the installation as otherwise it will break when running inside make
1639 // as the output path to install will not be specified. Not all uninstallable
1640 // modules can skip installation as some are needed for resolving make side
1641 // dependencies.
1642 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001643 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001644}
1645
Colin Cross0ea8ba82019-06-06 14:33:29 -07001646func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001647 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001648 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001649 }
Colin Crossca860ac2016-01-04 14:34:37 -08001650 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001651}
1652
Colin Crossca860ac2016-01-04 14:34:37 -08001653func (c *Module) begin(ctx BaseModuleContext) {
1654 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001655 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001656 }
Colin Crossca860ac2016-01-04 14:34:37 -08001657 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001658 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001659 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001660 if c.stl != nil {
1661 c.stl.begin(ctx)
1662 }
Colin Cross16b23492016-01-06 14:41:07 -08001663 if c.sanitize != nil {
1664 c.sanitize.begin(ctx)
1665 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001666 if c.coverage != nil {
1667 c.coverage.begin(ctx)
1668 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001669 if c.sabi != nil {
1670 c.sabi.begin(ctx)
1671 }
Justin Yun8effde42017-06-23 19:24:43 +09001672 if c.vndkdep != nil {
1673 c.vndkdep.begin(ctx)
1674 }
Stephen Craneba090d12017-05-09 15:44:35 -07001675 if c.lto != nil {
1676 c.lto.begin(ctx)
1677 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001678 if c.pgo != nil {
1679 c.pgo.begin(ctx)
1680 }
Colin Crossca860ac2016-01-04 14:34:37 -08001681 for _, feature := range c.features {
1682 feature.begin(ctx)
1683 }
Dan Albert92fe7402020-07-15 13:33:30 -07001684 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albertf5415d72017-08-17 16:19:59 -07001685 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001686 if err != nil {
1687 ctx.PropertyErrorf("sdk_version", err.Error())
1688 }
Nan Zhang0007d812017-11-07 10:57:05 -08001689 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001690 }
Colin Crossca860ac2016-01-04 14:34:37 -08001691}
1692
Colin Cross37047f12016-12-13 17:06:13 -08001693func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001694 deps := Deps{}
1695
1696 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001697 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001698 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001699 // Add the PGO dependency (the clang_rt.profile runtime library), which
1700 // sometimes depends on symbols from libgcc, before libgcc gets added
1701 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001702 if c.pgo != nil {
1703 deps = c.pgo.deps(ctx, deps)
1704 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001705 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001706 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001707 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001708 if c.stl != nil {
1709 deps = c.stl.deps(ctx, deps)
1710 }
Colin Cross16b23492016-01-06 14:41:07 -08001711 if c.sanitize != nil {
1712 deps = c.sanitize.deps(ctx, deps)
1713 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001714 if c.coverage != nil {
1715 deps = c.coverage.deps(ctx, deps)
1716 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001717 if c.sabi != nil {
1718 deps = c.sabi.deps(ctx, deps)
1719 }
Justin Yun8effde42017-06-23 19:24:43 +09001720 if c.vndkdep != nil {
1721 deps = c.vndkdep.deps(ctx, deps)
1722 }
Stephen Craneba090d12017-05-09 15:44:35 -07001723 if c.lto != nil {
1724 deps = c.lto.deps(ctx, deps)
1725 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001726 for _, feature := range c.features {
1727 deps = feature.deps(ctx, deps)
1728 }
1729
Colin Crossb6715442017-10-24 11:13:31 -07001730 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1731 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1732 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1733 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1734 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1735 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001736 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001737
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001738 for _, lib := range deps.ReexportSharedLibHeaders {
1739 if !inList(lib, deps.SharedLibs) {
1740 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1741 }
1742 }
1743
1744 for _, lib := range deps.ReexportStaticLibHeaders {
1745 if !inList(lib, deps.StaticLibs) {
1746 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1747 }
1748 }
1749
Colin Cross5950f382016-12-13 12:50:57 -08001750 for _, lib := range deps.ReexportHeaderLibHeaders {
1751 if !inList(lib, deps.HeaderLibs) {
1752 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1753 }
1754 }
1755
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001756 for _, gen := range deps.ReexportGeneratedHeaders {
1757 if !inList(gen, deps.GeneratedHeaders) {
1758 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1759 }
1760 }
1761
Colin Crossc99deeb2016-04-11 15:06:20 -07001762 return deps
1763}
1764
Dan Albert7e9d2952016-08-04 13:02:36 -07001765func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001766 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001767 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001768 moduleContextImpl: moduleContextImpl{
1769 mod: c,
1770 },
1771 }
1772 ctx.ctx = ctx
1773
Colin Crossca860ac2016-01-04 14:34:37 -08001774 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001775}
1776
Jiyong Park7ed9de32018-10-15 22:25:07 +09001777// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001778func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001779 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1780 version := name[sharp+1:]
1781 libname := name[:sharp]
1782 return libname, version
1783 }
1784 return name, ""
1785}
1786
Dan Albert92fe7402020-07-15 13:33:30 -07001787func GetCrtVariations(ctx android.BottomUpMutatorContext,
1788 m LinkableInterface) []blueprint.Variation {
1789 if ctx.Os() != android.Android {
1790 return nil
1791 }
1792 if m.UseSdk() {
1793 return []blueprint.Variation{
1794 {Mutator: "sdk", Variation: "sdk"},
1795 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1796 }
1797 }
1798 return []blueprint.Variation{
1799 {Mutator: "sdk", Variation: ""},
1800 }
1801}
1802
Colin Cross1e676be2016-10-12 14:38:15 -07001803func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001804 if !c.Enabled() {
1805 return
1806 }
1807
Colin Cross37047f12016-12-13 17:06:13 -08001808 ctx := &depsContext{
1809 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001810 moduleContextImpl: moduleContextImpl{
1811 mod: c,
1812 },
1813 }
1814 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001815
Colin Crossc99deeb2016-04-11 15:06:20 -07001816 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001817
Dan Albert914449f2016-06-17 16:45:24 -07001818 variantNdkLibs := []string{}
1819 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001820 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001821 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001822 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001823 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001824 // 1. Name of an NDK library that refers to a prebuilt module.
1825 // For each of these, it adds the name of the prebuilt module (which will be in
1826 // prebuilts/ndk) to the list of nonvariant libs.
1827 // 2. Name of an NDK library that refers to an ndk_library module.
1828 // For each of these, it adds the name of the ndk_library module to the list of
1829 // variant libs.
1830 // 3. Anything else (so anything that isn't an NDK library).
1831 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001832 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001833 // The caller can then know to add the variantLibs dependencies differently from the
1834 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001835
Inseob Kim9516ee92019-05-09 10:56:13 +09001836 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001837 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1838
1839 rewriteVendorLibs := func(lib string) string {
1840 if isLlndkLibrary(lib, ctx.Config()) {
1841 return lib + llndkLibrarySuffix
1842 }
1843
1844 // only modules with BOARD_VNDK_VERSION uses snapshot.
1845 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1846 return lib
1847 }
1848
1849 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1850 return snapshot
1851 }
1852
1853 return lib
1854 }
1855
1856 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001857 variantLibs = []string{}
1858 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001859 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001860 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001861 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001862 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1863 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001864 } else if ctx.useVndk() {
1865 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001866 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001867 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001868 if actx.OtherModuleExists(vendorPublicLib) {
1869 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1870 } else {
1871 // This can happen if vendor_public_library module is defined in a
1872 // namespace that isn't visible to the current module. In that case,
1873 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001874 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001875 }
Dan Albert914449f2016-06-17 16:45:24 -07001876 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001877 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001878 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001879 }
1880 }
Dan Albert914449f2016-06-17 16:45:24 -07001881 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001882 }
1883
Inseob Kimeec88e12020-01-22 11:11:29 +09001884 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1885 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1886 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1887 if ctx.useVndk() {
1888 for idx, lib := range deps.RuntimeLibs {
1889 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1890 }
1891 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001892 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001893
Jiyong Park7e636d02019-01-28 16:16:54 +09001894 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001895 if c.linker != nil {
1896 if library, ok := c.linker.(*libraryDecorator); ok {
1897 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001898 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001899 }
1900 }
1901 }
1902
Inseob Kimeec88e12020-01-22 11:11:29 +09001903 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1904 // only modules with BOARD_VNDK_VERSION uses snapshot.
1905 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1906 return lib
1907 }
1908
1909 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1910 return snapshot
1911 }
1912
1913 return lib
1914 }
1915
1916 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001917 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001918 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001919 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001920 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001921 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001922
1923 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1924
Jiyong Park7e636d02019-01-28 16:16:54 +09001925 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001926 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001927 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001928 } else {
1929 actx.AddVariationDependencies(nil, depTag, lib)
1930 }
1931 }
1932
1933 if buildStubs {
1934 // Stubs lib does not have dependency to other static/shared libraries.
1935 // Don't proceed.
1936 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001937 }
Colin Cross5950f382016-12-13 12:50:57 -08001938
Inseob Kimc0907f12019-02-08 21:00:45 +09001939 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001940 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001941
Jiyong Park5d1598f2019-02-25 22:14:17 +09001942 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001943 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001944 if impl, ok := syspropImplLibraries[lib]; ok {
1945 lib = impl
1946 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001947
1948 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1949
Jiyong Park5d1598f2019-02-25 22:14:17 +09001950 actx.AddVariationDependencies([]blueprint.Variation{
1951 {Mutator: "link", Variation: "static"},
1952 }, depTag, lib)
1953 }
1954
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001955 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001956 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001957 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001958 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001959 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001960
1961 if impl, ok := syspropImplLibraries[lib]; ok {
1962 lib = impl
1963 }
1964
Inseob Kimeec88e12020-01-22 11:11:29 +09001965 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1966
Dan Willemsen59339a22018-07-22 21:18:45 -07001967 actx.AddVariationDependencies([]blueprint.Variation{
1968 {Mutator: "link", Variation: "static"},
1969 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001970 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001971
Jooyung Han75568392020-03-20 04:29:24 +09001972 // staticUnwinderDep is treated as staticDep for Q apexes
1973 // so that native libraries/binaries are linked with static unwinder
1974 // because Q libc doesn't have unwinder APIs
1975 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001976 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001977 actx.AddVariationDependencies([]blueprint.Variation{
1978 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001979 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001980 }
1981
Inseob Kimeec88e12020-01-22 11:11:29 +09001982 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001983 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001984 actx.AddVariationDependencies([]blueprint.Variation{
1985 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001986 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001987 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001988
Colin Cross6e511a92020-07-27 21:26:48 -07001989 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001990 var variations []blueprint.Variation
1991 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001992 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001993 // Version is explicitly specified. i.e. libFoo#30
1994 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07001995 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001996 }
1997 actx.AddVariationDependencies(variations, depTag, name)
1998
Jooyung Han03b51852020-02-26 22:45:42 +09001999 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002000 // The stubs library will be used when the depending module is built for APEX and
2001 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002002 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09002003 for _, ver := range stubsVersionsFor(actx.Config())[name] {
2004 // Note that depTag.ExplicitlyVersioned is false in this case.
2005 actx.AddVariationDependencies([]blueprint.Variation{
2006 {Mutator: "link", Variation: "shared"},
2007 {Mutator: "version", Variation: ver},
2008 }, depTag, name)
2009 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002010 }
2011 }
2012
Jiyong Park7ed9de32018-10-15 22:25:07 +09002013 // shared lib names without the #version suffix
2014 var sharedLibNames []string
2015
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002016 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002017 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002018 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002019 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002020 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002021
2022 if impl, ok := syspropImplLibraries[lib]; ok {
2023 lib = impl
2024 }
2025
Jiyong Park73c54ee2019-10-22 20:31:18 +09002026 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002027 sharedLibNames = append(sharedLibNames, name)
2028
Jiyong Park25fc6a92018-11-18 18:02:45 +09002029 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002030 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002031
Jiyong Park7ed9de32018-10-15 22:25:07 +09002032 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002033 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002034 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2035 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2036 // linking against both the stubs lib and the non-stubs lib at the same time.
2037 continue
2038 }
Colin Cross6e511a92020-07-27 21:26:48 -07002039 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2040 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002041 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002042
Dan Willemsen59339a22018-07-22 21:18:45 -07002043 actx.AddVariationDependencies([]blueprint.Variation{
2044 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002045 }, dataLibDepTag, deps.DataLibs...)
2046
2047 actx.AddVariationDependencies([]blueprint.Variation{
2048 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002049 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002050
Colin Cross68861832016-07-08 10:41:41 -07002051 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002052
2053 for _, gen := range deps.GeneratedHeaders {
2054 depTag := genHeaderDepTag
2055 if inList(gen, deps.ReexportGeneratedHeaders) {
2056 depTag = genHeaderExportDepTag
2057 }
2058 actx.AddDependency(c, depTag, gen)
2059 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002060
Colin Cross42d48b72018-08-29 14:10:52 -07002061 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002062
Inseob Kim1042d292020-06-01 23:23:05 +09002063 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2064
Dan Albert92fe7402020-07-15 13:33:30 -07002065 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002066 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002067 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2068 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002069 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002070 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002071 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2072 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002073 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002074 if deps.LinkerFlagsFile != "" {
2075 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2076 }
2077 if deps.DynamicLinker != "" {
2078 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002079 }
Dan Albert914449f2016-06-17 16:45:24 -07002080
2081 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002082
2083 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002084 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002085 {Mutator: "ndk_api", Variation: version},
2086 {Mutator: "link", Variation: "shared"},
2087 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002088
2089 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002090 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002091 {Mutator: "ndk_api", Variation: version},
2092 {Mutator: "link", Variation: "shared"},
2093 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002094
2095 if vndkdep := c.vndkdep; vndkdep != nil {
2096 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002097 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002098 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002099 {Mutator: "link", Variation: "shared"},
2100 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002101 }
2102 }
Colin Cross6362e272015-10-29 15:25:03 -07002103}
Colin Cross21b9a242015-03-24 14:15:58 -07002104
Colin Crosse40b4ea2018-10-02 22:25:58 -07002105func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002106 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2107 c.beginMutator(ctx)
2108 }
2109}
2110
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002111// Whether a module can link to another module, taking into
2112// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002113func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2114 tag blueprint.DependencyTag) {
2115
2116 switch t := tag.(type) {
2117 case dependencyTag:
2118 if t != vndkExtDepTag {
2119 return
2120 }
2121 case libraryDependencyTag:
2122 default:
2123 return
2124 }
2125
Ivan Lozano52767be2019-10-18 14:49:46 -07002126 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002127 // Host code is not restricted
2128 return
2129 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002130
2131 // VNDK is cc.Module supported only for now.
2132 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002133 // Though vendor code is limited by the vendor mutator,
2134 // each vendor-available module needs to check
2135 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002136 if ccTo, ok := to.(*Module); ok {
2137 if ccFrom.vndkdep != nil {
2138 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2139 }
2140 } else {
2141 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002142 }
2143 return
2144 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002145 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002146 // Platform code can link to anything
2147 return
2148 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002149 if from.InRamdisk() {
2150 // Ramdisk code is not NDK
2151 return
2152 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002153 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002154 // Recovery code is not NDK
2155 return
2156 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002157 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002158 // These are always allowed
2159 return
2160 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002161 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002162 // These are allowed, but they don't set sdk_version
2163 return
2164 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002165 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002166 // These aren't real libraries, but are the stub shared libraries that are included in
2167 // the NDK.
2168 return
2169 }
Logan Chien834b9a62019-01-14 15:39:03 +08002170
Ivan Lozano52767be2019-10-18 14:49:46 -07002171 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002172 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2173 // to link to libc++ (non-NDK and without sdk_version).
2174 return
2175 }
2176
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002178 // NDK code linking to platform code is never okay.
2179 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002180 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002181 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002182 }
2183
2184 // At this point we know we have two NDK libraries, but we need to
2185 // check that we're not linking against anything built against a higher
2186 // API level, as it is only valid to link against older or equivalent
2187 // APIs.
2188
Inseob Kim01a28722018-04-11 09:48:45 +09002189 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002190 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002191 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002192 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002193 // Current can't be linked against by anything else.
2194 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002195 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002196 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002198 if err != nil {
2199 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002200 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002201 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002202 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002204 if err != nil {
2205 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002206 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002207 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002208 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002209
Inseob Kim01a28722018-04-11 09:48:45 +09002210 if toApi > fromApi {
2211 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002212 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002213 }
2214 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002215 }
Dan Albert202fe492017-12-15 13:56:59 -08002216
2217 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002218 fromStl := from.SelectedStl()
2219 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002220 if fromStl == "" || toStl == "" {
2221 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002222 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002223 // We can be permissive with the system "STL" since it is only the C++
2224 // ABI layer, but in the future we should make sure that everyone is
2225 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002226 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002227 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002228 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2229 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002230 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002231}
2232
Jiyong Park5fb8c102018-04-09 12:03:06 +09002233// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002234// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2235// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002236// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002237func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2238 check := func(child, parent android.Module) bool {
2239 to, ok := child.(*Module)
2240 if !ok {
2241 // follow thru cc.Defaults, etc.
2242 return true
2243 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002244
Jooyung Hana70f0672019-01-18 15:20:43 +09002245 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2246 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002247 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002248
2249 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002250 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002251 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002252 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002253
Jooyung Han0302a842019-10-30 18:43:49 +09002254 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002255 return false
2256 }
2257
2258 var stringPath []string
2259 for _, m := range ctx.GetWalkPath() {
2260 stringPath = append(stringPath, m.Name())
2261 }
2262 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2263 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2264 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2265 return false
2266 }
2267 if module, ok := ctx.Module().(*Module); ok {
2268 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002269 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002270 ctx.WalkDeps(check)
2271 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002272 }
2273 }
2274}
2275
Colin Crossc99deeb2016-04-11 15:06:20 -07002276// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002277func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002278 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002279
Ivan Lozano183a3212019-10-18 14:18:45 -07002280 directStaticDeps := []LinkableInterface{}
2281 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002282
Inseob Kim69378442019-06-03 19:10:47 +09002283 reexportExporter := func(exporter exportedFlagsProducer) {
2284 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2285 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2286 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2287 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002288 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002289 }
2290
Jooyung Hande34d232020-07-23 13:04:15 +09002291 // For the dependency from platform to apex, use the latest stubs
2292 c.apexSdkVersion = android.FutureApiLevel
2293 if !c.IsForPlatform() {
2294 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2295 }
2296
2297 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2298 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2299 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2300 // (b/144430859)
2301 c.apexSdkVersion = android.FutureApiLevel
2302 }
2303
Colin Crossd11fcda2017-10-23 17:59:01 -07002304 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002305 depName := ctx.OtherModuleName(dep)
2306 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002307
Ivan Lozano52767be2019-10-18 14:49:46 -07002308 ccDep, ok := dep.(LinkableInterface)
2309 if !ok {
2310
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002311 // handling for a few module types that aren't cc Module but that are also supported
2312 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002313 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002314 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002315 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2316 genRule.GeneratedSourceFiles()...)
2317 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002318 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002319 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002320 // Support exported headers from a generated_sources dependency
2321 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002322 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002323 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002324 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002325 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002326 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002327 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002328 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002329 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002330 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2331 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002332 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002333 // 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 +09002334 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002335
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002336 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002337 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002338 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002339 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002340 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002341 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002342 files := genRule.GeneratedSourceFiles()
2343 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002344 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002345 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002346 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 -07002347 }
2348 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002349 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002350 }
Colin Crossca860ac2016-01-04 14:34:37 -08002351 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002352 return
2353 }
2354
Colin Crossfe17f6f2019-03-28 19:30:56 -07002355 if depTag == android.ProtoPluginDepTag {
2356 return
2357 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002358 if depTag == llndkImplDep {
2359 return
2360 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002361
Colin Crossd11fcda2017-10-23 17:59:01 -07002362 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002363 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2364 return
2365 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002366 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002367 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2368 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002369 return
2370 }
2371
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002372 // re-exporting flags
2373 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002374 // reusing objects only make sense for cc.Modules.
2375 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002376 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002377 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002378 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002379 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002380 return
2381 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002382 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002383
Jiyong Parke4bb9862019-02-01 00:31:10 +09002384 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002385 // staticVariants are a cc.Module specific concept.
2386 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002387 c.staticVariant = ccDep
2388 return
2389 }
2390 }
2391
Colin Cross6e511a92020-07-27 21:26:48 -07002392 checkLinkType(ctx, c, ccDep, depTag)
2393
2394 linkFile := ccDep.OutputFile()
2395
2396 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2397 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2398 if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002399 return
2400 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002401
Colin Cross6e511a92020-07-27 21:26:48 -07002402 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002403 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002404 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002405 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002406 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002407
2408 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002409 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002410 // Always respect dependency to the versioned stubs (i.e. libX#10)
2411 useThisDep = true
2412 } else if !depHasStubs {
2413 // Use non-stub variant if that is the only choice
2414 // (i.e. depending on a lib without stubs.version property)
2415 useThisDep = true
2416 } else if c.IsForPlatform() {
2417 // If not building for APEX, use stubs only when it is from
2418 // an APEX (and not from platform)
2419 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002420 if c.bootstrap() {
2421 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002422 // always link to non-stub variant
2423 useThisDep = !depIsStubs
2424 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002425 for _, testFor := range c.TestFor() {
2426 // Another exception: if this module is bundled with an APEX, then
2427 // it is linked with the non-stub variant of a module in the APEX
2428 // as if this is part of the APEX.
2429 if android.DirectlyInApex(testFor, depName) {
2430 useThisDep = !depIsStubs
2431 break
2432 }
2433 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002434 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002435 // If building for APEX, use stubs when the parent is in any APEX that
2436 // the child is not in.
2437 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002438 }
2439
Jooyung Han03b51852020-02-26 22:45:42 +09002440 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002441 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002442 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002443 if err != nil {
2444 ctx.OtherModuleErrorf(dep, err.Error())
2445 return
2446 }
2447 if versionToUse != ccDep.StubsVersion() {
2448 useThisDep = false
2449 }
2450 }
2451
Jiyong Park25fc6a92018-11-18 18:02:45 +09002452 if !useThisDep {
2453 return // stop processing this dep
2454 }
2455 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002456 if c.UseVndk() {
2457 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2458 // by default, use current version of LLNDK
2459 versionToUse := ""
2460 versions := stubsVersionsFor(ctx.Config())[depName]
Colin Crosse07f2312020-08-13 11:24:56 -07002461 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002462 // if this is for use_vendor apex && dep has stubsVersions
2463 // apply the same rule of apex sdk enforcement to choose right version
2464 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002465 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002466 if err != nil {
2467 ctx.OtherModuleErrorf(dep, err.Error())
2468 return
2469 }
2470 }
2471 if versionToUse != ccDep.StubsVersion() {
2472 return
2473 }
2474 }
2475 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002476
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002477 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2478
Ivan Lozano52767be2019-10-18 14:49:46 -07002479 // Exporting flags only makes sense for cc.Modules
2480 if _, ok := ccDep.(*Module); ok {
2481 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002482 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002483 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002484 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002485
Colin Cross6e511a92020-07-27 21:26:48 -07002486 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002487 reexportExporter(i)
2488 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2489 // Re-exported shared library headers must be included as well since they can help us with type information
2490 // about template instantiations (instantiated from their headers).
2491 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2492 // scripts.
2493 c.sabi.Properties.ReexportedIncludes = append(
2494 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2495 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002496 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002497 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002498
Colin Cross6e511a92020-07-27 21:26:48 -07002499 var ptr *android.Paths
2500 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002501
Colin Cross6e511a92020-07-27 21:26:48 -07002502 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002503
Colin Cross6e511a92020-07-27 21:26:48 -07002504 switch {
2505 case libDepTag.header():
2506 // nothing
2507 case libDepTag.shared():
2508 ptr = &depPaths.SharedLibs
2509 switch libDepTag.Order {
2510 case earlyLibraryDependency:
2511 ptr = &depPaths.EarlySharedLibs
2512 depPtr = &depPaths.EarlySharedLibsDeps
2513 case normalLibraryDependency:
2514 ptr = &depPaths.SharedLibs
2515 depPtr = &depPaths.SharedLibsDeps
2516 directSharedDeps = append(directSharedDeps, ccDep)
2517 case lateLibraryDependency:
2518 ptr = &depPaths.LateSharedLibs
2519 depPtr = &depPaths.LateSharedLibsDeps
2520 default:
2521 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002522 }
Colin Cross6e511a92020-07-27 21:26:48 -07002523 depFile = ccDep.Toc()
2524 case libDepTag.static():
2525 if libDepTag.wholeStatic {
2526 ptr = &depPaths.WholeStaticLibs
2527 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2528 ctx.ModuleErrorf("module %q not a static library", depName)
2529 return
Inseob Kim752edec2020-03-14 01:30:34 +09002530 }
2531
Colin Cross6e511a92020-07-27 21:26:48 -07002532 // Because the static library objects are included, this only makes sense
2533 // in the context of proper cc.Modules.
2534 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2535 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2536 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2537 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2538 for i := range missingDeps {
2539 missingDeps[i] += postfix
2540 }
2541 ctx.AddMissingDependencies(missingDeps)
2542 }
2543 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2544 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2545 } else {
2546 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2547 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002548 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002549 ctx.ModuleErrorf(
2550 "non-cc.Modules cannot be included as whole static libraries.", depName)
2551 return
2552 }
2553
2554 } else {
2555 switch libDepTag.Order {
2556 case earlyLibraryDependency:
2557 panic(fmt.Errorf("early static libs not suppported"))
2558 case normalLibraryDependency:
2559 // static dependencies will be handled separately so they can be ordered
2560 // using transitive dependencies.
2561 ptr = nil
2562 directStaticDeps = append(directStaticDeps, ccDep)
2563 case lateLibraryDependency:
2564 ptr = &depPaths.LateStaticLibs
2565 default:
2566 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002567 }
2568 }
2569 }
2570
Colin Cross6e511a92020-07-27 21:26:48 -07002571 if libDepTag.static() && !libDepTag.wholeStatic {
2572 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2573 ctx.ModuleErrorf("module %q not a static library", depName)
2574 return
2575 }
Logan Chien43d34c32017-12-20 01:17:32 +08002576
Colin Cross6e511a92020-07-27 21:26:48 -07002577 // When combining coverage files for shared libraries and executables, coverage files
2578 // in static libraries act as if they were whole static libraries. The same goes for
2579 // source based Abi dump files.
2580 if c, ok := ccDep.(*Module); ok {
2581 staticLib := c.linker.(libraryInterface)
2582 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2583 staticLib.objs().coverageFiles...)
2584 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2585 staticLib.objs().sAbiDumpFiles...)
2586 } else if c, ok := ccDep.(LinkableInterface); ok {
2587 // Handle non-CC modules here
2588 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2589 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002590 }
2591 }
2592
Colin Cross6e511a92020-07-27 21:26:48 -07002593 if ptr != nil {
2594 if !linkFile.Valid() {
2595 if !ctx.Config().AllowMissingDependencies() {
2596 ctx.ModuleErrorf("module %q missing output file", depName)
2597 } else {
2598 ctx.AddMissingDependencies([]string{depName})
2599 }
2600 return
2601 }
2602 *ptr = append(*ptr, linkFile.Path())
2603 }
2604
2605 if depPtr != nil {
2606 dep := depFile
2607 if !dep.Valid() {
2608 dep = linkFile
2609 }
2610 *depPtr = append(*depPtr, dep.Path())
2611 }
2612
2613 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2614 switch {
2615 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002616 c.Properties.AndroidMkHeaderLibs = append(
2617 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002618 case libDepTag.shared():
2619 if ccDep.CcLibrary() {
2620 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2621 // Add the dependency to the APEX(es) providing the library so that
2622 // m <module> can trigger building the APEXes as well.
2623 for _, an := range android.GetApexesForModule(depName) {
2624 c.Properties.ApexesProvidingSharedLibs = append(
2625 c.Properties.ApexesProvidingSharedLibs, an)
2626 }
2627 }
2628 }
2629
2630 // Note: the order of libs in this list is not important because
2631 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002632 c.Properties.AndroidMkSharedLibs = append(
2633 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002634 // Record baseLibName for snapshots.
2635 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2636 case libDepTag.static():
2637 if libDepTag.wholeStatic {
2638 c.Properties.AndroidMkWholeStaticLibs = append(
2639 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2640 } else {
2641 c.Properties.AndroidMkStaticLibs = append(
2642 c.Properties.AndroidMkStaticLibs, makeLibName)
2643 }
2644 }
2645 } else {
2646 switch depTag {
2647 case runtimeDepTag:
2648 c.Properties.AndroidMkRuntimeLibs = append(
2649 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2650 // Record baseLibName for snapshots.
2651 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2652 case objDepTag:
2653 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2654 case CrtBeginDepTag:
2655 depPaths.CrtBegin = linkFile
2656 case CrtEndDepTag:
2657 depPaths.CrtEnd = linkFile
2658 case dynamicLinkerDepTag:
2659 depPaths.DynamicLinker = linkFile
2660 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002661 }
Colin Crossca860ac2016-01-04 14:34:37 -08002662 })
2663
Jeff Gaston294356f2017-09-27 17:05:30 -07002664 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002665 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002666
Colin Crossdd84e052017-05-17 13:44:16 -07002667 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002668 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002669 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2670 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002671 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002672 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2673 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002674 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002675 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002676 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002677
2678 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002679 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002680 }
Colin Crossdd84e052017-05-17 13:44:16 -07002681
Colin Crossca860ac2016-01-04 14:34:37 -08002682 return depPaths
2683}
2684
Colin Cross6e511a92020-07-27 21:26:48 -07002685// baseLibName trims known prefixes and suffixes
2686func baseLibName(depName string) string {
2687 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2688 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2689 libName = strings.TrimPrefix(libName, "prebuilt_")
2690 return libName
2691}
2692
2693func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2694 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2695 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2696
2697 libName := baseLibName(depName)
2698 isLLndk := isLlndkLibrary(libName, ctx.Config())
2699 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2700 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2701
2702 if c, ok := ccDep.(*Module); ok {
2703 // Use base module name for snapshots when exporting to Makefile.
2704 if c.isSnapshotPrebuilt() {
2705 baseName := c.BaseModuleName()
2706
2707 if c.IsVndk() {
2708 return baseName + ".vendor"
2709 }
2710
2711 if vendorSuffixModules[baseName] {
2712 return baseName + ".vendor"
2713 } else {
2714 return baseName
2715 }
2716 }
2717 }
2718
2719 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2720 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2721 // core module instead.
2722 return libName
2723 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2724 // The vendor module in Make will have been renamed to not conflict with the core
2725 // module, so update the dependency name here accordingly.
2726 return libName + c.getNameSuffixWithVndkVersion(ctx)
2727 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2728 return libName + vendorPublicLibrarySuffix
2729 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2730 return libName + ramdiskSuffix
2731 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2732 return libName + recoverySuffix
2733 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2734 return libName + nativeBridgeSuffix
2735 } else {
2736 return libName
2737 }
2738}
2739
Colin Crossca860ac2016-01-04 14:34:37 -08002740func (c *Module) InstallInData() bool {
2741 if c.installer == nil {
2742 return false
2743 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002744 return c.installer.inData()
2745}
2746
2747func (c *Module) InstallInSanitizerDir() bool {
2748 if c.installer == nil {
2749 return false
2750 }
2751 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002752 return true
2753 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002754 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002755}
2756
Yifan Hong1b3348d2020-01-21 15:53:22 -08002757func (c *Module) InstallInRamdisk() bool {
2758 return c.InRamdisk()
2759}
2760
Jiyong Parkf9332f12018-02-01 00:54:12 +09002761func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002762 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002763}
2764
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002765func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002766 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002767 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002768 return
2769 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002770 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002771}
2772
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002773func (c *Module) HostToolPath() android.OptionalPath {
2774 if c.installer == nil {
2775 return android.OptionalPath{}
2776 }
2777 return c.installer.hostToolPath()
2778}
2779
Nan Zhangd4e641b2017-07-12 12:55:28 -07002780func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2781 return c.outputFile
2782}
2783
Colin Cross41955e82019-05-29 14:40:35 -07002784func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2785 switch tag {
2786 case "":
2787 if c.outputFile.Valid() {
2788 return android.Paths{c.outputFile.Path()}, nil
2789 }
2790 return android.Paths{}, nil
2791 default:
2792 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002793 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002794}
2795
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002796func (c *Module) static() bool {
2797 if static, ok := c.linker.(interface {
2798 static() bool
2799 }); ok {
2800 return static.static()
2801 }
2802 return false
2803}
2804
Jiyong Park379de2f2018-12-19 02:47:14 +09002805func (c *Module) staticBinary() bool {
2806 if static, ok := c.linker.(interface {
2807 staticBinary() bool
2808 }); ok {
2809 return static.staticBinary()
2810 }
2811 return false
2812}
2813
Jiyong Park1d1119f2019-07-29 21:27:18 +09002814func (c *Module) header() bool {
2815 if h, ok := c.linker.(interface {
2816 header() bool
2817 }); ok {
2818 return h.header()
2819 }
2820 return false
2821}
2822
Inseob Kim7f283f42020-06-01 21:53:49 +09002823func (c *Module) binary() bool {
2824 if b, ok := c.linker.(interface {
2825 binary() bool
2826 }); ok {
2827 return b.binary()
2828 }
2829 return false
2830}
2831
Inseob Kim1042d292020-06-01 23:23:05 +09002832func (c *Module) object() bool {
2833 if o, ok := c.linker.(interface {
2834 object() bool
2835 }); ok {
2836 return o.object()
2837 }
2838 return false
2839}
2840
Jooyung Han38002912019-05-16 04:01:54 +09002841func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002842 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002843 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2844 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002845 return "native:vndk"
2846 }
Jooyung Han38002912019-05-16 04:01:54 +09002847 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002848 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002849 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002850 if Bool(c.VendorProperties.Vendor_available) {
2851 return "native:vndk"
2852 }
2853 return "native:vndk_private"
2854 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002855 if c.inProduct() {
2856 return "native:product"
2857 }
Jooyung Han38002912019-05-16 04:01:54 +09002858 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002859 } else if c.InRamdisk() {
2860 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002861 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002862 return "native:recovery"
2863 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2864 return "native:ndk:none:none"
2865 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2866 //family, link := getNdkStlFamilyAndLinkType(c)
2867 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002868 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002869 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002870 } else {
2871 return "native:platform"
2872 }
2873}
2874
Jiyong Park9d452992018-10-03 00:38:19 +09002875// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002876// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002877func (c *Module) IsInstallableToApex() bool {
2878 if shared, ok := c.linker.(interface {
2879 shared() bool
2880 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002881 // Stub libs and prebuilt libs in a versioned SDK are not
2882 // installable to APEX even though they are shared libs.
2883 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002884 } else if _, ok := c.linker.(testPerSrc); ok {
2885 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002886 }
2887 return false
2888}
2889
Jiyong Parka90ca002019-10-07 15:47:24 +09002890func (c *Module) AvailableFor(what string) bool {
2891 if linker, ok := c.linker.(interface {
2892 availableFor(string) bool
2893 }); ok {
2894 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2895 } else {
2896 return c.ApexModuleBase.AvailableFor(what)
2897 }
2898}
2899
Jiyong Park62304bb2020-04-13 16:19:48 +09002900func (c *Module) TestFor() []string {
2901 if test, ok := c.linker.(interface {
2902 testFor() []string
2903 }); ok {
2904 return test.testFor()
2905 } else {
2906 return c.ApexModuleBase.TestFor()
2907 }
2908}
2909
Colin Crossaede88c2020-08-11 12:17:01 -07002910func (c *Module) UniqueApexVariations() bool {
2911 if u, ok := c.compiler.(interface {
2912 uniqueApexVariations() bool
2913 }); ok {
2914 return u.uniqueApexVariations()
2915 } else {
2916 return false
2917 }
2918}
2919
Paul Duffin0cb37b92020-03-04 14:52:46 +00002920// Return true if the module is ever installable.
2921func (c *Module) EverInstallable() bool {
2922 return c.installer != nil &&
2923 // Check to see whether the module is actually ever installable.
2924 c.installer.everInstallable()
2925}
2926
Inseob Kim1f086e22019-05-09 13:29:15 +09002927func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002928 ret := c.EverInstallable() &&
2929 // Check to see whether the module has been configured to not be installed.
2930 proptools.BoolDefault(c.Properties.Installable, true) &&
2931 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002932
2933 // The platform variant doesn't need further condition. Apex variants however might not
2934 // be installable because it will likely to be included in the APEX and won't appear
2935 // in the system partition.
2936 if c.IsForPlatform() {
2937 return ret
2938 }
2939
2940 // Special case for modules that are configured to be installed to /data, which includes
2941 // test modules. For these modules, both APEX and non-APEX variants are considered as
2942 // installable. This is because even the APEX variants won't be included in the APEX, but
2943 // will anyway be installed to /data/*.
2944 // See b/146995717
2945 if c.InstallInData() {
2946 return ret
2947 }
2948
2949 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002950}
2951
Logan Chien41eabe62019-04-10 13:33:58 +08002952func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2953 if c.linker != nil {
2954 if library, ok := c.linker.(*libraryDecorator); ok {
2955 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2956 }
2957 }
2958}
2959
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002960func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002961 depTag := ctx.OtherModuleDependencyTag(dep)
2962 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2963
2964 if cc, ok := dep.(*Module); ok {
2965 if cc.HasStubsVariants() {
2966 if isLibDepTag && libDepTag.shared() {
2967 // dynamic dep to a stubs lib crosses APEX boundary
2968 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002969 }
Colin Cross6e511a92020-07-27 21:26:48 -07002970 if IsRuntimeDepTag(depTag) {
2971 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002972 return false
2973 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002974 }
Colin Crossaac32222020-07-29 12:51:56 -07002975 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002976 // shared_lib dependency from a static lib is considered as crossing
2977 // the APEX boundary because the dependency doesn't actually is
2978 // linked; the dependency is used only during the compilation phase.
2979 return false
2980 }
2981 }
2982 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09002983 // We don't track beyond LLNDK
2984 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002985 }
2986 return true
2987}
2988
Jooyung Han749dc692020-04-15 11:03:39 +09002989// b/154667674: refactor this to handle "current" in a consistent way
2990func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
2991 if versionString == "" {
2992 return 0, fmt.Errorf("not specified")
2993 }
2994 if versionString == "current" {
2995 if ctx.Config().PlatformSdkCodename() == "REL" {
2996 return ctx.Config().PlatformSdkVersionInt(), nil
2997 }
2998 return android.FutureApiLevel, nil
2999 }
3000 return android.ApiStrToNum(ctx, versionString)
3001}
3002
3003func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
3004 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3005 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3006 return nil
3007 }
3008 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3009 if c.ToolchainLibrary() {
3010 return nil
3011 }
3012 // We don't check for prebuilt modules
3013 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3014 return nil
3015 }
3016 minSdkVersion := c.MinSdkVersion()
3017 if minSdkVersion == "apex_inherit" {
3018 return nil
3019 }
3020 if minSdkVersion == "" {
3021 // JNI libs within APK-in-APEX fall into here
3022 // Those are okay to set sdk_version instead
3023 // We don't have to check if this is a SDK variant because
3024 // non-SDK variant resets sdk_version, which works too.
3025 minSdkVersion = c.SdkVersion()
3026 }
3027 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
3028 if err != nil {
3029 return err
3030 }
3031 if ver > sdkVersion {
3032 return fmt.Errorf("newer SDK(%v)", ver)
3033 }
3034 return nil
3035}
3036
Colin Cross2ba19d92015-05-07 15:44:20 -07003037//
Colin Crosscfad1192015-11-02 16:43:11 -08003038// Defaults
3039//
Colin Crossca860ac2016-01-04 14:34:37 -08003040type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003041 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003042 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003043 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003044}
3045
Patrice Arrudac249c712019-03-19 17:00:29 -07003046// cc_defaults provides a set of properties that can be inherited by other cc
3047// modules. A module can use the properties from a cc_defaults using
3048// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3049// merged (when possible) by prepending the default module's values to the
3050// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003051func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003052 return DefaultsFactory()
3053}
3054
Colin Cross36242852017-06-23 15:06:31 -07003055func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003056 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003057
Colin Cross36242852017-06-23 15:06:31 -07003058 module.AddProperties(props...)
3059 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003060 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003061 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003062 &BaseCompilerProperties{},
3063 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003064 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003065 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003066 &StaticProperties{},
3067 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003068 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003069 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003070 &TestProperties{},
3071 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003072 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003073 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003074 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003075 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003076 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003077 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003078 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003079 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003080 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003081 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003082 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003083 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003084 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003085 )
Colin Crosscfad1192015-11-02 16:43:11 -08003086
Jooyung Hancc372c52019-09-25 15:18:44 +09003087 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003088
3089 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003090}
3091
Jiyong Park6a43f042017-10-12 23:05:00 +09003092func squashVendorSrcs(m *Module) {
3093 if lib, ok := m.compiler.(*libraryDecorator); ok {
3094 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3095 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3096
3097 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3098 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003099
3100 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3101 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003102 }
3103}
3104
Jiyong Parkf9332f12018-02-01 00:54:12 +09003105func squashRecoverySrcs(m *Module) {
3106 if lib, ok := m.compiler.(*libraryDecorator); ok {
3107 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3108 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3109
3110 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3111 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003112
3113 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3114 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003115 }
3116}
3117
Jiyong Park2286afd2020-06-16 21:58:53 +09003118func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003119 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003120}
3121
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003122func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003123 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003124 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3125 }
Colin Cross6510f912017-11-29 00:27:14 -08003126 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003127}
3128
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003129func kytheExtractAllFactory() android.Singleton {
3130 return &kytheExtractAllSingleton{}
3131}
3132
3133type kytheExtractAllSingleton struct {
3134}
3135
3136func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3137 var xrefTargets android.Paths
3138 ctx.VisitAllModules(func(module android.Module) {
3139 if ccModule, ok := module.(xref); ok {
3140 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3141 }
3142 })
3143 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3144 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003145 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003146 }
3147}
3148
Colin Cross06a931b2015-10-28 17:23:31 -07003149var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003150var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003151var BoolPtr = proptools.BoolPtr
3152var String = proptools.String
3153var StringPtr = proptools.StringPtr