blob: 6f1a06d99ef499a4df13748ef0b0d28be1ad0212 [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
Colin Crossc511bc52020-04-07 16:50:32 +0000684func (c *Module) AlwaysSdk() bool {
685 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
686}
687
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800688func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700689 if c.linker != nil {
690 if library, ok := c.linker.(exportedFlagsProducer); ok {
691 return library.exportedDirs()
692 }
693 }
694 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
695}
696
697func (c *Module) HasStaticVariant() bool {
698 if c.staticVariant != nil {
699 return true
700 }
701 return false
702}
703
704func (c *Module) GetStaticVariant() LinkableInterface {
705 return c.staticVariant
706}
707
708func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
709 c.depsInLinkOrder = depsInLinkOrder
710}
711
712func (c *Module) GetDepsInLinkOrder() []android.Path {
713 return c.depsInLinkOrder
714}
715
716func (c *Module) StubsVersions() []string {
717 if c.linker != nil {
718 if library, ok := c.linker.(*libraryDecorator); ok {
719 return library.Properties.Stubs.Versions
720 }
721 }
722 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
723}
724
725func (c *Module) CcLibrary() bool {
726 if c.linker != nil {
727 if _, ok := c.linker.(*libraryDecorator); ok {
728 return true
729 }
730 }
731 return false
732}
733
734func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700735 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700736 return true
737 }
738 return false
739}
740
Ivan Lozano2b262972019-11-21 12:30:50 -0800741func (c *Module) NonCcVariants() bool {
742 return false
743}
744
Ivan Lozano183a3212019-10-18 14:18:45 -0700745func (c *Module) SetBuildStubs() {
746 if c.linker != nil {
747 if library, ok := c.linker.(*libraryDecorator); ok {
748 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700749 c.Properties.HideFromMake = true
750 c.sanitize = nil
751 c.stl = nil
752 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700753 return
754 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000755 if _, ok := c.linker.(*llndkStubDecorator); ok {
756 c.Properties.HideFromMake = true
757 return
758 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700759 }
760 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
761}
762
Ivan Lozano52767be2019-10-18 14:49:46 -0700763func (c *Module) BuildStubs() bool {
764 if c.linker != nil {
765 if library, ok := c.linker.(*libraryDecorator); ok {
766 return library.buildStubs()
767 }
768 }
769 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
770}
771
Ivan Lozano183a3212019-10-18 14:18:45 -0700772func (c *Module) SetStubsVersions(version string) {
773 if c.linker != nil {
774 if library, ok := c.linker.(*libraryDecorator); ok {
775 library.MutatedProperties.StubsVersion = version
776 return
777 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000778 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
779 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
780 return
781 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700782 }
783 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
784}
785
Jooyung Han03b51852020-02-26 22:45:42 +0900786func (c *Module) StubsVersion() string {
787 if c.linker != nil {
788 if library, ok := c.linker.(*libraryDecorator); ok {
789 return library.MutatedProperties.StubsVersion
790 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000791 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
792 return llndk.libraryDecorator.MutatedProperties.StubsVersion
793 }
Jooyung Han03b51852020-02-26 22:45:42 +0900794 }
795 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
796}
797
Ivan Lozano183a3212019-10-18 14:18:45 -0700798func (c *Module) SetStatic() {
799 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700800 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700801 library.setStatic()
802 return
803 }
804 }
805 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
806}
807
808func (c *Module) SetShared() {
809 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700810 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700811 library.setShared()
812 return
813 }
814 }
815 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
816}
817
818func (c *Module) BuildStaticVariant() bool {
819 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700820 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700821 return library.buildStatic()
822 }
823 }
824 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
825}
826
827func (c *Module) BuildSharedVariant() bool {
828 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700829 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700830 return library.buildShared()
831 }
832 }
833 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
834}
835
836func (c *Module) Module() android.Module {
837 return c
838}
839
Jiyong Parkc20eee32018-09-05 22:36:17 +0900840func (c *Module) OutputFile() android.OptionalPath {
841 return c.outputFile
842}
843
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400844func (c *Module) CoverageFiles() android.Paths {
845 if c.linker != nil {
846 if library, ok := c.linker.(libraryInterface); ok {
847 return library.objs().coverageFiles
848 }
849 }
850 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
851}
852
Ivan Lozano183a3212019-10-18 14:18:45 -0700853var _ LinkableInterface = (*Module)(nil)
854
Jiyong Park719b4462019-01-13 00:39:51 +0900855func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900856 if c.linker != nil {
857 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900858 }
859 return nil
860}
861
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900862func (c *Module) CoverageOutputFile() android.OptionalPath {
863 if c.linker != nil {
864 return c.linker.coverageOutputFilePath()
865 }
866 return android.OptionalPath{}
867}
868
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900869func (c *Module) RelativeInstallPath() string {
870 if c.installer != nil {
871 return c.installer.relativeInstallPath()
872 }
873 return ""
874}
875
Jooyung Han344d5432019-08-23 11:17:39 +0900876func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900877 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900878}
879
Colin Cross36242852017-06-23 15:06:31 -0700880func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700881 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800882 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700883 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800884 }
885 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700886 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800887 }
888 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700889 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800890 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700891 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700892 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700893 }
Colin Cross16b23492016-01-06 14:41:07 -0800894 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700895 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800896 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800897 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700898 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800899 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800900 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700901 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800902 }
Justin Yun8effde42017-06-23 19:24:43 +0900903 if c.vndkdep != nil {
904 c.AddProperties(c.vndkdep.props()...)
905 }
Stephen Craneba090d12017-05-09 15:44:35 -0700906 if c.lto != nil {
907 c.AddProperties(c.lto.props()...)
908 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700909 if c.pgo != nil {
910 c.AddProperties(c.pgo.props()...)
911 }
Colin Crossca860ac2016-01-04 14:34:37 -0800912 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700913 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800914 }
Colin Crossc472d572015-03-17 15:06:21 -0700915
Colin Crossa9d8bee2018-10-02 13:59:46 -0700916 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700917 // Windows builds always prefer 32-bit
918 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700919 })
Colin Cross36242852017-06-23 15:06:31 -0700920 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900921 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900922 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900923 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900924
Colin Cross36242852017-06-23 15:06:31 -0700925 return c
Colin Crossc472d572015-03-17 15:06:21 -0700926}
927
Colin Crossb916a382016-07-29 17:28:03 -0700928// Returns true for dependency roots (binaries)
929// TODO(ccross): also handle dlopenable libraries
930func (c *Module) isDependencyRoot() bool {
931 if root, ok := c.linker.(interface {
932 isDependencyRoot() bool
933 }); ok {
934 return root.isDependencyRoot()
935 }
936 return false
937}
938
Justin Yun5f7f7e82019-11-18 19:52:14 +0900939// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
940// "product" and "vendor" variant modules return true for this function.
941// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
942// "soc_specific: true" and more vendor installed modules are included here.
943// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
944// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700945func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900946 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700947}
948
Colin Crossc511bc52020-04-07 16:50:32 +0000949func (c *Module) canUseSdk() bool {
950 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
951}
952
953func (c *Module) UseSdk() bool {
954 if c.canUseSdk() {
955 return String(c.Properties.Sdk_version) != ""
956 }
957 return false
958}
959
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800960func (c *Module) isCoverageVariant() bool {
961 return c.coverage.Properties.IsCoverageVariant
962}
963
Peter Collingbournead84f972019-12-17 16:46:18 -0800964func (c *Module) IsNdk() bool {
Dan Albertde5aade2020-06-30 12:32:51 -0700965 return inList(c.Name(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800966}
967
Inseob Kim9516ee92019-05-09 10:56:13 +0900968func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800969 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900970 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800971}
972
Inseob Kim9516ee92019-05-09 10:56:13 +0900973func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800974 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900975 name := c.BaseModuleName()
976 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800977}
978
Inseob Kim9516ee92019-05-09 10:56:13 +0900979func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800980 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900981 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800982}
983
Ivan Lozano52767be2019-10-18 14:49:46 -0700984func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800985 if vndkdep := c.vndkdep; vndkdep != nil {
986 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900987 }
988 return false
989}
990
Yi Kong7e53c572018-02-14 18:16:12 +0800991func (c *Module) isPgoCompile() bool {
992 if pgo := c.pgo; pgo != nil {
993 return pgo.Properties.PgoCompile
994 }
995 return false
996}
997
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800998func (c *Module) isNDKStubLibrary() bool {
999 if _, ok := c.compiler.(*stubDecorator); ok {
1000 return true
1001 }
1002 return false
1003}
1004
Logan Chienf3511742017-10-31 18:04:35 +08001005func (c *Module) isVndkSp() bool {
1006 if vndkdep := c.vndkdep; vndkdep != nil {
1007 return vndkdep.isVndkSp()
1008 }
1009 return false
1010}
1011
1012func (c *Module) isVndkExt() bool {
1013 if vndkdep := c.vndkdep; vndkdep != nil {
1014 return vndkdep.isVndkExt()
1015 }
1016 return false
1017}
1018
Ivan Lozano52767be2019-10-18 14:49:46 -07001019func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001020 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001021}
1022
Logan Chienf3511742017-10-31 18:04:35 +08001023func (c *Module) getVndkExtendsModuleName() string {
1024 if vndkdep := c.vndkdep; vndkdep != nil {
1025 return vndkdep.getVndkExtendsModuleName()
1026 }
1027 return ""
1028}
1029
Jiyong Park25fc6a92018-11-18 18:02:45 +09001030func (c *Module) IsStubs() bool {
1031 if library, ok := c.linker.(*libraryDecorator); ok {
1032 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001033 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1034 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001035 }
1036 return false
1037}
1038
1039func (c *Module) HasStubsVariants() bool {
1040 if library, ok := c.linker.(*libraryDecorator); ok {
1041 return len(library.Properties.Stubs.Versions) > 0
1042 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001043 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1044 return len(library.Properties.Stubs.Versions) > 0
1045 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001046 return false
1047}
1048
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001049func (c *Module) bootstrap() bool {
1050 return Bool(c.Properties.Bootstrap)
1051}
1052
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001053func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001054 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1055 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1056 return false
1057 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001058 return c.linker != nil && c.linker.nativeCoverage()
1059}
1060
Inseob Kim8471cda2019-11-15 09:59:12 +09001061func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001062 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1063 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001064 }
1065 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001066}
1067
Jiyong Park73c54ee2019-10-22 20:31:18 +09001068func (c *Module) ExportedIncludeDirs() android.Paths {
1069 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1070 return flagsProducer.exportedDirs()
1071 }
Jiyong Park232e7852019-11-04 12:23:40 +09001072 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001073}
1074
1075func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1076 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1077 return flagsProducer.exportedSystemDirs()
1078 }
Jiyong Park232e7852019-11-04 12:23:40 +09001079 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001080}
1081
1082func (c *Module) ExportedFlags() []string {
1083 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1084 return flagsProducer.exportedFlags()
1085 }
Jiyong Park232e7852019-11-04 12:23:40 +09001086 return nil
1087}
1088
1089func (c *Module) ExportedDeps() android.Paths {
1090 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1091 return flagsProducer.exportedDeps()
1092 }
1093 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001094}
1095
Inseob Kimd110f872019-12-06 13:15:38 +09001096func (c *Module) ExportedGeneratedHeaders() android.Paths {
1097 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1098 return flagsProducer.exportedGeneratedHeaders()
1099 }
1100 return nil
1101}
1102
Jiyong Parkf1194352019-02-25 11:05:47 +09001103func isBionic(name string) bool {
1104 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001105 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001106 return true
1107 }
1108 return false
1109}
1110
Martin Stjernholm279de572019-09-10 23:18:20 +01001111func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001112 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001113 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001114 }
1115 return isBionic(name)
1116}
1117
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001118func (c *Module) XrefCcFiles() android.Paths {
1119 return c.kytheFiles
1120}
1121
Colin Crossca860ac2016-01-04 14:34:37 -08001122type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001123 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001124 moduleContextImpl
1125}
1126
Colin Cross37047f12016-12-13 17:06:13 -08001127type depsContext struct {
1128 android.BottomUpMutatorContext
1129 moduleContextImpl
1130}
1131
Colin Crossca860ac2016-01-04 14:34:37 -08001132type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001133 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001134 moduleContextImpl
1135}
1136
1137type moduleContextImpl struct {
1138 mod *Module
1139 ctx BaseModuleContext
1140}
1141
Colin Crossb98c8b02016-07-29 13:44:28 -07001142func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001143 return ctx.mod.toolchain(ctx.ctx)
1144}
1145
1146func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001147 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001148}
1149
1150func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001151 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001152}
1153
Jiyong Park1d1119f2019-07-29 21:27:18 +09001154func (ctx *moduleContextImpl) header() bool {
1155 return ctx.mod.header()
1156}
1157
Inseob Kim7f283f42020-06-01 21:53:49 +09001158func (ctx *moduleContextImpl) binary() bool {
1159 return ctx.mod.binary()
1160}
1161
Inseob Kim1042d292020-06-01 23:23:05 +09001162func (ctx *moduleContextImpl) object() bool {
1163 return ctx.mod.object()
1164}
1165
Jooyung Hanccce2f22020-03-07 03:45:53 +09001166func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001167 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001168}
1169
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001170func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001171 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001172}
1173
1174func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001175 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001176 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001177 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001178 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001179 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001180 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001181 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001182 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001183 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001184 }
1185 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001186}
1187
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001188func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001189 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001190}
Justin Yun8effde42017-06-23 19:24:43 +09001191
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001192func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001193 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001194}
1195
Inseob Kim9516ee92019-05-09 10:56:13 +09001196func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1197 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001198}
1199
Inseob Kim9516ee92019-05-09 10:56:13 +09001200func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1201 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001202}
1203
Inseob Kim9516ee92019-05-09 10:56:13 +09001204func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1205 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001206}
1207
Logan Chienf3511742017-10-31 18:04:35 +08001208func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001209 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001210}
1211
Yi Kong7e53c572018-02-14 18:16:12 +08001212func (ctx *moduleContextImpl) isPgoCompile() bool {
1213 return ctx.mod.isPgoCompile()
1214}
1215
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001216func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1217 return ctx.mod.isNDKStubLibrary()
1218}
1219
Justin Yun8effde42017-06-23 19:24:43 +09001220func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001221 return ctx.mod.isVndkSp()
1222}
1223
1224func (ctx *moduleContextImpl) isVndkExt() bool {
1225 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001226}
1227
Vic Yangefd249e2018-11-12 20:19:56 -08001228func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001229 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001230}
1231
Logan Chien2f2b8902018-07-10 15:01:19 +08001232// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001233func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001234 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1235 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001236 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001237
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001238 // Coverage builds have extra symbols.
1239 if ctx.mod.isCoverageVariant() {
1240 return false
1241 }
1242
Doug Hornc32c6b02019-01-17 14:44:05 -08001243 if ctx.ctx.Fuchsia() {
1244 return false
1245 }
1246
Logan Chien2f2b8902018-07-10 15:01:19 +08001247 if sanitize := ctx.mod.sanitize; sanitize != nil {
1248 if !sanitize.isVariantOnProductionDevice() {
1249 return false
1250 }
1251 }
1252 if !ctx.ctx.Device() {
1253 // Host modules do not need ABI dumps.
1254 return false
1255 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001256 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001257 // Stubs do not need ABI dumps.
1258 return false
1259 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001260 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001261}
1262
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001263func (ctx *moduleContextImpl) selectedStl() string {
1264 if stl := ctx.mod.stl; stl != nil {
1265 return stl.Properties.SelectedStl
1266 }
1267 return ""
1268}
1269
Ivan Lozanobd721262018-11-27 14:33:03 -08001270func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1271 return ctx.mod.linker.useClangLld(actx)
1272}
1273
Colin Crossce75d2c2016-10-06 16:12:58 -07001274func (ctx *moduleContextImpl) baseModuleName() string {
1275 return ctx.mod.ModuleBase.BaseModuleName()
1276}
1277
Logan Chienf3511742017-10-31 18:04:35 +08001278func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1279 return ctx.mod.getVndkExtendsModuleName()
1280}
1281
Logan Chiene274fc92019-12-03 11:18:32 -08001282func (ctx *moduleContextImpl) isForPlatform() bool {
1283 return ctx.mod.IsForPlatform()
1284}
1285
Jiyong Park58e364a2019-01-19 19:24:06 +09001286func (ctx *moduleContextImpl) apexName() string {
1287 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001288}
1289
Jooyung Hanccce2f22020-03-07 03:45:53 +09001290func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001291 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001292}
1293
Jiyong Parkb0788572018-12-20 22:10:17 +09001294func (ctx *moduleContextImpl) hasStubsVariants() bool {
1295 return ctx.mod.HasStubsVariants()
1296}
1297
1298func (ctx *moduleContextImpl) isStubs() bool {
1299 return ctx.mod.IsStubs()
1300}
1301
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001302func (ctx *moduleContextImpl) bootstrap() bool {
1303 return ctx.mod.bootstrap()
1304}
1305
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001306func (ctx *moduleContextImpl) nativeCoverage() bool {
1307 return ctx.mod.nativeCoverage()
1308}
1309
Colin Cross635c3b02016-05-18 15:37:25 -07001310func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001311 return &Module{
1312 hod: hod,
1313 multilib: multilib,
1314 }
1315}
1316
Colin Cross635c3b02016-05-18 15:37:25 -07001317func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001318 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001319 module.features = []feature{
1320 &tidyFeature{},
1321 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001322 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001323 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001324 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001325 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001326 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001327 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001328 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001329 return module
1330}
1331
Colin Crossce75d2c2016-10-06 16:12:58 -07001332func (c *Module) Prebuilt() *android.Prebuilt {
1333 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1334 return p.prebuilt()
1335 }
1336 return nil
1337}
1338
1339func (c *Module) Name() string {
1340 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001341 if p, ok := c.linker.(interface {
1342 Name(string) string
1343 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001344 name = p.Name(name)
1345 }
1346 return name
1347}
1348
Alex Light3d673592019-01-18 14:37:31 -08001349func (c *Module) Symlinks() []string {
1350 if p, ok := c.installer.(interface {
1351 symlinkList() []string
1352 }); ok {
1353 return p.symlinkList()
1354 }
1355 return nil
1356}
1357
Jeff Gaston294356f2017-09-27 17:05:30 -07001358// orderDeps reorders dependencies into a list such that if module A depends on B, then
1359// A will precede B in the resultant list.
1360// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001361// Note that directSharedDeps should be the analogous static library for each shared lib dep
1362func 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 -07001363 // If A depends on B, then
1364 // Every list containing A will also contain B later in the list
1365 // So, after concatenating all lists, the final instance of B will have come from the same
1366 // original list as the final instance of A
1367 // So, the final instance of B will be later in the concatenation than the final A
1368 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1369 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001370 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001371 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001372 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1373 }
1374 for _, dep := range directSharedDeps {
1375 orderedAllDeps = append(orderedAllDeps, dep)
1376 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001377 }
1378
Colin Crossb6715442017-10-24 11:13:31 -07001379 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001380
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001381 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001382 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001383 // resultant list to only what the caller has chosen to include in directStaticDeps
1384 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001385
1386 return orderedAllDeps, orderedDeclaredDeps
1387}
1388
Ivan Lozano183a3212019-10-18 14:18:45 -07001389func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001390 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001391 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001392 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1393 staticDepFiles := []android.Path{}
1394 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001395 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1396 if dep.OutputFile().Valid() {
1397 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1398 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1399 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001400 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001401 sharedDepFiles := []android.Path{}
1402 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001403 if sharedDep.HasStaticVariant() {
1404 staticAnalogue := sharedDep.GetStaticVariant()
1405 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1406 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001407 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001408 }
1409
1410 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001411 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1412 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001413
1414 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001415}
1416
Roland Levillainf89cd092019-07-29 16:22:59 +01001417func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1418 test, ok := c.linker.(testPerSrc)
1419 return ok && test.isAllTestsVariation()
1420}
1421
Chris Parsons216e10a2020-07-09 17:12:52 -04001422func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001423 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001424 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001425 }); ok {
1426 return p.dataPaths()
1427 }
1428 return nil
1429}
1430
Justin Yun5f7f7e82019-11-18 19:52:14 +09001431func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1432 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1433 // "current", it will append the VNDK version to the name suffix.
1434 var vndkVersion string
1435 var nameSuffix string
1436 if c.inProduct() {
1437 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1438 nameSuffix = productSuffix
1439 } else {
1440 vndkVersion = ctx.DeviceConfig().VndkVersion()
1441 nameSuffix = vendorSuffix
1442 }
1443 if vndkVersion == "current" {
1444 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1445 }
1446 if c.Properties.VndkVersion != vndkVersion {
1447 // add version suffix only if the module is using different vndk version than the
1448 // version in product or vendor partition.
1449 nameSuffix += "." + c.Properties.VndkVersion
1450 }
1451 return nameSuffix
1452}
1453
Colin Cross635c3b02016-05-18 15:37:25 -07001454func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001455 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001456 //
1457 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1458 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1459 // module and return early, as this module does not produce an output file per se.
1460 if c.IsTestPerSrcAllTestsVariation() {
1461 c.outputFile = android.OptionalPath{}
1462 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001463 }
1464
Jooyung Han38002912019-05-16 04:01:54 +09001465 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001466
Inseob Kim64c43952019-08-26 16:52:35 +09001467 c.Properties.SubName = ""
1468
1469 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1470 c.Properties.SubName += nativeBridgeSuffix
1471 }
1472
Justin Yun5f7f7e82019-11-18 19:52:14 +09001473 _, llndk := c.linker.(*llndkStubDecorator)
1474 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1475 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1476 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1477 // added for product variant only when we have vendor and product variants with core
1478 // variant. The suffix is not added for vendor-only or product-only module.
1479 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1480 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001481 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1482 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1483 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001484 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1485 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001486 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001487 c.Properties.SubName += recoverySuffix
Colin Crossc511bc52020-04-07 16:50:32 +00001488 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1489 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001490 }
1491
Colin Crossca860ac2016-01-04 14:34:37 -08001492 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001493 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001494 moduleContextImpl: moduleContextImpl{
1495 mod: c,
1496 },
1497 }
1498 ctx.ctx = ctx
1499
Colin Crossf18e1102017-11-16 14:33:08 -08001500 deps := c.depsToPaths(ctx)
1501 if ctx.Failed() {
1502 return
1503 }
1504
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001505 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1506 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1507 }
1508
Colin Crossca860ac2016-01-04 14:34:37 -08001509 flags := Flags{
1510 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001511 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001512 }
Colin Crossca860ac2016-01-04 14:34:37 -08001513 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001514 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001515 }
1516 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001517 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001518 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001519 if c.stl != nil {
1520 flags = c.stl.flags(ctx, flags)
1521 }
Colin Cross16b23492016-01-06 14:41:07 -08001522 if c.sanitize != nil {
1523 flags = c.sanitize.flags(ctx, flags)
1524 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001525 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001526 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001527 }
Stephen Craneba090d12017-05-09 15:44:35 -07001528 if c.lto != nil {
1529 flags = c.lto.flags(ctx, flags)
1530 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001531 if c.pgo != nil {
1532 flags = c.pgo.flags(ctx, flags)
1533 }
Colin Crossca860ac2016-01-04 14:34:37 -08001534 for _, feature := range c.features {
1535 flags = feature.flags(ctx, flags)
1536 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001537 if ctx.Failed() {
1538 return
1539 }
1540
Colin Cross4af21ed2019-11-04 09:37:55 -08001541 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1542 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1543 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001544
Colin Cross4af21ed2019-11-04 09:37:55 -08001545 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001546
1547 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001548 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001549 }
1550 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001551 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001552 }
1553
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001554 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001555 // We need access to all the flags seen by a source file.
1556 if c.sabi != nil {
1557 flags = c.sabi.flags(ctx, flags)
1558 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001559
Colin Cross4af21ed2019-11-04 09:37:55 -08001560 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001561
Colin Crossca860ac2016-01-04 14:34:37 -08001562 // Optimization to reduce size of build.ninja
1563 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001564 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1565 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1566 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1567 flags.Local.CFlags = []string{"$cflags"}
1568 flags.Local.CppFlags = []string{"$cppflags"}
1569 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001570
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001571 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001572 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001573 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001574 if ctx.Failed() {
1575 return
1576 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001577 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001578 }
1579
Colin Crossca860ac2016-01-04 14:34:37 -08001580 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001581 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001582 if ctx.Failed() {
1583 return
1584 }
Colin Cross635c3b02016-05-18 15:37:25 -07001585 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001586
1587 // If a lib is directly included in any of the APEXes, unhide the stubs
1588 // variant having the latest version gets visible to make. In addition,
1589 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1590 // force anything in the make world to link against the stubs library.
1591 // (unless it is explicitly referenced via .bootstrap suffix or the
1592 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001593 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001594 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001595 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001596 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001597 c.Properties.HideFromMake = false // unhide
1598 // Note: this is still non-installable
1599 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001600
1601 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1602 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1603 if isSnapshotAware(ctx, c) {
1604 i.collectHeadersForSnapshot(ctx)
1605 }
1606 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001607 }
Colin Cross5049f022015-03-18 13:28:46 -07001608
Inseob Kim1f086e22019-05-09 13:29:15 +09001609 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001610 c.installer.install(ctx, c.outputFile.Path())
1611 if ctx.Failed() {
1612 return
Colin Crossca860ac2016-01-04 14:34:37 -08001613 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001614 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1615 // If the module has been specifically configure to not be installed then
1616 // skip the installation as otherwise it will break when running inside make
1617 // as the output path to install will not be specified. Not all uninstallable
1618 // modules can skip installation as some are needed for resolving make side
1619 // dependencies.
1620 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001621 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001622}
1623
Colin Cross0ea8ba82019-06-06 14:33:29 -07001624func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001625 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001626 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001627 }
Colin Crossca860ac2016-01-04 14:34:37 -08001628 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001629}
1630
Colin Crossca860ac2016-01-04 14:34:37 -08001631func (c *Module) begin(ctx BaseModuleContext) {
1632 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001633 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001634 }
Colin Crossca860ac2016-01-04 14:34:37 -08001635 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001636 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001637 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001638 if c.stl != nil {
1639 c.stl.begin(ctx)
1640 }
Colin Cross16b23492016-01-06 14:41:07 -08001641 if c.sanitize != nil {
1642 c.sanitize.begin(ctx)
1643 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001644 if c.coverage != nil {
1645 c.coverage.begin(ctx)
1646 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001647 if c.sabi != nil {
1648 c.sabi.begin(ctx)
1649 }
Justin Yun8effde42017-06-23 19:24:43 +09001650 if c.vndkdep != nil {
1651 c.vndkdep.begin(ctx)
1652 }
Stephen Craneba090d12017-05-09 15:44:35 -07001653 if c.lto != nil {
1654 c.lto.begin(ctx)
1655 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001656 if c.pgo != nil {
1657 c.pgo.begin(ctx)
1658 }
Colin Crossca860ac2016-01-04 14:34:37 -08001659 for _, feature := range c.features {
1660 feature.begin(ctx)
1661 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001662 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001663 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001664 if err != nil {
1665 ctx.PropertyErrorf("sdk_version", err.Error())
1666 }
Nan Zhang0007d812017-11-07 10:57:05 -08001667 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001668 }
Colin Crossca860ac2016-01-04 14:34:37 -08001669}
1670
Colin Cross37047f12016-12-13 17:06:13 -08001671func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001672 deps := Deps{}
1673
1674 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001675 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001676 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001677 // Add the PGO dependency (the clang_rt.profile runtime library), which
1678 // sometimes depends on symbols from libgcc, before libgcc gets added
1679 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001680 if c.pgo != nil {
1681 deps = c.pgo.deps(ctx, deps)
1682 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001683 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001684 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001685 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001686 if c.stl != nil {
1687 deps = c.stl.deps(ctx, deps)
1688 }
Colin Cross16b23492016-01-06 14:41:07 -08001689 if c.sanitize != nil {
1690 deps = c.sanitize.deps(ctx, deps)
1691 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001692 if c.coverage != nil {
1693 deps = c.coverage.deps(ctx, deps)
1694 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001695 if c.sabi != nil {
1696 deps = c.sabi.deps(ctx, deps)
1697 }
Justin Yun8effde42017-06-23 19:24:43 +09001698 if c.vndkdep != nil {
1699 deps = c.vndkdep.deps(ctx, deps)
1700 }
Stephen Craneba090d12017-05-09 15:44:35 -07001701 if c.lto != nil {
1702 deps = c.lto.deps(ctx, deps)
1703 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001704 for _, feature := range c.features {
1705 deps = feature.deps(ctx, deps)
1706 }
1707
Colin Crossb6715442017-10-24 11:13:31 -07001708 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1709 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1710 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1711 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1712 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1713 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001714 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001715
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001716 for _, lib := range deps.ReexportSharedLibHeaders {
1717 if !inList(lib, deps.SharedLibs) {
1718 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1719 }
1720 }
1721
1722 for _, lib := range deps.ReexportStaticLibHeaders {
1723 if !inList(lib, deps.StaticLibs) {
1724 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1725 }
1726 }
1727
Colin Cross5950f382016-12-13 12:50:57 -08001728 for _, lib := range deps.ReexportHeaderLibHeaders {
1729 if !inList(lib, deps.HeaderLibs) {
1730 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1731 }
1732 }
1733
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001734 for _, gen := range deps.ReexportGeneratedHeaders {
1735 if !inList(gen, deps.GeneratedHeaders) {
1736 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1737 }
1738 }
1739
Colin Crossc99deeb2016-04-11 15:06:20 -07001740 return deps
1741}
1742
Dan Albert7e9d2952016-08-04 13:02:36 -07001743func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001744 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001745 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001746 moduleContextImpl: moduleContextImpl{
1747 mod: c,
1748 },
1749 }
1750 ctx.ctx = ctx
1751
Colin Crossca860ac2016-01-04 14:34:37 -08001752 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001753}
1754
Jiyong Park7ed9de32018-10-15 22:25:07 +09001755// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001756func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001757 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1758 version := name[sharp+1:]
1759 libname := name[:sharp]
1760 return libname, version
1761 }
1762 return name, ""
1763}
1764
Colin Cross1e676be2016-10-12 14:38:15 -07001765func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001766 if !c.Enabled() {
1767 return
1768 }
1769
Colin Cross37047f12016-12-13 17:06:13 -08001770 ctx := &depsContext{
1771 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001772 moduleContextImpl: moduleContextImpl{
1773 mod: c,
1774 },
1775 }
1776 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001777
Colin Crossc99deeb2016-04-11 15:06:20 -07001778 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001779
Dan Albert914449f2016-06-17 16:45:24 -07001780 variantNdkLibs := []string{}
1781 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001782 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001783 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001784 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001785 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001786 // 1. Name of an NDK library that refers to a prebuilt module.
1787 // For each of these, it adds the name of the prebuilt module (which will be in
1788 // prebuilts/ndk) to the list of nonvariant libs.
1789 // 2. Name of an NDK library that refers to an ndk_library module.
1790 // For each of these, it adds the name of the ndk_library module to the list of
1791 // variant libs.
1792 // 3. Anything else (so anything that isn't an NDK library).
1793 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001794 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001795 // The caller can then know to add the variantLibs dependencies differently from the
1796 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001797
Inseob Kim9516ee92019-05-09 10:56:13 +09001798 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001799 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1800
1801 rewriteVendorLibs := func(lib string) string {
1802 if isLlndkLibrary(lib, ctx.Config()) {
1803 return lib + llndkLibrarySuffix
1804 }
1805
1806 // only modules with BOARD_VNDK_VERSION uses snapshot.
1807 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1808 return lib
1809 }
1810
1811 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1812 return snapshot
1813 }
1814
1815 return lib
1816 }
1817
1818 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001819 variantLibs = []string{}
1820 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001821 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001822 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001823 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001824 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1825 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001826 } else if ctx.useVndk() {
1827 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001828 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001829 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001830 if actx.OtherModuleExists(vendorPublicLib) {
1831 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1832 } else {
1833 // This can happen if vendor_public_library module is defined in a
1834 // namespace that isn't visible to the current module. In that case,
1835 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001836 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001837 }
Dan Albert914449f2016-06-17 16:45:24 -07001838 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001839 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001840 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001841 }
1842 }
Dan Albert914449f2016-06-17 16:45:24 -07001843 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001844 }
1845
Inseob Kimeec88e12020-01-22 11:11:29 +09001846 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1847 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1848 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1849 if ctx.useVndk() {
1850 for idx, lib := range deps.RuntimeLibs {
1851 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1852 }
1853 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001854 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001855
Jiyong Park7e636d02019-01-28 16:16:54 +09001856 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001857 if c.linker != nil {
1858 if library, ok := c.linker.(*libraryDecorator); ok {
1859 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001860 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001861 }
1862 }
1863 }
1864
Inseob Kimeec88e12020-01-22 11:11:29 +09001865 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1866 // only modules with BOARD_VNDK_VERSION uses snapshot.
1867 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1868 return lib
1869 }
1870
1871 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1872 return snapshot
1873 }
1874
1875 return lib
1876 }
1877
1878 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001879 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001880 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001881 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001882 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001883 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001884
1885 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1886
Jiyong Park7e636d02019-01-28 16:16:54 +09001887 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001888 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001889 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001890 } else {
1891 actx.AddVariationDependencies(nil, depTag, lib)
1892 }
1893 }
1894
1895 if buildStubs {
1896 // Stubs lib does not have dependency to other static/shared libraries.
1897 // Don't proceed.
1898 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001899 }
Colin Cross5950f382016-12-13 12:50:57 -08001900
Inseob Kimc0907f12019-02-08 21:00:45 +09001901 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001902 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001903
Jiyong Park5d1598f2019-02-25 22:14:17 +09001904 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001905 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001906 if impl, ok := syspropImplLibraries[lib]; ok {
1907 lib = impl
1908 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001909
1910 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1911
Jiyong Park5d1598f2019-02-25 22:14:17 +09001912 actx.AddVariationDependencies([]blueprint.Variation{
1913 {Mutator: "link", Variation: "static"},
1914 }, depTag, lib)
1915 }
1916
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001917 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001918 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001919 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001920 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001921 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001922
1923 if impl, ok := syspropImplLibraries[lib]; ok {
1924 lib = impl
1925 }
1926
Inseob Kimeec88e12020-01-22 11:11:29 +09001927 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1928
Dan Willemsen59339a22018-07-22 21:18:45 -07001929 actx.AddVariationDependencies([]blueprint.Variation{
1930 {Mutator: "link", Variation: "static"},
1931 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001932 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001933
Jooyung Han75568392020-03-20 04:29:24 +09001934 // staticUnwinderDep is treated as staticDep for Q apexes
1935 // so that native libraries/binaries are linked with static unwinder
1936 // because Q libc doesn't have unwinder APIs
1937 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001938 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001939 actx.AddVariationDependencies([]blueprint.Variation{
1940 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001941 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001942 }
1943
Inseob Kimeec88e12020-01-22 11:11:29 +09001944 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001945 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001946 actx.AddVariationDependencies([]blueprint.Variation{
1947 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001948 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001949 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001950
Colin Cross6e511a92020-07-27 21:26:48 -07001951 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001952 var variations []blueprint.Variation
1953 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09001954 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001955 // Version is explicitly specified. i.e. libFoo#30
1956 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07001957 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001958 }
1959 actx.AddVariationDependencies(variations, depTag, name)
1960
Jooyung Han03b51852020-02-26 22:45:42 +09001961 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001962 // The stubs library will be used when the depending module is built for APEX and
1963 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09001964 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09001965 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1966 // Note that depTag.ExplicitlyVersioned is false in this case.
1967 actx.AddVariationDependencies([]blueprint.Variation{
1968 {Mutator: "link", Variation: "shared"},
1969 {Mutator: "version", Variation: ver},
1970 }, depTag, name)
1971 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001972 }
1973 }
1974
Jiyong Park7ed9de32018-10-15 22:25:07 +09001975 // shared lib names without the #version suffix
1976 var sharedLibNames []string
1977
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001978 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001979 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001980 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001981 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001982 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001983
1984 if impl, ok := syspropImplLibraries[lib]; ok {
1985 lib = impl
1986 }
1987
Jiyong Park73c54ee2019-10-22 20:31:18 +09001988 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001989 sharedLibNames = append(sharedLibNames, name)
1990
Jiyong Park25fc6a92018-11-18 18:02:45 +09001991 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001992 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001993
Jiyong Park7ed9de32018-10-15 22:25:07 +09001994 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001995 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001996 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1997 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1998 // linking against both the stubs lib and the non-stubs lib at the same time.
1999 continue
2000 }
Colin Cross6e511a92020-07-27 21:26:48 -07002001 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2002 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002003 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002004
Dan Willemsen59339a22018-07-22 21:18:45 -07002005 actx.AddVariationDependencies([]blueprint.Variation{
2006 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002007 }, dataLibDepTag, deps.DataLibs...)
2008
2009 actx.AddVariationDependencies([]blueprint.Variation{
2010 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002011 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002012
Colin Cross68861832016-07-08 10:41:41 -07002013 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002014
2015 for _, gen := range deps.GeneratedHeaders {
2016 depTag := genHeaderDepTag
2017 if inList(gen, deps.ReexportGeneratedHeaders) {
2018 depTag = genHeaderExportDepTag
2019 }
2020 actx.AddDependency(c, depTag, gen)
2021 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002022
Colin Cross42d48b72018-08-29 14:10:52 -07002023 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002024
Inseob Kim1042d292020-06-01 23:23:05 +09002025 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2026
Colin Crossc99deeb2016-04-11 15:06:20 -07002027 if deps.CrtBegin != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002028 actx.AddVariationDependencies(nil, CrtBeginDepTag, rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002029 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002030 if deps.CrtEnd != "" {
Inseob Kim1042d292020-06-01 23:23:05 +09002031 actx.AddVariationDependencies(nil, CrtEndDepTag, rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002032 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002033 if deps.LinkerFlagsFile != "" {
2034 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2035 }
2036 if deps.DynamicLinker != "" {
2037 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002038 }
Dan Albert914449f2016-06-17 16:45:24 -07002039
2040 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002041
2042 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002043 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002044 {Mutator: "ndk_api", Variation: version},
2045 {Mutator: "link", Variation: "shared"},
2046 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002047
2048 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002049 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002050 {Mutator: "ndk_api", Variation: version},
2051 {Mutator: "link", Variation: "shared"},
2052 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002053
2054 if vndkdep := c.vndkdep; vndkdep != nil {
2055 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002056 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002057 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002058 {Mutator: "link", Variation: "shared"},
2059 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002060 }
2061 }
Colin Cross6362e272015-10-29 15:25:03 -07002062}
Colin Cross21b9a242015-03-24 14:15:58 -07002063
Colin Crosse40b4ea2018-10-02 22:25:58 -07002064func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002065 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2066 c.beginMutator(ctx)
2067 }
2068}
2069
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002070// Whether a module can link to another module, taking into
2071// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002072func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2073 tag blueprint.DependencyTag) {
2074
2075 switch t := tag.(type) {
2076 case dependencyTag:
2077 if t != vndkExtDepTag {
2078 return
2079 }
2080 case libraryDependencyTag:
2081 default:
2082 return
2083 }
2084
Ivan Lozano52767be2019-10-18 14:49:46 -07002085 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002086 // Host code is not restricted
2087 return
2088 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002089
2090 // VNDK is cc.Module supported only for now.
2091 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002092 // Though vendor code is limited by the vendor mutator,
2093 // each vendor-available module needs to check
2094 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002095 if ccTo, ok := to.(*Module); ok {
2096 if ccFrom.vndkdep != nil {
2097 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2098 }
2099 } else {
2100 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002101 }
2102 return
2103 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002104 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002105 // Platform code can link to anything
2106 return
2107 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002108 if from.InRamdisk() {
2109 // Ramdisk code is not NDK
2110 return
2111 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002112 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002113 // Recovery code is not NDK
2114 return
2115 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002116 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002117 // These are always allowed
2118 return
2119 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002120 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002121 // These are allowed, but they don't set sdk_version
2122 return
2123 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002124 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002125 // These aren't real libraries, but are the stub shared libraries that are included in
2126 // the NDK.
2127 return
2128 }
Logan Chien834b9a62019-01-14 15:39:03 +08002129
Ivan Lozano52767be2019-10-18 14:49:46 -07002130 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002131 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2132 // to link to libc++ (non-NDK and without sdk_version).
2133 return
2134 }
2135
Ivan Lozano52767be2019-10-18 14:49:46 -07002136 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002137 // NDK code linking to platform code is never okay.
2138 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002139 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002140 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002141 }
2142
2143 // At this point we know we have two NDK libraries, but we need to
2144 // check that we're not linking against anything built against a higher
2145 // API level, as it is only valid to link against older or equivalent
2146 // APIs.
2147
Inseob Kim01a28722018-04-11 09:48:45 +09002148 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002149 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002150 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002151 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002152 // Current can't be linked against by anything else.
2153 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002154 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002155 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002156 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002157 if err != nil {
2158 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002159 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002160 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002161 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002162 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002163 if err != nil {
2164 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002165 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002166 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002167 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002168
Inseob Kim01a28722018-04-11 09:48:45 +09002169 if toApi > fromApi {
2170 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002171 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002172 }
2173 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002174 }
Dan Albert202fe492017-12-15 13:56:59 -08002175
2176 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 fromStl := from.SelectedStl()
2178 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002179 if fromStl == "" || toStl == "" {
2180 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002181 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002182 // We can be permissive with the system "STL" since it is only the C++
2183 // ABI layer, but in the future we should make sure that everyone is
2184 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002185 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002186 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002187 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2188 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002189 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002190}
2191
Jiyong Park5fb8c102018-04-09 12:03:06 +09002192// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002193// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2194// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002195// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002196func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2197 check := func(child, parent android.Module) bool {
2198 to, ok := child.(*Module)
2199 if !ok {
2200 // follow thru cc.Defaults, etc.
2201 return true
2202 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002203
Jooyung Hana70f0672019-01-18 15:20:43 +09002204 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2205 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002206 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002207
2208 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002209 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002210 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002211 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002212
Jooyung Han0302a842019-10-30 18:43:49 +09002213 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002214 return false
2215 }
2216
2217 var stringPath []string
2218 for _, m := range ctx.GetWalkPath() {
2219 stringPath = append(stringPath, m.Name())
2220 }
2221 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2222 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2223 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2224 return false
2225 }
2226 if module, ok := ctx.Module().(*Module); ok {
2227 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002228 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002229 ctx.WalkDeps(check)
2230 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002231 }
2232 }
2233}
2234
Colin Crossc99deeb2016-04-11 15:06:20 -07002235// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002236func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002237 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002238
Ivan Lozano183a3212019-10-18 14:18:45 -07002239 directStaticDeps := []LinkableInterface{}
2240 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002241
Inseob Kim69378442019-06-03 19:10:47 +09002242 reexportExporter := func(exporter exportedFlagsProducer) {
2243 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2244 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2245 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2246 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002247 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002248 }
2249
Jooyung Hande34d232020-07-23 13:04:15 +09002250 // For the dependency from platform to apex, use the latest stubs
2251 c.apexSdkVersion = android.FutureApiLevel
2252 if !c.IsForPlatform() {
2253 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2254 }
2255
2256 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2257 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2258 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2259 // (b/144430859)
2260 c.apexSdkVersion = android.FutureApiLevel
2261 }
2262
Colin Crossd11fcda2017-10-23 17:59:01 -07002263 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002264 depName := ctx.OtherModuleName(dep)
2265 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002266
Ivan Lozano52767be2019-10-18 14:49:46 -07002267 ccDep, ok := dep.(LinkableInterface)
2268 if !ok {
2269
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002270 // handling for a few module types that aren't cc Module but that are also supported
2271 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002272 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002273 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002274 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2275 genRule.GeneratedSourceFiles()...)
2276 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002277 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002278 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002279 // Support exported headers from a generated_sources dependency
2280 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002281 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002282 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002283 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002284 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002285 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002286 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002287 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002288 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002289 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2290 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002291 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002292 // 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 +09002293 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002294
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002295 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002296 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002297 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002298 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002299 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002300 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002301 files := genRule.GeneratedSourceFiles()
2302 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002303 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002304 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002305 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 -07002306 }
2307 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002308 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002309 }
Colin Crossca860ac2016-01-04 14:34:37 -08002310 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002311 return
2312 }
2313
Colin Crossfe17f6f2019-03-28 19:30:56 -07002314 if depTag == android.ProtoPluginDepTag {
2315 return
2316 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002317 if depTag == llndkImplDep {
2318 return
2319 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002320
Colin Crossd11fcda2017-10-23 17:59:01 -07002321 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002322 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2323 return
2324 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002325 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002326 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2327 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002328 return
2329 }
2330
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002331 // re-exporting flags
2332 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002333 // reusing objects only make sense for cc.Modules.
2334 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002335 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002336 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002337 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002338 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002339 return
2340 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002341 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002342
Jiyong Parke4bb9862019-02-01 00:31:10 +09002343 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002344 // staticVariants are a cc.Module specific concept.
2345 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002346 c.staticVariant = ccDep
2347 return
2348 }
2349 }
2350
Colin Cross6e511a92020-07-27 21:26:48 -07002351 checkLinkType(ctx, c, ccDep, depTag)
2352
2353 linkFile := ccDep.OutputFile()
2354
2355 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2356 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2357 if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002358 return
2359 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002360
Colin Cross6e511a92020-07-27 21:26:48 -07002361 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002362 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002363 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002364 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002365 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002366
2367 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002368 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002369 // Always respect dependency to the versioned stubs (i.e. libX#10)
2370 useThisDep = true
2371 } else if !depHasStubs {
2372 // Use non-stub variant if that is the only choice
2373 // (i.e. depending on a lib without stubs.version property)
2374 useThisDep = true
2375 } else if c.IsForPlatform() {
2376 // If not building for APEX, use stubs only when it is from
2377 // an APEX (and not from platform)
2378 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002379 if c.bootstrap() {
2380 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002381 // always link to non-stub variant
2382 useThisDep = !depIsStubs
2383 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002384 for _, testFor := range c.TestFor() {
2385 // Another exception: if this module is bundled with an APEX, then
2386 // it is linked with the non-stub variant of a module in the APEX
2387 // as if this is part of the APEX.
2388 if android.DirectlyInApex(testFor, depName) {
2389 useThisDep = !depIsStubs
2390 break
2391 }
2392 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002393 } else {
2394 // If building for APEX, use stubs only when it is not from
2395 // the same APEX
2396 useThisDep = (depInSameApex != depIsStubs)
2397 }
2398
Jooyung Han03b51852020-02-26 22:45:42 +09002399 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002400 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002401 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002402 if err != nil {
2403 ctx.OtherModuleErrorf(dep, err.Error())
2404 return
2405 }
2406 if versionToUse != ccDep.StubsVersion() {
2407 useThisDep = false
2408 }
2409 }
2410
Jiyong Park25fc6a92018-11-18 18:02:45 +09002411 if !useThisDep {
2412 return // stop processing this dep
2413 }
2414 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002415 if c.UseVndk() {
2416 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2417 // by default, use current version of LLNDK
2418 versionToUse := ""
2419 versions := stubsVersionsFor(ctx.Config())[depName]
2420 if c.ApexName() != "" && len(versions) > 0 {
2421 // if this is for use_vendor apex && dep has stubsVersions
2422 // apply the same rule of apex sdk enforcement to choose right version
2423 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002424 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002425 if err != nil {
2426 ctx.OtherModuleErrorf(dep, err.Error())
2427 return
2428 }
2429 }
2430 if versionToUse != ccDep.StubsVersion() {
2431 return
2432 }
2433 }
2434 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002435
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002436 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2437
Ivan Lozano52767be2019-10-18 14:49:46 -07002438 // Exporting flags only makes sense for cc.Modules
2439 if _, ok := ccDep.(*Module); ok {
2440 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002441 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002442 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002443 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002444
Colin Cross6e511a92020-07-27 21:26:48 -07002445 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002446 reexportExporter(i)
2447 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2448 // Re-exported shared library headers must be included as well since they can help us with type information
2449 // about template instantiations (instantiated from their headers).
2450 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2451 // scripts.
2452 c.sabi.Properties.ReexportedIncludes = append(
2453 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2454 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002455 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002456 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002457
Colin Cross6e511a92020-07-27 21:26:48 -07002458 var ptr *android.Paths
2459 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002460
Colin Cross6e511a92020-07-27 21:26:48 -07002461 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002462
Colin Cross6e511a92020-07-27 21:26:48 -07002463 switch {
2464 case libDepTag.header():
2465 // nothing
2466 case libDepTag.shared():
2467 ptr = &depPaths.SharedLibs
2468 switch libDepTag.Order {
2469 case earlyLibraryDependency:
2470 ptr = &depPaths.EarlySharedLibs
2471 depPtr = &depPaths.EarlySharedLibsDeps
2472 case normalLibraryDependency:
2473 ptr = &depPaths.SharedLibs
2474 depPtr = &depPaths.SharedLibsDeps
2475 directSharedDeps = append(directSharedDeps, ccDep)
2476 case lateLibraryDependency:
2477 ptr = &depPaths.LateSharedLibs
2478 depPtr = &depPaths.LateSharedLibsDeps
2479 default:
2480 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002481 }
Colin Cross6e511a92020-07-27 21:26:48 -07002482 depFile = ccDep.Toc()
2483 case libDepTag.static():
2484 if libDepTag.wholeStatic {
2485 ptr = &depPaths.WholeStaticLibs
2486 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2487 ctx.ModuleErrorf("module %q not a static library", depName)
2488 return
Inseob Kim752edec2020-03-14 01:30:34 +09002489 }
2490
Colin Cross6e511a92020-07-27 21:26:48 -07002491 // Because the static library objects are included, this only makes sense
2492 // in the context of proper cc.Modules.
2493 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2494 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2495 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2496 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2497 for i := range missingDeps {
2498 missingDeps[i] += postfix
2499 }
2500 ctx.AddMissingDependencies(missingDeps)
2501 }
2502 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2503 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2504 } else {
2505 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2506 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002507 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002508 ctx.ModuleErrorf(
2509 "non-cc.Modules cannot be included as whole static libraries.", depName)
2510 return
2511 }
2512
2513 } else {
2514 switch libDepTag.Order {
2515 case earlyLibraryDependency:
2516 panic(fmt.Errorf("early static libs not suppported"))
2517 case normalLibraryDependency:
2518 // static dependencies will be handled separately so they can be ordered
2519 // using transitive dependencies.
2520 ptr = nil
2521 directStaticDeps = append(directStaticDeps, ccDep)
2522 case lateLibraryDependency:
2523 ptr = &depPaths.LateStaticLibs
2524 default:
2525 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002526 }
2527 }
2528 }
2529
Colin Cross6e511a92020-07-27 21:26:48 -07002530 if libDepTag.static() && !libDepTag.wholeStatic {
2531 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2532 ctx.ModuleErrorf("module %q not a static library", depName)
2533 return
2534 }
Logan Chien43d34c32017-12-20 01:17:32 +08002535
Colin Cross6e511a92020-07-27 21:26:48 -07002536 // When combining coverage files for shared libraries and executables, coverage files
2537 // in static libraries act as if they were whole static libraries. The same goes for
2538 // source based Abi dump files.
2539 if c, ok := ccDep.(*Module); ok {
2540 staticLib := c.linker.(libraryInterface)
2541 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2542 staticLib.objs().coverageFiles...)
2543 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2544 staticLib.objs().sAbiDumpFiles...)
2545 } else if c, ok := ccDep.(LinkableInterface); ok {
2546 // Handle non-CC modules here
2547 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2548 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002549 }
2550 }
2551
Colin Cross6e511a92020-07-27 21:26:48 -07002552 if ptr != nil {
2553 if !linkFile.Valid() {
2554 if !ctx.Config().AllowMissingDependencies() {
2555 ctx.ModuleErrorf("module %q missing output file", depName)
2556 } else {
2557 ctx.AddMissingDependencies([]string{depName})
2558 }
2559 return
2560 }
2561 *ptr = append(*ptr, linkFile.Path())
2562 }
2563
2564 if depPtr != nil {
2565 dep := depFile
2566 if !dep.Valid() {
2567 dep = linkFile
2568 }
2569 *depPtr = append(*depPtr, dep.Path())
2570 }
2571
2572 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2573 switch {
2574 case libDepTag.header():
2575 // TODO(ccross): The reexportFlags check is there to maintain previous
2576 // behavior when adding libraryDependencyTag and should be removed.
2577 if !libDepTag.reexportFlags {
2578 c.Properties.AndroidMkHeaderLibs = append(
2579 c.Properties.AndroidMkHeaderLibs, makeLibName)
2580 }
2581 case libDepTag.shared():
2582 if ccDep.CcLibrary() {
2583 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2584 // Add the dependency to the APEX(es) providing the library so that
2585 // m <module> can trigger building the APEXes as well.
2586 for _, an := range android.GetApexesForModule(depName) {
2587 c.Properties.ApexesProvidingSharedLibs = append(
2588 c.Properties.ApexesProvidingSharedLibs, an)
2589 }
2590 }
2591 }
2592
2593 // Note: the order of libs in this list is not important because
2594 // they merely serve as Make dependencies and do not affect this lib itself.
2595 // TODO(ccross): The reexportFlags, order and ndk checks are there to
2596 // maintain previous behavior when adding libraryDependencyTag and
2597 // should be removed.
2598 if !c.static() || libDepTag.reexportFlags || libDepTag.Order == lateLibraryDependency || libDepTag.ndk {
2599 c.Properties.AndroidMkSharedLibs = append(
2600 c.Properties.AndroidMkSharedLibs, makeLibName)
2601 }
2602 // Record baseLibName for snapshots.
2603 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2604 case libDepTag.static():
2605 if libDepTag.wholeStatic {
2606 c.Properties.AndroidMkWholeStaticLibs = append(
2607 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2608 } else {
2609 c.Properties.AndroidMkStaticLibs = append(
2610 c.Properties.AndroidMkStaticLibs, makeLibName)
2611 }
2612 }
2613 } else {
2614 switch depTag {
2615 case runtimeDepTag:
2616 c.Properties.AndroidMkRuntimeLibs = append(
2617 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2618 // Record baseLibName for snapshots.
2619 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2620 case objDepTag:
2621 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2622 case CrtBeginDepTag:
2623 depPaths.CrtBegin = linkFile
2624 case CrtEndDepTag:
2625 depPaths.CrtEnd = linkFile
2626 case dynamicLinkerDepTag:
2627 depPaths.DynamicLinker = linkFile
2628 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002629 }
Colin Crossca860ac2016-01-04 14:34:37 -08002630 })
2631
Jeff Gaston294356f2017-09-27 17:05:30 -07002632 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002633 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002634
Colin Crossdd84e052017-05-17 13:44:16 -07002635 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002636 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002637 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2638 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002639 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002640 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2641 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002642 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002643 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002644 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002645
2646 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002647 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002648 }
Colin Crossdd84e052017-05-17 13:44:16 -07002649
Colin Crossca860ac2016-01-04 14:34:37 -08002650 return depPaths
2651}
2652
Colin Cross6e511a92020-07-27 21:26:48 -07002653// baseLibName trims known prefixes and suffixes
2654func baseLibName(depName string) string {
2655 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2656 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2657 libName = strings.TrimPrefix(libName, "prebuilt_")
2658 return libName
2659}
2660
2661func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2662 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2663 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2664
2665 libName := baseLibName(depName)
2666 isLLndk := isLlndkLibrary(libName, ctx.Config())
2667 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2668 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2669
2670 if c, ok := ccDep.(*Module); ok {
2671 // Use base module name for snapshots when exporting to Makefile.
2672 if c.isSnapshotPrebuilt() {
2673 baseName := c.BaseModuleName()
2674
2675 if c.IsVndk() {
2676 return baseName + ".vendor"
2677 }
2678
2679 if vendorSuffixModules[baseName] {
2680 return baseName + ".vendor"
2681 } else {
2682 return baseName
2683 }
2684 }
2685 }
2686
2687 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2688 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2689 // core module instead.
2690 return libName
2691 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2692 // The vendor module in Make will have been renamed to not conflict with the core
2693 // module, so update the dependency name here accordingly.
2694 return libName + c.getNameSuffixWithVndkVersion(ctx)
2695 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2696 return libName + vendorPublicLibrarySuffix
2697 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2698 return libName + ramdiskSuffix
2699 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2700 return libName + recoverySuffix
2701 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2702 return libName + nativeBridgeSuffix
2703 } else {
2704 return libName
2705 }
2706}
2707
Colin Crossca860ac2016-01-04 14:34:37 -08002708func (c *Module) InstallInData() bool {
2709 if c.installer == nil {
2710 return false
2711 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002712 return c.installer.inData()
2713}
2714
2715func (c *Module) InstallInSanitizerDir() bool {
2716 if c.installer == nil {
2717 return false
2718 }
2719 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002720 return true
2721 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002722 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002723}
2724
Yifan Hong1b3348d2020-01-21 15:53:22 -08002725func (c *Module) InstallInRamdisk() bool {
2726 return c.InRamdisk()
2727}
2728
Jiyong Parkf9332f12018-02-01 00:54:12 +09002729func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002730 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002731}
2732
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002733func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002734 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002735 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002736 return
2737 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002738 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002739}
2740
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002741func (c *Module) HostToolPath() android.OptionalPath {
2742 if c.installer == nil {
2743 return android.OptionalPath{}
2744 }
2745 return c.installer.hostToolPath()
2746}
2747
Nan Zhangd4e641b2017-07-12 12:55:28 -07002748func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2749 return c.outputFile
2750}
2751
Colin Cross41955e82019-05-29 14:40:35 -07002752func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2753 switch tag {
2754 case "":
2755 if c.outputFile.Valid() {
2756 return android.Paths{c.outputFile.Path()}, nil
2757 }
2758 return android.Paths{}, nil
2759 default:
2760 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002761 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002762}
2763
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002764func (c *Module) static() bool {
2765 if static, ok := c.linker.(interface {
2766 static() bool
2767 }); ok {
2768 return static.static()
2769 }
2770 return false
2771}
2772
Jiyong Park379de2f2018-12-19 02:47:14 +09002773func (c *Module) staticBinary() bool {
2774 if static, ok := c.linker.(interface {
2775 staticBinary() bool
2776 }); ok {
2777 return static.staticBinary()
2778 }
2779 return false
2780}
2781
Jiyong Park1d1119f2019-07-29 21:27:18 +09002782func (c *Module) header() bool {
2783 if h, ok := c.linker.(interface {
2784 header() bool
2785 }); ok {
2786 return h.header()
2787 }
2788 return false
2789}
2790
Inseob Kim7f283f42020-06-01 21:53:49 +09002791func (c *Module) binary() bool {
2792 if b, ok := c.linker.(interface {
2793 binary() bool
2794 }); ok {
2795 return b.binary()
2796 }
2797 return false
2798}
2799
Inseob Kim1042d292020-06-01 23:23:05 +09002800func (c *Module) object() bool {
2801 if o, ok := c.linker.(interface {
2802 object() bool
2803 }); ok {
2804 return o.object()
2805 }
2806 return false
2807}
2808
Jooyung Han38002912019-05-16 04:01:54 +09002809func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002810 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002811 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2812 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002813 return "native:vndk"
2814 }
Jooyung Han38002912019-05-16 04:01:54 +09002815 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002816 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002817 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002818 if Bool(c.VendorProperties.Vendor_available) {
2819 return "native:vndk"
2820 }
2821 return "native:vndk_private"
2822 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002823 if c.inProduct() {
2824 return "native:product"
2825 }
Jooyung Han38002912019-05-16 04:01:54 +09002826 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002827 } else if c.InRamdisk() {
2828 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002829 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002830 return "native:recovery"
2831 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2832 return "native:ndk:none:none"
2833 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2834 //family, link := getNdkStlFamilyAndLinkType(c)
2835 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002836 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002837 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002838 } else {
2839 return "native:platform"
2840 }
2841}
2842
Jiyong Park9d452992018-10-03 00:38:19 +09002843// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002844// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002845func (c *Module) IsInstallableToApex() bool {
2846 if shared, ok := c.linker.(interface {
2847 shared() bool
2848 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002849 // Stub libs and prebuilt libs in a versioned SDK are not
2850 // installable to APEX even though they are shared libs.
2851 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002852 } else if _, ok := c.linker.(testPerSrc); ok {
2853 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002854 }
2855 return false
2856}
2857
Jiyong Parka90ca002019-10-07 15:47:24 +09002858func (c *Module) AvailableFor(what string) bool {
2859 if linker, ok := c.linker.(interface {
2860 availableFor(string) bool
2861 }); ok {
2862 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2863 } else {
2864 return c.ApexModuleBase.AvailableFor(what)
2865 }
2866}
2867
Jiyong Park62304bb2020-04-13 16:19:48 +09002868func (c *Module) TestFor() []string {
2869 if test, ok := c.linker.(interface {
2870 testFor() []string
2871 }); ok {
2872 return test.testFor()
2873 } else {
2874 return c.ApexModuleBase.TestFor()
2875 }
2876}
2877
Paul Duffin0cb37b92020-03-04 14:52:46 +00002878// Return true if the module is ever installable.
2879func (c *Module) EverInstallable() bool {
2880 return c.installer != nil &&
2881 // Check to see whether the module is actually ever installable.
2882 c.installer.everInstallable()
2883}
2884
Inseob Kim1f086e22019-05-09 13:29:15 +09002885func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002886 ret := c.EverInstallable() &&
2887 // Check to see whether the module has been configured to not be installed.
2888 proptools.BoolDefault(c.Properties.Installable, true) &&
2889 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002890
2891 // The platform variant doesn't need further condition. Apex variants however might not
2892 // be installable because it will likely to be included in the APEX and won't appear
2893 // in the system partition.
2894 if c.IsForPlatform() {
2895 return ret
2896 }
2897
2898 // Special case for modules that are configured to be installed to /data, which includes
2899 // test modules. For these modules, both APEX and non-APEX variants are considered as
2900 // installable. This is because even the APEX variants won't be included in the APEX, but
2901 // will anyway be installed to /data/*.
2902 // See b/146995717
2903 if c.InstallInData() {
2904 return ret
2905 }
2906
2907 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002908}
2909
Logan Chien41eabe62019-04-10 13:33:58 +08002910func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2911 if c.linker != nil {
2912 if library, ok := c.linker.(*libraryDecorator); ok {
2913 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2914 }
2915 }
2916}
2917
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002918func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002919 depTag := ctx.OtherModuleDependencyTag(dep)
2920 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2921
2922 if cc, ok := dep.(*Module); ok {
2923 if cc.HasStubsVariants() {
2924 if isLibDepTag && libDepTag.shared() {
2925 // dynamic dep to a stubs lib crosses APEX boundary
2926 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002927 }
Colin Cross6e511a92020-07-27 21:26:48 -07002928 if IsRuntimeDepTag(depTag) {
2929 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002930 return false
2931 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002932 }
Colin Cross6e511a92020-07-27 21:26:48 -07002933 // TODO(ccross): The libDepTag.reexportFlags is there to maintain previous behavior
2934 // when adding libraryDependencyTag and should be removed.
2935 if isLibDepTag && c.static() && libDepTag.shared() && !libDepTag.reexportFlags {
2936 // shared_lib dependency from a static lib is considered as crossing
2937 // the APEX boundary because the dependency doesn't actually is
2938 // linked; the dependency is used only during the compilation phase.
2939 return false
2940 }
2941 }
2942 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09002943 // We don't track beyond LLNDK
2944 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002945 }
2946 return true
2947}
2948
Jooyung Han749dc692020-04-15 11:03:39 +09002949// b/154667674: refactor this to handle "current" in a consistent way
2950func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
2951 if versionString == "" {
2952 return 0, fmt.Errorf("not specified")
2953 }
2954 if versionString == "current" {
2955 if ctx.Config().PlatformSdkCodename() == "REL" {
2956 return ctx.Config().PlatformSdkVersionInt(), nil
2957 }
2958 return android.FutureApiLevel, nil
2959 }
2960 return android.ApiStrToNum(ctx, versionString)
2961}
2962
2963func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
2964 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
2965 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
2966 return nil
2967 }
2968 // b/154569636: set min_sdk_version correctly for toolchain_libraries
2969 if c.ToolchainLibrary() {
2970 return nil
2971 }
2972 // We don't check for prebuilt modules
2973 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
2974 return nil
2975 }
2976 minSdkVersion := c.MinSdkVersion()
2977 if minSdkVersion == "apex_inherit" {
2978 return nil
2979 }
2980 if minSdkVersion == "" {
2981 // JNI libs within APK-in-APEX fall into here
2982 // Those are okay to set sdk_version instead
2983 // We don't have to check if this is a SDK variant because
2984 // non-SDK variant resets sdk_version, which works too.
2985 minSdkVersion = c.SdkVersion()
2986 }
2987 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
2988 if err != nil {
2989 return err
2990 }
2991 if ver > sdkVersion {
2992 return fmt.Errorf("newer SDK(%v)", ver)
2993 }
2994 return nil
2995}
2996
Colin Cross2ba19d92015-05-07 15:44:20 -07002997//
Colin Crosscfad1192015-11-02 16:43:11 -08002998// Defaults
2999//
Colin Crossca860ac2016-01-04 14:34:37 -08003000type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003001 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003002 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003003 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003004}
3005
Patrice Arrudac249c712019-03-19 17:00:29 -07003006// cc_defaults provides a set of properties that can be inherited by other cc
3007// modules. A module can use the properties from a cc_defaults using
3008// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3009// merged (when possible) by prepending the default module's values to the
3010// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003011func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003012 return DefaultsFactory()
3013}
3014
Colin Cross36242852017-06-23 15:06:31 -07003015func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003016 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003017
Colin Cross36242852017-06-23 15:06:31 -07003018 module.AddProperties(props...)
3019 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003020 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003021 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003022 &BaseCompilerProperties{},
3023 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003024 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003025 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003026 &StaticProperties{},
3027 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003028 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003029 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003030 &TestProperties{},
3031 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003032 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003033 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003034 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003035 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003036 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003037 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003038 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003039 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003040 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003041 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003042 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003043 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003044 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003045 )
Colin Crosscfad1192015-11-02 16:43:11 -08003046
Jooyung Hancc372c52019-09-25 15:18:44 +09003047 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003048
3049 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003050}
3051
Jiyong Park6a43f042017-10-12 23:05:00 +09003052func squashVendorSrcs(m *Module) {
3053 if lib, ok := m.compiler.(*libraryDecorator); ok {
3054 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3055 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3056
3057 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3058 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003059
3060 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3061 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003062 }
3063}
3064
Jiyong Parkf9332f12018-02-01 00:54:12 +09003065func squashRecoverySrcs(m *Module) {
3066 if lib, ok := m.compiler.(*libraryDecorator); ok {
3067 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3068 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3069
3070 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3071 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003072
3073 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3074 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003075 }
3076}
3077
Jiyong Park2286afd2020-06-16 21:58:53 +09003078func (c *Module) IsSdkVariant() bool {
3079 return c.Properties.IsSdkVariant
3080}
3081
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003082func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003083 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003084 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3085 }
Colin Cross6510f912017-11-29 00:27:14 -08003086 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003087}
3088
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003089func kytheExtractAllFactory() android.Singleton {
3090 return &kytheExtractAllSingleton{}
3091}
3092
3093type kytheExtractAllSingleton struct {
3094}
3095
3096func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3097 var xrefTargets android.Paths
3098 ctx.VisitAllModules(func(module android.Module) {
3099 if ccModule, ok := module.(xref); ok {
3100 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3101 }
3102 })
3103 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3104 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003105 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003106 }
3107}
3108
Colin Cross06a931b2015-10-28 17:23:31 -07003109var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003110var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003111var BoolPtr = proptools.BoolPtr
3112var String = proptools.String
3113var StringPtr = proptools.StringPtr