blob: 7698bd3da96c3b03dea3f660614470d159791fb9 [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
Jiyong Parkf9332f12018-02-01 00:54:12 +0900261 // Make this module available when building for recovery
262 Recovery_available *bool
263
Colin Crossae6c5202019-11-20 13:35:50 -0800264 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800265 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800266 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800267 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900268 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900269
270 // Allows this module to use non-APEX version of libraries. Useful
271 // for building binaries that are started before APEXes are activated.
272 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900273
274 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
275 // see soong/cc/config/vndk.go
276 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900277
278 // Used by vendor snapshot to record dependencies from snapshot modules.
279 SnapshotSharedLibs []string `blueprint:"mutated"`
280 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000281
282 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000283
284 // Set by factories of module types that can only be referenced from variants compiled against
285 // the SDK.
286 AlwaysSdk bool `blueprint:"mutated"`
287
288 // Variant is an SDK variant created by sdkMutator
289 IsSdkVariant bool `blueprint:"mutated"`
290 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
291 // variant to have a ".sdk" suffix.
292 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700293
294 // Normally Soong uses the directory structure to decide which modules
295 // should be included (framework) or excluded (non-framework) from the
296 // vendor snapshot, but this property allows a partner to exclude a
297 // module normally thought of as a framework module from the vendor
298 // snapshot.
299 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700300}
301
302type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900303 // whether this module should be allowed to be directly depended by other
304 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900305 // In addition, this module should be allowed to be directly depended by
306 // product modules with `product_specific: true`.
307 // If set to true, three variants will be built separately, one like
308 // normal, another limited to the set of libraries and headers
309 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700310 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900311 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700312 // so it shouldn't have any unversioned runtime dependencies, or
313 // make assumptions about the system that may not be true in the
314 // future.
315 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900316 // If set to false, this module becomes inaccessible from /vendor or /product
317 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900318 //
319 // Default value is true when vndk: {enabled: true} or vendor: true.
320 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700321 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900322 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700323 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900324
325 // whether this module is capable of being loaded with other instance
326 // (possibly an older version) of the same module in the same process.
327 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
328 // can be double loaded in a vendor process if the library is also a
329 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
330 // explicitly marked as `double_loadable: true` by the owner, or the dependency
331 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
332 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800333}
334
Colin Crossca860ac2016-01-04 14:34:37 -0800335type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800336 static() bool
337 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900338 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900339 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900340 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700341 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900342 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700343 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800344 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700345 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800346 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900347 isLlndk(config android.Config) bool
348 isLlndkPublic(config android.Config) bool
349 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900350 isVndk() bool
351 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800352 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900353 inProduct() bool
354 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800355 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900356 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800357 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700358 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700359 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800360 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800361 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800362 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800363 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800364 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700365 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700366 apexSdkVersion() android.ApiLevel
Jiyong Parkb0788572018-12-20 22:10:17 +0900367 hasStubsVariants() bool
368 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900369 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800370 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700371 nativeCoverage() bool
Colin Cross56a83212020-09-15 18:30:11 -0700372 directlyInAnyApex() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800373}
374
375type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700376 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800377 ModuleContextIntf
378}
379
380type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700381 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800382 ModuleContextIntf
383}
384
Colin Cross37047f12016-12-13 17:06:13 -0800385type DepsContext interface {
386 android.BottomUpMutatorContext
387 ModuleContextIntf
388}
389
Colin Crossca860ac2016-01-04 14:34:37 -0800390type feature interface {
391 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800392 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800393 flags(ctx ModuleContext, flags Flags) Flags
394 props() []interface{}
395}
396
397type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700398 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800399 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800400 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700401 compilerProps() []interface{}
402
Colin Cross76fada02016-07-27 10:31:13 -0700403 appendCflags([]string)
404 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700405 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800406}
407
408type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700409 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800410 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700411 linkerFlags(ctx ModuleContext, flags Flags) Flags
412 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800413 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700414
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700415 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700416 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900417 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700418
419 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900420 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000421
422 // Get the deps that have been explicitly specified in the properties.
423 // Only updates the
424 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
425}
426
427type specifiedDeps struct {
428 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000429 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800430}
431
432type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700433 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700434 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000435 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800436 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700437 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700438 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900439 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100440 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800441}
442
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800443type xref interface {
444 XrefCcFiles() android.Paths
445}
446
Colin Cross6e511a92020-07-27 21:26:48 -0700447type libraryDependencyKind int
448
449const (
450 headerLibraryDependency = iota
451 sharedLibraryDependency
452 staticLibraryDependency
453)
454
455func (k libraryDependencyKind) String() string {
456 switch k {
457 case headerLibraryDependency:
458 return "headerLibraryDependency"
459 case sharedLibraryDependency:
460 return "sharedLibraryDependency"
461 case staticLibraryDependency:
462 return "staticLibraryDependency"
463 default:
464 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
465 }
466}
467
468type libraryDependencyOrder int
469
470const (
471 earlyLibraryDependency = -1
472 normalLibraryDependency = 0
473 lateLibraryDependency = 1
474)
475
476func (o libraryDependencyOrder) String() string {
477 switch o {
478 case earlyLibraryDependency:
479 return "earlyLibraryDependency"
480 case normalLibraryDependency:
481 return "normalLibraryDependency"
482 case lateLibraryDependency:
483 return "lateLibraryDependency"
484 default:
485 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
486 }
487}
488
489// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
490// tags that have a set of predefined tag objects that are reused for each dependency, a
491// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
492// That means that comparing a libraryDependencyTag for equality will only be equal if all
493// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
494// then check individual metadata fields instead.
495type libraryDependencyTag struct {
496 blueprint.BaseDependencyTag
497
498 // These are exported so that fmt.Printf("%#v") can call their String methods.
499 Kind libraryDependencyKind
500 Order libraryDependencyOrder
501
502 wholeStatic bool
503
504 reexportFlags bool
505 explicitlyVersioned bool
506 dataLib bool
507 ndk bool
508
509 staticUnwinder bool
510
511 makeSuffix string
512}
513
514// header returns true if the libraryDependencyTag is tagging a header lib dependency.
515func (d libraryDependencyTag) header() bool {
516 return d.Kind == headerLibraryDependency
517}
518
519// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
520func (d libraryDependencyTag) shared() bool {
521 return d.Kind == sharedLibraryDependency
522}
523
524// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
525func (d libraryDependencyTag) static() bool {
526 return d.Kind == staticLibraryDependency
527}
528
529// dependencyTag is used for tagging miscellanous dependency types that don't fit into
530// libraryDependencyTag. Each tag object is created globally and reused for multiple
531// dependencies (although since the object contains no references, assigning a tag to a
532// variable and modifying it will not modify the original). Users can compare the tag
533// returned by ctx.OtherModuleDependencyTag against the global original
534type dependencyTag struct {
535 blueprint.BaseDependencyTag
536 name string
537}
538
Colin Crossc99deeb2016-04-11 15:06:20 -0700539var (
Colin Cross6e511a92020-07-27 21:26:48 -0700540 genSourceDepTag = dependencyTag{name: "gen source"}
541 genHeaderDepTag = dependencyTag{name: "gen header"}
542 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
543 objDepTag = dependencyTag{name: "obj"}
544 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
545 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
546 reuseObjTag = dependencyTag{name: "reuse objects"}
547 staticVariantTag = dependencyTag{name: "static variant"}
548 vndkExtDepTag = dependencyTag{name: "vndk extends"}
549 dataLibDepTag = dependencyTag{name: "data lib"}
550 runtimeDepTag = dependencyTag{name: "runtime lib"}
551 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700552 stubImplDepTag = dependencyTag{name: "stub_impl"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700553)
554
Colin Cross56a83212020-09-15 18:30:11 -0700555type copyDirectlyInAnyApexDependencyTag dependencyTag
556
557func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
558
559var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
560
Roland Levillainf89cd092019-07-29 16:22:59 +0100561func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700562 ccLibDepTag, ok := depTag.(libraryDependencyTag)
563 return ok && ccLibDepTag.shared()
564}
565
566func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
567 ccLibDepTag, ok := depTag.(libraryDependencyTag)
568 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100569}
570
571func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700572 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100573 return ok && ccDepTag == runtimeDepTag
574}
575
576func IsTestPerSrcDepTag(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 == testPerSrcDepTag
579}
580
Colin Crossca860ac2016-01-04 14:34:37 -0800581// Module contains the properties and members used by all C/C++ module types, and implements
582// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
583// to construct the output file. Behavior can be customized with a Customizer interface
584type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700585 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700586 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900587 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900588 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700589
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700590 Properties BaseProperties
591 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700592
Colin Crossca860ac2016-01-04 14:34:37 -0800593 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700594 hod android.HostOrDeviceSupported
595 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700596
Paul Duffina0843f62019-12-13 19:50:38 +0000597 // Allowable SdkMemberTypes of this module type.
598 sdkMemberTypes []android.SdkMemberType
599
Colin Crossca860ac2016-01-04 14:34:37 -0800600 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700601 features []feature
602 compiler compiler
603 linker linker
604 installer installer
605 stl *stl
606 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800607 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800608 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900609 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700610 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700611 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800612
Colin Cross635c3b02016-05-18 15:37:25 -0700613 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800614
Colin Crossb98c8b02016-07-29 13:44:28 -0700615 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700616
617 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800618
619 // Flags used to compile this module
620 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700621
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800622 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700623 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900624
625 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800626 // Kythe (source file indexer) paths for this compilation module
627 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900628
629 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700630 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700631
632 hideApexVariantFromMake bool
Colin Crossc472d572015-03-17 15:06:21 -0700633}
634
Ivan Lozano52767be2019-10-18 14:49:46 -0700635func (c *Module) Toc() android.OptionalPath {
636 if c.linker != nil {
637 if library, ok := c.linker.(libraryInterface); ok {
638 return library.toc()
639 }
640 }
641 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
642}
643
644func (c *Module) ApiLevel() string {
645 if c.linker != nil {
646 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700647 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700648 }
649 }
650 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
651}
652
653func (c *Module) Static() bool {
654 if c.linker != nil {
655 if library, ok := c.linker.(libraryInterface); ok {
656 return library.static()
657 }
658 }
659 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
660}
661
662func (c *Module) Shared() bool {
663 if c.linker != nil {
664 if library, ok := c.linker.(libraryInterface); ok {
665 return library.shared()
666 }
667 }
668 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
669}
670
671func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000672 if c.stl != nil {
673 return c.stl.Properties.SelectedStl
674 }
675 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700676}
677
678func (c *Module) ToolchainLibrary() bool {
679 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
680 return true
681 }
682 return false
683}
684
685func (c *Module) NdkPrebuiltStl() bool {
686 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
687 return true
688 }
689 return false
690}
691
692func (c *Module) StubDecorator() bool {
693 if _, ok := c.linker.(*stubDecorator); ok {
694 return true
695 }
696 return false
697}
698
699func (c *Module) SdkVersion() string {
700 return String(c.Properties.Sdk_version)
701}
702
Artur Satayev480e25b2020-04-27 18:53:18 +0100703func (c *Module) MinSdkVersion() string {
704 return String(c.Properties.Min_sdk_version)
705}
706
Dan Albert92fe7402020-07-15 13:33:30 -0700707func (c *Module) SplitPerApiLevel() bool {
Colin Cross1348ce32020-10-01 13:37:16 -0700708 if !c.canUseSdk() {
709 return false
710 }
Dan Albert92fe7402020-07-15 13:33:30 -0700711 if linker, ok := c.linker.(*objectLinker); ok {
712 return linker.isCrt()
713 }
714 return false
715}
716
Colin Crossc511bc52020-04-07 16:50:32 +0000717func (c *Module) AlwaysSdk() bool {
718 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
719}
720
Colin Cross3572cf72020-10-01 15:58:11 -0700721func (c *Module) StubsVersions(ctx android.BaseMutatorContext) []string {
Colin Crossc88c2722020-09-28 17:32:47 -0700722 if versioned, ok := c.linker.(versionedInterface); ok {
Colin Cross3572cf72020-10-01 15:58:11 -0700723 return versioned.stubsVersions(ctx)
Ivan Lozano183a3212019-10-18 14:18:45 -0700724 }
725 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
726}
727
728func (c *Module) CcLibrary() bool {
729 if c.linker != nil {
730 if _, ok := c.linker.(*libraryDecorator); ok {
731 return true
732 }
Colin Crossd48fe732020-09-23 20:37:24 -0700733 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
734 return true
735 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700736 }
737 return false
738}
739
740func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700741 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700742 return true
743 }
744 return false
745}
746
Ivan Lozano2b262972019-11-21 12:30:50 -0800747func (c *Module) NonCcVariants() bool {
748 return false
749}
750
Ivan Lozano183a3212019-10-18 14:18:45 -0700751func (c *Module) SetBuildStubs() {
Colin Crossc88c2722020-09-28 17:32:47 -0700752 if versioned, ok := c.linker.(versionedInterface); ok {
753 versioned.setBuildStubs()
754 c.Properties.HideFromMake = true
755 c.sanitize = nil
756 c.stl = nil
757 c.Properties.PreventInstall = true
758 return
Ivan Lozano183a3212019-10-18 14:18:45 -0700759 }
760 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
761}
762
Ivan Lozano52767be2019-10-18 14:49:46 -0700763func (c *Module) BuildStubs() bool {
Colin Crossc88c2722020-09-28 17:32:47 -0700764 if versioned, ok := c.linker.(versionedInterface); ok {
765 return versioned.buildStubs()
Ivan Lozano52767be2019-10-18 14:49:46 -0700766 }
767 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
768}
769
Colin Crossd1f898e2020-08-18 18:35:15 -0700770func (c *Module) SetAllStubsVersions(versions []string) {
Colin Crossc88c2722020-09-28 17:32:47 -0700771 if versioned, ok := c.linker.(versionedInterface); ok {
772 versioned.setAllStubsVersions(versions)
Colin Crossd1f898e2020-08-18 18:35:15 -0700773 }
774}
775
776func (c *Module) AllStubsVersions() []string {
Colin Crossc88c2722020-09-28 17:32:47 -0700777 if versioned, ok := c.linker.(versionedInterface); ok {
778 return versioned.allStubsVersions()
Colin Crossd1f898e2020-08-18 18:35:15 -0700779 }
780 return nil
781}
782
783func (c *Module) SetStubsVersion(version string) {
Colin Crossc88c2722020-09-28 17:32:47 -0700784 if versioned, ok := c.linker.(versionedInterface); ok {
785 versioned.setStubsVersion(version)
786 return
Ivan Lozano183a3212019-10-18 14:18:45 -0700787 }
Colin Crossd1f898e2020-08-18 18:35:15 -0700788 panic(fmt.Errorf("SetStubsVersion called on non-library module: %q", c.BaseModuleName()))
Ivan Lozano183a3212019-10-18 14:18:45 -0700789}
790
Jooyung Han03b51852020-02-26 22:45:42 +0900791func (c *Module) StubsVersion() string {
Colin Crossc88c2722020-09-28 17:32:47 -0700792 if versioned, ok := c.linker.(versionedInterface); ok {
793 return versioned.stubsVersion()
Jooyung Han03b51852020-02-26 22:45:42 +0900794 }
795 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
796}
797
Ivan Lozano183a3212019-10-18 14:18:45 -0700798func (c *Module) SetStatic() {
799 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700800 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700801 library.setStatic()
802 return
803 }
804 }
805 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
806}
807
808func (c *Module) SetShared() {
809 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700810 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700811 library.setShared()
812 return
813 }
814 }
815 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
816}
817
818func (c *Module) BuildStaticVariant() bool {
819 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700820 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700821 return library.buildStatic()
822 }
823 }
824 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
825}
826
827func (c *Module) BuildSharedVariant() bool {
828 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700829 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700830 return library.buildShared()
831 }
832 }
833 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
834}
835
836func (c *Module) Module() android.Module {
837 return c
838}
839
Jiyong Parkc20eee32018-09-05 22:36:17 +0900840func (c *Module) OutputFile() android.OptionalPath {
841 return c.outputFile
842}
843
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400844func (c *Module) CoverageFiles() android.Paths {
845 if c.linker != nil {
846 if library, ok := c.linker.(libraryInterface); ok {
847 return library.objs().coverageFiles
848 }
849 }
850 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
851}
852
Ivan Lozano183a3212019-10-18 14:18:45 -0700853var _ LinkableInterface = (*Module)(nil)
854
Jiyong Park719b4462019-01-13 00:39:51 +0900855func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900856 if c.linker != nil {
857 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900858 }
859 return nil
860}
861
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900862func (c *Module) CoverageOutputFile() android.OptionalPath {
863 if c.linker != nil {
864 return c.linker.coverageOutputFilePath()
865 }
866 return android.OptionalPath{}
867}
868
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900869func (c *Module) RelativeInstallPath() string {
870 if c.installer != nil {
871 return c.installer.relativeInstallPath()
872 }
873 return ""
874}
875
Jooyung Han344d5432019-08-23 11:17:39 +0900876func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900877 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900878}
879
Colin Cross36242852017-06-23 15:06:31 -0700880func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700881 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800882 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700883 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800884 }
885 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700886 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800887 }
888 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700889 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800890 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700891 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700892 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700893 }
Colin Cross16b23492016-01-06 14:41:07 -0800894 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700895 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800896 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800897 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700898 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800899 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800900 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700901 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800902 }
Justin Yun8effde42017-06-23 19:24:43 +0900903 if c.vndkdep != nil {
904 c.AddProperties(c.vndkdep.props()...)
905 }
Stephen Craneba090d12017-05-09 15:44:35 -0700906 if c.lto != nil {
907 c.AddProperties(c.lto.props()...)
908 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700909 if c.pgo != nil {
910 c.AddProperties(c.pgo.props()...)
911 }
Colin Crossca860ac2016-01-04 14:34:37 -0800912 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700913 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800914 }
Colin Crossc472d572015-03-17 15:06:21 -0700915
Jiyong Park1613e552020-09-14 19:43:17 +0900916 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700917 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900918 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700919 })
Colin Cross36242852017-06-23 15:06:31 -0700920 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900921 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900922 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900923 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900924
Colin Cross36242852017-06-23 15:06:31 -0700925 return c
Colin Crossc472d572015-03-17 15:06:21 -0700926}
927
Colin Crossb916a382016-07-29 17:28:03 -0700928// Returns true for dependency roots (binaries)
929// TODO(ccross): also handle dlopenable libraries
930func (c *Module) isDependencyRoot() bool {
931 if root, ok := c.linker.(interface {
932 isDependencyRoot() bool
933 }); ok {
934 return root.isDependencyRoot()
935 }
936 return false
937}
938
Justin Yun5f7f7e82019-11-18 19:52:14 +0900939// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
940// "product" and "vendor" variant modules return true for this function.
941// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
942// "soc_specific: true" and more vendor installed modules are included here.
943// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
944// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700945func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900946 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700947}
948
Colin Crossc511bc52020-04-07 16:50:32 +0000949func (c *Module) canUseSdk() bool {
950 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
951}
952
953func (c *Module) UseSdk() bool {
954 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -0700955 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +0000956 }
957 return false
958}
959
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800960func (c *Module) isCoverageVariant() bool {
961 return c.coverage.Properties.IsCoverageVariant
962}
963
Peter Collingbournead84f972019-12-17 16:46:18 -0800964func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -0700965 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800966}
967
Inseob Kim9516ee92019-05-09 10:56:13 +0900968func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800969 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900970 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800971}
972
Inseob Kim9516ee92019-05-09 10:56:13 +0900973func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800974 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900975 name := c.BaseModuleName()
976 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800977}
978
Inseob Kim9516ee92019-05-09 10:56:13 +0900979func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800980 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900981 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800982}
983
Ivan Lozano52767be2019-10-18 14:49:46 -0700984func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800985 if vndkdep := c.vndkdep; vndkdep != nil {
986 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900987 }
988 return false
989}
990
Yi Kong7e53c572018-02-14 18:16:12 +0800991func (c *Module) isPgoCompile() bool {
992 if pgo := c.pgo; pgo != nil {
993 return pgo.Properties.PgoCompile
994 }
995 return false
996}
997
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800998func (c *Module) isNDKStubLibrary() bool {
999 if _, ok := c.compiler.(*stubDecorator); ok {
1000 return true
1001 }
1002 return false
1003}
1004
Logan Chienf3511742017-10-31 18:04:35 +08001005func (c *Module) isVndkSp() bool {
1006 if vndkdep := c.vndkdep; vndkdep != nil {
1007 return vndkdep.isVndkSp()
1008 }
1009 return false
1010}
1011
1012func (c *Module) isVndkExt() bool {
1013 if vndkdep := c.vndkdep; vndkdep != nil {
1014 return vndkdep.isVndkExt()
1015 }
1016 return false
1017}
1018
Ivan Lozano52767be2019-10-18 14:49:46 -07001019func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001020 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001021}
1022
Logan Chienf3511742017-10-31 18:04:35 +08001023func (c *Module) getVndkExtendsModuleName() string {
1024 if vndkdep := c.vndkdep; vndkdep != nil {
1025 return vndkdep.getVndkExtendsModuleName()
1026 }
1027 return ""
1028}
1029
Jiyong Park25fc6a92018-11-18 18:02:45 +09001030func (c *Module) IsStubs() bool {
Colin Crossc88c2722020-09-28 17:32:47 -07001031 if versioned, ok := c.linker.(versionedInterface); ok {
1032 return versioned.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001033 }
1034 return false
1035}
1036
1037func (c *Module) HasStubsVariants() bool {
Colin Crossc88c2722020-09-28 17:32:47 -07001038 if versioned, ok := c.linker.(versionedInterface); ok {
1039 return versioned.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001040 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001041 return false
1042}
1043
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001044func (c *Module) bootstrap() bool {
1045 return Bool(c.Properties.Bootstrap)
1046}
1047
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001048func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001049 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1050 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1051 return false
1052 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001053 return c.linker != nil && c.linker.nativeCoverage()
1054}
1055
Inseob Kim8471cda2019-11-15 09:59:12 +09001056func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001057 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1058 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001059 }
1060 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001061}
1062
Bill Peckham945441c2020-08-31 16:07:58 -07001063func (c *Module) ExcludeFromVendorSnapshot() bool {
1064 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1065}
1066
Jiyong Parkf1194352019-02-25 11:05:47 +09001067func isBionic(name string) bool {
1068 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001069 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001070 return true
1071 }
1072 return false
1073}
1074
Martin Stjernholm279de572019-09-10 23:18:20 +01001075func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001076 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001077 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001078 }
1079 return isBionic(name)
1080}
1081
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001082func (c *Module) XrefCcFiles() android.Paths {
1083 return c.kytheFiles
1084}
1085
Colin Crossca860ac2016-01-04 14:34:37 -08001086type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001087 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001088 moduleContextImpl
1089}
1090
Colin Cross37047f12016-12-13 17:06:13 -08001091type depsContext struct {
1092 android.BottomUpMutatorContext
1093 moduleContextImpl
1094}
1095
Colin Crossca860ac2016-01-04 14:34:37 -08001096type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001097 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001098 moduleContextImpl
1099}
1100
1101type moduleContextImpl struct {
1102 mod *Module
1103 ctx BaseModuleContext
1104}
1105
Colin Crossb98c8b02016-07-29 13:44:28 -07001106func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001107 return ctx.mod.toolchain(ctx.ctx)
1108}
1109
1110func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001111 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001112}
1113
1114func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001115 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001116}
1117
Jiyong Park1d1119f2019-07-29 21:27:18 +09001118func (ctx *moduleContextImpl) header() bool {
1119 return ctx.mod.header()
1120}
1121
Inseob Kim7f283f42020-06-01 21:53:49 +09001122func (ctx *moduleContextImpl) binary() bool {
1123 return ctx.mod.binary()
1124}
1125
Inseob Kim1042d292020-06-01 23:23:05 +09001126func (ctx *moduleContextImpl) object() bool {
1127 return ctx.mod.object()
1128}
1129
Jooyung Hanccce2f22020-03-07 03:45:53 +09001130func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001131 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001132}
1133
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001134func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001135 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001136}
1137
1138func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001139 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001140 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001141 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001142 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001143 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001144 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001145 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001146 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001147 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001148 }
1149 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001150}
1151
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001152func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001153 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001154}
Justin Yun8effde42017-06-23 19:24:43 +09001155
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001156func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001157 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001158}
1159
Inseob Kim9516ee92019-05-09 10:56:13 +09001160func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1161 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001162}
1163
Inseob Kim9516ee92019-05-09 10:56:13 +09001164func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1165 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001166}
1167
Inseob Kim9516ee92019-05-09 10:56:13 +09001168func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1169 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001170}
1171
Logan Chienf3511742017-10-31 18:04:35 +08001172func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001173 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001174}
1175
Yi Kong7e53c572018-02-14 18:16:12 +08001176func (ctx *moduleContextImpl) isPgoCompile() bool {
1177 return ctx.mod.isPgoCompile()
1178}
1179
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001180func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1181 return ctx.mod.isNDKStubLibrary()
1182}
1183
Justin Yun8effde42017-06-23 19:24:43 +09001184func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001185 return ctx.mod.isVndkSp()
1186}
1187
1188func (ctx *moduleContextImpl) isVndkExt() bool {
1189 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001190}
1191
Vic Yangefd249e2018-11-12 20:19:56 -08001192func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001193 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001194}
1195
Logan Chien2f2b8902018-07-10 15:01:19 +08001196// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001197func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001198 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1199 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001200 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001201
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001202 // Coverage builds have extra symbols.
1203 if ctx.mod.isCoverageVariant() {
1204 return false
1205 }
1206
Doug Hornc32c6b02019-01-17 14:44:05 -08001207 if ctx.ctx.Fuchsia() {
1208 return false
1209 }
1210
Logan Chien2f2b8902018-07-10 15:01:19 +08001211 if sanitize := ctx.mod.sanitize; sanitize != nil {
1212 if !sanitize.isVariantOnProductionDevice() {
1213 return false
1214 }
1215 }
1216 if !ctx.ctx.Device() {
1217 // Host modules do not need ABI dumps.
1218 return false
1219 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001220 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001221 // Stubs do not need ABI dumps.
1222 return false
1223 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001224 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001225}
1226
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001227func (ctx *moduleContextImpl) selectedStl() string {
1228 if stl := ctx.mod.stl; stl != nil {
1229 return stl.Properties.SelectedStl
1230 }
1231 return ""
1232}
1233
Ivan Lozanobd721262018-11-27 14:33:03 -08001234func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1235 return ctx.mod.linker.useClangLld(actx)
1236}
1237
Colin Crossce75d2c2016-10-06 16:12:58 -07001238func (ctx *moduleContextImpl) baseModuleName() string {
1239 return ctx.mod.ModuleBase.BaseModuleName()
1240}
1241
Logan Chienf3511742017-10-31 18:04:35 +08001242func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1243 return ctx.mod.getVndkExtendsModuleName()
1244}
1245
Logan Chiene274fc92019-12-03 11:18:32 -08001246func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Cross56a83212020-09-15 18:30:11 -07001247 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001248}
1249
Colin Crosse07f2312020-08-13 11:24:56 -07001250func (ctx *moduleContextImpl) apexVariationName() string {
Colin Cross56a83212020-09-15 18:30:11 -07001251 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001252}
1253
Dan Albertc8060532020-07-22 22:32:17 -07001254func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001255 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001256}
1257
Jiyong Parkb0788572018-12-20 22:10:17 +09001258func (ctx *moduleContextImpl) hasStubsVariants() bool {
1259 return ctx.mod.HasStubsVariants()
1260}
1261
1262func (ctx *moduleContextImpl) isStubs() bool {
1263 return ctx.mod.IsStubs()
1264}
1265
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001266func (ctx *moduleContextImpl) bootstrap() bool {
1267 return ctx.mod.bootstrap()
1268}
1269
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001270func (ctx *moduleContextImpl) nativeCoverage() bool {
1271 return ctx.mod.nativeCoverage()
1272}
1273
Colin Cross56a83212020-09-15 18:30:11 -07001274func (ctx *moduleContextImpl) directlyInAnyApex() bool {
1275 return ctx.mod.DirectlyInAnyApex()
1276}
1277
Colin Cross635c3b02016-05-18 15:37:25 -07001278func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001279 return &Module{
1280 hod: hod,
1281 multilib: multilib,
1282 }
1283}
1284
Colin Cross635c3b02016-05-18 15:37:25 -07001285func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001286 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001287 module.features = []feature{
1288 &tidyFeature{},
1289 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001290 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001291 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001292 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001293 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001294 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001295 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001296 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001297 return module
1298}
1299
Colin Crossce75d2c2016-10-06 16:12:58 -07001300func (c *Module) Prebuilt() *android.Prebuilt {
1301 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1302 return p.prebuilt()
1303 }
1304 return nil
1305}
1306
1307func (c *Module) Name() string {
1308 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001309 if p, ok := c.linker.(interface {
1310 Name(string) string
1311 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001312 name = p.Name(name)
1313 }
1314 return name
1315}
1316
Alex Light3d673592019-01-18 14:37:31 -08001317func (c *Module) Symlinks() []string {
1318 if p, ok := c.installer.(interface {
1319 symlinkList() []string
1320 }); ok {
1321 return p.symlinkList()
1322 }
1323 return nil
1324}
1325
Roland Levillainf89cd092019-07-29 16:22:59 +01001326func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1327 test, ok := c.linker.(testPerSrc)
1328 return ok && test.isAllTestsVariation()
1329}
1330
Chris Parsons216e10a2020-07-09 17:12:52 -04001331func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001332 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001333 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001334 }); ok {
1335 return p.dataPaths()
1336 }
1337 return nil
1338}
1339
Justin Yun5f7f7e82019-11-18 19:52:14 +09001340func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1341 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1342 // "current", it will append the VNDK version to the name suffix.
1343 var vndkVersion string
1344 var nameSuffix string
1345 if c.inProduct() {
1346 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1347 nameSuffix = productSuffix
1348 } else {
1349 vndkVersion = ctx.DeviceConfig().VndkVersion()
1350 nameSuffix = vendorSuffix
1351 }
1352 if vndkVersion == "current" {
1353 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1354 }
1355 if c.Properties.VndkVersion != vndkVersion {
1356 // add version suffix only if the module is using different vndk version than the
1357 // version in product or vendor partition.
1358 nameSuffix += "." + c.Properties.VndkVersion
1359 }
1360 return nameSuffix
1361}
1362
Colin Cross635c3b02016-05-18 15:37:25 -07001363func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001364 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001365 //
1366 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1367 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1368 // module and return early, as this module does not produce an output file per se.
1369 if c.IsTestPerSrcAllTestsVariation() {
1370 c.outputFile = android.OptionalPath{}
1371 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001372 }
1373
Colin Cross56a83212020-09-15 18:30:11 -07001374 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1375 if !apexInfo.IsForPlatform() {
1376 c.hideApexVariantFromMake = true
1377 }
1378
Jooyung Han38002912019-05-16 04:01:54 +09001379 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001380
Inseob Kim64c43952019-08-26 16:52:35 +09001381 c.Properties.SubName = ""
1382
1383 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1384 c.Properties.SubName += nativeBridgeSuffix
1385 }
1386
Justin Yun5f7f7e82019-11-18 19:52:14 +09001387 _, llndk := c.linker.(*llndkStubDecorator)
1388 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1389 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1390 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1391 // added for product variant only when we have vendor and product variants with core
1392 // variant. The suffix is not added for vendor-only or product-only module.
1393 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1394 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001395 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1396 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1397 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001398 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1399 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001400 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001401 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001402 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001403 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001404 if c.SplitPerApiLevel() {
1405 c.Properties.SubName += "." + c.SdkVersion()
1406 }
Inseob Kim64c43952019-08-26 16:52:35 +09001407 }
1408
Colin Crossca860ac2016-01-04 14:34:37 -08001409 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001410 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001411 moduleContextImpl: moduleContextImpl{
1412 mod: c,
1413 },
1414 }
1415 ctx.ctx = ctx
1416
Colin Crossf18e1102017-11-16 14:33:08 -08001417 deps := c.depsToPaths(ctx)
1418 if ctx.Failed() {
1419 return
1420 }
1421
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001422 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1423 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1424 }
1425
Colin Crossca860ac2016-01-04 14:34:37 -08001426 flags := Flags{
1427 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001428 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001429 }
Colin Crossca860ac2016-01-04 14:34:37 -08001430 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001431 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001432 }
1433 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001434 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001435 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001436 if c.stl != nil {
1437 flags = c.stl.flags(ctx, flags)
1438 }
Colin Cross16b23492016-01-06 14:41:07 -08001439 if c.sanitize != nil {
1440 flags = c.sanitize.flags(ctx, flags)
1441 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001442 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001443 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001444 }
Stephen Craneba090d12017-05-09 15:44:35 -07001445 if c.lto != nil {
1446 flags = c.lto.flags(ctx, flags)
1447 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001448 if c.pgo != nil {
1449 flags = c.pgo.flags(ctx, flags)
1450 }
Colin Crossca860ac2016-01-04 14:34:37 -08001451 for _, feature := range c.features {
1452 flags = feature.flags(ctx, flags)
1453 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001454 if ctx.Failed() {
1455 return
1456 }
1457
Colin Cross4af21ed2019-11-04 09:37:55 -08001458 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1459 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1460 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001461
Colin Cross4af21ed2019-11-04 09:37:55 -08001462 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001463
1464 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001465 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001466 }
1467 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001468 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001469 }
1470
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001471 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001472 // We need access to all the flags seen by a source file.
1473 if c.sabi != nil {
1474 flags = c.sabi.flags(ctx, flags)
1475 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001476
Colin Cross4af21ed2019-11-04 09:37:55 -08001477 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001478
Colin Crossca860ac2016-01-04 14:34:37 -08001479 // Optimization to reduce size of build.ninja
1480 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001481 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1482 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1483 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1484 flags.Local.CFlags = []string{"$cflags"}
1485 flags.Local.CppFlags = []string{"$cppflags"}
1486 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001487
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001488 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001489 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001490 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001491 if ctx.Failed() {
1492 return
1493 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001494 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001495 }
1496
Colin Crossca860ac2016-01-04 14:34:37 -08001497 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001498 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001499 if ctx.Failed() {
1500 return
1501 }
Colin Cross635c3b02016-05-18 15:37:25 -07001502 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001503
1504 // If a lib is directly included in any of the APEXes, unhide the stubs
1505 // variant having the latest version gets visible to make. In addition,
1506 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1507 // force anything in the make world to link against the stubs library.
1508 // (unless it is explicitly referenced via .bootstrap suffix or the
1509 // module is marked with 'bootstrap: true').
Colin Cross56a83212020-09-15 18:30:11 -07001510 if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001511 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001512 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001513 c.Properties.HideFromMake = false // unhide
1514 // Note: this is still non-installable
1515 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001516
1517 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1518 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
Colin Cross56a83212020-09-15 18:30:11 -07001519 if isSnapshotAware(ctx, c, apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001520 i.collectHeadersForSnapshot(ctx)
1521 }
1522 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001523 }
Colin Cross5049f022015-03-18 13:28:46 -07001524
Colin Cross56a83212020-09-15 18:30:11 -07001525 if c.installable(apexInfo) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001526 c.installer.install(ctx, c.outputFile.Path())
1527 if ctx.Failed() {
1528 return
Colin Crossca860ac2016-01-04 14:34:37 -08001529 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001530 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1531 // If the module has been specifically configure to not be installed then
1532 // skip the installation as otherwise it will break when running inside make
1533 // as the output path to install will not be specified. Not all uninstallable
1534 // modules can skip installation as some are needed for resolving make side
1535 // dependencies.
1536 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001537 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001538}
1539
Colin Cross0ea8ba82019-06-06 14:33:29 -07001540func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001541 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001542 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001543 }
Colin Crossca860ac2016-01-04 14:34:37 -08001544 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001545}
1546
Colin Crossca860ac2016-01-04 14:34:37 -08001547func (c *Module) begin(ctx BaseModuleContext) {
1548 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001549 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001550 }
Colin Crossca860ac2016-01-04 14:34:37 -08001551 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001552 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001553 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001554 if c.stl != nil {
1555 c.stl.begin(ctx)
1556 }
Colin Cross16b23492016-01-06 14:41:07 -08001557 if c.sanitize != nil {
1558 c.sanitize.begin(ctx)
1559 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001560 if c.coverage != nil {
1561 c.coverage.begin(ctx)
1562 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001563 if c.sabi != nil {
1564 c.sabi.begin(ctx)
1565 }
Justin Yun8effde42017-06-23 19:24:43 +09001566 if c.vndkdep != nil {
1567 c.vndkdep.begin(ctx)
1568 }
Stephen Craneba090d12017-05-09 15:44:35 -07001569 if c.lto != nil {
1570 c.lto.begin(ctx)
1571 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001572 if c.pgo != nil {
1573 c.pgo.begin(ctx)
1574 }
Colin Crossca860ac2016-01-04 14:34:37 -08001575 for _, feature := range c.features {
1576 feature.begin(ctx)
1577 }
Dan Albert92fe7402020-07-15 13:33:30 -07001578 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001579 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001580 if err != nil {
1581 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001582 c.Properties.Sdk_version = nil
1583 } else {
1584 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001585 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001586 }
Colin Crossca860ac2016-01-04 14:34:37 -08001587}
1588
Colin Cross37047f12016-12-13 17:06:13 -08001589func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001590 deps := Deps{}
1591
1592 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001593 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001594 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001595 // Add the PGO dependency (the clang_rt.profile runtime library), which
1596 // sometimes depends on symbols from libgcc, before libgcc gets added
1597 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001598 if c.pgo != nil {
1599 deps = c.pgo.deps(ctx, deps)
1600 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001601 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001602 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001603 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001604 if c.stl != nil {
1605 deps = c.stl.deps(ctx, deps)
1606 }
Colin Cross16b23492016-01-06 14:41:07 -08001607 if c.sanitize != nil {
1608 deps = c.sanitize.deps(ctx, deps)
1609 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001610 if c.coverage != nil {
1611 deps = c.coverage.deps(ctx, deps)
1612 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001613 if c.sabi != nil {
1614 deps = c.sabi.deps(ctx, deps)
1615 }
Justin Yun8effde42017-06-23 19:24:43 +09001616 if c.vndkdep != nil {
1617 deps = c.vndkdep.deps(ctx, deps)
1618 }
Stephen Craneba090d12017-05-09 15:44:35 -07001619 if c.lto != nil {
1620 deps = c.lto.deps(ctx, deps)
1621 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001622 for _, feature := range c.features {
1623 deps = feature.deps(ctx, deps)
1624 }
1625
Colin Crossb6715442017-10-24 11:13:31 -07001626 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1627 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1628 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1629 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1630 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1631 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001632 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001633
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001634 for _, lib := range deps.ReexportSharedLibHeaders {
1635 if !inList(lib, deps.SharedLibs) {
1636 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1637 }
1638 }
1639
1640 for _, lib := range deps.ReexportStaticLibHeaders {
1641 if !inList(lib, deps.StaticLibs) {
1642 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1643 }
1644 }
1645
Colin Cross5950f382016-12-13 12:50:57 -08001646 for _, lib := range deps.ReexportHeaderLibHeaders {
1647 if !inList(lib, deps.HeaderLibs) {
1648 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1649 }
1650 }
1651
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001652 for _, gen := range deps.ReexportGeneratedHeaders {
1653 if !inList(gen, deps.GeneratedHeaders) {
1654 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1655 }
1656 }
1657
Colin Crossc99deeb2016-04-11 15:06:20 -07001658 return deps
1659}
1660
Dan Albert7e9d2952016-08-04 13:02:36 -07001661func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001662 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001663 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001664 moduleContextImpl: moduleContextImpl{
1665 mod: c,
1666 },
1667 }
1668 ctx.ctx = ctx
1669
Colin Crossca860ac2016-01-04 14:34:37 -08001670 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001671}
1672
Jiyong Park7ed9de32018-10-15 22:25:07 +09001673// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001674func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001675 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1676 version := name[sharp+1:]
1677 libname := name[:sharp]
1678 return libname, version
1679 }
1680 return name, ""
1681}
1682
Dan Albert92fe7402020-07-15 13:33:30 -07001683func GetCrtVariations(ctx android.BottomUpMutatorContext,
1684 m LinkableInterface) []blueprint.Variation {
1685 if ctx.Os() != android.Android {
1686 return nil
1687 }
1688 if m.UseSdk() {
1689 return []blueprint.Variation{
1690 {Mutator: "sdk", Variation: "sdk"},
Colin Crossbbc941b2020-09-30 12:27:01 -07001691 {Mutator: "version", Variation: m.SdkVersion()},
Dan Albert92fe7402020-07-15 13:33:30 -07001692 }
1693 }
1694 return []blueprint.Variation{
1695 {Mutator: "sdk", Variation: ""},
1696 }
1697}
1698
Colin Crosse7257d22020-09-24 09:56:18 -07001699func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1700 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1701
1702 variations = append([]blueprint.Variation(nil), variations...)
1703
Colin Cross3146c5c2020-09-30 15:34:40 -07001704 if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001705 // Version is explicitly specified. i.e. libFoo#30
1706 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1707 depTag.explicitlyVersioned = true
1708 }
Colin Crosse7257d22020-09-24 09:56:18 -07001709
Colin Cross0de8a1e2020-09-18 14:15:30 -07001710 if far {
1711 ctx.AddFarVariationDependencies(variations, depTag, name)
1712 } else {
1713 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07001714 }
1715}
1716
Colin Cross1e676be2016-10-12 14:38:15 -07001717func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001718 if !c.Enabled() {
1719 return
1720 }
1721
Colin Cross37047f12016-12-13 17:06:13 -08001722 ctx := &depsContext{
1723 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001724 moduleContextImpl: moduleContextImpl{
1725 mod: c,
1726 },
1727 }
1728 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001729
Colin Crossc99deeb2016-04-11 15:06:20 -07001730 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001731
Yo Chiang219968c2020-09-22 18:45:04 +08001732 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1733
Dan Albert914449f2016-06-17 16:45:24 -07001734 variantNdkLibs := []string{}
1735 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001736 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001737 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001738 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001739 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001740 // 1. Name of an NDK library that refers to a prebuilt module.
1741 // For each of these, it adds the name of the prebuilt module (which will be in
1742 // prebuilts/ndk) to the list of nonvariant libs.
1743 // 2. Name of an NDK library that refers to an ndk_library module.
1744 // For each of these, it adds the name of the ndk_library module to the list of
1745 // variant libs.
1746 // 3. Anything else (so anything that isn't an NDK library).
1747 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001748 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001749 // The caller can then know to add the variantLibs dependencies differently from the
1750 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001751
Inseob Kim9516ee92019-05-09 10:56:13 +09001752 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001753 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1754
1755 rewriteVendorLibs := func(lib string) string {
1756 if isLlndkLibrary(lib, ctx.Config()) {
1757 return lib + llndkLibrarySuffix
1758 }
1759
1760 // only modules with BOARD_VNDK_VERSION uses snapshot.
1761 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1762 return lib
1763 }
1764
1765 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1766 return snapshot
1767 }
1768
1769 return lib
1770 }
1771
1772 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001773 variantLibs = []string{}
1774 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001775 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001776 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001777 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001778 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1779 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001780 } else if ctx.useVndk() {
1781 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001782 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001783 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001784 if actx.OtherModuleExists(vendorPublicLib) {
1785 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1786 } else {
1787 // This can happen if vendor_public_library module is defined in a
1788 // namespace that isn't visible to the current module. In that case,
1789 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001790 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001791 }
Dan Albert914449f2016-06-17 16:45:24 -07001792 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001793 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001794 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001795 }
1796 }
Dan Albert914449f2016-06-17 16:45:24 -07001797 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001798 }
1799
Inseob Kimeec88e12020-01-22 11:11:29 +09001800 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1801 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1802 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1803 if ctx.useVndk() {
1804 for idx, lib := range deps.RuntimeLibs {
1805 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1806 }
1807 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001808 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001809
Jiyong Park7e636d02019-01-28 16:16:54 +09001810 buildStubs := false
Colin Crossc88c2722020-09-28 17:32:47 -07001811 if versioned, ok := c.linker.(versionedInterface); ok {
1812 if versioned.buildStubs() {
1813 buildStubs = true
Colin Crossd48fe732020-09-23 20:37:24 -07001814 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001815 }
1816
Inseob Kimeec88e12020-01-22 11:11:29 +09001817 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1818 // only modules with BOARD_VNDK_VERSION uses snapshot.
1819 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1820 return lib
1821 }
1822
1823 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1824 return snapshot
1825 }
1826
1827 return lib
1828 }
1829
1830 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001831 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001832 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001833 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001834 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001835 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001836
1837 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1838
Jiyong Park7e636d02019-01-28 16:16:54 +09001839 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001840 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001841 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001842 } else {
1843 actx.AddVariationDependencies(nil, depTag, lib)
1844 }
1845 }
1846
1847 if buildStubs {
1848 // Stubs lib does not have dependency to other static/shared libraries.
1849 // Don't proceed.
1850 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001851 }
Colin Cross5950f382016-12-13 12:50:57 -08001852
Inseob Kimc0907f12019-02-08 21:00:45 +09001853 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001854 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001855
Jiyong Park5d1598f2019-02-25 22:14:17 +09001856 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001857 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001858 if impl, ok := syspropImplLibraries[lib]; ok {
1859 lib = impl
1860 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001861
1862 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1863
Jiyong Park5d1598f2019-02-25 22:14:17 +09001864 actx.AddVariationDependencies([]blueprint.Variation{
1865 {Mutator: "link", Variation: "static"},
1866 }, depTag, lib)
1867 }
1868
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001869 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001870 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001871 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001872 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001873 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001874
1875 if impl, ok := syspropImplLibraries[lib]; ok {
1876 lib = impl
1877 }
1878
Inseob Kimeec88e12020-01-22 11:11:29 +09001879 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1880
Dan Willemsen59339a22018-07-22 21:18:45 -07001881 actx.AddVariationDependencies([]blueprint.Variation{
1882 {Mutator: "link", Variation: "static"},
1883 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001884 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001885
Jooyung Han75568392020-03-20 04:29:24 +09001886 // staticUnwinderDep is treated as staticDep for Q apexes
1887 // so that native libraries/binaries are linked with static unwinder
1888 // because Q libc doesn't have unwinder APIs
1889 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001890 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001891 actx.AddVariationDependencies([]blueprint.Variation{
1892 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001893 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001894 }
1895
Inseob Kimeec88e12020-01-22 11:11:29 +09001896 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001897 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001898 actx.AddVariationDependencies([]blueprint.Variation{
1899 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001900 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001901 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001902
Jiyong Park7ed9de32018-10-15 22:25:07 +09001903 // shared lib names without the #version suffix
1904 var sharedLibNames []string
1905
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001906 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001907 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001908 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001909 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001910 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001911
1912 if impl, ok := syspropImplLibraries[lib]; ok {
1913 lib = impl
1914 }
1915
Jiyong Park73c54ee2019-10-22 20:31:18 +09001916 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001917 sharedLibNames = append(sharedLibNames, name)
1918
Colin Crosse7257d22020-09-24 09:56:18 -07001919 variations := []blueprint.Variation{
1920 {Mutator: "link", Variation: "shared"},
1921 }
1922 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001923 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001924
Jiyong Park7ed9de32018-10-15 22:25:07 +09001925 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001926 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001927 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1928 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1929 // linking against both the stubs lib and the non-stubs lib at the same time.
1930 continue
1931 }
Colin Cross6e511a92020-07-27 21:26:48 -07001932 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07001933 variations := []blueprint.Variation{
1934 {Mutator: "link", Variation: "shared"},
1935 }
1936 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001937 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001938
Dan Willemsen59339a22018-07-22 21:18:45 -07001939 actx.AddVariationDependencies([]blueprint.Variation{
1940 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04001941 }, dataLibDepTag, deps.DataLibs...)
1942
1943 actx.AddVariationDependencies([]blueprint.Variation{
1944 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07001945 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001946
Colin Cross68861832016-07-08 10:41:41 -07001947 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001948
1949 for _, gen := range deps.GeneratedHeaders {
1950 depTag := genHeaderDepTag
1951 if inList(gen, deps.ReexportGeneratedHeaders) {
1952 depTag = genHeaderExportDepTag
1953 }
1954 actx.AddDependency(c, depTag, gen)
1955 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001956
Inseob Kim1042d292020-06-01 23:23:05 +09001957 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
1958
Dan Albert92fe7402020-07-15 13:33:30 -07001959 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07001960 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001961 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001962 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
1963 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08001964 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001965 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001966 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
1967 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07001968 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001969 if deps.LinkerFlagsFile != "" {
1970 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1971 }
1972 if deps.DynamicLinker != "" {
1973 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001974 }
Dan Albert914449f2016-06-17 16:45:24 -07001975
1976 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07001977
1978 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07001979 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07001980 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07001981 {Mutator: "link", Variation: "shared"},
1982 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07001983
1984 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07001985 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07001986 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07001987 {Mutator: "link", Variation: "shared"},
1988 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001989
1990 if vndkdep := c.vndkdep; vndkdep != nil {
1991 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001992 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001993 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001994 {Mutator: "link", Variation: "shared"},
1995 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001996 }
1997 }
Colin Cross6362e272015-10-29 15:25:03 -07001998}
Colin Cross21b9a242015-03-24 14:15:58 -07001999
Colin Crosse40b4ea2018-10-02 22:25:58 -07002000func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002001 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2002 c.beginMutator(ctx)
2003 }
2004}
2005
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002006// Whether a module can link to another module, taking into
2007// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002008func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002009 tag blueprint.DependencyTag) {
2010
2011 switch t := tag.(type) {
2012 case dependencyTag:
2013 if t != vndkExtDepTag {
2014 return
2015 }
2016 case libraryDependencyTag:
2017 default:
2018 return
2019 }
2020
Ivan Lozano52767be2019-10-18 14:49:46 -07002021 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002022 // Host code is not restricted
2023 return
2024 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002025
2026 // VNDK is cc.Module supported only for now.
2027 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002028 // Though vendor code is limited by the vendor mutator,
2029 // each vendor-available module needs to check
2030 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002031 if ccTo, ok := to.(*Module); ok {
2032 if ccFrom.vndkdep != nil {
2033 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2034 }
2035 } else {
2036 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002037 }
2038 return
2039 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002040 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002041 // Platform code can link to anything
2042 return
2043 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002044 if from.InRamdisk() {
2045 // Ramdisk code is not NDK
2046 return
2047 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002048 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002049 // Recovery code is not NDK
2050 return
2051 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002052 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002053 // These are always allowed
2054 return
2055 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002056 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002057 // These are allowed, but they don't set sdk_version
2058 return
2059 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002060 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002061 // These aren't real libraries, but are the stub shared libraries that are included in
2062 // the NDK.
2063 return
2064 }
Logan Chien834b9a62019-01-14 15:39:03 +08002065
Ivan Lozano52767be2019-10-18 14:49:46 -07002066 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002067 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2068 // to link to libc++ (non-NDK and without sdk_version).
2069 return
2070 }
2071
Ivan Lozano52767be2019-10-18 14:49:46 -07002072 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002073 // NDK code linking to platform code is never okay.
2074 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002075 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002076 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002077 }
2078
2079 // At this point we know we have two NDK libraries, but we need to
2080 // check that we're not linking against anything built against a higher
2081 // API level, as it is only valid to link against older or equivalent
2082 // APIs.
2083
Inseob Kim01a28722018-04-11 09:48:45 +09002084 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002085 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002086 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002087 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002088 // Current can't be linked against by anything else.
2089 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002090 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002091 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002092 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002093 if err != nil {
2094 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002095 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002096 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002097 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002098 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002099 if err != nil {
2100 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002101 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002102 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002103 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002104
Inseob Kim01a28722018-04-11 09:48:45 +09002105 if toApi > fromApi {
2106 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002107 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002108 }
2109 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002110 }
Dan Albert202fe492017-12-15 13:56:59 -08002111
2112 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002113 fromStl := from.SelectedStl()
2114 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002115 if fromStl == "" || toStl == "" {
2116 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002117 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002118 // We can be permissive with the system "STL" since it is only the C++
2119 // ABI layer, but in the future we should make sure that everyone is
2120 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002121 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002122 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002123 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2124 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002125 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002126}
2127
Jooyung Han479ca172020-10-19 18:51:07 +09002128func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2129 if c, ok := ctx.Module().(*Module); ok {
2130 ctx.VisitDirectDeps(func(dep android.Module) {
2131 depTag := ctx.OtherModuleDependencyTag(dep)
2132 ccDep, ok := dep.(LinkableInterface)
2133 if ok {
2134 checkLinkType(ctx, c, ccDep, depTag)
2135 }
2136 })
2137 }
2138}
2139
Jiyong Park5fb8c102018-04-09 12:03:06 +09002140// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002141// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2142// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002143// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002144func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2145 check := func(child, parent android.Module) bool {
2146 to, ok := child.(*Module)
2147 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002148 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002149 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002150
Jooyung Hana70f0672019-01-18 15:20:43 +09002151 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2152 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002153 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002154
Jooyung Han479ca172020-10-19 18:51:07 +09002155 // Even if target lib has no vendor variant, keep checking dependency graph
2156 // in case it depends on vendor_available but not double_loadable transtively.
Ivan Lozano52767be2019-10-18 14:49:46 -07002157 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002158 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002159 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002160
Jooyung Han0302a842019-10-30 18:43:49 +09002161 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002162 return false
2163 }
2164
2165 var stringPath []string
2166 for _, m := range ctx.GetWalkPath() {
2167 stringPath = append(stringPath, m.Name())
2168 }
2169 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2170 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2171 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2172 return false
2173 }
2174 if module, ok := ctx.Module().(*Module); ok {
2175 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002176 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002177 ctx.WalkDeps(check)
2178 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002179 }
2180 }
2181}
2182
Colin Cross0de8a1e2020-09-18 14:15:30 -07002183// Returns the highest version which is <= maxSdkVersion.
2184// For example, with maxSdkVersion is 10 and versionList is [9,11]
2185// it returns 9 as string. The list of stubs must be in order from
2186// oldest to newest.
2187func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedLibraryStubsInfo,
2188 maxSdkVersion android.ApiLevel) (SharedLibraryStubsInfo, error) {
2189
2190 for i := range stubsInfo {
2191 stubInfo := stubsInfo[len(stubsInfo)-i-1]
2192 var ver android.ApiLevel
2193 if stubInfo.Version == "" {
2194 ver = android.FutureApiLevel
2195 } else {
2196 var err error
2197 ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
2198 if err != nil {
2199 return SharedLibraryStubsInfo{}, err
2200 }
2201 }
2202 if ver.LessThanOrEqualTo(maxSdkVersion) {
2203 return stubInfo, nil
2204 }
2205 }
2206 var versionList []string
2207 for _, stubInfo := range stubsInfo {
2208 versionList = append(versionList, stubInfo.Version)
2209 }
2210 return SharedLibraryStubsInfo{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
2211}
2212
Colin Crossc99deeb2016-04-11 15:06:20 -07002213// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002214func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002215 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002216
Colin Cross0de8a1e2020-09-18 14:15:30 -07002217 var directStaticDeps []StaticLibraryInfo
2218 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07002219
Colin Cross0de8a1e2020-09-18 14:15:30 -07002220 reexportExporter := func(exporter FlagExporterInfo) {
2221 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
2222 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
2223 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
2224 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
2225 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09002226 }
2227
Jooyung Hande34d232020-07-23 13:04:15 +09002228 // For the dependency from platform to apex, use the latest stubs
2229 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002230 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2231 if !apexInfo.IsForPlatform() {
2232 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002233 }
2234
2235 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2236 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2237 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2238 // (b/144430859)
2239 c.apexSdkVersion = android.FutureApiLevel
2240 }
2241
Colin Crossd11fcda2017-10-23 17:59:01 -07002242 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002243 depName := ctx.OtherModuleName(dep)
2244 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002245
Ivan Lozano52767be2019-10-18 14:49:46 -07002246 ccDep, ok := dep.(LinkableInterface)
2247 if !ok {
2248
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002249 // handling for a few module types that aren't cc Module but that are also supported
2250 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002251 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002252 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002253 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2254 genRule.GeneratedSourceFiles()...)
2255 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002256 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002257 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002258 // Support exported headers from a generated_sources dependency
2259 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002260 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002261 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002262 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002263 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002264 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002265 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002266 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002267 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002268 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2269 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002270 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002271 // 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 +09002272 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002273
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002274 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002275 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002276 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002277 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002278 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002279 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002280 files := genRule.GeneratedSourceFiles()
2281 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002282 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002283 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002284 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 -07002285 }
2286 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002287 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002288 }
Colin Crossca860ac2016-01-04 14:34:37 -08002289 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002290 return
2291 }
2292
Colin Crossfe17f6f2019-03-28 19:30:56 -07002293 if depTag == android.ProtoPluginDepTag {
2294 return
2295 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002296 if depTag == llndkImplDep {
2297 return
2298 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002299
Colin Crossd11fcda2017-10-23 17:59:01 -07002300 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002301 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2302 return
2303 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002304 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002305 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2306 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002307 return
2308 }
2309
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002310 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002311 // reusing objects only make sense for cc.Modules.
Colin Cross0de8a1e2020-09-18 14:15:30 -07002312 staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2313 objs := staticAnalogue.ReuseObjects
2314 depPaths.Objs = depPaths.Objs.Append(objs)
2315 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
2316 reexportExporter(depExporterInfo)
2317 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09002318 }
2319
Colin Cross6e511a92020-07-27 21:26:48 -07002320 linkFile := ccDep.OutputFile()
2321
2322 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2323 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002324 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002325 return
2326 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002327
Colin Cross0de8a1e2020-09-18 14:15:30 -07002328 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
Colin Crossc99deeb2016-04-11 15:06:20 -07002329
Colin Cross6e511a92020-07-27 21:26:48 -07002330 var ptr *android.Paths
2331 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002332
Colin Cross6e511a92020-07-27 21:26:48 -07002333 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002334
Colin Cross6e511a92020-07-27 21:26:48 -07002335 switch {
2336 case libDepTag.header():
2337 // nothing
2338 case libDepTag.shared():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002339 if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
2340 if !ctx.Config().AllowMissingDependencies() {
2341 ctx.ModuleErrorf("module %q is not a shared library", depName)
2342 } else {
2343 ctx.AddMissingDependencies([]string{depName})
2344 }
2345 return
2346 }
2347 sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
2348 sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryImplementationStubsInfoProvider).(SharedLibraryImplementationStubsInfo)
2349
2350 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedLibraryStubsInfos) > 0 {
2351 useStubs := false
2352 if m, ok := ccDep.(*Module); ok && m.IsStubs() && c.UseVndk() { // LLNDK
2353 if !apexInfo.IsForPlatform() {
2354 // For platform libraries, use current version of LLNDK
2355 // If this is for use_vendor apex we will apply the same rules
2356 // of apex sdk enforcement below to choose right version.
2357 useStubs = true
2358 }
2359 } else if apexInfo.IsForPlatform() {
2360 // If not building for APEX, use stubs only when it is from
2361 // an APEX (and not from platform)
2362 // However, for host, ramdisk, recovery or bootstrap modules,
2363 // always link to non-stub variant
2364 useStubs = dep.(android.ApexModule).AnyVariantDirectlyInAnyApex() && !c.bootstrap()
2365 // Another exception: if this module is bundled with an APEX, then
2366 // it is linked with the non-stub variant of a module in the APEX
2367 // as if this is part of the APEX.
2368 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2369 for _, apexContents := range testFor.ApexContents {
2370 if apexContents.DirectlyInApex(depName) {
2371 useStubs = false
2372 break
2373 }
2374 }
2375 } else {
2376 // If building for APEX, use stubs when the parent is in any APEX that
2377 // the child is not in.
2378 useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
2379 }
2380
2381 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2382 if useStubs {
2383 sharedLibraryStubsInfo, err :=
2384 c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedLibraryStubsInfos, c.apexSdkVersion)
2385 if err != nil {
2386 ctx.OtherModuleErrorf(dep, err.Error())
2387 return
2388 }
2389 sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
2390 depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
2391 }
2392 }
2393
2394 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
2395 depFile = sharedLibraryInfo.TableOfContents
2396
Colin Cross6e511a92020-07-27 21:26:48 -07002397 ptr = &depPaths.SharedLibs
2398 switch libDepTag.Order {
2399 case earlyLibraryDependency:
2400 ptr = &depPaths.EarlySharedLibs
2401 depPtr = &depPaths.EarlySharedLibsDeps
2402 case normalLibraryDependency:
2403 ptr = &depPaths.SharedLibs
2404 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07002405 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002406 case lateLibraryDependency:
2407 ptr = &depPaths.LateSharedLibs
2408 depPtr = &depPaths.LateSharedLibsDeps
2409 default:
2410 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002411 }
Colin Cross6e511a92020-07-27 21:26:48 -07002412 case libDepTag.static():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002413 if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
2414 if !ctx.Config().AllowMissingDependencies() {
2415 ctx.ModuleErrorf("module %q is not a static library", depName)
2416 } else {
2417 ctx.AddMissingDependencies([]string{depName})
2418 }
2419 return
2420 }
2421 staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2422 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
Colin Cross6e511a92020-07-27 21:26:48 -07002423 if libDepTag.wholeStatic {
2424 ptr = &depPaths.WholeStaticLibs
Colin Cross0de8a1e2020-09-18 14:15:30 -07002425 if len(staticLibraryInfo.Objects.objFiles) > 0 {
2426 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
Inseob Kimeec88e12020-01-22 11:11:29 +09002427 } else {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002428 // This case normally catches prebuilt static
2429 // libraries, but it can also occur when
2430 // AllowMissingDependencies is on and the
2431 // dependencies has no sources of its own
2432 // but has a whole_static_libs dependency
2433 // on a missing library. We want to depend
2434 // on the .a file so that there is something
2435 // in the dependency tree that contains the
2436 // error rule for the missing transitive
2437 // dependency.
2438 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002439 }
Colin Cross6e511a92020-07-27 21:26:48 -07002440 } else {
2441 switch libDepTag.Order {
2442 case earlyLibraryDependency:
2443 panic(fmt.Errorf("early static libs not suppported"))
2444 case normalLibraryDependency:
2445 // static dependencies will be handled separately so they can be ordered
2446 // using transitive dependencies.
2447 ptr = nil
Colin Cross0de8a1e2020-09-18 14:15:30 -07002448 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002449 case lateLibraryDependency:
2450 ptr = &depPaths.LateStaticLibs
2451 default:
2452 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002453 }
2454 }
2455 }
2456
Colin Cross6e511a92020-07-27 21:26:48 -07002457 if libDepTag.static() && !libDepTag.wholeStatic {
2458 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2459 ctx.ModuleErrorf("module %q not a static library", depName)
2460 return
2461 }
Logan Chien43d34c32017-12-20 01:17:32 +08002462
Colin Cross6e511a92020-07-27 21:26:48 -07002463 // When combining coverage files for shared libraries and executables, coverage files
2464 // in static libraries act as if they were whole static libraries. The same goes for
2465 // source based Abi dump files.
2466 if c, ok := ccDep.(*Module); ok {
2467 staticLib := c.linker.(libraryInterface)
2468 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2469 staticLib.objs().coverageFiles...)
2470 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2471 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002472 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002473 // Handle non-CC modules here
2474 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002475 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002476 }
2477 }
2478
Colin Cross6e511a92020-07-27 21:26:48 -07002479 if ptr != nil {
2480 if !linkFile.Valid() {
2481 if !ctx.Config().AllowMissingDependencies() {
2482 ctx.ModuleErrorf("module %q missing output file", depName)
2483 } else {
2484 ctx.AddMissingDependencies([]string{depName})
2485 }
2486 return
2487 }
2488 *ptr = append(*ptr, linkFile.Path())
2489 }
2490
2491 if depPtr != nil {
2492 dep := depFile
2493 if !dep.Valid() {
2494 dep = linkFile
2495 }
2496 *depPtr = append(*depPtr, dep.Path())
2497 }
2498
Colin Cross0de8a1e2020-09-18 14:15:30 -07002499 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
2500 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
2501 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
2502 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
2503
2504 if libDepTag.reexportFlags {
2505 reexportExporter(depExporterInfo)
2506 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2507 // Re-exported shared library headers must be included as well since they can help us with type information
2508 // about template instantiations (instantiated from their headers).
2509 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2510 // scripts.
2511 c.sabi.Properties.ReexportedIncludes = append(
2512 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
2513 }
2514
Colin Cross6e511a92020-07-27 21:26:48 -07002515 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2516 switch {
2517 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002518 c.Properties.AndroidMkHeaderLibs = append(
2519 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002520 case libDepTag.shared():
2521 if ccDep.CcLibrary() {
Colin Cross56a83212020-09-15 18:30:11 -07002522 if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002523 // Add the dependency to the APEX(es) providing the library so that
2524 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002525 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2526 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002527 c.Properties.ApexesProvidingSharedLibs = append(
2528 c.Properties.ApexesProvidingSharedLibs, an)
2529 }
2530 }
2531 }
2532
2533 // Note: the order of libs in this list is not important because
2534 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002535 c.Properties.AndroidMkSharedLibs = append(
2536 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002537 // Record baseLibName for snapshots.
2538 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2539 case libDepTag.static():
2540 if libDepTag.wholeStatic {
2541 c.Properties.AndroidMkWholeStaticLibs = append(
2542 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2543 } else {
2544 c.Properties.AndroidMkStaticLibs = append(
2545 c.Properties.AndroidMkStaticLibs, makeLibName)
2546 }
2547 }
2548 } else {
2549 switch depTag {
2550 case runtimeDepTag:
2551 c.Properties.AndroidMkRuntimeLibs = append(
2552 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2553 // Record baseLibName for snapshots.
2554 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2555 case objDepTag:
2556 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2557 case CrtBeginDepTag:
2558 depPaths.CrtBegin = linkFile
2559 case CrtEndDepTag:
2560 depPaths.CrtEnd = linkFile
2561 case dynamicLinkerDepTag:
2562 depPaths.DynamicLinker = linkFile
2563 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002564 }
Colin Crossca860ac2016-01-04 14:34:37 -08002565 })
2566
Jeff Gaston294356f2017-09-27 17:05:30 -07002567 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07002568 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
2569 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
2570 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002571
Colin Crossdd84e052017-05-17 13:44:16 -07002572 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002573 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002574 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2575 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002576 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002577 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2578 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002579 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002580 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002581 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002582
2583 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002584 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002585 }
Colin Crossdd84e052017-05-17 13:44:16 -07002586
Colin Crossca860ac2016-01-04 14:34:37 -08002587 return depPaths
2588}
2589
Colin Cross0de8a1e2020-09-18 14:15:30 -07002590// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
2591// to match the topological order of the dependency tree, including any static analogues of
2592// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
2593// of the transitive dependencies.
2594func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
2595 transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
2596 var staticPaths android.Paths
2597 for _, staticDep := range staticDeps {
2598 staticPaths = append(staticPaths, staticDep.StaticLibrary)
2599 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
2600 }
2601 for _, sharedDep := range sharedDeps {
2602 if sharedDep.StaticAnalogue != nil {
2603 transitiveStaticLibsBuilder.Transitive(sharedDep.StaticAnalogue.TransitiveStaticLibrariesForOrdering)
2604 }
2605 }
2606 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
2607
2608 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
2609
2610 // reorder the dependencies based on transitive dependencies
2611 staticPaths = android.FirstUniquePaths(staticPaths)
2612 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
2613
2614 if len(orderedStaticPaths) != len(staticPaths) {
2615 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
2616 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
2617 }
2618
2619 return orderedStaticPaths, transitiveStaticLibs
2620}
2621
Colin Cross6e511a92020-07-27 21:26:48 -07002622// baseLibName trims known prefixes and suffixes
2623func baseLibName(depName string) string {
2624 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2625 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2626 libName = strings.TrimPrefix(libName, "prebuilt_")
2627 return libName
2628}
2629
2630func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2631 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2632 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2633
2634 libName := baseLibName(depName)
2635 isLLndk := isLlndkLibrary(libName, ctx.Config())
2636 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2637 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2638
2639 if c, ok := ccDep.(*Module); ok {
2640 // Use base module name for snapshots when exporting to Makefile.
2641 if c.isSnapshotPrebuilt() {
2642 baseName := c.BaseModuleName()
2643
2644 if c.IsVndk() {
2645 return baseName + ".vendor"
2646 }
2647
2648 if vendorSuffixModules[baseName] {
2649 return baseName + ".vendor"
2650 } else {
2651 return baseName
2652 }
2653 }
2654 }
2655
2656 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2657 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2658 // core module instead.
2659 return libName
2660 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2661 // The vendor module in Make will have been renamed to not conflict with the core
2662 // module, so update the dependency name here accordingly.
2663 return libName + c.getNameSuffixWithVndkVersion(ctx)
2664 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2665 return libName + vendorPublicLibrarySuffix
2666 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2667 return libName + ramdiskSuffix
2668 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2669 return libName + recoverySuffix
2670 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2671 return libName + nativeBridgeSuffix
2672 } else {
2673 return libName
2674 }
2675}
2676
Colin Crossca860ac2016-01-04 14:34:37 -08002677func (c *Module) InstallInData() bool {
2678 if c.installer == nil {
2679 return false
2680 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002681 return c.installer.inData()
2682}
2683
2684func (c *Module) InstallInSanitizerDir() bool {
2685 if c.installer == nil {
2686 return false
2687 }
2688 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002689 return true
2690 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002691 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002692}
2693
Yifan Hong1b3348d2020-01-21 15:53:22 -08002694func (c *Module) InstallInRamdisk() bool {
2695 return c.InRamdisk()
2696}
2697
Jiyong Parkf9332f12018-02-01 00:54:12 +09002698func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002699 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002700}
2701
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002702func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002703 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002704 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002705 return
2706 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002707 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002708}
2709
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002710func (c *Module) HostToolPath() android.OptionalPath {
2711 if c.installer == nil {
2712 return android.OptionalPath{}
2713 }
2714 return c.installer.hostToolPath()
2715}
2716
Nan Zhangd4e641b2017-07-12 12:55:28 -07002717func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2718 return c.outputFile
2719}
2720
Colin Cross41955e82019-05-29 14:40:35 -07002721func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2722 switch tag {
2723 case "":
2724 if c.outputFile.Valid() {
2725 return android.Paths{c.outputFile.Path()}, nil
2726 }
2727 return android.Paths{}, nil
2728 default:
2729 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002730 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002731}
2732
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002733func (c *Module) static() bool {
2734 if static, ok := c.linker.(interface {
2735 static() bool
2736 }); ok {
2737 return static.static()
2738 }
2739 return false
2740}
2741
Jiyong Park379de2f2018-12-19 02:47:14 +09002742func (c *Module) staticBinary() bool {
2743 if static, ok := c.linker.(interface {
2744 staticBinary() bool
2745 }); ok {
2746 return static.staticBinary()
2747 }
2748 return false
2749}
2750
Jiyong Park1d1119f2019-07-29 21:27:18 +09002751func (c *Module) header() bool {
2752 if h, ok := c.linker.(interface {
2753 header() bool
2754 }); ok {
2755 return h.header()
2756 }
2757 return false
2758}
2759
Inseob Kim7f283f42020-06-01 21:53:49 +09002760func (c *Module) binary() bool {
2761 if b, ok := c.linker.(interface {
2762 binary() bool
2763 }); ok {
2764 return b.binary()
2765 }
2766 return false
2767}
2768
Inseob Kim1042d292020-06-01 23:23:05 +09002769func (c *Module) object() bool {
2770 if o, ok := c.linker.(interface {
2771 object() bool
2772 }); ok {
2773 return o.object()
2774 }
2775 return false
2776}
2777
Jooyung Han38002912019-05-16 04:01:54 +09002778func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002779 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002780 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2781 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002782 return "native:vndk"
2783 }
Jooyung Han38002912019-05-16 04:01:54 +09002784 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002785 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002786 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002787 if Bool(c.VendorProperties.Vendor_available) {
2788 return "native:vndk"
2789 }
2790 return "native:vndk_private"
2791 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002792 if c.inProduct() {
2793 return "native:product"
2794 }
Jooyung Han38002912019-05-16 04:01:54 +09002795 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002796 } else if c.InRamdisk() {
2797 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002798 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002799 return "native:recovery"
2800 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2801 return "native:ndk:none:none"
2802 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2803 //family, link := getNdkStlFamilyAndLinkType(c)
2804 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002805 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002806 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002807 } else {
2808 return "native:platform"
2809 }
2810}
2811
Jiyong Park9d452992018-10-03 00:38:19 +09002812// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002813// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002814func (c *Module) IsInstallableToApex() bool {
2815 if shared, ok := c.linker.(interface {
2816 shared() bool
2817 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002818 // Stub libs and prebuilt libs in a versioned SDK are not
2819 // installable to APEX even though they are shared libs.
2820 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002821 } else if _, ok := c.linker.(testPerSrc); ok {
2822 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002823 }
2824 return false
2825}
2826
Jiyong Parka90ca002019-10-07 15:47:24 +09002827func (c *Module) AvailableFor(what string) bool {
2828 if linker, ok := c.linker.(interface {
2829 availableFor(string) bool
2830 }); ok {
2831 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2832 } else {
2833 return c.ApexModuleBase.AvailableFor(what)
2834 }
2835}
2836
Jiyong Park62304bb2020-04-13 16:19:48 +09002837func (c *Module) TestFor() []string {
2838 if test, ok := c.linker.(interface {
2839 testFor() []string
2840 }); ok {
2841 return test.testFor()
2842 } else {
2843 return c.ApexModuleBase.TestFor()
2844 }
2845}
2846
Colin Crossaede88c2020-08-11 12:17:01 -07002847func (c *Module) UniqueApexVariations() bool {
2848 if u, ok := c.compiler.(interface {
2849 uniqueApexVariations() bool
2850 }); ok {
2851 return u.uniqueApexVariations()
2852 } else {
2853 return false
2854 }
2855}
2856
Paul Duffin0cb37b92020-03-04 14:52:46 +00002857// Return true if the module is ever installable.
2858func (c *Module) EverInstallable() bool {
2859 return c.installer != nil &&
2860 // Check to see whether the module is actually ever installable.
2861 c.installer.everInstallable()
2862}
2863
Colin Cross56a83212020-09-15 18:30:11 -07002864func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002865 ret := c.EverInstallable() &&
2866 // Check to see whether the module has been configured to not be installed.
2867 proptools.BoolDefault(c.Properties.Installable, true) &&
2868 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002869
2870 // The platform variant doesn't need further condition. Apex variants however might not
2871 // be installable because it will likely to be included in the APEX and won't appear
2872 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07002873 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002874 return ret
2875 }
2876
2877 // Special case for modules that are configured to be installed to /data, which includes
2878 // test modules. For these modules, both APEX and non-APEX variants are considered as
2879 // installable. This is because even the APEX variants won't be included in the APEX, but
2880 // will anyway be installed to /data/*.
2881 // See b/146995717
2882 if c.InstallInData() {
2883 return ret
2884 }
2885
2886 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002887}
2888
Logan Chien41eabe62019-04-10 13:33:58 +08002889func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2890 if c.linker != nil {
2891 if library, ok := c.linker.(*libraryDecorator); ok {
2892 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2893 }
2894 }
2895}
2896
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002897func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002898 depTag := ctx.OtherModuleDependencyTag(dep)
2899 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2900
2901 if cc, ok := dep.(*Module); ok {
2902 if cc.HasStubsVariants() {
2903 if isLibDepTag && libDepTag.shared() {
2904 // dynamic dep to a stubs lib crosses APEX boundary
2905 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002906 }
Colin Cross6e511a92020-07-27 21:26:48 -07002907 if IsRuntimeDepTag(depTag) {
2908 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002909 return false
2910 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002911 }
Colin Crossaac32222020-07-29 12:51:56 -07002912 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002913 // shared_lib dependency from a static lib is considered as crossing
2914 // the APEX boundary because the dependency doesn't actually is
2915 // linked; the dependency is used only during the compilation phase.
2916 return false
2917 }
2918 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07002919 if depTag == stubImplDepTag || depTag == llndkImplDep {
2920 // We don't track beyond LLNDK or from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09002921 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002922 }
2923 return true
2924}
2925
Dan Albertc8060532020-07-22 22:32:17 -07002926func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
2927 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09002928 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
2929 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
2930 return nil
2931 }
2932 // b/154569636: set min_sdk_version correctly for toolchain_libraries
2933 if c.ToolchainLibrary() {
2934 return nil
2935 }
2936 // We don't check for prebuilt modules
2937 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
2938 return nil
2939 }
2940 minSdkVersion := c.MinSdkVersion()
2941 if minSdkVersion == "apex_inherit" {
2942 return nil
2943 }
2944 if minSdkVersion == "" {
2945 // JNI libs within APK-in-APEX fall into here
2946 // Those are okay to set sdk_version instead
2947 // We don't have to check if this is a SDK variant because
2948 // non-SDK variant resets sdk_version, which works too.
2949 minSdkVersion = c.SdkVersion()
2950 }
Dan Albertc8060532020-07-22 22:32:17 -07002951 if minSdkVersion == "" {
2952 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
2953 }
2954 // Not using nativeApiLevelFromUser because the context here is not
2955 // necessarily a native context.
2956 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09002957 if err != nil {
2958 return err
2959 }
Dan Albertc8060532020-07-22 22:32:17 -07002960
2961 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09002962 return fmt.Errorf("newer SDK(%v)", ver)
2963 }
2964 return nil
2965}
2966
Colin Cross2ba19d92015-05-07 15:44:20 -07002967//
Colin Crosscfad1192015-11-02 16:43:11 -08002968// Defaults
2969//
Colin Crossca860ac2016-01-04 14:34:37 -08002970type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002971 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002972 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002973 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002974}
2975
Patrice Arrudac249c712019-03-19 17:00:29 -07002976// cc_defaults provides a set of properties that can be inherited by other cc
2977// modules. A module can use the properties from a cc_defaults using
2978// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2979// merged (when possible) by prepending the default module's values to the
2980// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002981func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002982 return DefaultsFactory()
2983}
2984
Colin Cross36242852017-06-23 15:06:31 -07002985func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002986 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002987
Colin Cross36242852017-06-23 15:06:31 -07002988 module.AddProperties(props...)
2989 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002990 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002991 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002992 &BaseCompilerProperties{},
2993 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002994 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002995 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002996 &StaticProperties{},
2997 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002998 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002999 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003000 &TestProperties{},
3001 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003002 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003003 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003004 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003005 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003006 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003007 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003008 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003009 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003010 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003011 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003012 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003013 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003014 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003015 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3016 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003017 )
Colin Crosscfad1192015-11-02 16:43:11 -08003018
Jooyung Hancc372c52019-09-25 15:18:44 +09003019 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003020
3021 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003022}
3023
Jiyong Park6a43f042017-10-12 23:05:00 +09003024func squashVendorSrcs(m *Module) {
3025 if lib, ok := m.compiler.(*libraryDecorator); ok {
3026 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3027 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3028
3029 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3030 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003031
3032 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3033 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003034 }
3035}
3036
Jiyong Parkf9332f12018-02-01 00:54:12 +09003037func squashRecoverySrcs(m *Module) {
3038 if lib, ok := m.compiler.(*libraryDecorator); ok {
3039 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3040 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3041
3042 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3043 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003044
3045 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3046 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003047 }
3048}
3049
Jiyong Park2286afd2020-06-16 21:58:53 +09003050func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003051 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003052}
3053
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003054func kytheExtractAllFactory() android.Singleton {
3055 return &kytheExtractAllSingleton{}
3056}
3057
3058type kytheExtractAllSingleton struct {
3059}
3060
3061func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3062 var xrefTargets android.Paths
3063 ctx.VisitAllModules(func(module android.Module) {
3064 if ccModule, ok := module.(xref); ok {
3065 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3066 }
3067 })
3068 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3069 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003070 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003071 }
3072}
3073
Colin Cross06a931b2015-10-28 17:23:31 -07003074var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003075var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003076var BoolPtr = proptools.BoolPtr
3077var String = proptools.String
3078var StringPtr = proptools.StringPtr