blob: e0e6a2ffa31b4d0c087a76b7d4399227492d2917 [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
Chris Parsons79d66a52020-06-05 17:26:16 -040099 // Used for data dependencies adjacent to tests
100 DataLibs []string
101
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800102 StaticUnwinderIfLegacy bool
103
Colin Cross5950f382016-12-13 12:50:57 -0800104 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700105
Colin Cross81413472016-04-11 14:37:39 -0700106 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700107
Dan Willemsenb40aab62016-04-20 14:21:14 -0700108 GeneratedSources []string
109 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900110 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700111
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700112 ReexportGeneratedHeaders []string
113
Colin Cross97ba0732015-03-23 17:50:24 -0700114 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700115
116 // Used for host bionic
117 LinkerFlagsFile string
118 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700119}
120
Colin Crossca860ac2016-01-04 14:34:37 -0800121type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900123 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700124 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900125 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700127 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700128
Colin Cross26c34ed2016-09-30 17:10:16 -0700129 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100130 Objs Objects
131 // Paths to .o files in dependencies that provide them. Note that these lists
132 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800133 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700134 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700135
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100136 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
137 // the libs from all whole_static_lib dependencies.
138 WholeStaticLibsFromPrebuilts android.Paths
139
Colin Cross26c34ed2016-09-30 17:10:16 -0700140 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700141 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900142 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700143
Inseob Kimd110f872019-12-06 13:15:38 +0900144 Flags []string
145 IncludeDirs android.Paths
146 SystemIncludeDirs android.Paths
147 ReexportedDirs android.Paths
148 ReexportedSystemDirs android.Paths
149 ReexportedFlags []string
150 ReexportedGeneratedHeaders android.Paths
151 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152
Colin Cross26c34ed2016-09-30 17:10:16 -0700153 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700154 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700155
156 // Path to the file container flags to use with the linker
157 LinkerFlagsFile android.OptionalPath
158
159 // Path to the dynamic linker binary
160 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700161}
162
Colin Cross4af21ed2019-11-04 09:37:55 -0800163// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
164// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
165// command line so they can be overridden by the local module flags).
166type LocalOrGlobalFlags struct {
167 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700168 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800169 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700170 CFlags []string // Flags that apply to C and C++ source files
171 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
172 ConlyFlags []string // Flags that apply to C source files
173 CppFlags []string // Flags that apply to C++ source files
174 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700175 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800176}
177
178type Flags struct {
179 Local LocalOrGlobalFlags
180 Global LocalOrGlobalFlags
181
182 aidlFlags []string // Flags that apply to aidl source files
183 rsFlags []string // Flags that apply to renderscript source files
184 libFlags []string // Flags to add libraries early to the link order
185 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
186 TidyFlags []string // Flags that apply to clang-tidy
187 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700188
Colin Crossc3199482017-03-30 15:03:04 -0700189 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800190 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700191 SystemIncludeFlags []string
192
Oliver Nguyen04526782020-04-21 12:40:27 -0700193 Toolchain config.Toolchain
194 Tidy bool
195 GcovCoverage bool
196 SAbiDump bool
197 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800198
199 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800200 DynamicLinker string
201
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700202 CFlagsDeps android.Paths // Files depended on by compiler flags
203 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800204
Dan Willemsen98ab3112019-08-27 21:20:40 -0700205 AssemblerWithCpp bool
206 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800207
Colin Cross19878da2019-03-28 14:45:07 -0700208 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700209 protoC bool // Whether to use C instead of C++
210 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700211
212 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200213 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700214}
215
Colin Crossca860ac2016-01-04 14:34:37 -0800216// Properties used to compile all C or C++ modules
217type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700218 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800219 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700220
Colin Crossc511bc52020-04-07 16:50:32 +0000221 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
222 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800223 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700224
Jooyung Han379660c2020-04-21 15:24:00 +0900225 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
226 Min_sdk_version *string
227
Colin Crossc511bc52020-04-07 16:50:32 +0000228 // If true, always create an sdk variant and don't create a platform variant.
229 Sdk_variant_only *bool
230
Jiyong Parkde866cb2018-12-07 23:08:36 +0900231 AndroidMkSharedLibs []string `blueprint:"mutated"`
232 AndroidMkStaticLibs []string `blueprint:"mutated"`
233 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
234 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700235 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900236 HideFromMake bool `blueprint:"mutated"`
237 PreventInstall bool `blueprint:"mutated"`
238 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700239
Justin Yun5f7f7e82019-11-18 19:52:14 +0900240 ImageVariationPrefix string `blueprint:"mutated"`
241 VndkVersion string `blueprint:"mutated"`
242 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800243
244 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
245 // file
246 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900247
Yifan Hong1b3348d2020-01-21 15:53:22 -0800248 // Make this module available when building for ramdisk
249 Ramdisk_available *bool
250
Jiyong Parkf9332f12018-02-01 00:54:12 +0900251 // Make this module available when building for recovery
252 Recovery_available *bool
253
Colin Crossae6c5202019-11-20 13:35:50 -0800254 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800255 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800256 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800257 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900258 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900259
260 // Allows this module to use non-APEX version of libraries. Useful
261 // for building binaries that are started before APEXes are activated.
262 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900263
264 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
265 // see soong/cc/config/vndk.go
266 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900267
268 // Used by vendor snapshot to record dependencies from snapshot modules.
269 SnapshotSharedLibs []string `blueprint:"mutated"`
270 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000271
272 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000273
274 // Set by factories of module types that can only be referenced from variants compiled against
275 // the SDK.
276 AlwaysSdk bool `blueprint:"mutated"`
277
278 // Variant is an SDK variant created by sdkMutator
279 IsSdkVariant bool `blueprint:"mutated"`
280 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
281 // variant to have a ".sdk" suffix.
282 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700283
284 // Normally Soong uses the directory structure to decide which modules
285 // should be included (framework) or excluded (non-framework) from the
286 // vendor snapshot, but this property allows a partner to exclude a
287 // module normally thought of as a framework module from the vendor
288 // snapshot.
289 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700290}
291
292type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900293 // whether this module should be allowed to be directly depended by other
294 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900295 // In addition, this module should be allowed to be directly depended by
296 // product modules with `product_specific: true`.
297 // If set to true, three variants will be built separately, one like
298 // normal, another limited to the set of libraries and headers
299 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700300 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900301 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700302 // so it shouldn't have any unversioned runtime dependencies, or
303 // make assumptions about the system that may not be true in the
304 // future.
305 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900306 // If set to false, this module becomes inaccessible from /vendor or /product
307 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900308 //
309 // Default value is true when vndk: {enabled: true} or vendor: true.
310 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700311 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900312 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700313 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900314
315 // whether this module is capable of being loaded with other instance
316 // (possibly an older version) of the same module in the same process.
317 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
318 // can be double loaded in a vendor process if the library is also a
319 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
320 // explicitly marked as `double_loadable: true` by the owner, or the dependency
321 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
322 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
Colin Crossca860ac2016-01-04 14:34:37 -0800325type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800326 static() bool
327 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900328 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900329 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900330 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700331 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900332 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700333 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800334 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700335 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800336 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900337 isLlndk(config android.Config) bool
338 isLlndkPublic(config android.Config) bool
339 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900340 isVndk() bool
341 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800342 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900343 inProduct() bool
344 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800345 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900346 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800347 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700348 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700349 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800350 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800351 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800352 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800353 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800354 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700355 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700356 apexSdkVersion() android.ApiLevel
Jiyong Parkb0788572018-12-20 22:10:17 +0900357 hasStubsVariants() bool
358 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900359 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800360 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700361 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800362}
363
364type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700365 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800366 ModuleContextIntf
367}
368
369type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700370 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800371 ModuleContextIntf
372}
373
Colin Cross37047f12016-12-13 17:06:13 -0800374type DepsContext interface {
375 android.BottomUpMutatorContext
376 ModuleContextIntf
377}
378
Colin Crossca860ac2016-01-04 14:34:37 -0800379type feature interface {
380 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800381 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800382 flags(ctx ModuleContext, flags Flags) Flags
383 props() []interface{}
384}
385
386type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700387 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800388 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800389 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700390 compilerProps() []interface{}
391
Colin Cross76fada02016-07-27 10:31:13 -0700392 appendCflags([]string)
393 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700394 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800395}
396
397type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700398 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800399 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700400 linkerFlags(ctx ModuleContext, flags Flags) Flags
401 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800402 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700403
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700404 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700405 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900406 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700407
408 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900409 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000410
411 // Get the deps that have been explicitly specified in the properties.
412 // Only updates the
413 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
414}
415
416type specifiedDeps struct {
417 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000418 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800419}
420
421type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700422 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700423 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000424 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800425 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700426 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700427 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900428 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100429 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800430}
431
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800432type xref interface {
433 XrefCcFiles() android.Paths
434}
435
Colin Cross6e511a92020-07-27 21:26:48 -0700436type libraryDependencyKind int
437
438const (
439 headerLibraryDependency = iota
440 sharedLibraryDependency
441 staticLibraryDependency
442)
443
444func (k libraryDependencyKind) String() string {
445 switch k {
446 case headerLibraryDependency:
447 return "headerLibraryDependency"
448 case sharedLibraryDependency:
449 return "sharedLibraryDependency"
450 case staticLibraryDependency:
451 return "staticLibraryDependency"
452 default:
453 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
454 }
455}
456
457type libraryDependencyOrder int
458
459const (
460 earlyLibraryDependency = -1
461 normalLibraryDependency = 0
462 lateLibraryDependency = 1
463)
464
465func (o libraryDependencyOrder) String() string {
466 switch o {
467 case earlyLibraryDependency:
468 return "earlyLibraryDependency"
469 case normalLibraryDependency:
470 return "normalLibraryDependency"
471 case lateLibraryDependency:
472 return "lateLibraryDependency"
473 default:
474 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
475 }
476}
477
478// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
479// tags that have a set of predefined tag objects that are reused for each dependency, a
480// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
481// That means that comparing a libraryDependencyTag for equality will only be equal if all
482// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
483// then check individual metadata fields instead.
484type libraryDependencyTag struct {
485 blueprint.BaseDependencyTag
486
487 // These are exported so that fmt.Printf("%#v") can call their String methods.
488 Kind libraryDependencyKind
489 Order libraryDependencyOrder
490
491 wholeStatic bool
492
493 reexportFlags bool
494 explicitlyVersioned bool
495 dataLib bool
496 ndk bool
497
498 staticUnwinder bool
499
500 makeSuffix string
501}
502
503// header returns true if the libraryDependencyTag is tagging a header lib dependency.
504func (d libraryDependencyTag) header() bool {
505 return d.Kind == headerLibraryDependency
506}
507
508// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
509func (d libraryDependencyTag) shared() bool {
510 return d.Kind == sharedLibraryDependency
511}
512
513// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
514func (d libraryDependencyTag) static() bool {
515 return d.Kind == staticLibraryDependency
516}
517
518// dependencyTag is used for tagging miscellanous dependency types that don't fit into
519// libraryDependencyTag. Each tag object is created globally and reused for multiple
520// dependencies (although since the object contains no references, assigning a tag to a
521// variable and modifying it will not modify the original). Users can compare the tag
522// returned by ctx.OtherModuleDependencyTag against the global original
523type dependencyTag struct {
524 blueprint.BaseDependencyTag
525 name string
526}
527
Colin Crossc99deeb2016-04-11 15:06:20 -0700528var (
Colin Cross6e511a92020-07-27 21:26:48 -0700529 genSourceDepTag = dependencyTag{name: "gen source"}
530 genHeaderDepTag = dependencyTag{name: "gen header"}
531 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
532 objDepTag = dependencyTag{name: "obj"}
533 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
534 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
535 reuseObjTag = dependencyTag{name: "reuse objects"}
536 staticVariantTag = dependencyTag{name: "static variant"}
537 vndkExtDepTag = dependencyTag{name: "vndk extends"}
538 dataLibDepTag = dependencyTag{name: "data lib"}
539 runtimeDepTag = dependencyTag{name: "runtime lib"}
540 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700541)
542
Roland Levillainf89cd092019-07-29 16:22:59 +0100543func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700544 ccLibDepTag, ok := depTag.(libraryDependencyTag)
545 return ok && ccLibDepTag.shared()
546}
547
548func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
549 ccLibDepTag, ok := depTag.(libraryDependencyTag)
550 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100551}
552
553func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700554 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100555 return ok && ccDepTag == runtimeDepTag
556}
557
558func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700559 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100560 return ok && ccDepTag == testPerSrcDepTag
561}
562
Colin Crossca860ac2016-01-04 14:34:37 -0800563// Module contains the properties and members used by all C/C++ module types, and implements
564// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
565// to construct the output file. Behavior can be customized with a Customizer interface
566type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700567 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700568 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900569 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900570 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700571
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700572 Properties BaseProperties
573 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700574
Colin Crossca860ac2016-01-04 14:34:37 -0800575 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700576 hod android.HostOrDeviceSupported
577 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700578
Paul Duffina0843f62019-12-13 19:50:38 +0000579 // Allowable SdkMemberTypes of this module type.
580 sdkMemberTypes []android.SdkMemberType
581
Colin Crossca860ac2016-01-04 14:34:37 -0800582 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700583 features []feature
584 compiler compiler
585 linker linker
586 installer installer
587 stl *stl
588 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800589 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800590 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900591 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700592 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700593 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800594
Colin Cross635c3b02016-05-18 15:37:25 -0700595 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800596
Colin Crossb98c8b02016-07-29 13:44:28 -0700597 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700598
599 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800600
601 // Flags used to compile this module
602 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700603
604 // 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 -0800605 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700606 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800607 depsInLinkOrder android.Paths
608
609 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700610 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900611
612 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800613 // Kythe (source file indexer) paths for this compilation module
614 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900615
616 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700617 apexSdkVersion android.ApiLevel
Colin Crossc472d572015-03-17 15:06:21 -0700618}
619
Ivan Lozano52767be2019-10-18 14:49:46 -0700620func (c *Module) Toc() android.OptionalPath {
621 if c.linker != nil {
622 if library, ok := c.linker.(libraryInterface); ok {
623 return library.toc()
624 }
625 }
626 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
627}
628
629func (c *Module) ApiLevel() string {
630 if c.linker != nil {
631 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700632 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700633 }
634 }
635 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
636}
637
638func (c *Module) Static() bool {
639 if c.linker != nil {
640 if library, ok := c.linker.(libraryInterface); ok {
641 return library.static()
642 }
643 }
644 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
645}
646
647func (c *Module) Shared() bool {
648 if c.linker != nil {
649 if library, ok := c.linker.(libraryInterface); ok {
650 return library.shared()
651 }
652 }
653 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
654}
655
656func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000657 if c.stl != nil {
658 return c.stl.Properties.SelectedStl
659 }
660 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700661}
662
663func (c *Module) ToolchainLibrary() bool {
664 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
665 return true
666 }
667 return false
668}
669
670func (c *Module) NdkPrebuiltStl() bool {
671 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
672 return true
673 }
674 return false
675}
676
677func (c *Module) StubDecorator() bool {
678 if _, ok := c.linker.(*stubDecorator); ok {
679 return true
680 }
681 return false
682}
683
684func (c *Module) SdkVersion() string {
685 return String(c.Properties.Sdk_version)
686}
687
Artur Satayev480e25b2020-04-27 18:53:18 +0100688func (c *Module) MinSdkVersion() string {
689 return String(c.Properties.Min_sdk_version)
690}
691
Dan Albert92fe7402020-07-15 13:33:30 -0700692func (c *Module) SplitPerApiLevel() bool {
693 if linker, ok := c.linker.(*objectLinker); ok {
694 return linker.isCrt()
695 }
696 return false
697}
698
Colin Crossc511bc52020-04-07 16:50:32 +0000699func (c *Module) AlwaysSdk() bool {
700 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
701}
702
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800703func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700704 if c.linker != nil {
705 if library, ok := c.linker.(exportedFlagsProducer); ok {
706 return library.exportedDirs()
707 }
708 }
709 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
710}
711
712func (c *Module) HasStaticVariant() bool {
713 if c.staticVariant != nil {
714 return true
715 }
716 return false
717}
718
719func (c *Module) GetStaticVariant() LinkableInterface {
720 return c.staticVariant
721}
722
723func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
724 c.depsInLinkOrder = depsInLinkOrder
725}
726
727func (c *Module) GetDepsInLinkOrder() []android.Path {
728 return c.depsInLinkOrder
729}
730
731func (c *Module) StubsVersions() []string {
732 if c.linker != nil {
733 if library, ok := c.linker.(*libraryDecorator); ok {
734 return library.Properties.Stubs.Versions
735 }
736 }
737 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
738}
739
740func (c *Module) CcLibrary() bool {
741 if c.linker != nil {
742 if _, ok := c.linker.(*libraryDecorator); ok {
743 return true
744 }
745 }
746 return false
747}
748
749func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700750 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700751 return true
752 }
753 return false
754}
755
Ivan Lozano2b262972019-11-21 12:30:50 -0800756func (c *Module) NonCcVariants() bool {
757 return false
758}
759
Ivan Lozano183a3212019-10-18 14:18:45 -0700760func (c *Module) SetBuildStubs() {
761 if c.linker != nil {
762 if library, ok := c.linker.(*libraryDecorator); ok {
763 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700764 c.Properties.HideFromMake = true
765 c.sanitize = nil
766 c.stl = nil
767 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700768 return
769 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000770 if _, ok := c.linker.(*llndkStubDecorator); ok {
771 c.Properties.HideFromMake = true
772 return
773 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700774 }
775 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
776}
777
Ivan Lozano52767be2019-10-18 14:49:46 -0700778func (c *Module) BuildStubs() bool {
779 if c.linker != nil {
780 if library, ok := c.linker.(*libraryDecorator); ok {
781 return library.buildStubs()
782 }
783 }
784 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
785}
786
Ivan Lozano183a3212019-10-18 14:18:45 -0700787func (c *Module) SetStubsVersions(version string) {
788 if c.linker != nil {
789 if library, ok := c.linker.(*libraryDecorator); ok {
790 library.MutatedProperties.StubsVersion = version
791 return
792 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000793 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
794 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
795 return
796 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700797 }
798 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
799}
800
Jooyung Han03b51852020-02-26 22:45:42 +0900801func (c *Module) StubsVersion() string {
802 if c.linker != nil {
803 if library, ok := c.linker.(*libraryDecorator); ok {
804 return library.MutatedProperties.StubsVersion
805 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000806 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
807 return llndk.libraryDecorator.MutatedProperties.StubsVersion
808 }
Jooyung Han03b51852020-02-26 22:45:42 +0900809 }
810 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
811}
812
Ivan Lozano183a3212019-10-18 14:18:45 -0700813func (c *Module) SetStatic() {
814 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700815 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700816 library.setStatic()
817 return
818 }
819 }
820 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
821}
822
823func (c *Module) SetShared() {
824 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700825 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700826 library.setShared()
827 return
828 }
829 }
830 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
831}
832
833func (c *Module) BuildStaticVariant() bool {
834 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700835 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700836 return library.buildStatic()
837 }
838 }
839 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
840}
841
842func (c *Module) BuildSharedVariant() bool {
843 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700844 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700845 return library.buildShared()
846 }
847 }
848 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
849}
850
851func (c *Module) Module() android.Module {
852 return c
853}
854
Jiyong Parkc20eee32018-09-05 22:36:17 +0900855func (c *Module) OutputFile() android.OptionalPath {
856 return c.outputFile
857}
858
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400859func (c *Module) CoverageFiles() android.Paths {
860 if c.linker != nil {
861 if library, ok := c.linker.(libraryInterface); ok {
862 return library.objs().coverageFiles
863 }
864 }
865 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
866}
867
Ivan Lozano183a3212019-10-18 14:18:45 -0700868var _ LinkableInterface = (*Module)(nil)
869
Jiyong Park719b4462019-01-13 00:39:51 +0900870func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900871 if c.linker != nil {
872 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900873 }
874 return nil
875}
876
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900877func (c *Module) CoverageOutputFile() android.OptionalPath {
878 if c.linker != nil {
879 return c.linker.coverageOutputFilePath()
880 }
881 return android.OptionalPath{}
882}
883
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900884func (c *Module) RelativeInstallPath() string {
885 if c.installer != nil {
886 return c.installer.relativeInstallPath()
887 }
888 return ""
889}
890
Jooyung Han344d5432019-08-23 11:17:39 +0900891func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900892 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900893}
894
Colin Cross36242852017-06-23 15:06:31 -0700895func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700896 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800897 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700898 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800899 }
900 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700901 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800902 }
903 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700904 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800905 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700906 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700907 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700908 }
Colin Cross16b23492016-01-06 14:41:07 -0800909 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700910 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800911 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800912 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700913 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800914 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800915 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700916 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800917 }
Justin Yun8effde42017-06-23 19:24:43 +0900918 if c.vndkdep != nil {
919 c.AddProperties(c.vndkdep.props()...)
920 }
Stephen Craneba090d12017-05-09 15:44:35 -0700921 if c.lto != nil {
922 c.AddProperties(c.lto.props()...)
923 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700924 if c.pgo != nil {
925 c.AddProperties(c.pgo.props()...)
926 }
Colin Crossca860ac2016-01-04 14:34:37 -0800927 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700928 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800929 }
Colin Crossc472d572015-03-17 15:06:21 -0700930
Colin Crossa9d8bee2018-10-02 13:59:46 -0700931 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700932 // Windows builds always prefer 32-bit
933 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700934 })
Colin Cross36242852017-06-23 15:06:31 -0700935 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900936 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900937 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900938 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900939
Colin Cross36242852017-06-23 15:06:31 -0700940 return c
Colin Crossc472d572015-03-17 15:06:21 -0700941}
942
Colin Crossb916a382016-07-29 17:28:03 -0700943// Returns true for dependency roots (binaries)
944// TODO(ccross): also handle dlopenable libraries
945func (c *Module) isDependencyRoot() bool {
946 if root, ok := c.linker.(interface {
947 isDependencyRoot() bool
948 }); ok {
949 return root.isDependencyRoot()
950 }
951 return false
952}
953
Justin Yun5f7f7e82019-11-18 19:52:14 +0900954// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
955// "product" and "vendor" variant modules return true for this function.
956// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
957// "soc_specific: true" and more vendor installed modules are included here.
958// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
959// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700960func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900961 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700962}
963
Colin Crossc511bc52020-04-07 16:50:32 +0000964func (c *Module) canUseSdk() bool {
965 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
966}
967
968func (c *Module) UseSdk() bool {
969 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -0700970 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +0000971 }
972 return false
973}
974
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800975func (c *Module) isCoverageVariant() bool {
976 return c.coverage.Properties.IsCoverageVariant
977}
978
Peter Collingbournead84f972019-12-17 16:46:18 -0800979func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -0700980 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800981}
982
Inseob Kim9516ee92019-05-09 10:56:13 +0900983func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800984 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900985 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800986}
987
Inseob Kim9516ee92019-05-09 10:56:13 +0900988func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800989 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900990 name := c.BaseModuleName()
991 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800992}
993
Inseob Kim9516ee92019-05-09 10:56:13 +0900994func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800995 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900996 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800997}
998
Ivan Lozano52767be2019-10-18 14:49:46 -0700999func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001000 if vndkdep := c.vndkdep; vndkdep != nil {
1001 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001002 }
1003 return false
1004}
1005
Yi Kong7e53c572018-02-14 18:16:12 +08001006func (c *Module) isPgoCompile() bool {
1007 if pgo := c.pgo; pgo != nil {
1008 return pgo.Properties.PgoCompile
1009 }
1010 return false
1011}
1012
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001013func (c *Module) isNDKStubLibrary() bool {
1014 if _, ok := c.compiler.(*stubDecorator); ok {
1015 return true
1016 }
1017 return false
1018}
1019
Logan Chienf3511742017-10-31 18:04:35 +08001020func (c *Module) isVndkSp() bool {
1021 if vndkdep := c.vndkdep; vndkdep != nil {
1022 return vndkdep.isVndkSp()
1023 }
1024 return false
1025}
1026
1027func (c *Module) isVndkExt() bool {
1028 if vndkdep := c.vndkdep; vndkdep != nil {
1029 return vndkdep.isVndkExt()
1030 }
1031 return false
1032}
1033
Ivan Lozano52767be2019-10-18 14:49:46 -07001034func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001035 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001036}
1037
Logan Chienf3511742017-10-31 18:04:35 +08001038func (c *Module) getVndkExtendsModuleName() string {
1039 if vndkdep := c.vndkdep; vndkdep != nil {
1040 return vndkdep.getVndkExtendsModuleName()
1041 }
1042 return ""
1043}
1044
Jiyong Park25fc6a92018-11-18 18:02:45 +09001045func (c *Module) IsStubs() bool {
1046 if library, ok := c.linker.(*libraryDecorator); ok {
1047 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001048 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1049 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001050 }
1051 return false
1052}
1053
1054func (c *Module) HasStubsVariants() bool {
1055 if library, ok := c.linker.(*libraryDecorator); ok {
1056 return len(library.Properties.Stubs.Versions) > 0
1057 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001058 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1059 return len(library.Properties.Stubs.Versions) > 0
1060 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001061 return false
1062}
1063
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001064func (c *Module) bootstrap() bool {
1065 return Bool(c.Properties.Bootstrap)
1066}
1067
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001068func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001069 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1070 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1071 return false
1072 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001073 return c.linker != nil && c.linker.nativeCoverage()
1074}
1075
Inseob Kim8471cda2019-11-15 09:59:12 +09001076func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001077 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1078 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001079 }
1080 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001081}
1082
Jiyong Park73c54ee2019-10-22 20:31:18 +09001083func (c *Module) ExportedIncludeDirs() android.Paths {
1084 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1085 return flagsProducer.exportedDirs()
1086 }
Jiyong Park232e7852019-11-04 12:23:40 +09001087 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001088}
1089
1090func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1091 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1092 return flagsProducer.exportedSystemDirs()
1093 }
Jiyong Park232e7852019-11-04 12:23:40 +09001094 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001095}
1096
1097func (c *Module) ExportedFlags() []string {
1098 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1099 return flagsProducer.exportedFlags()
1100 }
Jiyong Park232e7852019-11-04 12:23:40 +09001101 return nil
1102}
1103
1104func (c *Module) ExportedDeps() android.Paths {
1105 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1106 return flagsProducer.exportedDeps()
1107 }
1108 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001109}
1110
Inseob Kimd110f872019-12-06 13:15:38 +09001111func (c *Module) ExportedGeneratedHeaders() android.Paths {
1112 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1113 return flagsProducer.exportedGeneratedHeaders()
1114 }
1115 return nil
1116}
1117
Bill Peckham945441c2020-08-31 16:07:58 -07001118func (c *Module) ExcludeFromVendorSnapshot() bool {
1119 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1120}
1121
Jiyong Parkf1194352019-02-25 11:05:47 +09001122func isBionic(name string) bool {
1123 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001124 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001125 return true
1126 }
1127 return false
1128}
1129
Martin Stjernholm279de572019-09-10 23:18:20 +01001130func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001131 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001132 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001133 }
1134 return isBionic(name)
1135}
1136
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001137func (c *Module) XrefCcFiles() android.Paths {
1138 return c.kytheFiles
1139}
1140
Colin Crossca860ac2016-01-04 14:34:37 -08001141type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001142 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001143 moduleContextImpl
1144}
1145
Colin Cross37047f12016-12-13 17:06:13 -08001146type depsContext struct {
1147 android.BottomUpMutatorContext
1148 moduleContextImpl
1149}
1150
Colin Crossca860ac2016-01-04 14:34:37 -08001151type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001152 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001153 moduleContextImpl
1154}
1155
1156type moduleContextImpl struct {
1157 mod *Module
1158 ctx BaseModuleContext
1159}
1160
Colin Crossb98c8b02016-07-29 13:44:28 -07001161func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001162 return ctx.mod.toolchain(ctx.ctx)
1163}
1164
1165func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001166 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001167}
1168
1169func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001170 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001171}
1172
Jiyong Park1d1119f2019-07-29 21:27:18 +09001173func (ctx *moduleContextImpl) header() bool {
1174 return ctx.mod.header()
1175}
1176
Inseob Kim7f283f42020-06-01 21:53:49 +09001177func (ctx *moduleContextImpl) binary() bool {
1178 return ctx.mod.binary()
1179}
1180
Inseob Kim1042d292020-06-01 23:23:05 +09001181func (ctx *moduleContextImpl) object() bool {
1182 return ctx.mod.object()
1183}
1184
Jooyung Hanccce2f22020-03-07 03:45:53 +09001185func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001186 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001187}
1188
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001190 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001191}
1192
1193func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001194 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001195 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001196 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001197 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001198 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001199 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001200 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001201 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001202 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001203 }
1204 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001205}
1206
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001207func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001208 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001209}
Justin Yun8effde42017-06-23 19:24:43 +09001210
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001211func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001212 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001213}
1214
Inseob Kim9516ee92019-05-09 10:56:13 +09001215func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1216 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001217}
1218
Inseob Kim9516ee92019-05-09 10:56:13 +09001219func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1220 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001221}
1222
Inseob Kim9516ee92019-05-09 10:56:13 +09001223func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1224 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001225}
1226
Logan Chienf3511742017-10-31 18:04:35 +08001227func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001228 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001229}
1230
Yi Kong7e53c572018-02-14 18:16:12 +08001231func (ctx *moduleContextImpl) isPgoCompile() bool {
1232 return ctx.mod.isPgoCompile()
1233}
1234
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001235func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1236 return ctx.mod.isNDKStubLibrary()
1237}
1238
Justin Yun8effde42017-06-23 19:24:43 +09001239func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001240 return ctx.mod.isVndkSp()
1241}
1242
1243func (ctx *moduleContextImpl) isVndkExt() bool {
1244 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001245}
1246
Vic Yangefd249e2018-11-12 20:19:56 -08001247func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001248 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001249}
1250
Logan Chien2f2b8902018-07-10 15:01:19 +08001251// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001252func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001253 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1254 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001255 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001256
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001257 // Coverage builds have extra symbols.
1258 if ctx.mod.isCoverageVariant() {
1259 return false
1260 }
1261
Doug Hornc32c6b02019-01-17 14:44:05 -08001262 if ctx.ctx.Fuchsia() {
1263 return false
1264 }
1265
Logan Chien2f2b8902018-07-10 15:01:19 +08001266 if sanitize := ctx.mod.sanitize; sanitize != nil {
1267 if !sanitize.isVariantOnProductionDevice() {
1268 return false
1269 }
1270 }
1271 if !ctx.ctx.Device() {
1272 // Host modules do not need ABI dumps.
1273 return false
1274 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001275 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001276 // Stubs do not need ABI dumps.
1277 return false
1278 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001279 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001280}
1281
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001282func (ctx *moduleContextImpl) selectedStl() string {
1283 if stl := ctx.mod.stl; stl != nil {
1284 return stl.Properties.SelectedStl
1285 }
1286 return ""
1287}
1288
Ivan Lozanobd721262018-11-27 14:33:03 -08001289func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1290 return ctx.mod.linker.useClangLld(actx)
1291}
1292
Colin Crossce75d2c2016-10-06 16:12:58 -07001293func (ctx *moduleContextImpl) baseModuleName() string {
1294 return ctx.mod.ModuleBase.BaseModuleName()
1295}
1296
Logan Chienf3511742017-10-31 18:04:35 +08001297func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1298 return ctx.mod.getVndkExtendsModuleName()
1299}
1300
Logan Chiene274fc92019-12-03 11:18:32 -08001301func (ctx *moduleContextImpl) isForPlatform() bool {
1302 return ctx.mod.IsForPlatform()
1303}
1304
Colin Crosse07f2312020-08-13 11:24:56 -07001305func (ctx *moduleContextImpl) apexVariationName() string {
1306 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001307}
1308
Dan Albertc8060532020-07-22 22:32:17 -07001309func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001310 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001311}
1312
Jiyong Parkb0788572018-12-20 22:10:17 +09001313func (ctx *moduleContextImpl) hasStubsVariants() bool {
1314 return ctx.mod.HasStubsVariants()
1315}
1316
1317func (ctx *moduleContextImpl) isStubs() bool {
1318 return ctx.mod.IsStubs()
1319}
1320
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001321func (ctx *moduleContextImpl) bootstrap() bool {
1322 return ctx.mod.bootstrap()
1323}
1324
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001325func (ctx *moduleContextImpl) nativeCoverage() bool {
1326 return ctx.mod.nativeCoverage()
1327}
1328
Colin Cross635c3b02016-05-18 15:37:25 -07001329func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001330 return &Module{
1331 hod: hod,
1332 multilib: multilib,
1333 }
1334}
1335
Colin Cross635c3b02016-05-18 15:37:25 -07001336func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001337 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001338 module.features = []feature{
1339 &tidyFeature{},
1340 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001341 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001342 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001343 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001344 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001345 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001346 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001347 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001348 return module
1349}
1350
Colin Crossce75d2c2016-10-06 16:12:58 -07001351func (c *Module) Prebuilt() *android.Prebuilt {
1352 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1353 return p.prebuilt()
1354 }
1355 return nil
1356}
1357
1358func (c *Module) Name() string {
1359 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001360 if p, ok := c.linker.(interface {
1361 Name(string) string
1362 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001363 name = p.Name(name)
1364 }
1365 return name
1366}
1367
Alex Light3d673592019-01-18 14:37:31 -08001368func (c *Module) Symlinks() []string {
1369 if p, ok := c.installer.(interface {
1370 symlinkList() []string
1371 }); ok {
1372 return p.symlinkList()
1373 }
1374 return nil
1375}
1376
Jeff Gaston294356f2017-09-27 17:05:30 -07001377// orderDeps reorders dependencies into a list such that if module A depends on B, then
1378// A will precede B in the resultant list.
1379// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001380// Note that directSharedDeps should be the analogous static library for each shared lib dep
1381func 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 -07001382 // If A depends on B, then
1383 // Every list containing A will also contain B later in the list
1384 // So, after concatenating all lists, the final instance of B will have come from the same
1385 // original list as the final instance of A
1386 // So, the final instance of B will be later in the concatenation than the final A
1387 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1388 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001389 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001390 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001391 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1392 }
1393 for _, dep := range directSharedDeps {
1394 orderedAllDeps = append(orderedAllDeps, dep)
1395 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001396 }
1397
Colin Crossb6715442017-10-24 11:13:31 -07001398 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001399
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001400 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001401 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001402 // resultant list to only what the caller has chosen to include in directStaticDeps
1403 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001404
1405 return orderedAllDeps, orderedDeclaredDeps
1406}
1407
Ivan Lozano183a3212019-10-18 14:18:45 -07001408func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001409 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001410 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001411 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1412 staticDepFiles := []android.Path{}
1413 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001414 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1415 if dep.OutputFile().Valid() {
1416 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1417 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1418 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001419 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001420 sharedDepFiles := []android.Path{}
1421 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001422 if sharedDep.HasStaticVariant() {
1423 staticAnalogue := sharedDep.GetStaticVariant()
1424 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1425 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001426 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001427 }
1428
1429 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001430 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1431 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001432
1433 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001434}
1435
Roland Levillainf89cd092019-07-29 16:22:59 +01001436func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1437 test, ok := c.linker.(testPerSrc)
1438 return ok && test.isAllTestsVariation()
1439}
1440
Chris Parsons216e10a2020-07-09 17:12:52 -04001441func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001442 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001443 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001444 }); ok {
1445 return p.dataPaths()
1446 }
1447 return nil
1448}
1449
Justin Yun5f7f7e82019-11-18 19:52:14 +09001450func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1451 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1452 // "current", it will append the VNDK version to the name suffix.
1453 var vndkVersion string
1454 var nameSuffix string
1455 if c.inProduct() {
1456 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1457 nameSuffix = productSuffix
1458 } else {
1459 vndkVersion = ctx.DeviceConfig().VndkVersion()
1460 nameSuffix = vendorSuffix
1461 }
1462 if vndkVersion == "current" {
1463 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1464 }
1465 if c.Properties.VndkVersion != vndkVersion {
1466 // add version suffix only if the module is using different vndk version than the
1467 // version in product or vendor partition.
1468 nameSuffix += "." + c.Properties.VndkVersion
1469 }
1470 return nameSuffix
1471}
1472
Colin Cross635c3b02016-05-18 15:37:25 -07001473func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001474 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001475 //
1476 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1477 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1478 // module and return early, as this module does not produce an output file per se.
1479 if c.IsTestPerSrcAllTestsVariation() {
1480 c.outputFile = android.OptionalPath{}
1481 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001482 }
1483
Jooyung Han38002912019-05-16 04:01:54 +09001484 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001485
Inseob Kim64c43952019-08-26 16:52:35 +09001486 c.Properties.SubName = ""
1487
1488 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1489 c.Properties.SubName += nativeBridgeSuffix
1490 }
1491
Justin Yun5f7f7e82019-11-18 19:52:14 +09001492 _, llndk := c.linker.(*llndkStubDecorator)
1493 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1494 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1495 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1496 // added for product variant only when we have vendor and product variants with core
1497 // variant. The suffix is not added for vendor-only or product-only module.
1498 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1499 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001500 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1501 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1502 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001503 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1504 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001505 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001506 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001507 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001508 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001509 if c.SplitPerApiLevel() {
1510 c.Properties.SubName += "." + c.SdkVersion()
1511 }
Inseob Kim64c43952019-08-26 16:52:35 +09001512 }
1513
Colin Crossca860ac2016-01-04 14:34:37 -08001514 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001515 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001516 moduleContextImpl: moduleContextImpl{
1517 mod: c,
1518 },
1519 }
1520 ctx.ctx = ctx
1521
Colin Crossf18e1102017-11-16 14:33:08 -08001522 deps := c.depsToPaths(ctx)
1523 if ctx.Failed() {
1524 return
1525 }
1526
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001527 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1528 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1529 }
1530
Colin Crossca860ac2016-01-04 14:34:37 -08001531 flags := Flags{
1532 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001533 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001534 }
Colin Crossca860ac2016-01-04 14:34:37 -08001535 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001536 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001537 }
1538 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001539 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001540 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001541 if c.stl != nil {
1542 flags = c.stl.flags(ctx, flags)
1543 }
Colin Cross16b23492016-01-06 14:41:07 -08001544 if c.sanitize != nil {
1545 flags = c.sanitize.flags(ctx, flags)
1546 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001547 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001548 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001549 }
Stephen Craneba090d12017-05-09 15:44:35 -07001550 if c.lto != nil {
1551 flags = c.lto.flags(ctx, flags)
1552 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001553 if c.pgo != nil {
1554 flags = c.pgo.flags(ctx, flags)
1555 }
Colin Crossca860ac2016-01-04 14:34:37 -08001556 for _, feature := range c.features {
1557 flags = feature.flags(ctx, flags)
1558 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001559 if ctx.Failed() {
1560 return
1561 }
1562
Colin Cross4af21ed2019-11-04 09:37:55 -08001563 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1564 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1565 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001566
Colin Cross4af21ed2019-11-04 09:37:55 -08001567 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001568
1569 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001570 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001571 }
1572 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001573 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001574 }
1575
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001576 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001577 // We need access to all the flags seen by a source file.
1578 if c.sabi != nil {
1579 flags = c.sabi.flags(ctx, flags)
1580 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001581
Colin Cross4af21ed2019-11-04 09:37:55 -08001582 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001583
Colin Crossca860ac2016-01-04 14:34:37 -08001584 // Optimization to reduce size of build.ninja
1585 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001586 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1587 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1588 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1589 flags.Local.CFlags = []string{"$cflags"}
1590 flags.Local.CppFlags = []string{"$cppflags"}
1591 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001592
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001593 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001594 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001595 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001596 if ctx.Failed() {
1597 return
1598 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001599 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001600 }
1601
Colin Crossca860ac2016-01-04 14:34:37 -08001602 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001603 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001604 if ctx.Failed() {
1605 return
1606 }
Colin Cross635c3b02016-05-18 15:37:25 -07001607 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001608
1609 // If a lib is directly included in any of the APEXes, unhide the stubs
1610 // variant having the latest version gets visible to make. In addition,
1611 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1612 // force anything in the make world to link against the stubs library.
1613 // (unless it is explicitly referenced via .bootstrap suffix or the
1614 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001615 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001616 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001617 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001618 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001619 c.Properties.HideFromMake = false // unhide
1620 // Note: this is still non-installable
1621 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001622
1623 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1624 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1625 if isSnapshotAware(ctx, c) {
1626 i.collectHeadersForSnapshot(ctx)
1627 }
1628 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001629 }
Colin Cross5049f022015-03-18 13:28:46 -07001630
Inseob Kim1f086e22019-05-09 13:29:15 +09001631 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001632 c.installer.install(ctx, c.outputFile.Path())
1633 if ctx.Failed() {
1634 return
Colin Crossca860ac2016-01-04 14:34:37 -08001635 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001636 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1637 // If the module has been specifically configure to not be installed then
1638 // skip the installation as otherwise it will break when running inside make
1639 // as the output path to install will not be specified. Not all uninstallable
1640 // modules can skip installation as some are needed for resolving make side
1641 // dependencies.
1642 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001643 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001644}
1645
Colin Cross0ea8ba82019-06-06 14:33:29 -07001646func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001647 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001648 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001649 }
Colin Crossca860ac2016-01-04 14:34:37 -08001650 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001651}
1652
Colin Crossca860ac2016-01-04 14:34:37 -08001653func (c *Module) begin(ctx BaseModuleContext) {
1654 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001655 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001656 }
Colin Crossca860ac2016-01-04 14:34:37 -08001657 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001658 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001659 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001660 if c.stl != nil {
1661 c.stl.begin(ctx)
1662 }
Colin Cross16b23492016-01-06 14:41:07 -08001663 if c.sanitize != nil {
1664 c.sanitize.begin(ctx)
1665 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001666 if c.coverage != nil {
1667 c.coverage.begin(ctx)
1668 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001669 if c.sabi != nil {
1670 c.sabi.begin(ctx)
1671 }
Justin Yun8effde42017-06-23 19:24:43 +09001672 if c.vndkdep != nil {
1673 c.vndkdep.begin(ctx)
1674 }
Stephen Craneba090d12017-05-09 15:44:35 -07001675 if c.lto != nil {
1676 c.lto.begin(ctx)
1677 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001678 if c.pgo != nil {
1679 c.pgo.begin(ctx)
1680 }
Colin Crossca860ac2016-01-04 14:34:37 -08001681 for _, feature := range c.features {
1682 feature.begin(ctx)
1683 }
Dan Albert92fe7402020-07-15 13:33:30 -07001684 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001685 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001686 if err != nil {
1687 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001688 c.Properties.Sdk_version = nil
1689 } else {
1690 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001691 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001692 }
Colin Crossca860ac2016-01-04 14:34:37 -08001693}
1694
Colin Cross37047f12016-12-13 17:06:13 -08001695func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001696 deps := Deps{}
1697
1698 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001699 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001700 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001701 // Add the PGO dependency (the clang_rt.profile runtime library), which
1702 // sometimes depends on symbols from libgcc, before libgcc gets added
1703 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001704 if c.pgo != nil {
1705 deps = c.pgo.deps(ctx, deps)
1706 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001707 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001708 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001709 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001710 if c.stl != nil {
1711 deps = c.stl.deps(ctx, deps)
1712 }
Colin Cross16b23492016-01-06 14:41:07 -08001713 if c.sanitize != nil {
1714 deps = c.sanitize.deps(ctx, deps)
1715 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001716 if c.coverage != nil {
1717 deps = c.coverage.deps(ctx, deps)
1718 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001719 if c.sabi != nil {
1720 deps = c.sabi.deps(ctx, deps)
1721 }
Justin Yun8effde42017-06-23 19:24:43 +09001722 if c.vndkdep != nil {
1723 deps = c.vndkdep.deps(ctx, deps)
1724 }
Stephen Craneba090d12017-05-09 15:44:35 -07001725 if c.lto != nil {
1726 deps = c.lto.deps(ctx, deps)
1727 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001728 for _, feature := range c.features {
1729 deps = feature.deps(ctx, deps)
1730 }
1731
Colin Crossb6715442017-10-24 11:13:31 -07001732 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1733 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1734 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1735 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1736 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1737 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001738 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001739
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001740 for _, lib := range deps.ReexportSharedLibHeaders {
1741 if !inList(lib, deps.SharedLibs) {
1742 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1743 }
1744 }
1745
1746 for _, lib := range deps.ReexportStaticLibHeaders {
1747 if !inList(lib, deps.StaticLibs) {
1748 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1749 }
1750 }
1751
Colin Cross5950f382016-12-13 12:50:57 -08001752 for _, lib := range deps.ReexportHeaderLibHeaders {
1753 if !inList(lib, deps.HeaderLibs) {
1754 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1755 }
1756 }
1757
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001758 for _, gen := range deps.ReexportGeneratedHeaders {
1759 if !inList(gen, deps.GeneratedHeaders) {
1760 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1761 }
1762 }
1763
Colin Crossc99deeb2016-04-11 15:06:20 -07001764 return deps
1765}
1766
Dan Albert7e9d2952016-08-04 13:02:36 -07001767func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001768 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001769 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001770 moduleContextImpl: moduleContextImpl{
1771 mod: c,
1772 },
1773 }
1774 ctx.ctx = ctx
1775
Colin Crossca860ac2016-01-04 14:34:37 -08001776 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001777}
1778
Jiyong Park7ed9de32018-10-15 22:25:07 +09001779// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001780func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001781 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1782 version := name[sharp+1:]
1783 libname := name[:sharp]
1784 return libname, version
1785 }
1786 return name, ""
1787}
1788
Dan Albert92fe7402020-07-15 13:33:30 -07001789func GetCrtVariations(ctx android.BottomUpMutatorContext,
1790 m LinkableInterface) []blueprint.Variation {
1791 if ctx.Os() != android.Android {
1792 return nil
1793 }
1794 if m.UseSdk() {
1795 return []blueprint.Variation{
1796 {Mutator: "sdk", Variation: "sdk"},
1797 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1798 }
1799 }
1800 return []blueprint.Variation{
1801 {Mutator: "sdk", Variation: ""},
1802 }
1803}
1804
Colin Cross1e676be2016-10-12 14:38:15 -07001805func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001806 if !c.Enabled() {
1807 return
1808 }
1809
Colin Cross37047f12016-12-13 17:06:13 -08001810 ctx := &depsContext{
1811 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001812 moduleContextImpl: moduleContextImpl{
1813 mod: c,
1814 },
1815 }
1816 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001817
Colin Crossc99deeb2016-04-11 15:06:20 -07001818 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001819
Dan Albert914449f2016-06-17 16:45:24 -07001820 variantNdkLibs := []string{}
1821 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001822 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001823 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001824 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001825 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001826 // 1. Name of an NDK library that refers to a prebuilt module.
1827 // For each of these, it adds the name of the prebuilt module (which will be in
1828 // prebuilts/ndk) to the list of nonvariant libs.
1829 // 2. Name of an NDK library that refers to an ndk_library module.
1830 // For each of these, it adds the name of the ndk_library module to the list of
1831 // variant libs.
1832 // 3. Anything else (so anything that isn't an NDK library).
1833 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001834 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001835 // The caller can then know to add the variantLibs dependencies differently from the
1836 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001837
Inseob Kim9516ee92019-05-09 10:56:13 +09001838 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001839 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1840
1841 rewriteVendorLibs := func(lib string) string {
1842 if isLlndkLibrary(lib, ctx.Config()) {
1843 return lib + llndkLibrarySuffix
1844 }
1845
1846 // only modules with BOARD_VNDK_VERSION uses snapshot.
1847 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1848 return lib
1849 }
1850
1851 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1852 return snapshot
1853 }
1854
1855 return lib
1856 }
1857
1858 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001859 variantLibs = []string{}
1860 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001861 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001862 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001863 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001864 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1865 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001866 } else if ctx.useVndk() {
1867 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001868 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001869 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001870 if actx.OtherModuleExists(vendorPublicLib) {
1871 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1872 } else {
1873 // This can happen if vendor_public_library module is defined in a
1874 // namespace that isn't visible to the current module. In that case,
1875 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001876 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001877 }
Dan Albert914449f2016-06-17 16:45:24 -07001878 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001879 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001880 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001881 }
1882 }
Dan Albert914449f2016-06-17 16:45:24 -07001883 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001884 }
1885
Inseob Kimeec88e12020-01-22 11:11:29 +09001886 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1887 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1888 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1889 if ctx.useVndk() {
1890 for idx, lib := range deps.RuntimeLibs {
1891 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1892 }
1893 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001894 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001895
Jiyong Park7e636d02019-01-28 16:16:54 +09001896 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001897 if c.linker != nil {
1898 if library, ok := c.linker.(*libraryDecorator); ok {
1899 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001900 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001901 }
1902 }
1903 }
1904
Inseob Kimeec88e12020-01-22 11:11:29 +09001905 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1906 // only modules with BOARD_VNDK_VERSION uses snapshot.
1907 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1908 return lib
1909 }
1910
1911 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1912 return snapshot
1913 }
1914
1915 return lib
1916 }
1917
1918 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001919 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001920 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001921 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001922 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001923 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001924
1925 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1926
Jiyong Park7e636d02019-01-28 16:16:54 +09001927 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001928 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001929 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001930 } else {
1931 actx.AddVariationDependencies(nil, depTag, lib)
1932 }
1933 }
1934
1935 if buildStubs {
1936 // Stubs lib does not have dependency to other static/shared libraries.
1937 // Don't proceed.
1938 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001939 }
Colin Cross5950f382016-12-13 12:50:57 -08001940
Inseob Kimc0907f12019-02-08 21:00:45 +09001941 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001942 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001943
Jiyong Park5d1598f2019-02-25 22:14:17 +09001944 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001945 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001946 if impl, ok := syspropImplLibraries[lib]; ok {
1947 lib = impl
1948 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001949
1950 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1951
Jiyong Park5d1598f2019-02-25 22:14:17 +09001952 actx.AddVariationDependencies([]blueprint.Variation{
1953 {Mutator: "link", Variation: "static"},
1954 }, depTag, lib)
1955 }
1956
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001957 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001958 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001959 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001960 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001961 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001962
1963 if impl, ok := syspropImplLibraries[lib]; ok {
1964 lib = impl
1965 }
1966
Inseob Kimeec88e12020-01-22 11:11:29 +09001967 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1968
Dan Willemsen59339a22018-07-22 21:18:45 -07001969 actx.AddVariationDependencies([]blueprint.Variation{
1970 {Mutator: "link", Variation: "static"},
1971 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001972 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001973
Jooyung Han75568392020-03-20 04:29:24 +09001974 // staticUnwinderDep is treated as staticDep for Q apexes
1975 // so that native libraries/binaries are linked with static unwinder
1976 // because Q libc doesn't have unwinder APIs
1977 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001978 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001979 actx.AddVariationDependencies([]blueprint.Variation{
1980 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001981 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001982 }
1983
Inseob Kimeec88e12020-01-22 11:11:29 +09001984 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001985 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001986 actx.AddVariationDependencies([]blueprint.Variation{
1987 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001988 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001989 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001990
Colin Cross6e511a92020-07-27 21:26:48 -07001991 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001992 var variations []blueprint.Variation
1993 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001994 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001995 // Version is explicitly specified. i.e. libFoo#30
1996 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07001997 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001998 }
1999 actx.AddVariationDependencies(variations, depTag, name)
2000
Jooyung Han03b51852020-02-26 22:45:42 +09002001 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002002 // The stubs library will be used when the depending module is built for APEX and
2003 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002004 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09002005 for _, ver := range stubsVersionsFor(actx.Config())[name] {
2006 // Note that depTag.ExplicitlyVersioned is false in this case.
2007 actx.AddVariationDependencies([]blueprint.Variation{
2008 {Mutator: "link", Variation: "shared"},
2009 {Mutator: "version", Variation: ver},
2010 }, depTag, name)
2011 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002012 }
2013 }
2014
Jiyong Park7ed9de32018-10-15 22:25:07 +09002015 // shared lib names without the #version suffix
2016 var sharedLibNames []string
2017
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002018 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002019 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002020 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002021 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002022 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002023
2024 if impl, ok := syspropImplLibraries[lib]; ok {
2025 lib = impl
2026 }
2027
Jiyong Park73c54ee2019-10-22 20:31:18 +09002028 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002029 sharedLibNames = append(sharedLibNames, name)
2030
Jiyong Park25fc6a92018-11-18 18:02:45 +09002031 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002032 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002033
Jiyong Park7ed9de32018-10-15 22:25:07 +09002034 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002035 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002036 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2037 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2038 // linking against both the stubs lib and the non-stubs lib at the same time.
2039 continue
2040 }
Colin Cross6e511a92020-07-27 21:26:48 -07002041 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2042 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002043 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002044
Dan Willemsen59339a22018-07-22 21:18:45 -07002045 actx.AddVariationDependencies([]blueprint.Variation{
2046 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002047 }, dataLibDepTag, deps.DataLibs...)
2048
2049 actx.AddVariationDependencies([]blueprint.Variation{
2050 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002051 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002052
Colin Cross68861832016-07-08 10:41:41 -07002053 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002054
2055 for _, gen := range deps.GeneratedHeaders {
2056 depTag := genHeaderDepTag
2057 if inList(gen, deps.ReexportGeneratedHeaders) {
2058 depTag = genHeaderExportDepTag
2059 }
2060 actx.AddDependency(c, depTag, gen)
2061 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002062
Colin Cross42d48b72018-08-29 14:10:52 -07002063 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002064
Inseob Kim1042d292020-06-01 23:23:05 +09002065 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2066
Dan Albert92fe7402020-07-15 13:33:30 -07002067 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002068 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002069 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2070 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002071 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002072 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002073 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2074 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002075 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002076 if deps.LinkerFlagsFile != "" {
2077 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2078 }
2079 if deps.DynamicLinker != "" {
2080 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002081 }
Dan Albert914449f2016-06-17 16:45:24 -07002082
2083 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002084
2085 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002086 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002087 {Mutator: "ndk_api", Variation: version},
2088 {Mutator: "link", Variation: "shared"},
2089 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002090
2091 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002092 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002093 {Mutator: "ndk_api", Variation: version},
2094 {Mutator: "link", Variation: "shared"},
2095 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002096
2097 if vndkdep := c.vndkdep; vndkdep != nil {
2098 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002099 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002100 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002101 {Mutator: "link", Variation: "shared"},
2102 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002103 }
2104 }
Colin Cross6362e272015-10-29 15:25:03 -07002105}
Colin Cross21b9a242015-03-24 14:15:58 -07002106
Colin Crosse40b4ea2018-10-02 22:25:58 -07002107func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002108 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2109 c.beginMutator(ctx)
2110 }
2111}
2112
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002113// Whether a module can link to another module, taking into
2114// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002115func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2116 tag blueprint.DependencyTag) {
2117
2118 switch t := tag.(type) {
2119 case dependencyTag:
2120 if t != vndkExtDepTag {
2121 return
2122 }
2123 case libraryDependencyTag:
2124 default:
2125 return
2126 }
2127
Ivan Lozano52767be2019-10-18 14:49:46 -07002128 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002129 // Host code is not restricted
2130 return
2131 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002132
2133 // VNDK is cc.Module supported only for now.
2134 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002135 // Though vendor code is limited by the vendor mutator,
2136 // each vendor-available module needs to check
2137 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002138 if ccTo, ok := to.(*Module); ok {
2139 if ccFrom.vndkdep != nil {
2140 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2141 }
2142 } else {
2143 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002144 }
2145 return
2146 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002147 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002148 // Platform code can link to anything
2149 return
2150 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002151 if from.InRamdisk() {
2152 // Ramdisk code is not NDK
2153 return
2154 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002155 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002156 // Recovery code is not NDK
2157 return
2158 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002159 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002160 // These are always allowed
2161 return
2162 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002163 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002164 // These are allowed, but they don't set sdk_version
2165 return
2166 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002167 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002168 // These aren't real libraries, but are the stub shared libraries that are included in
2169 // the NDK.
2170 return
2171 }
Logan Chien834b9a62019-01-14 15:39:03 +08002172
Ivan Lozano52767be2019-10-18 14:49:46 -07002173 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002174 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2175 // to link to libc++ (non-NDK and without sdk_version).
2176 return
2177 }
2178
Ivan Lozano52767be2019-10-18 14:49:46 -07002179 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002180 // NDK code linking to platform code is never okay.
2181 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002182 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002183 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002184 }
2185
2186 // At this point we know we have two NDK libraries, but we need to
2187 // check that we're not linking against anything built against a higher
2188 // API level, as it is only valid to link against older or equivalent
2189 // APIs.
2190
Inseob Kim01a28722018-04-11 09:48:45 +09002191 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002192 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002193 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002194 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002195 // Current can't be linked against by anything else.
2196 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002198 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002199 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002200 if err != nil {
2201 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002202 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002204 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002205 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002206 if err != nil {
2207 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002208 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002209 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002210 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002211
Inseob Kim01a28722018-04-11 09:48:45 +09002212 if toApi > fromApi {
2213 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002214 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002215 }
2216 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002217 }
Dan Albert202fe492017-12-15 13:56:59 -08002218
2219 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002220 fromStl := from.SelectedStl()
2221 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002222 if fromStl == "" || toStl == "" {
2223 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002224 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002225 // We can be permissive with the system "STL" since it is only the C++
2226 // ABI layer, but in the future we should make sure that everyone is
2227 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002228 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002229 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002230 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2231 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002232 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002233}
2234
Jiyong Park5fb8c102018-04-09 12:03:06 +09002235// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002236// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2237// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002238// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002239func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2240 check := func(child, parent android.Module) bool {
2241 to, ok := child.(*Module)
2242 if !ok {
2243 // follow thru cc.Defaults, etc.
2244 return true
2245 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002246
Jooyung Hana70f0672019-01-18 15:20:43 +09002247 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2248 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002249 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002250
2251 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002252 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002253 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002254 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002255
Jooyung Han0302a842019-10-30 18:43:49 +09002256 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002257 return false
2258 }
2259
2260 var stringPath []string
2261 for _, m := range ctx.GetWalkPath() {
2262 stringPath = append(stringPath, m.Name())
2263 }
2264 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2265 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2266 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2267 return false
2268 }
2269 if module, ok := ctx.Module().(*Module); ok {
2270 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002271 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002272 ctx.WalkDeps(check)
2273 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002274 }
2275 }
2276}
2277
Colin Crossc99deeb2016-04-11 15:06:20 -07002278// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002279func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002280 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002281
Ivan Lozano183a3212019-10-18 14:18:45 -07002282 directStaticDeps := []LinkableInterface{}
2283 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002284
Inseob Kim69378442019-06-03 19:10:47 +09002285 reexportExporter := func(exporter exportedFlagsProducer) {
2286 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2287 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2288 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2289 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002290 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002291 }
2292
Jooyung Hande34d232020-07-23 13:04:15 +09002293 // For the dependency from platform to apex, use the latest stubs
Dan Albertc8060532020-07-22 22:32:17 -07002294 c.apexSdkVersion = android.CurrentApiLevel
Jooyung Hande34d232020-07-23 13:04:15 +09002295 if !c.IsForPlatform() {
Dan Albertc8060532020-07-22 22:32:17 -07002296 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002297 }
2298
2299 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2300 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2301 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2302 // (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002303 c.apexSdkVersion = android.CurrentApiLevel
Jooyung Hande34d232020-07-23 13:04:15 +09002304 }
2305
Colin Crossd11fcda2017-10-23 17:59:01 -07002306 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002307 depName := ctx.OtherModuleName(dep)
2308 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002309
Ivan Lozano52767be2019-10-18 14:49:46 -07002310 ccDep, ok := dep.(LinkableInterface)
2311 if !ok {
2312
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002313 // handling for a few module types that aren't cc Module but that are also supported
2314 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002315 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002316 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002317 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2318 genRule.GeneratedSourceFiles()...)
2319 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002320 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002321 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002322 // Support exported headers from a generated_sources dependency
2323 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002324 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002325 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002326 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002327 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002328 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002329 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002330 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002331 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002332 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2333 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002334 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002335 // 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 +09002336 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002337
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002338 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002339 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002340 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002341 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002342 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002343 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002344 files := genRule.GeneratedSourceFiles()
2345 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002346 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002347 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002348 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 -07002349 }
2350 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002351 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002352 }
Colin Crossca860ac2016-01-04 14:34:37 -08002353 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002354 return
2355 }
2356
Colin Crossfe17f6f2019-03-28 19:30:56 -07002357 if depTag == android.ProtoPluginDepTag {
2358 return
2359 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002360 if depTag == llndkImplDep {
2361 return
2362 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002363
Colin Crossd11fcda2017-10-23 17:59:01 -07002364 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002365 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2366 return
2367 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002368 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002369 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2370 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002371 return
2372 }
2373
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002374 // re-exporting flags
2375 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002376 // reusing objects only make sense for cc.Modules.
2377 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002378 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002379 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002380 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002381 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002382 return
2383 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002384 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002385
Jiyong Parke4bb9862019-02-01 00:31:10 +09002386 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002387 // staticVariants are a cc.Module specific concept.
2388 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002389 c.staticVariant = ccDep
2390 return
2391 }
2392 }
2393
Colin Cross6e511a92020-07-27 21:26:48 -07002394 checkLinkType(ctx, c, ccDep, depTag)
2395
2396 linkFile := ccDep.OutputFile()
2397
2398 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2399 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002400 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002401 return
2402 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002403
Colin Cross6e511a92020-07-27 21:26:48 -07002404 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002405 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002406 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002407 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002408 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002409
2410 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002411 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002412 // Always respect dependency to the versioned stubs (i.e. libX#10)
2413 useThisDep = true
2414 } else if !depHasStubs {
2415 // Use non-stub variant if that is the only choice
2416 // (i.e. depending on a lib without stubs.version property)
2417 useThisDep = true
2418 } else if c.IsForPlatform() {
2419 // If not building for APEX, use stubs only when it is from
2420 // an APEX (and not from platform)
2421 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002422 if c.bootstrap() {
2423 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002424 // always link to non-stub variant
2425 useThisDep = !depIsStubs
2426 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002427 for _, testFor := range c.TestFor() {
2428 // Another exception: if this module is bundled with an APEX, then
2429 // it is linked with the non-stub variant of a module in the APEX
2430 // as if this is part of the APEX.
2431 if android.DirectlyInApex(testFor, depName) {
2432 useThisDep = !depIsStubs
2433 break
2434 }
2435 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002436 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002437 // If building for APEX, use stubs when the parent is in any APEX that
2438 // the child is not in.
2439 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002440 }
2441
Jooyung Han03b51852020-02-26 22:45:42 +09002442 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002443 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Dan Albertc8060532020-07-22 22:32:17 -07002444 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion.FinalOrFutureInt())
Jooyung Han03b51852020-02-26 22:45:42 +09002445 if err != nil {
2446 ctx.OtherModuleErrorf(dep, err.Error())
2447 return
2448 }
2449 if versionToUse != ccDep.StubsVersion() {
2450 useThisDep = false
2451 }
2452 }
2453
Jiyong Park25fc6a92018-11-18 18:02:45 +09002454 if !useThisDep {
2455 return // stop processing this dep
2456 }
2457 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002458 if c.UseVndk() {
2459 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2460 // by default, use current version of LLNDK
2461 versionToUse := ""
2462 versions := stubsVersionsFor(ctx.Config())[depName]
Colin Crosse07f2312020-08-13 11:24:56 -07002463 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002464 // if this is for use_vendor apex && dep has stubsVersions
2465 // apply the same rule of apex sdk enforcement to choose right version
2466 var err error
Dan Albertc8060532020-07-22 22:32:17 -07002467 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion.FinalOrFutureInt())
Jooyung Han61b66e92020-03-21 14:21:46 +00002468 if err != nil {
2469 ctx.OtherModuleErrorf(dep, err.Error())
2470 return
2471 }
2472 }
2473 if versionToUse != ccDep.StubsVersion() {
2474 return
2475 }
2476 }
2477 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002478
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002479 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2480
Ivan Lozano52767be2019-10-18 14:49:46 -07002481 // Exporting flags only makes sense for cc.Modules
2482 if _, ok := ccDep.(*Module); ok {
2483 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002484 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002485 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002486 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002487
Colin Cross6e511a92020-07-27 21:26:48 -07002488 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002489 reexportExporter(i)
2490 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2491 // Re-exported shared library headers must be included as well since they can help us with type information
2492 // about template instantiations (instantiated from their headers).
2493 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2494 // scripts.
2495 c.sabi.Properties.ReexportedIncludes = append(
2496 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2497 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002498 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002499 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002500
Colin Cross6e511a92020-07-27 21:26:48 -07002501 var ptr *android.Paths
2502 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002503
Colin Cross6e511a92020-07-27 21:26:48 -07002504 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002505
Colin Cross6e511a92020-07-27 21:26:48 -07002506 switch {
2507 case libDepTag.header():
2508 // nothing
2509 case libDepTag.shared():
2510 ptr = &depPaths.SharedLibs
2511 switch libDepTag.Order {
2512 case earlyLibraryDependency:
2513 ptr = &depPaths.EarlySharedLibs
2514 depPtr = &depPaths.EarlySharedLibsDeps
2515 case normalLibraryDependency:
2516 ptr = &depPaths.SharedLibs
2517 depPtr = &depPaths.SharedLibsDeps
2518 directSharedDeps = append(directSharedDeps, ccDep)
2519 case lateLibraryDependency:
2520 ptr = &depPaths.LateSharedLibs
2521 depPtr = &depPaths.LateSharedLibsDeps
2522 default:
2523 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002524 }
Colin Cross6e511a92020-07-27 21:26:48 -07002525 depFile = ccDep.Toc()
2526 case libDepTag.static():
2527 if libDepTag.wholeStatic {
2528 ptr = &depPaths.WholeStaticLibs
2529 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2530 ctx.ModuleErrorf("module %q not a static library", depName)
2531 return
Inseob Kim752edec2020-03-14 01:30:34 +09002532 }
2533
Colin Cross6e511a92020-07-27 21:26:48 -07002534 // Because the static library objects are included, this only makes sense
2535 // in the context of proper cc.Modules.
2536 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2537 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2538 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2539 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2540 for i := range missingDeps {
2541 missingDeps[i] += postfix
2542 }
2543 ctx.AddMissingDependencies(missingDeps)
2544 }
2545 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2546 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2547 } else {
2548 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2549 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002550 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002551 ctx.ModuleErrorf(
2552 "non-cc.Modules cannot be included as whole static libraries.", depName)
2553 return
2554 }
2555
2556 } else {
2557 switch libDepTag.Order {
2558 case earlyLibraryDependency:
2559 panic(fmt.Errorf("early static libs not suppported"))
2560 case normalLibraryDependency:
2561 // static dependencies will be handled separately so they can be ordered
2562 // using transitive dependencies.
2563 ptr = nil
2564 directStaticDeps = append(directStaticDeps, ccDep)
2565 case lateLibraryDependency:
2566 ptr = &depPaths.LateStaticLibs
2567 default:
2568 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002569 }
2570 }
2571 }
2572
Colin Cross6e511a92020-07-27 21:26:48 -07002573 if libDepTag.static() && !libDepTag.wholeStatic {
2574 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2575 ctx.ModuleErrorf("module %q not a static library", depName)
2576 return
2577 }
Logan Chien43d34c32017-12-20 01:17:32 +08002578
Colin Cross6e511a92020-07-27 21:26:48 -07002579 // When combining coverage files for shared libraries and executables, coverage files
2580 // in static libraries act as if they were whole static libraries. The same goes for
2581 // source based Abi dump files.
2582 if c, ok := ccDep.(*Module); ok {
2583 staticLib := c.linker.(libraryInterface)
2584 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2585 staticLib.objs().coverageFiles...)
2586 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2587 staticLib.objs().sAbiDumpFiles...)
2588 } else if c, ok := ccDep.(LinkableInterface); ok {
2589 // Handle non-CC modules here
2590 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2591 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002592 }
2593 }
2594
Colin Cross6e511a92020-07-27 21:26:48 -07002595 if ptr != nil {
2596 if !linkFile.Valid() {
2597 if !ctx.Config().AllowMissingDependencies() {
2598 ctx.ModuleErrorf("module %q missing output file", depName)
2599 } else {
2600 ctx.AddMissingDependencies([]string{depName})
2601 }
2602 return
2603 }
2604 *ptr = append(*ptr, linkFile.Path())
2605 }
2606
2607 if depPtr != nil {
2608 dep := depFile
2609 if !dep.Valid() {
2610 dep = linkFile
2611 }
2612 *depPtr = append(*depPtr, dep.Path())
2613 }
2614
2615 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2616 switch {
2617 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002618 c.Properties.AndroidMkHeaderLibs = append(
2619 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002620 case libDepTag.shared():
2621 if ccDep.CcLibrary() {
2622 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2623 // Add the dependency to the APEX(es) providing the library so that
2624 // m <module> can trigger building the APEXes as well.
2625 for _, an := range android.GetApexesForModule(depName) {
2626 c.Properties.ApexesProvidingSharedLibs = append(
2627 c.Properties.ApexesProvidingSharedLibs, an)
2628 }
2629 }
2630 }
2631
2632 // Note: the order of libs in this list is not important because
2633 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002634 c.Properties.AndroidMkSharedLibs = append(
2635 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002636 // Record baseLibName for snapshots.
2637 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2638 case libDepTag.static():
2639 if libDepTag.wholeStatic {
2640 c.Properties.AndroidMkWholeStaticLibs = append(
2641 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2642 } else {
2643 c.Properties.AndroidMkStaticLibs = append(
2644 c.Properties.AndroidMkStaticLibs, makeLibName)
2645 }
2646 }
2647 } else {
2648 switch depTag {
2649 case runtimeDepTag:
2650 c.Properties.AndroidMkRuntimeLibs = append(
2651 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2652 // Record baseLibName for snapshots.
2653 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2654 case objDepTag:
2655 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2656 case CrtBeginDepTag:
2657 depPaths.CrtBegin = linkFile
2658 case CrtEndDepTag:
2659 depPaths.CrtEnd = linkFile
2660 case dynamicLinkerDepTag:
2661 depPaths.DynamicLinker = linkFile
2662 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002663 }
Colin Crossca860ac2016-01-04 14:34:37 -08002664 })
2665
Jeff Gaston294356f2017-09-27 17:05:30 -07002666 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002667 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002668
Colin Crossdd84e052017-05-17 13:44:16 -07002669 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002670 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002671 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2672 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002673 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002674 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2675 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002676 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002677 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002678 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002679
2680 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002681 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002682 }
Colin Crossdd84e052017-05-17 13:44:16 -07002683
Colin Crossca860ac2016-01-04 14:34:37 -08002684 return depPaths
2685}
2686
Colin Cross6e511a92020-07-27 21:26:48 -07002687// baseLibName trims known prefixes and suffixes
2688func baseLibName(depName string) string {
2689 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2690 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2691 libName = strings.TrimPrefix(libName, "prebuilt_")
2692 return libName
2693}
2694
2695func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2696 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2697 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2698
2699 libName := baseLibName(depName)
2700 isLLndk := isLlndkLibrary(libName, ctx.Config())
2701 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2702 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2703
2704 if c, ok := ccDep.(*Module); ok {
2705 // Use base module name for snapshots when exporting to Makefile.
2706 if c.isSnapshotPrebuilt() {
2707 baseName := c.BaseModuleName()
2708
2709 if c.IsVndk() {
2710 return baseName + ".vendor"
2711 }
2712
2713 if vendorSuffixModules[baseName] {
2714 return baseName + ".vendor"
2715 } else {
2716 return baseName
2717 }
2718 }
2719 }
2720
2721 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2722 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2723 // core module instead.
2724 return libName
2725 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2726 // The vendor module in Make will have been renamed to not conflict with the core
2727 // module, so update the dependency name here accordingly.
2728 return libName + c.getNameSuffixWithVndkVersion(ctx)
2729 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2730 return libName + vendorPublicLibrarySuffix
2731 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2732 return libName + ramdiskSuffix
2733 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2734 return libName + recoverySuffix
2735 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2736 return libName + nativeBridgeSuffix
2737 } else {
2738 return libName
2739 }
2740}
2741
Colin Crossca860ac2016-01-04 14:34:37 -08002742func (c *Module) InstallInData() bool {
2743 if c.installer == nil {
2744 return false
2745 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002746 return c.installer.inData()
2747}
2748
2749func (c *Module) InstallInSanitizerDir() bool {
2750 if c.installer == nil {
2751 return false
2752 }
2753 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002754 return true
2755 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002756 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002757}
2758
Yifan Hong1b3348d2020-01-21 15:53:22 -08002759func (c *Module) InstallInRamdisk() bool {
2760 return c.InRamdisk()
2761}
2762
Jiyong Parkf9332f12018-02-01 00:54:12 +09002763func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002764 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002765}
2766
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002767func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002768 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002769 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002770 return
2771 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002772 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002773}
2774
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002775func (c *Module) HostToolPath() android.OptionalPath {
2776 if c.installer == nil {
2777 return android.OptionalPath{}
2778 }
2779 return c.installer.hostToolPath()
2780}
2781
Nan Zhangd4e641b2017-07-12 12:55:28 -07002782func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2783 return c.outputFile
2784}
2785
Colin Cross41955e82019-05-29 14:40:35 -07002786func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2787 switch tag {
2788 case "":
2789 if c.outputFile.Valid() {
2790 return android.Paths{c.outputFile.Path()}, nil
2791 }
2792 return android.Paths{}, nil
2793 default:
2794 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002795 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002796}
2797
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002798func (c *Module) static() bool {
2799 if static, ok := c.linker.(interface {
2800 static() bool
2801 }); ok {
2802 return static.static()
2803 }
2804 return false
2805}
2806
Jiyong Park379de2f2018-12-19 02:47:14 +09002807func (c *Module) staticBinary() bool {
2808 if static, ok := c.linker.(interface {
2809 staticBinary() bool
2810 }); ok {
2811 return static.staticBinary()
2812 }
2813 return false
2814}
2815
Jiyong Park1d1119f2019-07-29 21:27:18 +09002816func (c *Module) header() bool {
2817 if h, ok := c.linker.(interface {
2818 header() bool
2819 }); ok {
2820 return h.header()
2821 }
2822 return false
2823}
2824
Inseob Kim7f283f42020-06-01 21:53:49 +09002825func (c *Module) binary() bool {
2826 if b, ok := c.linker.(interface {
2827 binary() bool
2828 }); ok {
2829 return b.binary()
2830 }
2831 return false
2832}
2833
Inseob Kim1042d292020-06-01 23:23:05 +09002834func (c *Module) object() bool {
2835 if o, ok := c.linker.(interface {
2836 object() bool
2837 }); ok {
2838 return o.object()
2839 }
2840 return false
2841}
2842
Jooyung Han38002912019-05-16 04:01:54 +09002843func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002844 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002845 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2846 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002847 return "native:vndk"
2848 }
Jooyung Han38002912019-05-16 04:01:54 +09002849 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002850 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002851 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002852 if Bool(c.VendorProperties.Vendor_available) {
2853 return "native:vndk"
2854 }
2855 return "native:vndk_private"
2856 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002857 if c.inProduct() {
2858 return "native:product"
2859 }
Jooyung Han38002912019-05-16 04:01:54 +09002860 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002861 } else if c.InRamdisk() {
2862 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002863 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002864 return "native:recovery"
2865 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2866 return "native:ndk:none:none"
2867 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2868 //family, link := getNdkStlFamilyAndLinkType(c)
2869 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002870 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002871 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002872 } else {
2873 return "native:platform"
2874 }
2875}
2876
Jiyong Park9d452992018-10-03 00:38:19 +09002877// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002878// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002879func (c *Module) IsInstallableToApex() bool {
2880 if shared, ok := c.linker.(interface {
2881 shared() bool
2882 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002883 // Stub libs and prebuilt libs in a versioned SDK are not
2884 // installable to APEX even though they are shared libs.
2885 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002886 } else if _, ok := c.linker.(testPerSrc); ok {
2887 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002888 }
2889 return false
2890}
2891
Jiyong Parka90ca002019-10-07 15:47:24 +09002892func (c *Module) AvailableFor(what string) bool {
2893 if linker, ok := c.linker.(interface {
2894 availableFor(string) bool
2895 }); ok {
2896 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2897 } else {
2898 return c.ApexModuleBase.AvailableFor(what)
2899 }
2900}
2901
Jiyong Park62304bb2020-04-13 16:19:48 +09002902func (c *Module) TestFor() []string {
2903 if test, ok := c.linker.(interface {
2904 testFor() []string
2905 }); ok {
2906 return test.testFor()
2907 } else {
2908 return c.ApexModuleBase.TestFor()
2909 }
2910}
2911
Colin Crossaede88c2020-08-11 12:17:01 -07002912func (c *Module) UniqueApexVariations() bool {
2913 if u, ok := c.compiler.(interface {
2914 uniqueApexVariations() bool
2915 }); ok {
2916 return u.uniqueApexVariations()
2917 } else {
2918 return false
2919 }
2920}
2921
Paul Duffin0cb37b92020-03-04 14:52:46 +00002922// Return true if the module is ever installable.
2923func (c *Module) EverInstallable() bool {
2924 return c.installer != nil &&
2925 // Check to see whether the module is actually ever installable.
2926 c.installer.everInstallable()
2927}
2928
Inseob Kim1f086e22019-05-09 13:29:15 +09002929func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002930 ret := c.EverInstallable() &&
2931 // Check to see whether the module has been configured to not be installed.
2932 proptools.BoolDefault(c.Properties.Installable, true) &&
2933 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002934
2935 // The platform variant doesn't need further condition. Apex variants however might not
2936 // be installable because it will likely to be included in the APEX and won't appear
2937 // in the system partition.
2938 if c.IsForPlatform() {
2939 return ret
2940 }
2941
2942 // Special case for modules that are configured to be installed to /data, which includes
2943 // test modules. For these modules, both APEX and non-APEX variants are considered as
2944 // installable. This is because even the APEX variants won't be included in the APEX, but
2945 // will anyway be installed to /data/*.
2946 // See b/146995717
2947 if c.InstallInData() {
2948 return ret
2949 }
2950
2951 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002952}
2953
Logan Chien41eabe62019-04-10 13:33:58 +08002954func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2955 if c.linker != nil {
2956 if library, ok := c.linker.(*libraryDecorator); ok {
2957 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2958 }
2959 }
2960}
2961
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002962func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002963 depTag := ctx.OtherModuleDependencyTag(dep)
2964 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2965
2966 if cc, ok := dep.(*Module); ok {
2967 if cc.HasStubsVariants() {
2968 if isLibDepTag && libDepTag.shared() {
2969 // dynamic dep to a stubs lib crosses APEX boundary
2970 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002971 }
Colin Cross6e511a92020-07-27 21:26:48 -07002972 if IsRuntimeDepTag(depTag) {
2973 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002974 return false
2975 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002976 }
Colin Crossaac32222020-07-29 12:51:56 -07002977 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002978 // shared_lib dependency from a static lib is considered as crossing
2979 // the APEX boundary because the dependency doesn't actually is
2980 // linked; the dependency is used only during the compilation phase.
2981 return false
2982 }
2983 }
2984 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09002985 // We don't track beyond LLNDK
2986 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002987 }
2988 return true
2989}
2990
Dan Albertc8060532020-07-22 22:32:17 -07002991func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
2992 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09002993 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
2994 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
2995 return nil
2996 }
2997 // b/154569636: set min_sdk_version correctly for toolchain_libraries
2998 if c.ToolchainLibrary() {
2999 return nil
3000 }
3001 // We don't check for prebuilt modules
3002 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3003 return nil
3004 }
3005 minSdkVersion := c.MinSdkVersion()
3006 if minSdkVersion == "apex_inherit" {
3007 return nil
3008 }
3009 if minSdkVersion == "" {
3010 // JNI libs within APK-in-APEX fall into here
3011 // Those are okay to set sdk_version instead
3012 // We don't have to check if this is a SDK variant because
3013 // non-SDK variant resets sdk_version, which works too.
3014 minSdkVersion = c.SdkVersion()
3015 }
Dan Albertc8060532020-07-22 22:32:17 -07003016 if minSdkVersion == "" {
3017 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3018 }
3019 // Not using nativeApiLevelFromUser because the context here is not
3020 // necessarily a native context.
3021 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003022 if err != nil {
3023 return err
3024 }
Dan Albertc8060532020-07-22 22:32:17 -07003025
3026 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003027 return fmt.Errorf("newer SDK(%v)", ver)
3028 }
3029 return nil
3030}
3031
Colin Cross2ba19d92015-05-07 15:44:20 -07003032//
Colin Crosscfad1192015-11-02 16:43:11 -08003033// Defaults
3034//
Colin Crossca860ac2016-01-04 14:34:37 -08003035type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003036 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003037 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003038 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003039}
3040
Patrice Arrudac249c712019-03-19 17:00:29 -07003041// cc_defaults provides a set of properties that can be inherited by other cc
3042// modules. A module can use the properties from a cc_defaults using
3043// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3044// merged (when possible) by prepending the default module's values to the
3045// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003046func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003047 return DefaultsFactory()
3048}
3049
Colin Cross36242852017-06-23 15:06:31 -07003050func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003051 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003052
Colin Cross36242852017-06-23 15:06:31 -07003053 module.AddProperties(props...)
3054 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003055 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003056 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003057 &BaseCompilerProperties{},
3058 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003059 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003060 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003061 &StaticProperties{},
3062 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003063 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003064 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003065 &TestProperties{},
3066 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003067 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003068 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003069 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003070 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003071 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003072 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003073 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003074 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003075 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003076 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003077 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003078 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003079 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003080 )
Colin Crosscfad1192015-11-02 16:43:11 -08003081
Jooyung Hancc372c52019-09-25 15:18:44 +09003082 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003083
3084 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003085}
3086
Jiyong Park6a43f042017-10-12 23:05:00 +09003087func squashVendorSrcs(m *Module) {
3088 if lib, ok := m.compiler.(*libraryDecorator); ok {
3089 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3090 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3091
3092 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3093 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003094
3095 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3096 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003097 }
3098}
3099
Jiyong Parkf9332f12018-02-01 00:54:12 +09003100func squashRecoverySrcs(m *Module) {
3101 if lib, ok := m.compiler.(*libraryDecorator); ok {
3102 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3103 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3104
3105 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3106 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003107
3108 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3109 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003110 }
3111}
3112
Jiyong Park2286afd2020-06-16 21:58:53 +09003113func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003114 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003115}
3116
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003117func kytheExtractAllFactory() android.Singleton {
3118 return &kytheExtractAllSingleton{}
3119}
3120
3121type kytheExtractAllSingleton struct {
3122}
3123
3124func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3125 var xrefTargets android.Paths
3126 ctx.VisitAllModules(func(module android.Module) {
3127 if ccModule, ok := module.(xref); ok {
3128 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3129 }
3130 })
3131 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3132 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003133 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003134 }
3135}
3136
Colin Cross06a931b2015-10-28 17:23:31 -07003137var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003138var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003139var BoolPtr = proptools.BoolPtr
3140var String = proptools.String
3141var StringPtr = proptools.StringPtr