blob: 69dcb8e33a2387ef2d3853a108a7f470c47a95c5 [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
Inseob Kim7f283f42020-06-01 21:53:49 +0900319 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900320 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700321 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900322 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700323 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800324 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700325 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800326 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900327 isLlndk(config android.Config) bool
328 isLlndkPublic(config android.Config) bool
329 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900330 isVndk() bool
331 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800332 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900333 inProduct() bool
334 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800335 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900336 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800337 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700338 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700339 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800340 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800341 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800342 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800343 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800344 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900345 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900346 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900347 hasStubsVariants() bool
348 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900349 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800350 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700351 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800352}
353
354type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700355 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800356 ModuleContextIntf
357}
358
359type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700360 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800361 ModuleContextIntf
362}
363
Colin Cross37047f12016-12-13 17:06:13 -0800364type DepsContext interface {
365 android.BottomUpMutatorContext
366 ModuleContextIntf
367}
368
Colin Crossca860ac2016-01-04 14:34:37 -0800369type feature interface {
370 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800371 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800372 flags(ctx ModuleContext, flags Flags) Flags
373 props() []interface{}
374}
375
376type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700377 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800378 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800379 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700380 compilerProps() []interface{}
381
Colin Cross76fada02016-07-27 10:31:13 -0700382 appendCflags([]string)
383 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700384 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800385}
386
387type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700388 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800389 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700390 linkerFlags(ctx ModuleContext, flags Flags) Flags
391 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800392 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700393
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700394 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700395 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900396 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700397
398 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900399 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000400
401 // Get the deps that have been explicitly specified in the properties.
402 // Only updates the
403 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
404}
405
406type specifiedDeps struct {
407 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000408 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800409}
410
411type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700412 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700413 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000414 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800415 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700416 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700417 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900418 relativeInstallPath() string
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100419 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800420}
421
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800422type xref interface {
423 XrefCcFiles() android.Paths
424}
425
Colin Crossc99deeb2016-04-11 15:06:20 -0700426var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700427 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
428 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
429 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
430 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
431 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800432 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700433 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
434 headerDepTag = DependencyTag{Name: "header", Library: true}
435 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
436 genSourceDepTag = DependencyTag{Name: "gen source"}
437 genHeaderDepTag = DependencyTag{Name: "gen header"}
438 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
439 objDepTag = DependencyTag{Name: "obj"}
440 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
441 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
442 reuseObjTag = DependencyTag{Name: "reuse objects"}
443 staticVariantTag = DependencyTag{Name: "static variant"}
444 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
445 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
446 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
447 runtimeDepTag = DependencyTag{Name: "runtime lib"}
Ivan Lozano183a3212019-10-18 14:18:45 -0700448 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700449)
450
Roland Levillainf89cd092019-07-29 16:22:59 +0100451func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700452 ccDepTag, ok := depTag.(DependencyTag)
453 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100454}
455
456func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700457 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100458 return ok && ccDepTag == runtimeDepTag
459}
460
461func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700462 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100463 return ok && ccDepTag == testPerSrcDepTag
464}
465
Colin Crossca860ac2016-01-04 14:34:37 -0800466// Module contains the properties and members used by all C/C++ module types, and implements
467// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
468// to construct the output file. Behavior can be customized with a Customizer interface
469type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700470 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700471 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900472 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900473 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700474
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700475 Properties BaseProperties
476 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700477
Colin Crossca860ac2016-01-04 14:34:37 -0800478 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700479 hod android.HostOrDeviceSupported
480 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700481
Paul Duffina0843f62019-12-13 19:50:38 +0000482 // Allowable SdkMemberTypes of this module type.
483 sdkMemberTypes []android.SdkMemberType
484
Colin Crossca860ac2016-01-04 14:34:37 -0800485 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700486 features []feature
487 compiler compiler
488 linker linker
489 installer installer
490 stl *stl
491 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800492 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800493 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900494 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700495 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700496 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800497
Colin Cross635c3b02016-05-18 15:37:25 -0700498 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800499
Colin Crossb98c8b02016-07-29 13:44:28 -0700500 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700501
502 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800503
504 // Flags used to compile this module
505 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700506
507 // 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 -0800508 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700509 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800510 depsInLinkOrder android.Paths
511
512 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700513 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900514
515 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800516 // Kythe (source file indexer) paths for this compilation module
517 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900518
519 // For apex variants, this is set as apex.min_sdk_version
520 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700521}
522
Ivan Lozano52767be2019-10-18 14:49:46 -0700523func (c *Module) Toc() android.OptionalPath {
524 if c.linker != nil {
525 if library, ok := c.linker.(libraryInterface); ok {
526 return library.toc()
527 }
528 }
529 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
530}
531
532func (c *Module) ApiLevel() string {
533 if c.linker != nil {
534 if stub, ok := c.linker.(*stubDecorator); ok {
535 return stub.properties.ApiLevel
536 }
537 }
538 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
539}
540
541func (c *Module) Static() bool {
542 if c.linker != nil {
543 if library, ok := c.linker.(libraryInterface); ok {
544 return library.static()
545 }
546 }
547 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
548}
549
550func (c *Module) Shared() bool {
551 if c.linker != nil {
552 if library, ok := c.linker.(libraryInterface); ok {
553 return library.shared()
554 }
555 }
556 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
557}
558
559func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000560 if c.stl != nil {
561 return c.stl.Properties.SelectedStl
562 }
563 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700564}
565
566func (c *Module) ToolchainLibrary() bool {
567 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
568 return true
569 }
570 return false
571}
572
573func (c *Module) NdkPrebuiltStl() bool {
574 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
575 return true
576 }
577 return false
578}
579
580func (c *Module) StubDecorator() bool {
581 if _, ok := c.linker.(*stubDecorator); ok {
582 return true
583 }
584 return false
585}
586
587func (c *Module) SdkVersion() string {
588 return String(c.Properties.Sdk_version)
589}
590
Artur Satayev480e25b2020-04-27 18:53:18 +0100591func (c *Module) MinSdkVersion() string {
592 return String(c.Properties.Min_sdk_version)
593}
594
Colin Crossc511bc52020-04-07 16:50:32 +0000595func (c *Module) AlwaysSdk() bool {
596 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
597}
598
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800599func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700600 if c.linker != nil {
601 if library, ok := c.linker.(exportedFlagsProducer); ok {
602 return library.exportedDirs()
603 }
604 }
605 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
606}
607
608func (c *Module) HasStaticVariant() bool {
609 if c.staticVariant != nil {
610 return true
611 }
612 return false
613}
614
615func (c *Module) GetStaticVariant() LinkableInterface {
616 return c.staticVariant
617}
618
619func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
620 c.depsInLinkOrder = depsInLinkOrder
621}
622
623func (c *Module) GetDepsInLinkOrder() []android.Path {
624 return c.depsInLinkOrder
625}
626
627func (c *Module) StubsVersions() []string {
628 if c.linker != nil {
629 if library, ok := c.linker.(*libraryDecorator); ok {
630 return library.Properties.Stubs.Versions
631 }
632 }
633 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
634}
635
636func (c *Module) CcLibrary() bool {
637 if c.linker != nil {
638 if _, ok := c.linker.(*libraryDecorator); ok {
639 return true
640 }
641 }
642 return false
643}
644
645func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700646 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700647 return true
648 }
649 return false
650}
651
Ivan Lozano2b262972019-11-21 12:30:50 -0800652func (c *Module) NonCcVariants() bool {
653 return false
654}
655
Ivan Lozano183a3212019-10-18 14:18:45 -0700656func (c *Module) SetBuildStubs() {
657 if c.linker != nil {
658 if library, ok := c.linker.(*libraryDecorator); ok {
659 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700660 c.Properties.HideFromMake = true
661 c.sanitize = nil
662 c.stl = nil
663 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700664 return
665 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000666 if _, ok := c.linker.(*llndkStubDecorator); ok {
667 c.Properties.HideFromMake = true
668 return
669 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700670 }
671 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
672}
673
Ivan Lozano52767be2019-10-18 14:49:46 -0700674func (c *Module) BuildStubs() bool {
675 if c.linker != nil {
676 if library, ok := c.linker.(*libraryDecorator); ok {
677 return library.buildStubs()
678 }
679 }
680 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
681}
682
Ivan Lozano183a3212019-10-18 14:18:45 -0700683func (c *Module) SetStubsVersions(version string) {
684 if c.linker != nil {
685 if library, ok := c.linker.(*libraryDecorator); ok {
686 library.MutatedProperties.StubsVersion = version
687 return
688 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000689 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
690 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
691 return
692 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700693 }
694 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
695}
696
Jooyung Han03b51852020-02-26 22:45:42 +0900697func (c *Module) StubsVersion() string {
698 if c.linker != nil {
699 if library, ok := c.linker.(*libraryDecorator); ok {
700 return library.MutatedProperties.StubsVersion
701 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000702 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
703 return llndk.libraryDecorator.MutatedProperties.StubsVersion
704 }
Jooyung Han03b51852020-02-26 22:45:42 +0900705 }
706 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
707}
708
Ivan Lozano183a3212019-10-18 14:18:45 -0700709func (c *Module) SetStatic() {
710 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700711 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700712 library.setStatic()
713 return
714 }
715 }
716 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
717}
718
719func (c *Module) SetShared() {
720 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700721 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700722 library.setShared()
723 return
724 }
725 }
726 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
727}
728
729func (c *Module) BuildStaticVariant() bool {
730 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700731 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700732 return library.buildStatic()
733 }
734 }
735 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
736}
737
738func (c *Module) BuildSharedVariant() bool {
739 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700740 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700741 return library.buildShared()
742 }
743 }
744 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
745}
746
747func (c *Module) Module() android.Module {
748 return c
749}
750
Jiyong Parkc20eee32018-09-05 22:36:17 +0900751func (c *Module) OutputFile() android.OptionalPath {
752 return c.outputFile
753}
754
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400755func (c *Module) CoverageFiles() android.Paths {
756 if c.linker != nil {
757 if library, ok := c.linker.(libraryInterface); ok {
758 return library.objs().coverageFiles
759 }
760 }
761 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
762}
763
Ivan Lozano183a3212019-10-18 14:18:45 -0700764var _ LinkableInterface = (*Module)(nil)
765
Jiyong Park719b4462019-01-13 00:39:51 +0900766func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900767 if c.linker != nil {
768 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900769 }
770 return nil
771}
772
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900773func (c *Module) CoverageOutputFile() android.OptionalPath {
774 if c.linker != nil {
775 return c.linker.coverageOutputFilePath()
776 }
777 return android.OptionalPath{}
778}
779
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900780func (c *Module) RelativeInstallPath() string {
781 if c.installer != nil {
782 return c.installer.relativeInstallPath()
783 }
784 return ""
785}
786
Jooyung Han344d5432019-08-23 11:17:39 +0900787func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900788 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900789}
790
Colin Cross36242852017-06-23 15:06:31 -0700791func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700792 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800793 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700794 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800795 }
796 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700797 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800798 }
799 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700800 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800801 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700802 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700803 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700804 }
Colin Cross16b23492016-01-06 14:41:07 -0800805 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700806 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800807 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800808 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700809 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800810 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800811 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700812 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800813 }
Justin Yun8effde42017-06-23 19:24:43 +0900814 if c.vndkdep != nil {
815 c.AddProperties(c.vndkdep.props()...)
816 }
Stephen Craneba090d12017-05-09 15:44:35 -0700817 if c.lto != nil {
818 c.AddProperties(c.lto.props()...)
819 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700820 if c.pgo != nil {
821 c.AddProperties(c.pgo.props()...)
822 }
Colin Crossca860ac2016-01-04 14:34:37 -0800823 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700824 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800825 }
Colin Crossc472d572015-03-17 15:06:21 -0700826
Colin Crossa9d8bee2018-10-02 13:59:46 -0700827 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
828 switch class {
829 case android.Device:
830 return ctx.Config().DevicePrefer32BitExecutables()
831 case android.HostCross:
832 // Windows builds always prefer 32-bit
833 return true
834 default:
835 return false
836 }
837 })
Colin Cross36242852017-06-23 15:06:31 -0700838 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900839 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900840 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900841 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900842
Colin Cross36242852017-06-23 15:06:31 -0700843 return c
Colin Crossc472d572015-03-17 15:06:21 -0700844}
845
Colin Crossb916a382016-07-29 17:28:03 -0700846// Returns true for dependency roots (binaries)
847// TODO(ccross): also handle dlopenable libraries
848func (c *Module) isDependencyRoot() bool {
849 if root, ok := c.linker.(interface {
850 isDependencyRoot() bool
851 }); ok {
852 return root.isDependencyRoot()
853 }
854 return false
855}
856
Justin Yun5f7f7e82019-11-18 19:52:14 +0900857// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
858// "product" and "vendor" variant modules return true for this function.
859// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
860// "soc_specific: true" and more vendor installed modules are included here.
861// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
862// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700863func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900864 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700865}
866
Colin Crossc511bc52020-04-07 16:50:32 +0000867func (c *Module) canUseSdk() bool {
868 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
869}
870
871func (c *Module) UseSdk() bool {
872 if c.canUseSdk() {
873 return String(c.Properties.Sdk_version) != ""
874 }
875 return false
876}
877
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800878func (c *Module) isCoverageVariant() bool {
879 return c.coverage.Properties.IsCoverageVariant
880}
881
Peter Collingbournead84f972019-12-17 16:46:18 -0800882func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800883 return inList(c.Name(), ndkMigratedLibs)
884}
885
Inseob Kim9516ee92019-05-09 10:56:13 +0900886func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800887 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900888 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800889}
890
Inseob Kim9516ee92019-05-09 10:56:13 +0900891func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800892 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900893 name := c.BaseModuleName()
894 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800895}
896
Inseob Kim9516ee92019-05-09 10:56:13 +0900897func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800898 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900899 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800900}
901
Ivan Lozano52767be2019-10-18 14:49:46 -0700902func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800903 if vndkdep := c.vndkdep; vndkdep != nil {
904 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900905 }
906 return false
907}
908
Yi Kong7e53c572018-02-14 18:16:12 +0800909func (c *Module) isPgoCompile() bool {
910 if pgo := c.pgo; pgo != nil {
911 return pgo.Properties.PgoCompile
912 }
913 return false
914}
915
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800916func (c *Module) isNDKStubLibrary() bool {
917 if _, ok := c.compiler.(*stubDecorator); ok {
918 return true
919 }
920 return false
921}
922
Logan Chienf3511742017-10-31 18:04:35 +0800923func (c *Module) isVndkSp() bool {
924 if vndkdep := c.vndkdep; vndkdep != nil {
925 return vndkdep.isVndkSp()
926 }
927 return false
928}
929
930func (c *Module) isVndkExt() bool {
931 if vndkdep := c.vndkdep; vndkdep != nil {
932 return vndkdep.isVndkExt()
933 }
934 return false
935}
936
Ivan Lozano52767be2019-10-18 14:49:46 -0700937func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900938 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800939}
940
Logan Chienf3511742017-10-31 18:04:35 +0800941func (c *Module) getVndkExtendsModuleName() string {
942 if vndkdep := c.vndkdep; vndkdep != nil {
943 return vndkdep.getVndkExtendsModuleName()
944 }
945 return ""
946}
947
Justin Yun5f7f7e82019-11-18 19:52:14 +0900948// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900949// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700950func (c *Module) HasVendorVariant() bool {
951 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900952}
953
Justin Yun5f7f7e82019-11-18 19:52:14 +0900954const (
955 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
956 // against the VNDK.
957 VendorVariationPrefix = "vendor."
958
959 // ProductVariationPrefix is the variant prefix used for /product code that compiles
960 // against the VNDK.
961 ProductVariationPrefix = "product."
962)
963
964// Returns true if the module is "product" variant. Usually these modules are installed in /product
965func (c *Module) inProduct() bool {
966 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
967}
968
969// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
970func (c *Module) inVendor() bool {
971 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
972}
973
Yifan Hong1b3348d2020-01-21 15:53:22 -0800974func (c *Module) InRamdisk() bool {
975 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
976}
977
Ivan Lozano52767be2019-10-18 14:49:46 -0700978func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800979 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900980}
981
Yifan Hong1b3348d2020-01-21 15:53:22 -0800982func (c *Module) OnlyInRamdisk() bool {
983 return c.ModuleBase.InstallInRamdisk()
984}
985
Ivan Lozano52767be2019-10-18 14:49:46 -0700986func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900987 return c.ModuleBase.InstallInRecovery()
988}
989
Jiyong Park25fc6a92018-11-18 18:02:45 +0900990func (c *Module) IsStubs() bool {
991 if library, ok := c.linker.(*libraryDecorator); ok {
992 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900993 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
994 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900995 }
996 return false
997}
998
999func (c *Module) HasStubsVariants() bool {
1000 if library, ok := c.linker.(*libraryDecorator); ok {
1001 return len(library.Properties.Stubs.Versions) > 0
1002 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001003 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1004 return len(library.Properties.Stubs.Versions) > 0
1005 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001006 return false
1007}
1008
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001009func (c *Module) bootstrap() bool {
1010 return Bool(c.Properties.Bootstrap)
1011}
1012
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001013func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001014 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1015 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1016 return false
1017 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001018 return c.linker != nil && c.linker.nativeCoverage()
1019}
1020
Inseob Kim8471cda2019-11-15 09:59:12 +09001021func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001022 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1023 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001024 }
1025 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001026}
1027
Jiyong Park73c54ee2019-10-22 20:31:18 +09001028func (c *Module) ExportedIncludeDirs() android.Paths {
1029 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1030 return flagsProducer.exportedDirs()
1031 }
Jiyong Park232e7852019-11-04 12:23:40 +09001032 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001033}
1034
1035func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1036 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1037 return flagsProducer.exportedSystemDirs()
1038 }
Jiyong Park232e7852019-11-04 12:23:40 +09001039 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001040}
1041
1042func (c *Module) ExportedFlags() []string {
1043 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1044 return flagsProducer.exportedFlags()
1045 }
Jiyong Park232e7852019-11-04 12:23:40 +09001046 return nil
1047}
1048
1049func (c *Module) ExportedDeps() android.Paths {
1050 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1051 return flagsProducer.exportedDeps()
1052 }
1053 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001054}
1055
Inseob Kimd110f872019-12-06 13:15:38 +09001056func (c *Module) ExportedGeneratedHeaders() android.Paths {
1057 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1058 return flagsProducer.exportedGeneratedHeaders()
1059 }
1060 return nil
1061}
1062
Jiyong Parkf1194352019-02-25 11:05:47 +09001063func isBionic(name string) bool {
1064 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001065 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001066 return true
1067 }
1068 return false
1069}
1070
Martin Stjernholm279de572019-09-10 23:18:20 +01001071func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001072 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001073 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001074 }
1075 return isBionic(name)
1076}
1077
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001078func (c *Module) XrefCcFiles() android.Paths {
1079 return c.kytheFiles
1080}
1081
Colin Crossca860ac2016-01-04 14:34:37 -08001082type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001083 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001084 moduleContextImpl
1085}
1086
Colin Cross37047f12016-12-13 17:06:13 -08001087type depsContext struct {
1088 android.BottomUpMutatorContext
1089 moduleContextImpl
1090}
1091
Colin Crossca860ac2016-01-04 14:34:37 -08001092type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001093 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001094 moduleContextImpl
1095}
1096
Justin Yun5f7f7e82019-11-18 19:52:14 +09001097func (ctx *moduleContext) ProductSpecific() bool {
1098 return ctx.ModuleContext.ProductSpecific() ||
1099 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1100}
1101
Jiyong Park2db76922017-11-08 16:03:48 +09001102func (ctx *moduleContext) SocSpecific() bool {
1103 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001104 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001105}
1106
Colin Crossca860ac2016-01-04 14:34:37 -08001107type moduleContextImpl struct {
1108 mod *Module
1109 ctx BaseModuleContext
1110}
1111
Colin Crossb98c8b02016-07-29 13:44:28 -07001112func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001113 return ctx.mod.toolchain(ctx.ctx)
1114}
1115
1116func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001117 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001118}
1119
1120func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001121 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001122}
1123
Jiyong Park1d1119f2019-07-29 21:27:18 +09001124func (ctx *moduleContextImpl) header() bool {
1125 return ctx.mod.header()
1126}
1127
Inseob Kim7f283f42020-06-01 21:53:49 +09001128func (ctx *moduleContextImpl) binary() bool {
1129 return ctx.mod.binary()
1130}
1131
Inseob Kim1042d292020-06-01 23:23:05 +09001132func (ctx *moduleContextImpl) object() bool {
1133 return ctx.mod.object()
1134}
1135
Jooyung Hanccce2f22020-03-07 03:45:53 +09001136func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001137 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001138}
1139
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001140func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001141 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001142}
1143
1144func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001145 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001146 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001147 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001148 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001149 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001150 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001151 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001152 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001153 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001154 }
1155 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001156}
1157
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001158func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001159 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001160}
Justin Yun8effde42017-06-23 19:24:43 +09001161
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001162func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001163 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001164}
1165
Inseob Kim9516ee92019-05-09 10:56:13 +09001166func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1167 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001168}
1169
Inseob Kim9516ee92019-05-09 10:56:13 +09001170func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1171 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001172}
1173
Inseob Kim9516ee92019-05-09 10:56:13 +09001174func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1175 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001176}
1177
Logan Chienf3511742017-10-31 18:04:35 +08001178func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001179 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001180}
1181
Yi Kong7e53c572018-02-14 18:16:12 +08001182func (ctx *moduleContextImpl) isPgoCompile() bool {
1183 return ctx.mod.isPgoCompile()
1184}
1185
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001186func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1187 return ctx.mod.isNDKStubLibrary()
1188}
1189
Justin Yun8effde42017-06-23 19:24:43 +09001190func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001191 return ctx.mod.isVndkSp()
1192}
1193
1194func (ctx *moduleContextImpl) isVndkExt() bool {
1195 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001196}
1197
Vic Yangefd249e2018-11-12 20:19:56 -08001198func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001199 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001200}
1201
Justin Yun5f7f7e82019-11-18 19:52:14 +09001202func (ctx *moduleContextImpl) inProduct() bool {
1203 return ctx.mod.inProduct()
1204}
1205
1206func (ctx *moduleContextImpl) inVendor() bool {
1207 return ctx.mod.inVendor()
1208}
1209
Yifan Hong1b3348d2020-01-21 15:53:22 -08001210func (ctx *moduleContextImpl) inRamdisk() bool {
1211 return ctx.mod.InRamdisk()
1212}
1213
Jiyong Parkf9332f12018-02-01 00:54:12 +09001214func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001215 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001216}
1217
Logan Chien2f2b8902018-07-10 15:01:19 +08001218// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001219func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001220 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1221 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001222 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001223
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001224 // Coverage builds have extra symbols.
1225 if ctx.mod.isCoverageVariant() {
1226 return false
1227 }
1228
Doug Hornc32c6b02019-01-17 14:44:05 -08001229 if ctx.ctx.Fuchsia() {
1230 return false
1231 }
1232
Logan Chien2f2b8902018-07-10 15:01:19 +08001233 if sanitize := ctx.mod.sanitize; sanitize != nil {
1234 if !sanitize.isVariantOnProductionDevice() {
1235 return false
1236 }
1237 }
1238 if !ctx.ctx.Device() {
1239 // Host modules do not need ABI dumps.
1240 return false
1241 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001242 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001243 // Stubs do not need ABI dumps.
1244 return false
1245 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001246 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001247}
1248
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001249func (ctx *moduleContextImpl) selectedStl() string {
1250 if stl := ctx.mod.stl; stl != nil {
1251 return stl.Properties.SelectedStl
1252 }
1253 return ""
1254}
1255
Ivan Lozanobd721262018-11-27 14:33:03 -08001256func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1257 return ctx.mod.linker.useClangLld(actx)
1258}
1259
Colin Crossce75d2c2016-10-06 16:12:58 -07001260func (ctx *moduleContextImpl) baseModuleName() string {
1261 return ctx.mod.ModuleBase.BaseModuleName()
1262}
1263
Logan Chienf3511742017-10-31 18:04:35 +08001264func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1265 return ctx.mod.getVndkExtendsModuleName()
1266}
1267
Logan Chiene274fc92019-12-03 11:18:32 -08001268func (ctx *moduleContextImpl) isForPlatform() bool {
1269 return ctx.mod.IsForPlatform()
1270}
1271
Jiyong Park58e364a2019-01-19 19:24:06 +09001272func (ctx *moduleContextImpl) apexName() string {
1273 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001274}
1275
Jooyung Hanccce2f22020-03-07 03:45:53 +09001276func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001277 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001278}
1279
Jiyong Parkb0788572018-12-20 22:10:17 +09001280func (ctx *moduleContextImpl) hasStubsVariants() bool {
1281 return ctx.mod.HasStubsVariants()
1282}
1283
1284func (ctx *moduleContextImpl) isStubs() bool {
1285 return ctx.mod.IsStubs()
1286}
1287
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001288func (ctx *moduleContextImpl) bootstrap() bool {
1289 return ctx.mod.bootstrap()
1290}
1291
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001292func (ctx *moduleContextImpl) nativeCoverage() bool {
1293 return ctx.mod.nativeCoverage()
1294}
1295
Colin Cross635c3b02016-05-18 15:37:25 -07001296func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001297 return &Module{
1298 hod: hod,
1299 multilib: multilib,
1300 }
1301}
1302
Colin Cross635c3b02016-05-18 15:37:25 -07001303func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001304 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001305 module.features = []feature{
1306 &tidyFeature{},
1307 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001308 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001309 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001310 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001311 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001312 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001313 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001314 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001315 return module
1316}
1317
Colin Crossce75d2c2016-10-06 16:12:58 -07001318func (c *Module) Prebuilt() *android.Prebuilt {
1319 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1320 return p.prebuilt()
1321 }
1322 return nil
1323}
1324
1325func (c *Module) Name() string {
1326 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001327 if p, ok := c.linker.(interface {
1328 Name(string) string
1329 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001330 name = p.Name(name)
1331 }
1332 return name
1333}
1334
Alex Light3d673592019-01-18 14:37:31 -08001335func (c *Module) Symlinks() []string {
1336 if p, ok := c.installer.(interface {
1337 symlinkList() []string
1338 }); ok {
1339 return p.symlinkList()
1340 }
1341 return nil
1342}
1343
Jeff Gaston294356f2017-09-27 17:05:30 -07001344// orderDeps reorders dependencies into a list such that if module A depends on B, then
1345// A will precede B in the resultant list.
1346// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001347// Note that directSharedDeps should be the analogous static library for each shared lib dep
1348func 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 -07001349 // If A depends on B, then
1350 // Every list containing A will also contain B later in the list
1351 // So, after concatenating all lists, the final instance of B will have come from the same
1352 // original list as the final instance of A
1353 // So, the final instance of B will be later in the concatenation than the final A
1354 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1355 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001356 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001357 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001358 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1359 }
1360 for _, dep := range directSharedDeps {
1361 orderedAllDeps = append(orderedAllDeps, dep)
1362 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001363 }
1364
Colin Crossb6715442017-10-24 11:13:31 -07001365 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001366
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001367 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001368 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001369 // resultant list to only what the caller has chosen to include in directStaticDeps
1370 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001371
1372 return orderedAllDeps, orderedDeclaredDeps
1373}
1374
Ivan Lozano183a3212019-10-18 14:18:45 -07001375func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001376 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001377 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001378 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1379 staticDepFiles := []android.Path{}
1380 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001381 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1382 if dep.OutputFile().Valid() {
1383 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1384 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1385 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001386 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001387 sharedDepFiles := []android.Path{}
1388 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001389 if sharedDep.HasStaticVariant() {
1390 staticAnalogue := sharedDep.GetStaticVariant()
1391 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1392 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001393 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001394 }
1395
1396 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001397 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1398 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001399
1400 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001401}
1402
Roland Levillainf89cd092019-07-29 16:22:59 +01001403func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1404 test, ok := c.linker.(testPerSrc)
1405 return ok && test.isAllTestsVariation()
1406}
1407
Liz Kammer1c14a212020-05-12 15:26:55 -07001408func (c *Module) DataPaths() android.Paths {
1409 if p, ok := c.installer.(interface {
1410 dataPaths() android.Paths
1411 }); ok {
1412 return p.dataPaths()
1413 }
1414 return nil
1415}
1416
Justin Yun5f7f7e82019-11-18 19:52:14 +09001417func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1418 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1419 // "current", it will append the VNDK version to the name suffix.
1420 var vndkVersion string
1421 var nameSuffix string
1422 if c.inProduct() {
1423 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1424 nameSuffix = productSuffix
1425 } else {
1426 vndkVersion = ctx.DeviceConfig().VndkVersion()
1427 nameSuffix = vendorSuffix
1428 }
1429 if vndkVersion == "current" {
1430 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1431 }
1432 if c.Properties.VndkVersion != vndkVersion {
1433 // add version suffix only if the module is using different vndk version than the
1434 // version in product or vendor partition.
1435 nameSuffix += "." + c.Properties.VndkVersion
1436 }
1437 return nameSuffix
1438}
1439
Colin Cross635c3b02016-05-18 15:37:25 -07001440func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001441 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001442 //
1443 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1444 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1445 // module and return early, as this module does not produce an output file per se.
1446 if c.IsTestPerSrcAllTestsVariation() {
1447 c.outputFile = android.OptionalPath{}
1448 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001449 }
1450
Jooyung Han38002912019-05-16 04:01:54 +09001451 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001452
Inseob Kim64c43952019-08-26 16:52:35 +09001453 c.Properties.SubName = ""
1454
1455 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1456 c.Properties.SubName += nativeBridgeSuffix
1457 }
1458
Justin Yun5f7f7e82019-11-18 19:52:14 +09001459 _, llndk := c.linker.(*llndkStubDecorator)
1460 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1461 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1462 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1463 // added for product variant only when we have vendor and product variants with core
1464 // variant. The suffix is not added for vendor-only or product-only module.
1465 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1466 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001467 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1468 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1469 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001470 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1471 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001472 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001473 c.Properties.SubName += recoverySuffix
Colin Crossc511bc52020-04-07 16:50:32 +00001474 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1475 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001476 }
1477
Colin Crossca860ac2016-01-04 14:34:37 -08001478 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001479 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001480 moduleContextImpl: moduleContextImpl{
1481 mod: c,
1482 },
1483 }
1484 ctx.ctx = ctx
1485
Colin Crossf18e1102017-11-16 14:33:08 -08001486 deps := c.depsToPaths(ctx)
1487 if ctx.Failed() {
1488 return
1489 }
1490
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001491 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1492 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1493 }
1494
Colin Crossca860ac2016-01-04 14:34:37 -08001495 flags := Flags{
1496 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001497 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001498 }
Colin Crossca860ac2016-01-04 14:34:37 -08001499 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001500 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001501 }
1502 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001503 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001504 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001505 if c.stl != nil {
1506 flags = c.stl.flags(ctx, flags)
1507 }
Colin Cross16b23492016-01-06 14:41:07 -08001508 if c.sanitize != nil {
1509 flags = c.sanitize.flags(ctx, flags)
1510 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001511 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001512 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001513 }
Stephen Craneba090d12017-05-09 15:44:35 -07001514 if c.lto != nil {
1515 flags = c.lto.flags(ctx, flags)
1516 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001517 if c.pgo != nil {
1518 flags = c.pgo.flags(ctx, flags)
1519 }
Colin Crossca860ac2016-01-04 14:34:37 -08001520 for _, feature := range c.features {
1521 flags = feature.flags(ctx, flags)
1522 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001523 if ctx.Failed() {
1524 return
1525 }
1526
Colin Cross4af21ed2019-11-04 09:37:55 -08001527 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1528 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1529 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001530
Colin Cross4af21ed2019-11-04 09:37:55 -08001531 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001532
1533 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001534 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001535 }
1536 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001537 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001538 }
1539
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001540 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001541 // We need access to all the flags seen by a source file.
1542 if c.sabi != nil {
1543 flags = c.sabi.flags(ctx, flags)
1544 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001545
Colin Cross4af21ed2019-11-04 09:37:55 -08001546 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001547
Colin Crossca860ac2016-01-04 14:34:37 -08001548 // Optimization to reduce size of build.ninja
1549 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001550 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1551 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1552 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1553 flags.Local.CFlags = []string{"$cflags"}
1554 flags.Local.CppFlags = []string{"$cppflags"}
1555 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001556
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001557 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001558 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001559 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001560 if ctx.Failed() {
1561 return
1562 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001563 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001564 }
1565
Colin Crossca860ac2016-01-04 14:34:37 -08001566 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001567 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001568 if ctx.Failed() {
1569 return
1570 }
Colin Cross635c3b02016-05-18 15:37:25 -07001571 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001572
1573 // If a lib is directly included in any of the APEXes, unhide the stubs
1574 // variant having the latest version gets visible to make. In addition,
1575 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1576 // force anything in the make world to link against the stubs library.
1577 // (unless it is explicitly referenced via .bootstrap suffix or the
1578 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001579 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001580 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001581 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001582 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001583 c.Properties.HideFromMake = false // unhide
1584 // Note: this is still non-installable
1585 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001586
1587 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1588 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1589 if isSnapshotAware(ctx, c) {
1590 i.collectHeadersForSnapshot(ctx)
1591 }
1592 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001593 }
Colin Cross5049f022015-03-18 13:28:46 -07001594
Inseob Kim1f086e22019-05-09 13:29:15 +09001595 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001596 c.installer.install(ctx, c.outputFile.Path())
1597 if ctx.Failed() {
1598 return
Colin Crossca860ac2016-01-04 14:34:37 -08001599 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001600 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1601 // If the module has been specifically configure to not be installed then
1602 // skip the installation as otherwise it will break when running inside make
1603 // as the output path to install will not be specified. Not all uninstallable
1604 // modules can skip installation as some are needed for resolving make side
1605 // dependencies.
1606 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001607 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001608}
1609
Colin Cross0ea8ba82019-06-06 14:33:29 -07001610func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001611 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001612 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001613 }
Colin Crossca860ac2016-01-04 14:34:37 -08001614 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001615}
1616
Colin Crossca860ac2016-01-04 14:34:37 -08001617func (c *Module) begin(ctx BaseModuleContext) {
1618 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001619 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001620 }
Colin Crossca860ac2016-01-04 14:34:37 -08001621 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001622 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001623 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001624 if c.stl != nil {
1625 c.stl.begin(ctx)
1626 }
Colin Cross16b23492016-01-06 14:41:07 -08001627 if c.sanitize != nil {
1628 c.sanitize.begin(ctx)
1629 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001630 if c.coverage != nil {
1631 c.coverage.begin(ctx)
1632 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001633 if c.sabi != nil {
1634 c.sabi.begin(ctx)
1635 }
Justin Yun8effde42017-06-23 19:24:43 +09001636 if c.vndkdep != nil {
1637 c.vndkdep.begin(ctx)
1638 }
Stephen Craneba090d12017-05-09 15:44:35 -07001639 if c.lto != nil {
1640 c.lto.begin(ctx)
1641 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001642 if c.pgo != nil {
1643 c.pgo.begin(ctx)
1644 }
Colin Crossca860ac2016-01-04 14:34:37 -08001645 for _, feature := range c.features {
1646 feature.begin(ctx)
1647 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001648 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001649 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001650 if err != nil {
1651 ctx.PropertyErrorf("sdk_version", err.Error())
1652 }
Nan Zhang0007d812017-11-07 10:57:05 -08001653 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001654 }
Colin Crossca860ac2016-01-04 14:34:37 -08001655}
1656
Colin Cross37047f12016-12-13 17:06:13 -08001657func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001658 deps := Deps{}
1659
1660 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001661 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001662 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001663 // Add the PGO dependency (the clang_rt.profile runtime library), which
1664 // sometimes depends on symbols from libgcc, before libgcc gets added
1665 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001666 if c.pgo != nil {
1667 deps = c.pgo.deps(ctx, deps)
1668 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001669 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001670 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001671 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001672 if c.stl != nil {
1673 deps = c.stl.deps(ctx, deps)
1674 }
Colin Cross16b23492016-01-06 14:41:07 -08001675 if c.sanitize != nil {
1676 deps = c.sanitize.deps(ctx, deps)
1677 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001678 if c.coverage != nil {
1679 deps = c.coverage.deps(ctx, deps)
1680 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001681 if c.sabi != nil {
1682 deps = c.sabi.deps(ctx, deps)
1683 }
Justin Yun8effde42017-06-23 19:24:43 +09001684 if c.vndkdep != nil {
1685 deps = c.vndkdep.deps(ctx, deps)
1686 }
Stephen Craneba090d12017-05-09 15:44:35 -07001687 if c.lto != nil {
1688 deps = c.lto.deps(ctx, deps)
1689 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001690 for _, feature := range c.features {
1691 deps = feature.deps(ctx, deps)
1692 }
1693
Colin Crossb6715442017-10-24 11:13:31 -07001694 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1695 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1696 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1697 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1698 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1699 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001700 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001701
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001702 for _, lib := range deps.ReexportSharedLibHeaders {
1703 if !inList(lib, deps.SharedLibs) {
1704 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1705 }
1706 }
1707
1708 for _, lib := range deps.ReexportStaticLibHeaders {
1709 if !inList(lib, deps.StaticLibs) {
1710 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1711 }
1712 }
1713
Colin Cross5950f382016-12-13 12:50:57 -08001714 for _, lib := range deps.ReexportHeaderLibHeaders {
1715 if !inList(lib, deps.HeaderLibs) {
1716 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1717 }
1718 }
1719
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001720 for _, gen := range deps.ReexportGeneratedHeaders {
1721 if !inList(gen, deps.GeneratedHeaders) {
1722 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1723 }
1724 }
1725
Colin Crossc99deeb2016-04-11 15:06:20 -07001726 return deps
1727}
1728
Dan Albert7e9d2952016-08-04 13:02:36 -07001729func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001730 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001731 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001732 moduleContextImpl: moduleContextImpl{
1733 mod: c,
1734 },
1735 }
1736 ctx.ctx = ctx
1737
Colin Crossca860ac2016-01-04 14:34:37 -08001738 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001739}
1740
Jiyong Park7ed9de32018-10-15 22:25:07 +09001741// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001742func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001743 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1744 version := name[sharp+1:]
1745 libname := name[:sharp]
1746 return libname, version
1747 }
1748 return name, ""
1749}
1750
Colin Cross1e676be2016-10-12 14:38:15 -07001751func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001752 if !c.Enabled() {
1753 return
1754 }
1755
Colin Cross37047f12016-12-13 17:06:13 -08001756 ctx := &depsContext{
1757 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001758 moduleContextImpl: moduleContextImpl{
1759 mod: c,
1760 },
1761 }
1762 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001763
Colin Crossc99deeb2016-04-11 15:06:20 -07001764 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001765
Dan Albert914449f2016-06-17 16:45:24 -07001766 variantNdkLibs := []string{}
1767 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001768 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001769 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001770
Inseob Kimeec88e12020-01-22 11:11:29 +09001771 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001772 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001773 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001774 // 1. Name of an NDK library that refers to a prebuilt module.
1775 // For each of these, it adds the name of the prebuilt module (which will be in
1776 // prebuilts/ndk) to the list of nonvariant libs.
1777 // 2. Name of an NDK library that refers to an ndk_library module.
1778 // For each of these, it adds the name of the ndk_library module to the list of
1779 // variant libs.
1780 // 3. Anything else (so anything that isn't an NDK library).
1781 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001782 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001783 // The caller can then know to add the variantLibs dependencies differently from the
1784 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001785
Inseob Kim9516ee92019-05-09 10:56:13 +09001786 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001787 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1788
1789 rewriteVendorLibs := func(lib string) string {
1790 if isLlndkLibrary(lib, ctx.Config()) {
1791 return lib + llndkLibrarySuffix
1792 }
1793
1794 // only modules with BOARD_VNDK_VERSION uses snapshot.
1795 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1796 return lib
1797 }
1798
1799 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1800 return snapshot
1801 }
1802
1803 return lib
1804 }
1805
1806 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001807 variantLibs = []string{}
1808 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001809 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001810 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001811 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001812 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1813 if !inList(name, ndkMigratedLibs) {
1814 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001815 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001816 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001817 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001818 } else if ctx.useVndk() {
1819 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001820 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001821 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001822 if actx.OtherModuleExists(vendorPublicLib) {
1823 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1824 } else {
1825 // This can happen if vendor_public_library module is defined in a
1826 // namespace that isn't visible to the current module. In that case,
1827 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001828 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001829 }
Dan Albert914449f2016-06-17 16:45:24 -07001830 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001831 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001832 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001833 }
1834 }
Dan Albert914449f2016-06-17 16:45:24 -07001835 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001836 }
1837
Inseob Kimeec88e12020-01-22 11:11:29 +09001838 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1839 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1840 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1841 if ctx.useVndk() {
1842 for idx, lib := range deps.RuntimeLibs {
1843 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1844 }
1845 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001846 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001847
Jiyong Park7e636d02019-01-28 16:16:54 +09001848 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001849 if c.linker != nil {
1850 if library, ok := c.linker.(*libraryDecorator); ok {
1851 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001852 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001853 }
1854 }
1855 }
1856
Inseob Kimeec88e12020-01-22 11:11:29 +09001857 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1858 // only modules with BOARD_VNDK_VERSION uses snapshot.
1859 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1860 return lib
1861 }
1862
1863 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1864 return snapshot
1865 }
1866
1867 return lib
1868 }
1869
1870 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001871 for _, lib := range deps.HeaderLibs {
1872 depTag := headerDepTag
1873 if inList(lib, deps.ReexportHeaderLibHeaders) {
1874 depTag = headerExportDepTag
1875 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001876
1877 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1878
Jiyong Park7e636d02019-01-28 16:16:54 +09001879 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001880 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001881 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001882 } else {
1883 actx.AddVariationDependencies(nil, depTag, lib)
1884 }
1885 }
1886
1887 if buildStubs {
1888 // Stubs lib does not have dependency to other static/shared libraries.
1889 // Don't proceed.
1890 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001891 }
Colin Cross5950f382016-12-13 12:50:57 -08001892
Inseob Kimc0907f12019-02-08 21:00:45 +09001893 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001894 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001895
Jiyong Park5d1598f2019-02-25 22:14:17 +09001896 for _, lib := range deps.WholeStaticLibs {
1897 depTag := wholeStaticDepTag
1898 if impl, ok := syspropImplLibraries[lib]; ok {
1899 lib = impl
1900 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001901
1902 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1903
Jiyong Park5d1598f2019-02-25 22:14:17 +09001904 actx.AddVariationDependencies([]blueprint.Variation{
1905 {Mutator: "link", Variation: "static"},
1906 }, depTag, lib)
1907 }
1908
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001909 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001910 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001911 if inList(lib, deps.ReexportStaticLibHeaders) {
1912 depTag = staticExportDepTag
1913 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001914
1915 if impl, ok := syspropImplLibraries[lib]; ok {
1916 lib = impl
1917 }
1918
Inseob Kimeec88e12020-01-22 11:11:29 +09001919 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1920
Dan Willemsen59339a22018-07-22 21:18:45 -07001921 actx.AddVariationDependencies([]blueprint.Variation{
1922 {Mutator: "link", Variation: "static"},
1923 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001924 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001925
Jooyung Han75568392020-03-20 04:29:24 +09001926 // staticUnwinderDep is treated as staticDep for Q apexes
1927 // so that native libraries/binaries are linked with static unwinder
1928 // because Q libc doesn't have unwinder APIs
1929 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001930 actx.AddVariationDependencies([]blueprint.Variation{
1931 {Mutator: "link", Variation: "static"},
Inseob Kim7f283f42020-06-01 21:53:49 +09001932 }, staticUnwinderDepTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001933 }
1934
Inseob Kimeec88e12020-01-22 11:11:29 +09001935 for _, lib := range deps.LateStaticLibs {
1936 actx.AddVariationDependencies([]blueprint.Variation{
1937 {Mutator: "link", Variation: "static"},
1938 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1939 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001940
Ivan Lozano183a3212019-10-18 14:18:45 -07001941 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001942 var variations []blueprint.Variation
1943 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001944 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001945 // Version is explicitly specified. i.e. libFoo#30
1946 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001947 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001948 }
1949 actx.AddVariationDependencies(variations, depTag, name)
1950
Jooyung Han03b51852020-02-26 22:45:42 +09001951 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001952 // The stubs library will be used when the depending module is built for APEX and
1953 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09001954 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09001955 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1956 // Note that depTag.ExplicitlyVersioned is false in this case.
1957 actx.AddVariationDependencies([]blueprint.Variation{
1958 {Mutator: "link", Variation: "shared"},
1959 {Mutator: "version", Variation: ver},
1960 }, depTag, name)
1961 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001962 }
1963 }
1964
Jiyong Park7ed9de32018-10-15 22:25:07 +09001965 // shared lib names without the #version suffix
1966 var sharedLibNames []string
1967
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001968 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001969 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001970 if c.static() {
1971 depTag = SharedFromStaticDepTag
1972 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001973 if inList(lib, deps.ReexportSharedLibHeaders) {
1974 depTag = sharedExportDepTag
1975 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001976
1977 if impl, ok := syspropImplLibraries[lib]; ok {
1978 lib = impl
1979 }
1980
Jiyong Park73c54ee2019-10-22 20:31:18 +09001981 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001982 sharedLibNames = append(sharedLibNames, name)
1983
Jiyong Park25fc6a92018-11-18 18:02:45 +09001984 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001985 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001986
Jiyong Park7ed9de32018-10-15 22:25:07 +09001987 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001988 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001989 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1990 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1991 // linking against both the stubs lib and the non-stubs lib at the same time.
1992 continue
1993 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001994 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001995 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001996
Dan Willemsen59339a22018-07-22 21:18:45 -07001997 actx.AddVariationDependencies([]blueprint.Variation{
1998 {Mutator: "link", Variation: "shared"},
1999 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002000
Colin Cross68861832016-07-08 10:41:41 -07002001 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002002
2003 for _, gen := range deps.GeneratedHeaders {
2004 depTag := genHeaderDepTag
2005 if inList(gen, deps.ReexportGeneratedHeaders) {
2006 depTag = genHeaderExportDepTag
2007 }
2008 actx.AddDependency(c, depTag, gen)
2009 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002010
Colin Cross42d48b72018-08-29 14:10:52 -07002011 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002012
Inseob Kim1042d292020-06-01 23:23:05 +09002013 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2014
Colin Crossc99deeb2016-04-11 15:06:20 -07002015 if deps.CrtBegin != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002016 actx.AddVariationDependencies(nil, CrtBeginDepTag, rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002017 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002018 if deps.CrtEnd != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002019 actx.AddVariationDependencies(nil, CrtEndDepTag, rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002020 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002021 if deps.LinkerFlagsFile != "" {
2022 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2023 }
2024 if deps.DynamicLinker != "" {
2025 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002026 }
Dan Albert914449f2016-06-17 16:45:24 -07002027
2028 version := ctx.sdkVersion()
2029 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002030 {Mutator: "ndk_api", Variation: version},
2031 {Mutator: "link", Variation: "shared"},
2032 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07002033 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002034 {Mutator: "ndk_api", Variation: version},
2035 {Mutator: "link", Variation: "shared"},
2036 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002037
2038 if vndkdep := c.vndkdep; vndkdep != nil {
2039 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002040 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002041 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002042 {Mutator: "link", Variation: "shared"},
2043 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002044 }
2045 }
Colin Cross6362e272015-10-29 15:25:03 -07002046}
Colin Cross21b9a242015-03-24 14:15:58 -07002047
Colin Crosse40b4ea2018-10-02 22:25:58 -07002048func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002049 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2050 c.beginMutator(ctx)
2051 }
2052}
2053
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002054// Whether a module can link to another module, taking into
2055// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07002056func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
2057 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002058 // Host code is not restricted
2059 return
2060 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002061
2062 // VNDK is cc.Module supported only for now.
2063 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002064 // Though vendor code is limited by the vendor mutator,
2065 // each vendor-available module needs to check
2066 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002067 if ccTo, ok := to.(*Module); ok {
2068 if ccFrom.vndkdep != nil {
2069 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2070 }
2071 } else {
2072 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002073 }
2074 return
2075 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002076 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002077 // Platform code can link to anything
2078 return
2079 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002080 if from.InRamdisk() {
2081 // Ramdisk code is not NDK
2082 return
2083 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002084 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002085 // Recovery code is not NDK
2086 return
2087 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002088 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002089 // These are always allowed
2090 return
2091 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002092 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002093 // These are allowed, but they don't set sdk_version
2094 return
2095 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002096 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002097 // These aren't real libraries, but are the stub shared libraries that are included in
2098 // the NDK.
2099 return
2100 }
Logan Chien834b9a62019-01-14 15:39:03 +08002101
Ivan Lozano52767be2019-10-18 14:49:46 -07002102 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002103 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2104 // to link to libc++ (non-NDK and without sdk_version).
2105 return
2106 }
2107
Ivan Lozano52767be2019-10-18 14:49:46 -07002108 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002109 // NDK code linking to platform code is never okay.
2110 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002111 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002112 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002113 }
2114
2115 // At this point we know we have two NDK libraries, but we need to
2116 // check that we're not linking against anything built against a higher
2117 // API level, as it is only valid to link against older or equivalent
2118 // APIs.
2119
Inseob Kim01a28722018-04-11 09:48:45 +09002120 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002121 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002122 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002123 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002124 // Current can't be linked against by anything else.
2125 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002126 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002127 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002128 fromApi, err := strconv.Atoi(from.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 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002133 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002134 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002135 if err != nil {
2136 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002137 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002138 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002139 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002140
Inseob Kim01a28722018-04-11 09:48:45 +09002141 if toApi > fromApi {
2142 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002143 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002144 }
2145 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002146 }
Dan Albert202fe492017-12-15 13:56:59 -08002147
2148 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002149 fromStl := from.SelectedStl()
2150 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002151 if fromStl == "" || toStl == "" {
2152 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002153 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002154 // We can be permissive with the system "STL" since it is only the C++
2155 // ABI layer, but in the future we should make sure that everyone is
2156 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002157 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002158 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002159 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2160 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002161 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002162}
2163
Jiyong Park5fb8c102018-04-09 12:03:06 +09002164// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002165// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2166// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002167// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002168func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2169 check := func(child, parent android.Module) bool {
2170 to, ok := child.(*Module)
2171 if !ok {
2172 // follow thru cc.Defaults, etc.
2173 return true
2174 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002175
Jooyung Hana70f0672019-01-18 15:20:43 +09002176 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2177 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002178 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002179
2180 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002181 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002182 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002183 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002184
Jooyung Han0302a842019-10-30 18:43:49 +09002185 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002186 return false
2187 }
2188
2189 var stringPath []string
2190 for _, m := range ctx.GetWalkPath() {
2191 stringPath = append(stringPath, m.Name())
2192 }
2193 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2194 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2195 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2196 return false
2197 }
2198 if module, ok := ctx.Module().(*Module); ok {
2199 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002200 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002201 ctx.WalkDeps(check)
2202 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002203 }
2204 }
2205}
2206
Colin Crossc99deeb2016-04-11 15:06:20 -07002207// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002208func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002209 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002210
Ivan Lozano183a3212019-10-18 14:18:45 -07002211 directStaticDeps := []LinkableInterface{}
2212 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002213
Inseob Kim9516ee92019-05-09 10:56:13 +09002214 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2215
Inseob Kim69378442019-06-03 19:10:47 +09002216 reexportExporter := func(exporter exportedFlagsProducer) {
2217 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2218 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2219 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2220 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002221 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002222 }
2223
Colin Crossd11fcda2017-10-23 17:59:01 -07002224 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002225 depName := ctx.OtherModuleName(dep)
2226 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002227
Ivan Lozano52767be2019-10-18 14:49:46 -07002228 ccDep, ok := dep.(LinkableInterface)
2229 if !ok {
2230
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002231 // handling for a few module types that aren't cc Module but that are also supported
2232 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002233 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002234 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002235 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2236 genRule.GeneratedSourceFiles()...)
2237 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002238 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002239 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002240 // Support exported headers from a generated_sources dependency
2241 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002242 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002243 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002244 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002245 genRule.GeneratedSourceFiles()...)
2246 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002247 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002248 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002249 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002250 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002251 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002252 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2253 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002254 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002255 // 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 +09002256 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002257
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002258 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002259 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002260 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002261 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002262 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002263 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002264 files := genRule.GeneratedSourceFiles()
2265 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002266 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002267 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002268 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 -07002269 }
2270 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002271 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002272 }
Colin Crossca860ac2016-01-04 14:34:37 -08002273 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002274 return
2275 }
2276
Colin Crossfe17f6f2019-03-28 19:30:56 -07002277 if depTag == android.ProtoPluginDepTag {
2278 return
2279 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002280 if depTag == llndkImplDep {
2281 return
2282 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002283
Colin Crossd11fcda2017-10-23 17:59:01 -07002284 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002285 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2286 return
2287 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002288 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002289 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2290 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002291 return
2292 }
2293
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002294 // re-exporting flags
2295 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002296 // reusing objects only make sense for cc.Modules.
2297 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002298 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002299 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002300 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002301 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002302 return
2303 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002304 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002305
Jiyong Parke4bb9862019-02-01 00:31:10 +09002306 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002307 // staticVariants are a cc.Module specific concept.
2308 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002309 c.staticVariant = ccDep
2310 return
2311 }
2312 }
2313
Jooyung Han75568392020-03-20 04:29:24 +09002314 // For the dependency from platform to apex, use the latest stubs
2315 c.apexSdkVersion = android.FutureApiLevel
2316 if !c.IsForPlatform() {
2317 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2318 }
2319
2320 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2321 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2322 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2323 // (b/144430859)
2324 c.apexSdkVersion = android.FutureApiLevel
2325 }
2326
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002327 if depTag == staticUnwinderDepTag {
Jooyung Han75568392020-03-20 04:29:24 +09002328 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2329 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002330 depTag = StaticDepTag
2331 } else {
2332 return
2333 }
2334 }
2335
Ivan Lozano183a3212019-10-18 14:18:45 -07002336 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2337 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2338 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002339 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002340 if t, ok := depTag.(DependencyTag); ok {
2341 explicitlyVersioned = t.ExplicitlyVersioned
2342 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002343 depTag = t
2344 }
2345
Ivan Lozano183a3212019-10-18 14:18:45 -07002346 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002347 depIsStatic := false
2348 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002349 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002350 depIsStatic = true
2351 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002352 if ccDep.CcLibrary() && !depIsStatic {
2353 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002354 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002355 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002356 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002357
2358 var useThisDep bool
2359 if depIsStubs && explicitlyVersioned {
2360 // Always respect dependency to the versioned stubs (i.e. libX#10)
2361 useThisDep = true
2362 } else if !depHasStubs {
2363 // Use non-stub variant if that is the only choice
2364 // (i.e. depending on a lib without stubs.version property)
2365 useThisDep = true
2366 } else if c.IsForPlatform() {
2367 // If not building for APEX, use stubs only when it is from
2368 // an APEX (and not from platform)
2369 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002370 if c.bootstrap() {
2371 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002372 // always link to non-stub variant
2373 useThisDep = !depIsStubs
2374 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002375 for _, testFor := range c.TestFor() {
2376 // Another exception: if this module is bundled with an APEX, then
2377 // it is linked with the non-stub variant of a module in the APEX
2378 // as if this is part of the APEX.
2379 if android.DirectlyInApex(testFor, depName) {
2380 useThisDep = !depIsStubs
2381 break
2382 }
2383 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002384 } else {
2385 // If building for APEX, use stubs only when it is not from
2386 // the same APEX
2387 useThisDep = (depInSameApex != depIsStubs)
2388 }
2389
Jooyung Han03b51852020-02-26 22:45:42 +09002390 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2391 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002392 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002393 if err != nil {
2394 ctx.OtherModuleErrorf(dep, err.Error())
2395 return
2396 }
2397 if versionToUse != ccDep.StubsVersion() {
2398 useThisDep = false
2399 }
2400 }
2401
Jiyong Park25fc6a92018-11-18 18:02:45 +09002402 if !useThisDep {
2403 return // stop processing this dep
2404 }
2405 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002406 if c.UseVndk() {
2407 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2408 // by default, use current version of LLNDK
2409 versionToUse := ""
2410 versions := stubsVersionsFor(ctx.Config())[depName]
2411 if c.ApexName() != "" && len(versions) > 0 {
2412 // if this is for use_vendor apex && dep has stubsVersions
2413 // apply the same rule of apex sdk enforcement to choose right version
2414 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002415 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002416 if err != nil {
2417 ctx.OtherModuleErrorf(dep, err.Error())
2418 return
2419 }
2420 }
2421 if versionToUse != ccDep.StubsVersion() {
2422 return
2423 }
2424 }
2425 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002426
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002427 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2428
Ivan Lozano52767be2019-10-18 14:49:46 -07002429 // Exporting flags only makes sense for cc.Modules
2430 if _, ok := ccDep.(*Module); ok {
2431 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002432 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002433 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2434 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002435 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002436
Ivan Lozano52767be2019-10-18 14:49:46 -07002437 if t.ReexportFlags {
2438 reexportExporter(i)
2439 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2440 // Re-exported shared library headers must be included as well since they can help us with type information
2441 // about template instantiations (instantiated from their headers).
2442 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2443 // scripts.
2444 c.sabi.Properties.ReexportedIncludes = append(
2445 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2446 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002447 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002448 }
Logan Chienf3511742017-10-31 18:04:35 +08002449 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002450 }
2451
Colin Cross26c34ed2016-09-30 17:10:16 -07002452 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002453 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002454
Ivan Lozano52767be2019-10-18 14:49:46 -07002455 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002456 depFile := android.OptionalPath{}
2457
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002458 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002459 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002460 ptr = &depPaths.SharedLibs
2461 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002462 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002463 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002464
Jiyong Park64a44f22019-01-18 14:37:08 +09002465 case earlySharedDepTag:
2466 ptr = &depPaths.EarlySharedLibs
2467 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002468 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002469 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002470 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002471 ptr = &depPaths.LateSharedLibs
2472 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002473 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002474 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002475 ptr = nil
2476 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002477 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002478 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002479 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002480 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002481 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002482 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002483 return
2484 }
2485
Ivan Lozano52767be2019-10-18 14:49:46 -07002486 // Because the static library objects are included, this only makes sense
2487 // in the context of proper cc.Modules.
2488 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2489 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2490 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2491 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2492 for i := range missingDeps {
2493 missingDeps[i] += postfix
2494 }
2495 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002496 }
Martin Stjernholm391d94c2020-04-17 17:34:31 +01002497 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2498 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2499 } else {
2500 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2501 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002502 } else {
2503 ctx.ModuleErrorf(
2504 "non-cc.Modules cannot be included as whole static libraries.", depName)
2505 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002506 }
Colin Cross5950f382016-12-13 12:50:57 -08002507 case headerDepTag:
2508 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002509 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002510 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002511 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002512 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002513 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002514 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002515 case dynamicLinkerDepTag:
2516 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002517 }
2518
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002519 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002520 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002521 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002522 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002523 return
2524 }
2525
2526 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002527 // in static libraries act as if they were whole static libraries. The same goes for
2528 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002529 if c, ok := ccDep.(*Module); ok {
2530 staticLib := c.linker.(libraryInterface)
2531 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2532 staticLib.objs().coverageFiles...)
2533 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2534 staticLib.objs().sAbiDumpFiles...)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002535 } else if c, ok := ccDep.(LinkableInterface); ok {
2536 // Handle non-CC modules here
2537 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2538 c.CoverageFiles()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002539 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002540 }
2541
Colin Cross26c34ed2016-09-30 17:10:16 -07002542 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002543 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002544 if !ctx.Config().AllowMissingDependencies() {
2545 ctx.ModuleErrorf("module %q missing output file", depName)
2546 } else {
2547 ctx.AddMissingDependencies([]string{depName})
2548 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002549 return
2550 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002551 *ptr = append(*ptr, linkFile.Path())
2552 }
2553
Colin Crossc99deeb2016-04-11 15:06:20 -07002554 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002555 dep := depFile
2556 if !dep.Valid() {
2557 dep = linkFile
2558 }
2559 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002560 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002561
Inseob Kimeec88e12020-01-22 11:11:29 +09002562 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2563
2564 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002565 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002566 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002567 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002568 return libName
2569 }
2570
2571 makeLibName := func(depName string) string {
2572 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002573 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002574 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002575 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002576
Inseob Kimeec88e12020-01-22 11:11:29 +09002577 if c, ok := ccDep.(*Module); ok {
2578 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim752edec2020-03-14 01:30:34 +09002579 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002580 baseName := c.BaseModuleName()
Inseob Kim752edec2020-03-14 01:30:34 +09002581
2582 if c.IsVndk() {
2583 return baseName + ".vendor"
2584 }
2585
Inseob Kimeec88e12020-01-22 11:11:29 +09002586 if vendorSuffixModules[baseName] {
2587 return baseName + ".vendor"
2588 } else {
2589 return baseName
2590 }
2591 }
2592 }
2593
Yifan Hong1b3348d2020-01-21 15:53:22 -08002594 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002595 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2596 // core module instead.
2597 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002598 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002599 // The vendor module in Make will have been renamed to not conflict with the core
2600 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002601 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002602 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002603 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002604 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2605 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002606 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002607 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002608 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002609 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002610 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002611 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002612 }
Logan Chien43d34c32017-12-20 01:17:32 +08002613 }
2614
2615 // Export the shared libs to Make.
2616 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002617 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002618 if ccDep.CcLibrary() {
2619 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002620 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002621 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002622 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002623 c.Properties.ApexesProvidingSharedLibs = append(
2624 c.Properties.ApexesProvidingSharedLibs, an)
2625 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002626 }
2627 }
2628
Jiyong Park27b188b2017-07-18 13:23:39 +09002629 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002630 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002631 c.Properties.AndroidMkSharedLibs = append(
2632 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002633 // Record baseLibName for snapshots.
2634 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002635 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002636 c.Properties.AndroidMkSharedLibs = append(
2637 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002638 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002639 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002640 c.Properties.AndroidMkStaticLibs = append(
2641 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002642 case runtimeDepTag:
2643 c.Properties.AndroidMkRuntimeLibs = append(
2644 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002645 // Record baseLibName for snapshots.
2646 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002647 case wholeStaticDepTag:
2648 c.Properties.AndroidMkWholeStaticLibs = append(
2649 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Bill Peckhama46de702020-04-21 17:23:37 -07002650 case headerDepTag:
2651 c.Properties.AndroidMkHeaderLibs = append(
2652 c.Properties.AndroidMkHeaderLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002653 }
Colin Crossca860ac2016-01-04 14:34:37 -08002654 })
2655
Jeff Gaston294356f2017-09-27 17:05:30 -07002656 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002657 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002658
Colin Crossdd84e052017-05-17 13:44:16 -07002659 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002660 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002661 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2662 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002663 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002664 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002665 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2666 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002667 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002668 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002669 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002670
2671 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002672 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002673 }
Colin Crossdd84e052017-05-17 13:44:16 -07002674
Colin Crossca860ac2016-01-04 14:34:37 -08002675 return depPaths
2676}
2677
2678func (c *Module) InstallInData() bool {
2679 if c.installer == nil {
2680 return false
2681 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002682 return c.installer.inData()
2683}
2684
2685func (c *Module) InstallInSanitizerDir() bool {
2686 if c.installer == nil {
2687 return false
2688 }
2689 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002690 return true
2691 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002692 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002693}
2694
Yifan Hong1b3348d2020-01-21 15:53:22 -08002695func (c *Module) InstallInRamdisk() bool {
2696 return c.InRamdisk()
2697}
2698
Jiyong Parkf9332f12018-02-01 00:54:12 +09002699func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002700 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002701}
2702
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002703func (c *Module) SkipInstall() {
2704 if c.installer == nil {
2705 c.ModuleBase.SkipInstall()
2706 return
2707 }
2708 c.installer.skipInstall(c)
2709}
2710
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002711func (c *Module) HostToolPath() android.OptionalPath {
2712 if c.installer == nil {
2713 return android.OptionalPath{}
2714 }
2715 return c.installer.hostToolPath()
2716}
2717
Nan Zhangd4e641b2017-07-12 12:55:28 -07002718func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2719 return c.outputFile
2720}
2721
Colin Cross41955e82019-05-29 14:40:35 -07002722func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2723 switch tag {
2724 case "":
2725 if c.outputFile.Valid() {
2726 return android.Paths{c.outputFile.Path()}, nil
2727 }
2728 return android.Paths{}, nil
2729 default:
2730 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002731 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002732}
2733
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002734func (c *Module) static() bool {
2735 if static, ok := c.linker.(interface {
2736 static() bool
2737 }); ok {
2738 return static.static()
2739 }
2740 return false
2741}
2742
Jiyong Park379de2f2018-12-19 02:47:14 +09002743func (c *Module) staticBinary() bool {
2744 if static, ok := c.linker.(interface {
2745 staticBinary() bool
2746 }); ok {
2747 return static.staticBinary()
2748 }
2749 return false
2750}
2751
Jiyong Park1d1119f2019-07-29 21:27:18 +09002752func (c *Module) header() bool {
2753 if h, ok := c.linker.(interface {
2754 header() bool
2755 }); ok {
2756 return h.header()
2757 }
2758 return false
2759}
2760
Inseob Kim7f283f42020-06-01 21:53:49 +09002761func (c *Module) binary() bool {
2762 if b, ok := c.linker.(interface {
2763 binary() bool
2764 }); ok {
2765 return b.binary()
2766 }
2767 return false
2768}
2769
Inseob Kim1042d292020-06-01 23:23:05 +09002770func (c *Module) object() bool {
2771 if o, ok := c.linker.(interface {
2772 object() bool
2773 }); ok {
2774 return o.object()
2775 }
2776 return false
2777}
2778
Jooyung Han38002912019-05-16 04:01:54 +09002779func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002780 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002781 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2782 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002783 return "native:vndk"
2784 }
Jooyung Han38002912019-05-16 04:01:54 +09002785 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002786 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002787 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002788 if Bool(c.VendorProperties.Vendor_available) {
2789 return "native:vndk"
2790 }
2791 return "native:vndk_private"
2792 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002793 if c.inProduct() {
2794 return "native:product"
2795 }
Jooyung Han38002912019-05-16 04:01:54 +09002796 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002797 } else if c.InRamdisk() {
2798 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002799 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002800 return "native:recovery"
2801 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2802 return "native:ndk:none:none"
2803 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2804 //family, link := getNdkStlFamilyAndLinkType(c)
2805 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002806 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002807 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002808 } else {
2809 return "native:platform"
2810 }
2811}
2812
Jiyong Park9d452992018-10-03 00:38:19 +09002813// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002814// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002815func (c *Module) IsInstallableToApex() bool {
2816 if shared, ok := c.linker.(interface {
2817 shared() bool
2818 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002819 // Stub libs and prebuilt libs in a versioned SDK are not
2820 // installable to APEX even though they are shared libs.
2821 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002822 } else if _, ok := c.linker.(testPerSrc); ok {
2823 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002824 }
2825 return false
2826}
2827
Jiyong Parka90ca002019-10-07 15:47:24 +09002828func (c *Module) AvailableFor(what string) bool {
2829 if linker, ok := c.linker.(interface {
2830 availableFor(string) bool
2831 }); ok {
2832 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2833 } else {
2834 return c.ApexModuleBase.AvailableFor(what)
2835 }
2836}
2837
Jiyong Park62304bb2020-04-13 16:19:48 +09002838func (c *Module) TestFor() []string {
2839 if test, ok := c.linker.(interface {
2840 testFor() []string
2841 }); ok {
2842 return test.testFor()
2843 } else {
2844 return c.ApexModuleBase.TestFor()
2845 }
2846}
2847
Paul Duffin0cb37b92020-03-04 14:52:46 +00002848// Return true if the module is ever installable.
2849func (c *Module) EverInstallable() bool {
2850 return c.installer != nil &&
2851 // Check to see whether the module is actually ever installable.
2852 c.installer.everInstallable()
2853}
2854
Inseob Kim1f086e22019-05-09 13:29:15 +09002855func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002856 ret := c.EverInstallable() &&
2857 // Check to see whether the module has been configured to not be installed.
2858 proptools.BoolDefault(c.Properties.Installable, true) &&
2859 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002860
2861 // The platform variant doesn't need further condition. Apex variants however might not
2862 // be installable because it will likely to be included in the APEX and won't appear
2863 // in the system partition.
2864 if c.IsForPlatform() {
2865 return ret
2866 }
2867
2868 // Special case for modules that are configured to be installed to /data, which includes
2869 // test modules. For these modules, both APEX and non-APEX variants are considered as
2870 // installable. This is because even the APEX variants won't be included in the APEX, but
2871 // will anyway be installed to /data/*.
2872 // See b/146995717
2873 if c.InstallInData() {
2874 return ret
2875 }
2876
2877 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002878}
2879
Logan Chien41eabe62019-04-10 13:33:58 +08002880func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2881 if c.linker != nil {
2882 if library, ok := c.linker.(*libraryDecorator); ok {
2883 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2884 }
2885 }
2886}
2887
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002888func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002889 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002890 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002891 if cc.HasStubsVariants() {
2892 if depTag.Shared && depTag.Library {
2893 // dynamic dep to a stubs lib crosses APEX boundary
2894 return false
2895 }
2896 if IsRuntimeDepTag(depTag) {
2897 // runtime dep to a stubs lib also crosses APEX boundary
2898 return false
2899 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002900 }
2901 if depTag.FromStatic {
2902 // shared_lib dependency from a static lib is considered as crossing
2903 // the APEX boundary because the dependency doesn't actually is
2904 // linked; the dependency is used only during the compilation phase.
2905 return false
2906 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002907 }
Jiyong Park7d95a512020-05-10 15:16:24 +09002908 } else if ctx.OtherModuleDependencyTag(dep) == llndkImplDep {
2909 // We don't track beyond LLNDK
2910 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002911 }
2912 return true
2913}
2914
Colin Cross2ba19d92015-05-07 15:44:20 -07002915//
Colin Crosscfad1192015-11-02 16:43:11 -08002916// Defaults
2917//
Colin Crossca860ac2016-01-04 14:34:37 -08002918type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002919 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002920 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002921 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002922}
2923
Patrice Arrudac249c712019-03-19 17:00:29 -07002924// cc_defaults provides a set of properties that can be inherited by other cc
2925// modules. A module can use the properties from a cc_defaults using
2926// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2927// merged (when possible) by prepending the default module's values to the
2928// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002929func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002930 return DefaultsFactory()
2931}
2932
Colin Cross36242852017-06-23 15:06:31 -07002933func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002934 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002935
Colin Cross36242852017-06-23 15:06:31 -07002936 module.AddProperties(props...)
2937 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002938 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002939 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002940 &BaseCompilerProperties{},
2941 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002942 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002943 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002944 &StaticProperties{},
2945 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002946 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002947 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002948 &TestProperties{},
2949 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002950 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002951 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002952 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002953 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002954 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002955 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002956 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002957 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002958 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002959 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002960 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002961 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002962 )
Colin Crosscfad1192015-11-02 16:43:11 -08002963
Jooyung Hancc372c52019-09-25 15:18:44 +09002964 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002965
2966 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002967}
2968
Jiyong Park6a43f042017-10-12 23:05:00 +09002969func squashVendorSrcs(m *Module) {
2970 if lib, ok := m.compiler.(*libraryDecorator); ok {
2971 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2972 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2973
2974 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2975 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2976 }
2977}
2978
Jiyong Parkf9332f12018-02-01 00:54:12 +09002979func squashRecoverySrcs(m *Module) {
2980 if lib, ok := m.compiler.(*libraryDecorator); ok {
2981 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2982 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2983
2984 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2985 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2986 }
2987}
2988
Colin Cross7228ecd2019-11-18 16:00:16 -08002989var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002990
Colin Cross7228ecd2019-11-18 16:00:16 -08002991func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002992 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002993 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002994 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002995
2996 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002997 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002998 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002999 }
Logan Chienf3511742017-10-31 18:04:35 +08003000
3001 if vndkdep := m.vndkdep; vndkdep != nil {
3002 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09003003 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08003004 if !vndkdep.isVndkExt() {
3005 mctx.PropertyErrorf("vndk",
3006 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09003007 } else if m.VendorProperties.Vendor_available != nil {
3008 mctx.PropertyErrorf("vendor_available",
3009 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08003010 }
3011 } else {
3012 if vndkdep.isVndkExt() {
3013 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09003014 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08003015 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08003016 }
3017 if m.VendorProperties.Vendor_available == nil {
3018 mctx.PropertyErrorf("vndk",
3019 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08003020 }
3021 }
3022 } else {
3023 if vndkdep.isVndkSp() {
3024 mctx.PropertyErrorf("vndk",
3025 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08003026 }
3027 if vndkdep.isVndkExt() {
3028 mctx.PropertyErrorf("vndk",
3029 "must set `enabled: true` to set `extends: %q`",
3030 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08003031 }
Justin Yun8effde42017-06-23 19:24:43 +09003032 }
3033 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003034
Jiyong Parkf9332f12018-02-01 00:54:12 +09003035 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08003036 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09003037 var recoveryVariantNeeded bool = false
3038
Inseob Kim64c43952019-08-26 16:52:35 +09003039 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09003040 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09003041
3042 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09003043 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
3044 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
3045 if boardVndkVersion == "current" {
3046 boardVndkVersion = platformVndkVersion
3047 }
3048 if productVndkVersion == "current" {
3049 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09003050 }
3051
Justin Yun5f7f7e82019-11-18 19:52:14 +09003052 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003053 // If the device isn't compiling against the VNDK, we always
3054 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003055 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003056 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003057 // LL-NDK stubs only exist in the vendor and product variants,
3058 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09003059 vendorVariants = append(vendorVariants,
3060 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003061 boardVndkVersion,
3062 )
3063 productVariants = append(productVariants,
3064 platformVndkVersion,
3065 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003066 )
Jiyong Park2a454122017-10-19 15:59:33 +09003067 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
3068 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09003069 vendorVariants = append(vendorVariants,
3070 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003071 boardVndkVersion,
3072 )
3073 productVariants = append(productVariants,
3074 platformVndkVersion,
3075 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003076 )
Inseob Kimeec88e12020-01-22 11:11:29 +09003077 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09003078 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
3079 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09003080 if snapshot, ok := m.linker.(interface {
3081 version() string
3082 }); ok {
3083 vendorVariants = append(vendorVariants, snapshot.version())
3084 } else {
3085 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
3086 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09003087 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003088 // This will be available in /system, /vendor and /product
3089 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003090 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09003091 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09003092 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09003093 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
3094 // code is PLATFORM_VNDK_VERSION.
3095 // On the other hand, vendor_available modules which are not VNDK should
3096 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09003097 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09003098 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003099 vendorVariants = append(vendorVariants, boardVndkVersion)
3100 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09003101 }
Logan Chienf3511742017-10-31 18:04:35 +08003102 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09003103 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09003104 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003105 } else {
3106 // This is either in /system (or similar: /data), or is a
3107 // modules built with the NDK. Modules built with the NDK
3108 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003109 coreVariantNeeded = true
3110 }
3111
Justin Yun5f7f7e82019-11-18 19:52:14 +09003112 if boardVndkVersion != "" && productVndkVersion != "" {
3113 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
3114 // The module has "product_specific: true" that does not create core variant.
3115 coreVariantNeeded = false
3116 productVariants = append(productVariants, productVndkVersion)
3117 }
3118 } else {
3119 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
3120 // restriction to use system libs.
3121 // No product variants defined in this case.
3122 productVariants = []string{}
3123 }
3124
Yifan Hong1b3348d2020-01-21 15:53:22 -08003125 if Bool(m.Properties.Ramdisk_available) {
3126 ramdiskVariantNeeded = true
3127 }
3128
3129 if m.ModuleBase.InstallInRamdisk() {
3130 ramdiskVariantNeeded = true
3131 coreVariantNeeded = false
3132 }
3133
Jiyong Parkf9332f12018-02-01 00:54:12 +09003134 if Bool(m.Properties.Recovery_available) {
3135 recoveryVariantNeeded = true
3136 }
3137
3138 if m.ModuleBase.InstallInRecovery() {
3139 recoveryVariantNeeded = true
3140 coreVariantNeeded = false
3141 }
3142
Inseob Kim64c43952019-08-26 16:52:35 +09003143 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003144 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3145 }
3146
3147 for _, variant := range android.FirstUniqueStrings(productVariants) {
3148 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003149 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003150
Yifan Hong1b3348d2020-01-21 15:53:22 -08003151 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003152 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3153 m.Properties.CoreVariantNeeded = coreVariantNeeded
3154}
3155
3156func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3157 return c.Properties.CoreVariantNeeded
3158}
3159
Yifan Hong1b3348d2020-01-21 15:53:22 -08003160func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3161 return c.Properties.RamdiskVariantNeeded
3162}
3163
Colin Cross7228ecd2019-11-18 16:00:16 -08003164func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3165 return c.Properties.RecoveryVariantNeeded
3166}
3167
3168func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003169 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003170}
3171
3172func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3173 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003174 if variant == android.RamdiskVariation {
3175 m.MakeAsPlatform()
3176 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003177 m.MakeAsPlatform()
3178 squashRecoverySrcs(m)
3179 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003180 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003181 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3182 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003183
3184 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3185 // Hide other vendor variants to avoid collision.
3186 vndkVersion := ctx.DeviceConfig().VndkVersion()
3187 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3188 m.Properties.HideFromMake = true
3189 m.SkipInstall()
3190 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003191 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3192 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3193 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3194 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003195 }
3196}
3197
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003198func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003199 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003200 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3201 }
Colin Cross6510f912017-11-29 00:27:14 -08003202 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003203}
3204
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003205func kytheExtractAllFactory() android.Singleton {
3206 return &kytheExtractAllSingleton{}
3207}
3208
3209type kytheExtractAllSingleton struct {
3210}
3211
3212func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3213 var xrefTargets android.Paths
3214 ctx.VisitAllModules(func(module android.Module) {
3215 if ccModule, ok := module.(xref); ok {
3216 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3217 }
3218 })
3219 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3220 if len(xrefTargets) > 0 {
3221 ctx.Build(pctx, android.BuildParams{
3222 Rule: blueprint.Phony,
3223 Output: android.PathForPhony(ctx, "xref_cxx"),
3224 Inputs: xrefTargets,
3225 //Default: true,
3226 })
3227 }
3228}
3229
Colin Cross06a931b2015-10-28 17:23:31 -07003230var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003231var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003232var BoolPtr = proptools.BoolPtr
3233var String = proptools.String
3234var StringPtr = proptools.StringPtr