blob: 94512d53d661629ab30edb229169895e803521ef [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070051 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090052 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090053 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
54 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070055 })
Colin Cross16b23492016-01-06 14:41:07 -080056
Paul Duffin036e7002019-12-19 19:16:28 +000057 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070058 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
59 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080060
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070061 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
62 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
63
Mitch Phillipsbfeade62019-05-01 14:42:05 -070064 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
65 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
66
Jiyong Park1d1119f2019-07-29 21:27:18 +090067 // cfi mutator shouldn't run before sanitizers that return true for
68 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000069 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
70 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
71
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080072 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
73 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
74
Colin Cross1e676be2016-10-12 14:38:15 -070075 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
76 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080077
Colin Cross0b908332019-06-19 23:00:20 -070078 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090079 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080080
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080081 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080082 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070083
84 ctx.TopDown("lto_deps", ltoDepsMutator)
85 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090086
87 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070088 })
Colin Crossb98c8b02016-07-29 13:44:28 -070089
Sasha Smundak2a4549e2018-11-05 16:49:08 -080090 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070091}
92
Colin Crossca860ac2016-01-04 14:34:37 -080093type Deps struct {
94 SharedLibs, LateSharedLibs []string
95 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080096 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080097 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070098
Peter Collingbournedc4f9862020-02-12 17:13:25 -080099 StaticUnwinderIfLegacy bool
100
Colin Cross5950f382016-12-13 12:50:57 -0800101 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700102
Colin Cross81413472016-04-11 14:37:39 -0700103 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Dan Willemsenb40aab62016-04-20 14:21:14 -0700105 GeneratedSources []string
106 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900107 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700108
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700109 ReexportGeneratedHeaders []string
110
Colin Cross97ba0732015-03-23 17:50:24 -0700111 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700112
113 // Used for host bionic
114 LinkerFlagsFile string
115 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700116}
117
Colin Crossca860ac2016-01-04 14:34:37 -0800118type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700119 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900120 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900122 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700123 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700124 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100127 Objs Objects
128 // Paths to .o files in dependencies that provide them. Note that these lists
129 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800130 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700131 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100133 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
134 // the libs from all whole_static_lib dependencies.
135 WholeStaticLibsFromPrebuilts android.Paths
136
Colin Cross26c34ed2016-09-30 17:10:16 -0700137 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700138 GeneratedSources android.Paths
139 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900140 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700141
Inseob Kimd110f872019-12-06 13:15:38 +0900142 Flags []string
143 IncludeDirs android.Paths
144 SystemIncludeDirs android.Paths
145 ReexportedDirs android.Paths
146 ReexportedSystemDirs android.Paths
147 ReexportedFlags []string
148 ReexportedGeneratedHeaders android.Paths
149 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700150
Colin Cross26c34ed2016-09-30 17:10:16 -0700151 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700152 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700153
154 // Path to the file container flags to use with the linker
155 LinkerFlagsFile android.OptionalPath
156
157 // Path to the dynamic linker binary
158 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700159}
160
Colin Cross4af21ed2019-11-04 09:37:55 -0800161// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
162// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
163// command line so they can be overridden by the local module flags).
164type LocalOrGlobalFlags struct {
165 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700166 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800167 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700168 CFlags []string // Flags that apply to C and C++ source files
169 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
170 ConlyFlags []string // Flags that apply to C source files
171 CppFlags []string // Flags that apply to C++ source files
172 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700173 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800174}
175
176type Flags struct {
177 Local LocalOrGlobalFlags
178 Global LocalOrGlobalFlags
179
180 aidlFlags []string // Flags that apply to aidl source files
181 rsFlags []string // Flags that apply to renderscript source files
182 libFlags []string // Flags to add libraries early to the link order
183 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
184 TidyFlags []string // Flags that apply to clang-tidy
185 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700186
Colin Crossc3199482017-03-30 15:03:04 -0700187 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800188 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700189 SystemIncludeFlags []string
190
Oliver Nguyen04526782020-04-21 12:40:27 -0700191 Toolchain config.Toolchain
192 Tidy bool
193 GcovCoverage bool
194 SAbiDump bool
195 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800196
197 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800198 DynamicLinker string
199
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700200 CFlagsDeps android.Paths // Files depended on by compiler flags
201 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800202
Dan Willemsen98ab3112019-08-27 21:20:40 -0700203 AssemblerWithCpp bool
204 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800205
Colin Cross19878da2019-03-28 14:45:07 -0700206 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700207 protoC bool // Whether to use C instead of C++
208 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700209
210 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700211}
212
Colin Crossca860ac2016-01-04 14:34:37 -0800213// Properties used to compile all C or C++ modules
214type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700215 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800216 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700217
Colin Crossc511bc52020-04-07 16:50:32 +0000218 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
219 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800220 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700221
Jooyung Han379660c2020-04-21 15:24:00 +0900222 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
223 Min_sdk_version *string
224
Colin Crossc511bc52020-04-07 16:50:32 +0000225 // If true, always create an sdk variant and don't create a platform variant.
226 Sdk_variant_only *bool
227
Jiyong Parkde866cb2018-12-07 23:08:36 +0900228 AndroidMkSharedLibs []string `blueprint:"mutated"`
229 AndroidMkStaticLibs []string `blueprint:"mutated"`
230 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
231 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700232 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900233 HideFromMake bool `blueprint:"mutated"`
234 PreventInstall bool `blueprint:"mutated"`
235 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700236
Justin Yun5f7f7e82019-11-18 19:52:14 +0900237 ImageVariationPrefix string `blueprint:"mutated"`
238 VndkVersion string `blueprint:"mutated"`
239 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800240
241 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
242 // file
243 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900244
Yifan Hong1b3348d2020-01-21 15:53:22 -0800245 // Make this module available when building for ramdisk
246 Ramdisk_available *bool
247
Jiyong Parkf9332f12018-02-01 00:54:12 +0900248 // Make this module available when building for recovery
249 Recovery_available *bool
250
Colin Crossae6c5202019-11-20 13:35:50 -0800251 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800252 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800253 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800254 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900255 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900256
257 // Allows this module to use non-APEX version of libraries. Useful
258 // for building binaries that are started before APEXes are activated.
259 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900260
261 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
262 // see soong/cc/config/vndk.go
263 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900264
265 // Used by vendor snapshot to record dependencies from snapshot modules.
266 SnapshotSharedLibs []string `blueprint:"mutated"`
267 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000268
269 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000270
271 // Set by factories of module types that can only be referenced from variants compiled against
272 // the SDK.
273 AlwaysSdk bool `blueprint:"mutated"`
274
275 // Variant is an SDK variant created by sdkMutator
276 IsSdkVariant bool `blueprint:"mutated"`
277 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
278 // variant to have a ".sdk" suffix.
279 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700280}
281
282type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900283 // whether this module should be allowed to be directly depended by other
284 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900285 // In addition, this module should be allowed to be directly depended by
286 // product modules with `product_specific: true`.
287 // If set to true, three variants will be built separately, one like
288 // normal, another limited to the set of libraries and headers
289 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700290 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900291 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700292 // so it shouldn't have any unversioned runtime dependencies, or
293 // make assumptions about the system that may not be true in the
294 // future.
295 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900296 // If set to false, this module becomes inaccessible from /vendor or /product
297 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900298 //
299 // Default value is true when vndk: {enabled: true} or vendor: true.
300 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700301 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900302 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700303 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900304
305 // whether this module is capable of being loaded with other instance
306 // (possibly an older version) of the same module in the same process.
307 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
308 // can be double loaded in a vendor process if the library is also a
309 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
310 // explicitly marked as `double_loadable: true` by the owner, or the dependency
311 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
312 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800313}
314
Colin Crossca860ac2016-01-04 14:34:37 -0800315type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800316 static() bool
317 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900318 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700319 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900320 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700321 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800322 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700323 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800324 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900325 isLlndk(config android.Config) bool
326 isLlndkPublic(config android.Config) bool
327 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900328 isVndk() bool
329 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800330 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900331 inProduct() bool
332 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800333 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900334 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800335 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700336 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700337 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800338 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800339 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800340 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800341 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800342 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900343 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900344 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900345 hasStubsVariants() bool
346 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900347 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800348 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700349 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800350}
351
352type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700353 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800354 ModuleContextIntf
355}
356
357type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700358 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800359 ModuleContextIntf
360}
361
Colin Cross37047f12016-12-13 17:06:13 -0800362type DepsContext interface {
363 android.BottomUpMutatorContext
364 ModuleContextIntf
365}
366
Colin Crossca860ac2016-01-04 14:34:37 -0800367type feature interface {
368 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800369 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800370 flags(ctx ModuleContext, flags Flags) Flags
371 props() []interface{}
372}
373
374type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700375 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800376 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800377 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700378 compilerProps() []interface{}
379
Colin Cross76fada02016-07-27 10:31:13 -0700380 appendCflags([]string)
381 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700382 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800383}
384
385type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700386 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800387 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700388 linkerFlags(ctx ModuleContext, flags Flags) Flags
389 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800390 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700391
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700392 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700393 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900394 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700395
396 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900397 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000398
399 // Get the deps that have been explicitly specified in the properties.
400 // Only updates the
401 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
402}
403
404type specifiedDeps struct {
405 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000406 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800407}
408
409type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700410 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700411 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000412 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800413 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700414 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700415 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900416 relativeInstallPath() string
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100417 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800418}
419
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800420type xref interface {
421 XrefCcFiles() android.Paths
422}
423
Colin Crossc99deeb2016-04-11 15:06:20 -0700424var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700425 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
426 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
427 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
428 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
429 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800430 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700431 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
432 headerDepTag = DependencyTag{Name: "header", Library: true}
433 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
434 genSourceDepTag = DependencyTag{Name: "gen source"}
435 genHeaderDepTag = DependencyTag{Name: "gen header"}
436 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
437 objDepTag = DependencyTag{Name: "obj"}
438 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
439 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
440 reuseObjTag = DependencyTag{Name: "reuse objects"}
441 staticVariantTag = DependencyTag{Name: "static variant"}
442 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
443 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
444 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
445 runtimeDepTag = DependencyTag{Name: "runtime lib"}
Ivan Lozano183a3212019-10-18 14:18:45 -0700446 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700447)
448
Roland Levillainf89cd092019-07-29 16:22:59 +0100449func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700450 ccDepTag, ok := depTag.(DependencyTag)
451 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100452}
453
454func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700455 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100456 return ok && ccDepTag == runtimeDepTag
457}
458
459func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700460 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100461 return ok && ccDepTag == testPerSrcDepTag
462}
463
Colin Crossca860ac2016-01-04 14:34:37 -0800464// Module contains the properties and members used by all C/C++ module types, and implements
465// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
466// to construct the output file. Behavior can be customized with a Customizer interface
467type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700468 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700469 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900470 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900471 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700472
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700473 Properties BaseProperties
474 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700475
Colin Crossca860ac2016-01-04 14:34:37 -0800476 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700477 hod android.HostOrDeviceSupported
478 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700479
Paul Duffina0843f62019-12-13 19:50:38 +0000480 // Allowable SdkMemberTypes of this module type.
481 sdkMemberTypes []android.SdkMemberType
482
Colin Crossca860ac2016-01-04 14:34:37 -0800483 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700484 features []feature
485 compiler compiler
486 linker linker
487 installer installer
488 stl *stl
489 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800490 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800491 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900492 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700493 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700494 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800495
Colin Cross635c3b02016-05-18 15:37:25 -0700496 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800497
Colin Crossb98c8b02016-07-29 13:44:28 -0700498 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700499
500 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800501
502 // Flags used to compile this module
503 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700504
505 // When calling a linker, if module A depends on module B, then A must precede B in its command
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800506 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700507 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800508 depsInLinkOrder android.Paths
509
510 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700511 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900512
513 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800514 // Kythe (source file indexer) paths for this compilation module
515 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900516
517 // For apex variants, this is set as apex.min_sdk_version
518 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700519}
520
Ivan Lozano52767be2019-10-18 14:49:46 -0700521func (c *Module) Toc() android.OptionalPath {
522 if c.linker != nil {
523 if library, ok := c.linker.(libraryInterface); ok {
524 return library.toc()
525 }
526 }
527 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
528}
529
530func (c *Module) ApiLevel() string {
531 if c.linker != nil {
532 if stub, ok := c.linker.(*stubDecorator); ok {
533 return stub.properties.ApiLevel
534 }
535 }
536 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
537}
538
539func (c *Module) Static() bool {
540 if c.linker != nil {
541 if library, ok := c.linker.(libraryInterface); ok {
542 return library.static()
543 }
544 }
545 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
546}
547
548func (c *Module) Shared() bool {
549 if c.linker != nil {
550 if library, ok := c.linker.(libraryInterface); ok {
551 return library.shared()
552 }
553 }
554 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
555}
556
557func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000558 if c.stl != nil {
559 return c.stl.Properties.SelectedStl
560 }
561 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700562}
563
564func (c *Module) ToolchainLibrary() bool {
565 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
566 return true
567 }
568 return false
569}
570
571func (c *Module) NdkPrebuiltStl() bool {
572 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
573 return true
574 }
575 return false
576}
577
578func (c *Module) StubDecorator() bool {
579 if _, ok := c.linker.(*stubDecorator); ok {
580 return true
581 }
582 return false
583}
584
585func (c *Module) SdkVersion() string {
586 return String(c.Properties.Sdk_version)
587}
588
Artur Satayev480e25b2020-04-27 18:53:18 +0100589func (c *Module) MinSdkVersion() string {
590 return String(c.Properties.Min_sdk_version)
591}
592
Colin Crossc511bc52020-04-07 16:50:32 +0000593func (c *Module) AlwaysSdk() bool {
594 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
595}
596
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800597func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700598 if c.linker != nil {
599 if library, ok := c.linker.(exportedFlagsProducer); ok {
600 return library.exportedDirs()
601 }
602 }
603 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
604}
605
606func (c *Module) HasStaticVariant() bool {
607 if c.staticVariant != nil {
608 return true
609 }
610 return false
611}
612
613func (c *Module) GetStaticVariant() LinkableInterface {
614 return c.staticVariant
615}
616
617func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
618 c.depsInLinkOrder = depsInLinkOrder
619}
620
621func (c *Module) GetDepsInLinkOrder() []android.Path {
622 return c.depsInLinkOrder
623}
624
625func (c *Module) StubsVersions() []string {
626 if c.linker != nil {
627 if library, ok := c.linker.(*libraryDecorator); ok {
628 return library.Properties.Stubs.Versions
629 }
630 }
631 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
632}
633
634func (c *Module) CcLibrary() bool {
635 if c.linker != nil {
636 if _, ok := c.linker.(*libraryDecorator); ok {
637 return true
638 }
639 }
640 return false
641}
642
643func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700644 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700645 return true
646 }
647 return false
648}
649
Ivan Lozano2b262972019-11-21 12:30:50 -0800650func (c *Module) NonCcVariants() bool {
651 return false
652}
653
Ivan Lozano183a3212019-10-18 14:18:45 -0700654func (c *Module) SetBuildStubs() {
655 if c.linker != nil {
656 if library, ok := c.linker.(*libraryDecorator); ok {
657 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700658 c.Properties.HideFromMake = true
659 c.sanitize = nil
660 c.stl = nil
661 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700662 return
663 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000664 if _, ok := c.linker.(*llndkStubDecorator); ok {
665 c.Properties.HideFromMake = true
666 return
667 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700668 }
669 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
670}
671
Ivan Lozano52767be2019-10-18 14:49:46 -0700672func (c *Module) BuildStubs() bool {
673 if c.linker != nil {
674 if library, ok := c.linker.(*libraryDecorator); ok {
675 return library.buildStubs()
676 }
677 }
678 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
679}
680
Ivan Lozano183a3212019-10-18 14:18:45 -0700681func (c *Module) SetStubsVersions(version string) {
682 if c.linker != nil {
683 if library, ok := c.linker.(*libraryDecorator); ok {
684 library.MutatedProperties.StubsVersion = version
685 return
686 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000687 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
688 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
689 return
690 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700691 }
692 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
693}
694
Jooyung Han03b51852020-02-26 22:45:42 +0900695func (c *Module) StubsVersion() string {
696 if c.linker != nil {
697 if library, ok := c.linker.(*libraryDecorator); ok {
698 return library.MutatedProperties.StubsVersion
699 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000700 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
701 return llndk.libraryDecorator.MutatedProperties.StubsVersion
702 }
Jooyung Han03b51852020-02-26 22:45:42 +0900703 }
704 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
705}
706
Ivan Lozano183a3212019-10-18 14:18:45 -0700707func (c *Module) SetStatic() {
708 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700709 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700710 library.setStatic()
711 return
712 }
713 }
714 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
715}
716
717func (c *Module) SetShared() {
718 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700719 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700720 library.setShared()
721 return
722 }
723 }
724 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
725}
726
727func (c *Module) BuildStaticVariant() bool {
728 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700729 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700730 return library.buildStatic()
731 }
732 }
733 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
734}
735
736func (c *Module) BuildSharedVariant() bool {
737 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700738 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700739 return library.buildShared()
740 }
741 }
742 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
743}
744
745func (c *Module) Module() android.Module {
746 return c
747}
748
Jiyong Parkc20eee32018-09-05 22:36:17 +0900749func (c *Module) OutputFile() android.OptionalPath {
750 return c.outputFile
751}
752
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400753func (c *Module) CoverageFiles() android.Paths {
754 if c.linker != nil {
755 if library, ok := c.linker.(libraryInterface); ok {
756 return library.objs().coverageFiles
757 }
758 }
759 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
760}
761
Ivan Lozano183a3212019-10-18 14:18:45 -0700762var _ LinkableInterface = (*Module)(nil)
763
Jiyong Park719b4462019-01-13 00:39:51 +0900764func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900765 if c.linker != nil {
766 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900767 }
768 return nil
769}
770
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900771func (c *Module) CoverageOutputFile() android.OptionalPath {
772 if c.linker != nil {
773 return c.linker.coverageOutputFilePath()
774 }
775 return android.OptionalPath{}
776}
777
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900778func (c *Module) RelativeInstallPath() string {
779 if c.installer != nil {
780 return c.installer.relativeInstallPath()
781 }
782 return ""
783}
784
Jooyung Han344d5432019-08-23 11:17:39 +0900785func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900786 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900787}
788
Colin Cross36242852017-06-23 15:06:31 -0700789func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700790 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800791 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700792 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800793 }
794 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700795 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800796 }
797 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700798 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800799 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700800 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700801 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700802 }
Colin Cross16b23492016-01-06 14:41:07 -0800803 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700804 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800805 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800806 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700807 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800808 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800809 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700810 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800811 }
Justin Yun8effde42017-06-23 19:24:43 +0900812 if c.vndkdep != nil {
813 c.AddProperties(c.vndkdep.props()...)
814 }
Stephen Craneba090d12017-05-09 15:44:35 -0700815 if c.lto != nil {
816 c.AddProperties(c.lto.props()...)
817 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700818 if c.pgo != nil {
819 c.AddProperties(c.pgo.props()...)
820 }
Colin Crossca860ac2016-01-04 14:34:37 -0800821 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700822 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800823 }
Colin Crossc472d572015-03-17 15:06:21 -0700824
Colin Crossa9d8bee2018-10-02 13:59:46 -0700825 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
826 switch class {
827 case android.Device:
828 return ctx.Config().DevicePrefer32BitExecutables()
829 case android.HostCross:
830 // Windows builds always prefer 32-bit
831 return true
832 default:
833 return false
834 }
835 })
Colin Cross36242852017-06-23 15:06:31 -0700836 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900837 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900838 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900839 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900840
Colin Cross36242852017-06-23 15:06:31 -0700841 return c
Colin Crossc472d572015-03-17 15:06:21 -0700842}
843
Colin Crossb916a382016-07-29 17:28:03 -0700844// Returns true for dependency roots (binaries)
845// TODO(ccross): also handle dlopenable libraries
846func (c *Module) isDependencyRoot() bool {
847 if root, ok := c.linker.(interface {
848 isDependencyRoot() bool
849 }); ok {
850 return root.isDependencyRoot()
851 }
852 return false
853}
854
Justin Yun5f7f7e82019-11-18 19:52:14 +0900855// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
856// "product" and "vendor" variant modules return true for this function.
857// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
858// "soc_specific: true" and more vendor installed modules are included here.
859// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
860// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700861func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900862 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700863}
864
Colin Crossc511bc52020-04-07 16:50:32 +0000865func (c *Module) canUseSdk() bool {
866 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
867}
868
869func (c *Module) UseSdk() bool {
870 if c.canUseSdk() {
871 return String(c.Properties.Sdk_version) != ""
872 }
873 return false
874}
875
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800876func (c *Module) isCoverageVariant() bool {
877 return c.coverage.Properties.IsCoverageVariant
878}
879
Peter Collingbournead84f972019-12-17 16:46:18 -0800880func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800881 return inList(c.Name(), ndkMigratedLibs)
882}
883
Inseob Kim9516ee92019-05-09 10:56:13 +0900884func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800885 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900886 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800887}
888
Inseob Kim9516ee92019-05-09 10:56:13 +0900889func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800890 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900891 name := c.BaseModuleName()
892 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800893}
894
Inseob Kim9516ee92019-05-09 10:56:13 +0900895func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800896 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900897 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800898}
899
Ivan Lozano52767be2019-10-18 14:49:46 -0700900func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800901 if vndkdep := c.vndkdep; vndkdep != nil {
902 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900903 }
904 return false
905}
906
Yi Kong7e53c572018-02-14 18:16:12 +0800907func (c *Module) isPgoCompile() bool {
908 if pgo := c.pgo; pgo != nil {
909 return pgo.Properties.PgoCompile
910 }
911 return false
912}
913
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800914func (c *Module) isNDKStubLibrary() bool {
915 if _, ok := c.compiler.(*stubDecorator); ok {
916 return true
917 }
918 return false
919}
920
Logan Chienf3511742017-10-31 18:04:35 +0800921func (c *Module) isVndkSp() bool {
922 if vndkdep := c.vndkdep; vndkdep != nil {
923 return vndkdep.isVndkSp()
924 }
925 return false
926}
927
928func (c *Module) isVndkExt() bool {
929 if vndkdep := c.vndkdep; vndkdep != nil {
930 return vndkdep.isVndkExt()
931 }
932 return false
933}
934
Ivan Lozano52767be2019-10-18 14:49:46 -0700935func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900936 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800937}
938
Logan Chienf3511742017-10-31 18:04:35 +0800939func (c *Module) getVndkExtendsModuleName() string {
940 if vndkdep := c.vndkdep; vndkdep != nil {
941 return vndkdep.getVndkExtendsModuleName()
942 }
943 return ""
944}
945
Justin Yun5f7f7e82019-11-18 19:52:14 +0900946// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900947// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700948func (c *Module) HasVendorVariant() bool {
949 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900950}
951
Justin Yun5f7f7e82019-11-18 19:52:14 +0900952const (
953 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
954 // against the VNDK.
955 VendorVariationPrefix = "vendor."
956
957 // ProductVariationPrefix is the variant prefix used for /product code that compiles
958 // against the VNDK.
959 ProductVariationPrefix = "product."
960)
961
962// Returns true if the module is "product" variant. Usually these modules are installed in /product
963func (c *Module) inProduct() bool {
964 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
965}
966
967// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
968func (c *Module) inVendor() bool {
969 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
970}
971
Yifan Hong1b3348d2020-01-21 15:53:22 -0800972func (c *Module) InRamdisk() bool {
973 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
974}
975
Ivan Lozano52767be2019-10-18 14:49:46 -0700976func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800977 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900978}
979
Yifan Hong1b3348d2020-01-21 15:53:22 -0800980func (c *Module) OnlyInRamdisk() bool {
981 return c.ModuleBase.InstallInRamdisk()
982}
983
Ivan Lozano52767be2019-10-18 14:49:46 -0700984func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900985 return c.ModuleBase.InstallInRecovery()
986}
987
Jiyong Park25fc6a92018-11-18 18:02:45 +0900988func (c *Module) IsStubs() bool {
989 if library, ok := c.linker.(*libraryDecorator); ok {
990 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900991 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
992 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900993 }
994 return false
995}
996
997func (c *Module) HasStubsVariants() bool {
998 if library, ok := c.linker.(*libraryDecorator); ok {
999 return len(library.Properties.Stubs.Versions) > 0
1000 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001001 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1002 return len(library.Properties.Stubs.Versions) > 0
1003 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001004 return false
1005}
1006
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001007func (c *Module) bootstrap() bool {
1008 return Bool(c.Properties.Bootstrap)
1009}
1010
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001011func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001012 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1013 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1014 return false
1015 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001016 return c.linker != nil && c.linker.nativeCoverage()
1017}
1018
Inseob Kim8471cda2019-11-15 09:59:12 +09001019func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +09001020 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1021 return true
1022 }
1023 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
1024 return true
1025 }
1026 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
1027 return true
1028 }
1029 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001030}
1031
Jiyong Park73c54ee2019-10-22 20:31:18 +09001032func (c *Module) ExportedIncludeDirs() android.Paths {
1033 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1034 return flagsProducer.exportedDirs()
1035 }
Jiyong Park232e7852019-11-04 12:23:40 +09001036 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001037}
1038
1039func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1040 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1041 return flagsProducer.exportedSystemDirs()
1042 }
Jiyong Park232e7852019-11-04 12:23:40 +09001043 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001044}
1045
1046func (c *Module) ExportedFlags() []string {
1047 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1048 return flagsProducer.exportedFlags()
1049 }
Jiyong Park232e7852019-11-04 12:23:40 +09001050 return nil
1051}
1052
1053func (c *Module) ExportedDeps() android.Paths {
1054 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1055 return flagsProducer.exportedDeps()
1056 }
1057 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001058}
1059
Inseob Kimd110f872019-12-06 13:15:38 +09001060func (c *Module) ExportedGeneratedHeaders() android.Paths {
1061 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1062 return flagsProducer.exportedGeneratedHeaders()
1063 }
1064 return nil
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
Justin Yun5f7f7e82019-11-18 19:52:14 +09001101func (ctx *moduleContext) ProductSpecific() bool {
1102 return ctx.ModuleContext.ProductSpecific() ||
1103 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1104}
1105
Jiyong Park2db76922017-11-08 16:03:48 +09001106func (ctx *moduleContext) SocSpecific() bool {
1107 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001108 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001109}
1110
Colin Crossca860ac2016-01-04 14:34:37 -08001111type moduleContextImpl struct {
1112 mod *Module
1113 ctx BaseModuleContext
1114}
1115
Colin Crossb98c8b02016-07-29 13:44:28 -07001116func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001117 return ctx.mod.toolchain(ctx.ctx)
1118}
1119
1120func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001121 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001122}
1123
1124func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001125 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001126}
1127
Jiyong Park1d1119f2019-07-29 21:27:18 +09001128func (ctx *moduleContextImpl) header() bool {
1129 return ctx.mod.header()
1130}
1131
Jooyung Hanccce2f22020-03-07 03:45:53 +09001132func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001133 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001134}
1135
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001136func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001137 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001138}
1139
1140func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001141 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001142 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001143 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001144 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001145 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001146 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001147 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001148 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001149 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001150 }
1151 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001152}
1153
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001154func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001155 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001156}
Justin Yun8effde42017-06-23 19:24:43 +09001157
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001158func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001159 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001160}
1161
Inseob Kim9516ee92019-05-09 10:56:13 +09001162func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1163 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001164}
1165
Inseob Kim9516ee92019-05-09 10:56:13 +09001166func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1167 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001168}
1169
Inseob Kim9516ee92019-05-09 10:56:13 +09001170func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1171 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001172}
1173
Logan Chienf3511742017-10-31 18:04:35 +08001174func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001175 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001176}
1177
Yi Kong7e53c572018-02-14 18:16:12 +08001178func (ctx *moduleContextImpl) isPgoCompile() bool {
1179 return ctx.mod.isPgoCompile()
1180}
1181
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001182func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1183 return ctx.mod.isNDKStubLibrary()
1184}
1185
Justin Yun8effde42017-06-23 19:24:43 +09001186func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001187 return ctx.mod.isVndkSp()
1188}
1189
1190func (ctx *moduleContextImpl) isVndkExt() bool {
1191 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001192}
1193
Vic Yangefd249e2018-11-12 20:19:56 -08001194func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001195 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001196}
1197
Justin Yun5f7f7e82019-11-18 19:52:14 +09001198func (ctx *moduleContextImpl) inProduct() bool {
1199 return ctx.mod.inProduct()
1200}
1201
1202func (ctx *moduleContextImpl) inVendor() bool {
1203 return ctx.mod.inVendor()
1204}
1205
Yifan Hong1b3348d2020-01-21 15:53:22 -08001206func (ctx *moduleContextImpl) inRamdisk() bool {
1207 return ctx.mod.InRamdisk()
1208}
1209
Jiyong Parkf9332f12018-02-01 00:54:12 +09001210func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001211 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001212}
1213
Logan Chien2f2b8902018-07-10 15:01:19 +08001214// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001215func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001216 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1217 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001218 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001219
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001220 // Coverage builds have extra symbols.
1221 if ctx.mod.isCoverageVariant() {
1222 return false
1223 }
1224
Doug Hornc32c6b02019-01-17 14:44:05 -08001225 if ctx.ctx.Fuchsia() {
1226 return false
1227 }
1228
Logan Chien2f2b8902018-07-10 15:01:19 +08001229 if sanitize := ctx.mod.sanitize; sanitize != nil {
1230 if !sanitize.isVariantOnProductionDevice() {
1231 return false
1232 }
1233 }
1234 if !ctx.ctx.Device() {
1235 // Host modules do not need ABI dumps.
1236 return false
1237 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001238 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001239 // Stubs do not need ABI dumps.
1240 return false
1241 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001242 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001243}
1244
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001245func (ctx *moduleContextImpl) selectedStl() string {
1246 if stl := ctx.mod.stl; stl != nil {
1247 return stl.Properties.SelectedStl
1248 }
1249 return ""
1250}
1251
Ivan Lozanobd721262018-11-27 14:33:03 -08001252func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1253 return ctx.mod.linker.useClangLld(actx)
1254}
1255
Colin Crossce75d2c2016-10-06 16:12:58 -07001256func (ctx *moduleContextImpl) baseModuleName() string {
1257 return ctx.mod.ModuleBase.BaseModuleName()
1258}
1259
Logan Chienf3511742017-10-31 18:04:35 +08001260func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1261 return ctx.mod.getVndkExtendsModuleName()
1262}
1263
Logan Chiene274fc92019-12-03 11:18:32 -08001264func (ctx *moduleContextImpl) isForPlatform() bool {
1265 return ctx.mod.IsForPlatform()
1266}
1267
Jiyong Park58e364a2019-01-19 19:24:06 +09001268func (ctx *moduleContextImpl) apexName() string {
1269 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001270}
1271
Jooyung Hanccce2f22020-03-07 03:45:53 +09001272func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001273 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001274}
1275
Jiyong Parkb0788572018-12-20 22:10:17 +09001276func (ctx *moduleContextImpl) hasStubsVariants() bool {
1277 return ctx.mod.HasStubsVariants()
1278}
1279
1280func (ctx *moduleContextImpl) isStubs() bool {
1281 return ctx.mod.IsStubs()
1282}
1283
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001284func (ctx *moduleContextImpl) bootstrap() bool {
1285 return ctx.mod.bootstrap()
1286}
1287
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001288func (ctx *moduleContextImpl) nativeCoverage() bool {
1289 return ctx.mod.nativeCoverage()
1290}
1291
Colin Cross635c3b02016-05-18 15:37:25 -07001292func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001293 return &Module{
1294 hod: hod,
1295 multilib: multilib,
1296 }
1297}
1298
Colin Cross635c3b02016-05-18 15:37:25 -07001299func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001300 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001301 module.features = []feature{
1302 &tidyFeature{},
1303 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001304 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001305 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001306 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001307 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001308 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001309 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001310 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001311 return module
1312}
1313
Colin Crossce75d2c2016-10-06 16:12:58 -07001314func (c *Module) Prebuilt() *android.Prebuilt {
1315 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1316 return p.prebuilt()
1317 }
1318 return nil
1319}
1320
1321func (c *Module) Name() string {
1322 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001323 if p, ok := c.linker.(interface {
1324 Name(string) string
1325 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001326 name = p.Name(name)
1327 }
1328 return name
1329}
1330
Alex Light3d673592019-01-18 14:37:31 -08001331func (c *Module) Symlinks() []string {
1332 if p, ok := c.installer.(interface {
1333 symlinkList() []string
1334 }); ok {
1335 return p.symlinkList()
1336 }
1337 return nil
1338}
1339
Jeff Gaston294356f2017-09-27 17:05:30 -07001340// orderDeps reorders dependencies into a list such that if module A depends on B, then
1341// A will precede B in the resultant list.
1342// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001343// Note that directSharedDeps should be the analogous static library for each shared lib dep
1344func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001345 // If A depends on B, then
1346 // Every list containing A will also contain B later in the list
1347 // So, after concatenating all lists, the final instance of B will have come from the same
1348 // original list as the final instance of A
1349 // So, the final instance of B will be later in the concatenation than the final A
1350 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1351 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001352 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001353 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001354 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1355 }
1356 for _, dep := range directSharedDeps {
1357 orderedAllDeps = append(orderedAllDeps, dep)
1358 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001359 }
1360
Colin Crossb6715442017-10-24 11:13:31 -07001361 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001362
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001363 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001364 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001365 // resultant list to only what the caller has chosen to include in directStaticDeps
1366 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001367
1368 return orderedAllDeps, orderedDeclaredDeps
1369}
1370
Ivan Lozano183a3212019-10-18 14:18:45 -07001371func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001372 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001373 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001374 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1375 staticDepFiles := []android.Path{}
1376 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001377 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1378 if dep.OutputFile().Valid() {
1379 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1380 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1381 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001382 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001383 sharedDepFiles := []android.Path{}
1384 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001385 if sharedDep.HasStaticVariant() {
1386 staticAnalogue := sharedDep.GetStaticVariant()
1387 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1388 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001389 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001390 }
1391
1392 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001393 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1394 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001395
1396 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001397}
1398
Roland Levillainf89cd092019-07-29 16:22:59 +01001399func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1400 test, ok := c.linker.(testPerSrc)
1401 return ok && test.isAllTestsVariation()
1402}
1403
Liz Kammer1c14a212020-05-12 15:26:55 -07001404func (c *Module) DataPaths() android.Paths {
1405 if p, ok := c.installer.(interface {
1406 dataPaths() android.Paths
1407 }); ok {
1408 return p.dataPaths()
1409 }
1410 return nil
1411}
1412
Justin Yun5f7f7e82019-11-18 19:52:14 +09001413func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1414 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1415 // "current", it will append the VNDK version to the name suffix.
1416 var vndkVersion string
1417 var nameSuffix string
1418 if c.inProduct() {
1419 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1420 nameSuffix = productSuffix
1421 } else {
1422 vndkVersion = ctx.DeviceConfig().VndkVersion()
1423 nameSuffix = vendorSuffix
1424 }
1425 if vndkVersion == "current" {
1426 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1427 }
1428 if c.Properties.VndkVersion != vndkVersion {
1429 // add version suffix only if the module is using different vndk version than the
1430 // version in product or vendor partition.
1431 nameSuffix += "." + c.Properties.VndkVersion
1432 }
1433 return nameSuffix
1434}
1435
Colin Cross635c3b02016-05-18 15:37:25 -07001436func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001437 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001438 //
1439 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1440 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1441 // module and return early, as this module does not produce an output file per se.
1442 if c.IsTestPerSrcAllTestsVariation() {
1443 c.outputFile = android.OptionalPath{}
1444 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001445 }
1446
Jooyung Han38002912019-05-16 04:01:54 +09001447 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001448
Inseob Kim64c43952019-08-26 16:52:35 +09001449 c.Properties.SubName = ""
1450
1451 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1452 c.Properties.SubName += nativeBridgeSuffix
1453 }
1454
Justin Yun5f7f7e82019-11-18 19:52:14 +09001455 _, llndk := c.linker.(*llndkStubDecorator)
1456 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1457 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1458 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1459 // added for product variant only when we have vendor and product variants with core
1460 // variant. The suffix is not added for vendor-only or product-only module.
1461 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1462 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001463 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1464 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1465 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001466 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1467 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001468 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001469 c.Properties.SubName += recoverySuffix
Colin Crossc511bc52020-04-07 16:50:32 +00001470 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1471 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001472 }
1473
Colin Crossca860ac2016-01-04 14:34:37 -08001474 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001475 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001476 moduleContextImpl: moduleContextImpl{
1477 mod: c,
1478 },
1479 }
1480 ctx.ctx = ctx
1481
Colin Crossf18e1102017-11-16 14:33:08 -08001482 deps := c.depsToPaths(ctx)
1483 if ctx.Failed() {
1484 return
1485 }
1486
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001487 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1488 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1489 }
1490
Colin Crossca860ac2016-01-04 14:34:37 -08001491 flags := Flags{
1492 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001493 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001494 }
Colin Crossca860ac2016-01-04 14:34:37 -08001495 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001496 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001497 }
1498 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001499 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001500 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001501 if c.stl != nil {
1502 flags = c.stl.flags(ctx, flags)
1503 }
Colin Cross16b23492016-01-06 14:41:07 -08001504 if c.sanitize != nil {
1505 flags = c.sanitize.flags(ctx, flags)
1506 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001507 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001508 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001509 }
Stephen Craneba090d12017-05-09 15:44:35 -07001510 if c.lto != nil {
1511 flags = c.lto.flags(ctx, flags)
1512 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001513 if c.pgo != nil {
1514 flags = c.pgo.flags(ctx, flags)
1515 }
Colin Crossca860ac2016-01-04 14:34:37 -08001516 for _, feature := range c.features {
1517 flags = feature.flags(ctx, flags)
1518 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001519 if ctx.Failed() {
1520 return
1521 }
1522
Colin Cross4af21ed2019-11-04 09:37:55 -08001523 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1524 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1525 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001526
Colin Cross4af21ed2019-11-04 09:37:55 -08001527 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001528
1529 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001530 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001531 }
1532 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001533 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001534 }
1535
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001536 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001537 // We need access to all the flags seen by a source file.
1538 if c.sabi != nil {
1539 flags = c.sabi.flags(ctx, flags)
1540 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001541
Colin Cross4af21ed2019-11-04 09:37:55 -08001542 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001543
Colin Crossca860ac2016-01-04 14:34:37 -08001544 // Optimization to reduce size of build.ninja
1545 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001546 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1547 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1548 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1549 flags.Local.CFlags = []string{"$cflags"}
1550 flags.Local.CppFlags = []string{"$cppflags"}
1551 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001552
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001553 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001554 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001555 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001556 if ctx.Failed() {
1557 return
1558 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001559 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001560 }
1561
Colin Crossca860ac2016-01-04 14:34:37 -08001562 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001563 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001564 if ctx.Failed() {
1565 return
1566 }
Colin Cross635c3b02016-05-18 15:37:25 -07001567 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001568
1569 // If a lib is directly included in any of the APEXes, unhide the stubs
1570 // variant having the latest version gets visible to make. In addition,
1571 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1572 // force anything in the make world to link against the stubs library.
1573 // (unless it is explicitly referenced via .bootstrap suffix or the
1574 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001575 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001576 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001577 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001578 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001579 c.Properties.HideFromMake = false // unhide
1580 // Note: this is still non-installable
1581 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001582
1583 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1584 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1585 if isSnapshotAware(ctx, c) {
1586 i.collectHeadersForSnapshot(ctx)
1587 }
1588 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001589 }
Colin Cross5049f022015-03-18 13:28:46 -07001590
Inseob Kim1f086e22019-05-09 13:29:15 +09001591 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001592 c.installer.install(ctx, c.outputFile.Path())
1593 if ctx.Failed() {
1594 return
Colin Crossca860ac2016-01-04 14:34:37 -08001595 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001596 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1597 // If the module has been specifically configure to not be installed then
1598 // skip the installation as otherwise it will break when running inside make
1599 // as the output path to install will not be specified. Not all uninstallable
1600 // modules can skip installation as some are needed for resolving make side
1601 // dependencies.
1602 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001603 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001604}
1605
Colin Cross0ea8ba82019-06-06 14:33:29 -07001606func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001607 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001608 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001609 }
Colin Crossca860ac2016-01-04 14:34:37 -08001610 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001611}
1612
Colin Crossca860ac2016-01-04 14:34:37 -08001613func (c *Module) begin(ctx BaseModuleContext) {
1614 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001615 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001616 }
Colin Crossca860ac2016-01-04 14:34:37 -08001617 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001618 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001619 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001620 if c.stl != nil {
1621 c.stl.begin(ctx)
1622 }
Colin Cross16b23492016-01-06 14:41:07 -08001623 if c.sanitize != nil {
1624 c.sanitize.begin(ctx)
1625 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001626 if c.coverage != nil {
1627 c.coverage.begin(ctx)
1628 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001629 if c.sabi != nil {
1630 c.sabi.begin(ctx)
1631 }
Justin Yun8effde42017-06-23 19:24:43 +09001632 if c.vndkdep != nil {
1633 c.vndkdep.begin(ctx)
1634 }
Stephen Craneba090d12017-05-09 15:44:35 -07001635 if c.lto != nil {
1636 c.lto.begin(ctx)
1637 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001638 if c.pgo != nil {
1639 c.pgo.begin(ctx)
1640 }
Colin Crossca860ac2016-01-04 14:34:37 -08001641 for _, feature := range c.features {
1642 feature.begin(ctx)
1643 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001644 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001645 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001646 if err != nil {
1647 ctx.PropertyErrorf("sdk_version", err.Error())
1648 }
Nan Zhang0007d812017-11-07 10:57:05 -08001649 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001650 }
Colin Crossca860ac2016-01-04 14:34:37 -08001651}
1652
Colin Cross37047f12016-12-13 17:06:13 -08001653func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001654 deps := Deps{}
1655
1656 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001657 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001658 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001659 // Add the PGO dependency (the clang_rt.profile runtime library), which
1660 // sometimes depends on symbols from libgcc, before libgcc gets added
1661 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001662 if c.pgo != nil {
1663 deps = c.pgo.deps(ctx, deps)
1664 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001665 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001666 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001667 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001668 if c.stl != nil {
1669 deps = c.stl.deps(ctx, deps)
1670 }
Colin Cross16b23492016-01-06 14:41:07 -08001671 if c.sanitize != nil {
1672 deps = c.sanitize.deps(ctx, deps)
1673 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001674 if c.coverage != nil {
1675 deps = c.coverage.deps(ctx, deps)
1676 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001677 if c.sabi != nil {
1678 deps = c.sabi.deps(ctx, deps)
1679 }
Justin Yun8effde42017-06-23 19:24:43 +09001680 if c.vndkdep != nil {
1681 deps = c.vndkdep.deps(ctx, deps)
1682 }
Stephen Craneba090d12017-05-09 15:44:35 -07001683 if c.lto != nil {
1684 deps = c.lto.deps(ctx, deps)
1685 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001686 for _, feature := range c.features {
1687 deps = feature.deps(ctx, deps)
1688 }
1689
Colin Crossb6715442017-10-24 11:13:31 -07001690 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1691 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1692 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1693 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1694 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1695 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001696 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001697
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001698 for _, lib := range deps.ReexportSharedLibHeaders {
1699 if !inList(lib, deps.SharedLibs) {
1700 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1701 }
1702 }
1703
1704 for _, lib := range deps.ReexportStaticLibHeaders {
1705 if !inList(lib, deps.StaticLibs) {
1706 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1707 }
1708 }
1709
Colin Cross5950f382016-12-13 12:50:57 -08001710 for _, lib := range deps.ReexportHeaderLibHeaders {
1711 if !inList(lib, deps.HeaderLibs) {
1712 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1713 }
1714 }
1715
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001716 for _, gen := range deps.ReexportGeneratedHeaders {
1717 if !inList(gen, deps.GeneratedHeaders) {
1718 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1719 }
1720 }
1721
Colin Crossc99deeb2016-04-11 15:06:20 -07001722 return deps
1723}
1724
Dan Albert7e9d2952016-08-04 13:02:36 -07001725func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001726 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001727 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001728 moduleContextImpl: moduleContextImpl{
1729 mod: c,
1730 },
1731 }
1732 ctx.ctx = ctx
1733
Colin Crossca860ac2016-01-04 14:34:37 -08001734 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001735}
1736
Jiyong Park7ed9de32018-10-15 22:25:07 +09001737// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001738func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001739 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1740 version := name[sharp+1:]
1741 libname := name[:sharp]
1742 return libname, version
1743 }
1744 return name, ""
1745}
1746
Colin Cross1e676be2016-10-12 14:38:15 -07001747func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001748 if !c.Enabled() {
1749 return
1750 }
1751
Colin Cross37047f12016-12-13 17:06:13 -08001752 ctx := &depsContext{
1753 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001754 moduleContextImpl: moduleContextImpl{
1755 mod: c,
1756 },
1757 }
1758 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001759
Colin Crossc99deeb2016-04-11 15:06:20 -07001760 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001761
Dan Albert914449f2016-06-17 16:45:24 -07001762 variantNdkLibs := []string{}
1763 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001764 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001765 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001766
Inseob Kimeec88e12020-01-22 11:11:29 +09001767 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001768 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001769 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001770 // 1. Name of an NDK library that refers to a prebuilt module.
1771 // For each of these, it adds the name of the prebuilt module (which will be in
1772 // prebuilts/ndk) to the list of nonvariant libs.
1773 // 2. Name of an NDK library that refers to an ndk_library module.
1774 // For each of these, it adds the name of the ndk_library module to the list of
1775 // variant libs.
1776 // 3. Anything else (so anything that isn't an NDK library).
1777 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001778 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001779 // The caller can then know to add the variantLibs dependencies differently from the
1780 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001781
Inseob Kim9516ee92019-05-09 10:56:13 +09001782 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001783 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1784
1785 rewriteVendorLibs := func(lib string) string {
1786 if isLlndkLibrary(lib, ctx.Config()) {
1787 return lib + llndkLibrarySuffix
1788 }
1789
1790 // only modules with BOARD_VNDK_VERSION uses snapshot.
1791 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1792 return lib
1793 }
1794
1795 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1796 return snapshot
1797 }
1798
1799 return lib
1800 }
1801
1802 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001803 variantLibs = []string{}
1804 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001805 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001806 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001807 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001808 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1809 if !inList(name, ndkMigratedLibs) {
1810 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001811 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001812 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001813 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001814 } else if ctx.useVndk() {
1815 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001816 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001817 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001818 if actx.OtherModuleExists(vendorPublicLib) {
1819 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1820 } else {
1821 // This can happen if vendor_public_library module is defined in a
1822 // namespace that isn't visible to the current module. In that case,
1823 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001824 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001825 }
Dan Albert914449f2016-06-17 16:45:24 -07001826 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001827 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001828 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001829 }
1830 }
Dan Albert914449f2016-06-17 16:45:24 -07001831 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001832 }
1833
Inseob Kimeec88e12020-01-22 11:11:29 +09001834 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1835 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1836 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1837 if ctx.useVndk() {
1838 for idx, lib := range deps.RuntimeLibs {
1839 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1840 }
1841 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001842 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001843
Jiyong Park7e636d02019-01-28 16:16:54 +09001844 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001845 if c.linker != nil {
1846 if library, ok := c.linker.(*libraryDecorator); ok {
1847 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001848 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001849 }
1850 }
1851 }
1852
Inseob Kimeec88e12020-01-22 11:11:29 +09001853 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1854 // only modules with BOARD_VNDK_VERSION uses snapshot.
1855 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1856 return lib
1857 }
1858
1859 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1860 return snapshot
1861 }
1862
1863 return lib
1864 }
1865
1866 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001867 for _, lib := range deps.HeaderLibs {
1868 depTag := headerDepTag
1869 if inList(lib, deps.ReexportHeaderLibHeaders) {
1870 depTag = headerExportDepTag
1871 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001872
1873 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1874
Jiyong Park7e636d02019-01-28 16:16:54 +09001875 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001876 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001877 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001878 } else {
1879 actx.AddVariationDependencies(nil, depTag, lib)
1880 }
1881 }
1882
1883 if buildStubs {
1884 // Stubs lib does not have dependency to other static/shared libraries.
1885 // Don't proceed.
1886 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001887 }
Colin Cross5950f382016-12-13 12:50:57 -08001888
Inseob Kimc0907f12019-02-08 21:00:45 +09001889 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001890 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001891
Jiyong Park5d1598f2019-02-25 22:14:17 +09001892 for _, lib := range deps.WholeStaticLibs {
1893 depTag := wholeStaticDepTag
1894 if impl, ok := syspropImplLibraries[lib]; ok {
1895 lib = impl
1896 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001897
1898 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1899
Jiyong Park5d1598f2019-02-25 22:14:17 +09001900 actx.AddVariationDependencies([]blueprint.Variation{
1901 {Mutator: "link", Variation: "static"},
1902 }, depTag, lib)
1903 }
1904
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001905 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001906 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001907 if inList(lib, deps.ReexportStaticLibHeaders) {
1908 depTag = staticExportDepTag
1909 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001910
1911 if impl, ok := syspropImplLibraries[lib]; ok {
1912 lib = impl
1913 }
1914
Inseob Kimeec88e12020-01-22 11:11:29 +09001915 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1916
Dan Willemsen59339a22018-07-22 21:18:45 -07001917 actx.AddVariationDependencies([]blueprint.Variation{
1918 {Mutator: "link", Variation: "static"},
1919 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001920 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001921
Jooyung Han75568392020-03-20 04:29:24 +09001922 // staticUnwinderDep is treated as staticDep for Q apexes
1923 // so that native libraries/binaries are linked with static unwinder
1924 // because Q libc doesn't have unwinder APIs
1925 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001926 actx.AddVariationDependencies([]blueprint.Variation{
1927 {Mutator: "link", Variation: "static"},
1928 }, staticUnwinderDepTag, staticUnwinder(actx))
1929 }
1930
Inseob Kimeec88e12020-01-22 11:11:29 +09001931 for _, lib := range deps.LateStaticLibs {
1932 actx.AddVariationDependencies([]blueprint.Variation{
1933 {Mutator: "link", Variation: "static"},
1934 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1935 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001936
Ivan Lozano183a3212019-10-18 14:18:45 -07001937 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001938 var variations []blueprint.Variation
1939 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001940 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001941 // Version is explicitly specified. i.e. libFoo#30
1942 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001943 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001944 }
1945 actx.AddVariationDependencies(variations, depTag, name)
1946
Jooyung Han03b51852020-02-26 22:45:42 +09001947 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001948 // The stubs library will be used when the depending module is built for APEX and
1949 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09001950 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09001951 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1952 // Note that depTag.ExplicitlyVersioned is false in this case.
1953 actx.AddVariationDependencies([]blueprint.Variation{
1954 {Mutator: "link", Variation: "shared"},
1955 {Mutator: "version", Variation: ver},
1956 }, depTag, name)
1957 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001958 }
1959 }
1960
Jiyong Park7ed9de32018-10-15 22:25:07 +09001961 // shared lib names without the #version suffix
1962 var sharedLibNames []string
1963
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001964 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001965 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001966 if c.static() {
1967 depTag = SharedFromStaticDepTag
1968 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001969 if inList(lib, deps.ReexportSharedLibHeaders) {
1970 depTag = sharedExportDepTag
1971 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001972
1973 if impl, ok := syspropImplLibraries[lib]; ok {
1974 lib = impl
1975 }
1976
Jiyong Park73c54ee2019-10-22 20:31:18 +09001977 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001978 sharedLibNames = append(sharedLibNames, name)
1979
Jiyong Park25fc6a92018-11-18 18:02:45 +09001980 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001981 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001982
Jiyong Park7ed9de32018-10-15 22:25:07 +09001983 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001984 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001985 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1986 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1987 // linking against both the stubs lib and the non-stubs lib at the same time.
1988 continue
1989 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001990 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001991 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001992
Dan Willemsen59339a22018-07-22 21:18:45 -07001993 actx.AddVariationDependencies([]blueprint.Variation{
1994 {Mutator: "link", Variation: "shared"},
1995 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001996
Colin Cross68861832016-07-08 10:41:41 -07001997 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001998
1999 for _, gen := range deps.GeneratedHeaders {
2000 depTag := genHeaderDepTag
2001 if inList(gen, deps.ReexportGeneratedHeaders) {
2002 depTag = genHeaderExportDepTag
2003 }
2004 actx.AddDependency(c, depTag, gen)
2005 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002006
Colin Cross42d48b72018-08-29 14:10:52 -07002007 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002008
2009 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07002010 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08002011 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002012 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07002013 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07002014 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002015 if deps.LinkerFlagsFile != "" {
2016 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2017 }
2018 if deps.DynamicLinker != "" {
2019 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002020 }
Dan Albert914449f2016-06-17 16:45:24 -07002021
2022 version := ctx.sdkVersion()
2023 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002024 {Mutator: "ndk_api", Variation: version},
2025 {Mutator: "link", Variation: "shared"},
2026 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07002027 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002028 {Mutator: "ndk_api", Variation: version},
2029 {Mutator: "link", Variation: "shared"},
2030 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002031
2032 if vndkdep := c.vndkdep; vndkdep != nil {
2033 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002034 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002035 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002036 {Mutator: "link", Variation: "shared"},
2037 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002038 }
2039 }
Colin Cross6362e272015-10-29 15:25:03 -07002040}
Colin Cross21b9a242015-03-24 14:15:58 -07002041
Colin Crosse40b4ea2018-10-02 22:25:58 -07002042func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002043 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2044 c.beginMutator(ctx)
2045 }
2046}
2047
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002048// Whether a module can link to another module, taking into
2049// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07002050func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
2051 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002052 // Host code is not restricted
2053 return
2054 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002055
2056 // VNDK is cc.Module supported only for now.
2057 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002058 // Though vendor code is limited by the vendor mutator,
2059 // each vendor-available module needs to check
2060 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002061 if ccTo, ok := to.(*Module); ok {
2062 if ccFrom.vndkdep != nil {
2063 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2064 }
2065 } else {
2066 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002067 }
2068 return
2069 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002070 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002071 // Platform code can link to anything
2072 return
2073 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002074 if from.InRamdisk() {
2075 // Ramdisk code is not NDK
2076 return
2077 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002078 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002079 // Recovery code is not NDK
2080 return
2081 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002082 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002083 // These are always allowed
2084 return
2085 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002086 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002087 // These are allowed, but they don't set sdk_version
2088 return
2089 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002090 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002091 // These aren't real libraries, but are the stub shared libraries that are included in
2092 // the NDK.
2093 return
2094 }
Logan Chien834b9a62019-01-14 15:39:03 +08002095
Ivan Lozano52767be2019-10-18 14:49:46 -07002096 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002097 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2098 // to link to libc++ (non-NDK and without sdk_version).
2099 return
2100 }
2101
Ivan Lozano52767be2019-10-18 14:49:46 -07002102 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002103 // NDK code linking to platform code is never okay.
2104 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002105 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002106 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002107 }
2108
2109 // At this point we know we have two NDK libraries, but we need to
2110 // check that we're not linking against anything built against a higher
2111 // API level, as it is only valid to link against older or equivalent
2112 // APIs.
2113
Inseob Kim01a28722018-04-11 09:48:45 +09002114 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002115 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002116 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002117 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002118 // Current can't be linked against by anything else.
2119 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002120 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002121 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002122 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002123 if err != nil {
2124 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002125 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002126 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002127 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002128 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002129 if err != nil {
2130 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002131 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002132 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002133 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002134
Inseob Kim01a28722018-04-11 09:48:45 +09002135 if toApi > fromApi {
2136 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002137 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002138 }
2139 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002140 }
Dan Albert202fe492017-12-15 13:56:59 -08002141
2142 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002143 fromStl := from.SelectedStl()
2144 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002145 if fromStl == "" || toStl == "" {
2146 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002147 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002148 // We can be permissive with the system "STL" since it is only the C++
2149 // ABI layer, but in the future we should make sure that everyone is
2150 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002151 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002152 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002153 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2154 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002155 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002156}
2157
Jiyong Park5fb8c102018-04-09 12:03:06 +09002158// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002159// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2160// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002161// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002162func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2163 check := func(child, parent android.Module) bool {
2164 to, ok := child.(*Module)
2165 if !ok {
2166 // follow thru cc.Defaults, etc.
2167 return true
2168 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002169
Jooyung Hana70f0672019-01-18 15:20:43 +09002170 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2171 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002172 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002173
2174 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002175 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002176 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002177 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002178
Jooyung Han0302a842019-10-30 18:43:49 +09002179 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002180 return false
2181 }
2182
2183 var stringPath []string
2184 for _, m := range ctx.GetWalkPath() {
2185 stringPath = append(stringPath, m.Name())
2186 }
2187 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2188 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2189 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2190 return false
2191 }
2192 if module, ok := ctx.Module().(*Module); ok {
2193 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002194 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002195 ctx.WalkDeps(check)
2196 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002197 }
2198 }
2199}
2200
Colin Crossc99deeb2016-04-11 15:06:20 -07002201// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002202func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002203 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002204
Ivan Lozano183a3212019-10-18 14:18:45 -07002205 directStaticDeps := []LinkableInterface{}
2206 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002207
Inseob Kim9516ee92019-05-09 10:56:13 +09002208 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2209
Inseob Kim69378442019-06-03 19:10:47 +09002210 reexportExporter := func(exporter exportedFlagsProducer) {
2211 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2212 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2213 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2214 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002215 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002216 }
2217
Colin Crossd11fcda2017-10-23 17:59:01 -07002218 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002219 depName := ctx.OtherModuleName(dep)
2220 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002221
Ivan Lozano52767be2019-10-18 14:49:46 -07002222 ccDep, ok := dep.(LinkableInterface)
2223 if !ok {
2224
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002225 // handling for a few module types that aren't cc Module but that are also supported
2226 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002227 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002228 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002229 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2230 genRule.GeneratedSourceFiles()...)
2231 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002232 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002233 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002234 // Support exported headers from a generated_sources dependency
2235 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002236 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002237 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002238 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002239 genRule.GeneratedSourceFiles()...)
2240 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002241 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002242 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002243 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002244 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002245 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002246 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2247 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002248 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002249 // 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 +09002250 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002251
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002252 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002253 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002254 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002255 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002256 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002257 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002258 files := genRule.GeneratedSourceFiles()
2259 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002260 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002261 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002262 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 -07002263 }
2264 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002265 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002266 }
Colin Crossca860ac2016-01-04 14:34:37 -08002267 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002268 return
2269 }
2270
Colin Crossfe17f6f2019-03-28 19:30:56 -07002271 if depTag == android.ProtoPluginDepTag {
2272 return
2273 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002274 if depTag == llndkImplDep {
2275 return
2276 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002277
Colin Crossd11fcda2017-10-23 17:59:01 -07002278 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002279 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2280 return
2281 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002282 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002283 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2284 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002285 return
2286 }
2287
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002288 // re-exporting flags
2289 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002290 // reusing objects only make sense for cc.Modules.
2291 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002292 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002293 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002294 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002295 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002296 return
2297 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002298 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002299
Jiyong Parke4bb9862019-02-01 00:31:10 +09002300 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002301 // staticVariants are a cc.Module specific concept.
2302 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002303 c.staticVariant = ccDep
2304 return
2305 }
2306 }
2307
Jooyung Han75568392020-03-20 04:29:24 +09002308 // For the dependency from platform to apex, use the latest stubs
2309 c.apexSdkVersion = android.FutureApiLevel
2310 if !c.IsForPlatform() {
2311 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2312 }
2313
2314 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2315 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2316 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2317 // (b/144430859)
2318 c.apexSdkVersion = android.FutureApiLevel
2319 }
2320
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002321 if depTag == staticUnwinderDepTag {
Jooyung Han75568392020-03-20 04:29:24 +09002322 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2323 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002324 depTag = StaticDepTag
2325 } else {
2326 return
2327 }
2328 }
2329
Ivan Lozano183a3212019-10-18 14:18:45 -07002330 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2331 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2332 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002333 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002334 if t, ok := depTag.(DependencyTag); ok {
2335 explicitlyVersioned = t.ExplicitlyVersioned
2336 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002337 depTag = t
2338 }
2339
Ivan Lozano183a3212019-10-18 14:18:45 -07002340 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002341 depIsStatic := false
2342 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002343 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002344 depIsStatic = true
2345 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002346 if ccDep.CcLibrary() && !depIsStatic {
2347 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002348 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002349 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002350 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002351
2352 var useThisDep bool
2353 if depIsStubs && explicitlyVersioned {
2354 // Always respect dependency to the versioned stubs (i.e. libX#10)
2355 useThisDep = true
2356 } else if !depHasStubs {
2357 // Use non-stub variant if that is the only choice
2358 // (i.e. depending on a lib without stubs.version property)
2359 useThisDep = true
2360 } else if c.IsForPlatform() {
2361 // If not building for APEX, use stubs only when it is from
2362 // an APEX (and not from platform)
2363 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002364 if c.bootstrap() {
2365 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002366 // always link to non-stub variant
2367 useThisDep = !depIsStubs
2368 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002369 for _, testFor := range c.TestFor() {
2370 // Another exception: if this module is bundled with an APEX, then
2371 // it is linked with the non-stub variant of a module in the APEX
2372 // as if this is part of the APEX.
2373 if android.DirectlyInApex(testFor, depName) {
2374 useThisDep = !depIsStubs
2375 break
2376 }
2377 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002378 } else {
2379 // If building for APEX, use stubs only when it is not from
2380 // the same APEX
2381 useThisDep = (depInSameApex != depIsStubs)
2382 }
2383
Jooyung Han03b51852020-02-26 22:45:42 +09002384 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2385 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002386 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002387 if err != nil {
2388 ctx.OtherModuleErrorf(dep, err.Error())
2389 return
2390 }
2391 if versionToUse != ccDep.StubsVersion() {
2392 useThisDep = false
2393 }
2394 }
2395
Jiyong Park25fc6a92018-11-18 18:02:45 +09002396 if !useThisDep {
2397 return // stop processing this dep
2398 }
2399 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002400 if c.UseVndk() {
2401 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2402 // by default, use current version of LLNDK
2403 versionToUse := ""
2404 versions := stubsVersionsFor(ctx.Config())[depName]
2405 if c.ApexName() != "" && len(versions) > 0 {
2406 // if this is for use_vendor apex && dep has stubsVersions
2407 // apply the same rule of apex sdk enforcement to choose right version
2408 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002409 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002410 if err != nil {
2411 ctx.OtherModuleErrorf(dep, err.Error())
2412 return
2413 }
2414 }
2415 if versionToUse != ccDep.StubsVersion() {
2416 return
2417 }
2418 }
2419 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002420
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002421 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2422
Ivan Lozano52767be2019-10-18 14:49:46 -07002423 // Exporting flags only makes sense for cc.Modules
2424 if _, ok := ccDep.(*Module); ok {
2425 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002426 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002427 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2428 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002429 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002430
Ivan Lozano52767be2019-10-18 14:49:46 -07002431 if t.ReexportFlags {
2432 reexportExporter(i)
2433 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2434 // Re-exported shared library headers must be included as well since they can help us with type information
2435 // about template instantiations (instantiated from their headers).
2436 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2437 // scripts.
2438 c.sabi.Properties.ReexportedIncludes = append(
2439 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2440 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002441 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002442 }
Logan Chienf3511742017-10-31 18:04:35 +08002443 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002444 }
2445
Colin Cross26c34ed2016-09-30 17:10:16 -07002446 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002447 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002448
Ivan Lozano52767be2019-10-18 14:49:46 -07002449 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002450 depFile := android.OptionalPath{}
2451
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002452 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002453 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002454 ptr = &depPaths.SharedLibs
2455 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002456 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002457 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002458
Jiyong Park64a44f22019-01-18 14:37:08 +09002459 case earlySharedDepTag:
2460 ptr = &depPaths.EarlySharedLibs
2461 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002462 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002463 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002464 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002465 ptr = &depPaths.LateSharedLibs
2466 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002467 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002468 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002469 ptr = nil
2470 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002471 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002472 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002473 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002474 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002475 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002476 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002477 return
2478 }
2479
Ivan Lozano52767be2019-10-18 14:49:46 -07002480 // Because the static library objects are included, this only makes sense
2481 // in the context of proper cc.Modules.
2482 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2483 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2484 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2485 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2486 for i := range missingDeps {
2487 missingDeps[i] += postfix
2488 }
2489 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002490 }
Martin Stjernholm391d94c2020-04-17 17:34:31 +01002491 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2492 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2493 } else {
2494 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2495 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002496 } else {
2497 ctx.ModuleErrorf(
2498 "non-cc.Modules cannot be included as whole static libraries.", depName)
2499 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002500 }
Colin Cross5950f382016-12-13 12:50:57 -08002501 case headerDepTag:
2502 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002503 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002504 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002505 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002506 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002507 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002508 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002509 case dynamicLinkerDepTag:
2510 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002511 }
2512
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002513 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002514 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002515 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002516 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002517 return
2518 }
2519
2520 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002521 // in static libraries act as if they were whole static libraries. The same goes for
2522 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002523 if c, ok := ccDep.(*Module); ok {
2524 staticLib := c.linker.(libraryInterface)
2525 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2526 staticLib.objs().coverageFiles...)
2527 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2528 staticLib.objs().sAbiDumpFiles...)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002529 } else if c, ok := ccDep.(LinkableInterface); ok {
2530 // Handle non-CC modules here
2531 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2532 c.CoverageFiles()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002533 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002534 }
2535
Colin Cross26c34ed2016-09-30 17:10:16 -07002536 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002537 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002538 if !ctx.Config().AllowMissingDependencies() {
2539 ctx.ModuleErrorf("module %q missing output file", depName)
2540 } else {
2541 ctx.AddMissingDependencies([]string{depName})
2542 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002543 return
2544 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002545 *ptr = append(*ptr, linkFile.Path())
2546 }
2547
Colin Crossc99deeb2016-04-11 15:06:20 -07002548 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002549 dep := depFile
2550 if !dep.Valid() {
2551 dep = linkFile
2552 }
2553 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002554 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002555
Inseob Kimeec88e12020-01-22 11:11:29 +09002556 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2557
2558 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002559 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002560 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002561 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002562 return libName
2563 }
2564
2565 makeLibName := func(depName string) string {
2566 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002567 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002568 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002569 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002570
Inseob Kimeec88e12020-01-22 11:11:29 +09002571 if c, ok := ccDep.(*Module); ok {
2572 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim752edec2020-03-14 01:30:34 +09002573 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002574 baseName := c.BaseModuleName()
Inseob Kim752edec2020-03-14 01:30:34 +09002575
2576 if c.IsVndk() {
2577 return baseName + ".vendor"
2578 }
2579
Inseob Kimeec88e12020-01-22 11:11:29 +09002580 if vendorSuffixModules[baseName] {
2581 return baseName + ".vendor"
2582 } else {
2583 return baseName
2584 }
2585 }
2586 }
2587
Yifan Hong1b3348d2020-01-21 15:53:22 -08002588 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002589 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2590 // core module instead.
2591 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002592 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002593 // The vendor module in Make will have been renamed to not conflict with the core
2594 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002595 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002596 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002597 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002598 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2599 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002600 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002601 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002602 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002603 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002604 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002605 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002606 }
Logan Chien43d34c32017-12-20 01:17:32 +08002607 }
2608
2609 // Export the shared libs to Make.
2610 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002611 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002612 if ccDep.CcLibrary() {
2613 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002614 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002615 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002616 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002617 c.Properties.ApexesProvidingSharedLibs = append(
2618 c.Properties.ApexesProvidingSharedLibs, an)
2619 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002620 }
2621 }
2622
Jiyong Park27b188b2017-07-18 13:23:39 +09002623 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002624 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002625 c.Properties.AndroidMkSharedLibs = append(
2626 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002627 // Record baseLibName for snapshots.
2628 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002629 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002630 c.Properties.AndroidMkSharedLibs = append(
2631 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002632 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002633 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002634 c.Properties.AndroidMkStaticLibs = append(
2635 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002636 case runtimeDepTag:
2637 c.Properties.AndroidMkRuntimeLibs = append(
2638 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002639 // Record baseLibName for snapshots.
2640 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002641 case wholeStaticDepTag:
2642 c.Properties.AndroidMkWholeStaticLibs = append(
2643 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Bill Peckhama46de702020-04-21 17:23:37 -07002644 case headerDepTag:
2645 c.Properties.AndroidMkHeaderLibs = append(
2646 c.Properties.AndroidMkHeaderLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002647 }
Colin Crossca860ac2016-01-04 14:34:37 -08002648 })
2649
Jeff Gaston294356f2017-09-27 17:05:30 -07002650 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002651 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002652
Colin Crossdd84e052017-05-17 13:44:16 -07002653 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002654 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002655 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2656 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002657 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002658 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002659 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2660 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002661 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002662 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002663 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002664
2665 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002666 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002667 }
Colin Crossdd84e052017-05-17 13:44:16 -07002668
Colin Crossca860ac2016-01-04 14:34:37 -08002669 return depPaths
2670}
2671
2672func (c *Module) InstallInData() bool {
2673 if c.installer == nil {
2674 return false
2675 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002676 return c.installer.inData()
2677}
2678
2679func (c *Module) InstallInSanitizerDir() bool {
2680 if c.installer == nil {
2681 return false
2682 }
2683 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002684 return true
2685 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002686 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002687}
2688
Yifan Hong1b3348d2020-01-21 15:53:22 -08002689func (c *Module) InstallInRamdisk() bool {
2690 return c.InRamdisk()
2691}
2692
Jiyong Parkf9332f12018-02-01 00:54:12 +09002693func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002694 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002695}
2696
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002697func (c *Module) SkipInstall() {
2698 if c.installer == nil {
2699 c.ModuleBase.SkipInstall()
2700 return
2701 }
2702 c.installer.skipInstall(c)
2703}
2704
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002705func (c *Module) HostToolPath() android.OptionalPath {
2706 if c.installer == nil {
2707 return android.OptionalPath{}
2708 }
2709 return c.installer.hostToolPath()
2710}
2711
Nan Zhangd4e641b2017-07-12 12:55:28 -07002712func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2713 return c.outputFile
2714}
2715
Colin Cross41955e82019-05-29 14:40:35 -07002716func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2717 switch tag {
2718 case "":
2719 if c.outputFile.Valid() {
2720 return android.Paths{c.outputFile.Path()}, nil
2721 }
2722 return android.Paths{}, nil
2723 default:
2724 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002725 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002726}
2727
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002728func (c *Module) static() bool {
2729 if static, ok := c.linker.(interface {
2730 static() bool
2731 }); ok {
2732 return static.static()
2733 }
2734 return false
2735}
2736
Jiyong Park379de2f2018-12-19 02:47:14 +09002737func (c *Module) staticBinary() bool {
2738 if static, ok := c.linker.(interface {
2739 staticBinary() bool
2740 }); ok {
2741 return static.staticBinary()
2742 }
2743 return false
2744}
2745
Jiyong Park1d1119f2019-07-29 21:27:18 +09002746func (c *Module) header() bool {
2747 if h, ok := c.linker.(interface {
2748 header() bool
2749 }); ok {
2750 return h.header()
2751 }
2752 return false
2753}
2754
Jooyung Han38002912019-05-16 04:01:54 +09002755func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002756 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002757 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2758 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002759 return "native:vndk"
2760 }
Jooyung Han38002912019-05-16 04:01:54 +09002761 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002762 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002763 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002764 if Bool(c.VendorProperties.Vendor_available) {
2765 return "native:vndk"
2766 }
2767 return "native:vndk_private"
2768 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002769 if c.inProduct() {
2770 return "native:product"
2771 }
Jooyung Han38002912019-05-16 04:01:54 +09002772 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002773 } else if c.InRamdisk() {
2774 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002775 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002776 return "native:recovery"
2777 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2778 return "native:ndk:none:none"
2779 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2780 //family, link := getNdkStlFamilyAndLinkType(c)
2781 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002782 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002783 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002784 } else {
2785 return "native:platform"
2786 }
2787}
2788
Jiyong Park9d452992018-10-03 00:38:19 +09002789// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002790// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002791func (c *Module) IsInstallableToApex() bool {
2792 if shared, ok := c.linker.(interface {
2793 shared() bool
2794 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002795 // Stub libs and prebuilt libs in a versioned SDK are not
2796 // installable to APEX even though they are shared libs.
2797 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002798 } else if _, ok := c.linker.(testPerSrc); ok {
2799 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002800 }
2801 return false
2802}
2803
Jiyong Parka90ca002019-10-07 15:47:24 +09002804func (c *Module) AvailableFor(what string) bool {
2805 if linker, ok := c.linker.(interface {
2806 availableFor(string) bool
2807 }); ok {
2808 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2809 } else {
2810 return c.ApexModuleBase.AvailableFor(what)
2811 }
2812}
2813
Jiyong Park62304bb2020-04-13 16:19:48 +09002814func (c *Module) TestFor() []string {
2815 if test, ok := c.linker.(interface {
2816 testFor() []string
2817 }); ok {
2818 return test.testFor()
2819 } else {
2820 return c.ApexModuleBase.TestFor()
2821 }
2822}
2823
Paul Duffin0cb37b92020-03-04 14:52:46 +00002824// Return true if the module is ever installable.
2825func (c *Module) EverInstallable() bool {
2826 return c.installer != nil &&
2827 // Check to see whether the module is actually ever installable.
2828 c.installer.everInstallable()
2829}
2830
Inseob Kim1f086e22019-05-09 13:29:15 +09002831func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002832 ret := c.EverInstallable() &&
2833 // Check to see whether the module has been configured to not be installed.
2834 proptools.BoolDefault(c.Properties.Installable, true) &&
2835 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002836
2837 // The platform variant doesn't need further condition. Apex variants however might not
2838 // be installable because it will likely to be included in the APEX and won't appear
2839 // in the system partition.
2840 if c.IsForPlatform() {
2841 return ret
2842 }
2843
2844 // Special case for modules that are configured to be installed to /data, which includes
2845 // test modules. For these modules, both APEX and non-APEX variants are considered as
2846 // installable. This is because even the APEX variants won't be included in the APEX, but
2847 // will anyway be installed to /data/*.
2848 // See b/146995717
2849 if c.InstallInData() {
2850 return ret
2851 }
2852
2853 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002854}
2855
Logan Chien41eabe62019-04-10 13:33:58 +08002856func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2857 if c.linker != nil {
2858 if library, ok := c.linker.(*libraryDecorator); ok {
2859 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2860 }
2861 }
2862}
2863
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002864func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002865 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002866 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002867 if cc.HasStubsVariants() {
2868 if depTag.Shared && depTag.Library {
2869 // dynamic dep to a stubs lib crosses APEX boundary
2870 return false
2871 }
2872 if IsRuntimeDepTag(depTag) {
2873 // runtime dep to a stubs lib also crosses APEX boundary
2874 return false
2875 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002876 }
2877 if depTag.FromStatic {
2878 // shared_lib dependency from a static lib is considered as crossing
2879 // the APEX boundary because the dependency doesn't actually is
2880 // linked; the dependency is used only during the compilation phase.
2881 return false
2882 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002883 }
Jiyong Park7d95a512020-05-10 15:16:24 +09002884 } else if ctx.OtherModuleDependencyTag(dep) == llndkImplDep {
2885 // We don't track beyond LLNDK
2886 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002887 }
2888 return true
2889}
2890
Colin Cross2ba19d92015-05-07 15:44:20 -07002891//
Colin Crosscfad1192015-11-02 16:43:11 -08002892// Defaults
2893//
Colin Crossca860ac2016-01-04 14:34:37 -08002894type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002895 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002896 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002897 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002898}
2899
Patrice Arrudac249c712019-03-19 17:00:29 -07002900// cc_defaults provides a set of properties that can be inherited by other cc
2901// modules. A module can use the properties from a cc_defaults using
2902// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2903// merged (when possible) by prepending the default module's values to the
2904// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002905func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002906 return DefaultsFactory()
2907}
2908
Colin Cross36242852017-06-23 15:06:31 -07002909func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002910 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002911
Colin Cross36242852017-06-23 15:06:31 -07002912 module.AddProperties(props...)
2913 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002914 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002915 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002916 &BaseCompilerProperties{},
2917 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002918 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002919 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002920 &StaticProperties{},
2921 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002922 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002923 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002924 &TestProperties{},
2925 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002926 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002927 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002928 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002929 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002930 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002931 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002932 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002933 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002934 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002935 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002936 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002937 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002938 )
Colin Crosscfad1192015-11-02 16:43:11 -08002939
Jooyung Hancc372c52019-09-25 15:18:44 +09002940 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002941
2942 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002943}
2944
Jiyong Park6a43f042017-10-12 23:05:00 +09002945func squashVendorSrcs(m *Module) {
2946 if lib, ok := m.compiler.(*libraryDecorator); ok {
2947 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2948 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2949
2950 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2951 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2952 }
2953}
2954
Jiyong Parkf9332f12018-02-01 00:54:12 +09002955func squashRecoverySrcs(m *Module) {
2956 if lib, ok := m.compiler.(*libraryDecorator); ok {
2957 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2958 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2959
2960 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2961 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2962 }
2963}
2964
Colin Cross7228ecd2019-11-18 16:00:16 -08002965var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002966
Colin Cross7228ecd2019-11-18 16:00:16 -08002967func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002968 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002969 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002970 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002971
2972 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002973 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002974 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002975 }
Logan Chienf3511742017-10-31 18:04:35 +08002976
2977 if vndkdep := m.vndkdep; vndkdep != nil {
2978 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09002979 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002980 if !vndkdep.isVndkExt() {
2981 mctx.PropertyErrorf("vndk",
2982 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09002983 } else if m.VendorProperties.Vendor_available != nil {
2984 mctx.PropertyErrorf("vendor_available",
2985 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002986 }
2987 } else {
2988 if vndkdep.isVndkExt() {
2989 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09002990 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002991 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002992 }
2993 if m.VendorProperties.Vendor_available == nil {
2994 mctx.PropertyErrorf("vndk",
2995 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002996 }
2997 }
2998 } else {
2999 if vndkdep.isVndkSp() {
3000 mctx.PropertyErrorf("vndk",
3001 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08003002 }
3003 if vndkdep.isVndkExt() {
3004 mctx.PropertyErrorf("vndk",
3005 "must set `enabled: true` to set `extends: %q`",
3006 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08003007 }
Justin Yun8effde42017-06-23 19:24:43 +09003008 }
3009 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003010
Jiyong Parkf9332f12018-02-01 00:54:12 +09003011 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08003012 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09003013 var recoveryVariantNeeded bool = false
3014
Inseob Kim64c43952019-08-26 16:52:35 +09003015 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09003016 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09003017
3018 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09003019 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
3020 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
3021 if boardVndkVersion == "current" {
3022 boardVndkVersion = platformVndkVersion
3023 }
3024 if productVndkVersion == "current" {
3025 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09003026 }
3027
Justin Yun5f7f7e82019-11-18 19:52:14 +09003028 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003029 // If the device isn't compiling against the VNDK, we always
3030 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003031 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003032 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003033 // LL-NDK stubs only exist in the vendor and product variants,
3034 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09003035 vendorVariants = append(vendorVariants,
3036 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003037 boardVndkVersion,
3038 )
3039 productVariants = append(productVariants,
3040 platformVndkVersion,
3041 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003042 )
Jiyong Park2a454122017-10-19 15:59:33 +09003043 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
3044 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09003045 vendorVariants = append(vendorVariants,
3046 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003047 boardVndkVersion,
3048 )
3049 productVariants = append(productVariants,
3050 platformVndkVersion,
3051 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003052 )
Inseob Kimeec88e12020-01-22 11:11:29 +09003053 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09003054 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
3055 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09003056 if snapshot, ok := m.linker.(interface {
3057 version() string
3058 }); ok {
3059 vendorVariants = append(vendorVariants, snapshot.version())
3060 } else {
3061 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
3062 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09003063 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003064 // This will be available in /system, /vendor and /product
3065 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003066 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09003067 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09003068 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09003069 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
3070 // code is PLATFORM_VNDK_VERSION.
3071 // On the other hand, vendor_available modules which are not VNDK should
3072 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09003073 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09003074 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003075 vendorVariants = append(vendorVariants, boardVndkVersion)
3076 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09003077 }
Logan Chienf3511742017-10-31 18:04:35 +08003078 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09003079 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09003080 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003081 } else {
3082 // This is either in /system (or similar: /data), or is a
3083 // modules built with the NDK. Modules built with the NDK
3084 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003085 coreVariantNeeded = true
3086 }
3087
Justin Yun5f7f7e82019-11-18 19:52:14 +09003088 if boardVndkVersion != "" && productVndkVersion != "" {
3089 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
3090 // The module has "product_specific: true" that does not create core variant.
3091 coreVariantNeeded = false
3092 productVariants = append(productVariants, productVndkVersion)
3093 }
3094 } else {
3095 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
3096 // restriction to use system libs.
3097 // No product variants defined in this case.
3098 productVariants = []string{}
3099 }
3100
Yifan Hong1b3348d2020-01-21 15:53:22 -08003101 if Bool(m.Properties.Ramdisk_available) {
3102 ramdiskVariantNeeded = true
3103 }
3104
3105 if m.ModuleBase.InstallInRamdisk() {
3106 ramdiskVariantNeeded = true
3107 coreVariantNeeded = false
3108 }
3109
Jiyong Parkf9332f12018-02-01 00:54:12 +09003110 if Bool(m.Properties.Recovery_available) {
3111 recoveryVariantNeeded = true
3112 }
3113
3114 if m.ModuleBase.InstallInRecovery() {
3115 recoveryVariantNeeded = true
3116 coreVariantNeeded = false
3117 }
3118
Inseob Kim64c43952019-08-26 16:52:35 +09003119 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003120 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3121 }
3122
3123 for _, variant := range android.FirstUniqueStrings(productVariants) {
3124 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003125 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003126
Yifan Hong1b3348d2020-01-21 15:53:22 -08003127 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003128 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3129 m.Properties.CoreVariantNeeded = coreVariantNeeded
3130}
3131
3132func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3133 return c.Properties.CoreVariantNeeded
3134}
3135
Yifan Hong1b3348d2020-01-21 15:53:22 -08003136func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3137 return c.Properties.RamdiskVariantNeeded
3138}
3139
Colin Cross7228ecd2019-11-18 16:00:16 -08003140func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3141 return c.Properties.RecoveryVariantNeeded
3142}
3143
3144func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003145 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003146}
3147
3148func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3149 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003150 if variant == android.RamdiskVariation {
3151 m.MakeAsPlatform()
3152 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003153 m.MakeAsPlatform()
3154 squashRecoverySrcs(m)
3155 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003156 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003157 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3158 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003159
3160 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3161 // Hide other vendor variants to avoid collision.
3162 vndkVersion := ctx.DeviceConfig().VndkVersion()
3163 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3164 m.Properties.HideFromMake = true
3165 m.SkipInstall()
3166 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003167 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3168 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3169 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3170 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003171 }
3172}
3173
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003174func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003175 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003176 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3177 }
Colin Cross6510f912017-11-29 00:27:14 -08003178 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003179}
3180
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003181func kytheExtractAllFactory() android.Singleton {
3182 return &kytheExtractAllSingleton{}
3183}
3184
3185type kytheExtractAllSingleton struct {
3186}
3187
3188func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3189 var xrefTargets android.Paths
3190 ctx.VisitAllModules(func(module android.Module) {
3191 if ccModule, ok := module.(xref); ok {
3192 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3193 }
3194 })
3195 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3196 if len(xrefTargets) > 0 {
3197 ctx.Build(pctx, android.BuildParams{
3198 Rule: blueprint.Phony,
3199 Output: android.PathForPhony(ctx, "xref_cxx"),
3200 Inputs: xrefTargets,
3201 //Default: true,
3202 })
3203 }
3204}
3205
Colin Cross06a931b2015-10-28 17:23:31 -07003206var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003207var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003208var BoolPtr = proptools.BoolPtr
3209var String = proptools.String
3210var StringPtr = proptools.StringPtr