blob: cef99eb2423e28cf8a351ff46e67ae10a7a35f21 [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
Colin Crossc472d572015-03-17 15:06:21 -0700213}
214
Colin Crossca860ac2016-01-04 14:34:37 -0800215// Properties used to compile all C or C++ modules
216type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700217 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800218 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700219
Colin Crossc511bc52020-04-07 16:50:32 +0000220 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
221 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800222 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700223
Jooyung Han379660c2020-04-21 15:24:00 +0900224 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
225 Min_sdk_version *string
226
Colin Crossc511bc52020-04-07 16:50:32 +0000227 // If true, always create an sdk variant and don't create a platform variant.
228 Sdk_variant_only *bool
229
Jiyong Parkde866cb2018-12-07 23:08:36 +0900230 AndroidMkSharedLibs []string `blueprint:"mutated"`
231 AndroidMkStaticLibs []string `blueprint:"mutated"`
232 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
233 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700234 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900235 HideFromMake bool `blueprint:"mutated"`
236 PreventInstall bool `blueprint:"mutated"`
237 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700238
Justin Yun5f7f7e82019-11-18 19:52:14 +0900239 ImageVariationPrefix string `blueprint:"mutated"`
240 VndkVersion string `blueprint:"mutated"`
241 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800242
243 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
244 // file
245 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900246
Yifan Hong1b3348d2020-01-21 15:53:22 -0800247 // Make this module available when building for ramdisk
248 Ramdisk_available *bool
249
Jiyong Parkf9332f12018-02-01 00:54:12 +0900250 // Make this module available when building for recovery
251 Recovery_available *bool
252
Colin Crossae6c5202019-11-20 13:35:50 -0800253 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800254 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800255 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800256 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900257 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900258
259 // Allows this module to use non-APEX version of libraries. Useful
260 // for building binaries that are started before APEXes are activated.
261 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900262
263 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
264 // see soong/cc/config/vndk.go
265 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900266
267 // Used by vendor snapshot to record dependencies from snapshot modules.
268 SnapshotSharedLibs []string `blueprint:"mutated"`
269 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000270
271 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000272
273 // Set by factories of module types that can only be referenced from variants compiled against
274 // the SDK.
275 AlwaysSdk bool `blueprint:"mutated"`
276
277 // Variant is an SDK variant created by sdkMutator
278 IsSdkVariant bool `blueprint:"mutated"`
279 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
280 // variant to have a ".sdk" suffix.
281 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700282}
283
284type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900285 // whether this module should be allowed to be directly depended by other
286 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900287 // In addition, this module should be allowed to be directly depended by
288 // product modules with `product_specific: true`.
289 // If set to true, three variants will be built separately, one like
290 // normal, another limited to the set of libraries and headers
291 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700292 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900293 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700294 // so it shouldn't have any unversioned runtime dependencies, or
295 // make assumptions about the system that may not be true in the
296 // future.
297 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900298 // If set to false, this module becomes inaccessible from /vendor or /product
299 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900300 //
301 // Default value is true when vndk: {enabled: true} or vendor: true.
302 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700303 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900304 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700305 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900306
307 // whether this module is capable of being loaded with other instance
308 // (possibly an older version) of the same module in the same process.
309 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
310 // can be double loaded in a vendor process if the library is also a
311 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
312 // explicitly marked as `double_loadable: true` by the owner, or the dependency
313 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
314 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800315}
316
Colin Crossca860ac2016-01-04 14:34:37 -0800317type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800318 static() bool
319 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900320 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900321 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900322 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700323 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900324 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700325 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800326 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700327 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800328 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900329 isLlndk(config android.Config) bool
330 isLlndkPublic(config android.Config) bool
331 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900332 isVndk() bool
333 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800334 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900335 inProduct() bool
336 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800337 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900338 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800339 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700340 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700341 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800342 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800343 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800344 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800345 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800346 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900347 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900348 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900349 hasStubsVariants() bool
350 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900351 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800352 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700353 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800354}
355
356type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700357 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800358 ModuleContextIntf
359}
360
361type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700362 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800363 ModuleContextIntf
364}
365
Colin Cross37047f12016-12-13 17:06:13 -0800366type DepsContext interface {
367 android.BottomUpMutatorContext
368 ModuleContextIntf
369}
370
Colin Crossca860ac2016-01-04 14:34:37 -0800371type feature interface {
372 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800373 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800374 flags(ctx ModuleContext, flags Flags) Flags
375 props() []interface{}
376}
377
378type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700379 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800380 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800381 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700382 compilerProps() []interface{}
383
Colin Cross76fada02016-07-27 10:31:13 -0700384 appendCflags([]string)
385 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700386 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800387}
388
389type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700390 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800391 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700392 linkerFlags(ctx ModuleContext, flags Flags) Flags
393 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800394 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700395
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700396 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700397 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900398 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700399
400 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900401 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000402
403 // Get the deps that have been explicitly specified in the properties.
404 // Only updates the
405 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
406}
407
408type specifiedDeps struct {
409 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000410 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800411}
412
413type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700414 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700415 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000416 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800417 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700418 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700419 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900420 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100421 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800422}
423
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800424type xref interface {
425 XrefCcFiles() android.Paths
426}
427
Colin Cross6e511a92020-07-27 21:26:48 -0700428type libraryDependencyKind int
429
430const (
431 headerLibraryDependency = iota
432 sharedLibraryDependency
433 staticLibraryDependency
434)
435
436func (k libraryDependencyKind) String() string {
437 switch k {
438 case headerLibraryDependency:
439 return "headerLibraryDependency"
440 case sharedLibraryDependency:
441 return "sharedLibraryDependency"
442 case staticLibraryDependency:
443 return "staticLibraryDependency"
444 default:
445 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
446 }
447}
448
449type libraryDependencyOrder int
450
451const (
452 earlyLibraryDependency = -1
453 normalLibraryDependency = 0
454 lateLibraryDependency = 1
455)
456
457func (o libraryDependencyOrder) String() string {
458 switch o {
459 case earlyLibraryDependency:
460 return "earlyLibraryDependency"
461 case normalLibraryDependency:
462 return "normalLibraryDependency"
463 case lateLibraryDependency:
464 return "lateLibraryDependency"
465 default:
466 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
467 }
468}
469
470// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
471// tags that have a set of predefined tag objects that are reused for each dependency, a
472// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
473// That means that comparing a libraryDependencyTag for equality will only be equal if all
474// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
475// then check individual metadata fields instead.
476type libraryDependencyTag struct {
477 blueprint.BaseDependencyTag
478
479 // These are exported so that fmt.Printf("%#v") can call their String methods.
480 Kind libraryDependencyKind
481 Order libraryDependencyOrder
482
483 wholeStatic bool
484
485 reexportFlags bool
486 explicitlyVersioned bool
487 dataLib bool
488 ndk bool
489
490 staticUnwinder bool
491
492 makeSuffix string
493}
494
495// header returns true if the libraryDependencyTag is tagging a header lib dependency.
496func (d libraryDependencyTag) header() bool {
497 return d.Kind == headerLibraryDependency
498}
499
500// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
501func (d libraryDependencyTag) shared() bool {
502 return d.Kind == sharedLibraryDependency
503}
504
505// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
506func (d libraryDependencyTag) static() bool {
507 return d.Kind == staticLibraryDependency
508}
509
510// dependencyTag is used for tagging miscellanous dependency types that don't fit into
511// libraryDependencyTag. Each tag object is created globally and reused for multiple
512// dependencies (although since the object contains no references, assigning a tag to a
513// variable and modifying it will not modify the original). Users can compare the tag
514// returned by ctx.OtherModuleDependencyTag against the global original
515type dependencyTag struct {
516 blueprint.BaseDependencyTag
517 name string
518}
519
Colin Crossc99deeb2016-04-11 15:06:20 -0700520var (
Colin Cross6e511a92020-07-27 21:26:48 -0700521 genSourceDepTag = dependencyTag{name: "gen source"}
522 genHeaderDepTag = dependencyTag{name: "gen header"}
523 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
524 objDepTag = dependencyTag{name: "obj"}
525 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
526 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
527 reuseObjTag = dependencyTag{name: "reuse objects"}
528 staticVariantTag = dependencyTag{name: "static variant"}
529 vndkExtDepTag = dependencyTag{name: "vndk extends"}
530 dataLibDepTag = dependencyTag{name: "data lib"}
531 runtimeDepTag = dependencyTag{name: "runtime lib"}
532 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700533)
534
Roland Levillainf89cd092019-07-29 16:22:59 +0100535func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700536 ccLibDepTag, ok := depTag.(libraryDependencyTag)
537 return ok && ccLibDepTag.shared()
538}
539
540func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
541 ccLibDepTag, ok := depTag.(libraryDependencyTag)
542 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100543}
544
545func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700546 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100547 return ok && ccDepTag == runtimeDepTag
548}
549
550func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700551 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100552 return ok && ccDepTag == testPerSrcDepTag
553}
554
Colin Crossca860ac2016-01-04 14:34:37 -0800555// Module contains the properties and members used by all C/C++ module types, and implements
556// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
557// to construct the output file. Behavior can be customized with a Customizer interface
558type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700559 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700560 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900561 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900562 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700563
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700564 Properties BaseProperties
565 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700566
Colin Crossca860ac2016-01-04 14:34:37 -0800567 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700568 hod android.HostOrDeviceSupported
569 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700570
Paul Duffina0843f62019-12-13 19:50:38 +0000571 // Allowable SdkMemberTypes of this module type.
572 sdkMemberTypes []android.SdkMemberType
573
Colin Crossca860ac2016-01-04 14:34:37 -0800574 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700575 features []feature
576 compiler compiler
577 linker linker
578 installer installer
579 stl *stl
580 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800581 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800582 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900583 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700584 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700585 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800586
Colin Cross635c3b02016-05-18 15:37:25 -0700587 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800588
Colin Crossb98c8b02016-07-29 13:44:28 -0700589 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700590
591 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800592
593 // Flags used to compile this module
594 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700595
596 // 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 -0800597 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700598 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800599 depsInLinkOrder android.Paths
600
601 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700602 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900603
604 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800605 // Kythe (source file indexer) paths for this compilation module
606 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900607
608 // For apex variants, this is set as apex.min_sdk_version
609 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700610}
611
Ivan Lozano52767be2019-10-18 14:49:46 -0700612func (c *Module) Toc() android.OptionalPath {
613 if c.linker != nil {
614 if library, ok := c.linker.(libraryInterface); ok {
615 return library.toc()
616 }
617 }
618 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
619}
620
621func (c *Module) ApiLevel() string {
622 if c.linker != nil {
623 if stub, ok := c.linker.(*stubDecorator); ok {
624 return stub.properties.ApiLevel
625 }
626 }
627 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
628}
629
630func (c *Module) Static() bool {
631 if c.linker != nil {
632 if library, ok := c.linker.(libraryInterface); ok {
633 return library.static()
634 }
635 }
636 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
637}
638
639func (c *Module) Shared() bool {
640 if c.linker != nil {
641 if library, ok := c.linker.(libraryInterface); ok {
642 return library.shared()
643 }
644 }
645 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
646}
647
648func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000649 if c.stl != nil {
650 return c.stl.Properties.SelectedStl
651 }
652 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700653}
654
655func (c *Module) ToolchainLibrary() bool {
656 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
657 return true
658 }
659 return false
660}
661
662func (c *Module) NdkPrebuiltStl() bool {
663 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
664 return true
665 }
666 return false
667}
668
669func (c *Module) StubDecorator() bool {
670 if _, ok := c.linker.(*stubDecorator); ok {
671 return true
672 }
673 return false
674}
675
676func (c *Module) SdkVersion() string {
677 return String(c.Properties.Sdk_version)
678}
679
Artur Satayev480e25b2020-04-27 18:53:18 +0100680func (c *Module) MinSdkVersion() string {
681 return String(c.Properties.Min_sdk_version)
682}
683
Dan Albert92fe7402020-07-15 13:33:30 -0700684func (c *Module) SplitPerApiLevel() bool {
685 if linker, ok := c.linker.(*objectLinker); ok {
686 return linker.isCrt()
687 }
688 return false
689}
690
Colin Crossc511bc52020-04-07 16:50:32 +0000691func (c *Module) AlwaysSdk() bool {
692 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
693}
694
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800695func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700696 if c.linker != nil {
697 if library, ok := c.linker.(exportedFlagsProducer); ok {
698 return library.exportedDirs()
699 }
700 }
701 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
702}
703
704func (c *Module) HasStaticVariant() bool {
705 if c.staticVariant != nil {
706 return true
707 }
708 return false
709}
710
711func (c *Module) GetStaticVariant() LinkableInterface {
712 return c.staticVariant
713}
714
715func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
716 c.depsInLinkOrder = depsInLinkOrder
717}
718
719func (c *Module) GetDepsInLinkOrder() []android.Path {
720 return c.depsInLinkOrder
721}
722
723func (c *Module) StubsVersions() []string {
724 if c.linker != nil {
725 if library, ok := c.linker.(*libraryDecorator); ok {
726 return library.Properties.Stubs.Versions
727 }
728 }
729 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
730}
731
732func (c *Module) CcLibrary() bool {
733 if c.linker != nil {
734 if _, ok := c.linker.(*libraryDecorator); ok {
735 return true
736 }
737 }
738 return false
739}
740
741func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700742 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700743 return true
744 }
745 return false
746}
747
Ivan Lozano2b262972019-11-21 12:30:50 -0800748func (c *Module) NonCcVariants() bool {
749 return false
750}
751
Ivan Lozano183a3212019-10-18 14:18:45 -0700752func (c *Module) SetBuildStubs() {
753 if c.linker != nil {
754 if library, ok := c.linker.(*libraryDecorator); ok {
755 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700756 c.Properties.HideFromMake = true
757 c.sanitize = nil
758 c.stl = nil
759 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700760 return
761 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000762 if _, ok := c.linker.(*llndkStubDecorator); ok {
763 c.Properties.HideFromMake = true
764 return
765 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700766 }
767 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
768}
769
Ivan Lozano52767be2019-10-18 14:49:46 -0700770func (c *Module) BuildStubs() bool {
771 if c.linker != nil {
772 if library, ok := c.linker.(*libraryDecorator); ok {
773 return library.buildStubs()
774 }
775 }
776 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
777}
778
Ivan Lozano183a3212019-10-18 14:18:45 -0700779func (c *Module) SetStubsVersions(version string) {
780 if c.linker != nil {
781 if library, ok := c.linker.(*libraryDecorator); ok {
782 library.MutatedProperties.StubsVersion = version
783 return
784 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000785 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
786 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
787 return
788 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700789 }
790 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
791}
792
Jooyung Han03b51852020-02-26 22:45:42 +0900793func (c *Module) StubsVersion() string {
794 if c.linker != nil {
795 if library, ok := c.linker.(*libraryDecorator); ok {
796 return library.MutatedProperties.StubsVersion
797 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000798 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
799 return llndk.libraryDecorator.MutatedProperties.StubsVersion
800 }
Jooyung Han03b51852020-02-26 22:45:42 +0900801 }
802 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
803}
804
Ivan Lozano183a3212019-10-18 14:18:45 -0700805func (c *Module) SetStatic() {
806 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700807 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700808 library.setStatic()
809 return
810 }
811 }
812 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
813}
814
815func (c *Module) SetShared() {
816 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700817 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700818 library.setShared()
819 return
820 }
821 }
822 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
823}
824
825func (c *Module) BuildStaticVariant() bool {
826 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700827 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700828 return library.buildStatic()
829 }
830 }
831 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
832}
833
834func (c *Module) BuildSharedVariant() bool {
835 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700836 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700837 return library.buildShared()
838 }
839 }
840 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
841}
842
843func (c *Module) Module() android.Module {
844 return c
845}
846
Jiyong Parkc20eee32018-09-05 22:36:17 +0900847func (c *Module) OutputFile() android.OptionalPath {
848 return c.outputFile
849}
850
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400851func (c *Module) CoverageFiles() android.Paths {
852 if c.linker != nil {
853 if library, ok := c.linker.(libraryInterface); ok {
854 return library.objs().coverageFiles
855 }
856 }
857 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
858}
859
Ivan Lozano183a3212019-10-18 14:18:45 -0700860var _ LinkableInterface = (*Module)(nil)
861
Jiyong Park719b4462019-01-13 00:39:51 +0900862func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900863 if c.linker != nil {
864 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900865 }
866 return nil
867}
868
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900869func (c *Module) CoverageOutputFile() android.OptionalPath {
870 if c.linker != nil {
871 return c.linker.coverageOutputFilePath()
872 }
873 return android.OptionalPath{}
874}
875
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900876func (c *Module) RelativeInstallPath() string {
877 if c.installer != nil {
878 return c.installer.relativeInstallPath()
879 }
880 return ""
881}
882
Jooyung Han344d5432019-08-23 11:17:39 +0900883func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900884 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900885}
886
Colin Cross36242852017-06-23 15:06:31 -0700887func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700888 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800889 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700890 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800891 }
892 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700893 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800894 }
895 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700896 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800897 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700898 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700899 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700900 }
Colin Cross16b23492016-01-06 14:41:07 -0800901 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700902 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800903 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800904 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700905 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800906 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800907 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700908 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800909 }
Justin Yun8effde42017-06-23 19:24:43 +0900910 if c.vndkdep != nil {
911 c.AddProperties(c.vndkdep.props()...)
912 }
Stephen Craneba090d12017-05-09 15:44:35 -0700913 if c.lto != nil {
914 c.AddProperties(c.lto.props()...)
915 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700916 if c.pgo != nil {
917 c.AddProperties(c.pgo.props()...)
918 }
Colin Crossca860ac2016-01-04 14:34:37 -0800919 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700920 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800921 }
Colin Crossc472d572015-03-17 15:06:21 -0700922
Colin Crossa9d8bee2018-10-02 13:59:46 -0700923 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700924 // Windows builds always prefer 32-bit
925 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700926 })
Colin Cross36242852017-06-23 15:06:31 -0700927 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900928 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900929 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900930 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900931
Colin Cross36242852017-06-23 15:06:31 -0700932 return c
Colin Crossc472d572015-03-17 15:06:21 -0700933}
934
Colin Crossb916a382016-07-29 17:28:03 -0700935// Returns true for dependency roots (binaries)
936// TODO(ccross): also handle dlopenable libraries
937func (c *Module) isDependencyRoot() bool {
938 if root, ok := c.linker.(interface {
939 isDependencyRoot() bool
940 }); ok {
941 return root.isDependencyRoot()
942 }
943 return false
944}
945
Justin Yun5f7f7e82019-11-18 19:52:14 +0900946// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
947// "product" and "vendor" variant modules return true for this function.
948// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
949// "soc_specific: true" and more vendor installed modules are included here.
950// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
951// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700952func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900953 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700954}
955
Colin Crossc511bc52020-04-07 16:50:32 +0000956func (c *Module) canUseSdk() bool {
957 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
958}
959
960func (c *Module) UseSdk() bool {
961 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -0700962 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +0000963 }
964 return false
965}
966
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800967func (c *Module) isCoverageVariant() bool {
968 return c.coverage.Properties.IsCoverageVariant
969}
970
Peter Collingbournead84f972019-12-17 16:46:18 -0800971func (c *Module) IsNdk() bool {
Dan Albertde5aade2020-06-30 12:32:51 -0700972 return inList(c.Name(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800973}
974
Inseob Kim9516ee92019-05-09 10:56:13 +0900975func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800976 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900977 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800978}
979
Inseob Kim9516ee92019-05-09 10:56:13 +0900980func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800981 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900982 name := c.BaseModuleName()
983 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800984}
985
Inseob Kim9516ee92019-05-09 10:56:13 +0900986func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800987 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900988 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800989}
990
Ivan Lozano52767be2019-10-18 14:49:46 -0700991func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800992 if vndkdep := c.vndkdep; vndkdep != nil {
993 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900994 }
995 return false
996}
997
Yi Kong7e53c572018-02-14 18:16:12 +0800998func (c *Module) isPgoCompile() bool {
999 if pgo := c.pgo; pgo != nil {
1000 return pgo.Properties.PgoCompile
1001 }
1002 return false
1003}
1004
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001005func (c *Module) isNDKStubLibrary() bool {
1006 if _, ok := c.compiler.(*stubDecorator); ok {
1007 return true
1008 }
1009 return false
1010}
1011
Logan Chienf3511742017-10-31 18:04:35 +08001012func (c *Module) isVndkSp() bool {
1013 if vndkdep := c.vndkdep; vndkdep != nil {
1014 return vndkdep.isVndkSp()
1015 }
1016 return false
1017}
1018
1019func (c *Module) isVndkExt() bool {
1020 if vndkdep := c.vndkdep; vndkdep != nil {
1021 return vndkdep.isVndkExt()
1022 }
1023 return false
1024}
1025
Ivan Lozano52767be2019-10-18 14:49:46 -07001026func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001027 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001028}
1029
Logan Chienf3511742017-10-31 18:04:35 +08001030func (c *Module) getVndkExtendsModuleName() string {
1031 if vndkdep := c.vndkdep; vndkdep != nil {
1032 return vndkdep.getVndkExtendsModuleName()
1033 }
1034 return ""
1035}
1036
Jiyong Park25fc6a92018-11-18 18:02:45 +09001037func (c *Module) IsStubs() bool {
1038 if library, ok := c.linker.(*libraryDecorator); ok {
1039 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001040 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1041 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001042 }
1043 return false
1044}
1045
1046func (c *Module) HasStubsVariants() bool {
1047 if library, ok := c.linker.(*libraryDecorator); ok {
1048 return len(library.Properties.Stubs.Versions) > 0
1049 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001050 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1051 return len(library.Properties.Stubs.Versions) > 0
1052 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001053 return false
1054}
1055
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001056func (c *Module) bootstrap() bool {
1057 return Bool(c.Properties.Bootstrap)
1058}
1059
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001060func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001061 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1062 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1063 return false
1064 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001065 return c.linker != nil && c.linker.nativeCoverage()
1066}
1067
Inseob Kim8471cda2019-11-15 09:59:12 +09001068func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001069 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1070 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001071 }
1072 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001073}
1074
Jiyong Park73c54ee2019-10-22 20:31:18 +09001075func (c *Module) ExportedIncludeDirs() android.Paths {
1076 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1077 return flagsProducer.exportedDirs()
1078 }
Jiyong Park232e7852019-11-04 12:23:40 +09001079 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001080}
1081
1082func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1083 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1084 return flagsProducer.exportedSystemDirs()
1085 }
Jiyong Park232e7852019-11-04 12:23:40 +09001086 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001087}
1088
1089func (c *Module) ExportedFlags() []string {
1090 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1091 return flagsProducer.exportedFlags()
1092 }
Jiyong Park232e7852019-11-04 12:23:40 +09001093 return nil
1094}
1095
1096func (c *Module) ExportedDeps() android.Paths {
1097 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1098 return flagsProducer.exportedDeps()
1099 }
1100 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001101}
1102
Inseob Kimd110f872019-12-06 13:15:38 +09001103func (c *Module) ExportedGeneratedHeaders() android.Paths {
1104 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1105 return flagsProducer.exportedGeneratedHeaders()
1106 }
1107 return nil
1108}
1109
Jiyong Parkf1194352019-02-25 11:05:47 +09001110func isBionic(name string) bool {
1111 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001112 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001113 return true
1114 }
1115 return false
1116}
1117
Martin Stjernholm279de572019-09-10 23:18:20 +01001118func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001119 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001120 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001121 }
1122 return isBionic(name)
1123}
1124
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001125func (c *Module) XrefCcFiles() android.Paths {
1126 return c.kytheFiles
1127}
1128
Colin Crossca860ac2016-01-04 14:34:37 -08001129type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001130 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001131 moduleContextImpl
1132}
1133
Colin Cross37047f12016-12-13 17:06:13 -08001134type depsContext struct {
1135 android.BottomUpMutatorContext
1136 moduleContextImpl
1137}
1138
Colin Crossca860ac2016-01-04 14:34:37 -08001139type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001140 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001141 moduleContextImpl
1142}
1143
1144type moduleContextImpl struct {
1145 mod *Module
1146 ctx BaseModuleContext
1147}
1148
Colin Crossb98c8b02016-07-29 13:44:28 -07001149func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001150 return ctx.mod.toolchain(ctx.ctx)
1151}
1152
1153func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001154 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001155}
1156
1157func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001158 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001159}
1160
Jiyong Park1d1119f2019-07-29 21:27:18 +09001161func (ctx *moduleContextImpl) header() bool {
1162 return ctx.mod.header()
1163}
1164
Inseob Kim7f283f42020-06-01 21:53:49 +09001165func (ctx *moduleContextImpl) binary() bool {
1166 return ctx.mod.binary()
1167}
1168
Inseob Kim1042d292020-06-01 23:23:05 +09001169func (ctx *moduleContextImpl) object() bool {
1170 return ctx.mod.object()
1171}
1172
Jooyung Hanccce2f22020-03-07 03:45:53 +09001173func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001174 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001175}
1176
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001177func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001178 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001179}
1180
1181func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001182 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001183 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001184 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001185 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001186 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001187 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001188 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001189 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001190 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001191 }
1192 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001193}
1194
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001195func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001196 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001197}
Justin Yun8effde42017-06-23 19:24:43 +09001198
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001199func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001200 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001201}
1202
Inseob Kim9516ee92019-05-09 10:56:13 +09001203func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1204 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001205}
1206
Inseob Kim9516ee92019-05-09 10:56:13 +09001207func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1208 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001209}
1210
Inseob Kim9516ee92019-05-09 10:56:13 +09001211func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1212 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001213}
1214
Logan Chienf3511742017-10-31 18:04:35 +08001215func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001216 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001217}
1218
Yi Kong7e53c572018-02-14 18:16:12 +08001219func (ctx *moduleContextImpl) isPgoCompile() bool {
1220 return ctx.mod.isPgoCompile()
1221}
1222
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001223func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1224 return ctx.mod.isNDKStubLibrary()
1225}
1226
Justin Yun8effde42017-06-23 19:24:43 +09001227func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001228 return ctx.mod.isVndkSp()
1229}
1230
1231func (ctx *moduleContextImpl) isVndkExt() bool {
1232 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001233}
1234
Vic Yangefd249e2018-11-12 20:19:56 -08001235func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001236 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001237}
1238
Logan Chien2f2b8902018-07-10 15:01:19 +08001239// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001240func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001241 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1242 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001243 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001244
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001245 // Coverage builds have extra symbols.
1246 if ctx.mod.isCoverageVariant() {
1247 return false
1248 }
1249
Doug Hornc32c6b02019-01-17 14:44:05 -08001250 if ctx.ctx.Fuchsia() {
1251 return false
1252 }
1253
Logan Chien2f2b8902018-07-10 15:01:19 +08001254 if sanitize := ctx.mod.sanitize; sanitize != nil {
1255 if !sanitize.isVariantOnProductionDevice() {
1256 return false
1257 }
1258 }
1259 if !ctx.ctx.Device() {
1260 // Host modules do not need ABI dumps.
1261 return false
1262 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001263 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001264 // Stubs do not need ABI dumps.
1265 return false
1266 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001267 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001268}
1269
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001270func (ctx *moduleContextImpl) selectedStl() string {
1271 if stl := ctx.mod.stl; stl != nil {
1272 return stl.Properties.SelectedStl
1273 }
1274 return ""
1275}
1276
Ivan Lozanobd721262018-11-27 14:33:03 -08001277func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1278 return ctx.mod.linker.useClangLld(actx)
1279}
1280
Colin Crossce75d2c2016-10-06 16:12:58 -07001281func (ctx *moduleContextImpl) baseModuleName() string {
1282 return ctx.mod.ModuleBase.BaseModuleName()
1283}
1284
Logan Chienf3511742017-10-31 18:04:35 +08001285func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1286 return ctx.mod.getVndkExtendsModuleName()
1287}
1288
Logan Chiene274fc92019-12-03 11:18:32 -08001289func (ctx *moduleContextImpl) isForPlatform() bool {
1290 return ctx.mod.IsForPlatform()
1291}
1292
Jiyong Park58e364a2019-01-19 19:24:06 +09001293func (ctx *moduleContextImpl) apexName() string {
1294 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001295}
1296
Jooyung Hanccce2f22020-03-07 03:45:53 +09001297func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001298 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001299}
1300
Jiyong Parkb0788572018-12-20 22:10:17 +09001301func (ctx *moduleContextImpl) hasStubsVariants() bool {
1302 return ctx.mod.HasStubsVariants()
1303}
1304
1305func (ctx *moduleContextImpl) isStubs() bool {
1306 return ctx.mod.IsStubs()
1307}
1308
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001309func (ctx *moduleContextImpl) bootstrap() bool {
1310 return ctx.mod.bootstrap()
1311}
1312
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001313func (ctx *moduleContextImpl) nativeCoverage() bool {
1314 return ctx.mod.nativeCoverage()
1315}
1316
Colin Cross635c3b02016-05-18 15:37:25 -07001317func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001318 return &Module{
1319 hod: hod,
1320 multilib: multilib,
1321 }
1322}
1323
Colin Cross635c3b02016-05-18 15:37:25 -07001324func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001325 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001326 module.features = []feature{
1327 &tidyFeature{},
1328 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001329 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001330 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001331 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001332 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001333 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001334 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001335 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001336 return module
1337}
1338
Colin Crossce75d2c2016-10-06 16:12:58 -07001339func (c *Module) Prebuilt() *android.Prebuilt {
1340 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1341 return p.prebuilt()
1342 }
1343 return nil
1344}
1345
1346func (c *Module) Name() string {
1347 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001348 if p, ok := c.linker.(interface {
1349 Name(string) string
1350 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001351 name = p.Name(name)
1352 }
1353 return name
1354}
1355
Alex Light3d673592019-01-18 14:37:31 -08001356func (c *Module) Symlinks() []string {
1357 if p, ok := c.installer.(interface {
1358 symlinkList() []string
1359 }); ok {
1360 return p.symlinkList()
1361 }
1362 return nil
1363}
1364
Jeff Gaston294356f2017-09-27 17:05:30 -07001365// orderDeps reorders dependencies into a list such that if module A depends on B, then
1366// A will precede B in the resultant list.
1367// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001368// Note that directSharedDeps should be the analogous static library for each shared lib dep
1369func 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 -07001370 // If A depends on B, then
1371 // Every list containing A will also contain B later in the list
1372 // So, after concatenating all lists, the final instance of B will have come from the same
1373 // original list as the final instance of A
1374 // So, the final instance of B will be later in the concatenation than the final A
1375 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1376 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001377 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001378 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001379 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1380 }
1381 for _, dep := range directSharedDeps {
1382 orderedAllDeps = append(orderedAllDeps, dep)
1383 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001384 }
1385
Colin Crossb6715442017-10-24 11:13:31 -07001386 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001387
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001388 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001389 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001390 // resultant list to only what the caller has chosen to include in directStaticDeps
1391 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001392
1393 return orderedAllDeps, orderedDeclaredDeps
1394}
1395
Ivan Lozano183a3212019-10-18 14:18:45 -07001396func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001397 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001398 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001399 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1400 staticDepFiles := []android.Path{}
1401 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001402 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1403 if dep.OutputFile().Valid() {
1404 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1405 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1406 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001407 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001408 sharedDepFiles := []android.Path{}
1409 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001410 if sharedDep.HasStaticVariant() {
1411 staticAnalogue := sharedDep.GetStaticVariant()
1412 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1413 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001414 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001415 }
1416
1417 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001418 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1419 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001420
1421 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001422}
1423
Roland Levillainf89cd092019-07-29 16:22:59 +01001424func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1425 test, ok := c.linker.(testPerSrc)
1426 return ok && test.isAllTestsVariation()
1427}
1428
Chris Parsons216e10a2020-07-09 17:12:52 -04001429func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001430 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001431 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001432 }); ok {
1433 return p.dataPaths()
1434 }
1435 return nil
1436}
1437
Justin Yun5f7f7e82019-11-18 19:52:14 +09001438func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1439 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1440 // "current", it will append the VNDK version to the name suffix.
1441 var vndkVersion string
1442 var nameSuffix string
1443 if c.inProduct() {
1444 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1445 nameSuffix = productSuffix
1446 } else {
1447 vndkVersion = ctx.DeviceConfig().VndkVersion()
1448 nameSuffix = vendorSuffix
1449 }
1450 if vndkVersion == "current" {
1451 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1452 }
1453 if c.Properties.VndkVersion != vndkVersion {
1454 // add version suffix only if the module is using different vndk version than the
1455 // version in product or vendor partition.
1456 nameSuffix += "." + c.Properties.VndkVersion
1457 }
1458 return nameSuffix
1459}
1460
Colin Cross635c3b02016-05-18 15:37:25 -07001461func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001462 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001463 //
1464 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1465 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1466 // module and return early, as this module does not produce an output file per se.
1467 if c.IsTestPerSrcAllTestsVariation() {
1468 c.outputFile = android.OptionalPath{}
1469 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001470 }
1471
Jooyung Han38002912019-05-16 04:01:54 +09001472 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001473
Inseob Kim64c43952019-08-26 16:52:35 +09001474 c.Properties.SubName = ""
1475
1476 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1477 c.Properties.SubName += nativeBridgeSuffix
1478 }
1479
Justin Yun5f7f7e82019-11-18 19:52:14 +09001480 _, llndk := c.linker.(*llndkStubDecorator)
1481 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1482 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1483 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1484 // added for product variant only when we have vendor and product variants with core
1485 // variant. The suffix is not added for vendor-only or product-only module.
1486 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1487 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001488 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1489 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1490 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001491 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1492 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001493 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001494 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001495 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001496 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001497 if c.SplitPerApiLevel() {
1498 c.Properties.SubName += "." + c.SdkVersion()
1499 }
Inseob Kim64c43952019-08-26 16:52:35 +09001500 }
1501
Colin Crossca860ac2016-01-04 14:34:37 -08001502 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001503 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001504 moduleContextImpl: moduleContextImpl{
1505 mod: c,
1506 },
1507 }
1508 ctx.ctx = ctx
1509
Colin Crossf18e1102017-11-16 14:33:08 -08001510 deps := c.depsToPaths(ctx)
1511 if ctx.Failed() {
1512 return
1513 }
1514
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001515 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1516 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1517 }
1518
Colin Crossca860ac2016-01-04 14:34:37 -08001519 flags := Flags{
1520 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001521 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001522 }
Colin Crossca860ac2016-01-04 14:34:37 -08001523 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001524 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001525 }
1526 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001527 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001528 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001529 if c.stl != nil {
1530 flags = c.stl.flags(ctx, flags)
1531 }
Colin Cross16b23492016-01-06 14:41:07 -08001532 if c.sanitize != nil {
1533 flags = c.sanitize.flags(ctx, flags)
1534 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001535 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001536 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001537 }
Stephen Craneba090d12017-05-09 15:44:35 -07001538 if c.lto != nil {
1539 flags = c.lto.flags(ctx, flags)
1540 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001541 if c.pgo != nil {
1542 flags = c.pgo.flags(ctx, flags)
1543 }
Colin Crossca860ac2016-01-04 14:34:37 -08001544 for _, feature := range c.features {
1545 flags = feature.flags(ctx, flags)
1546 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001547 if ctx.Failed() {
1548 return
1549 }
1550
Colin Cross4af21ed2019-11-04 09:37:55 -08001551 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1552 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1553 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001554
Colin Cross4af21ed2019-11-04 09:37:55 -08001555 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001556
1557 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001558 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001559 }
1560 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001561 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001562 }
1563
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001564 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001565 // We need access to all the flags seen by a source file.
1566 if c.sabi != nil {
1567 flags = c.sabi.flags(ctx, flags)
1568 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001569
Colin Cross4af21ed2019-11-04 09:37:55 -08001570 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001571
Colin Crossca860ac2016-01-04 14:34:37 -08001572 // Optimization to reduce size of build.ninja
1573 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001574 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1575 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1576 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1577 flags.Local.CFlags = []string{"$cflags"}
1578 flags.Local.CppFlags = []string{"$cppflags"}
1579 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001580
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001581 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001582 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001583 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001584 if ctx.Failed() {
1585 return
1586 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001587 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001588 }
1589
Colin Crossca860ac2016-01-04 14:34:37 -08001590 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001591 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001592 if ctx.Failed() {
1593 return
1594 }
Colin Cross635c3b02016-05-18 15:37:25 -07001595 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001596
1597 // If a lib is directly included in any of the APEXes, unhide the stubs
1598 // variant having the latest version gets visible to make. In addition,
1599 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1600 // force anything in the make world to link against the stubs library.
1601 // (unless it is explicitly referenced via .bootstrap suffix or the
1602 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001603 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001604 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001605 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001606 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001607 c.Properties.HideFromMake = false // unhide
1608 // Note: this is still non-installable
1609 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001610
1611 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1612 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1613 if isSnapshotAware(ctx, c) {
1614 i.collectHeadersForSnapshot(ctx)
1615 }
1616 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001617 }
Colin Cross5049f022015-03-18 13:28:46 -07001618
Inseob Kim1f086e22019-05-09 13:29:15 +09001619 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001620 c.installer.install(ctx, c.outputFile.Path())
1621 if ctx.Failed() {
1622 return
Colin Crossca860ac2016-01-04 14:34:37 -08001623 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001624 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1625 // If the module has been specifically configure to not be installed then
1626 // skip the installation as otherwise it will break when running inside make
1627 // as the output path to install will not be specified. Not all uninstallable
1628 // modules can skip installation as some are needed for resolving make side
1629 // dependencies.
1630 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001631 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001632}
1633
Colin Cross0ea8ba82019-06-06 14:33:29 -07001634func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001635 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001636 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001637 }
Colin Crossca860ac2016-01-04 14:34:37 -08001638 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001639}
1640
Colin Crossca860ac2016-01-04 14:34:37 -08001641func (c *Module) begin(ctx BaseModuleContext) {
1642 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001643 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001644 }
Colin Crossca860ac2016-01-04 14:34:37 -08001645 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001646 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001647 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001648 if c.stl != nil {
1649 c.stl.begin(ctx)
1650 }
Colin Cross16b23492016-01-06 14:41:07 -08001651 if c.sanitize != nil {
1652 c.sanitize.begin(ctx)
1653 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001654 if c.coverage != nil {
1655 c.coverage.begin(ctx)
1656 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001657 if c.sabi != nil {
1658 c.sabi.begin(ctx)
1659 }
Justin Yun8effde42017-06-23 19:24:43 +09001660 if c.vndkdep != nil {
1661 c.vndkdep.begin(ctx)
1662 }
Stephen Craneba090d12017-05-09 15:44:35 -07001663 if c.lto != nil {
1664 c.lto.begin(ctx)
1665 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001666 if c.pgo != nil {
1667 c.pgo.begin(ctx)
1668 }
Colin Crossca860ac2016-01-04 14:34:37 -08001669 for _, feature := range c.features {
1670 feature.begin(ctx)
1671 }
Dan Albert92fe7402020-07-15 13:33:30 -07001672 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albertf5415d72017-08-17 16:19:59 -07001673 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001674 if err != nil {
1675 ctx.PropertyErrorf("sdk_version", err.Error())
1676 }
Nan Zhang0007d812017-11-07 10:57:05 -08001677 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001678 }
Colin Crossca860ac2016-01-04 14:34:37 -08001679}
1680
Colin Cross37047f12016-12-13 17:06:13 -08001681func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001682 deps := Deps{}
1683
1684 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001685 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001686 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001687 // Add the PGO dependency (the clang_rt.profile runtime library), which
1688 // sometimes depends on symbols from libgcc, before libgcc gets added
1689 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001690 if c.pgo != nil {
1691 deps = c.pgo.deps(ctx, deps)
1692 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001693 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001694 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001695 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001696 if c.stl != nil {
1697 deps = c.stl.deps(ctx, deps)
1698 }
Colin Cross16b23492016-01-06 14:41:07 -08001699 if c.sanitize != nil {
1700 deps = c.sanitize.deps(ctx, deps)
1701 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001702 if c.coverage != nil {
1703 deps = c.coverage.deps(ctx, deps)
1704 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001705 if c.sabi != nil {
1706 deps = c.sabi.deps(ctx, deps)
1707 }
Justin Yun8effde42017-06-23 19:24:43 +09001708 if c.vndkdep != nil {
1709 deps = c.vndkdep.deps(ctx, deps)
1710 }
Stephen Craneba090d12017-05-09 15:44:35 -07001711 if c.lto != nil {
1712 deps = c.lto.deps(ctx, deps)
1713 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001714 for _, feature := range c.features {
1715 deps = feature.deps(ctx, deps)
1716 }
1717
Colin Crossb6715442017-10-24 11:13:31 -07001718 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1719 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1720 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1721 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1722 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1723 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001724 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001725
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001726 for _, lib := range deps.ReexportSharedLibHeaders {
1727 if !inList(lib, deps.SharedLibs) {
1728 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1729 }
1730 }
1731
1732 for _, lib := range deps.ReexportStaticLibHeaders {
1733 if !inList(lib, deps.StaticLibs) {
1734 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1735 }
1736 }
1737
Colin Cross5950f382016-12-13 12:50:57 -08001738 for _, lib := range deps.ReexportHeaderLibHeaders {
1739 if !inList(lib, deps.HeaderLibs) {
1740 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1741 }
1742 }
1743
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001744 for _, gen := range deps.ReexportGeneratedHeaders {
1745 if !inList(gen, deps.GeneratedHeaders) {
1746 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1747 }
1748 }
1749
Colin Crossc99deeb2016-04-11 15:06:20 -07001750 return deps
1751}
1752
Dan Albert7e9d2952016-08-04 13:02:36 -07001753func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001754 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001755 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001756 moduleContextImpl: moduleContextImpl{
1757 mod: c,
1758 },
1759 }
1760 ctx.ctx = ctx
1761
Colin Crossca860ac2016-01-04 14:34:37 -08001762 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001763}
1764
Jiyong Park7ed9de32018-10-15 22:25:07 +09001765// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001766func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001767 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1768 version := name[sharp+1:]
1769 libname := name[:sharp]
1770 return libname, version
1771 }
1772 return name, ""
1773}
1774
Dan Albert92fe7402020-07-15 13:33:30 -07001775func GetCrtVariations(ctx android.BottomUpMutatorContext,
1776 m LinkableInterface) []blueprint.Variation {
1777 if ctx.Os() != android.Android {
1778 return nil
1779 }
1780 if m.UseSdk() {
1781 return []blueprint.Variation{
1782 {Mutator: "sdk", Variation: "sdk"},
1783 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1784 }
1785 }
1786 return []blueprint.Variation{
1787 {Mutator: "sdk", Variation: ""},
1788 }
1789}
1790
Colin Cross1e676be2016-10-12 14:38:15 -07001791func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001792 if !c.Enabled() {
1793 return
1794 }
1795
Colin Cross37047f12016-12-13 17:06:13 -08001796 ctx := &depsContext{
1797 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001798 moduleContextImpl: moduleContextImpl{
1799 mod: c,
1800 },
1801 }
1802 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001803
Colin Crossc99deeb2016-04-11 15:06:20 -07001804 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001805
Dan Albert914449f2016-06-17 16:45:24 -07001806 variantNdkLibs := []string{}
1807 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001808 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001809 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001810 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001811 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001812 // 1. Name of an NDK library that refers to a prebuilt module.
1813 // For each of these, it adds the name of the prebuilt module (which will be in
1814 // prebuilts/ndk) to the list of nonvariant libs.
1815 // 2. Name of an NDK library that refers to an ndk_library module.
1816 // For each of these, it adds the name of the ndk_library module to the list of
1817 // variant libs.
1818 // 3. Anything else (so anything that isn't an NDK library).
1819 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001820 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001821 // The caller can then know to add the variantLibs dependencies differently from the
1822 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001823
Inseob Kim9516ee92019-05-09 10:56:13 +09001824 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001825 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1826
1827 rewriteVendorLibs := func(lib string) string {
1828 if isLlndkLibrary(lib, ctx.Config()) {
1829 return lib + llndkLibrarySuffix
1830 }
1831
1832 // only modules with BOARD_VNDK_VERSION uses snapshot.
1833 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1834 return lib
1835 }
1836
1837 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1838 return snapshot
1839 }
1840
1841 return lib
1842 }
1843
1844 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001845 variantLibs = []string{}
1846 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001847 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001848 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001849 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001850 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1851 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001852 } else if ctx.useVndk() {
1853 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001854 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001855 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001856 if actx.OtherModuleExists(vendorPublicLib) {
1857 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1858 } else {
1859 // This can happen if vendor_public_library module is defined in a
1860 // namespace that isn't visible to the current module. In that case,
1861 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001862 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001863 }
Dan Albert914449f2016-06-17 16:45:24 -07001864 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001865 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001866 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001867 }
1868 }
Dan Albert914449f2016-06-17 16:45:24 -07001869 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001870 }
1871
Inseob Kimeec88e12020-01-22 11:11:29 +09001872 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1873 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1874 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1875 if ctx.useVndk() {
1876 for idx, lib := range deps.RuntimeLibs {
1877 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1878 }
1879 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001880 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001881
Jiyong Park7e636d02019-01-28 16:16:54 +09001882 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001883 if c.linker != nil {
1884 if library, ok := c.linker.(*libraryDecorator); ok {
1885 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001886 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001887 }
1888 }
1889 }
1890
Inseob Kimeec88e12020-01-22 11:11:29 +09001891 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1892 // only modules with BOARD_VNDK_VERSION uses snapshot.
1893 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1894 return lib
1895 }
1896
1897 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1898 return snapshot
1899 }
1900
1901 return lib
1902 }
1903
1904 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001905 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001906 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001907 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001908 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001909 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001910
1911 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1912
Jiyong Park7e636d02019-01-28 16:16:54 +09001913 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001914 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001915 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001916 } else {
1917 actx.AddVariationDependencies(nil, depTag, lib)
1918 }
1919 }
1920
1921 if buildStubs {
1922 // Stubs lib does not have dependency to other static/shared libraries.
1923 // Don't proceed.
1924 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001925 }
Colin Cross5950f382016-12-13 12:50:57 -08001926
Inseob Kimc0907f12019-02-08 21:00:45 +09001927 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001928 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001929
Jiyong Park5d1598f2019-02-25 22:14:17 +09001930 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001931 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001932 if impl, ok := syspropImplLibraries[lib]; ok {
1933 lib = impl
1934 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001935
1936 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1937
Jiyong Park5d1598f2019-02-25 22:14:17 +09001938 actx.AddVariationDependencies([]blueprint.Variation{
1939 {Mutator: "link", Variation: "static"},
1940 }, depTag, lib)
1941 }
1942
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001943 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001944 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001945 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001946 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001947 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001948
1949 if impl, ok := syspropImplLibraries[lib]; ok {
1950 lib = impl
1951 }
1952
Inseob Kimeec88e12020-01-22 11:11:29 +09001953 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1954
Dan Willemsen59339a22018-07-22 21:18:45 -07001955 actx.AddVariationDependencies([]blueprint.Variation{
1956 {Mutator: "link", Variation: "static"},
1957 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001958 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001959
Jooyung Han75568392020-03-20 04:29:24 +09001960 // staticUnwinderDep is treated as staticDep for Q apexes
1961 // so that native libraries/binaries are linked with static unwinder
1962 // because Q libc doesn't have unwinder APIs
1963 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001964 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001965 actx.AddVariationDependencies([]blueprint.Variation{
1966 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001967 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001968 }
1969
Inseob Kimeec88e12020-01-22 11:11:29 +09001970 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001971 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001972 actx.AddVariationDependencies([]blueprint.Variation{
1973 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001974 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001975 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001976
Colin Cross6e511a92020-07-27 21:26:48 -07001977 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001978 var variations []blueprint.Variation
1979 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001980 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001981 // Version is explicitly specified. i.e. libFoo#30
1982 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07001983 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001984 }
1985 actx.AddVariationDependencies(variations, depTag, name)
1986
Jooyung Han03b51852020-02-26 22:45:42 +09001987 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001988 // The stubs library will be used when the depending module is built for APEX and
1989 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09001990 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09001991 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1992 // Note that depTag.ExplicitlyVersioned is false in this case.
1993 actx.AddVariationDependencies([]blueprint.Variation{
1994 {Mutator: "link", Variation: "shared"},
1995 {Mutator: "version", Variation: ver},
1996 }, depTag, name)
1997 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001998 }
1999 }
2000
Jiyong Park7ed9de32018-10-15 22:25:07 +09002001 // shared lib names without the #version suffix
2002 var sharedLibNames []string
2003
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002004 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002005 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002006 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002007 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002008 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002009
2010 if impl, ok := syspropImplLibraries[lib]; ok {
2011 lib = impl
2012 }
2013
Jiyong Park73c54ee2019-10-22 20:31:18 +09002014 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002015 sharedLibNames = append(sharedLibNames, name)
2016
Jiyong Park25fc6a92018-11-18 18:02:45 +09002017 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002018 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002019
Jiyong Park7ed9de32018-10-15 22:25:07 +09002020 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002021 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002022 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2023 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2024 // linking against both the stubs lib and the non-stubs lib at the same time.
2025 continue
2026 }
Colin Cross6e511a92020-07-27 21:26:48 -07002027 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2028 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002029 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002030
Dan Willemsen59339a22018-07-22 21:18:45 -07002031 actx.AddVariationDependencies([]blueprint.Variation{
2032 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002033 }, dataLibDepTag, deps.DataLibs...)
2034
2035 actx.AddVariationDependencies([]blueprint.Variation{
2036 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002037 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002038
Colin Cross68861832016-07-08 10:41:41 -07002039 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002040
2041 for _, gen := range deps.GeneratedHeaders {
2042 depTag := genHeaderDepTag
2043 if inList(gen, deps.ReexportGeneratedHeaders) {
2044 depTag = genHeaderExportDepTag
2045 }
2046 actx.AddDependency(c, depTag, gen)
2047 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002048
Colin Cross42d48b72018-08-29 14:10:52 -07002049 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002050
Inseob Kim1042d292020-06-01 23:23:05 +09002051 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2052
Dan Albert92fe7402020-07-15 13:33:30 -07002053 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002054 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002055 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2056 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002057 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002058 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002059 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2060 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002061 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002062 if deps.LinkerFlagsFile != "" {
2063 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2064 }
2065 if deps.DynamicLinker != "" {
2066 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002067 }
Dan Albert914449f2016-06-17 16:45:24 -07002068
2069 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002070
2071 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002072 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002073 {Mutator: "ndk_api", Variation: version},
2074 {Mutator: "link", Variation: "shared"},
2075 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002076
2077 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002078 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002079 {Mutator: "ndk_api", Variation: version},
2080 {Mutator: "link", Variation: "shared"},
2081 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002082
2083 if vndkdep := c.vndkdep; vndkdep != nil {
2084 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002085 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002086 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002087 {Mutator: "link", Variation: "shared"},
2088 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002089 }
2090 }
Colin Cross6362e272015-10-29 15:25:03 -07002091}
Colin Cross21b9a242015-03-24 14:15:58 -07002092
Colin Crosse40b4ea2018-10-02 22:25:58 -07002093func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002094 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2095 c.beginMutator(ctx)
2096 }
2097}
2098
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002099// Whether a module can link to another module, taking into
2100// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002101func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2102 tag blueprint.DependencyTag) {
2103
2104 switch t := tag.(type) {
2105 case dependencyTag:
2106 if t != vndkExtDepTag {
2107 return
2108 }
2109 case libraryDependencyTag:
2110 default:
2111 return
2112 }
2113
Ivan Lozano52767be2019-10-18 14:49:46 -07002114 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002115 // Host code is not restricted
2116 return
2117 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002118
2119 // VNDK is cc.Module supported only for now.
2120 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002121 // Though vendor code is limited by the vendor mutator,
2122 // each vendor-available module needs to check
2123 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002124 if ccTo, ok := to.(*Module); ok {
2125 if ccFrom.vndkdep != nil {
2126 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2127 }
2128 } else {
2129 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002130 }
2131 return
2132 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002133 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002134 // Platform code can link to anything
2135 return
2136 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002137 if from.InRamdisk() {
2138 // Ramdisk code is not NDK
2139 return
2140 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002141 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002142 // Recovery code is not NDK
2143 return
2144 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002145 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002146 // These are always allowed
2147 return
2148 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002149 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002150 // These are allowed, but they don't set sdk_version
2151 return
2152 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002153 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 // These aren't real libraries, but are the stub shared libraries that are included in
2155 // the NDK.
2156 return
2157 }
Logan Chien834b9a62019-01-14 15:39:03 +08002158
Ivan Lozano52767be2019-10-18 14:49:46 -07002159 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002160 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2161 // to link to libc++ (non-NDK and without sdk_version).
2162 return
2163 }
2164
Ivan Lozano52767be2019-10-18 14:49:46 -07002165 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002166 // NDK code linking to platform code is never okay.
2167 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002168 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002169 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 }
2171
2172 // At this point we know we have two NDK libraries, but we need to
2173 // check that we're not linking against anything built against a higher
2174 // API level, as it is only valid to link against older or equivalent
2175 // APIs.
2176
Inseob Kim01a28722018-04-11 09:48:45 +09002177 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002178 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002179 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002180 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002181 // Current can't be linked against by anything else.
2182 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002183 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002184 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002185 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002186 if err != nil {
2187 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002188 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002189 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002190 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002191 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002192 if err != nil {
2193 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002194 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002195 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002196 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002197
Inseob Kim01a28722018-04-11 09:48:45 +09002198 if toApi > fromApi {
2199 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002200 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002201 }
2202 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002203 }
Dan Albert202fe492017-12-15 13:56:59 -08002204
2205 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002206 fromStl := from.SelectedStl()
2207 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002208 if fromStl == "" || toStl == "" {
2209 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002210 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002211 // We can be permissive with the system "STL" since it is only the C++
2212 // ABI layer, but in the future we should make sure that everyone is
2213 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002214 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002215 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002216 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2217 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002218 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002219}
2220
Jiyong Park5fb8c102018-04-09 12:03:06 +09002221// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002222// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2223// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002224// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002225func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2226 check := func(child, parent android.Module) bool {
2227 to, ok := child.(*Module)
2228 if !ok {
2229 // follow thru cc.Defaults, etc.
2230 return true
2231 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002232
Jooyung Hana70f0672019-01-18 15:20:43 +09002233 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2234 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002235 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002236
2237 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002238 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002239 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002240 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002241
Jooyung Han0302a842019-10-30 18:43:49 +09002242 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002243 return false
2244 }
2245
2246 var stringPath []string
2247 for _, m := range ctx.GetWalkPath() {
2248 stringPath = append(stringPath, m.Name())
2249 }
2250 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2251 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2252 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2253 return false
2254 }
2255 if module, ok := ctx.Module().(*Module); ok {
2256 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002257 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002258 ctx.WalkDeps(check)
2259 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002260 }
2261 }
2262}
2263
Colin Crossc99deeb2016-04-11 15:06:20 -07002264// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002265func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002266 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002267
Ivan Lozano183a3212019-10-18 14:18:45 -07002268 directStaticDeps := []LinkableInterface{}
2269 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002270
Inseob Kim69378442019-06-03 19:10:47 +09002271 reexportExporter := func(exporter exportedFlagsProducer) {
2272 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2273 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2274 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2275 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002276 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002277 }
2278
Jooyung Hande34d232020-07-23 13:04:15 +09002279 // For the dependency from platform to apex, use the latest stubs
2280 c.apexSdkVersion = android.FutureApiLevel
2281 if !c.IsForPlatform() {
2282 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2283 }
2284
2285 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2286 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2287 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2288 // (b/144430859)
2289 c.apexSdkVersion = android.FutureApiLevel
2290 }
2291
Colin Crossd11fcda2017-10-23 17:59:01 -07002292 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002293 depName := ctx.OtherModuleName(dep)
2294 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002295
Ivan Lozano52767be2019-10-18 14:49:46 -07002296 ccDep, ok := dep.(LinkableInterface)
2297 if !ok {
2298
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002299 // handling for a few module types that aren't cc Module but that are also supported
2300 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002301 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002302 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002303 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2304 genRule.GeneratedSourceFiles()...)
2305 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002306 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002307 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002308 // Support exported headers from a generated_sources dependency
2309 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002310 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002311 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002312 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002313 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002314 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002315 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002316 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002317 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002318 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2319 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002320 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002321 // 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 +09002322 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002323
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002324 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002325 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002326 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002327 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002328 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002329 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002330 files := genRule.GeneratedSourceFiles()
2331 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002332 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002333 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002334 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 -07002335 }
2336 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002337 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002338 }
Colin Crossca860ac2016-01-04 14:34:37 -08002339 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002340 return
2341 }
2342
Colin Crossfe17f6f2019-03-28 19:30:56 -07002343 if depTag == android.ProtoPluginDepTag {
2344 return
2345 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002346 if depTag == llndkImplDep {
2347 return
2348 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002349
Colin Crossd11fcda2017-10-23 17:59:01 -07002350 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002351 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2352 return
2353 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002354 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002355 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2356 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002357 return
2358 }
2359
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002360 // re-exporting flags
2361 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002362 // reusing objects only make sense for cc.Modules.
2363 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002364 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002365 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002366 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002367 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002368 return
2369 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002370 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002371
Jiyong Parke4bb9862019-02-01 00:31:10 +09002372 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002373 // staticVariants are a cc.Module specific concept.
2374 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002375 c.staticVariant = ccDep
2376 return
2377 }
2378 }
2379
Colin Cross6e511a92020-07-27 21:26:48 -07002380 checkLinkType(ctx, c, ccDep, depTag)
2381
2382 linkFile := ccDep.OutputFile()
2383
2384 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2385 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2386 if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002387 return
2388 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002389
Colin Cross6e511a92020-07-27 21:26:48 -07002390 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002391 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002392 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002393 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002394 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002395
2396 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002397 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002398 // Always respect dependency to the versioned stubs (i.e. libX#10)
2399 useThisDep = true
2400 } else if !depHasStubs {
2401 // Use non-stub variant if that is the only choice
2402 // (i.e. depending on a lib without stubs.version property)
2403 useThisDep = true
2404 } else if c.IsForPlatform() {
2405 // If not building for APEX, use stubs only when it is from
2406 // an APEX (and not from platform)
2407 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002408 if c.bootstrap() {
2409 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002410 // always link to non-stub variant
2411 useThisDep = !depIsStubs
2412 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002413 for _, testFor := range c.TestFor() {
2414 // Another exception: if this module is bundled with an APEX, then
2415 // it is linked with the non-stub variant of a module in the APEX
2416 // as if this is part of the APEX.
2417 if android.DirectlyInApex(testFor, depName) {
2418 useThisDep = !depIsStubs
2419 break
2420 }
2421 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002422 } else {
2423 // If building for APEX, use stubs only when it is not from
2424 // the same APEX
2425 useThisDep = (depInSameApex != depIsStubs)
2426 }
2427
Jooyung Han03b51852020-02-26 22:45:42 +09002428 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002429 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002430 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002431 if err != nil {
2432 ctx.OtherModuleErrorf(dep, err.Error())
2433 return
2434 }
2435 if versionToUse != ccDep.StubsVersion() {
2436 useThisDep = false
2437 }
2438 }
2439
Jiyong Park25fc6a92018-11-18 18:02:45 +09002440 if !useThisDep {
2441 return // stop processing this dep
2442 }
2443 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002444 if c.UseVndk() {
2445 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2446 // by default, use current version of LLNDK
2447 versionToUse := ""
2448 versions := stubsVersionsFor(ctx.Config())[depName]
2449 if c.ApexName() != "" && len(versions) > 0 {
2450 // if this is for use_vendor apex && dep has stubsVersions
2451 // apply the same rule of apex sdk enforcement to choose right version
2452 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002453 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002454 if err != nil {
2455 ctx.OtherModuleErrorf(dep, err.Error())
2456 return
2457 }
2458 }
2459 if versionToUse != ccDep.StubsVersion() {
2460 return
2461 }
2462 }
2463 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002464
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002465 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2466
Ivan Lozano52767be2019-10-18 14:49:46 -07002467 // Exporting flags only makes sense for cc.Modules
2468 if _, ok := ccDep.(*Module); ok {
2469 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002470 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002471 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002472 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002473
Colin Cross6e511a92020-07-27 21:26:48 -07002474 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002475 reexportExporter(i)
2476 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2477 // Re-exported shared library headers must be included as well since they can help us with type information
2478 // about template instantiations (instantiated from their headers).
2479 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2480 // scripts.
2481 c.sabi.Properties.ReexportedIncludes = append(
2482 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2483 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002484 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002485 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002486
Colin Cross6e511a92020-07-27 21:26:48 -07002487 var ptr *android.Paths
2488 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002489
Colin Cross6e511a92020-07-27 21:26:48 -07002490 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002491
Colin Cross6e511a92020-07-27 21:26:48 -07002492 switch {
2493 case libDepTag.header():
2494 // nothing
2495 case libDepTag.shared():
2496 ptr = &depPaths.SharedLibs
2497 switch libDepTag.Order {
2498 case earlyLibraryDependency:
2499 ptr = &depPaths.EarlySharedLibs
2500 depPtr = &depPaths.EarlySharedLibsDeps
2501 case normalLibraryDependency:
2502 ptr = &depPaths.SharedLibs
2503 depPtr = &depPaths.SharedLibsDeps
2504 directSharedDeps = append(directSharedDeps, ccDep)
2505 case lateLibraryDependency:
2506 ptr = &depPaths.LateSharedLibs
2507 depPtr = &depPaths.LateSharedLibsDeps
2508 default:
2509 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002510 }
Colin Cross6e511a92020-07-27 21:26:48 -07002511 depFile = ccDep.Toc()
2512 case libDepTag.static():
2513 if libDepTag.wholeStatic {
2514 ptr = &depPaths.WholeStaticLibs
2515 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2516 ctx.ModuleErrorf("module %q not a static library", depName)
2517 return
Inseob Kim752edec2020-03-14 01:30:34 +09002518 }
2519
Colin Cross6e511a92020-07-27 21:26:48 -07002520 // Because the static library objects are included, this only makes sense
2521 // in the context of proper cc.Modules.
2522 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2523 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2524 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2525 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2526 for i := range missingDeps {
2527 missingDeps[i] += postfix
2528 }
2529 ctx.AddMissingDependencies(missingDeps)
2530 }
2531 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2532 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2533 } else {
2534 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2535 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002536 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002537 ctx.ModuleErrorf(
2538 "non-cc.Modules cannot be included as whole static libraries.", depName)
2539 return
2540 }
2541
2542 } else {
2543 switch libDepTag.Order {
2544 case earlyLibraryDependency:
2545 panic(fmt.Errorf("early static libs not suppported"))
2546 case normalLibraryDependency:
2547 // static dependencies will be handled separately so they can be ordered
2548 // using transitive dependencies.
2549 ptr = nil
2550 directStaticDeps = append(directStaticDeps, ccDep)
2551 case lateLibraryDependency:
2552 ptr = &depPaths.LateStaticLibs
2553 default:
2554 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002555 }
2556 }
2557 }
2558
Colin Cross6e511a92020-07-27 21:26:48 -07002559 if libDepTag.static() && !libDepTag.wholeStatic {
2560 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2561 ctx.ModuleErrorf("module %q not a static library", depName)
2562 return
2563 }
Logan Chien43d34c32017-12-20 01:17:32 +08002564
Colin Cross6e511a92020-07-27 21:26:48 -07002565 // When combining coverage files for shared libraries and executables, coverage files
2566 // in static libraries act as if they were whole static libraries. The same goes for
2567 // source based Abi dump files.
2568 if c, ok := ccDep.(*Module); ok {
2569 staticLib := c.linker.(libraryInterface)
2570 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2571 staticLib.objs().coverageFiles...)
2572 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2573 staticLib.objs().sAbiDumpFiles...)
2574 } else if c, ok := ccDep.(LinkableInterface); ok {
2575 // Handle non-CC modules here
2576 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2577 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002578 }
2579 }
2580
Colin Cross6e511a92020-07-27 21:26:48 -07002581 if ptr != nil {
2582 if !linkFile.Valid() {
2583 if !ctx.Config().AllowMissingDependencies() {
2584 ctx.ModuleErrorf("module %q missing output file", depName)
2585 } else {
2586 ctx.AddMissingDependencies([]string{depName})
2587 }
2588 return
2589 }
2590 *ptr = append(*ptr, linkFile.Path())
2591 }
2592
2593 if depPtr != nil {
2594 dep := depFile
2595 if !dep.Valid() {
2596 dep = linkFile
2597 }
2598 *depPtr = append(*depPtr, dep.Path())
2599 }
2600
2601 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2602 switch {
2603 case libDepTag.header():
2604 // TODO(ccross): The reexportFlags check is there to maintain previous
2605 // behavior when adding libraryDependencyTag and should be removed.
2606 if !libDepTag.reexportFlags {
2607 c.Properties.AndroidMkHeaderLibs = append(
2608 c.Properties.AndroidMkHeaderLibs, makeLibName)
2609 }
2610 case libDepTag.shared():
2611 if ccDep.CcLibrary() {
2612 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2613 // Add the dependency to the APEX(es) providing the library so that
2614 // m <module> can trigger building the APEXes as well.
2615 for _, an := range android.GetApexesForModule(depName) {
2616 c.Properties.ApexesProvidingSharedLibs = append(
2617 c.Properties.ApexesProvidingSharedLibs, an)
2618 }
2619 }
2620 }
2621
2622 // Note: the order of libs in this list is not important because
2623 // they merely serve as Make dependencies and do not affect this lib itself.
2624 // TODO(ccross): The reexportFlags, order and ndk checks are there to
2625 // maintain previous behavior when adding libraryDependencyTag and
2626 // should be removed.
2627 if !c.static() || libDepTag.reexportFlags || libDepTag.Order == lateLibraryDependency || libDepTag.ndk {
2628 c.Properties.AndroidMkSharedLibs = append(
2629 c.Properties.AndroidMkSharedLibs, makeLibName)
2630 }
2631 // Record baseLibName for snapshots.
2632 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2633 case libDepTag.static():
2634 if libDepTag.wholeStatic {
2635 c.Properties.AndroidMkWholeStaticLibs = append(
2636 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2637 } else {
2638 c.Properties.AndroidMkStaticLibs = append(
2639 c.Properties.AndroidMkStaticLibs, makeLibName)
2640 }
2641 }
2642 } else {
2643 switch depTag {
2644 case runtimeDepTag:
2645 c.Properties.AndroidMkRuntimeLibs = append(
2646 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2647 // Record baseLibName for snapshots.
2648 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2649 case objDepTag:
2650 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2651 case CrtBeginDepTag:
2652 depPaths.CrtBegin = linkFile
2653 case CrtEndDepTag:
2654 depPaths.CrtEnd = linkFile
2655 case dynamicLinkerDepTag:
2656 depPaths.DynamicLinker = linkFile
2657 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002658 }
Colin Crossca860ac2016-01-04 14:34:37 -08002659 })
2660
Jeff Gaston294356f2017-09-27 17:05:30 -07002661 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002662 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002663
Colin Crossdd84e052017-05-17 13:44:16 -07002664 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002665 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002666 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2667 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002668 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002669 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2670 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002671 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002672 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002673 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002674
2675 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002676 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002677 }
Colin Crossdd84e052017-05-17 13:44:16 -07002678
Colin Crossca860ac2016-01-04 14:34:37 -08002679 return depPaths
2680}
2681
Colin Cross6e511a92020-07-27 21:26:48 -07002682// baseLibName trims known prefixes and suffixes
2683func baseLibName(depName string) string {
2684 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2685 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2686 libName = strings.TrimPrefix(libName, "prebuilt_")
2687 return libName
2688}
2689
2690func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2691 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2692 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2693
2694 libName := baseLibName(depName)
2695 isLLndk := isLlndkLibrary(libName, ctx.Config())
2696 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2697 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2698
2699 if c, ok := ccDep.(*Module); ok {
2700 // Use base module name for snapshots when exporting to Makefile.
2701 if c.isSnapshotPrebuilt() {
2702 baseName := c.BaseModuleName()
2703
2704 if c.IsVndk() {
2705 return baseName + ".vendor"
2706 }
2707
2708 if vendorSuffixModules[baseName] {
2709 return baseName + ".vendor"
2710 } else {
2711 return baseName
2712 }
2713 }
2714 }
2715
2716 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2717 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2718 // core module instead.
2719 return libName
2720 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2721 // The vendor module in Make will have been renamed to not conflict with the core
2722 // module, so update the dependency name here accordingly.
2723 return libName + c.getNameSuffixWithVndkVersion(ctx)
2724 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2725 return libName + vendorPublicLibrarySuffix
2726 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2727 return libName + ramdiskSuffix
2728 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2729 return libName + recoverySuffix
2730 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2731 return libName + nativeBridgeSuffix
2732 } else {
2733 return libName
2734 }
2735}
2736
Colin Crossca860ac2016-01-04 14:34:37 -08002737func (c *Module) InstallInData() bool {
2738 if c.installer == nil {
2739 return false
2740 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002741 return c.installer.inData()
2742}
2743
2744func (c *Module) InstallInSanitizerDir() bool {
2745 if c.installer == nil {
2746 return false
2747 }
2748 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002749 return true
2750 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002751 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002752}
2753
Yifan Hong1b3348d2020-01-21 15:53:22 -08002754func (c *Module) InstallInRamdisk() bool {
2755 return c.InRamdisk()
2756}
2757
Jiyong Parkf9332f12018-02-01 00:54:12 +09002758func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002759 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002760}
2761
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002762func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002763 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002764 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002765 return
2766 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002767 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002768}
2769
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002770func (c *Module) HostToolPath() android.OptionalPath {
2771 if c.installer == nil {
2772 return android.OptionalPath{}
2773 }
2774 return c.installer.hostToolPath()
2775}
2776
Nan Zhangd4e641b2017-07-12 12:55:28 -07002777func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2778 return c.outputFile
2779}
2780
Colin Cross41955e82019-05-29 14:40:35 -07002781func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2782 switch tag {
2783 case "":
2784 if c.outputFile.Valid() {
2785 return android.Paths{c.outputFile.Path()}, nil
2786 }
2787 return android.Paths{}, nil
2788 default:
2789 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002790 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002791}
2792
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002793func (c *Module) static() bool {
2794 if static, ok := c.linker.(interface {
2795 static() bool
2796 }); ok {
2797 return static.static()
2798 }
2799 return false
2800}
2801
Jiyong Park379de2f2018-12-19 02:47:14 +09002802func (c *Module) staticBinary() bool {
2803 if static, ok := c.linker.(interface {
2804 staticBinary() bool
2805 }); ok {
2806 return static.staticBinary()
2807 }
2808 return false
2809}
2810
Jiyong Park1d1119f2019-07-29 21:27:18 +09002811func (c *Module) header() bool {
2812 if h, ok := c.linker.(interface {
2813 header() bool
2814 }); ok {
2815 return h.header()
2816 }
2817 return false
2818}
2819
Inseob Kim7f283f42020-06-01 21:53:49 +09002820func (c *Module) binary() bool {
2821 if b, ok := c.linker.(interface {
2822 binary() bool
2823 }); ok {
2824 return b.binary()
2825 }
2826 return false
2827}
2828
Inseob Kim1042d292020-06-01 23:23:05 +09002829func (c *Module) object() bool {
2830 if o, ok := c.linker.(interface {
2831 object() bool
2832 }); ok {
2833 return o.object()
2834 }
2835 return false
2836}
2837
Jooyung Han38002912019-05-16 04:01:54 +09002838func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002839 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002840 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2841 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002842 return "native:vndk"
2843 }
Jooyung Han38002912019-05-16 04:01:54 +09002844 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002845 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002846 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002847 if Bool(c.VendorProperties.Vendor_available) {
2848 return "native:vndk"
2849 }
2850 return "native:vndk_private"
2851 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002852 if c.inProduct() {
2853 return "native:product"
2854 }
Jooyung Han38002912019-05-16 04:01:54 +09002855 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002856 } else if c.InRamdisk() {
2857 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002858 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002859 return "native:recovery"
2860 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2861 return "native:ndk:none:none"
2862 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2863 //family, link := getNdkStlFamilyAndLinkType(c)
2864 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002865 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002866 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002867 } else {
2868 return "native:platform"
2869 }
2870}
2871
Jiyong Park9d452992018-10-03 00:38:19 +09002872// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002873// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002874func (c *Module) IsInstallableToApex() bool {
2875 if shared, ok := c.linker.(interface {
2876 shared() bool
2877 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002878 // Stub libs and prebuilt libs in a versioned SDK are not
2879 // installable to APEX even though they are shared libs.
2880 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002881 } else if _, ok := c.linker.(testPerSrc); ok {
2882 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002883 }
2884 return false
2885}
2886
Jiyong Parka90ca002019-10-07 15:47:24 +09002887func (c *Module) AvailableFor(what string) bool {
2888 if linker, ok := c.linker.(interface {
2889 availableFor(string) bool
2890 }); ok {
2891 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2892 } else {
2893 return c.ApexModuleBase.AvailableFor(what)
2894 }
2895}
2896
Jiyong Park62304bb2020-04-13 16:19:48 +09002897func (c *Module) TestFor() []string {
2898 if test, ok := c.linker.(interface {
2899 testFor() []string
2900 }); ok {
2901 return test.testFor()
2902 } else {
2903 return c.ApexModuleBase.TestFor()
2904 }
2905}
2906
Paul Duffin0cb37b92020-03-04 14:52:46 +00002907// Return true if the module is ever installable.
2908func (c *Module) EverInstallable() bool {
2909 return c.installer != nil &&
2910 // Check to see whether the module is actually ever installable.
2911 c.installer.everInstallable()
2912}
2913
Inseob Kim1f086e22019-05-09 13:29:15 +09002914func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002915 ret := c.EverInstallable() &&
2916 // Check to see whether the module has been configured to not be installed.
2917 proptools.BoolDefault(c.Properties.Installable, true) &&
2918 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002919
2920 // The platform variant doesn't need further condition. Apex variants however might not
2921 // be installable because it will likely to be included in the APEX and won't appear
2922 // in the system partition.
2923 if c.IsForPlatform() {
2924 return ret
2925 }
2926
2927 // Special case for modules that are configured to be installed to /data, which includes
2928 // test modules. For these modules, both APEX and non-APEX variants are considered as
2929 // installable. This is because even the APEX variants won't be included in the APEX, but
2930 // will anyway be installed to /data/*.
2931 // See b/146995717
2932 if c.InstallInData() {
2933 return ret
2934 }
2935
2936 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002937}
2938
Logan Chien41eabe62019-04-10 13:33:58 +08002939func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2940 if c.linker != nil {
2941 if library, ok := c.linker.(*libraryDecorator); ok {
2942 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2943 }
2944 }
2945}
2946
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002947func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002948 depTag := ctx.OtherModuleDependencyTag(dep)
2949 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2950
2951 if cc, ok := dep.(*Module); ok {
2952 if cc.HasStubsVariants() {
2953 if isLibDepTag && libDepTag.shared() {
2954 // dynamic dep to a stubs lib crosses APEX boundary
2955 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002956 }
Colin Cross6e511a92020-07-27 21:26:48 -07002957 if IsRuntimeDepTag(depTag) {
2958 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002959 return false
2960 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002961 }
Colin Cross6e511a92020-07-27 21:26:48 -07002962 // TODO(ccross): The libDepTag.reexportFlags is there to maintain previous behavior
2963 // when adding libraryDependencyTag and should be removed.
2964 if isLibDepTag && c.static() && libDepTag.shared() && !libDepTag.reexportFlags {
2965 // shared_lib dependency from a static lib is considered as crossing
2966 // the APEX boundary because the dependency doesn't actually is
2967 // linked; the dependency is used only during the compilation phase.
2968 return false
2969 }
2970 }
2971 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09002972 // We don't track beyond LLNDK
2973 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002974 }
2975 return true
2976}
2977
Jooyung Han749dc692020-04-15 11:03:39 +09002978// b/154667674: refactor this to handle "current" in a consistent way
2979func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
2980 if versionString == "" {
2981 return 0, fmt.Errorf("not specified")
2982 }
2983 if versionString == "current" {
2984 if ctx.Config().PlatformSdkCodename() == "REL" {
2985 return ctx.Config().PlatformSdkVersionInt(), nil
2986 }
2987 return android.FutureApiLevel, nil
2988 }
2989 return android.ApiStrToNum(ctx, versionString)
2990}
2991
2992func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
2993 // 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 }
3016 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
3017 if err != nil {
3018 return err
3019 }
3020 if ver > sdkVersion {
3021 return fmt.Errorf("newer SDK(%v)", ver)
3022 }
3023 return nil
3024}
3025
Colin Cross2ba19d92015-05-07 15:44:20 -07003026//
Colin Crosscfad1192015-11-02 16:43:11 -08003027// Defaults
3028//
Colin Crossca860ac2016-01-04 14:34:37 -08003029type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003030 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003031 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003032 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003033}
3034
Patrice Arrudac249c712019-03-19 17:00:29 -07003035// cc_defaults provides a set of properties that can be inherited by other cc
3036// modules. A module can use the properties from a cc_defaults using
3037// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3038// merged (when possible) by prepending the default module's values to the
3039// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003040func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003041 return DefaultsFactory()
3042}
3043
Colin Cross36242852017-06-23 15:06:31 -07003044func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003045 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003046
Colin Cross36242852017-06-23 15:06:31 -07003047 module.AddProperties(props...)
3048 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003049 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003050 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003051 &BaseCompilerProperties{},
3052 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003053 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003054 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003055 &StaticProperties{},
3056 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003057 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003058 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003059 &TestProperties{},
3060 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003061 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003062 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003063 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003064 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003065 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003066 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003067 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003068 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003069 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003070 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003071 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003072 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003073 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003074 )
Colin Crosscfad1192015-11-02 16:43:11 -08003075
Jooyung Hancc372c52019-09-25 15:18:44 +09003076 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003077
3078 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003079}
3080
Jiyong Park6a43f042017-10-12 23:05:00 +09003081func squashVendorSrcs(m *Module) {
3082 if lib, ok := m.compiler.(*libraryDecorator); ok {
3083 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3084 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3085
3086 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3087 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003088
3089 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3090 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003091 }
3092}
3093
Jiyong Parkf9332f12018-02-01 00:54:12 +09003094func squashRecoverySrcs(m *Module) {
3095 if lib, ok := m.compiler.(*libraryDecorator); ok {
3096 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3097 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3098
3099 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3100 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003101
3102 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3103 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003104 }
3105}
3106
Jiyong Park2286afd2020-06-16 21:58:53 +09003107func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003108 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003109}
3110
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003111func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003112 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003113 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3114 }
Colin Cross6510f912017-11-29 00:27:14 -08003115 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003116}
3117
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003118func kytheExtractAllFactory() android.Singleton {
3119 return &kytheExtractAllSingleton{}
3120}
3121
3122type kytheExtractAllSingleton struct {
3123}
3124
3125func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3126 var xrefTargets android.Paths
3127 ctx.VisitAllModules(func(module android.Module) {
3128 if ccModule, ok := module.(xref); ok {
3129 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3130 }
3131 })
3132 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3133 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003134 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003135 }
3136}
3137
Colin Cross06a931b2015-10-28 17:23:31 -07003138var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003139var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003140var BoolPtr = proptools.BoolPtr
3141var String = proptools.String
3142var StringPtr = proptools.StringPtr