blob: 8235e35cdbdd63e37fc6cfb7547a6c84ec97aca4 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Colin Crossd1f898e2020-08-18 18:35:15 -070050 ctx.BottomUp("version_selector", versionSelectorMutator).Parallel()
51 ctx.BottomUp("version", versionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070052 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090053 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090054 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
55 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070056 })
Colin Cross16b23492016-01-06 14:41:07 -080057
Paul Duffin036e7002019-12-19 19:16:28 +000058 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
60 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080061
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070062 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
63 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
64
Mitch Phillipsbfeade62019-05-01 14:42:05 -070065 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
66 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
67
Jiyong Park1d1119f2019-07-29 21:27:18 +090068 // cfi mutator shouldn't run before sanitizers that return true for
69 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000070 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
71 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
72
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080073 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
74 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
75
Colin Cross1e676be2016-10-12 14:38:15 -070076 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
77 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080078
Colin Cross0b908332019-06-19 23:00:20 -070079 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090080 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080081
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080082 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080083 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070084
85 ctx.TopDown("lto_deps", ltoDepsMutator)
86 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090087
88 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
Ivan Lozano183a3212019-10-18 14:18:45 -0700721func (c *Module) StubsVersions() []string {
Colin Crossc88c2722020-09-28 17:32:47 -0700722 if versioned, ok := c.linker.(versionedInterface); ok {
723 return versioned.stubsVersions()
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"},
1691 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1692 }
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
Colin Cross42d48b72018-08-29 14:10:52 -07001957 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001958
Inseob Kim1042d292020-06-01 23:23:05 +09001959 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
1960
Dan Albert92fe7402020-07-15 13:33:30 -07001961 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07001962 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001963 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
1964 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08001965 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001966 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07001967 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
1968 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07001969 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001970 if deps.LinkerFlagsFile != "" {
1971 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1972 }
1973 if deps.DynamicLinker != "" {
1974 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001975 }
Dan Albert914449f2016-06-17 16:45:24 -07001976
1977 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07001978
1979 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07001980 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001981 {Mutator: "ndk_api", Variation: version},
1982 {Mutator: "link", Variation: "shared"},
1983 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07001984
1985 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07001986 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001987 {Mutator: "ndk_api", Variation: version},
1988 {Mutator: "link", Variation: "shared"},
1989 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001990
1991 if vndkdep := c.vndkdep; vndkdep != nil {
1992 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001993 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001994 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001995 {Mutator: "link", Variation: "shared"},
1996 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001997 }
1998 }
Colin Cross6362e272015-10-29 15:25:03 -07001999}
Colin Cross21b9a242015-03-24 14:15:58 -07002000
Colin Crosse40b4ea2018-10-02 22:25:58 -07002001func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002002 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2003 c.beginMutator(ctx)
2004 }
2005}
2006
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002007// Whether a module can link to another module, taking into
2008// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002009func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2010 tag blueprint.DependencyTag) {
2011
2012 switch t := tag.(type) {
2013 case dependencyTag:
2014 if t != vndkExtDepTag {
2015 return
2016 }
2017 case libraryDependencyTag:
2018 default:
2019 return
2020 }
2021
Ivan Lozano52767be2019-10-18 14:49:46 -07002022 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002023 // Host code is not restricted
2024 return
2025 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002026
2027 // VNDK is cc.Module supported only for now.
2028 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002029 // Though vendor code is limited by the vendor mutator,
2030 // each vendor-available module needs to check
2031 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002032 if ccTo, ok := to.(*Module); ok {
2033 if ccFrom.vndkdep != nil {
2034 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2035 }
2036 } else {
2037 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002038 }
2039 return
2040 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002041 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002042 // Platform code can link to anything
2043 return
2044 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002045 if from.InRamdisk() {
2046 // Ramdisk code is not NDK
2047 return
2048 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002049 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002050 // Recovery code is not NDK
2051 return
2052 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002053 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002054 // These are always allowed
2055 return
2056 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002057 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002058 // These are allowed, but they don't set sdk_version
2059 return
2060 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002061 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002062 // These aren't real libraries, but are the stub shared libraries that are included in
2063 // the NDK.
2064 return
2065 }
Logan Chien834b9a62019-01-14 15:39:03 +08002066
Ivan Lozano52767be2019-10-18 14:49:46 -07002067 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002068 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2069 // to link to libc++ (non-NDK and without sdk_version).
2070 return
2071 }
2072
Ivan Lozano52767be2019-10-18 14:49:46 -07002073 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002074 // NDK code linking to platform code is never okay.
2075 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002076 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002077 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002078 }
2079
2080 // At this point we know we have two NDK libraries, but we need to
2081 // check that we're not linking against anything built against a higher
2082 // API level, as it is only valid to link against older or equivalent
2083 // APIs.
2084
Inseob Kim01a28722018-04-11 09:48:45 +09002085 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002086 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002087 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002088 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002089 // Current can't be linked against by anything else.
2090 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002091 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002092 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002093 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002094 if err != nil {
2095 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002096 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002097 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002098 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002099 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002100 if err != nil {
2101 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002102 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002103 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002104 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002105
Inseob Kim01a28722018-04-11 09:48:45 +09002106 if toApi > fromApi {
2107 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002108 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002109 }
2110 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002111 }
Dan Albert202fe492017-12-15 13:56:59 -08002112
2113 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002114 fromStl := from.SelectedStl()
2115 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002116 if fromStl == "" || toStl == "" {
2117 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002118 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002119 // We can be permissive with the system "STL" since it is only the C++
2120 // ABI layer, but in the future we should make sure that everyone is
2121 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002122 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002123 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002124 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2125 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002126 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002127}
2128
Jiyong Park5fb8c102018-04-09 12:03:06 +09002129// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002130// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2131// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002132// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002133func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2134 check := func(child, parent android.Module) bool {
2135 to, ok := child.(*Module)
2136 if !ok {
2137 // follow thru cc.Defaults, etc.
2138 return true
2139 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002140
Jooyung Hana70f0672019-01-18 15:20:43 +09002141 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2142 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002143 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002144
2145 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002146 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002147 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002148 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002149
Jooyung Han0302a842019-10-30 18:43:49 +09002150 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002151 return false
2152 }
2153
2154 var stringPath []string
2155 for _, m := range ctx.GetWalkPath() {
2156 stringPath = append(stringPath, m.Name())
2157 }
2158 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2159 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2160 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2161 return false
2162 }
2163 if module, ok := ctx.Module().(*Module); ok {
2164 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002165 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002166 ctx.WalkDeps(check)
2167 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002168 }
2169 }
2170}
2171
Colin Cross0de8a1e2020-09-18 14:15:30 -07002172// Returns the highest version which is <= maxSdkVersion.
2173// For example, with maxSdkVersion is 10 and versionList is [9,11]
2174// it returns 9 as string. The list of stubs must be in order from
2175// oldest to newest.
2176func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedLibraryStubsInfo,
2177 maxSdkVersion android.ApiLevel) (SharedLibraryStubsInfo, error) {
2178
2179 for i := range stubsInfo {
2180 stubInfo := stubsInfo[len(stubsInfo)-i-1]
2181 var ver android.ApiLevel
2182 if stubInfo.Version == "" {
2183 ver = android.FutureApiLevel
2184 } else {
2185 var err error
2186 ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
2187 if err != nil {
2188 return SharedLibraryStubsInfo{}, err
2189 }
2190 }
2191 if ver.LessThanOrEqualTo(maxSdkVersion) {
2192 return stubInfo, nil
2193 }
2194 }
2195 var versionList []string
2196 for _, stubInfo := range stubsInfo {
2197 versionList = append(versionList, stubInfo.Version)
2198 }
2199 return SharedLibraryStubsInfo{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
2200}
2201
Colin Crossc99deeb2016-04-11 15:06:20 -07002202// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002203func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002204 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002205
Colin Cross0de8a1e2020-09-18 14:15:30 -07002206 var directStaticDeps []StaticLibraryInfo
2207 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07002208
Colin Cross0de8a1e2020-09-18 14:15:30 -07002209 reexportExporter := func(exporter FlagExporterInfo) {
2210 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
2211 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
2212 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
2213 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
2214 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09002215 }
2216
Jooyung Hande34d232020-07-23 13:04:15 +09002217 // For the dependency from platform to apex, use the latest stubs
2218 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002219 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2220 if !apexInfo.IsForPlatform() {
2221 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002222 }
2223
2224 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2225 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2226 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2227 // (b/144430859)
2228 c.apexSdkVersion = android.FutureApiLevel
2229 }
2230
Colin Crossd11fcda2017-10-23 17:59:01 -07002231 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002232 depName := ctx.OtherModuleName(dep)
2233 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002234
Ivan Lozano52767be2019-10-18 14:49:46 -07002235 ccDep, ok := dep.(LinkableInterface)
2236 if !ok {
2237
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002238 // handling for a few module types that aren't cc Module but that are also supported
2239 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002240 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002241 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002242 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2243 genRule.GeneratedSourceFiles()...)
2244 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002245 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002246 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002247 // Support exported headers from a generated_sources dependency
2248 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002249 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002250 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002251 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002252 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002253 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002254 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002255 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002256 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002257 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2258 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002259 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002260 // 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 +09002261 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002262
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002263 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002264 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002265 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002266 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002267 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002268 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002269 files := genRule.GeneratedSourceFiles()
2270 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002271 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002272 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002273 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 -07002274 }
2275 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002276 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002277 }
Colin Crossca860ac2016-01-04 14:34:37 -08002278 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002279 return
2280 }
2281
Colin Crossfe17f6f2019-03-28 19:30:56 -07002282 if depTag == android.ProtoPluginDepTag {
2283 return
2284 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002285 if depTag == llndkImplDep {
2286 return
2287 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002288
Colin Crossd11fcda2017-10-23 17:59:01 -07002289 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002290 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2291 return
2292 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002293 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002294 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2295 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002296 return
2297 }
2298
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002299 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002300 // reusing objects only make sense for cc.Modules.
Colin Cross0de8a1e2020-09-18 14:15:30 -07002301 staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2302 objs := staticAnalogue.ReuseObjects
2303 depPaths.Objs = depPaths.Objs.Append(objs)
2304 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
2305 reexportExporter(depExporterInfo)
2306 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09002307 }
2308
Colin Cross6e511a92020-07-27 21:26:48 -07002309 checkLinkType(ctx, c, ccDep, depTag)
2310
2311 linkFile := ccDep.OutputFile()
2312
2313 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2314 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002315 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002316 return
2317 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002318
Colin Cross0de8a1e2020-09-18 14:15:30 -07002319 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
Colin Crossc99deeb2016-04-11 15:06:20 -07002320
Colin Cross6e511a92020-07-27 21:26:48 -07002321 var ptr *android.Paths
2322 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002323
Colin Cross6e511a92020-07-27 21:26:48 -07002324 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002325
Colin Cross6e511a92020-07-27 21:26:48 -07002326 switch {
2327 case libDepTag.header():
2328 // nothing
2329 case libDepTag.shared():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002330 if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
2331 if !ctx.Config().AllowMissingDependencies() {
2332 ctx.ModuleErrorf("module %q is not a shared library", depName)
2333 } else {
2334 ctx.AddMissingDependencies([]string{depName})
2335 }
2336 return
2337 }
2338 sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
2339 sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryImplementationStubsInfoProvider).(SharedLibraryImplementationStubsInfo)
2340
2341 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedLibraryStubsInfos) > 0 {
2342 useStubs := false
2343 if m, ok := ccDep.(*Module); ok && m.IsStubs() && c.UseVndk() { // LLNDK
2344 if !apexInfo.IsForPlatform() {
2345 // For platform libraries, use current version of LLNDK
2346 // If this is for use_vendor apex we will apply the same rules
2347 // of apex sdk enforcement below to choose right version.
2348 useStubs = true
2349 }
2350 } else if apexInfo.IsForPlatform() {
2351 // If not building for APEX, use stubs only when it is from
2352 // an APEX (and not from platform)
2353 // However, for host, ramdisk, recovery or bootstrap modules,
2354 // always link to non-stub variant
2355 useStubs = dep.(android.ApexModule).AnyVariantDirectlyInAnyApex() && !c.bootstrap()
2356 // Another exception: if this module is bundled with an APEX, then
2357 // it is linked with the non-stub variant of a module in the APEX
2358 // as if this is part of the APEX.
2359 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2360 for _, apexContents := range testFor.ApexContents {
2361 if apexContents.DirectlyInApex(depName) {
2362 useStubs = false
2363 break
2364 }
2365 }
2366 } else {
2367 // If building for APEX, use stubs when the parent is in any APEX that
2368 // the child is not in.
2369 useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
2370 }
2371
2372 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2373 if useStubs {
2374 sharedLibraryStubsInfo, err :=
2375 c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedLibraryStubsInfos, c.apexSdkVersion)
2376 if err != nil {
2377 ctx.OtherModuleErrorf(dep, err.Error())
2378 return
2379 }
2380 sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
2381 depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
2382 }
2383 }
2384
2385 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
2386 depFile = sharedLibraryInfo.TableOfContents
2387
Colin Cross6e511a92020-07-27 21:26:48 -07002388 ptr = &depPaths.SharedLibs
2389 switch libDepTag.Order {
2390 case earlyLibraryDependency:
2391 ptr = &depPaths.EarlySharedLibs
2392 depPtr = &depPaths.EarlySharedLibsDeps
2393 case normalLibraryDependency:
2394 ptr = &depPaths.SharedLibs
2395 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07002396 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002397 case lateLibraryDependency:
2398 ptr = &depPaths.LateSharedLibs
2399 depPtr = &depPaths.LateSharedLibsDeps
2400 default:
2401 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002402 }
Colin Cross6e511a92020-07-27 21:26:48 -07002403 case libDepTag.static():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002404 if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
2405 if !ctx.Config().AllowMissingDependencies() {
2406 ctx.ModuleErrorf("module %q is not a static library", depName)
2407 } else {
2408 ctx.AddMissingDependencies([]string{depName})
2409 }
2410 return
2411 }
2412 staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2413 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
Colin Cross6e511a92020-07-27 21:26:48 -07002414 if libDepTag.wholeStatic {
2415 ptr = &depPaths.WholeStaticLibs
Colin Cross0de8a1e2020-09-18 14:15:30 -07002416 if len(staticLibraryInfo.Objects.objFiles) > 0 {
2417 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
Inseob Kimeec88e12020-01-22 11:11:29 +09002418 } else {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002419 // This case normally catches prebuilt static
2420 // libraries, but it can also occur when
2421 // AllowMissingDependencies is on and the
2422 // dependencies has no sources of its own
2423 // but has a whole_static_libs dependency
2424 // on a missing library. We want to depend
2425 // on the .a file so that there is something
2426 // in the dependency tree that contains the
2427 // error rule for the missing transitive
2428 // dependency.
2429 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002430 }
Colin Cross6e511a92020-07-27 21:26:48 -07002431 } else {
2432 switch libDepTag.Order {
2433 case earlyLibraryDependency:
2434 panic(fmt.Errorf("early static libs not suppported"))
2435 case normalLibraryDependency:
2436 // static dependencies will be handled separately so they can be ordered
2437 // using transitive dependencies.
2438 ptr = nil
Colin Cross0de8a1e2020-09-18 14:15:30 -07002439 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002440 case lateLibraryDependency:
2441 ptr = &depPaths.LateStaticLibs
2442 default:
2443 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002444 }
2445 }
2446 }
2447
Colin Cross6e511a92020-07-27 21:26:48 -07002448 if libDepTag.static() && !libDepTag.wholeStatic {
2449 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2450 ctx.ModuleErrorf("module %q not a static library", depName)
2451 return
2452 }
Logan Chien43d34c32017-12-20 01:17:32 +08002453
Colin Cross6e511a92020-07-27 21:26:48 -07002454 // When combining coverage files for shared libraries and executables, coverage files
2455 // in static libraries act as if they were whole static libraries. The same goes for
2456 // source based Abi dump files.
2457 if c, ok := ccDep.(*Module); ok {
2458 staticLib := c.linker.(libraryInterface)
2459 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2460 staticLib.objs().coverageFiles...)
2461 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2462 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002463 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002464 // Handle non-CC modules here
2465 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002466 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002467 }
2468 }
2469
Colin Cross6e511a92020-07-27 21:26:48 -07002470 if ptr != nil {
2471 if !linkFile.Valid() {
2472 if !ctx.Config().AllowMissingDependencies() {
2473 ctx.ModuleErrorf("module %q missing output file", depName)
2474 } else {
2475 ctx.AddMissingDependencies([]string{depName})
2476 }
2477 return
2478 }
2479 *ptr = append(*ptr, linkFile.Path())
2480 }
2481
2482 if depPtr != nil {
2483 dep := depFile
2484 if !dep.Valid() {
2485 dep = linkFile
2486 }
2487 *depPtr = append(*depPtr, dep.Path())
2488 }
2489
Colin Cross0de8a1e2020-09-18 14:15:30 -07002490 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
2491 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
2492 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
2493 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
2494
2495 if libDepTag.reexportFlags {
2496 reexportExporter(depExporterInfo)
2497 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2498 // Re-exported shared library headers must be included as well since they can help us with type information
2499 // about template instantiations (instantiated from their headers).
2500 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2501 // scripts.
2502 c.sabi.Properties.ReexportedIncludes = append(
2503 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
2504 }
2505
Colin Cross6e511a92020-07-27 21:26:48 -07002506 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2507 switch {
2508 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002509 c.Properties.AndroidMkHeaderLibs = append(
2510 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002511 case libDepTag.shared():
2512 if ccDep.CcLibrary() {
Colin Cross56a83212020-09-15 18:30:11 -07002513 if ccDep.BuildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002514 // Add the dependency to the APEX(es) providing the library so that
2515 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002516 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2517 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002518 c.Properties.ApexesProvidingSharedLibs = append(
2519 c.Properties.ApexesProvidingSharedLibs, an)
2520 }
2521 }
2522 }
2523
2524 // Note: the order of libs in this list is not important because
2525 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002526 c.Properties.AndroidMkSharedLibs = append(
2527 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002528 // Record baseLibName for snapshots.
2529 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2530 case libDepTag.static():
2531 if libDepTag.wholeStatic {
2532 c.Properties.AndroidMkWholeStaticLibs = append(
2533 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2534 } else {
2535 c.Properties.AndroidMkStaticLibs = append(
2536 c.Properties.AndroidMkStaticLibs, makeLibName)
2537 }
2538 }
2539 } else {
2540 switch depTag {
2541 case runtimeDepTag:
2542 c.Properties.AndroidMkRuntimeLibs = append(
2543 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2544 // Record baseLibName for snapshots.
2545 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2546 case objDepTag:
2547 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2548 case CrtBeginDepTag:
2549 depPaths.CrtBegin = linkFile
2550 case CrtEndDepTag:
2551 depPaths.CrtEnd = linkFile
2552 case dynamicLinkerDepTag:
2553 depPaths.DynamicLinker = linkFile
2554 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002555 }
Colin Crossca860ac2016-01-04 14:34:37 -08002556 })
2557
Jeff Gaston294356f2017-09-27 17:05:30 -07002558 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07002559 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
2560 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
2561 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002562
Colin Crossdd84e052017-05-17 13:44:16 -07002563 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002564 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002565 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2566 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002567 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002568 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2569 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002570 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002571 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002572 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002573
2574 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002575 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002576 }
Colin Crossdd84e052017-05-17 13:44:16 -07002577
Colin Crossca860ac2016-01-04 14:34:37 -08002578 return depPaths
2579}
2580
Colin Cross0de8a1e2020-09-18 14:15:30 -07002581// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
2582// to match the topological order of the dependency tree, including any static analogues of
2583// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
2584// of the transitive dependencies.
2585func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
2586 transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
2587 var staticPaths android.Paths
2588 for _, staticDep := range staticDeps {
2589 staticPaths = append(staticPaths, staticDep.StaticLibrary)
2590 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
2591 }
2592 for _, sharedDep := range sharedDeps {
2593 if sharedDep.StaticAnalogue != nil {
2594 transitiveStaticLibsBuilder.Transitive(sharedDep.StaticAnalogue.TransitiveStaticLibrariesForOrdering)
2595 }
2596 }
2597 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
2598
2599 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
2600
2601 // reorder the dependencies based on transitive dependencies
2602 staticPaths = android.FirstUniquePaths(staticPaths)
2603 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
2604
2605 if len(orderedStaticPaths) != len(staticPaths) {
2606 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
2607 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
2608 }
2609
2610 return orderedStaticPaths, transitiveStaticLibs
2611}
2612
Colin Cross6e511a92020-07-27 21:26:48 -07002613// baseLibName trims known prefixes and suffixes
2614func baseLibName(depName string) string {
2615 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2616 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2617 libName = strings.TrimPrefix(libName, "prebuilt_")
2618 return libName
2619}
2620
2621func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2622 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2623 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2624
2625 libName := baseLibName(depName)
2626 isLLndk := isLlndkLibrary(libName, ctx.Config())
2627 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2628 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2629
2630 if c, ok := ccDep.(*Module); ok {
2631 // Use base module name for snapshots when exporting to Makefile.
2632 if c.isSnapshotPrebuilt() {
2633 baseName := c.BaseModuleName()
2634
2635 if c.IsVndk() {
2636 return baseName + ".vendor"
2637 }
2638
2639 if vendorSuffixModules[baseName] {
2640 return baseName + ".vendor"
2641 } else {
2642 return baseName
2643 }
2644 }
2645 }
2646
2647 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2648 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2649 // core module instead.
2650 return libName
2651 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2652 // The vendor module in Make will have been renamed to not conflict with the core
2653 // module, so update the dependency name here accordingly.
2654 return libName + c.getNameSuffixWithVndkVersion(ctx)
2655 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2656 return libName + vendorPublicLibrarySuffix
2657 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2658 return libName + ramdiskSuffix
2659 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2660 return libName + recoverySuffix
2661 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2662 return libName + nativeBridgeSuffix
2663 } else {
2664 return libName
2665 }
2666}
2667
Colin Crossca860ac2016-01-04 14:34:37 -08002668func (c *Module) InstallInData() bool {
2669 if c.installer == nil {
2670 return false
2671 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002672 return c.installer.inData()
2673}
2674
2675func (c *Module) InstallInSanitizerDir() bool {
2676 if c.installer == nil {
2677 return false
2678 }
2679 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002680 return true
2681 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002682 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002683}
2684
Yifan Hong1b3348d2020-01-21 15:53:22 -08002685func (c *Module) InstallInRamdisk() bool {
2686 return c.InRamdisk()
2687}
2688
Jiyong Parkf9332f12018-02-01 00:54:12 +09002689func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002690 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002691}
2692
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002693func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002694 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002695 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002696 return
2697 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002698 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002699}
2700
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002701func (c *Module) HostToolPath() android.OptionalPath {
2702 if c.installer == nil {
2703 return android.OptionalPath{}
2704 }
2705 return c.installer.hostToolPath()
2706}
2707
Nan Zhangd4e641b2017-07-12 12:55:28 -07002708func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2709 return c.outputFile
2710}
2711
Colin Cross41955e82019-05-29 14:40:35 -07002712func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2713 switch tag {
2714 case "":
2715 if c.outputFile.Valid() {
2716 return android.Paths{c.outputFile.Path()}, nil
2717 }
2718 return android.Paths{}, nil
2719 default:
2720 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002721 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002722}
2723
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002724func (c *Module) static() bool {
2725 if static, ok := c.linker.(interface {
2726 static() bool
2727 }); ok {
2728 return static.static()
2729 }
2730 return false
2731}
2732
Jiyong Park379de2f2018-12-19 02:47:14 +09002733func (c *Module) staticBinary() bool {
2734 if static, ok := c.linker.(interface {
2735 staticBinary() bool
2736 }); ok {
2737 return static.staticBinary()
2738 }
2739 return false
2740}
2741
Jiyong Park1d1119f2019-07-29 21:27:18 +09002742func (c *Module) header() bool {
2743 if h, ok := c.linker.(interface {
2744 header() bool
2745 }); ok {
2746 return h.header()
2747 }
2748 return false
2749}
2750
Inseob Kim7f283f42020-06-01 21:53:49 +09002751func (c *Module) binary() bool {
2752 if b, ok := c.linker.(interface {
2753 binary() bool
2754 }); ok {
2755 return b.binary()
2756 }
2757 return false
2758}
2759
Inseob Kim1042d292020-06-01 23:23:05 +09002760func (c *Module) object() bool {
2761 if o, ok := c.linker.(interface {
2762 object() bool
2763 }); ok {
2764 return o.object()
2765 }
2766 return false
2767}
2768
Jooyung Han38002912019-05-16 04:01:54 +09002769func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002770 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002771 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2772 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002773 return "native:vndk"
2774 }
Jooyung Han38002912019-05-16 04:01:54 +09002775 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002776 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002777 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002778 if Bool(c.VendorProperties.Vendor_available) {
2779 return "native:vndk"
2780 }
2781 return "native:vndk_private"
2782 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002783 if c.inProduct() {
2784 return "native:product"
2785 }
Jooyung Han38002912019-05-16 04:01:54 +09002786 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002787 } else if c.InRamdisk() {
2788 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002789 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002790 return "native:recovery"
2791 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2792 return "native:ndk:none:none"
2793 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2794 //family, link := getNdkStlFamilyAndLinkType(c)
2795 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002796 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002797 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002798 } else {
2799 return "native:platform"
2800 }
2801}
2802
Jiyong Park9d452992018-10-03 00:38:19 +09002803// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002804// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002805func (c *Module) IsInstallableToApex() bool {
2806 if shared, ok := c.linker.(interface {
2807 shared() bool
2808 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002809 // Stub libs and prebuilt libs in a versioned SDK are not
2810 // installable to APEX even though they are shared libs.
2811 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002812 } else if _, ok := c.linker.(testPerSrc); ok {
2813 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002814 }
2815 return false
2816}
2817
Jiyong Parka90ca002019-10-07 15:47:24 +09002818func (c *Module) AvailableFor(what string) bool {
2819 if linker, ok := c.linker.(interface {
2820 availableFor(string) bool
2821 }); ok {
2822 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2823 } else {
2824 return c.ApexModuleBase.AvailableFor(what)
2825 }
2826}
2827
Jiyong Park62304bb2020-04-13 16:19:48 +09002828func (c *Module) TestFor() []string {
2829 if test, ok := c.linker.(interface {
2830 testFor() []string
2831 }); ok {
2832 return test.testFor()
2833 } else {
2834 return c.ApexModuleBase.TestFor()
2835 }
2836}
2837
Colin Crossaede88c2020-08-11 12:17:01 -07002838func (c *Module) UniqueApexVariations() bool {
2839 if u, ok := c.compiler.(interface {
2840 uniqueApexVariations() bool
2841 }); ok {
2842 return u.uniqueApexVariations()
2843 } else {
2844 return false
2845 }
2846}
2847
Paul Duffin0cb37b92020-03-04 14:52:46 +00002848// Return true if the module is ever installable.
2849func (c *Module) EverInstallable() bool {
2850 return c.installer != nil &&
2851 // Check to see whether the module is actually ever installable.
2852 c.installer.everInstallable()
2853}
2854
Colin Cross56a83212020-09-15 18:30:11 -07002855func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002856 ret := c.EverInstallable() &&
2857 // Check to see whether the module has been configured to not be installed.
2858 proptools.BoolDefault(c.Properties.Installable, true) &&
2859 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002860
2861 // The platform variant doesn't need further condition. Apex variants however might not
2862 // be installable because it will likely to be included in the APEX and won't appear
2863 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07002864 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002865 return ret
2866 }
2867
2868 // Special case for modules that are configured to be installed to /data, which includes
2869 // test modules. For these modules, both APEX and non-APEX variants are considered as
2870 // installable. This is because even the APEX variants won't be included in the APEX, but
2871 // will anyway be installed to /data/*.
2872 // See b/146995717
2873 if c.InstallInData() {
2874 return ret
2875 }
2876
2877 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002878}
2879
Logan Chien41eabe62019-04-10 13:33:58 +08002880func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2881 if c.linker != nil {
2882 if library, ok := c.linker.(*libraryDecorator); ok {
2883 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2884 }
2885 }
2886}
2887
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002888func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002889 depTag := ctx.OtherModuleDependencyTag(dep)
2890 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2891
2892 if cc, ok := dep.(*Module); ok {
2893 if cc.HasStubsVariants() {
2894 if isLibDepTag && libDepTag.shared() {
2895 // dynamic dep to a stubs lib crosses APEX boundary
2896 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002897 }
Colin Cross6e511a92020-07-27 21:26:48 -07002898 if IsRuntimeDepTag(depTag) {
2899 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002900 return false
2901 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002902 }
Colin Crossaac32222020-07-29 12:51:56 -07002903 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002904 // shared_lib dependency from a static lib is considered as crossing
2905 // the APEX boundary because the dependency doesn't actually is
2906 // linked; the dependency is used only during the compilation phase.
2907 return false
2908 }
2909 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07002910 if depTag == stubImplDepTag || depTag == llndkImplDep {
2911 // We don't track beyond LLNDK or from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09002912 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002913 }
2914 return true
2915}
2916
Dan Albertc8060532020-07-22 22:32:17 -07002917func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
2918 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09002919 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
2920 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
2921 return nil
2922 }
2923 // b/154569636: set min_sdk_version correctly for toolchain_libraries
2924 if c.ToolchainLibrary() {
2925 return nil
2926 }
2927 // We don't check for prebuilt modules
2928 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
2929 return nil
2930 }
2931 minSdkVersion := c.MinSdkVersion()
2932 if minSdkVersion == "apex_inherit" {
2933 return nil
2934 }
2935 if minSdkVersion == "" {
2936 // JNI libs within APK-in-APEX fall into here
2937 // Those are okay to set sdk_version instead
2938 // We don't have to check if this is a SDK variant because
2939 // non-SDK variant resets sdk_version, which works too.
2940 minSdkVersion = c.SdkVersion()
2941 }
Dan Albertc8060532020-07-22 22:32:17 -07002942 if minSdkVersion == "" {
2943 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
2944 }
2945 // Not using nativeApiLevelFromUser because the context here is not
2946 // necessarily a native context.
2947 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09002948 if err != nil {
2949 return err
2950 }
Dan Albertc8060532020-07-22 22:32:17 -07002951
2952 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09002953 return fmt.Errorf("newer SDK(%v)", ver)
2954 }
2955 return nil
2956}
2957
Colin Cross2ba19d92015-05-07 15:44:20 -07002958//
Colin Crosscfad1192015-11-02 16:43:11 -08002959// Defaults
2960//
Colin Crossca860ac2016-01-04 14:34:37 -08002961type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002962 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002963 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002964 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002965}
2966
Patrice Arrudac249c712019-03-19 17:00:29 -07002967// cc_defaults provides a set of properties that can be inherited by other cc
2968// modules. A module can use the properties from a cc_defaults using
2969// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2970// merged (when possible) by prepending the default module's values to the
2971// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002972func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002973 return DefaultsFactory()
2974}
2975
Colin Cross36242852017-06-23 15:06:31 -07002976func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002977 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002978
Colin Cross36242852017-06-23 15:06:31 -07002979 module.AddProperties(props...)
2980 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002981 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002982 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002983 &BaseCompilerProperties{},
2984 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002985 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002986 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002987 &StaticProperties{},
2988 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002989 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002990 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002991 &TestProperties{},
2992 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07002993 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002994 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002995 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002996 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002997 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002998 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002999 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003000 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003001 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003002 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003003 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003004 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003005 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003006 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3007 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003008 )
Colin Crosscfad1192015-11-02 16:43:11 -08003009
Jooyung Hancc372c52019-09-25 15:18:44 +09003010 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003011
3012 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003013}
3014
Jiyong Park6a43f042017-10-12 23:05:00 +09003015func squashVendorSrcs(m *Module) {
3016 if lib, ok := m.compiler.(*libraryDecorator); ok {
3017 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3018 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3019
3020 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3021 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003022
3023 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3024 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003025 }
3026}
3027
Jiyong Parkf9332f12018-02-01 00:54:12 +09003028func squashRecoverySrcs(m *Module) {
3029 if lib, ok := m.compiler.(*libraryDecorator); ok {
3030 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3031 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3032
3033 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3034 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003035
3036 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3037 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003038 }
3039}
3040
Jiyong Park2286afd2020-06-16 21:58:53 +09003041func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003042 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003043}
3044
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003045func kytheExtractAllFactory() android.Singleton {
3046 return &kytheExtractAllSingleton{}
3047}
3048
3049type kytheExtractAllSingleton struct {
3050}
3051
3052func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3053 var xrefTargets android.Paths
3054 ctx.VisitAllModules(func(module android.Module) {
3055 if ccModule, ok := module.(xref); ok {
3056 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3057 }
3058 })
3059 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3060 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003061 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003062 }
3063}
3064
Colin Cross06a931b2015-10-28 17:23:31 -07003065var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003066var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003067var BoolPtr = proptools.BoolPtr
3068var String = proptools.String
3069var StringPtr = proptools.StringPtr