blob: c1a4327439530e1607b9f050b8bacf14302110ec [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()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Colin Crossd1f898e2020-08-18 18:35:15 -070049 ctx.BottomUp("version_selector", versionSelectorMutator).Parallel()
50 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
Jooyung Han479ca172020-10-19 18:51:07 +090087 ctx.BottomUp("check_linktype", checkLinkTypeMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090088 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070089 })
Colin Crossb98c8b02016-07-29 13:44:28 -070090
Sasha Smundak2a4549e2018-11-05 16:49:08 -080091 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070092}
93
Colin Crossca860ac2016-01-04 14:34:37 -080094type Deps struct {
95 SharedLibs, LateSharedLibs []string
96 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080097 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080098 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070099
Chris Parsons79d66a52020-06-05 17:26:16 -0400100 // Used for data dependencies adjacent to tests
101 DataLibs []string
102
Yo Chiang219968c2020-09-22 18:45:04 +0800103 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
104 SystemSharedLibs []string
105
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800106 StaticUnwinderIfLegacy bool
107
Colin Cross5950f382016-12-13 12:50:57 -0800108 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700109
Colin Cross81413472016-04-11 14:37:39 -0700110 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700111
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112 GeneratedSources []string
113 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900114 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700115
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700116 ReexportGeneratedHeaders []string
117
Colin Cross97ba0732015-03-23 17:50:24 -0700118 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Used for host bionic
121 LinkerFlagsFile string
122 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700123}
124
Colin Crossca860ac2016-01-04 14:34:37 -0800125type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900127 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700128 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900129 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross0de8a1e2020-09-18 14:15:30 -0700133 // Transitive static library dependencies of static libraries for use in ordering.
134 TranstiveStaticLibrariesForOrdering *android.DepSet
135
Colin Cross26c34ed2016-09-30 17:10:16 -0700136 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100137 Objs Objects
138 // Paths to .o files in dependencies that provide them. Note that these lists
139 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800140 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700141 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700142
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100143 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
144 // the libs from all whole_static_lib dependencies.
145 WholeStaticLibsFromPrebuilts android.Paths
146
Colin Cross26c34ed2016-09-30 17:10:16 -0700147 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700148 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900149 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700150
Inseob Kimd110f872019-12-06 13:15:38 +0900151 Flags []string
152 IncludeDirs android.Paths
153 SystemIncludeDirs android.Paths
154 ReexportedDirs android.Paths
155 ReexportedSystemDirs android.Paths
156 ReexportedFlags []string
157 ReexportedGeneratedHeaders android.Paths
158 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700159
Colin Cross26c34ed2016-09-30 17:10:16 -0700160 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700161 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700162
163 // Path to the file container flags to use with the linker
164 LinkerFlagsFile android.OptionalPath
165
166 // Path to the dynamic linker binary
167 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700168}
169
Colin Cross4af21ed2019-11-04 09:37:55 -0800170// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
171// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
172// command line so they can be overridden by the local module flags).
173type LocalOrGlobalFlags struct {
174 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700175 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800176 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700177 CFlags []string // Flags that apply to C and C++ source files
178 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
179 ConlyFlags []string // Flags that apply to C source files
180 CppFlags []string // Flags that apply to C++ source files
181 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700182 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800183}
184
185type Flags struct {
186 Local LocalOrGlobalFlags
187 Global LocalOrGlobalFlags
188
189 aidlFlags []string // Flags that apply to aidl source files
190 rsFlags []string // Flags that apply to renderscript source files
191 libFlags []string // Flags to add libraries early to the link order
192 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
193 TidyFlags []string // Flags that apply to clang-tidy
194 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700195
Colin Crossc3199482017-03-30 15:03:04 -0700196 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800197 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700198 SystemIncludeFlags []string
199
Oliver Nguyen04526782020-04-21 12:40:27 -0700200 Toolchain config.Toolchain
201 Tidy bool
202 GcovCoverage bool
203 SAbiDump bool
204 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800205
206 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800207 DynamicLinker string
208
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700209 CFlagsDeps android.Paths // Files depended on by compiler flags
210 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800211
Dan Willemsen98ab3112019-08-27 21:20:40 -0700212 AssemblerWithCpp bool
213 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800214
Colin Cross19878da2019-03-28 14:45:07 -0700215 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700216 protoC bool // Whether to use C instead of C++
217 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700218
219 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200220 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700221}
222
Colin Crossca860ac2016-01-04 14:34:37 -0800223// Properties used to compile all C or C++ modules
224type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700225 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800226 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700227
Colin Crossc511bc52020-04-07 16:50:32 +0000228 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
229 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800230 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700231
Jooyung Han379660c2020-04-21 15:24:00 +0900232 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
233 Min_sdk_version *string
234
Colin Crossc511bc52020-04-07 16:50:32 +0000235 // If true, always create an sdk variant and don't create a platform variant.
236 Sdk_variant_only *bool
237
Jiyong Parkde866cb2018-12-07 23:08:36 +0900238 AndroidMkSharedLibs []string `blueprint:"mutated"`
239 AndroidMkStaticLibs []string `blueprint:"mutated"`
240 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
241 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700242 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900243 HideFromMake bool `blueprint:"mutated"`
244 PreventInstall bool `blueprint:"mutated"`
245 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700246
Yo Chiang219968c2020-09-22 18:45:04 +0800247 // Set by DepsMutator.
248 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
249
Justin Yun5f7f7e82019-11-18 19:52:14 +0900250 ImageVariationPrefix string `blueprint:"mutated"`
251 VndkVersion string `blueprint:"mutated"`
252 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800253
254 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
255 // file
256 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900257
Yifan Hong1b3348d2020-01-21 15:53:22 -0800258 // Make this module available when building for ramdisk
259 Ramdisk_available *bool
260
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700261 // Make this module available when building for vendor ramdisk
262 Vendor_ramdisk_available *bool
263
Jiyong Parkf9332f12018-02-01 00:54:12 +0900264 // Make this module available when building for recovery
265 Recovery_available *bool
266
Colin Crossae6c5202019-11-20 13:35:50 -0800267 // Set by imageMutator
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700268 CoreVariantNeeded bool `blueprint:"mutated"`
269 RamdiskVariantNeeded bool `blueprint:"mutated"`
270 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
271 RecoveryVariantNeeded bool `blueprint:"mutated"`
272 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900273
274 // Allows this module to use non-APEX version of libraries. Useful
275 // for building binaries that are started before APEXes are activated.
276 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900277
278 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
279 // see soong/cc/config/vndk.go
280 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900281
282 // Used by vendor snapshot to record dependencies from snapshot modules.
283 SnapshotSharedLibs []string `blueprint:"mutated"`
284 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000285
286 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000287
288 // Set by factories of module types that can only be referenced from variants compiled against
289 // the SDK.
290 AlwaysSdk bool `blueprint:"mutated"`
291
292 // Variant is an SDK variant created by sdkMutator
293 IsSdkVariant bool `blueprint:"mutated"`
294 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
295 // variant to have a ".sdk" suffix.
296 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700297
298 // Normally Soong uses the directory structure to decide which modules
299 // should be included (framework) or excluded (non-framework) from the
300 // vendor snapshot, but this property allows a partner to exclude a
301 // module normally thought of as a framework module from the vendor
302 // snapshot.
303 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700304}
305
306type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900307 // whether this module should be allowed to be directly depended by other
308 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900309 // In addition, this module should be allowed to be directly depended by
310 // product modules with `product_specific: true`.
311 // If set to true, three variants will be built separately, one like
312 // normal, another limited to the set of libraries and headers
313 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700314 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900315 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700316 // so it shouldn't have any unversioned runtime dependencies, or
317 // make assumptions about the system that may not be true in the
318 // future.
319 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900320 // If set to false, this module becomes inaccessible from /vendor or /product
321 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900322 //
323 // Default value is true when vndk: {enabled: true} or vendor: true.
324 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700325 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900326 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700327 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900328
329 // whether this module is capable of being loaded with other instance
330 // (possibly an older version) of the same module in the same process.
331 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
332 // can be double loaded in a vendor process if the library is also a
333 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
334 // explicitly marked as `double_loadable: true` by the owner, or the dependency
335 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
336 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800337}
338
Colin Crossca860ac2016-01-04 14:34:37 -0800339type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800340 static() bool
341 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900342 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900343 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900344 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700345 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900346 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700347 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800348 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700349 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800350 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900351 isLlndk(config android.Config) bool
352 isLlndkPublic(config android.Config) bool
353 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900354 isVndk() bool
355 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800356 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900357 inProduct() bool
358 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800359 inRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700360 inVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900361 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800362 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700363 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700364 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800365 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800366 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800367 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800368 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800369 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700370 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700371 apexSdkVersion() android.ApiLevel
Jiyong Parkb0788572018-12-20 22:10:17 +0900372 hasStubsVariants() bool
373 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900374 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800375 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700376 nativeCoverage() bool
Colin Cross56a83212020-09-15 18:30:11 -0700377 directlyInAnyApex() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800378}
379
380type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700381 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800382 ModuleContextIntf
383}
384
385type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700386 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800387 ModuleContextIntf
388}
389
Colin Cross37047f12016-12-13 17:06:13 -0800390type DepsContext interface {
391 android.BottomUpMutatorContext
392 ModuleContextIntf
393}
394
Colin Crossca860ac2016-01-04 14:34:37 -0800395type feature interface {
396 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800397 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800398 flags(ctx ModuleContext, flags Flags) Flags
399 props() []interface{}
400}
401
402type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700403 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800404 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800405 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700406 compilerProps() []interface{}
407
Colin Cross76fada02016-07-27 10:31:13 -0700408 appendCflags([]string)
409 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700410 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800411}
412
413type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700414 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800415 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700416 linkerFlags(ctx ModuleContext, flags Flags) Flags
417 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800418 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700419
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700420 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700421 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900422 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700423
424 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900425 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000426
427 // Get the deps that have been explicitly specified in the properties.
428 // Only updates the
429 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
430}
431
432type specifiedDeps struct {
433 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000434 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800435}
436
437type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700438 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700439 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000440 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800441 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700442 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700443 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900444 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100445 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800446}
447
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800448type xref interface {
449 XrefCcFiles() android.Paths
450}
451
Colin Cross6e511a92020-07-27 21:26:48 -0700452type libraryDependencyKind int
453
454const (
455 headerLibraryDependency = iota
456 sharedLibraryDependency
457 staticLibraryDependency
458)
459
460func (k libraryDependencyKind) String() string {
461 switch k {
462 case headerLibraryDependency:
463 return "headerLibraryDependency"
464 case sharedLibraryDependency:
465 return "sharedLibraryDependency"
466 case staticLibraryDependency:
467 return "staticLibraryDependency"
468 default:
469 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
470 }
471}
472
473type libraryDependencyOrder int
474
475const (
476 earlyLibraryDependency = -1
477 normalLibraryDependency = 0
478 lateLibraryDependency = 1
479)
480
481func (o libraryDependencyOrder) String() string {
482 switch o {
483 case earlyLibraryDependency:
484 return "earlyLibraryDependency"
485 case normalLibraryDependency:
486 return "normalLibraryDependency"
487 case lateLibraryDependency:
488 return "lateLibraryDependency"
489 default:
490 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
491 }
492}
493
494// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
495// tags that have a set of predefined tag objects that are reused for each dependency, a
496// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
497// That means that comparing a libraryDependencyTag for equality will only be equal if all
498// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
499// then check individual metadata fields instead.
500type libraryDependencyTag struct {
501 blueprint.BaseDependencyTag
502
503 // These are exported so that fmt.Printf("%#v") can call their String methods.
504 Kind libraryDependencyKind
505 Order libraryDependencyOrder
506
507 wholeStatic bool
508
509 reexportFlags bool
510 explicitlyVersioned bool
511 dataLib bool
512 ndk bool
513
514 staticUnwinder bool
515
516 makeSuffix string
517}
518
519// header returns true if the libraryDependencyTag is tagging a header lib dependency.
520func (d libraryDependencyTag) header() bool {
521 return d.Kind == headerLibraryDependency
522}
523
524// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
525func (d libraryDependencyTag) shared() bool {
526 return d.Kind == sharedLibraryDependency
527}
528
529// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
530func (d libraryDependencyTag) static() bool {
531 return d.Kind == staticLibraryDependency
532}
533
534// dependencyTag is used for tagging miscellanous dependency types that don't fit into
535// libraryDependencyTag. Each tag object is created globally and reused for multiple
536// dependencies (although since the object contains no references, assigning a tag to a
537// variable and modifying it will not modify the original). Users can compare the tag
538// returned by ctx.OtherModuleDependencyTag against the global original
539type dependencyTag struct {
540 blueprint.BaseDependencyTag
541 name string
542}
543
Colin Crossc99deeb2016-04-11 15:06:20 -0700544var (
Colin Cross6e511a92020-07-27 21:26:48 -0700545 genSourceDepTag = dependencyTag{name: "gen source"}
546 genHeaderDepTag = dependencyTag{name: "gen header"}
547 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
548 objDepTag = dependencyTag{name: "obj"}
549 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
550 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
551 reuseObjTag = dependencyTag{name: "reuse objects"}
552 staticVariantTag = dependencyTag{name: "static variant"}
553 vndkExtDepTag = dependencyTag{name: "vndk extends"}
554 dataLibDepTag = dependencyTag{name: "data lib"}
555 runtimeDepTag = dependencyTag{name: "runtime lib"}
556 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700557 stubImplDepTag = dependencyTag{name: "stub_impl"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700558)
559
Colin Cross56a83212020-09-15 18:30:11 -0700560type copyDirectlyInAnyApexDependencyTag dependencyTag
561
562func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
563
564var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
565
Roland Levillainf89cd092019-07-29 16:22:59 +0100566func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700567 ccLibDepTag, ok := depTag.(libraryDependencyTag)
568 return ok && ccLibDepTag.shared()
569}
570
571func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
572 ccLibDepTag, ok := depTag.(libraryDependencyTag)
573 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100574}
575
576func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700577 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100578 return ok && ccDepTag == runtimeDepTag
579}
580
581func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700582 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100583 return ok && ccDepTag == testPerSrcDepTag
584}
585
Colin Crossca860ac2016-01-04 14:34:37 -0800586// Module contains the properties and members used by all C/C++ module types, and implements
587// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
588// to construct the output file. Behavior can be customized with a Customizer interface
589type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700590 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700591 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900592 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900593 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700594
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700595 Properties BaseProperties
596 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700597
Colin Crossca860ac2016-01-04 14:34:37 -0800598 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700599 hod android.HostOrDeviceSupported
600 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700601
Paul Duffina0843f62019-12-13 19:50:38 +0000602 // Allowable SdkMemberTypes of this module type.
603 sdkMemberTypes []android.SdkMemberType
604
Colin Crossca860ac2016-01-04 14:34:37 -0800605 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700606 features []feature
607 compiler compiler
608 linker linker
609 installer installer
610 stl *stl
611 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800612 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800613 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900614 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700615 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700616 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800617
Colin Cross635c3b02016-05-18 15:37:25 -0700618 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800619
Colin Crossb98c8b02016-07-29 13:44:28 -0700620 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700621
622 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800623
624 // Flags used to compile this module
625 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700626
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800627 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700628 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900629
630 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800631 // Kythe (source file indexer) paths for this compilation module
632 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900633
634 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700635 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700636
637 hideApexVariantFromMake bool
Colin Crossc472d572015-03-17 15:06:21 -0700638}
639
Ivan Lozano52767be2019-10-18 14:49:46 -0700640func (c *Module) Toc() android.OptionalPath {
641 if c.linker != nil {
642 if library, ok := c.linker.(libraryInterface); ok {
643 return library.toc()
644 }
645 }
646 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
647}
648
649func (c *Module) ApiLevel() string {
650 if c.linker != nil {
651 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700652 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700653 }
654 }
655 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
656}
657
658func (c *Module) Static() bool {
659 if c.linker != nil {
660 if library, ok := c.linker.(libraryInterface); ok {
661 return library.static()
662 }
663 }
664 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
665}
666
667func (c *Module) Shared() bool {
668 if c.linker != nil {
669 if library, ok := c.linker.(libraryInterface); ok {
670 return library.shared()
671 }
672 }
673 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
674}
675
676func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000677 if c.stl != nil {
678 return c.stl.Properties.SelectedStl
679 }
680 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700681}
682
683func (c *Module) ToolchainLibrary() bool {
684 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
685 return true
686 }
687 return false
688}
689
690func (c *Module) NdkPrebuiltStl() bool {
691 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
692 return true
693 }
694 return false
695}
696
697func (c *Module) StubDecorator() bool {
698 if _, ok := c.linker.(*stubDecorator); ok {
699 return true
700 }
701 return false
702}
703
704func (c *Module) SdkVersion() string {
705 return String(c.Properties.Sdk_version)
706}
707
Artur Satayev480e25b2020-04-27 18:53:18 +0100708func (c *Module) MinSdkVersion() string {
709 return String(c.Properties.Min_sdk_version)
710}
711
Dan Albert92fe7402020-07-15 13:33:30 -0700712func (c *Module) SplitPerApiLevel() bool {
Colin Cross1348ce32020-10-01 13:37:16 -0700713 if !c.canUseSdk() {
714 return false
715 }
Dan Albert92fe7402020-07-15 13:33:30 -0700716 if linker, ok := c.linker.(*objectLinker); ok {
717 return linker.isCrt()
718 }
719 return false
720}
721
Colin Crossc511bc52020-04-07 16:50:32 +0000722func (c *Module) AlwaysSdk() bool {
723 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
724}
725
Colin Cross3572cf72020-10-01 15:58:11 -0700726func (c *Module) StubsVersions(ctx android.BaseMutatorContext) []string {
Colin Crossc88c2722020-09-28 17:32:47 -0700727 if versioned, ok := c.linker.(versionedInterface); ok {
Colin Cross3572cf72020-10-01 15:58:11 -0700728 return versioned.stubsVersions(ctx)
Ivan Lozano183a3212019-10-18 14:18:45 -0700729 }
730 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
731}
732
733func (c *Module) CcLibrary() bool {
734 if c.linker != nil {
735 if _, ok := c.linker.(*libraryDecorator); ok {
736 return true
737 }
Colin Crossd48fe732020-09-23 20:37:24 -0700738 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
739 return true
740 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700741 }
742 return false
743}
744
745func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700746 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700747 return true
748 }
749 return false
750}
751
Ivan Lozano2b262972019-11-21 12:30:50 -0800752func (c *Module) NonCcVariants() bool {
753 return false
754}
755
Ivan Lozano183a3212019-10-18 14:18:45 -0700756func (c *Module) SetBuildStubs() {
Colin Crossc88c2722020-09-28 17:32:47 -0700757 if versioned, ok := c.linker.(versionedInterface); ok {
758 versioned.setBuildStubs()
759 c.Properties.HideFromMake = true
760 c.sanitize = nil
761 c.stl = nil
762 c.Properties.PreventInstall = true
763 return
Ivan Lozano183a3212019-10-18 14:18:45 -0700764 }
765 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
766}
767
Ivan Lozano52767be2019-10-18 14:49:46 -0700768func (c *Module) BuildStubs() bool {
Colin Crossc88c2722020-09-28 17:32:47 -0700769 if versioned, ok := c.linker.(versionedInterface); ok {
770 return versioned.buildStubs()
Ivan Lozano52767be2019-10-18 14:49:46 -0700771 }
772 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
773}
774
Colin Crossd1f898e2020-08-18 18:35:15 -0700775func (c *Module) SetAllStubsVersions(versions []string) {
Colin Crossc88c2722020-09-28 17:32:47 -0700776 if versioned, ok := c.linker.(versionedInterface); ok {
777 versioned.setAllStubsVersions(versions)
Colin Crossd1f898e2020-08-18 18:35:15 -0700778 }
779}
780
781func (c *Module) AllStubsVersions() []string {
Colin Crossc88c2722020-09-28 17:32:47 -0700782 if versioned, ok := c.linker.(versionedInterface); ok {
783 return versioned.allStubsVersions()
Colin Crossd1f898e2020-08-18 18:35:15 -0700784 }
785 return nil
786}
787
788func (c *Module) SetStubsVersion(version string) {
Colin Crossc88c2722020-09-28 17:32:47 -0700789 if versioned, ok := c.linker.(versionedInterface); ok {
790 versioned.setStubsVersion(version)
791 return
Ivan Lozano183a3212019-10-18 14:18:45 -0700792 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700793 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700794}
795
Jooyung Han03b51852020-02-26 22:45:42 +0900796func (c *Module) StubsVersion() string {
Colin Crossc88c2722020-09-28 17:32:47 -0700797 if versioned, ok := c.linker.(versionedInterface); ok {
798 return versioned.stubsVersion()
Jooyung Han03b51852020-02-26 22:45:42 +0900799 }
800 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
801}
802
Ivan Lozano183a3212019-10-18 14:18:45 -0700803func (c *Module) SetStatic() {
804 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700805 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700806 library.setStatic()
807 return
808 }
809 }
810 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
811}
812
813func (c *Module) SetShared() {
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.setShared()
817 return
818 }
819 }
820 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
821}
822
823func (c *Module) BuildStaticVariant() bool {
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 return library.buildStatic()
827 }
828 }
829 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
830}
831
832func (c *Module) BuildSharedVariant() bool {
833 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700834 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700835 return library.buildShared()
836 }
837 }
838 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
839}
840
841func (c *Module) Module() android.Module {
842 return c
843}
844
Jiyong Parkc20eee32018-09-05 22:36:17 +0900845func (c *Module) OutputFile() android.OptionalPath {
846 return c.outputFile
847}
848
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400849func (c *Module) CoverageFiles() android.Paths {
850 if c.linker != nil {
851 if library, ok := c.linker.(libraryInterface); ok {
852 return library.objs().coverageFiles
853 }
854 }
855 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
856}
857
Ivan Lozano183a3212019-10-18 14:18:45 -0700858var _ LinkableInterface = (*Module)(nil)
859
Jiyong Park719b4462019-01-13 00:39:51 +0900860func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900861 if c.linker != nil {
862 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900863 }
864 return nil
865}
866
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900867func (c *Module) CoverageOutputFile() android.OptionalPath {
868 if c.linker != nil {
869 return c.linker.coverageOutputFilePath()
870 }
871 return android.OptionalPath{}
872}
873
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900874func (c *Module) RelativeInstallPath() string {
875 if c.installer != nil {
876 return c.installer.relativeInstallPath()
877 }
878 return ""
879}
880
Jooyung Han344d5432019-08-23 11:17:39 +0900881func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900882 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900883}
884
Colin Cross36242852017-06-23 15:06:31 -0700885func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700886 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800887 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700888 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800889 }
890 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700891 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800892 }
893 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700894 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800895 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700896 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700897 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700898 }
Colin Cross16b23492016-01-06 14:41:07 -0800899 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700900 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800901 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800902 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700903 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800904 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800905 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700906 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800907 }
Justin Yun8effde42017-06-23 19:24:43 +0900908 if c.vndkdep != nil {
909 c.AddProperties(c.vndkdep.props()...)
910 }
Stephen Craneba090d12017-05-09 15:44:35 -0700911 if c.lto != nil {
912 c.AddProperties(c.lto.props()...)
913 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700914 if c.pgo != nil {
915 c.AddProperties(c.pgo.props()...)
916 }
Colin Crossca860ac2016-01-04 14:34:37 -0800917 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700918 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800919 }
Colin Crossc472d572015-03-17 15:06:21 -0700920
Jiyong Park1613e552020-09-14 19:43:17 +0900921 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700922 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900923 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700924 })
Colin Cross36242852017-06-23 15:06:31 -0700925 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900926 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900927 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900928 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900929
Colin Cross36242852017-06-23 15:06:31 -0700930 return c
Colin Crossc472d572015-03-17 15:06:21 -0700931}
932
Colin Crossb916a382016-07-29 17:28:03 -0700933// Returns true for dependency roots (binaries)
934// TODO(ccross): also handle dlopenable libraries
935func (c *Module) isDependencyRoot() bool {
936 if root, ok := c.linker.(interface {
937 isDependencyRoot() bool
938 }); ok {
939 return root.isDependencyRoot()
940 }
941 return false
942}
943
Justin Yun5f7f7e82019-11-18 19:52:14 +0900944// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
945// "product" and "vendor" variant modules return true for this function.
946// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
947// "soc_specific: true" and more vendor installed modules are included here.
948// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
949// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700950func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900951 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700952}
953
Colin Crossc511bc52020-04-07 16:50:32 +0000954func (c *Module) canUseSdk() bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700955 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
Colin Crossc511bc52020-04-07 16:50:32 +0000956}
957
958func (c *Module) UseSdk() bool {
959 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -0700960 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +0000961 }
962 return false
963}
964
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800965func (c *Module) isCoverageVariant() bool {
966 return c.coverage.Properties.IsCoverageVariant
967}
968
Peter Collingbournead84f972019-12-17 16:46:18 -0800969func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -0700970 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800971}
972
Inseob Kim9516ee92019-05-09 10:56:13 +0900973func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800974 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900975 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800976}
977
Inseob Kim9516ee92019-05-09 10:56:13 +0900978func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800979 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900980 name := c.BaseModuleName()
981 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800982}
983
Inseob Kim9516ee92019-05-09 10:56:13 +0900984func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800985 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900986 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800987}
988
Ivan Lozano52767be2019-10-18 14:49:46 -0700989func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800990 if vndkdep := c.vndkdep; vndkdep != nil {
991 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900992 }
993 return false
994}
995
Yi Kong7e53c572018-02-14 18:16:12 +0800996func (c *Module) isPgoCompile() bool {
997 if pgo := c.pgo; pgo != nil {
998 return pgo.Properties.PgoCompile
999 }
1000 return false
1001}
1002
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001003func (c *Module) isNDKStubLibrary() bool {
1004 if _, ok := c.compiler.(*stubDecorator); ok {
1005 return true
1006 }
1007 return false
1008}
1009
Logan Chienf3511742017-10-31 18:04:35 +08001010func (c *Module) isVndkSp() bool {
1011 if vndkdep := c.vndkdep; vndkdep != nil {
1012 return vndkdep.isVndkSp()
1013 }
1014 return false
1015}
1016
1017func (c *Module) isVndkExt() bool {
1018 if vndkdep := c.vndkdep; vndkdep != nil {
1019 return vndkdep.isVndkExt()
1020 }
1021 return false
1022}
1023
Ivan Lozano52767be2019-10-18 14:49:46 -07001024func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001025 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001026}
1027
Logan Chienf3511742017-10-31 18:04:35 +08001028func (c *Module) getVndkExtendsModuleName() string {
1029 if vndkdep := c.vndkdep; vndkdep != nil {
1030 return vndkdep.getVndkExtendsModuleName()
1031 }
1032 return ""
1033}
1034
Jiyong Park25fc6a92018-11-18 18:02:45 +09001035func (c *Module) IsStubs() bool {
Colin Crossc88c2722020-09-28 17:32:47 -07001036 if versioned, ok := c.linker.(versionedInterface); ok {
1037 return versioned.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001038 }
1039 return false
1040}
1041
1042func (c *Module) HasStubsVariants() bool {
Colin Crossc88c2722020-09-28 17:32:47 -07001043 if versioned, ok := c.linker.(versionedInterface); ok {
1044 return versioned.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001045 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001046 return false
1047}
1048
Colin Cross0477b422020-10-13 18:43:54 -07001049// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
1050// the implementation. If it is an implementation library it returns its own name.
1051func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
1052 name := ctx.OtherModuleName(c)
1053 if versioned, ok := c.linker.(versionedInterface); ok {
1054 name = versioned.implementationModuleName(name)
1055 }
1056 return name
1057}
1058
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001059func (c *Module) bootstrap() bool {
1060 return Bool(c.Properties.Bootstrap)
1061}
1062
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001063func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001064 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1065 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1066 return false
1067 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001068 return c.linker != nil && c.linker.nativeCoverage()
1069}
1070
Inseob Kim8471cda2019-11-15 09:59:12 +09001071func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001072 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1073 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001074 }
1075 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001076}
1077
Bill Peckham945441c2020-08-31 16:07:58 -07001078func (c *Module) ExcludeFromVendorSnapshot() bool {
1079 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1080}
1081
Jiyong Parkf1194352019-02-25 11:05:47 +09001082func isBionic(name string) bool {
1083 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001084 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001085 return true
1086 }
1087 return false
1088}
1089
Martin Stjernholm279de572019-09-10 23:18:20 +01001090func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001091 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001092 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001093 }
1094 return isBionic(name)
1095}
1096
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001097func (c *Module) XrefCcFiles() android.Paths {
1098 return c.kytheFiles
1099}
1100
Colin Crossca860ac2016-01-04 14:34:37 -08001101type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001102 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001103 moduleContextImpl
1104}
1105
Colin Cross37047f12016-12-13 17:06:13 -08001106type depsContext struct {
1107 android.BottomUpMutatorContext
1108 moduleContextImpl
1109}
1110
Colin Crossca860ac2016-01-04 14:34:37 -08001111type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001112 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001113 moduleContextImpl
1114}
1115
1116type moduleContextImpl struct {
1117 mod *Module
1118 ctx BaseModuleContext
1119}
1120
Colin Crossb98c8b02016-07-29 13:44:28 -07001121func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001122 return ctx.mod.toolchain(ctx.ctx)
1123}
1124
1125func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001126 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001127}
1128
1129func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001130 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001131}
1132
Jiyong Park1d1119f2019-07-29 21:27:18 +09001133func (ctx *moduleContextImpl) header() bool {
1134 return ctx.mod.header()
1135}
1136
Inseob Kim7f283f42020-06-01 21:53:49 +09001137func (ctx *moduleContextImpl) binary() bool {
1138 return ctx.mod.binary()
1139}
1140
Inseob Kim1042d292020-06-01 23:23:05 +09001141func (ctx *moduleContextImpl) object() bool {
1142 return ctx.mod.object()
1143}
1144
Jooyung Hanccce2f22020-03-07 03:45:53 +09001145func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001146 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001147}
1148
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001149func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001150 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001151}
1152
1153func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001154 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001155 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001156 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001157 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001158 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001159 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001160 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001161 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001162 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001163 }
1164 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001165}
1166
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001167func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001168 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001169}
Justin Yun8effde42017-06-23 19:24:43 +09001170
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001171func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001172 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001173}
1174
Inseob Kim9516ee92019-05-09 10:56:13 +09001175func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1176 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001177}
1178
Inseob Kim9516ee92019-05-09 10:56:13 +09001179func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1180 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001181}
1182
Inseob Kim9516ee92019-05-09 10:56:13 +09001183func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1184 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001185}
1186
Logan Chienf3511742017-10-31 18:04:35 +08001187func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001188 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001189}
1190
Yi Kong7e53c572018-02-14 18:16:12 +08001191func (ctx *moduleContextImpl) isPgoCompile() bool {
1192 return ctx.mod.isPgoCompile()
1193}
1194
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001195func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1196 return ctx.mod.isNDKStubLibrary()
1197}
1198
Justin Yun8effde42017-06-23 19:24:43 +09001199func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001200 return ctx.mod.isVndkSp()
1201}
1202
1203func (ctx *moduleContextImpl) isVndkExt() bool {
1204 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001205}
1206
Vic Yangefd249e2018-11-12 20:19:56 -08001207func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001208 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001209}
1210
Logan Chien2f2b8902018-07-10 15:01:19 +08001211// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001212func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001213 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1214 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001215 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001216
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001217 // Coverage builds have extra symbols.
1218 if ctx.mod.isCoverageVariant() {
1219 return false
1220 }
1221
Doug Hornc32c6b02019-01-17 14:44:05 -08001222 if ctx.ctx.Fuchsia() {
1223 return false
1224 }
1225
Logan Chien2f2b8902018-07-10 15:01:19 +08001226 if sanitize := ctx.mod.sanitize; sanitize != nil {
1227 if !sanitize.isVariantOnProductionDevice() {
1228 return false
1229 }
1230 }
1231 if !ctx.ctx.Device() {
1232 // Host modules do not need ABI dumps.
1233 return false
1234 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001235 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001236 // Stubs do not need ABI dumps.
1237 return false
1238 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001239 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001240}
1241
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001242func (ctx *moduleContextImpl) selectedStl() string {
1243 if stl := ctx.mod.stl; stl != nil {
1244 return stl.Properties.SelectedStl
1245 }
1246 return ""
1247}
1248
Ivan Lozanobd721262018-11-27 14:33:03 -08001249func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1250 return ctx.mod.linker.useClangLld(actx)
1251}
1252
Colin Crossce75d2c2016-10-06 16:12:58 -07001253func (ctx *moduleContextImpl) baseModuleName() string {
1254 return ctx.mod.ModuleBase.BaseModuleName()
1255}
1256
Logan Chienf3511742017-10-31 18:04:35 +08001257func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1258 return ctx.mod.getVndkExtendsModuleName()
1259}
1260
Logan Chiene274fc92019-12-03 11:18:32 -08001261func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Cross56a83212020-09-15 18:30:11 -07001262 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001263}
1264
Colin Crosse07f2312020-08-13 11:24:56 -07001265func (ctx *moduleContextImpl) apexVariationName() string {
Colin Cross56a83212020-09-15 18:30:11 -07001266 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001267}
1268
Dan Albertc8060532020-07-22 22:32:17 -07001269func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001270 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001271}
1272
Jiyong Parkb0788572018-12-20 22:10:17 +09001273func (ctx *moduleContextImpl) hasStubsVariants() bool {
1274 return ctx.mod.HasStubsVariants()
1275}
1276
1277func (ctx *moduleContextImpl) isStubs() bool {
1278 return ctx.mod.IsStubs()
1279}
1280
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001281func (ctx *moduleContextImpl) bootstrap() bool {
1282 return ctx.mod.bootstrap()
1283}
1284
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001285func (ctx *moduleContextImpl) nativeCoverage() bool {
1286 return ctx.mod.nativeCoverage()
1287}
1288
Colin Cross56a83212020-09-15 18:30:11 -07001289func (ctx *moduleContextImpl) directlyInAnyApex() bool {
1290 return ctx.mod.DirectlyInAnyApex()
1291}
1292
Colin Cross635c3b02016-05-18 15:37:25 -07001293func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001294 return &Module{
1295 hod: hod,
1296 multilib: multilib,
1297 }
1298}
1299
Colin Cross635c3b02016-05-18 15:37:25 -07001300func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001301 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001302 module.features = []feature{
1303 &tidyFeature{},
1304 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001305 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001306 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001307 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001308 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001309 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001310 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001311 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001312 return module
1313}
1314
Colin Crossce75d2c2016-10-06 16:12:58 -07001315func (c *Module) Prebuilt() *android.Prebuilt {
1316 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1317 return p.prebuilt()
1318 }
1319 return nil
1320}
1321
1322func (c *Module) Name() string {
1323 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001324 if p, ok := c.linker.(interface {
1325 Name(string) string
1326 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001327 name = p.Name(name)
1328 }
1329 return name
1330}
1331
Alex Light3d673592019-01-18 14:37:31 -08001332func (c *Module) Symlinks() []string {
1333 if p, ok := c.installer.(interface {
1334 symlinkList() []string
1335 }); ok {
1336 return p.symlinkList()
1337 }
1338 return nil
1339}
1340
Roland Levillainf89cd092019-07-29 16:22:59 +01001341func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1342 test, ok := c.linker.(testPerSrc)
1343 return ok && test.isAllTestsVariation()
1344}
1345
Chris Parsons216e10a2020-07-09 17:12:52 -04001346func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001347 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001348 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001349 }); ok {
1350 return p.dataPaths()
1351 }
1352 return nil
1353}
1354
Justin Yun5f7f7e82019-11-18 19:52:14 +09001355func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1356 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1357 // "current", it will append the VNDK version to the name suffix.
1358 var vndkVersion string
1359 var nameSuffix string
1360 if c.inProduct() {
1361 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1362 nameSuffix = productSuffix
1363 } else {
1364 vndkVersion = ctx.DeviceConfig().VndkVersion()
1365 nameSuffix = vendorSuffix
1366 }
1367 if vndkVersion == "current" {
1368 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1369 }
1370 if c.Properties.VndkVersion != vndkVersion {
1371 // add version suffix only if the module is using different vndk version than the
1372 // version in product or vendor partition.
1373 nameSuffix += "." + c.Properties.VndkVersion
1374 }
1375 return nameSuffix
1376}
1377
Colin Cross635c3b02016-05-18 15:37:25 -07001378func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001379 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001380 //
1381 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1382 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1383 // module and return early, as this module does not produce an output file per se.
1384 if c.IsTestPerSrcAllTestsVariation() {
1385 c.outputFile = android.OptionalPath{}
1386 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001387 }
1388
Colin Cross56a83212020-09-15 18:30:11 -07001389 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1390 if !apexInfo.IsForPlatform() {
1391 c.hideApexVariantFromMake = true
1392 }
1393
Jooyung Han38002912019-05-16 04:01:54 +09001394 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001395
Inseob Kim64c43952019-08-26 16:52:35 +09001396 c.Properties.SubName = ""
1397
1398 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1399 c.Properties.SubName += nativeBridgeSuffix
1400 }
1401
Justin Yun5f7f7e82019-11-18 19:52:14 +09001402 _, llndk := c.linker.(*llndkStubDecorator)
1403 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1404 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1405 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1406 // added for product variant only when we have vendor and product variants with core
1407 // variant. The suffix is not added for vendor-only or product-only module.
1408 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1409 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001410 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1411 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1412 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001413 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1414 c.Properties.SubName += ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001415 } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
1416 c.Properties.SubName += vendorRamdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001417 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001418 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001419 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001420 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001421 if c.SplitPerApiLevel() {
1422 c.Properties.SubName += "." + c.SdkVersion()
1423 }
Inseob Kim64c43952019-08-26 16:52:35 +09001424 }
1425
Colin Crossca860ac2016-01-04 14:34:37 -08001426 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001427 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001428 moduleContextImpl: moduleContextImpl{
1429 mod: c,
1430 },
1431 }
1432 ctx.ctx = ctx
1433
Colin Crossf18e1102017-11-16 14:33:08 -08001434 deps := c.depsToPaths(ctx)
1435 if ctx.Failed() {
1436 return
1437 }
1438
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001439 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1440 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1441 }
1442
Colin Crossca860ac2016-01-04 14:34:37 -08001443 flags := Flags{
1444 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001445 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001446 }
Colin Crossca860ac2016-01-04 14:34:37 -08001447 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001448 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001449 }
1450 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001451 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001452 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001453 if c.stl != nil {
1454 flags = c.stl.flags(ctx, flags)
1455 }
Colin Cross16b23492016-01-06 14:41:07 -08001456 if c.sanitize != nil {
1457 flags = c.sanitize.flags(ctx, flags)
1458 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001459 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001460 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001461 }
Stephen Craneba090d12017-05-09 15:44:35 -07001462 if c.lto != nil {
1463 flags = c.lto.flags(ctx, flags)
1464 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001465 if c.pgo != nil {
1466 flags = c.pgo.flags(ctx, flags)
1467 }
Colin Crossca860ac2016-01-04 14:34:37 -08001468 for _, feature := range c.features {
1469 flags = feature.flags(ctx, flags)
1470 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001471 if ctx.Failed() {
1472 return
1473 }
1474
Colin Cross4af21ed2019-11-04 09:37:55 -08001475 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1476 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1477 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001478
Colin Cross4af21ed2019-11-04 09:37:55 -08001479 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001480
1481 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001482 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001483 }
1484 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001485 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001486 }
1487
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001488 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001489 // We need access to all the flags seen by a source file.
1490 if c.sabi != nil {
1491 flags = c.sabi.flags(ctx, flags)
1492 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001493
Colin Cross4af21ed2019-11-04 09:37:55 -08001494 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001495
Colin Crossca860ac2016-01-04 14:34:37 -08001496 // Optimization to reduce size of build.ninja
1497 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001498 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1499 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1500 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1501 flags.Local.CFlags = []string{"$cflags"}
1502 flags.Local.CppFlags = []string{"$cppflags"}
1503 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001504
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001505 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001506 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001507 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001508 if ctx.Failed() {
1509 return
1510 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001511 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001512 }
1513
Colin Crossca860ac2016-01-04 14:34:37 -08001514 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001515 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001516 if ctx.Failed() {
1517 return
1518 }
Colin Cross635c3b02016-05-18 15:37:25 -07001519 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001520
1521 // If a lib is directly included in any of the APEXes, unhide the stubs
1522 // variant having the latest version gets visible to make. In addition,
1523 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1524 // force anything in the make world to link against the stubs library.
1525 // (unless it is explicitly referenced via .bootstrap suffix or the
1526 // module is marked with 'bootstrap: true').
Colin Cross56a83212020-09-15 18:30:11 -07001527 if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001528 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001529 c.IsStubs() && !c.InVendorRamdisk() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001530 c.Properties.HideFromMake = false // unhide
1531 // Note: this is still non-installable
1532 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001533
1534 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1535 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
Colin Cross56a83212020-09-15 18:30:11 -07001536 if isSnapshotAware(ctx, c, apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001537 i.collectHeadersForSnapshot(ctx)
1538 }
1539 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001540 }
Colin Cross5049f022015-03-18 13:28:46 -07001541
Colin Cross56a83212020-09-15 18:30:11 -07001542 if c.installable(apexInfo) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001543 c.installer.install(ctx, c.outputFile.Path())
1544 if ctx.Failed() {
1545 return
Colin Crossca860ac2016-01-04 14:34:37 -08001546 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001547 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1548 // If the module has been specifically configure to not be installed then
1549 // skip the installation as otherwise it will break when running inside make
1550 // as the output path to install will not be specified. Not all uninstallable
1551 // modules can skip installation as some are needed for resolving make side
1552 // dependencies.
1553 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001554 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001555}
1556
Colin Cross0ea8ba82019-06-06 14:33:29 -07001557func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001558 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001559 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001560 }
Colin Crossca860ac2016-01-04 14:34:37 -08001561 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001562}
1563
Colin Crossca860ac2016-01-04 14:34:37 -08001564func (c *Module) begin(ctx BaseModuleContext) {
1565 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001566 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001567 }
Colin Crossca860ac2016-01-04 14:34:37 -08001568 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001569 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001570 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001571 if c.stl != nil {
1572 c.stl.begin(ctx)
1573 }
Colin Cross16b23492016-01-06 14:41:07 -08001574 if c.sanitize != nil {
1575 c.sanitize.begin(ctx)
1576 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001577 if c.coverage != nil {
1578 c.coverage.begin(ctx)
1579 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001580 if c.sabi != nil {
1581 c.sabi.begin(ctx)
1582 }
Justin Yun8effde42017-06-23 19:24:43 +09001583 if c.vndkdep != nil {
1584 c.vndkdep.begin(ctx)
1585 }
Stephen Craneba090d12017-05-09 15:44:35 -07001586 if c.lto != nil {
1587 c.lto.begin(ctx)
1588 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001589 if c.pgo != nil {
1590 c.pgo.begin(ctx)
1591 }
Colin Crossca860ac2016-01-04 14:34:37 -08001592 for _, feature := range c.features {
1593 feature.begin(ctx)
1594 }
Dan Albert92fe7402020-07-15 13:33:30 -07001595 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001596 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001597 if err != nil {
1598 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001599 c.Properties.Sdk_version = nil
1600 } else {
1601 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001602 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001603 }
Colin Crossca860ac2016-01-04 14:34:37 -08001604}
1605
Colin Cross37047f12016-12-13 17:06:13 -08001606func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001607 deps := Deps{}
1608
1609 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001610 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001611 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001612 // Add the PGO dependency (the clang_rt.profile runtime library), which
1613 // sometimes depends on symbols from libgcc, before libgcc gets added
1614 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001615 if c.pgo != nil {
1616 deps = c.pgo.deps(ctx, deps)
1617 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001618 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001619 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001620 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001621 if c.stl != nil {
1622 deps = c.stl.deps(ctx, deps)
1623 }
Colin Cross16b23492016-01-06 14:41:07 -08001624 if c.sanitize != nil {
1625 deps = c.sanitize.deps(ctx, deps)
1626 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001627 if c.coverage != nil {
1628 deps = c.coverage.deps(ctx, deps)
1629 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001630 if c.sabi != nil {
1631 deps = c.sabi.deps(ctx, deps)
1632 }
Justin Yun8effde42017-06-23 19:24:43 +09001633 if c.vndkdep != nil {
1634 deps = c.vndkdep.deps(ctx, deps)
1635 }
Stephen Craneba090d12017-05-09 15:44:35 -07001636 if c.lto != nil {
1637 deps = c.lto.deps(ctx, deps)
1638 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001639 for _, feature := range c.features {
1640 deps = feature.deps(ctx, deps)
1641 }
1642
Colin Crossb6715442017-10-24 11:13:31 -07001643 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1644 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1645 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1646 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1647 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1648 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001649 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001650
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001651 for _, lib := range deps.ReexportSharedLibHeaders {
1652 if !inList(lib, deps.SharedLibs) {
1653 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1654 }
1655 }
1656
1657 for _, lib := range deps.ReexportStaticLibHeaders {
1658 if !inList(lib, deps.StaticLibs) {
1659 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1660 }
1661 }
1662
Colin Cross5950f382016-12-13 12:50:57 -08001663 for _, lib := range deps.ReexportHeaderLibHeaders {
1664 if !inList(lib, deps.HeaderLibs) {
1665 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1666 }
1667 }
1668
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001669 for _, gen := range deps.ReexportGeneratedHeaders {
1670 if !inList(gen, deps.GeneratedHeaders) {
1671 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1672 }
1673 }
1674
Colin Crossc99deeb2016-04-11 15:06:20 -07001675 return deps
1676}
1677
Dan Albert7e9d2952016-08-04 13:02:36 -07001678func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001679 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001680 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001681 moduleContextImpl: moduleContextImpl{
1682 mod: c,
1683 },
1684 }
1685 ctx.ctx = ctx
1686
Colin Crossca860ac2016-01-04 14:34:37 -08001687 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001688}
1689
Jiyong Park7ed9de32018-10-15 22:25:07 +09001690// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001691func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001692 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1693 version := name[sharp+1:]
1694 libname := name[:sharp]
1695 return libname, version
1696 }
1697 return name, ""
1698}
1699
Dan Albert92fe7402020-07-15 13:33:30 -07001700func GetCrtVariations(ctx android.BottomUpMutatorContext,
1701 m LinkableInterface) []blueprint.Variation {
1702 if ctx.Os() != android.Android {
1703 return nil
1704 }
1705 if m.UseSdk() {
1706 return []blueprint.Variation{
1707 {Mutator: "sdk", Variation: "sdk"},
Colin Crossbbc941b2020-09-30 12:27:01 -07001708 {Mutator: "version", Variation: m.SdkVersion()},
Dan Albert92fe7402020-07-15 13:33:30 -07001709 }
1710 }
1711 return []blueprint.Variation{
1712 {Mutator: "sdk", Variation: ""},
1713 }
1714}
1715
Colin Crosse7257d22020-09-24 09:56:18 -07001716func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1717 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1718
1719 variations = append([]blueprint.Variation(nil), variations...)
1720
Colin Cross3146c5c2020-09-30 15:34:40 -07001721 if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001722 // Version is explicitly specified. i.e. libFoo#30
1723 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1724 depTag.explicitlyVersioned = true
1725 }
Colin Crosse7257d22020-09-24 09:56:18 -07001726
Colin Cross0de8a1e2020-09-18 14:15:30 -07001727 if far {
1728 ctx.AddFarVariationDependencies(variations, depTag, name)
1729 } else {
1730 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07001731 }
1732}
1733
Colin Cross1e676be2016-10-12 14:38:15 -07001734func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001735 if !c.Enabled() {
1736 return
1737 }
1738
Colin Cross37047f12016-12-13 17:06:13 -08001739 ctx := &depsContext{
1740 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001741 moduleContextImpl: moduleContextImpl{
1742 mod: c,
1743 },
1744 }
1745 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001746
Colin Crossc99deeb2016-04-11 15:06:20 -07001747 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001748
Yo Chiang219968c2020-09-22 18:45:04 +08001749 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1750
Dan Albert914449f2016-06-17 16:45:24 -07001751 variantNdkLibs := []string{}
1752 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001753 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001754 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001755 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001756 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001757 // 1. Name of an NDK library that refers to a prebuilt module.
1758 // For each of these, it adds the name of the prebuilt module (which will be in
1759 // prebuilts/ndk) to the list of nonvariant libs.
1760 // 2. Name of an NDK library that refers to an ndk_library module.
1761 // For each of these, it adds the name of the ndk_library module to the list of
1762 // variant libs.
1763 // 3. Anything else (so anything that isn't an NDK library).
1764 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001765 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001766 // The caller can then know to add the variantLibs dependencies differently from the
1767 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001768
Inseob Kim9516ee92019-05-09 10:56:13 +09001769 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001770 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1771
1772 rewriteVendorLibs := func(lib string) string {
1773 if isLlndkLibrary(lib, ctx.Config()) {
1774 return lib + llndkLibrarySuffix
1775 }
1776
1777 // only modules with BOARD_VNDK_VERSION uses snapshot.
1778 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1779 return lib
1780 }
1781
1782 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1783 return snapshot
1784 }
1785
1786 return lib
1787 }
1788
1789 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001790 variantLibs = []string{}
1791 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001792 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001793 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001794 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001795 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1796 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001797 } else if ctx.useVndk() {
1798 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001799 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001800 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001801 if actx.OtherModuleExists(vendorPublicLib) {
1802 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1803 } else {
1804 // This can happen if vendor_public_library module is defined in a
1805 // namespace that isn't visible to the current module. In that case,
1806 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001807 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001808 }
Dan Albert914449f2016-06-17 16:45:24 -07001809 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001810 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001811 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001812 }
1813 }
Dan Albert914449f2016-06-17 16:45:24 -07001814 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001815 }
1816
Inseob Kimeec88e12020-01-22 11:11:29 +09001817 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1818 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1819 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1820 if ctx.useVndk() {
1821 for idx, lib := range deps.RuntimeLibs {
1822 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1823 }
1824 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001825 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001826
Jiyong Park7e636d02019-01-28 16:16:54 +09001827 buildStubs := false
Colin Crossc88c2722020-09-28 17:32:47 -07001828 if versioned, ok := c.linker.(versionedInterface); ok {
1829 if versioned.buildStubs() {
1830 buildStubs = true
Colin Crossd48fe732020-09-23 20:37:24 -07001831 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001832 }
1833
Inseob Kimeec88e12020-01-22 11:11:29 +09001834 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1835 // only modules with BOARD_VNDK_VERSION uses snapshot.
1836 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1837 return lib
1838 }
1839
1840 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1841 return snapshot
1842 }
1843
1844 return lib
1845 }
1846
1847 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001848 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001849 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001850 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001851 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001852 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001853
1854 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1855
Jiyong Park7e636d02019-01-28 16:16:54 +09001856 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001857 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001858 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001859 } else {
1860 actx.AddVariationDependencies(nil, depTag, lib)
1861 }
1862 }
1863
1864 if buildStubs {
1865 // Stubs lib does not have dependency to other static/shared libraries.
1866 // Don't proceed.
1867 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001868 }
Colin Cross5950f382016-12-13 12:50:57 -08001869
Inseob Kimc0907f12019-02-08 21:00:45 +09001870 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001871 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001872
Jiyong Park5d1598f2019-02-25 22:14:17 +09001873 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001874 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001875 if impl, ok := syspropImplLibraries[lib]; ok {
1876 lib = impl
1877 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001878
1879 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1880
Jiyong Park5d1598f2019-02-25 22:14:17 +09001881 actx.AddVariationDependencies([]blueprint.Variation{
1882 {Mutator: "link", Variation: "static"},
1883 }, depTag, lib)
1884 }
1885
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001886 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001887 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001888 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001889 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001890 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001891
1892 if impl, ok := syspropImplLibraries[lib]; ok {
1893 lib = impl
1894 }
1895
Inseob Kimeec88e12020-01-22 11:11:29 +09001896 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1897
Dan Willemsen59339a22018-07-22 21:18:45 -07001898 actx.AddVariationDependencies([]blueprint.Variation{
1899 {Mutator: "link", Variation: "static"},
1900 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001901 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001902
Jooyung Han75568392020-03-20 04:29:24 +09001903 // staticUnwinderDep is treated as staticDep for Q apexes
1904 // so that native libraries/binaries are linked with static unwinder
1905 // because Q libc doesn't have unwinder APIs
1906 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001907 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001908 actx.AddVariationDependencies([]blueprint.Variation{
1909 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001910 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001911 }
1912
Inseob Kimeec88e12020-01-22 11:11:29 +09001913 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001914 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001915 actx.AddVariationDependencies([]blueprint.Variation{
1916 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001917 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001918 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001919
Jiyong Park7ed9de32018-10-15 22:25:07 +09001920 // shared lib names without the #version suffix
1921 var sharedLibNames []string
1922
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001923 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001924 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001925 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001926 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001927 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001928
1929 if impl, ok := syspropImplLibraries[lib]; ok {
1930 lib = impl
1931 }
1932
Jiyong Park73c54ee2019-10-22 20:31:18 +09001933 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001934 sharedLibNames = append(sharedLibNames, name)
1935
Colin Crosse7257d22020-09-24 09:56:18 -07001936 variations := []blueprint.Variation{
1937 {Mutator: "link", Variation: "shared"},
1938 }
1939 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001940 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001941
Jiyong Park7ed9de32018-10-15 22:25:07 +09001942 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001943 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001944 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1945 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1946 // linking against both the stubs lib and the non-stubs lib at the same time.
1947 continue
1948 }
Colin Cross6e511a92020-07-27 21:26:48 -07001949 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07001950 variations := []blueprint.Variation{
1951 {Mutator: "link", Variation: "shared"},
1952 }
1953 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001954 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001955
Dan Willemsen59339a22018-07-22 21:18:45 -07001956 actx.AddVariationDependencies([]blueprint.Variation{
1957 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04001958 }, dataLibDepTag, deps.DataLibs...)
1959
1960 actx.AddVariationDependencies([]blueprint.Variation{
1961 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07001962 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001963
Colin Cross68861832016-07-08 10:41:41 -07001964 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001965
1966 for _, gen := range deps.GeneratedHeaders {
1967 depTag := genHeaderDepTag
1968 if inList(gen, deps.ReexportGeneratedHeaders) {
1969 depTag = genHeaderExportDepTag
1970 }
1971 actx.AddDependency(c, depTag, gen)
1972 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001973
Inseob Kim1042d292020-06-01 23:23:05 +09001974 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
1975
Dan Albert92fe7402020-07-15 13:33:30 -07001976 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07001977 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001978 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001979 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
1980 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08001981 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001982 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001983 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
1984 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07001985 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001986 if deps.LinkerFlagsFile != "" {
1987 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1988 }
1989 if deps.DynamicLinker != "" {
1990 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001991 }
Dan Albert914449f2016-06-17 16:45:24 -07001992
1993 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07001994
1995 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07001996 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07001997 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07001998 {Mutator: "link", Variation: "shared"},
1999 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002000
2001 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002002 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002003 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002004 {Mutator: "link", Variation: "shared"},
2005 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002006
2007 if vndkdep := c.vndkdep; vndkdep != nil {
2008 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002009 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002010 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002011 {Mutator: "link", Variation: "shared"},
2012 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002013 }
2014 }
Colin Cross6362e272015-10-29 15:25:03 -07002015}
Colin Cross21b9a242015-03-24 14:15:58 -07002016
Colin Crosse40b4ea2018-10-02 22:25:58 -07002017func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002018 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2019 c.beginMutator(ctx)
2020 }
2021}
2022
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002023// Whether a module can link to another module, taking into
2024// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002025func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002026 tag blueprint.DependencyTag) {
2027
2028 switch t := tag.(type) {
2029 case dependencyTag:
2030 if t != vndkExtDepTag {
2031 return
2032 }
2033 case libraryDependencyTag:
2034 default:
2035 return
2036 }
2037
Ivan Lozano52767be2019-10-18 14:49:46 -07002038 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002039 // Host code is not restricted
2040 return
2041 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002042
2043 // VNDK is cc.Module supported only for now.
2044 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002045 // Though vendor code is limited by the vendor mutator,
2046 // each vendor-available module needs to check
2047 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002048 if ccTo, ok := to.(*Module); ok {
2049 if ccFrom.vndkdep != nil {
2050 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2051 }
2052 } else {
2053 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002054 }
2055 return
2056 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002057 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002058 // Platform code can link to anything
2059 return
2060 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002061 if from.InRamdisk() {
2062 // Ramdisk code is not NDK
2063 return
2064 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002065 if from.InVendorRamdisk() {
2066 // Vendor ramdisk code is not NDK
2067 return
2068 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002069 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002070 // Recovery code is not NDK
2071 return
2072 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002073 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002074 // These are always allowed
2075 return
2076 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002077 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002078 // These are allowed, but they don't set sdk_version
2079 return
2080 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002081 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002082 // These aren't real libraries, but are the stub shared libraries that are included in
2083 // the NDK.
2084 return
2085 }
Logan Chien834b9a62019-01-14 15:39:03 +08002086
Ivan Lozano52767be2019-10-18 14:49:46 -07002087 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002088 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2089 // to link to libc++ (non-NDK and without sdk_version).
2090 return
2091 }
2092
Ivan Lozano52767be2019-10-18 14:49:46 -07002093 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002094 // NDK code linking to platform code is never okay.
2095 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002096 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002097 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002098 }
2099
2100 // At this point we know we have two NDK libraries, but we need to
2101 // check that we're not linking against anything built against a higher
2102 // API level, as it is only valid to link against older or equivalent
2103 // APIs.
2104
Inseob Kim01a28722018-04-11 09:48:45 +09002105 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002106 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002107 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002108 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002109 // Current can't be linked against by anything else.
2110 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002111 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002112 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002113 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002114 if err != nil {
2115 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002116 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002117 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002118 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002119 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002120 if err != nil {
2121 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002122 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002123 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002124 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002125
Inseob Kim01a28722018-04-11 09:48:45 +09002126 if toApi > fromApi {
2127 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002128 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002129 }
2130 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002131 }
Dan Albert202fe492017-12-15 13:56:59 -08002132
2133 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002134 fromStl := from.SelectedStl()
2135 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002136 if fromStl == "" || toStl == "" {
2137 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002138 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002139 // We can be permissive with the system "STL" since it is only the C++
2140 // ABI layer, but in the future we should make sure that everyone is
2141 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002142 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002143 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002144 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2145 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002146 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002147}
2148
Jooyung Han479ca172020-10-19 18:51:07 +09002149func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2150 if c, ok := ctx.Module().(*Module); ok {
2151 ctx.VisitDirectDeps(func(dep android.Module) {
2152 depTag := ctx.OtherModuleDependencyTag(dep)
2153 ccDep, ok := dep.(LinkableInterface)
2154 if ok {
2155 checkLinkType(ctx, c, ccDep, depTag)
2156 }
2157 })
2158 }
2159}
2160
Jiyong Park5fb8c102018-04-09 12:03:06 +09002161// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002162// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2163// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002164// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002165func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2166 check := func(child, parent android.Module) bool {
2167 to, ok := child.(*Module)
2168 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002169 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002170 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002171
Jooyung Hana70f0672019-01-18 15:20:43 +09002172 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2173 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002174 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002175
Jooyung Han479ca172020-10-19 18:51:07 +09002176 // Even if target lib has no vendor variant, keep checking dependency graph
2177 // in case it depends on vendor_available but not double_loadable transtively.
Ivan Lozano52767be2019-10-18 14:49:46 -07002178 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002179 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002180 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002181
Jooyung Han0302a842019-10-30 18:43:49 +09002182 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002183 return false
2184 }
2185
2186 var stringPath []string
2187 for _, m := range ctx.GetWalkPath() {
2188 stringPath = append(stringPath, m.Name())
2189 }
2190 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2191 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2192 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2193 return false
2194 }
2195 if module, ok := ctx.Module().(*Module); ok {
2196 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002197 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002198 ctx.WalkDeps(check)
2199 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002200 }
2201 }
2202}
2203
Colin Cross0de8a1e2020-09-18 14:15:30 -07002204// Returns the highest version which is <= maxSdkVersion.
2205// For example, with maxSdkVersion is 10 and versionList is [9,11]
2206// it returns 9 as string. The list of stubs must be in order from
2207// oldest to newest.
2208func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedLibraryStubsInfo,
2209 maxSdkVersion android.ApiLevel) (SharedLibraryStubsInfo, error) {
2210
2211 for i := range stubsInfo {
2212 stubInfo := stubsInfo[len(stubsInfo)-i-1]
2213 var ver android.ApiLevel
2214 if stubInfo.Version == "" {
2215 ver = android.FutureApiLevel
2216 } else {
2217 var err error
2218 ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
2219 if err != nil {
2220 return SharedLibraryStubsInfo{}, err
2221 }
2222 }
2223 if ver.LessThanOrEqualTo(maxSdkVersion) {
2224 return stubInfo, nil
2225 }
2226 }
2227 var versionList []string
2228 for _, stubInfo := range stubsInfo {
2229 versionList = append(versionList, stubInfo.Version)
2230 }
2231 return SharedLibraryStubsInfo{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
2232}
2233
Colin Crossc99deeb2016-04-11 15:06:20 -07002234// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002235func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002236 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002237
Colin Cross0de8a1e2020-09-18 14:15:30 -07002238 var directStaticDeps []StaticLibraryInfo
2239 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07002240
Colin Cross0de8a1e2020-09-18 14:15:30 -07002241 reexportExporter := func(exporter FlagExporterInfo) {
2242 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
2243 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
2244 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
2245 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
2246 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09002247 }
2248
Jooyung Hande34d232020-07-23 13:04:15 +09002249 // For the dependency from platform to apex, use the latest stubs
2250 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002251 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2252 if !apexInfo.IsForPlatform() {
2253 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002254 }
2255
2256 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2257 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2258 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2259 // (b/144430859)
2260 c.apexSdkVersion = android.FutureApiLevel
2261 }
2262
Colin Crossd11fcda2017-10-23 17:59:01 -07002263 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002264 depName := ctx.OtherModuleName(dep)
2265 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002266
Ivan Lozano52767be2019-10-18 14:49:46 -07002267 ccDep, ok := dep.(LinkableInterface)
2268 if !ok {
2269
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002270 // handling for a few module types that aren't cc Module but that are also supported
2271 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002272 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002273 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002274 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2275 genRule.GeneratedSourceFiles()...)
2276 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002277 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002278 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002279 // Support exported headers from a generated_sources dependency
2280 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002281 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002282 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002283 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002284 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002285 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002286 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002287 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002288 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002289 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2290 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002291 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002292 // 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 +09002293 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002294
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002295 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002296 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002297 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002298 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002299 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002300 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002301 files := genRule.GeneratedSourceFiles()
2302 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002303 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002304 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002305 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 -07002306 }
2307 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002308 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002309 }
Colin Crossca860ac2016-01-04 14:34:37 -08002310 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002311 return
2312 }
2313
Colin Crossfe17f6f2019-03-28 19:30:56 -07002314 if depTag == android.ProtoPluginDepTag {
2315 return
2316 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002317 if depTag == llndkImplDep {
2318 return
2319 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002320
Colin Crossd11fcda2017-10-23 17:59:01 -07002321 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002322 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2323 return
2324 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002325 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002326 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2327 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002328 return
2329 }
2330
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002331 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002332 // reusing objects only make sense for cc.Modules.
Colin Cross0de8a1e2020-09-18 14:15:30 -07002333 staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2334 objs := staticAnalogue.ReuseObjects
2335 depPaths.Objs = depPaths.Objs.Append(objs)
2336 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
2337 reexportExporter(depExporterInfo)
2338 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09002339 }
2340
Colin Cross6e511a92020-07-27 21:26:48 -07002341 linkFile := ccDep.OutputFile()
2342
2343 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2344 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002345 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002346 return
2347 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002348
Colin Cross0de8a1e2020-09-18 14:15:30 -07002349 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
Colin Crossc99deeb2016-04-11 15:06:20 -07002350
Colin Cross6e511a92020-07-27 21:26:48 -07002351 var ptr *android.Paths
2352 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002353
Colin Cross6e511a92020-07-27 21:26:48 -07002354 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002355
Colin Cross6e511a92020-07-27 21:26:48 -07002356 switch {
2357 case libDepTag.header():
2358 // nothing
2359 case libDepTag.shared():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002360 if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
2361 if !ctx.Config().AllowMissingDependencies() {
2362 ctx.ModuleErrorf("module %q is not a shared library", depName)
2363 } else {
2364 ctx.AddMissingDependencies([]string{depName})
2365 }
2366 return
2367 }
2368 sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
2369 sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryImplementationStubsInfoProvider).(SharedLibraryImplementationStubsInfo)
2370
2371 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedLibraryStubsInfos) > 0 {
2372 useStubs := false
2373 if m, ok := ccDep.(*Module); ok && m.IsStubs() && c.UseVndk() { // LLNDK
2374 if !apexInfo.IsForPlatform() {
2375 // For platform libraries, use current version of LLNDK
2376 // If this is for use_vendor apex we will apply the same rules
2377 // of apex sdk enforcement below to choose right version.
2378 useStubs = true
2379 }
2380 } else if apexInfo.IsForPlatform() {
2381 // If not building for APEX, use stubs only when it is from
2382 // an APEX (and not from platform)
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002383 // However, for host, ramdisk, vendor_ramdisk, recovery or bootstrap modules,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002384 // always link to non-stub variant
2385 useStubs = dep.(android.ApexModule).AnyVariantDirectlyInAnyApex() && !c.bootstrap()
2386 // Another exception: if this module is bundled with an APEX, then
2387 // it is linked with the non-stub variant of a module in the APEX
2388 // as if this is part of the APEX.
2389 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2390 for _, apexContents := range testFor.ApexContents {
2391 if apexContents.DirectlyInApex(depName) {
2392 useStubs = false
2393 break
2394 }
2395 }
2396 } else {
2397 // If building for APEX, use stubs when the parent is in any APEX that
2398 // the child is not in.
2399 useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
2400 }
2401
2402 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2403 if useStubs {
2404 sharedLibraryStubsInfo, err :=
2405 c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedLibraryStubsInfos, c.apexSdkVersion)
2406 if err != nil {
2407 ctx.OtherModuleErrorf(dep, err.Error())
2408 return
2409 }
2410 sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
2411 depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
2412 }
2413 }
2414
2415 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
2416 depFile = sharedLibraryInfo.TableOfContents
2417
Colin Cross6e511a92020-07-27 21:26:48 -07002418 ptr = &depPaths.SharedLibs
2419 switch libDepTag.Order {
2420 case earlyLibraryDependency:
2421 ptr = &depPaths.EarlySharedLibs
2422 depPtr = &depPaths.EarlySharedLibsDeps
2423 case normalLibraryDependency:
2424 ptr = &depPaths.SharedLibs
2425 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07002426 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002427 case lateLibraryDependency:
2428 ptr = &depPaths.LateSharedLibs
2429 depPtr = &depPaths.LateSharedLibsDeps
2430 default:
2431 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002432 }
Colin Cross6e511a92020-07-27 21:26:48 -07002433 case libDepTag.static():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002434 if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
2435 if !ctx.Config().AllowMissingDependencies() {
2436 ctx.ModuleErrorf("module %q is not a static library", depName)
2437 } else {
2438 ctx.AddMissingDependencies([]string{depName})
2439 }
2440 return
2441 }
2442 staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2443 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
Colin Cross6e511a92020-07-27 21:26:48 -07002444 if libDepTag.wholeStatic {
2445 ptr = &depPaths.WholeStaticLibs
Colin Cross0de8a1e2020-09-18 14:15:30 -07002446 if len(staticLibraryInfo.Objects.objFiles) > 0 {
2447 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
Inseob Kimeec88e12020-01-22 11:11:29 +09002448 } else {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002449 // This case normally catches prebuilt static
2450 // libraries, but it can also occur when
2451 // AllowMissingDependencies is on and the
2452 // dependencies has no sources of its own
2453 // but has a whole_static_libs dependency
2454 // on a missing library. We want to depend
2455 // on the .a file so that there is something
2456 // in the dependency tree that contains the
2457 // error rule for the missing transitive
2458 // dependency.
2459 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002460 }
Colin Cross6e511a92020-07-27 21:26:48 -07002461 } else {
2462 switch libDepTag.Order {
2463 case earlyLibraryDependency:
2464 panic(fmt.Errorf("early static libs not suppported"))
2465 case normalLibraryDependency:
2466 // static dependencies will be handled separately so they can be ordered
2467 // using transitive dependencies.
2468 ptr = nil
Colin Cross0de8a1e2020-09-18 14:15:30 -07002469 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002470 case lateLibraryDependency:
2471 ptr = &depPaths.LateStaticLibs
2472 default:
2473 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002474 }
2475 }
2476 }
2477
Colin Cross6e511a92020-07-27 21:26:48 -07002478 if libDepTag.static() && !libDepTag.wholeStatic {
2479 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2480 ctx.ModuleErrorf("module %q not a static library", depName)
2481 return
2482 }
Logan Chien43d34c32017-12-20 01:17:32 +08002483
Colin Cross6e511a92020-07-27 21:26:48 -07002484 // When combining coverage files for shared libraries and executables, coverage files
2485 // in static libraries act as if they were whole static libraries. The same goes for
2486 // source based Abi dump files.
2487 if c, ok := ccDep.(*Module); ok {
2488 staticLib := c.linker.(libraryInterface)
2489 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2490 staticLib.objs().coverageFiles...)
2491 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2492 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002493 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002494 // Handle non-CC modules here
2495 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002496 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002497 }
2498 }
2499
Colin Cross6e511a92020-07-27 21:26:48 -07002500 if ptr != nil {
2501 if !linkFile.Valid() {
2502 if !ctx.Config().AllowMissingDependencies() {
2503 ctx.ModuleErrorf("module %q missing output file", depName)
2504 } else {
2505 ctx.AddMissingDependencies([]string{depName})
2506 }
2507 return
2508 }
2509 *ptr = append(*ptr, linkFile.Path())
2510 }
2511
2512 if depPtr != nil {
2513 dep := depFile
2514 if !dep.Valid() {
2515 dep = linkFile
2516 }
2517 *depPtr = append(*depPtr, dep.Path())
2518 }
2519
Colin Cross0de8a1e2020-09-18 14:15:30 -07002520 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
2521 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
2522 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
2523 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
2524
2525 if libDepTag.reexportFlags {
2526 reexportExporter(depExporterInfo)
2527 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2528 // Re-exported shared library headers must be included as well since they can help us with type information
2529 // about template instantiations (instantiated from their headers).
2530 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2531 // scripts.
2532 c.sabi.Properties.ReexportedIncludes = append(
2533 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
2534 }
2535
Colin Cross6e511a92020-07-27 21:26:48 -07002536 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2537 switch {
2538 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002539 c.Properties.AndroidMkHeaderLibs = append(
2540 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002541 case libDepTag.shared():
2542 if ccDep.CcLibrary() {
Colin Cross56a83212020-09-15 18:30:11 -07002543 if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002544 // Add the dependency to the APEX(es) providing the library so that
2545 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002546 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2547 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002548 c.Properties.ApexesProvidingSharedLibs = append(
2549 c.Properties.ApexesProvidingSharedLibs, an)
2550 }
2551 }
2552 }
2553
2554 // Note: the order of libs in this list is not important because
2555 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002556 c.Properties.AndroidMkSharedLibs = append(
2557 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002558 // Record baseLibName for snapshots.
2559 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2560 case libDepTag.static():
2561 if libDepTag.wholeStatic {
2562 c.Properties.AndroidMkWholeStaticLibs = append(
2563 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2564 } else {
2565 c.Properties.AndroidMkStaticLibs = append(
2566 c.Properties.AndroidMkStaticLibs, makeLibName)
2567 }
2568 }
2569 } else {
2570 switch depTag {
2571 case runtimeDepTag:
2572 c.Properties.AndroidMkRuntimeLibs = append(
2573 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2574 // Record baseLibName for snapshots.
2575 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2576 case objDepTag:
2577 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2578 case CrtBeginDepTag:
2579 depPaths.CrtBegin = linkFile
2580 case CrtEndDepTag:
2581 depPaths.CrtEnd = linkFile
2582 case dynamicLinkerDepTag:
2583 depPaths.DynamicLinker = linkFile
2584 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002585 }
Colin Crossca860ac2016-01-04 14:34:37 -08002586 })
2587
Jeff Gaston294356f2017-09-27 17:05:30 -07002588 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07002589 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
2590 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
2591 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002592
Colin Crossdd84e052017-05-17 13:44:16 -07002593 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002594 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002595 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2596 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002597 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002598 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2599 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002600 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002601 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002602 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002603
2604 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002605 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002606 }
Colin Crossdd84e052017-05-17 13:44:16 -07002607
Colin Crossca860ac2016-01-04 14:34:37 -08002608 return depPaths
2609}
2610
Colin Cross0de8a1e2020-09-18 14:15:30 -07002611// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
2612// to match the topological order of the dependency tree, including any static analogues of
2613// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
2614// of the transitive dependencies.
2615func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
2616 transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
2617 var staticPaths android.Paths
2618 for _, staticDep := range staticDeps {
2619 staticPaths = append(staticPaths, staticDep.StaticLibrary)
2620 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
2621 }
2622 for _, sharedDep := range sharedDeps {
2623 if sharedDep.StaticAnalogue != nil {
2624 transitiveStaticLibsBuilder.Transitive(sharedDep.StaticAnalogue.TransitiveStaticLibrariesForOrdering)
2625 }
2626 }
2627 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
2628
2629 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
2630
2631 // reorder the dependencies based on transitive dependencies
2632 staticPaths = android.FirstUniquePaths(staticPaths)
2633 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
2634
2635 if len(orderedStaticPaths) != len(staticPaths) {
2636 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
2637 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
2638 }
2639
2640 return orderedStaticPaths, transitiveStaticLibs
2641}
2642
Colin Cross6e511a92020-07-27 21:26:48 -07002643// baseLibName trims known prefixes and suffixes
2644func baseLibName(depName string) string {
2645 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2646 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2647 libName = strings.TrimPrefix(libName, "prebuilt_")
2648 return libName
2649}
2650
2651func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2652 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2653 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2654
2655 libName := baseLibName(depName)
2656 isLLndk := isLlndkLibrary(libName, ctx.Config())
2657 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2658 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2659
2660 if c, ok := ccDep.(*Module); ok {
2661 // Use base module name for snapshots when exporting to Makefile.
2662 if c.isSnapshotPrebuilt() {
2663 baseName := c.BaseModuleName()
2664
2665 if c.IsVndk() {
2666 return baseName + ".vendor"
2667 }
2668
2669 if vendorSuffixModules[baseName] {
2670 return baseName + ".vendor"
2671 } else {
2672 return baseName
2673 }
2674 }
2675 }
2676
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002677 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() &&
2678 !c.InRamdisk() && !c.InVendorRamdisk() && !c.InRecovery() {
Colin Cross6e511a92020-07-27 21:26:48 -07002679 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2680 // core module instead.
2681 return libName
2682 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2683 // The vendor module in Make will have been renamed to not conflict with the core
2684 // module, so update the dependency name here accordingly.
2685 return libName + c.getNameSuffixWithVndkVersion(ctx)
2686 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2687 return libName + vendorPublicLibrarySuffix
2688 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2689 return libName + ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002690 } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
2691 return libName + vendorRamdiskSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07002692 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2693 return libName + recoverySuffix
2694 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2695 return libName + nativeBridgeSuffix
2696 } else {
2697 return libName
2698 }
2699}
2700
Colin Crossca860ac2016-01-04 14:34:37 -08002701func (c *Module) InstallInData() bool {
2702 if c.installer == nil {
2703 return false
2704 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002705 return c.installer.inData()
2706}
2707
2708func (c *Module) InstallInSanitizerDir() bool {
2709 if c.installer == nil {
2710 return false
2711 }
2712 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002713 return true
2714 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002715 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002716}
2717
Yifan Hong1b3348d2020-01-21 15:53:22 -08002718func (c *Module) InstallInRamdisk() bool {
2719 return c.InRamdisk()
2720}
2721
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002722func (c *Module) InstallInVendorRamdisk() bool {
2723 return c.InVendorRamdisk()
2724}
2725
Jiyong Parkf9332f12018-02-01 00:54:12 +09002726func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002727 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002728}
2729
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002730func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002731 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002732 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002733 return
2734 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002735 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002736}
2737
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002738func (c *Module) HostToolPath() android.OptionalPath {
2739 if c.installer == nil {
2740 return android.OptionalPath{}
2741 }
2742 return c.installer.hostToolPath()
2743}
2744
Nan Zhangd4e641b2017-07-12 12:55:28 -07002745func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2746 return c.outputFile
2747}
2748
Colin Cross41955e82019-05-29 14:40:35 -07002749func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2750 switch tag {
2751 case "":
2752 if c.outputFile.Valid() {
2753 return android.Paths{c.outputFile.Path()}, nil
2754 }
2755 return android.Paths{}, nil
2756 default:
2757 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002758 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002759}
2760
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002761func (c *Module) static() bool {
2762 if static, ok := c.linker.(interface {
2763 static() bool
2764 }); ok {
2765 return static.static()
2766 }
2767 return false
2768}
2769
Jiyong Park379de2f2018-12-19 02:47:14 +09002770func (c *Module) staticBinary() bool {
2771 if static, ok := c.linker.(interface {
2772 staticBinary() bool
2773 }); ok {
2774 return static.staticBinary()
2775 }
2776 return false
2777}
2778
Jiyong Park1d1119f2019-07-29 21:27:18 +09002779func (c *Module) header() bool {
2780 if h, ok := c.linker.(interface {
2781 header() bool
2782 }); ok {
2783 return h.header()
2784 }
2785 return false
2786}
2787
Inseob Kim7f283f42020-06-01 21:53:49 +09002788func (c *Module) binary() bool {
2789 if b, ok := c.linker.(interface {
2790 binary() bool
2791 }); ok {
2792 return b.binary()
2793 }
2794 return false
2795}
2796
Inseob Kim1042d292020-06-01 23:23:05 +09002797func (c *Module) object() bool {
2798 if o, ok := c.linker.(interface {
2799 object() bool
2800 }); ok {
2801 return o.object()
2802 }
2803 return false
2804}
2805
Jooyung Han38002912019-05-16 04:01:54 +09002806func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002807 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002808 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2809 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002810 return "native:vndk"
2811 }
Jooyung Han38002912019-05-16 04:01:54 +09002812 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002813 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002814 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002815 if Bool(c.VendorProperties.Vendor_available) {
2816 return "native:vndk"
2817 }
2818 return "native:vndk_private"
2819 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002820 if c.inProduct() {
2821 return "native:product"
2822 }
Jooyung Han38002912019-05-16 04:01:54 +09002823 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002824 } else if c.InRamdisk() {
2825 return "native:ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002826 } else if c.InVendorRamdisk() {
2827 return "native:vendor_ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002828 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002829 return "native:recovery"
2830 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2831 return "native:ndk:none:none"
2832 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2833 //family, link := getNdkStlFamilyAndLinkType(c)
2834 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002835 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002836 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002837 } else {
2838 return "native:platform"
2839 }
2840}
2841
Jiyong Park9d452992018-10-03 00:38:19 +09002842// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002843// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002844func (c *Module) IsInstallableToApex() bool {
2845 if shared, ok := c.linker.(interface {
2846 shared() bool
2847 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002848 // Stub libs and prebuilt libs in a versioned SDK are not
2849 // installable to APEX even though they are shared libs.
2850 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002851 } else if _, ok := c.linker.(testPerSrc); ok {
2852 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002853 }
2854 return false
2855}
2856
Jiyong Parka90ca002019-10-07 15:47:24 +09002857func (c *Module) AvailableFor(what string) bool {
2858 if linker, ok := c.linker.(interface {
2859 availableFor(string) bool
2860 }); ok {
2861 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2862 } else {
2863 return c.ApexModuleBase.AvailableFor(what)
2864 }
2865}
2866
Jiyong Park62304bb2020-04-13 16:19:48 +09002867func (c *Module) TestFor() []string {
2868 if test, ok := c.linker.(interface {
2869 testFor() []string
2870 }); ok {
2871 return test.testFor()
2872 } else {
2873 return c.ApexModuleBase.TestFor()
2874 }
2875}
2876
Colin Crossaede88c2020-08-11 12:17:01 -07002877func (c *Module) UniqueApexVariations() bool {
2878 if u, ok := c.compiler.(interface {
2879 uniqueApexVariations() bool
2880 }); ok {
2881 return u.uniqueApexVariations()
2882 } else {
2883 return false
2884 }
2885}
2886
Paul Duffin0cb37b92020-03-04 14:52:46 +00002887// Return true if the module is ever installable.
2888func (c *Module) EverInstallable() bool {
2889 return c.installer != nil &&
2890 // Check to see whether the module is actually ever installable.
2891 c.installer.everInstallable()
2892}
2893
Colin Cross56a83212020-09-15 18:30:11 -07002894func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002895 ret := c.EverInstallable() &&
2896 // Check to see whether the module has been configured to not be installed.
2897 proptools.BoolDefault(c.Properties.Installable, true) &&
2898 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002899
2900 // The platform variant doesn't need further condition. Apex variants however might not
2901 // be installable because it will likely to be included in the APEX and won't appear
2902 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07002903 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002904 return ret
2905 }
2906
2907 // Special case for modules that are configured to be installed to /data, which includes
2908 // test modules. For these modules, both APEX and non-APEX variants are considered as
2909 // installable. This is because even the APEX variants won't be included in the APEX, but
2910 // will anyway be installed to /data/*.
2911 // See b/146995717
2912 if c.InstallInData() {
2913 return ret
2914 }
2915
2916 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002917}
2918
Logan Chien41eabe62019-04-10 13:33:58 +08002919func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2920 if c.linker != nil {
2921 if library, ok := c.linker.(*libraryDecorator); ok {
2922 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2923 }
2924 }
2925}
2926
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002927func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002928 depTag := ctx.OtherModuleDependencyTag(dep)
2929 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2930
2931 if cc, ok := dep.(*Module); ok {
2932 if cc.HasStubsVariants() {
2933 if isLibDepTag && libDepTag.shared() {
2934 // dynamic dep to a stubs lib crosses APEX boundary
2935 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002936 }
Colin Cross6e511a92020-07-27 21:26:48 -07002937 if IsRuntimeDepTag(depTag) {
2938 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002939 return false
2940 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002941 }
Colin Crossaac32222020-07-29 12:51:56 -07002942 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002943 // shared_lib dependency from a static lib is considered as crossing
2944 // the APEX boundary because the dependency doesn't actually is
2945 // linked; the dependency is used only during the compilation phase.
2946 return false
2947 }
2948 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07002949 if depTag == stubImplDepTag || depTag == llndkImplDep {
2950 // We don't track beyond LLNDK or from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09002951 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002952 }
2953 return true
2954}
2955
Dan Albertc8060532020-07-22 22:32:17 -07002956func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
2957 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09002958 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
2959 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
2960 return nil
2961 }
2962 // b/154569636: set min_sdk_version correctly for toolchain_libraries
2963 if c.ToolchainLibrary() {
2964 return nil
2965 }
2966 // We don't check for prebuilt modules
2967 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
2968 return nil
2969 }
2970 minSdkVersion := c.MinSdkVersion()
2971 if minSdkVersion == "apex_inherit" {
2972 return nil
2973 }
2974 if minSdkVersion == "" {
2975 // JNI libs within APK-in-APEX fall into here
2976 // Those are okay to set sdk_version instead
2977 // We don't have to check if this is a SDK variant because
2978 // non-SDK variant resets sdk_version, which works too.
2979 minSdkVersion = c.SdkVersion()
2980 }
Dan Albertc8060532020-07-22 22:32:17 -07002981 if minSdkVersion == "" {
2982 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
2983 }
2984 // Not using nativeApiLevelFromUser because the context here is not
2985 // necessarily a native context.
2986 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09002987 if err != nil {
2988 return err
2989 }
Dan Albertc8060532020-07-22 22:32:17 -07002990
2991 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09002992 return fmt.Errorf("newer SDK(%v)", ver)
2993 }
2994 return nil
2995}
2996
Colin Cross2ba19d92015-05-07 15:44:20 -07002997//
Colin Crosscfad1192015-11-02 16:43:11 -08002998// Defaults
2999//
Colin Crossca860ac2016-01-04 14:34:37 -08003000type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003001 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003002 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003003 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003004}
3005
Patrice Arrudac249c712019-03-19 17:00:29 -07003006// cc_defaults provides a set of properties that can be inherited by other cc
3007// modules. A module can use the properties from a cc_defaults using
3008// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3009// merged (when possible) by prepending the default module's values to the
3010// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003011func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003012 return DefaultsFactory()
3013}
3014
Colin Cross36242852017-06-23 15:06:31 -07003015func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003016 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003017
Colin Cross36242852017-06-23 15:06:31 -07003018 module.AddProperties(props...)
3019 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003020 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003021 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003022 &BaseCompilerProperties{},
3023 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003024 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003025 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003026 &StaticProperties{},
3027 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003028 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003029 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003030 &TestProperties{},
3031 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003032 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003033 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003034 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003035 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003036 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003037 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003038 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003039 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003040 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003041 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003042 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003043 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003044 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003045 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3046 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003047 )
Colin Crosscfad1192015-11-02 16:43:11 -08003048
Jooyung Hancc372c52019-09-25 15:18:44 +09003049 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003050
3051 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003052}
3053
Jiyong Park6a43f042017-10-12 23:05:00 +09003054func squashVendorSrcs(m *Module) {
3055 if lib, ok := m.compiler.(*libraryDecorator); ok {
3056 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3057 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3058
3059 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3060 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003061
3062 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3063 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003064 }
3065}
3066
Jiyong Parkf9332f12018-02-01 00:54:12 +09003067func squashRecoverySrcs(m *Module) {
3068 if lib, ok := m.compiler.(*libraryDecorator); ok {
3069 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3070 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3071
3072 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3073 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003074
3075 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3076 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003077 }
3078}
3079
Jiyong Park2286afd2020-06-16 21:58:53 +09003080func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003081 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003082}
3083
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003084func kytheExtractAllFactory() android.Singleton {
3085 return &kytheExtractAllSingleton{}
3086}
3087
3088type kytheExtractAllSingleton struct {
3089}
3090
3091func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3092 var xrefTargets android.Paths
3093 ctx.VisitAllModules(func(module android.Module) {
3094 if ccModule, ok := module.(xref); ok {
3095 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3096 }
3097 })
3098 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3099 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003100 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003101 }
3102}
3103
Colin Cross06a931b2015-10-28 17:23:31 -07003104var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003105var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003106var BoolPtr = proptools.BoolPtr
3107var String = proptools.String
3108var StringPtr = proptools.StringPtr