blob: e52adaf569e8e6b86db1f6cb38dc30d48eb52c19 [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
Inseob Kimd110f872019-12-06 13:15:38 +0900139 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700140
Inseob Kimd110f872019-12-06 13:15:38 +0900141 Flags []string
142 IncludeDirs android.Paths
143 SystemIncludeDirs android.Paths
144 ReexportedDirs android.Paths
145 ReexportedSystemDirs android.Paths
146 ReexportedFlags []string
147 ReexportedGeneratedHeaders android.Paths
148 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700149
Colin Cross26c34ed2016-09-30 17:10:16 -0700150 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700151 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700152
153 // Path to the file container flags to use with the linker
154 LinkerFlagsFile android.OptionalPath
155
156 // Path to the dynamic linker binary
157 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700158}
159
Colin Cross4af21ed2019-11-04 09:37:55 -0800160// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
161// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
162// command line so they can be overridden by the local module flags).
163type LocalOrGlobalFlags struct {
164 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700165 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800166 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700167 CFlags []string // Flags that apply to C and C++ source files
168 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
169 ConlyFlags []string // Flags that apply to C source files
170 CppFlags []string // Flags that apply to C++ source files
171 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700172 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800173}
174
175type Flags struct {
176 Local LocalOrGlobalFlags
177 Global LocalOrGlobalFlags
178
179 aidlFlags []string // Flags that apply to aidl source files
180 rsFlags []string // Flags that apply to renderscript source files
181 libFlags []string // Flags to add libraries early to the link order
182 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
183 TidyFlags []string // Flags that apply to clang-tidy
184 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700185
Colin Crossc3199482017-03-30 15:03:04 -0700186 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800187 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700188 SystemIncludeFlags []string
189
Oliver Nguyen04526782020-04-21 12:40:27 -0700190 Toolchain config.Toolchain
191 Tidy bool
192 GcovCoverage bool
193 SAbiDump bool
194 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800195
196 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800197 DynamicLinker string
198
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700199 CFlagsDeps android.Paths // Files depended on by compiler flags
200 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800201
Dan Willemsen98ab3112019-08-27 21:20:40 -0700202 AssemblerWithCpp bool
203 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800204
Colin Cross19878da2019-03-28 14:45:07 -0700205 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700206 protoC bool // Whether to use C instead of C++
207 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700208
209 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700210}
211
Colin Crossca860ac2016-01-04 14:34:37 -0800212// Properties used to compile all C or C++ modules
213type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700214 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800215 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700216
Colin Crossc511bc52020-04-07 16:50:32 +0000217 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
218 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800219 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700220
Jooyung Han379660c2020-04-21 15:24:00 +0900221 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
222 Min_sdk_version *string
223
Colin Crossc511bc52020-04-07 16:50:32 +0000224 // If true, always create an sdk variant and don't create a platform variant.
225 Sdk_variant_only *bool
226
Jiyong Parkde866cb2018-12-07 23:08:36 +0900227 AndroidMkSharedLibs []string `blueprint:"mutated"`
228 AndroidMkStaticLibs []string `blueprint:"mutated"`
229 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
230 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700231 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900232 HideFromMake bool `blueprint:"mutated"`
233 PreventInstall bool `blueprint:"mutated"`
234 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700235
Justin Yun5f7f7e82019-11-18 19:52:14 +0900236 ImageVariationPrefix string `blueprint:"mutated"`
237 VndkVersion string `blueprint:"mutated"`
238 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800239
240 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
241 // file
242 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900243
Yifan Hong1b3348d2020-01-21 15:53:22 -0800244 // Make this module available when building for ramdisk
245 Ramdisk_available *bool
246
Jiyong Parkf9332f12018-02-01 00:54:12 +0900247 // Make this module available when building for recovery
248 Recovery_available *bool
249
Colin Crossae6c5202019-11-20 13:35:50 -0800250 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800251 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800252 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800253 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900254 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900255
256 // Allows this module to use non-APEX version of libraries. Useful
257 // for building binaries that are started before APEXes are activated.
258 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900259
260 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
261 // see soong/cc/config/vndk.go
262 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900263
264 // Used by vendor snapshot to record dependencies from snapshot modules.
265 SnapshotSharedLibs []string `blueprint:"mutated"`
266 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000267
268 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000269
270 // Set by factories of module types that can only be referenced from variants compiled against
271 // the SDK.
272 AlwaysSdk bool `blueprint:"mutated"`
273
274 // Variant is an SDK variant created by sdkMutator
275 IsSdkVariant bool `blueprint:"mutated"`
276 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
277 // variant to have a ".sdk" suffix.
278 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700279}
280
281type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900282 // whether this module should be allowed to be directly depended by other
283 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900284 // In addition, this module should be allowed to be directly depended by
285 // product modules with `product_specific: true`.
286 // If set to true, three variants will be built separately, one like
287 // normal, another limited to the set of libraries and headers
288 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700289 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900290 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700291 // so it shouldn't have any unversioned runtime dependencies, or
292 // make assumptions about the system that may not be true in the
293 // future.
294 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900295 // If set to false, this module becomes inaccessible from /vendor or /product
296 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900297 //
298 // Default value is true when vndk: {enabled: true} or vendor: true.
299 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700300 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900301 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700302 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900303
304 // whether this module is capable of being loaded with other instance
305 // (possibly an older version) of the same module in the same process.
306 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
307 // can be double loaded in a vendor process if the library is also a
308 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
309 // explicitly marked as `double_loadable: true` by the owner, or the dependency
310 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
311 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800312}
313
Colin Crossca860ac2016-01-04 14:34:37 -0800314type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800315 static() bool
316 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900317 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900318 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900319 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700320 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900321 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700322 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800323 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700324 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800325 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900326 isLlndk(config android.Config) bool
327 isLlndkPublic(config android.Config) bool
328 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900329 isVndk() bool
330 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800331 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900332 inProduct() bool
333 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800334 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900335 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800336 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700337 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700338 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800339 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800340 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800341 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800342 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800343 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900344 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900345 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900346 hasStubsVariants() bool
347 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900348 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800349 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700350 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800351}
352
353type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700354 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800355 ModuleContextIntf
356}
357
358type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700359 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800360 ModuleContextIntf
361}
362
Colin Cross37047f12016-12-13 17:06:13 -0800363type DepsContext interface {
364 android.BottomUpMutatorContext
365 ModuleContextIntf
366}
367
Colin Crossca860ac2016-01-04 14:34:37 -0800368type feature interface {
369 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800370 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800371 flags(ctx ModuleContext, flags Flags) Flags
372 props() []interface{}
373}
374
375type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700376 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800377 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800378 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700379 compilerProps() []interface{}
380
Colin Cross76fada02016-07-27 10:31:13 -0700381 appendCflags([]string)
382 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700383 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800384}
385
386type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700387 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800388 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700389 linkerFlags(ctx ModuleContext, flags Flags) Flags
390 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800391 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700392
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700393 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700394 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900395 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700396
397 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900398 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000399
400 // Get the deps that have been explicitly specified in the properties.
401 // Only updates the
402 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
403}
404
405type specifiedDeps struct {
406 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000407 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800408}
409
410type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700411 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700412 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000413 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800414 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700415 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700416 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900417 relativeInstallPath() string
Martin Stjernholmbf37d162020-03-31 16:05:34 +0100418 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800419}
420
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800421type xref interface {
422 XrefCcFiles() android.Paths
423}
424
Colin Crossc99deeb2016-04-11 15:06:20 -0700425var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700426 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
427 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
428 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
429 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
430 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800431 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700432 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
433 headerDepTag = DependencyTag{Name: "header", Library: true}
434 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
435 genSourceDepTag = DependencyTag{Name: "gen source"}
436 genHeaderDepTag = DependencyTag{Name: "gen header"}
437 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
438 objDepTag = DependencyTag{Name: "obj"}
439 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
440 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
441 reuseObjTag = DependencyTag{Name: "reuse objects"}
442 staticVariantTag = DependencyTag{Name: "static variant"}
443 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
444 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
445 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
446 runtimeDepTag = DependencyTag{Name: "runtime lib"}
Ivan Lozano183a3212019-10-18 14:18:45 -0700447 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700448)
449
Roland Levillainf89cd092019-07-29 16:22:59 +0100450func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700451 ccDepTag, ok := depTag.(DependencyTag)
452 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100453}
454
455func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700456 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100457 return ok && ccDepTag == runtimeDepTag
458}
459
460func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700461 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100462 return ok && ccDepTag == testPerSrcDepTag
463}
464
Colin Crossca860ac2016-01-04 14:34:37 -0800465// Module contains the properties and members used by all C/C++ module types, and implements
466// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
467// to construct the output file. Behavior can be customized with a Customizer interface
468type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700469 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700470 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900471 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900472 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700473
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700474 Properties BaseProperties
475 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700476
Colin Crossca860ac2016-01-04 14:34:37 -0800477 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700478 hod android.HostOrDeviceSupported
479 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700480
Paul Duffina0843f62019-12-13 19:50:38 +0000481 // Allowable SdkMemberTypes of this module type.
482 sdkMemberTypes []android.SdkMemberType
483
Colin Crossca860ac2016-01-04 14:34:37 -0800484 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700485 features []feature
486 compiler compiler
487 linker linker
488 installer installer
489 stl *stl
490 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800491 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800492 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900493 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700494 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700495 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800496
Colin Cross635c3b02016-05-18 15:37:25 -0700497 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800498
Colin Crossb98c8b02016-07-29 13:44:28 -0700499 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700500
501 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800502
503 // Flags used to compile this module
504 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700505
506 // 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 -0800507 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700508 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800509 depsInLinkOrder android.Paths
510
511 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700512 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900513
514 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800515 // Kythe (source file indexer) paths for this compilation module
516 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900517
518 // For apex variants, this is set as apex.min_sdk_version
519 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700520}
521
Ivan Lozano52767be2019-10-18 14:49:46 -0700522func (c *Module) Toc() android.OptionalPath {
523 if c.linker != nil {
524 if library, ok := c.linker.(libraryInterface); ok {
525 return library.toc()
526 }
527 }
528 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
529}
530
531func (c *Module) ApiLevel() string {
532 if c.linker != nil {
533 if stub, ok := c.linker.(*stubDecorator); ok {
534 return stub.properties.ApiLevel
535 }
536 }
537 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
538}
539
540func (c *Module) Static() bool {
541 if c.linker != nil {
542 if library, ok := c.linker.(libraryInterface); ok {
543 return library.static()
544 }
545 }
546 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
547}
548
549func (c *Module) Shared() bool {
550 if c.linker != nil {
551 if library, ok := c.linker.(libraryInterface); ok {
552 return library.shared()
553 }
554 }
555 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
556}
557
558func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000559 if c.stl != nil {
560 return c.stl.Properties.SelectedStl
561 }
562 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700563}
564
565func (c *Module) ToolchainLibrary() bool {
566 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
567 return true
568 }
569 return false
570}
571
572func (c *Module) NdkPrebuiltStl() bool {
573 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
574 return true
575 }
576 return false
577}
578
579func (c *Module) StubDecorator() bool {
580 if _, ok := c.linker.(*stubDecorator); ok {
581 return true
582 }
583 return false
584}
585
586func (c *Module) SdkVersion() string {
587 return String(c.Properties.Sdk_version)
588}
589
Artur Satayev480e25b2020-04-27 18:53:18 +0100590func (c *Module) MinSdkVersion() string {
591 return String(c.Properties.Min_sdk_version)
592}
593
Colin Crossc511bc52020-04-07 16:50:32 +0000594func (c *Module) AlwaysSdk() bool {
595 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
596}
597
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800598func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700599 if c.linker != nil {
600 if library, ok := c.linker.(exportedFlagsProducer); ok {
601 return library.exportedDirs()
602 }
603 }
604 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
605}
606
607func (c *Module) HasStaticVariant() bool {
608 if c.staticVariant != nil {
609 return true
610 }
611 return false
612}
613
614func (c *Module) GetStaticVariant() LinkableInterface {
615 return c.staticVariant
616}
617
618func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
619 c.depsInLinkOrder = depsInLinkOrder
620}
621
622func (c *Module) GetDepsInLinkOrder() []android.Path {
623 return c.depsInLinkOrder
624}
625
626func (c *Module) StubsVersions() []string {
627 if c.linker != nil {
628 if library, ok := c.linker.(*libraryDecorator); ok {
629 return library.Properties.Stubs.Versions
630 }
631 }
632 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
633}
634
635func (c *Module) CcLibrary() bool {
636 if c.linker != nil {
637 if _, ok := c.linker.(*libraryDecorator); ok {
638 return true
639 }
640 }
641 return false
642}
643
644func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700645 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700646 return true
647 }
648 return false
649}
650
Ivan Lozano2b262972019-11-21 12:30:50 -0800651func (c *Module) NonCcVariants() bool {
652 return false
653}
654
Ivan Lozano183a3212019-10-18 14:18:45 -0700655func (c *Module) SetBuildStubs() {
656 if c.linker != nil {
657 if library, ok := c.linker.(*libraryDecorator); ok {
658 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700659 c.Properties.HideFromMake = true
660 c.sanitize = nil
661 c.stl = nil
662 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700663 return
664 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000665 if _, ok := c.linker.(*llndkStubDecorator); ok {
666 c.Properties.HideFromMake = true
667 return
668 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700669 }
670 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
671}
672
Ivan Lozano52767be2019-10-18 14:49:46 -0700673func (c *Module) BuildStubs() bool {
674 if c.linker != nil {
675 if library, ok := c.linker.(*libraryDecorator); ok {
676 return library.buildStubs()
677 }
678 }
679 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
680}
681
Ivan Lozano183a3212019-10-18 14:18:45 -0700682func (c *Module) SetStubsVersions(version string) {
683 if c.linker != nil {
684 if library, ok := c.linker.(*libraryDecorator); ok {
685 library.MutatedProperties.StubsVersion = version
686 return
687 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000688 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
689 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
690 return
691 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700692 }
693 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
694}
695
Jooyung Han03b51852020-02-26 22:45:42 +0900696func (c *Module) StubsVersion() string {
697 if c.linker != nil {
698 if library, ok := c.linker.(*libraryDecorator); ok {
699 return library.MutatedProperties.StubsVersion
700 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000701 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
702 return llndk.libraryDecorator.MutatedProperties.StubsVersion
703 }
Jooyung Han03b51852020-02-26 22:45:42 +0900704 }
705 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
706}
707
Ivan Lozano183a3212019-10-18 14:18:45 -0700708func (c *Module) SetStatic() {
709 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700710 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700711 library.setStatic()
712 return
713 }
714 }
715 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
716}
717
718func (c *Module) SetShared() {
719 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700720 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700721 library.setShared()
722 return
723 }
724 }
725 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
726}
727
728func (c *Module) BuildStaticVariant() bool {
729 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700730 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700731 return library.buildStatic()
732 }
733 }
734 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
735}
736
737func (c *Module) BuildSharedVariant() bool {
738 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700739 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700740 return library.buildShared()
741 }
742 }
743 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
744}
745
746func (c *Module) Module() android.Module {
747 return c
748}
749
Jiyong Parkc20eee32018-09-05 22:36:17 +0900750func (c *Module) OutputFile() android.OptionalPath {
751 return c.outputFile
752}
753
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400754func (c *Module) CoverageFiles() android.Paths {
755 if c.linker != nil {
756 if library, ok := c.linker.(libraryInterface); ok {
757 return library.objs().coverageFiles
758 }
759 }
760 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
761}
762
Ivan Lozano183a3212019-10-18 14:18:45 -0700763var _ LinkableInterface = (*Module)(nil)
764
Jiyong Park719b4462019-01-13 00:39:51 +0900765func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900766 if c.linker != nil {
767 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900768 }
769 return nil
770}
771
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900772func (c *Module) CoverageOutputFile() android.OptionalPath {
773 if c.linker != nil {
774 return c.linker.coverageOutputFilePath()
775 }
776 return android.OptionalPath{}
777}
778
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900779func (c *Module) RelativeInstallPath() string {
780 if c.installer != nil {
781 return c.installer.relativeInstallPath()
782 }
783 return ""
784}
785
Jooyung Han344d5432019-08-23 11:17:39 +0900786func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900787 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900788}
789
Colin Cross36242852017-06-23 15:06:31 -0700790func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700791 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800792 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700793 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800794 }
795 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700796 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800797 }
798 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700799 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800800 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700801 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700802 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700803 }
Colin Cross16b23492016-01-06 14:41:07 -0800804 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700805 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800806 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800807 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700808 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800809 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800810 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700811 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800812 }
Justin Yun8effde42017-06-23 19:24:43 +0900813 if c.vndkdep != nil {
814 c.AddProperties(c.vndkdep.props()...)
815 }
Stephen Craneba090d12017-05-09 15:44:35 -0700816 if c.lto != nil {
817 c.AddProperties(c.lto.props()...)
818 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700819 if c.pgo != nil {
820 c.AddProperties(c.pgo.props()...)
821 }
Colin Crossca860ac2016-01-04 14:34:37 -0800822 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700823 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800824 }
Colin Crossc472d572015-03-17 15:06:21 -0700825
Colin Crossa9d8bee2018-10-02 13:59:46 -0700826 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700827 // Windows builds always prefer 32-bit
828 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700829 })
Colin Cross36242852017-06-23 15:06:31 -0700830 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900831 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900832 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900833 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900834
Colin Cross36242852017-06-23 15:06:31 -0700835 return c
Colin Crossc472d572015-03-17 15:06:21 -0700836}
837
Colin Crossb916a382016-07-29 17:28:03 -0700838// Returns true for dependency roots (binaries)
839// TODO(ccross): also handle dlopenable libraries
840func (c *Module) isDependencyRoot() bool {
841 if root, ok := c.linker.(interface {
842 isDependencyRoot() bool
843 }); ok {
844 return root.isDependencyRoot()
845 }
846 return false
847}
848
Justin Yun5f7f7e82019-11-18 19:52:14 +0900849// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
850// "product" and "vendor" variant modules return true for this function.
851// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
852// "soc_specific: true" and more vendor installed modules are included here.
853// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
854// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700855func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900856 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700857}
858
Colin Crossc511bc52020-04-07 16:50:32 +0000859func (c *Module) canUseSdk() bool {
860 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
861}
862
863func (c *Module) UseSdk() bool {
864 if c.canUseSdk() {
865 return String(c.Properties.Sdk_version) != ""
866 }
867 return false
868}
869
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800870func (c *Module) isCoverageVariant() bool {
871 return c.coverage.Properties.IsCoverageVariant
872}
873
Peter Collingbournead84f972019-12-17 16:46:18 -0800874func (c *Module) IsNdk() bool {
Dan Albertde5aade2020-06-30 12:32:51 -0700875 return inList(c.Name(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800876}
877
Inseob Kim9516ee92019-05-09 10:56:13 +0900878func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800879 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900880 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800881}
882
Inseob Kim9516ee92019-05-09 10:56:13 +0900883func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800884 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900885 name := c.BaseModuleName()
886 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800887}
888
Inseob Kim9516ee92019-05-09 10:56:13 +0900889func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800890 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900891 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800892}
893
Ivan Lozano52767be2019-10-18 14:49:46 -0700894func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800895 if vndkdep := c.vndkdep; vndkdep != nil {
896 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900897 }
898 return false
899}
900
Yi Kong7e53c572018-02-14 18:16:12 +0800901func (c *Module) isPgoCompile() bool {
902 if pgo := c.pgo; pgo != nil {
903 return pgo.Properties.PgoCompile
904 }
905 return false
906}
907
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800908func (c *Module) isNDKStubLibrary() bool {
909 if _, ok := c.compiler.(*stubDecorator); ok {
910 return true
911 }
912 return false
913}
914
Logan Chienf3511742017-10-31 18:04:35 +0800915func (c *Module) isVndkSp() bool {
916 if vndkdep := c.vndkdep; vndkdep != nil {
917 return vndkdep.isVndkSp()
918 }
919 return false
920}
921
922func (c *Module) isVndkExt() bool {
923 if vndkdep := c.vndkdep; vndkdep != nil {
924 return vndkdep.isVndkExt()
925 }
926 return false
927}
928
Ivan Lozano52767be2019-10-18 14:49:46 -0700929func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900930 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800931}
932
Logan Chienf3511742017-10-31 18:04:35 +0800933func (c *Module) getVndkExtendsModuleName() string {
934 if vndkdep := c.vndkdep; vndkdep != nil {
935 return vndkdep.getVndkExtendsModuleName()
936 }
937 return ""
938}
939
Justin Yun5f7f7e82019-11-18 19:52:14 +0900940// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900941// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700942func (c *Module) HasVendorVariant() bool {
943 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900944}
945
Justin Yun5f7f7e82019-11-18 19:52:14 +0900946const (
947 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
948 // against the VNDK.
949 VendorVariationPrefix = "vendor."
950
951 // ProductVariationPrefix is the variant prefix used for /product code that compiles
952 // against the VNDK.
953 ProductVariationPrefix = "product."
954)
955
956// Returns true if the module is "product" variant. Usually these modules are installed in /product
957func (c *Module) inProduct() bool {
958 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
959}
960
961// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
962func (c *Module) inVendor() bool {
963 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
964}
965
Yifan Hong1b3348d2020-01-21 15:53:22 -0800966func (c *Module) InRamdisk() bool {
967 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
968}
969
Ivan Lozano52767be2019-10-18 14:49:46 -0700970func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800971 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900972}
973
Yifan Hong1b3348d2020-01-21 15:53:22 -0800974func (c *Module) OnlyInRamdisk() bool {
975 return c.ModuleBase.InstallInRamdisk()
976}
977
Ivan Lozano52767be2019-10-18 14:49:46 -0700978func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900979 return c.ModuleBase.InstallInRecovery()
980}
981
Jiyong Park25fc6a92018-11-18 18:02:45 +0900982func (c *Module) IsStubs() bool {
983 if library, ok := c.linker.(*libraryDecorator); ok {
984 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900985 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
986 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900987 }
988 return false
989}
990
991func (c *Module) HasStubsVariants() bool {
992 if library, ok := c.linker.(*libraryDecorator); ok {
993 return len(library.Properties.Stubs.Versions) > 0
994 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700995 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
996 return len(library.Properties.Stubs.Versions) > 0
997 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900998 return false
999}
1000
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001001func (c *Module) bootstrap() bool {
1002 return Bool(c.Properties.Bootstrap)
1003}
1004
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001005func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001006 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1007 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1008 return false
1009 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001010 return c.linker != nil && c.linker.nativeCoverage()
1011}
1012
Inseob Kim8471cda2019-11-15 09:59:12 +09001013func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001014 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1015 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001016 }
1017 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001018}
1019
Jiyong Park73c54ee2019-10-22 20:31:18 +09001020func (c *Module) ExportedIncludeDirs() android.Paths {
1021 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1022 return flagsProducer.exportedDirs()
1023 }
Jiyong Park232e7852019-11-04 12:23:40 +09001024 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001025}
1026
1027func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1028 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1029 return flagsProducer.exportedSystemDirs()
1030 }
Jiyong Park232e7852019-11-04 12:23:40 +09001031 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001032}
1033
1034func (c *Module) ExportedFlags() []string {
1035 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1036 return flagsProducer.exportedFlags()
1037 }
Jiyong Park232e7852019-11-04 12:23:40 +09001038 return nil
1039}
1040
1041func (c *Module) ExportedDeps() android.Paths {
1042 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1043 return flagsProducer.exportedDeps()
1044 }
1045 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001046}
1047
Inseob Kimd110f872019-12-06 13:15:38 +09001048func (c *Module) ExportedGeneratedHeaders() android.Paths {
1049 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1050 return flagsProducer.exportedGeneratedHeaders()
1051 }
1052 return nil
1053}
1054
Jiyong Parkf1194352019-02-25 11:05:47 +09001055func isBionic(name string) bool {
1056 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001057 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001058 return true
1059 }
1060 return false
1061}
1062
Martin Stjernholm279de572019-09-10 23:18:20 +01001063func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001064 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001065 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001066 }
1067 return isBionic(name)
1068}
1069
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001070func (c *Module) XrefCcFiles() android.Paths {
1071 return c.kytheFiles
1072}
1073
Colin Crossca860ac2016-01-04 14:34:37 -08001074type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001075 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001076 moduleContextImpl
1077}
1078
Colin Cross37047f12016-12-13 17:06:13 -08001079type depsContext struct {
1080 android.BottomUpMutatorContext
1081 moduleContextImpl
1082}
1083
Colin Crossca860ac2016-01-04 14:34:37 -08001084type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001085 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001086 moduleContextImpl
1087}
1088
Justin Yun5f7f7e82019-11-18 19:52:14 +09001089func (ctx *moduleContext) ProductSpecific() bool {
1090 return ctx.ModuleContext.ProductSpecific() ||
1091 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1092}
1093
Jiyong Park2db76922017-11-08 16:03:48 +09001094func (ctx *moduleContext) SocSpecific() bool {
1095 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001096 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001097}
1098
Colin Crossca860ac2016-01-04 14:34:37 -08001099type moduleContextImpl struct {
1100 mod *Module
1101 ctx BaseModuleContext
1102}
1103
Colin Crossb98c8b02016-07-29 13:44:28 -07001104func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001105 return ctx.mod.toolchain(ctx.ctx)
1106}
1107
1108func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001109 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001110}
1111
1112func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001113 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001114}
1115
Jiyong Park1d1119f2019-07-29 21:27:18 +09001116func (ctx *moduleContextImpl) header() bool {
1117 return ctx.mod.header()
1118}
1119
Inseob Kim7f283f42020-06-01 21:53:49 +09001120func (ctx *moduleContextImpl) binary() bool {
1121 return ctx.mod.binary()
1122}
1123
Inseob Kim1042d292020-06-01 23:23:05 +09001124func (ctx *moduleContextImpl) object() bool {
1125 return ctx.mod.object()
1126}
1127
Jooyung Hanccce2f22020-03-07 03:45:53 +09001128func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001129 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001130}
1131
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001132func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001133 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001134}
1135
1136func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001137 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001138 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001139 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001140 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001141 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001142 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001143 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001144 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001145 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001146 }
1147 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001148}
1149
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001150func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001151 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001152}
Justin Yun8effde42017-06-23 19:24:43 +09001153
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001154func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001155 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001156}
1157
Inseob Kim9516ee92019-05-09 10:56:13 +09001158func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1159 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001160}
1161
Inseob Kim9516ee92019-05-09 10:56:13 +09001162func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1163 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001164}
1165
Inseob Kim9516ee92019-05-09 10:56:13 +09001166func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1167 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001168}
1169
Logan Chienf3511742017-10-31 18:04:35 +08001170func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001171 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001172}
1173
Yi Kong7e53c572018-02-14 18:16:12 +08001174func (ctx *moduleContextImpl) isPgoCompile() bool {
1175 return ctx.mod.isPgoCompile()
1176}
1177
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001178func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1179 return ctx.mod.isNDKStubLibrary()
1180}
1181
Justin Yun8effde42017-06-23 19:24:43 +09001182func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001183 return ctx.mod.isVndkSp()
1184}
1185
1186func (ctx *moduleContextImpl) isVndkExt() bool {
1187 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001188}
1189
Vic Yangefd249e2018-11-12 20:19:56 -08001190func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001191 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001192}
1193
Justin Yun5f7f7e82019-11-18 19:52:14 +09001194func (ctx *moduleContextImpl) inProduct() bool {
1195 return ctx.mod.inProduct()
1196}
1197
1198func (ctx *moduleContextImpl) inVendor() bool {
1199 return ctx.mod.inVendor()
1200}
1201
Yifan Hong1b3348d2020-01-21 15:53:22 -08001202func (ctx *moduleContextImpl) inRamdisk() bool {
1203 return ctx.mod.InRamdisk()
1204}
1205
Jiyong Parkf9332f12018-02-01 00:54:12 +09001206func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001207 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001208}
1209
Logan Chien2f2b8902018-07-10 15:01:19 +08001210// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001211func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001212 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1213 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001214 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001215
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001216 // Coverage builds have extra symbols.
1217 if ctx.mod.isCoverageVariant() {
1218 return false
1219 }
1220
Doug Hornc32c6b02019-01-17 14:44:05 -08001221 if ctx.ctx.Fuchsia() {
1222 return false
1223 }
1224
Logan Chien2f2b8902018-07-10 15:01:19 +08001225 if sanitize := ctx.mod.sanitize; sanitize != nil {
1226 if !sanitize.isVariantOnProductionDevice() {
1227 return false
1228 }
1229 }
1230 if !ctx.ctx.Device() {
1231 // Host modules do not need ABI dumps.
1232 return false
1233 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001234 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001235 // Stubs do not need ABI dumps.
1236 return false
1237 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001238 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001239}
1240
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001241func (ctx *moduleContextImpl) selectedStl() string {
1242 if stl := ctx.mod.stl; stl != nil {
1243 return stl.Properties.SelectedStl
1244 }
1245 return ""
1246}
1247
Ivan Lozanobd721262018-11-27 14:33:03 -08001248func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1249 return ctx.mod.linker.useClangLld(actx)
1250}
1251
Colin Crossce75d2c2016-10-06 16:12:58 -07001252func (ctx *moduleContextImpl) baseModuleName() string {
1253 return ctx.mod.ModuleBase.BaseModuleName()
1254}
1255
Logan Chienf3511742017-10-31 18:04:35 +08001256func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1257 return ctx.mod.getVndkExtendsModuleName()
1258}
1259
Logan Chiene274fc92019-12-03 11:18:32 -08001260func (ctx *moduleContextImpl) isForPlatform() bool {
1261 return ctx.mod.IsForPlatform()
1262}
1263
Jiyong Park58e364a2019-01-19 19:24:06 +09001264func (ctx *moduleContextImpl) apexName() string {
1265 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001266}
1267
Jooyung Hanccce2f22020-03-07 03:45:53 +09001268func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001269 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001270}
1271
Jiyong Parkb0788572018-12-20 22:10:17 +09001272func (ctx *moduleContextImpl) hasStubsVariants() bool {
1273 return ctx.mod.HasStubsVariants()
1274}
1275
1276func (ctx *moduleContextImpl) isStubs() bool {
1277 return ctx.mod.IsStubs()
1278}
1279
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001280func (ctx *moduleContextImpl) bootstrap() bool {
1281 return ctx.mod.bootstrap()
1282}
1283
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001284func (ctx *moduleContextImpl) nativeCoverage() bool {
1285 return ctx.mod.nativeCoverage()
1286}
1287
Colin Cross635c3b02016-05-18 15:37:25 -07001288func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001289 return &Module{
1290 hod: hod,
1291 multilib: multilib,
1292 }
1293}
1294
Colin Cross635c3b02016-05-18 15:37:25 -07001295func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001296 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001297 module.features = []feature{
1298 &tidyFeature{},
1299 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001300 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001301 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001302 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001303 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001304 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001305 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001306 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001307 return module
1308}
1309
Colin Crossce75d2c2016-10-06 16:12:58 -07001310func (c *Module) Prebuilt() *android.Prebuilt {
1311 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1312 return p.prebuilt()
1313 }
1314 return nil
1315}
1316
1317func (c *Module) Name() string {
1318 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001319 if p, ok := c.linker.(interface {
1320 Name(string) string
1321 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001322 name = p.Name(name)
1323 }
1324 return name
1325}
1326
Alex Light3d673592019-01-18 14:37:31 -08001327func (c *Module) Symlinks() []string {
1328 if p, ok := c.installer.(interface {
1329 symlinkList() []string
1330 }); ok {
1331 return p.symlinkList()
1332 }
1333 return nil
1334}
1335
Jeff Gaston294356f2017-09-27 17:05:30 -07001336// orderDeps reorders dependencies into a list such that if module A depends on B, then
1337// A will precede B in the resultant list.
1338// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001339// Note that directSharedDeps should be the analogous static library for each shared lib dep
1340func 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 -07001341 // If A depends on B, then
1342 // Every list containing A will also contain B later in the list
1343 // So, after concatenating all lists, the final instance of B will have come from the same
1344 // original list as the final instance of A
1345 // So, the final instance of B will be later in the concatenation than the final A
1346 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1347 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001348 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001349 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001350 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1351 }
1352 for _, dep := range directSharedDeps {
1353 orderedAllDeps = append(orderedAllDeps, dep)
1354 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001355 }
1356
Colin Crossb6715442017-10-24 11:13:31 -07001357 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001358
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001359 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001360 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001361 // resultant list to only what the caller has chosen to include in directStaticDeps
1362 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001363
1364 return orderedAllDeps, orderedDeclaredDeps
1365}
1366
Ivan Lozano183a3212019-10-18 14:18:45 -07001367func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001368 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001369 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001370 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1371 staticDepFiles := []android.Path{}
1372 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001373 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1374 if dep.OutputFile().Valid() {
1375 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1376 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1377 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001378 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001379 sharedDepFiles := []android.Path{}
1380 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001381 if sharedDep.HasStaticVariant() {
1382 staticAnalogue := sharedDep.GetStaticVariant()
1383 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1384 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001385 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001386 }
1387
1388 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001389 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1390 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001391
1392 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001393}
1394
Roland Levillainf89cd092019-07-29 16:22:59 +01001395func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1396 test, ok := c.linker.(testPerSrc)
1397 return ok && test.isAllTestsVariation()
1398}
1399
Liz Kammer1c14a212020-05-12 15:26:55 -07001400func (c *Module) DataPaths() android.Paths {
1401 if p, ok := c.installer.(interface {
1402 dataPaths() android.Paths
1403 }); ok {
1404 return p.dataPaths()
1405 }
1406 return nil
1407}
1408
Justin Yun5f7f7e82019-11-18 19:52:14 +09001409func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1410 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1411 // "current", it will append the VNDK version to the name suffix.
1412 var vndkVersion string
1413 var nameSuffix string
1414 if c.inProduct() {
1415 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1416 nameSuffix = productSuffix
1417 } else {
1418 vndkVersion = ctx.DeviceConfig().VndkVersion()
1419 nameSuffix = vendorSuffix
1420 }
1421 if vndkVersion == "current" {
1422 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1423 }
1424 if c.Properties.VndkVersion != vndkVersion {
1425 // add version suffix only if the module is using different vndk version than the
1426 // version in product or vendor partition.
1427 nameSuffix += "." + c.Properties.VndkVersion
1428 }
1429 return nameSuffix
1430}
1431
Colin Cross635c3b02016-05-18 15:37:25 -07001432func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001433 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001434 //
1435 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1436 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1437 // module and return early, as this module does not produce an output file per se.
1438 if c.IsTestPerSrcAllTestsVariation() {
1439 c.outputFile = android.OptionalPath{}
1440 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001441 }
1442
Jooyung Han38002912019-05-16 04:01:54 +09001443 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001444
Inseob Kim64c43952019-08-26 16:52:35 +09001445 c.Properties.SubName = ""
1446
1447 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1448 c.Properties.SubName += nativeBridgeSuffix
1449 }
1450
Justin Yun5f7f7e82019-11-18 19:52:14 +09001451 _, llndk := c.linker.(*llndkStubDecorator)
1452 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1453 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1454 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1455 // added for product variant only when we have vendor and product variants with core
1456 // variant. The suffix is not added for vendor-only or product-only module.
1457 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1458 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001459 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1460 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1461 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001462 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1463 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001464 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001465 c.Properties.SubName += recoverySuffix
Colin Crossc511bc52020-04-07 16:50:32 +00001466 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1467 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001468 }
1469
Colin Crossca860ac2016-01-04 14:34:37 -08001470 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001471 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001472 moduleContextImpl: moduleContextImpl{
1473 mod: c,
1474 },
1475 }
1476 ctx.ctx = ctx
1477
Colin Crossf18e1102017-11-16 14:33:08 -08001478 deps := c.depsToPaths(ctx)
1479 if ctx.Failed() {
1480 return
1481 }
1482
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001483 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1484 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1485 }
1486
Colin Crossca860ac2016-01-04 14:34:37 -08001487 flags := Flags{
1488 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001489 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001490 }
Colin Crossca860ac2016-01-04 14:34:37 -08001491 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001492 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001493 }
1494 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001495 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001496 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001497 if c.stl != nil {
1498 flags = c.stl.flags(ctx, flags)
1499 }
Colin Cross16b23492016-01-06 14:41:07 -08001500 if c.sanitize != nil {
1501 flags = c.sanitize.flags(ctx, flags)
1502 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001503 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001504 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001505 }
Stephen Craneba090d12017-05-09 15:44:35 -07001506 if c.lto != nil {
1507 flags = c.lto.flags(ctx, flags)
1508 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001509 if c.pgo != nil {
1510 flags = c.pgo.flags(ctx, flags)
1511 }
Colin Crossca860ac2016-01-04 14:34:37 -08001512 for _, feature := range c.features {
1513 flags = feature.flags(ctx, flags)
1514 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001515 if ctx.Failed() {
1516 return
1517 }
1518
Colin Cross4af21ed2019-11-04 09:37:55 -08001519 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1520 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1521 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001522
Colin Cross4af21ed2019-11-04 09:37:55 -08001523 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001524
1525 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001526 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001527 }
1528 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001529 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001530 }
1531
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001532 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001533 // We need access to all the flags seen by a source file.
1534 if c.sabi != nil {
1535 flags = c.sabi.flags(ctx, flags)
1536 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001537
Colin Cross4af21ed2019-11-04 09:37:55 -08001538 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001539
Colin Crossca860ac2016-01-04 14:34:37 -08001540 // Optimization to reduce size of build.ninja
1541 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001542 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1543 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1544 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1545 flags.Local.CFlags = []string{"$cflags"}
1546 flags.Local.CppFlags = []string{"$cppflags"}
1547 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001548
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001549 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001550 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001551 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001552 if ctx.Failed() {
1553 return
1554 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001555 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001556 }
1557
Colin Crossca860ac2016-01-04 14:34:37 -08001558 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001559 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001560 if ctx.Failed() {
1561 return
1562 }
Colin Cross635c3b02016-05-18 15:37:25 -07001563 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001564
1565 // If a lib is directly included in any of the APEXes, unhide the stubs
1566 // variant having the latest version gets visible to make. In addition,
1567 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1568 // force anything in the make world to link against the stubs library.
1569 // (unless it is explicitly referenced via .bootstrap suffix or the
1570 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001571 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001572 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001573 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001574 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001575 c.Properties.HideFromMake = false // unhide
1576 // Note: this is still non-installable
1577 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001578
1579 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1580 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1581 if isSnapshotAware(ctx, c) {
1582 i.collectHeadersForSnapshot(ctx)
1583 }
1584 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001585 }
Colin Cross5049f022015-03-18 13:28:46 -07001586
Inseob Kim1f086e22019-05-09 13:29:15 +09001587 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001588 c.installer.install(ctx, c.outputFile.Path())
1589 if ctx.Failed() {
1590 return
Colin Crossca860ac2016-01-04 14:34:37 -08001591 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001592 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1593 // If the module has been specifically configure to not be installed then
1594 // skip the installation as otherwise it will break when running inside make
1595 // as the output path to install will not be specified. Not all uninstallable
1596 // modules can skip installation as some are needed for resolving make side
1597 // dependencies.
1598 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001599 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001600}
1601
Colin Cross0ea8ba82019-06-06 14:33:29 -07001602func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001603 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001604 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001605 }
Colin Crossca860ac2016-01-04 14:34:37 -08001606 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001607}
1608
Colin Crossca860ac2016-01-04 14:34:37 -08001609func (c *Module) begin(ctx BaseModuleContext) {
1610 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001611 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001612 }
Colin Crossca860ac2016-01-04 14:34:37 -08001613 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001614 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001615 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001616 if c.stl != nil {
1617 c.stl.begin(ctx)
1618 }
Colin Cross16b23492016-01-06 14:41:07 -08001619 if c.sanitize != nil {
1620 c.sanitize.begin(ctx)
1621 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001622 if c.coverage != nil {
1623 c.coverage.begin(ctx)
1624 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001625 if c.sabi != nil {
1626 c.sabi.begin(ctx)
1627 }
Justin Yun8effde42017-06-23 19:24:43 +09001628 if c.vndkdep != nil {
1629 c.vndkdep.begin(ctx)
1630 }
Stephen Craneba090d12017-05-09 15:44:35 -07001631 if c.lto != nil {
1632 c.lto.begin(ctx)
1633 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001634 if c.pgo != nil {
1635 c.pgo.begin(ctx)
1636 }
Colin Crossca860ac2016-01-04 14:34:37 -08001637 for _, feature := range c.features {
1638 feature.begin(ctx)
1639 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001640 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001641 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001642 if err != nil {
1643 ctx.PropertyErrorf("sdk_version", err.Error())
1644 }
Nan Zhang0007d812017-11-07 10:57:05 -08001645 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001646 }
Colin Crossca860ac2016-01-04 14:34:37 -08001647}
1648
Colin Cross37047f12016-12-13 17:06:13 -08001649func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001650 deps := Deps{}
1651
1652 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001653 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001654 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001655 // Add the PGO dependency (the clang_rt.profile runtime library), which
1656 // sometimes depends on symbols from libgcc, before libgcc gets added
1657 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001658 if c.pgo != nil {
1659 deps = c.pgo.deps(ctx, deps)
1660 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001661 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001662 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001663 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001664 if c.stl != nil {
1665 deps = c.stl.deps(ctx, deps)
1666 }
Colin Cross16b23492016-01-06 14:41:07 -08001667 if c.sanitize != nil {
1668 deps = c.sanitize.deps(ctx, deps)
1669 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001670 if c.coverage != nil {
1671 deps = c.coverage.deps(ctx, deps)
1672 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001673 if c.sabi != nil {
1674 deps = c.sabi.deps(ctx, deps)
1675 }
Justin Yun8effde42017-06-23 19:24:43 +09001676 if c.vndkdep != nil {
1677 deps = c.vndkdep.deps(ctx, deps)
1678 }
Stephen Craneba090d12017-05-09 15:44:35 -07001679 if c.lto != nil {
1680 deps = c.lto.deps(ctx, deps)
1681 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001682 for _, feature := range c.features {
1683 deps = feature.deps(ctx, deps)
1684 }
1685
Colin Crossb6715442017-10-24 11:13:31 -07001686 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1687 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1688 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1689 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1690 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1691 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001692 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001693
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001694 for _, lib := range deps.ReexportSharedLibHeaders {
1695 if !inList(lib, deps.SharedLibs) {
1696 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1697 }
1698 }
1699
1700 for _, lib := range deps.ReexportStaticLibHeaders {
1701 if !inList(lib, deps.StaticLibs) {
1702 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1703 }
1704 }
1705
Colin Cross5950f382016-12-13 12:50:57 -08001706 for _, lib := range deps.ReexportHeaderLibHeaders {
1707 if !inList(lib, deps.HeaderLibs) {
1708 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1709 }
1710 }
1711
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001712 for _, gen := range deps.ReexportGeneratedHeaders {
1713 if !inList(gen, deps.GeneratedHeaders) {
1714 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1715 }
1716 }
1717
Colin Crossc99deeb2016-04-11 15:06:20 -07001718 return deps
1719}
1720
Dan Albert7e9d2952016-08-04 13:02:36 -07001721func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001722 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001723 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001724 moduleContextImpl: moduleContextImpl{
1725 mod: c,
1726 },
1727 }
1728 ctx.ctx = ctx
1729
Colin Crossca860ac2016-01-04 14:34:37 -08001730 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001731}
1732
Jiyong Park7ed9de32018-10-15 22:25:07 +09001733// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001734func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001735 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1736 version := name[sharp+1:]
1737 libname := name[:sharp]
1738 return libname, version
1739 }
1740 return name, ""
1741}
1742
Colin Cross1e676be2016-10-12 14:38:15 -07001743func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001744 if !c.Enabled() {
1745 return
1746 }
1747
Colin Cross37047f12016-12-13 17:06:13 -08001748 ctx := &depsContext{
1749 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001750 moduleContextImpl: moduleContextImpl{
1751 mod: c,
1752 },
1753 }
1754 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001755
Colin Crossc99deeb2016-04-11 15:06:20 -07001756 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001757
Dan Albert914449f2016-06-17 16:45:24 -07001758 variantNdkLibs := []string{}
1759 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001760 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001761 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001762 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001763 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001764 // 1. Name of an NDK library that refers to a prebuilt module.
1765 // For each of these, it adds the name of the prebuilt module (which will be in
1766 // prebuilts/ndk) to the list of nonvariant libs.
1767 // 2. Name of an NDK library that refers to an ndk_library module.
1768 // For each of these, it adds the name of the ndk_library module to the list of
1769 // variant libs.
1770 // 3. Anything else (so anything that isn't an NDK library).
1771 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001772 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001773 // The caller can then know to add the variantLibs dependencies differently from the
1774 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001775
Inseob Kim9516ee92019-05-09 10:56:13 +09001776 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001777 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1778
1779 rewriteVendorLibs := func(lib string) string {
1780 if isLlndkLibrary(lib, ctx.Config()) {
1781 return lib + llndkLibrarySuffix
1782 }
1783
1784 // only modules with BOARD_VNDK_VERSION uses snapshot.
1785 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1786 return lib
1787 }
1788
1789 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1790 return snapshot
1791 }
1792
1793 return lib
1794 }
1795
1796 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001797 variantLibs = []string{}
1798 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001799 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001800 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001801 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001802 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1803 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001804 } else if ctx.useVndk() {
1805 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001806 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001807 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001808 if actx.OtherModuleExists(vendorPublicLib) {
1809 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1810 } else {
1811 // This can happen if vendor_public_library module is defined in a
1812 // namespace that isn't visible to the current module. In that case,
1813 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001814 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001815 }
Dan Albert914449f2016-06-17 16:45:24 -07001816 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001817 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001818 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001819 }
1820 }
Dan Albert914449f2016-06-17 16:45:24 -07001821 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001822 }
1823
Inseob Kimeec88e12020-01-22 11:11:29 +09001824 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1825 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1826 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1827 if ctx.useVndk() {
1828 for idx, lib := range deps.RuntimeLibs {
1829 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1830 }
1831 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001832 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001833
Jiyong Park7e636d02019-01-28 16:16:54 +09001834 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001835 if c.linker != nil {
1836 if library, ok := c.linker.(*libraryDecorator); ok {
1837 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001838 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001839 }
1840 }
1841 }
1842
Inseob Kimeec88e12020-01-22 11:11:29 +09001843 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1844 // only modules with BOARD_VNDK_VERSION uses snapshot.
1845 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1846 return lib
1847 }
1848
1849 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1850 return snapshot
1851 }
1852
1853 return lib
1854 }
1855
1856 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001857 for _, lib := range deps.HeaderLibs {
1858 depTag := headerDepTag
1859 if inList(lib, deps.ReexportHeaderLibHeaders) {
1860 depTag = headerExportDepTag
1861 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001862
1863 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1864
Jiyong Park7e636d02019-01-28 16:16:54 +09001865 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001866 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001867 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001868 } else {
1869 actx.AddVariationDependencies(nil, depTag, lib)
1870 }
1871 }
1872
1873 if buildStubs {
1874 // Stubs lib does not have dependency to other static/shared libraries.
1875 // Don't proceed.
1876 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001877 }
Colin Cross5950f382016-12-13 12:50:57 -08001878
Inseob Kimc0907f12019-02-08 21:00:45 +09001879 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001880 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001881
Jiyong Park5d1598f2019-02-25 22:14:17 +09001882 for _, lib := range deps.WholeStaticLibs {
1883 depTag := wholeStaticDepTag
1884 if impl, ok := syspropImplLibraries[lib]; ok {
1885 lib = impl
1886 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001887
1888 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1889
Jiyong Park5d1598f2019-02-25 22:14:17 +09001890 actx.AddVariationDependencies([]blueprint.Variation{
1891 {Mutator: "link", Variation: "static"},
1892 }, depTag, lib)
1893 }
1894
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001895 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001896 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001897 if inList(lib, deps.ReexportStaticLibHeaders) {
1898 depTag = staticExportDepTag
1899 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001900
1901 if impl, ok := syspropImplLibraries[lib]; ok {
1902 lib = impl
1903 }
1904
Inseob Kimeec88e12020-01-22 11:11:29 +09001905 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1906
Dan Willemsen59339a22018-07-22 21:18:45 -07001907 actx.AddVariationDependencies([]blueprint.Variation{
1908 {Mutator: "link", Variation: "static"},
1909 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001910 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001911
Jooyung Han75568392020-03-20 04:29:24 +09001912 // staticUnwinderDep is treated as staticDep for Q apexes
1913 // so that native libraries/binaries are linked with static unwinder
1914 // because Q libc doesn't have unwinder APIs
1915 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001916 actx.AddVariationDependencies([]blueprint.Variation{
1917 {Mutator: "link", Variation: "static"},
Inseob Kim7f283f42020-06-01 21:53:49 +09001918 }, staticUnwinderDepTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001919 }
1920
Inseob Kimeec88e12020-01-22 11:11:29 +09001921 for _, lib := range deps.LateStaticLibs {
1922 actx.AddVariationDependencies([]blueprint.Variation{
1923 {Mutator: "link", Variation: "static"},
1924 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1925 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001926
Ivan Lozano183a3212019-10-18 14:18:45 -07001927 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001928 var variations []blueprint.Variation
1929 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001930 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001931 // Version is explicitly specified. i.e. libFoo#30
1932 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001933 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001934 }
1935 actx.AddVariationDependencies(variations, depTag, name)
1936
Jooyung Han03b51852020-02-26 22:45:42 +09001937 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001938 // The stubs library will be used when the depending module is built for APEX and
1939 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09001940 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09001941 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1942 // Note that depTag.ExplicitlyVersioned is false in this case.
1943 actx.AddVariationDependencies([]blueprint.Variation{
1944 {Mutator: "link", Variation: "shared"},
1945 {Mutator: "version", Variation: ver},
1946 }, depTag, name)
1947 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001948 }
1949 }
1950
Jiyong Park7ed9de32018-10-15 22:25:07 +09001951 // shared lib names without the #version suffix
1952 var sharedLibNames []string
1953
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001954 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001955 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001956 if c.static() {
1957 depTag = SharedFromStaticDepTag
1958 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001959 if inList(lib, deps.ReexportSharedLibHeaders) {
1960 depTag = sharedExportDepTag
1961 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001962
1963 if impl, ok := syspropImplLibraries[lib]; ok {
1964 lib = impl
1965 }
1966
Jiyong Park73c54ee2019-10-22 20:31:18 +09001967 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001968 sharedLibNames = append(sharedLibNames, name)
1969
Jiyong Park25fc6a92018-11-18 18:02:45 +09001970 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001971 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001972
Jiyong Park7ed9de32018-10-15 22:25:07 +09001973 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001974 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001975 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1976 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1977 // linking against both the stubs lib and the non-stubs lib at the same time.
1978 continue
1979 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001980 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001981 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001982
Dan Willemsen59339a22018-07-22 21:18:45 -07001983 actx.AddVariationDependencies([]blueprint.Variation{
1984 {Mutator: "link", Variation: "shared"},
1985 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001986
Colin Cross68861832016-07-08 10:41:41 -07001987 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001988
1989 for _, gen := range deps.GeneratedHeaders {
1990 depTag := genHeaderDepTag
1991 if inList(gen, deps.ReexportGeneratedHeaders) {
1992 depTag = genHeaderExportDepTag
1993 }
1994 actx.AddDependency(c, depTag, gen)
1995 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001996
Colin Cross42d48b72018-08-29 14:10:52 -07001997 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001998
Inseob Kim1042d292020-06-01 23:23:05 +09001999 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2000
Colin Crossc99deeb2016-04-11 15:06:20 -07002001 if deps.CrtBegin != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002002 actx.AddVariationDependencies(nil, CrtBeginDepTag, rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002003 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002004 if deps.CrtEnd != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002005 actx.AddVariationDependencies(nil, CrtEndDepTag, rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002006 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002007 if deps.LinkerFlagsFile != "" {
2008 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2009 }
2010 if deps.DynamicLinker != "" {
2011 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002012 }
Dan Albert914449f2016-06-17 16:45:24 -07002013
2014 version := ctx.sdkVersion()
2015 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002016 {Mutator: "ndk_api", Variation: version},
2017 {Mutator: "link", Variation: "shared"},
2018 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07002019 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002020 {Mutator: "ndk_api", Variation: version},
2021 {Mutator: "link", Variation: "shared"},
2022 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002023
2024 if vndkdep := c.vndkdep; vndkdep != nil {
2025 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002026 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002027 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002028 {Mutator: "link", Variation: "shared"},
2029 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002030 }
2031 }
Colin Cross6362e272015-10-29 15:25:03 -07002032}
Colin Cross21b9a242015-03-24 14:15:58 -07002033
Colin Crosse40b4ea2018-10-02 22:25:58 -07002034func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002035 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2036 c.beginMutator(ctx)
2037 }
2038}
2039
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002040// Whether a module can link to another module, taking into
2041// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07002042func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
2043 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002044 // Host code is not restricted
2045 return
2046 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002047
2048 // VNDK is cc.Module supported only for now.
2049 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002050 // Though vendor code is limited by the vendor mutator,
2051 // each vendor-available module needs to check
2052 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002053 if ccTo, ok := to.(*Module); ok {
2054 if ccFrom.vndkdep != nil {
2055 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2056 }
2057 } else {
2058 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002059 }
2060 return
2061 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002062 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002063 // Platform code can link to anything
2064 return
2065 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002066 if from.InRamdisk() {
2067 // Ramdisk code is not NDK
2068 return
2069 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002070 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002071 // Recovery code is not NDK
2072 return
2073 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002074 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002075 // These are always allowed
2076 return
2077 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002078 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002079 // These are allowed, but they don't set sdk_version
2080 return
2081 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002082 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002083 // These aren't real libraries, but are the stub shared libraries that are included in
2084 // the NDK.
2085 return
2086 }
Logan Chien834b9a62019-01-14 15:39:03 +08002087
Ivan Lozano52767be2019-10-18 14:49:46 -07002088 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002089 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2090 // to link to libc++ (non-NDK and without sdk_version).
2091 return
2092 }
2093
Ivan Lozano52767be2019-10-18 14:49:46 -07002094 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002095 // NDK code linking to platform code is never okay.
2096 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002097 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002098 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002099 }
2100
2101 // At this point we know we have two NDK libraries, but we need to
2102 // check that we're not linking against anything built against a higher
2103 // API level, as it is only valid to link against older or equivalent
2104 // APIs.
2105
Inseob Kim01a28722018-04-11 09:48:45 +09002106 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002107 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002108 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002109 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002110 // Current can't be linked against by anything else.
2111 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002112 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002113 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002114 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002115 if err != nil {
2116 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002117 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002118 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002119 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002120 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002121 if err != nil {
2122 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002123 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002124 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002125 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002126
Inseob Kim01a28722018-04-11 09:48:45 +09002127 if toApi > fromApi {
2128 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002129 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002130 }
2131 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002132 }
Dan Albert202fe492017-12-15 13:56:59 -08002133
2134 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002135 fromStl := from.SelectedStl()
2136 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002137 if fromStl == "" || toStl == "" {
2138 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002139 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002140 // We can be permissive with the system "STL" since it is only the C++
2141 // ABI layer, but in the future we should make sure that everyone is
2142 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002143 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002144 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002145 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2146 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002147 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002148}
2149
Jiyong Park5fb8c102018-04-09 12:03:06 +09002150// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002151// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2152// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002153// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002154func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2155 check := func(child, parent android.Module) bool {
2156 to, ok := child.(*Module)
2157 if !ok {
2158 // follow thru cc.Defaults, etc.
2159 return true
2160 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002161
Jooyung Hana70f0672019-01-18 15:20:43 +09002162 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2163 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002164 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002165
2166 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002167 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002168 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002169 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002170
Jooyung Han0302a842019-10-30 18:43:49 +09002171 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002172 return false
2173 }
2174
2175 var stringPath []string
2176 for _, m := range ctx.GetWalkPath() {
2177 stringPath = append(stringPath, m.Name())
2178 }
2179 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2180 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2181 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2182 return false
2183 }
2184 if module, ok := ctx.Module().(*Module); ok {
2185 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002186 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002187 ctx.WalkDeps(check)
2188 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002189 }
2190 }
2191}
2192
Colin Crossc99deeb2016-04-11 15:06:20 -07002193// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002194func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002195 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002196
Ivan Lozano183a3212019-10-18 14:18:45 -07002197 directStaticDeps := []LinkableInterface{}
2198 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002199
Inseob Kim9516ee92019-05-09 10:56:13 +09002200 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2201
Inseob Kim69378442019-06-03 19:10:47 +09002202 reexportExporter := func(exporter exportedFlagsProducer) {
2203 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2204 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2205 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2206 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002207 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002208 }
2209
Colin Crossd11fcda2017-10-23 17:59:01 -07002210 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002211 depName := ctx.OtherModuleName(dep)
2212 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002213
Ivan Lozano52767be2019-10-18 14:49:46 -07002214 ccDep, ok := dep.(LinkableInterface)
2215 if !ok {
2216
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002217 // handling for a few module types that aren't cc Module but that are also supported
2218 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002219 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002220 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002221 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2222 genRule.GeneratedSourceFiles()...)
2223 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002224 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002225 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002226 // Support exported headers from a generated_sources dependency
2227 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002228 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002229 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002230 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002231 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002232 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002233 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002234 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002235 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002236 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2237 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002238 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002239 // 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 +09002240 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002241
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002242 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002243 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002244 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002245 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002246 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002247 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002248 files := genRule.GeneratedSourceFiles()
2249 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002250 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002251 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002252 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 -07002253 }
2254 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002255 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002256 }
Colin Crossca860ac2016-01-04 14:34:37 -08002257 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002258 return
2259 }
2260
Colin Crossfe17f6f2019-03-28 19:30:56 -07002261 if depTag == android.ProtoPluginDepTag {
2262 return
2263 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002264 if depTag == llndkImplDep {
2265 return
2266 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002267
Colin Crossd11fcda2017-10-23 17:59:01 -07002268 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002269 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2270 return
2271 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002272 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002273 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2274 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002275 return
2276 }
2277
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002278 // re-exporting flags
2279 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002280 // reusing objects only make sense for cc.Modules.
2281 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002282 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002283 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002284 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002285 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002286 return
2287 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002288 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002289
Jiyong Parke4bb9862019-02-01 00:31:10 +09002290 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002291 // staticVariants are a cc.Module specific concept.
2292 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002293 c.staticVariant = ccDep
2294 return
2295 }
2296 }
2297
Jooyung Han75568392020-03-20 04:29:24 +09002298 // For the dependency from platform to apex, use the latest stubs
2299 c.apexSdkVersion = android.FutureApiLevel
2300 if !c.IsForPlatform() {
2301 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2302 }
2303
2304 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2305 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2306 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2307 // (b/144430859)
2308 c.apexSdkVersion = android.FutureApiLevel
2309 }
2310
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002311 if depTag == staticUnwinderDepTag {
Jooyung Han75568392020-03-20 04:29:24 +09002312 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2313 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002314 depTag = StaticDepTag
2315 } else {
2316 return
2317 }
2318 }
2319
Ivan Lozano183a3212019-10-18 14:18:45 -07002320 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2321 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2322 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002323 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002324 if t, ok := depTag.(DependencyTag); ok {
2325 explicitlyVersioned = t.ExplicitlyVersioned
2326 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002327 depTag = t
2328 }
2329
Ivan Lozano183a3212019-10-18 14:18:45 -07002330 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002331 depIsStatic := false
2332 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002333 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002334 depIsStatic = true
2335 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002336 if ccDep.CcLibrary() && !depIsStatic {
2337 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002338 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002339 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002340 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002341
2342 var useThisDep bool
2343 if depIsStubs && explicitlyVersioned {
2344 // Always respect dependency to the versioned stubs (i.e. libX#10)
2345 useThisDep = true
2346 } else if !depHasStubs {
2347 // Use non-stub variant if that is the only choice
2348 // (i.e. depending on a lib without stubs.version property)
2349 useThisDep = true
2350 } else if c.IsForPlatform() {
2351 // If not building for APEX, use stubs only when it is from
2352 // an APEX (and not from platform)
2353 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002354 if c.bootstrap() {
2355 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002356 // always link to non-stub variant
2357 useThisDep = !depIsStubs
2358 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002359 for _, testFor := range c.TestFor() {
2360 // Another exception: if this module is bundled with an APEX, then
2361 // it is linked with the non-stub variant of a module in the APEX
2362 // as if this is part of the APEX.
2363 if android.DirectlyInApex(testFor, depName) {
2364 useThisDep = !depIsStubs
2365 break
2366 }
2367 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002368 } else {
2369 // If building for APEX, use stubs only when it is not from
2370 // the same APEX
2371 useThisDep = (depInSameApex != depIsStubs)
2372 }
2373
Jooyung Han03b51852020-02-26 22:45:42 +09002374 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2375 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002376 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002377 if err != nil {
2378 ctx.OtherModuleErrorf(dep, err.Error())
2379 return
2380 }
2381 if versionToUse != ccDep.StubsVersion() {
2382 useThisDep = false
2383 }
2384 }
2385
Jiyong Park25fc6a92018-11-18 18:02:45 +09002386 if !useThisDep {
2387 return // stop processing this dep
2388 }
2389 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002390 if c.UseVndk() {
2391 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2392 // by default, use current version of LLNDK
2393 versionToUse := ""
2394 versions := stubsVersionsFor(ctx.Config())[depName]
2395 if c.ApexName() != "" && len(versions) > 0 {
2396 // if this is for use_vendor apex && dep has stubsVersions
2397 // apply the same rule of apex sdk enforcement to choose right version
2398 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002399 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002400 if err != nil {
2401 ctx.OtherModuleErrorf(dep, err.Error())
2402 return
2403 }
2404 }
2405 if versionToUse != ccDep.StubsVersion() {
2406 return
2407 }
2408 }
2409 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002410
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002411 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2412
Ivan Lozano52767be2019-10-18 14:49:46 -07002413 // Exporting flags only makes sense for cc.Modules
2414 if _, ok := ccDep.(*Module); ok {
2415 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002416 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002417 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002418 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002419
Ivan Lozano52767be2019-10-18 14:49:46 -07002420 if t.ReexportFlags {
2421 reexportExporter(i)
2422 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2423 // Re-exported shared library headers must be included as well since they can help us with type information
2424 // about template instantiations (instantiated from their headers).
2425 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2426 // scripts.
2427 c.sabi.Properties.ReexportedIncludes = append(
2428 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2429 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002430 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002431 }
Logan Chienf3511742017-10-31 18:04:35 +08002432 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002433 }
2434
Colin Cross26c34ed2016-09-30 17:10:16 -07002435 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002436 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002437
Ivan Lozano52767be2019-10-18 14:49:46 -07002438 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002439 depFile := android.OptionalPath{}
2440
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002441 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002442 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002443 ptr = &depPaths.SharedLibs
2444 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002445 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002446 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002447
Jiyong Park64a44f22019-01-18 14:37:08 +09002448 case earlySharedDepTag:
2449 ptr = &depPaths.EarlySharedLibs
2450 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002451 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002452 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002453 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002454 ptr = &depPaths.LateSharedLibs
2455 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002456 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002457 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002458 ptr = nil
2459 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002460 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002461 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002462 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002463 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002464 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002465 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002466 return
2467 }
2468
Ivan Lozano52767be2019-10-18 14:49:46 -07002469 // Because the static library objects are included, this only makes sense
2470 // in the context of proper cc.Modules.
2471 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2472 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2473 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2474 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2475 for i := range missingDeps {
2476 missingDeps[i] += postfix
2477 }
2478 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002479 }
Martin Stjernholm391d94c2020-04-17 17:34:31 +01002480 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2481 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2482 } else {
2483 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2484 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002485 } else {
2486 ctx.ModuleErrorf(
2487 "non-cc.Modules cannot be included as whole static libraries.", depName)
2488 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002489 }
Colin Cross5950f382016-12-13 12:50:57 -08002490 case headerDepTag:
2491 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002492 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002493 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002494 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002495 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002496 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002497 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002498 case dynamicLinkerDepTag:
2499 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002500 }
2501
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002502 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002503 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002504 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002505 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002506 return
2507 }
2508
2509 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002510 // in static libraries act as if they were whole static libraries. The same goes for
2511 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002512 if c, ok := ccDep.(*Module); ok {
2513 staticLib := c.linker.(libraryInterface)
2514 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2515 staticLib.objs().coverageFiles...)
2516 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2517 staticLib.objs().sAbiDumpFiles...)
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -04002518 } else if c, ok := ccDep.(LinkableInterface); ok {
2519 // Handle non-CC modules here
2520 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2521 c.CoverageFiles()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002522 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002523 }
2524
Colin Cross26c34ed2016-09-30 17:10:16 -07002525 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002526 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002527 if !ctx.Config().AllowMissingDependencies() {
2528 ctx.ModuleErrorf("module %q missing output file", depName)
2529 } else {
2530 ctx.AddMissingDependencies([]string{depName})
2531 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002532 return
2533 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002534 *ptr = append(*ptr, linkFile.Path())
2535 }
2536
Colin Crossc99deeb2016-04-11 15:06:20 -07002537 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002538 dep := depFile
2539 if !dep.Valid() {
2540 dep = linkFile
2541 }
2542 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002543 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002544
Inseob Kimeec88e12020-01-22 11:11:29 +09002545 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2546
2547 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002548 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002549 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002550 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002551 return libName
2552 }
2553
2554 makeLibName := func(depName string) string {
2555 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002556 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002557 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002558 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002559
Inseob Kimeec88e12020-01-22 11:11:29 +09002560 if c, ok := ccDep.(*Module); ok {
2561 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim752edec2020-03-14 01:30:34 +09002562 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002563 baseName := c.BaseModuleName()
Inseob Kim752edec2020-03-14 01:30:34 +09002564
2565 if c.IsVndk() {
2566 return baseName + ".vendor"
2567 }
2568
Inseob Kimeec88e12020-01-22 11:11:29 +09002569 if vendorSuffixModules[baseName] {
2570 return baseName + ".vendor"
2571 } else {
2572 return baseName
2573 }
2574 }
2575 }
2576
Yifan Hong1b3348d2020-01-21 15:53:22 -08002577 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002578 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2579 // core module instead.
2580 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002581 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002582 // The vendor module in Make will have been renamed to not conflict with the core
2583 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002584 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002585 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002586 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002587 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2588 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002589 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002590 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002591 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002592 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002593 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002594 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002595 }
Logan Chien43d34c32017-12-20 01:17:32 +08002596 }
2597
2598 // Export the shared libs to Make.
2599 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002600 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002601 if ccDep.CcLibrary() {
2602 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002603 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002604 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002605 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002606 c.Properties.ApexesProvidingSharedLibs = append(
2607 c.Properties.ApexesProvidingSharedLibs, an)
2608 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002609 }
2610 }
2611
Jiyong Park27b188b2017-07-18 13:23:39 +09002612 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002613 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002614 c.Properties.AndroidMkSharedLibs = append(
2615 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002616 // Record baseLibName for snapshots.
2617 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002618 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002619 c.Properties.AndroidMkSharedLibs = append(
2620 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002621 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002622 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002623 c.Properties.AndroidMkStaticLibs = append(
2624 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002625 case runtimeDepTag:
2626 c.Properties.AndroidMkRuntimeLibs = append(
2627 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002628 // Record baseLibName for snapshots.
2629 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002630 case wholeStaticDepTag:
2631 c.Properties.AndroidMkWholeStaticLibs = append(
2632 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Bill Peckhama46de702020-04-21 17:23:37 -07002633 case headerDepTag:
2634 c.Properties.AndroidMkHeaderLibs = append(
2635 c.Properties.AndroidMkHeaderLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002636 }
Colin Crossca860ac2016-01-04 14:34:37 -08002637 })
2638
Jeff Gaston294356f2017-09-27 17:05:30 -07002639 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002640 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002641
Colin Crossdd84e052017-05-17 13:44:16 -07002642 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002643 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002644 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2645 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002646 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002647 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2648 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002649 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002650 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002651 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002652
2653 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002654 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002655 }
Colin Crossdd84e052017-05-17 13:44:16 -07002656
Colin Crossca860ac2016-01-04 14:34:37 -08002657 return depPaths
2658}
2659
2660func (c *Module) InstallInData() bool {
2661 if c.installer == nil {
2662 return false
2663 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002664 return c.installer.inData()
2665}
2666
2667func (c *Module) InstallInSanitizerDir() bool {
2668 if c.installer == nil {
2669 return false
2670 }
2671 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002672 return true
2673 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002674 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002675}
2676
Yifan Hong1b3348d2020-01-21 15:53:22 -08002677func (c *Module) InstallInRamdisk() bool {
2678 return c.InRamdisk()
2679}
2680
Jiyong Parkf9332f12018-02-01 00:54:12 +09002681func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002682 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002683}
2684
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002685func (c *Module) SkipInstall() {
2686 if c.installer == nil {
2687 c.ModuleBase.SkipInstall()
2688 return
2689 }
2690 c.installer.skipInstall(c)
2691}
2692
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002693func (c *Module) HostToolPath() android.OptionalPath {
2694 if c.installer == nil {
2695 return android.OptionalPath{}
2696 }
2697 return c.installer.hostToolPath()
2698}
2699
Nan Zhangd4e641b2017-07-12 12:55:28 -07002700func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2701 return c.outputFile
2702}
2703
Colin Cross41955e82019-05-29 14:40:35 -07002704func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2705 switch tag {
2706 case "":
2707 if c.outputFile.Valid() {
2708 return android.Paths{c.outputFile.Path()}, nil
2709 }
2710 return android.Paths{}, nil
2711 default:
2712 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002713 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002714}
2715
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002716func (c *Module) static() bool {
2717 if static, ok := c.linker.(interface {
2718 static() bool
2719 }); ok {
2720 return static.static()
2721 }
2722 return false
2723}
2724
Jiyong Park379de2f2018-12-19 02:47:14 +09002725func (c *Module) staticBinary() bool {
2726 if static, ok := c.linker.(interface {
2727 staticBinary() bool
2728 }); ok {
2729 return static.staticBinary()
2730 }
2731 return false
2732}
2733
Jiyong Park1d1119f2019-07-29 21:27:18 +09002734func (c *Module) header() bool {
2735 if h, ok := c.linker.(interface {
2736 header() bool
2737 }); ok {
2738 return h.header()
2739 }
2740 return false
2741}
2742
Inseob Kim7f283f42020-06-01 21:53:49 +09002743func (c *Module) binary() bool {
2744 if b, ok := c.linker.(interface {
2745 binary() bool
2746 }); ok {
2747 return b.binary()
2748 }
2749 return false
2750}
2751
Inseob Kim1042d292020-06-01 23:23:05 +09002752func (c *Module) object() bool {
2753 if o, ok := c.linker.(interface {
2754 object() bool
2755 }); ok {
2756 return o.object()
2757 }
2758 return false
2759}
2760
Jooyung Han38002912019-05-16 04:01:54 +09002761func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002762 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002763 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2764 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002765 return "native:vndk"
2766 }
Jooyung Han38002912019-05-16 04:01:54 +09002767 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002768 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002769 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002770 if Bool(c.VendorProperties.Vendor_available) {
2771 return "native:vndk"
2772 }
2773 return "native:vndk_private"
2774 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002775 if c.inProduct() {
2776 return "native:product"
2777 }
Jooyung Han38002912019-05-16 04:01:54 +09002778 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002779 } else if c.InRamdisk() {
2780 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002781 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002782 return "native:recovery"
2783 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2784 return "native:ndk:none:none"
2785 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2786 //family, link := getNdkStlFamilyAndLinkType(c)
2787 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002788 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002789 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002790 } else {
2791 return "native:platform"
2792 }
2793}
2794
Jiyong Park9d452992018-10-03 00:38:19 +09002795// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002796// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002797func (c *Module) IsInstallableToApex() bool {
2798 if shared, ok := c.linker.(interface {
2799 shared() bool
2800 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002801 // Stub libs and prebuilt libs in a versioned SDK are not
2802 // installable to APEX even though they are shared libs.
2803 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002804 } else if _, ok := c.linker.(testPerSrc); ok {
2805 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002806 }
2807 return false
2808}
2809
Jiyong Parka90ca002019-10-07 15:47:24 +09002810func (c *Module) AvailableFor(what string) bool {
2811 if linker, ok := c.linker.(interface {
2812 availableFor(string) bool
2813 }); ok {
2814 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2815 } else {
2816 return c.ApexModuleBase.AvailableFor(what)
2817 }
2818}
2819
Jiyong Park62304bb2020-04-13 16:19:48 +09002820func (c *Module) TestFor() []string {
2821 if test, ok := c.linker.(interface {
2822 testFor() []string
2823 }); ok {
2824 return test.testFor()
2825 } else {
2826 return c.ApexModuleBase.TestFor()
2827 }
2828}
2829
Paul Duffin0cb37b92020-03-04 14:52:46 +00002830// Return true if the module is ever installable.
2831func (c *Module) EverInstallable() bool {
2832 return c.installer != nil &&
2833 // Check to see whether the module is actually ever installable.
2834 c.installer.everInstallable()
2835}
2836
Inseob Kim1f086e22019-05-09 13:29:15 +09002837func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002838 ret := c.EverInstallable() &&
2839 // Check to see whether the module has been configured to not be installed.
2840 proptools.BoolDefault(c.Properties.Installable, true) &&
2841 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002842
2843 // The platform variant doesn't need further condition. Apex variants however might not
2844 // be installable because it will likely to be included in the APEX and won't appear
2845 // in the system partition.
2846 if c.IsForPlatform() {
2847 return ret
2848 }
2849
2850 // Special case for modules that are configured to be installed to /data, which includes
2851 // test modules. For these modules, both APEX and non-APEX variants are considered as
2852 // installable. This is because even the APEX variants won't be included in the APEX, but
2853 // will anyway be installed to /data/*.
2854 // See b/146995717
2855 if c.InstallInData() {
2856 return ret
2857 }
2858
2859 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002860}
2861
Logan Chien41eabe62019-04-10 13:33:58 +08002862func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2863 if c.linker != nil {
2864 if library, ok := c.linker.(*libraryDecorator); ok {
2865 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2866 }
2867 }
2868}
2869
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002870func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002871 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002872 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002873 if cc.HasStubsVariants() {
2874 if depTag.Shared && depTag.Library {
2875 // dynamic dep to a stubs lib crosses APEX boundary
2876 return false
2877 }
2878 if IsRuntimeDepTag(depTag) {
2879 // runtime dep to a stubs lib also crosses APEX boundary
2880 return false
2881 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002882 }
2883 if depTag.FromStatic {
2884 // shared_lib dependency from a static lib is considered as crossing
2885 // the APEX boundary because the dependency doesn't actually is
2886 // linked; the dependency is used only during the compilation phase.
2887 return false
2888 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002889 }
Jiyong Park7d95a512020-05-10 15:16:24 +09002890 } else if ctx.OtherModuleDependencyTag(dep) == llndkImplDep {
2891 // We don't track beyond LLNDK
2892 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002893 }
2894 return true
2895}
2896
Jooyung Han749dc692020-04-15 11:03:39 +09002897// b/154667674: refactor this to handle "current" in a consistent way
2898func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
2899 if versionString == "" {
2900 return 0, fmt.Errorf("not specified")
2901 }
2902 if versionString == "current" {
2903 if ctx.Config().PlatformSdkCodename() == "REL" {
2904 return ctx.Config().PlatformSdkVersionInt(), nil
2905 }
2906 return android.FutureApiLevel, nil
2907 }
2908 return android.ApiStrToNum(ctx, versionString)
2909}
2910
2911func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
2912 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
2913 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
2914 return nil
2915 }
2916 // b/154569636: set min_sdk_version correctly for toolchain_libraries
2917 if c.ToolchainLibrary() {
2918 return nil
2919 }
2920 // We don't check for prebuilt modules
2921 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
2922 return nil
2923 }
2924 minSdkVersion := c.MinSdkVersion()
2925 if minSdkVersion == "apex_inherit" {
2926 return nil
2927 }
2928 if minSdkVersion == "" {
2929 // JNI libs within APK-in-APEX fall into here
2930 // Those are okay to set sdk_version instead
2931 // We don't have to check if this is a SDK variant because
2932 // non-SDK variant resets sdk_version, which works too.
2933 minSdkVersion = c.SdkVersion()
2934 }
2935 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
2936 if err != nil {
2937 return err
2938 }
2939 if ver > sdkVersion {
2940 return fmt.Errorf("newer SDK(%v)", ver)
2941 }
2942 return nil
2943}
2944
Colin Cross2ba19d92015-05-07 15:44:20 -07002945//
Colin Crosscfad1192015-11-02 16:43:11 -08002946// Defaults
2947//
Colin Crossca860ac2016-01-04 14:34:37 -08002948type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002949 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002950 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002951 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002952}
2953
Patrice Arrudac249c712019-03-19 17:00:29 -07002954// cc_defaults provides a set of properties that can be inherited by other cc
2955// modules. A module can use the properties from a cc_defaults using
2956// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2957// merged (when possible) by prepending the default module's values to the
2958// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002959func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002960 return DefaultsFactory()
2961}
2962
Colin Cross36242852017-06-23 15:06:31 -07002963func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002964 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002965
Colin Cross36242852017-06-23 15:06:31 -07002966 module.AddProperties(props...)
2967 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002968 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002969 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002970 &BaseCompilerProperties{},
2971 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002972 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002973 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002974 &StaticProperties{},
2975 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002976 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002977 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002978 &TestProperties{},
2979 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07002980 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002981 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002982 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002983 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002984 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002985 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002986 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002987 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002988 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002989 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002990 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002991 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002992 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002993 )
Colin Crosscfad1192015-11-02 16:43:11 -08002994
Jooyung Hancc372c52019-09-25 15:18:44 +09002995 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002996
2997 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002998}
2999
Jiyong Park6a43f042017-10-12 23:05:00 +09003000func squashVendorSrcs(m *Module) {
3001 if lib, ok := m.compiler.(*libraryDecorator); ok {
3002 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3003 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3004
3005 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3006 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003007
3008 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3009 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003010 }
3011}
3012
Jiyong Parkf9332f12018-02-01 00:54:12 +09003013func squashRecoverySrcs(m *Module) {
3014 if lib, ok := m.compiler.(*libraryDecorator); ok {
3015 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3016 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3017
3018 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3019 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003020
3021 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3022 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003023 }
3024}
3025
Colin Cross7228ecd2019-11-18 16:00:16 -08003026var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003027
Colin Cross7228ecd2019-11-18 16:00:16 -08003028func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003029 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08003030 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09003031 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08003032
3033 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003034 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09003035 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003036 }
Logan Chienf3511742017-10-31 18:04:35 +08003037
3038 if vndkdep := m.vndkdep; vndkdep != nil {
3039 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09003040 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08003041 if !vndkdep.isVndkExt() {
3042 mctx.PropertyErrorf("vndk",
3043 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09003044 } else if m.VendorProperties.Vendor_available != nil {
3045 mctx.PropertyErrorf("vendor_available",
3046 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08003047 }
3048 } else {
3049 if vndkdep.isVndkExt() {
3050 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09003051 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08003052 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08003053 }
3054 if m.VendorProperties.Vendor_available == nil {
3055 mctx.PropertyErrorf("vndk",
3056 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08003057 }
3058 }
3059 } else {
3060 if vndkdep.isVndkSp() {
3061 mctx.PropertyErrorf("vndk",
3062 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08003063 }
3064 if vndkdep.isVndkExt() {
3065 mctx.PropertyErrorf("vndk",
3066 "must set `enabled: true` to set `extends: %q`",
3067 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08003068 }
Justin Yun8effde42017-06-23 19:24:43 +09003069 }
3070 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003071
Jiyong Parkf9332f12018-02-01 00:54:12 +09003072 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08003073 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09003074 var recoveryVariantNeeded bool = false
3075
Inseob Kim64c43952019-08-26 16:52:35 +09003076 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09003077 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09003078
3079 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09003080 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
3081 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
3082 if boardVndkVersion == "current" {
3083 boardVndkVersion = platformVndkVersion
3084 }
3085 if productVndkVersion == "current" {
3086 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09003087 }
3088
Justin Yun5f7f7e82019-11-18 19:52:14 +09003089 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003090 // If the device isn't compiling against the VNDK, we always
3091 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003092 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003093 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003094 // LL-NDK stubs only exist in the vendor and product variants,
3095 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09003096 vendorVariants = append(vendorVariants,
3097 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003098 boardVndkVersion,
3099 )
3100 productVariants = append(productVariants,
3101 platformVndkVersion,
3102 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003103 )
Jiyong Park2a454122017-10-19 15:59:33 +09003104 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
3105 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09003106 vendorVariants = append(vendorVariants,
3107 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09003108 boardVndkVersion,
3109 )
3110 productVariants = append(productVariants,
3111 platformVndkVersion,
3112 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09003113 )
Inseob Kimeec88e12020-01-22 11:11:29 +09003114 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09003115 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
3116 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09003117 if snapshot, ok := m.linker.(interface {
3118 version() string
3119 }); ok {
3120 vendorVariants = append(vendorVariants, snapshot.version())
3121 } else {
3122 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
3123 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09003124 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003125 // This will be available in /system, /vendor and /product
3126 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003127 coreVariantNeeded = true
Inseob Kim85708802020-06-02 00:06:15 +09003128
3129 // We assume that modules under proprietary paths are compatible for
3130 // BOARD_VNDK_VERSION. The other modules are regarded as AOSP, or
3131 // PLATFORM_VNDK_VERSION.
3132 if isVendorProprietaryPath(mctx.ModuleDir()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003133 vendorVariants = append(vendorVariants, boardVndkVersion)
Inseob Kim85708802020-06-02 00:06:15 +09003134 } else {
3135 vendorVariants = append(vendorVariants, platformVndkVersion)
3136 }
3137
3138 // vendor_available modules are also available to /product.
3139 productVariants = append(productVariants, platformVndkVersion)
3140 // VNDK is always PLATFORM_VNDK_VERSION
3141 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003142 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09003143 }
Logan Chienf3511742017-10-31 18:04:35 +08003144 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09003145 // This will be available in /vendor (or /odm) only
Inseob Kimf3044b62020-06-11 13:51:52 +09003146
3147 // kernel_headers is a special module type whose exported headers
3148 // are coming from DeviceKernelHeaders() which is always vendor
3149 // dependent. They'll always have both vendor variants.
3150 // For other modules, we assume that modules under proprietary
3151 // paths are compatible for BOARD_VNDK_VERSION. The other modules
3152 // are regarded as AOSP, which is PLATFORM_VNDK_VERSION.
3153 if _, ok := m.linker.(*kernelHeadersDecorator); ok {
3154 vendorVariants = append(vendorVariants,
3155 platformVndkVersion,
3156 boardVndkVersion,
3157 )
3158 } else if isVendorProprietaryPath(mctx.ModuleDir()) {
Inseob Kim85708802020-06-02 00:06:15 +09003159 vendorVariants = append(vendorVariants, boardVndkVersion)
3160 } else {
3161 vendorVariants = append(vendorVariants, platformVndkVersion)
3162 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003163 } else {
3164 // This is either in /system (or similar: /data), or is a
3165 // modules built with the NDK. Modules built with the NDK
3166 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003167 coreVariantNeeded = true
3168 }
3169
Justin Yun5f7f7e82019-11-18 19:52:14 +09003170 if boardVndkVersion != "" && productVndkVersion != "" {
3171 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
3172 // The module has "product_specific: true" that does not create core variant.
3173 coreVariantNeeded = false
3174 productVariants = append(productVariants, productVndkVersion)
3175 }
3176 } else {
3177 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
3178 // restriction to use system libs.
3179 // No product variants defined in this case.
3180 productVariants = []string{}
3181 }
3182
Yifan Hong1b3348d2020-01-21 15:53:22 -08003183 if Bool(m.Properties.Ramdisk_available) {
3184 ramdiskVariantNeeded = true
3185 }
3186
3187 if m.ModuleBase.InstallInRamdisk() {
3188 ramdiskVariantNeeded = true
3189 coreVariantNeeded = false
3190 }
3191
Jiyong Parkf9332f12018-02-01 00:54:12 +09003192 if Bool(m.Properties.Recovery_available) {
3193 recoveryVariantNeeded = true
3194 }
3195
3196 if m.ModuleBase.InstallInRecovery() {
3197 recoveryVariantNeeded = true
3198 coreVariantNeeded = false
3199 }
3200
Inseob Kim64c43952019-08-26 16:52:35 +09003201 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003202 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3203 }
3204
3205 for _, variant := range android.FirstUniqueStrings(productVariants) {
3206 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003207 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003208
Yifan Hong1b3348d2020-01-21 15:53:22 -08003209 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003210 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3211 m.Properties.CoreVariantNeeded = coreVariantNeeded
3212}
3213
3214func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3215 return c.Properties.CoreVariantNeeded
3216}
3217
Yifan Hong1b3348d2020-01-21 15:53:22 -08003218func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3219 return c.Properties.RamdiskVariantNeeded
3220}
3221
Colin Cross7228ecd2019-11-18 16:00:16 -08003222func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3223 return c.Properties.RecoveryVariantNeeded
3224}
3225
3226func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003227 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003228}
3229
3230func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3231 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003232 if variant == android.RamdiskVariation {
3233 m.MakeAsPlatform()
3234 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003235 m.MakeAsPlatform()
3236 squashRecoverySrcs(m)
3237 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003238 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003239 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3240 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003241
3242 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3243 // Hide other vendor variants to avoid collision.
3244 vndkVersion := ctx.DeviceConfig().VndkVersion()
3245 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3246 m.Properties.HideFromMake = true
3247 m.SkipInstall()
3248 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003249 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3250 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3251 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3252 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003253 }
3254}
3255
Jiyong Park2286afd2020-06-16 21:58:53 +09003256func (c *Module) IsSdkVariant() bool {
3257 return c.Properties.IsSdkVariant
3258}
3259
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003260func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003261 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003262 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3263 }
Colin Cross6510f912017-11-29 00:27:14 -08003264 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003265}
3266
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003267func kytheExtractAllFactory() android.Singleton {
3268 return &kytheExtractAllSingleton{}
3269}
3270
3271type kytheExtractAllSingleton struct {
3272}
3273
3274func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3275 var xrefTargets android.Paths
3276 ctx.VisitAllModules(func(module android.Module) {
3277 if ccModule, ok := module.(xref); ok {
3278 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3279 }
3280 })
3281 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3282 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003283 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003284 }
3285}
3286
Colin Cross06a931b2015-10-28 17:23:31 -07003287var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003288var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003289var BoolPtr = proptools.BoolPtr
3290var String = proptools.String
3291var StringPtr = proptools.StringPtr