blob: 7baaa66b55abbcb58be33fa861d60ee3e9f5b95f [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()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Colin Crossd1f898e2020-08-18 18:35:15 -070049 ctx.BottomUp("version_selector", versionSelectorMutator).Parallel()
50 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
Jooyung Han479ca172020-10-19 18:51:07 +090087 ctx.BottomUp("check_linktype", checkLinkTypeMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090088 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070089 })
Colin Crossb98c8b02016-07-29 13:44:28 -070090
Colin Cross57898582020-10-29 18:25:19 -070091 ctx.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070092}
93
Chris Parsonsef6e0cf2020-12-01 18:26:21 -050094// Deps is a struct containing module names of dependencies, separated by the kind of dependency.
95// Mutators should use `AddVariationDependencies` or its sibling methods to add actual dependency
96// edges to these modules.
97// This object is constructed in DepsMutator, by calling to various module delegates to set
98// relevant fields. For example, `module.compiler.compilerDeps()` may append type-specific
99// dependencies.
100// This is then consumed by the same DepsMutator, which will call `ctx.AddVariationDependencies()`
101// (or its sibling methods) to set real dependencies on the given modules.
Colin Crossca860ac2016-01-04 14:34:37 -0800102type Deps struct {
103 SharedLibs, LateSharedLibs []string
104 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -0800105 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +0800106 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -0700107
Chris Parsons79d66a52020-06-05 17:26:16 -0400108 // Used for data dependencies adjacent to tests
109 DataLibs []string
110
Yo Chiang219968c2020-09-22 18:45:04 +0800111 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
112 SystemSharedLibs []string
113
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500114 // If true, statically link the unwinder into native libraries/binaries.
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800115 StaticUnwinderIfLegacy bool
116
Colin Cross5950f382016-12-13 12:50:57 -0800117 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700118
Colin Cross81413472016-04-11 14:37:39 -0700119 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Dan Willemsenb40aab62016-04-20 14:21:14 -0700121 GeneratedSources []string
122 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900123 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700124
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700125 ReexportGeneratedHeaders []string
126
Colin Cross97ba0732015-03-23 17:50:24 -0700127 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700128
129 // Used for host bionic
130 LinkerFlagsFile string
131 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700132}
133
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500134// PathDeps is a struct containing file paths to dependencies of a module.
135// It's constructed in depsToPath() by traversing the direct dependencies of the current module.
136// It's used to construct flags for various build statements (such as for compiling and linking).
137// It is then passed to module decorator functions responsible for registering build statements
138// (such as `module.compiler.compile()`).`
Colin Crossca860ac2016-01-04 14:34:37 -0800139type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700140 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900141 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700142 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900143 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700146
Colin Cross0de8a1e2020-09-18 14:15:30 -0700147 // Transitive static library dependencies of static libraries for use in ordering.
148 TranstiveStaticLibrariesForOrdering *android.DepSet
149
Colin Cross26c34ed2016-09-30 17:10:16 -0700150 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100151 Objs Objects
152 // Paths to .o files in dependencies that provide them. Note that these lists
153 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800154 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700155 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700156
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100157 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
158 // the libs from all whole_static_lib dependencies.
159 WholeStaticLibsFromPrebuilts android.Paths
160
Colin Cross26c34ed2016-09-30 17:10:16 -0700161 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700162 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900163 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700164
Inseob Kimd110f872019-12-06 13:15:38 +0900165 Flags []string
166 IncludeDirs android.Paths
167 SystemIncludeDirs android.Paths
168 ReexportedDirs android.Paths
169 ReexportedSystemDirs android.Paths
170 ReexportedFlags []string
171 ReexportedGeneratedHeaders android.Paths
172 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700173
Colin Cross26c34ed2016-09-30 17:10:16 -0700174 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700175 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700176
177 // Path to the file container flags to use with the linker
178 LinkerFlagsFile android.OptionalPath
179
180 // Path to the dynamic linker binary
181 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700182}
183
Colin Cross4af21ed2019-11-04 09:37:55 -0800184// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
185// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
186// command line so they can be overridden by the local module flags).
187type LocalOrGlobalFlags struct {
188 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700189 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800190 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700191 CFlags []string // Flags that apply to C and C++ source files
192 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
193 ConlyFlags []string // Flags that apply to C source files
194 CppFlags []string // Flags that apply to C++ source files
195 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700196 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800197}
198
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500199// Flags contains various types of command line flags (and settings) for use in building build
200// statements related to C++.
Colin Cross4af21ed2019-11-04 09:37:55 -0800201type Flags struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500202 // Local flags (which individual modules are responsible for). These may override global flags.
203 Local LocalOrGlobalFlags
204 // Global flags (which build system or toolchain is responsible for).
Colin Cross4af21ed2019-11-04 09:37:55 -0800205 Global LocalOrGlobalFlags
206
207 aidlFlags []string // Flags that apply to aidl source files
208 rsFlags []string // Flags that apply to renderscript source files
209 libFlags []string // Flags to add libraries early to the link order
210 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
211 TidyFlags []string // Flags that apply to clang-tidy
212 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700213
Colin Crossc3199482017-03-30 15:03:04 -0700214 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800215 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700216 SystemIncludeFlags []string
217
Oliver Nguyen04526782020-04-21 12:40:27 -0700218 Toolchain config.Toolchain
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500219 Tidy bool // True if clang-tidy is enabled.
220 GcovCoverage bool // True if coverage files should be generated.
221 SAbiDump bool // True if header abi dumps should be generated.
Oliver Nguyen04526782020-04-21 12:40:27 -0700222 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800223
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500224 // The instruction set required for clang ("arm" or "thumb").
Colin Crossca860ac2016-01-04 14:34:37 -0800225 RequiredInstructionSet string
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500226 // The target-device system path to the dynamic linker.
227 DynamicLinker string
Colin Cross16b23492016-01-06 14:41:07 -0800228
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700229 CFlagsDeps android.Paths // Files depended on by compiler flags
230 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800231
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500232 // True if .s files should be processed with the c preprocessor.
Dan Willemsen98ab3112019-08-27 21:20:40 -0700233 AssemblerWithCpp bool
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500234 // True if static libraries should be grouped (using `-Wl,--start-group` and `-Wl,--end-group`).
235 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800236
Colin Cross19878da2019-03-28 14:45:07 -0700237 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700238 protoC bool // Whether to use C instead of C++
239 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700240
241 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200242 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700243}
244
Colin Crossca860ac2016-01-04 14:34:37 -0800245// Properties used to compile all C or C++ modules
246type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700247 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800248 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700249
Colin Crossc511bc52020-04-07 16:50:32 +0000250 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
251 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800252 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700253
Jooyung Han379660c2020-04-21 15:24:00 +0900254 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
255 Min_sdk_version *string
256
Colin Crossc511bc52020-04-07 16:50:32 +0000257 // If true, always create an sdk variant and don't create a platform variant.
258 Sdk_variant_only *bool
259
Jiyong Parkde866cb2018-12-07 23:08:36 +0900260 AndroidMkSharedLibs []string `blueprint:"mutated"`
261 AndroidMkStaticLibs []string `blueprint:"mutated"`
262 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
263 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700264 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900265 HideFromMake bool `blueprint:"mutated"`
266 PreventInstall bool `blueprint:"mutated"`
267 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700268
Yo Chiang219968c2020-09-22 18:45:04 +0800269 // Set by DepsMutator.
270 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
271
Justin Yun5f7f7e82019-11-18 19:52:14 +0900272 ImageVariationPrefix string `blueprint:"mutated"`
273 VndkVersion string `blueprint:"mutated"`
274 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800275
276 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
277 // file
278 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900279
Yifan Hong39143a92020-10-26 12:43:12 -0700280 // Make this module available when building for ramdisk.
281 // On device without a dedicated recovery partition, the module is only
282 // available after switching root into
283 // /first_stage_ramdisk. To expose the module before switching root, install
284 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -0800285 Ramdisk_available *bool
286
Yifan Hong39143a92020-10-26 12:43:12 -0700287 // Make this module available when building for vendor ramdisk.
288 // On device without a dedicated recovery partition, the module is only
289 // available after switching root into
290 // /first_stage_ramdisk. To expose the module before switching root, install
291 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700292 Vendor_ramdisk_available *bool
293
Jiyong Parkf9332f12018-02-01 00:54:12 +0900294 // Make this module available when building for recovery
295 Recovery_available *bool
296
Colin Crossae6c5202019-11-20 13:35:50 -0800297 // Set by imageMutator
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700298 CoreVariantNeeded bool `blueprint:"mutated"`
299 RamdiskVariantNeeded bool `blueprint:"mutated"`
300 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
301 RecoveryVariantNeeded bool `blueprint:"mutated"`
302 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900303
304 // Allows this module to use non-APEX version of libraries. Useful
305 // for building binaries that are started before APEXes are activated.
306 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900307
308 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
309 // see soong/cc/config/vndk.go
310 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900311
312 // Used by vendor snapshot to record dependencies from snapshot modules.
313 SnapshotSharedLibs []string `blueprint:"mutated"`
314 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000315
316 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000317
318 // Set by factories of module types that can only be referenced from variants compiled against
319 // the SDK.
320 AlwaysSdk bool `blueprint:"mutated"`
321
322 // Variant is an SDK variant created by sdkMutator
323 IsSdkVariant bool `blueprint:"mutated"`
324 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
325 // variant to have a ".sdk" suffix.
326 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700327
328 // Normally Soong uses the directory structure to decide which modules
329 // should be included (framework) or excluded (non-framework) from the
Jose Galmesf7294582020-11-13 12:07:36 -0800330 // different snapshots (vendor, recovery, etc.), but these properties
331 // allow a partner to exclude a module normally thought of as a
332 // framework module from a snapshot.
333 Exclude_from_vendor_snapshot *bool
334 Exclude_from_recovery_snapshot *bool
Jiyong Park46a512f2020-12-04 18:02:13 +0900335
336 // List of APEXes that this module has private access to for testing purpose. The module
337 // can depend on libraries that are not exported by the APEXes and use private symbols
338 // from the exported libraries.
339 Test_for []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700340}
341
342type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900343 // whether this module should be allowed to be directly depended by other
344 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun63e9ec72020-10-29 16:49:43 +0900345 // If set to true, two variants will be built separately, one like
346 // normal, and the other limited to the set of libraries and headers
347 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700348 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900349 // The vendor variant may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700350 // so it shouldn't have any unversioned runtime dependencies, or
351 // make assumptions about the system that may not be true in the
352 // future.
353 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900354 // If set to false, this module becomes inaccessible from /vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900355 //
356 // Default value is true when vndk: {enabled: true} or vendor: true.
357 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700358 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
359 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900360
Justin Yun63e9ec72020-10-29 16:49:43 +0900361 // whether this module should be allowed to be directly depended by other
362 // modules with `product_specific: true` or `product_available: true`.
363 // If set to true, an additional product variant will be built separately
364 // that is limited to the set of libraries and headers that are exposed to
365 // /product modules.
366 //
367 // The product variant may be used with a different (newer) /system,
368 // so it shouldn't have any unversioned runtime dependencies, or
369 // make assumptions about the system that may not be true in the
370 // future.
371 //
372 // It must be set to true by default for vndk: {enabled: true} modules.
373 //
374 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
375 // and PRODUCT_PRODUCT_VNDK_VERSION isn't set.
376 Product_available *bool
377
Jiyong Park5fb8c102018-04-09 12:03:06 +0900378 // whether this module is capable of being loaded with other instance
379 // (possibly an older version) of the same module in the same process.
380 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
381 // can be double loaded in a vendor process if the library is also a
382 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
383 // explicitly marked as `double_loadable: true` by the owner, or the dependency
384 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
385 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800386}
387
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500388// ModuleContextIntf is an interface (on a module context helper) consisting of functions related
389// to understanding details about the type of the current module.
390// For example, one might call these functions to determine whether the current module is a static
391// library and/or is installed in vendor directories.
Colin Crossca860ac2016-01-04 14:34:37 -0800392type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800393 static() bool
394 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900395 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900396 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900397 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700398 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900399 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700400 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800401 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700402 useVndk() bool
Colin Cross95f1ca02020-10-29 20:47:22 -0700403 isNdk(config android.Config) bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900404 isLlndk(config android.Config) bool
405 isLlndkPublic(config android.Config) bool
406 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900407 isVndk() bool
408 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800409 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900410 inProduct() bool
411 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800412 inRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700413 inVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900414 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800415 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700416 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700417 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800418 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800419 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800420 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800421 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800422 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700423 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700424 apexSdkVersion() android.ApiLevel
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900425 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800426 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700427 nativeCoverage() bool
Colin Cross56a83212020-09-15 18:30:11 -0700428 directlyInAnyApex() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800429}
430
431type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700432 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800433 ModuleContextIntf
434}
435
436type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700437 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800438 ModuleContextIntf
439}
440
Colin Cross37047f12016-12-13 17:06:13 -0800441type DepsContext interface {
442 android.BottomUpMutatorContext
443 ModuleContextIntf
444}
445
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500446// feature represents additional (optional) steps to building cc-related modules, such as invocation
447// of clang-tidy.
Colin Crossca860ac2016-01-04 14:34:37 -0800448type feature interface {
449 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800450 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800451 flags(ctx ModuleContext, flags Flags) Flags
452 props() []interface{}
453}
454
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500455// compiler is the interface for a compiler helper object. Different module decorators may implement
456// this helper differently. For example, compiling a `cc_library` may use a different build
457// statement than building a `toolchain_library`.
Colin Crossca860ac2016-01-04 14:34:37 -0800458type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700459 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800460 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800461 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700462 compilerProps() []interface{}
463
Colin Cross76fada02016-07-27 10:31:13 -0700464 appendCflags([]string)
465 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700466 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800467}
468
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500469// linker is the interface for a linker decorator object. Individual module types can provide
470// their own implementation for this decorator, and thus specify custom logic regarding build
471// statements pertaining to linking.
Colin Crossca860ac2016-01-04 14:34:37 -0800472type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700473 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800474 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700475 linkerFlags(ctx ModuleContext, flags Flags) Flags
476 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800477 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700478
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700479 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700480 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900481 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700482
483 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900484 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000485
486 // Get the deps that have been explicitly specified in the properties.
Paul Duffin13f02712020-03-06 12:30:43 +0000487 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
488}
489
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500490// specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
Paul Duffin13f02712020-03-06 12:30:43 +0000491type specifiedDeps struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500492 sharedLibs []string
493 // Note nil and [] are semantically distinct. [] prevents linking against the defaults (usually
494 // libc, libm, etc.)
495 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800496}
497
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500498// installer is the interface for an installer helper object. This helper is responsible for
499// copying build outputs to the appropriate locations so that they may be installed on device.
Colin Crossca860ac2016-01-04 14:34:37 -0800500type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700501 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700502 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000503 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800504 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700505 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700506 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900507 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100508 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800509}
510
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800511type xref interface {
512 XrefCcFiles() android.Paths
513}
514
Colin Cross6e511a92020-07-27 21:26:48 -0700515type libraryDependencyKind int
516
517const (
518 headerLibraryDependency = iota
519 sharedLibraryDependency
520 staticLibraryDependency
521)
522
523func (k libraryDependencyKind) String() string {
524 switch k {
525 case headerLibraryDependency:
526 return "headerLibraryDependency"
527 case sharedLibraryDependency:
528 return "sharedLibraryDependency"
529 case staticLibraryDependency:
530 return "staticLibraryDependency"
531 default:
532 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
533 }
534}
535
536type libraryDependencyOrder int
537
538const (
539 earlyLibraryDependency = -1
540 normalLibraryDependency = 0
541 lateLibraryDependency = 1
542)
543
544func (o libraryDependencyOrder) String() string {
545 switch o {
546 case earlyLibraryDependency:
547 return "earlyLibraryDependency"
548 case normalLibraryDependency:
549 return "normalLibraryDependency"
550 case lateLibraryDependency:
551 return "lateLibraryDependency"
552 default:
553 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
554 }
555}
556
557// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
558// tags that have a set of predefined tag objects that are reused for each dependency, a
559// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
560// That means that comparing a libraryDependencyTag for equality will only be equal if all
561// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
562// then check individual metadata fields instead.
563type libraryDependencyTag struct {
564 blueprint.BaseDependencyTag
565
566 // These are exported so that fmt.Printf("%#v") can call their String methods.
567 Kind libraryDependencyKind
568 Order libraryDependencyOrder
569
570 wholeStatic bool
571
572 reexportFlags bool
573 explicitlyVersioned bool
574 dataLib bool
575 ndk bool
576
577 staticUnwinder bool
578
579 makeSuffix string
580}
581
582// header returns true if the libraryDependencyTag is tagging a header lib dependency.
583func (d libraryDependencyTag) header() bool {
584 return d.Kind == headerLibraryDependency
585}
586
587// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
588func (d libraryDependencyTag) shared() bool {
589 return d.Kind == sharedLibraryDependency
590}
591
592// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
593func (d libraryDependencyTag) static() bool {
594 return d.Kind == staticLibraryDependency
595}
596
Colin Crosse9fe2942020-11-10 18:12:15 -0800597// InstallDepNeeded returns true for shared libraries so that shared library dependencies of
598// binaries or other shared libraries are installed as dependencies.
599func (d libraryDependencyTag) InstallDepNeeded() bool {
600 return d.shared()
601}
602
603var _ android.InstallNeededDependencyTag = libraryDependencyTag{}
604
605// dependencyTag is used for tagging miscellaneous dependency types that don't fit into
Colin Cross6e511a92020-07-27 21:26:48 -0700606// libraryDependencyTag. Each tag object is created globally and reused for multiple
607// dependencies (although since the object contains no references, assigning a tag to a
608// variable and modifying it will not modify the original). Users can compare the tag
609// returned by ctx.OtherModuleDependencyTag against the global original
610type dependencyTag struct {
611 blueprint.BaseDependencyTag
612 name string
613}
614
Colin Crosse9fe2942020-11-10 18:12:15 -0800615// installDependencyTag is used for tagging miscellaneous dependency types that don't fit into
616// libraryDependencyTag, but where the dependency needs to be installed when the parent is
617// installed.
618type installDependencyTag struct {
619 blueprint.BaseDependencyTag
620 android.InstallAlwaysNeededDependencyTag
621 name string
622}
623
Colin Crossc99deeb2016-04-11 15:06:20 -0700624var (
Colin Cross6e511a92020-07-27 21:26:48 -0700625 genSourceDepTag = dependencyTag{name: "gen source"}
626 genHeaderDepTag = dependencyTag{name: "gen header"}
627 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
628 objDepTag = dependencyTag{name: "obj"}
629 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
Jiyong Parkd630bdd2020-11-25 11:47:24 +0900630 dynamicLinkerDepTag = installDependencyTag{name: "dynamic linker"}
Colin Cross6e511a92020-07-27 21:26:48 -0700631 reuseObjTag = dependencyTag{name: "reuse objects"}
632 staticVariantTag = dependencyTag{name: "static variant"}
633 vndkExtDepTag = dependencyTag{name: "vndk extends"}
634 dataLibDepTag = dependencyTag{name: "data lib"}
Colin Crosse9fe2942020-11-10 18:12:15 -0800635 runtimeDepTag = installDependencyTag{name: "runtime lib"}
Colin Cross6e511a92020-07-27 21:26:48 -0700636 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700637 stubImplDepTag = dependencyTag{name: "stub_impl"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700638)
639
Colin Cross56a83212020-09-15 18:30:11 -0700640type copyDirectlyInAnyApexDependencyTag dependencyTag
641
642func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
643
644var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
645
Roland Levillainf89cd092019-07-29 16:22:59 +0100646func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700647 ccLibDepTag, ok := depTag.(libraryDependencyTag)
648 return ok && ccLibDepTag.shared()
649}
650
651func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
652 ccLibDepTag, ok := depTag.(libraryDependencyTag)
653 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100654}
655
Zach Johnson3df4e632020-11-06 11:56:27 -0800656func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
657 ccLibDepTag, ok := depTag.(libraryDependencyTag)
658 return ok && ccLibDepTag.header()
659}
660
Roland Levillainf89cd092019-07-29 16:22:59 +0100661func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Crosse9fe2942020-11-10 18:12:15 -0800662 return depTag == runtimeDepTag
Roland Levillainf89cd092019-07-29 16:22:59 +0100663}
664
665func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700666 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100667 return ok && ccDepTag == testPerSrcDepTag
668}
669
Colin Crossca860ac2016-01-04 14:34:37 -0800670// Module contains the properties and members used by all C/C++ module types, and implements
671// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500672// to construct the output file. Behavior can be customized with a Customizer, or "decorator",
673// interface.
674//
675// To define a C/C++ related module, construct a new Module object and point its delegates to
676// type-specific structs. These delegates will be invoked to register module-specific build
677// statements which may be unique to the module type. For example, module.compiler.compile() should
678// be defined so as to register build statements which are responsible for compiling the module.
679//
680// Another example: to construct a cc_binary module, one can create a `cc.binaryDecorator` struct
681// which implements the `linker` and `installer` interfaces, and points the `linker` and `installer`
682// members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
683// installer logic.
Colin Crossca860ac2016-01-04 14:34:37 -0800684type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700685 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700686 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900687 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900688 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700689
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700690 Properties BaseProperties
691 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700692
Colin Crossca860ac2016-01-04 14:34:37 -0800693 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700694 hod android.HostOrDeviceSupported
695 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700696
Paul Duffina0843f62019-12-13 19:50:38 +0000697 // Allowable SdkMemberTypes of this module type.
698 sdkMemberTypes []android.SdkMemberType
699
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500700 // decorator delegates, initialize before calling Init
701 // these may contain module-specific implementations, and effectively allow for custom
702 // type-specific logic. These members may reference different objects or the same object.
703 // Functions of these decorators will be invoked to initialize and register type-specific
704 // build statements.
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700705 compiler compiler
706 linker linker
707 installer installer
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500708
709 features []feature
710 stl *stl
711 sanitize *sanitize
712 coverage *coverage
713 sabi *sabi
714 vndkdep *vndkdep
715 lto *lto
716 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800717
Colin Cross31076b32020-10-23 17:22:06 -0700718 library libraryInterface
719
Colin Cross635c3b02016-05-18 15:37:25 -0700720 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800721
Colin Crossb98c8b02016-07-29 13:44:28 -0700722 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700723
724 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800725
726 // Flags used to compile this module
727 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700728
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800729 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700730 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900731
732 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800733 // Kythe (source file indexer) paths for this compilation module
734 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900735
736 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700737 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700738
739 hideApexVariantFromMake bool
Colin Crossc472d572015-03-17 15:06:21 -0700740}
741
Ivan Lozano52767be2019-10-18 14:49:46 -0700742func (c *Module) Toc() android.OptionalPath {
743 if c.linker != nil {
744 if library, ok := c.linker.(libraryInterface); ok {
745 return library.toc()
746 }
747 }
748 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
749}
750
751func (c *Module) ApiLevel() string {
752 if c.linker != nil {
753 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700754 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700755 }
756 }
757 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
758}
759
760func (c *Module) Static() bool {
761 if c.linker != nil {
762 if library, ok := c.linker.(libraryInterface); ok {
763 return library.static()
764 }
765 }
766 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
767}
768
769func (c *Module) Shared() bool {
770 if c.linker != nil {
771 if library, ok := c.linker.(libraryInterface); ok {
772 return library.shared()
773 }
774 }
775 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
776}
777
778func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000779 if c.stl != nil {
780 return c.stl.Properties.SelectedStl
781 }
782 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700783}
784
785func (c *Module) ToolchainLibrary() bool {
786 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
787 return true
788 }
789 return false
790}
791
792func (c *Module) NdkPrebuiltStl() bool {
793 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
794 return true
795 }
796 return false
797}
798
799func (c *Module) StubDecorator() bool {
800 if _, ok := c.linker.(*stubDecorator); ok {
801 return true
802 }
803 return false
804}
805
806func (c *Module) SdkVersion() string {
807 return String(c.Properties.Sdk_version)
808}
809
Artur Satayev480e25b2020-04-27 18:53:18 +0100810func (c *Module) MinSdkVersion() string {
811 return String(c.Properties.Min_sdk_version)
812}
813
Dan Albert92fe7402020-07-15 13:33:30 -0700814func (c *Module) SplitPerApiLevel() bool {
Colin Cross1348ce32020-10-01 13:37:16 -0700815 if !c.canUseSdk() {
816 return false
817 }
Dan Albert92fe7402020-07-15 13:33:30 -0700818 if linker, ok := c.linker.(*objectLinker); ok {
819 return linker.isCrt()
820 }
821 return false
822}
823
Colin Crossc511bc52020-04-07 16:50:32 +0000824func (c *Module) AlwaysSdk() bool {
825 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
826}
827
Ivan Lozano183a3212019-10-18 14:18:45 -0700828func (c *Module) CcLibrary() bool {
829 if c.linker != nil {
830 if _, ok := c.linker.(*libraryDecorator); ok {
831 return true
832 }
Colin Crossd48fe732020-09-23 20:37:24 -0700833 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
834 return true
835 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700836 }
837 return false
838}
839
840func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700841 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700842 return true
843 }
844 return false
845}
846
Ivan Lozano2b262972019-11-21 12:30:50 -0800847func (c *Module) NonCcVariants() bool {
848 return false
849}
850
Ivan Lozano183a3212019-10-18 14:18:45 -0700851func (c *Module) SetStatic() {
852 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700853 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700854 library.setStatic()
855 return
856 }
857 }
858 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
859}
860
861func (c *Module) SetShared() {
862 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700863 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700864 library.setShared()
865 return
866 }
867 }
868 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
869}
870
871func (c *Module) BuildStaticVariant() bool {
872 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700873 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700874 return library.buildStatic()
875 }
876 }
877 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
878}
879
880func (c *Module) BuildSharedVariant() bool {
881 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700882 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700883 return library.buildShared()
884 }
885 }
886 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
887}
888
889func (c *Module) Module() android.Module {
890 return c
891}
892
Jiyong Parkc20eee32018-09-05 22:36:17 +0900893func (c *Module) OutputFile() android.OptionalPath {
894 return c.outputFile
895}
896
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400897func (c *Module) CoverageFiles() android.Paths {
898 if c.linker != nil {
899 if library, ok := c.linker.(libraryInterface); ok {
900 return library.objs().coverageFiles
901 }
902 }
903 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
904}
905
Ivan Lozano183a3212019-10-18 14:18:45 -0700906var _ LinkableInterface = (*Module)(nil)
907
Jiyong Park719b4462019-01-13 00:39:51 +0900908func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900909 if c.linker != nil {
910 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900911 }
912 return nil
913}
914
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900915func (c *Module) CoverageOutputFile() android.OptionalPath {
916 if c.linker != nil {
917 return c.linker.coverageOutputFilePath()
918 }
919 return android.OptionalPath{}
920}
921
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900922func (c *Module) RelativeInstallPath() string {
923 if c.installer != nil {
924 return c.installer.relativeInstallPath()
925 }
926 return ""
927}
928
Jooyung Han344d5432019-08-23 11:17:39 +0900929func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900930 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900931}
932
Colin Cross36242852017-06-23 15:06:31 -0700933func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700934 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800935 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700936 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800937 }
938 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700939 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800940 }
941 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700942 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800943 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700944 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700945 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700946 }
Colin Cross16b23492016-01-06 14:41:07 -0800947 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700948 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800949 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800950 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700951 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800952 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800953 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700954 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800955 }
Justin Yun8effde42017-06-23 19:24:43 +0900956 if c.vndkdep != nil {
957 c.AddProperties(c.vndkdep.props()...)
958 }
Stephen Craneba090d12017-05-09 15:44:35 -0700959 if c.lto != nil {
960 c.AddProperties(c.lto.props()...)
961 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700962 if c.pgo != nil {
963 c.AddProperties(c.pgo.props()...)
964 }
Colin Crossca860ac2016-01-04 14:34:37 -0800965 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700966 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800967 }
Colin Crossc472d572015-03-17 15:06:21 -0700968
Jiyong Park1613e552020-09-14 19:43:17 +0900969 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700970 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900971 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700972 })
Colin Cross36242852017-06-23 15:06:31 -0700973 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900974 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900975 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900976 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900977
Colin Cross36242852017-06-23 15:06:31 -0700978 return c
Colin Crossc472d572015-03-17 15:06:21 -0700979}
980
Colin Crossb916a382016-07-29 17:28:03 -0700981// Returns true for dependency roots (binaries)
982// TODO(ccross): also handle dlopenable libraries
983func (c *Module) isDependencyRoot() bool {
984 if root, ok := c.linker.(interface {
985 isDependencyRoot() bool
986 }); ok {
987 return root.isDependencyRoot()
988 }
989 return false
990}
991
Justin Yun5f7f7e82019-11-18 19:52:14 +0900992// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
993// "product" and "vendor" variant modules return true for this function.
994// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
995// "soc_specific: true" and more vendor installed modules are included here.
Justin Yun63e9ec72020-10-29 16:49:43 +0900996// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "product_available: true" or
Justin Yun5f7f7e82019-11-18 19:52:14 +0900997// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700998func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900999 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001000}
1001
Colin Crossc511bc52020-04-07 16:50:32 +00001002func (c *Module) canUseSdk() bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001003 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
Colin Crossc511bc52020-04-07 16:50:32 +00001004}
1005
1006func (c *Module) UseSdk() bool {
1007 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001008 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001009 }
1010 return false
1011}
1012
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001013func (c *Module) isCoverageVariant() bool {
1014 return c.coverage.Properties.IsCoverageVariant
1015}
1016
Colin Cross95f1ca02020-10-29 20:47:22 -07001017func (c *Module) IsNdk(config android.Config) bool {
1018 return inList(c.BaseModuleName(), *getNDKKnownLibs(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001019}
1020
Inseob Kim9516ee92019-05-09 10:56:13 +09001021func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001022 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001023 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001024}
1025
Inseob Kim9516ee92019-05-09 10:56:13 +09001026func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001027 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001028 name := c.BaseModuleName()
1029 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001030}
1031
Inseob Kim9516ee92019-05-09 10:56:13 +09001032func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001033 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001034 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001035}
1036
Ivan Lozano52767be2019-10-18 14:49:46 -07001037func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001038 if vndkdep := c.vndkdep; vndkdep != nil {
1039 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001040 }
1041 return false
1042}
1043
Yi Kong7e53c572018-02-14 18:16:12 +08001044func (c *Module) isPgoCompile() bool {
1045 if pgo := c.pgo; pgo != nil {
1046 return pgo.Properties.PgoCompile
1047 }
1048 return false
1049}
1050
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001051func (c *Module) isNDKStubLibrary() bool {
1052 if _, ok := c.compiler.(*stubDecorator); ok {
1053 return true
1054 }
1055 return false
1056}
1057
Logan Chienf3511742017-10-31 18:04:35 +08001058func (c *Module) isVndkSp() bool {
1059 if vndkdep := c.vndkdep; vndkdep != nil {
1060 return vndkdep.isVndkSp()
1061 }
1062 return false
1063}
1064
1065func (c *Module) isVndkExt() bool {
1066 if vndkdep := c.vndkdep; vndkdep != nil {
1067 return vndkdep.isVndkExt()
1068 }
1069 return false
1070}
1071
Ivan Lozano52767be2019-10-18 14:49:46 -07001072func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001073 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001074}
1075
Logan Chienf3511742017-10-31 18:04:35 +08001076func (c *Module) getVndkExtendsModuleName() string {
1077 if vndkdep := c.vndkdep; vndkdep != nil {
1078 return vndkdep.getVndkExtendsModuleName()
1079 }
1080 return ""
1081}
1082
Jiyong Park25fc6a92018-11-18 18:02:45 +09001083func (c *Module) IsStubs() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001084 if lib := c.library; lib != nil {
1085 return lib.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001086 }
1087 return false
1088}
1089
1090func (c *Module) HasStubsVariants() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001091 if lib := c.library; lib != nil {
1092 return lib.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001093 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001094 return false
1095}
1096
Colin Cross0477b422020-10-13 18:43:54 -07001097// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
1098// the implementation. If it is an implementation library it returns its own name.
1099func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
1100 name := ctx.OtherModuleName(c)
1101 if versioned, ok := c.linker.(versionedInterface); ok {
1102 name = versioned.implementationModuleName(name)
1103 }
1104 return name
1105}
1106
Martin Stjernholm2856c662020-12-02 15:03:42 +00001107// Similar to ImplementationModuleName, but uses the Make variant of the module
1108// name as base name, for use in AndroidMk output. E.g. for a prebuilt module
1109// where the Soong name is prebuilt_foo, this returns foo (which works in Make
1110// under the premise that the prebuilt module overrides its source counterpart
1111// if it is exposed to Make).
1112func (c *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string {
1113 name := c.BaseModuleName()
1114 if versioned, ok := c.linker.(versionedInterface); ok {
1115 name = versioned.implementationModuleName(name)
1116 }
1117 return name
1118}
1119
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001120func (c *Module) bootstrap() bool {
1121 return Bool(c.Properties.Bootstrap)
1122}
1123
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001124func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001125 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1126 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1127 return false
1128 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001129 return c.linker != nil && c.linker.nativeCoverage()
1130}
1131
Inseob Kim8471cda2019-11-15 09:59:12 +09001132func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001133 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1134 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001135 }
1136 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001137}
1138
Bill Peckham945441c2020-08-31 16:07:58 -07001139func (c *Module) ExcludeFromVendorSnapshot() bool {
1140 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1141}
1142
Jose Galmesf7294582020-11-13 12:07:36 -08001143func (c *Module) ExcludeFromRecoverySnapshot() bool {
1144 return Bool(c.Properties.Exclude_from_recovery_snapshot)
1145}
1146
Jiyong Parkf1194352019-02-25 11:05:47 +09001147func isBionic(name string) bool {
1148 switch name {
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09001149 case "libc", "libm", "libdl", "libdl_android", "linker", "linkerconfig":
Jiyong Parkf1194352019-02-25 11:05:47 +09001150 return true
1151 }
1152 return false
1153}
1154
Martin Stjernholm279de572019-09-10 23:18:20 +01001155func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001156 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001157 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001158 }
1159 return isBionic(name)
1160}
1161
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001162func (c *Module) XrefCcFiles() android.Paths {
1163 return c.kytheFiles
1164}
1165
Colin Crossca860ac2016-01-04 14:34:37 -08001166type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001167 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001168 moduleContextImpl
1169}
1170
Colin Cross37047f12016-12-13 17:06:13 -08001171type depsContext struct {
1172 android.BottomUpMutatorContext
1173 moduleContextImpl
1174}
1175
Colin Crossca860ac2016-01-04 14:34:37 -08001176type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001177 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001178 moduleContextImpl
1179}
1180
1181type moduleContextImpl struct {
1182 mod *Module
1183 ctx BaseModuleContext
1184}
1185
Colin Crossb98c8b02016-07-29 13:44:28 -07001186func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001187 return ctx.mod.toolchain(ctx.ctx)
1188}
1189
1190func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001191 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001192}
1193
1194func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001195 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001196}
1197
Jiyong Park1d1119f2019-07-29 21:27:18 +09001198func (ctx *moduleContextImpl) header() bool {
1199 return ctx.mod.header()
1200}
1201
Inseob Kim7f283f42020-06-01 21:53:49 +09001202func (ctx *moduleContextImpl) binary() bool {
1203 return ctx.mod.binary()
1204}
1205
Inseob Kim1042d292020-06-01 23:23:05 +09001206func (ctx *moduleContextImpl) object() bool {
1207 return ctx.mod.object()
1208}
1209
Jooyung Hanccce2f22020-03-07 03:45:53 +09001210func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001211 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001212}
1213
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001214func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001215 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001216}
1217
1218func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001219 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001220 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001221 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001222 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001223 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001224 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001225 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001226 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001227 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001228 }
1229 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001230}
1231
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001232func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001233 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001234}
Justin Yun8effde42017-06-23 19:24:43 +09001235
Colin Cross95f1ca02020-10-29 20:47:22 -07001236func (ctx *moduleContextImpl) isNdk(config android.Config) bool {
1237 return ctx.mod.IsNdk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001238}
1239
Inseob Kim9516ee92019-05-09 10:56:13 +09001240func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1241 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001242}
1243
Inseob Kim9516ee92019-05-09 10:56:13 +09001244func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1245 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001246}
1247
Inseob Kim9516ee92019-05-09 10:56:13 +09001248func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1249 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001250}
1251
Logan Chienf3511742017-10-31 18:04:35 +08001252func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001253 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001254}
1255
Yi Kong7e53c572018-02-14 18:16:12 +08001256func (ctx *moduleContextImpl) isPgoCompile() bool {
1257 return ctx.mod.isPgoCompile()
1258}
1259
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001260func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1261 return ctx.mod.isNDKStubLibrary()
1262}
1263
Justin Yun8effde42017-06-23 19:24:43 +09001264func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001265 return ctx.mod.isVndkSp()
1266}
1267
1268func (ctx *moduleContextImpl) isVndkExt() bool {
1269 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001270}
1271
Vic Yangefd249e2018-11-12 20:19:56 -08001272func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001273 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001274}
1275
Logan Chien2f2b8902018-07-10 15:01:19 +08001276// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001277func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001278 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1279 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001280 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001281
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001282 // Coverage builds have extra symbols.
1283 if ctx.mod.isCoverageVariant() {
1284 return false
1285 }
1286
Doug Hornc32c6b02019-01-17 14:44:05 -08001287 if ctx.ctx.Fuchsia() {
1288 return false
1289 }
1290
Logan Chien2f2b8902018-07-10 15:01:19 +08001291 if sanitize := ctx.mod.sanitize; sanitize != nil {
1292 if !sanitize.isVariantOnProductionDevice() {
1293 return false
1294 }
1295 }
1296 if !ctx.ctx.Device() {
1297 // Host modules do not need ABI dumps.
1298 return false
1299 }
Colin Cross31076b32020-10-23 17:22:06 -07001300 if ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001301 // Stubs do not need ABI dumps.
1302 return false
1303 }
Colin Cross31076b32020-10-23 17:22:06 -07001304 if lib := ctx.mod.library; lib != nil && lib.buildStubs() {
1305 // Stubs do not need ABI dumps.
1306 return false
1307 }
1308
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001309 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001310}
1311
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001312func (ctx *moduleContextImpl) selectedStl() string {
1313 if stl := ctx.mod.stl; stl != nil {
1314 return stl.Properties.SelectedStl
1315 }
1316 return ""
1317}
1318
Ivan Lozanobd721262018-11-27 14:33:03 -08001319func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1320 return ctx.mod.linker.useClangLld(actx)
1321}
1322
Colin Crossce75d2c2016-10-06 16:12:58 -07001323func (ctx *moduleContextImpl) baseModuleName() string {
1324 return ctx.mod.ModuleBase.BaseModuleName()
1325}
1326
Logan Chienf3511742017-10-31 18:04:35 +08001327func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1328 return ctx.mod.getVndkExtendsModuleName()
1329}
1330
Logan Chiene274fc92019-12-03 11:18:32 -08001331func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Cross56a83212020-09-15 18:30:11 -07001332 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001333}
1334
Colin Crosse07f2312020-08-13 11:24:56 -07001335func (ctx *moduleContextImpl) apexVariationName() string {
Colin Cross56a83212020-09-15 18:30:11 -07001336 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001337}
1338
Dan Albertc8060532020-07-22 22:32:17 -07001339func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001340 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001341}
1342
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001343func (ctx *moduleContextImpl) bootstrap() bool {
1344 return ctx.mod.bootstrap()
1345}
1346
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001347func (ctx *moduleContextImpl) nativeCoverage() bool {
1348 return ctx.mod.nativeCoverage()
1349}
1350
Colin Cross56a83212020-09-15 18:30:11 -07001351func (ctx *moduleContextImpl) directlyInAnyApex() bool {
1352 return ctx.mod.DirectlyInAnyApex()
1353}
1354
Colin Cross635c3b02016-05-18 15:37:25 -07001355func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001356 return &Module{
1357 hod: hod,
1358 multilib: multilib,
1359 }
1360}
1361
Colin Cross635c3b02016-05-18 15:37:25 -07001362func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001363 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001364 module.features = []feature{
1365 &tidyFeature{},
1366 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001367 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001368 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001369 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001370 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001371 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001372 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001373 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001374 return module
1375}
1376
Colin Crossce75d2c2016-10-06 16:12:58 -07001377func (c *Module) Prebuilt() *android.Prebuilt {
1378 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1379 return p.prebuilt()
1380 }
1381 return nil
1382}
1383
1384func (c *Module) Name() string {
1385 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001386 if p, ok := c.linker.(interface {
1387 Name(string) string
1388 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001389 name = p.Name(name)
1390 }
1391 return name
1392}
1393
Alex Light3d673592019-01-18 14:37:31 -08001394func (c *Module) Symlinks() []string {
1395 if p, ok := c.installer.(interface {
1396 symlinkList() []string
1397 }); ok {
1398 return p.symlinkList()
1399 }
1400 return nil
1401}
1402
Roland Levillainf89cd092019-07-29 16:22:59 +01001403func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1404 test, ok := c.linker.(testPerSrc)
1405 return ok && test.isAllTestsVariation()
1406}
1407
Chris Parsons216e10a2020-07-09 17:12:52 -04001408func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001409 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001410 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001411 }); ok {
1412 return p.dataPaths()
1413 }
1414 return nil
1415}
1416
Justin Yun5f7f7e82019-11-18 19:52:14 +09001417func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1418 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1419 // "current", it will append the VNDK version to the name suffix.
1420 var vndkVersion string
1421 var nameSuffix string
1422 if c.inProduct() {
1423 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1424 nameSuffix = productSuffix
1425 } else {
1426 vndkVersion = ctx.DeviceConfig().VndkVersion()
1427 nameSuffix = vendorSuffix
1428 }
1429 if vndkVersion == "current" {
1430 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1431 }
1432 if c.Properties.VndkVersion != vndkVersion {
1433 // add version suffix only if the module is using different vndk version than the
1434 // version in product or vendor partition.
1435 nameSuffix += "." + c.Properties.VndkVersion
1436 }
1437 return nameSuffix
1438}
1439
Colin Cross635c3b02016-05-18 15:37:25 -07001440func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001441 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001442 //
1443 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1444 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1445 // module and return early, as this module does not produce an output file per se.
1446 if c.IsTestPerSrcAllTestsVariation() {
1447 c.outputFile = android.OptionalPath{}
1448 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001449 }
1450
Colin Cross56a83212020-09-15 18:30:11 -07001451 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1452 if !apexInfo.IsForPlatform() {
1453 c.hideApexVariantFromMake = true
1454 }
1455
Jooyung Han38002912019-05-16 04:01:54 +09001456 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001457
Inseob Kim64c43952019-08-26 16:52:35 +09001458 c.Properties.SubName = ""
1459
1460 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1461 c.Properties.SubName += nativeBridgeSuffix
1462 }
1463
Justin Yun5f7f7e82019-11-18 19:52:14 +09001464 _, llndk := c.linker.(*llndkStubDecorator)
1465 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
Justin Yun63e9ec72020-10-29 16:49:43 +09001466 if llndk || llndkHeader || (c.UseVndk() && c.HasNonSystemVariants()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001467 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1468 // added for product variant only when we have vendor and product variants with core
1469 // variant. The suffix is not added for vendor-only or product-only module.
1470 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1471 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001472 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1473 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1474 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001475 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1476 c.Properties.SubName += ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001477 } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
1478 c.Properties.SubName += vendorRamdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001479 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001480 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001481 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001482 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001483 if c.SplitPerApiLevel() {
1484 c.Properties.SubName += "." + c.SdkVersion()
1485 }
Inseob Kim64c43952019-08-26 16:52:35 +09001486 }
1487
Colin Crossca860ac2016-01-04 14:34:37 -08001488 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001489 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001490 moduleContextImpl: moduleContextImpl{
1491 mod: c,
1492 },
1493 }
1494 ctx.ctx = ctx
1495
Colin Crossf18e1102017-11-16 14:33:08 -08001496 deps := c.depsToPaths(ctx)
1497 if ctx.Failed() {
1498 return
1499 }
1500
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001501 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1502 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1503 }
1504
Colin Crossca860ac2016-01-04 14:34:37 -08001505 flags := Flags{
1506 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001507 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001508 }
Colin Crossca860ac2016-01-04 14:34:37 -08001509 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001510 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001511 }
1512 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001513 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001514 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001515 if c.stl != nil {
1516 flags = c.stl.flags(ctx, flags)
1517 }
Colin Cross16b23492016-01-06 14:41:07 -08001518 if c.sanitize != nil {
1519 flags = c.sanitize.flags(ctx, flags)
1520 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001521 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001522 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001523 }
Stephen Craneba090d12017-05-09 15:44:35 -07001524 if c.lto != nil {
1525 flags = c.lto.flags(ctx, flags)
1526 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001527 if c.pgo != nil {
1528 flags = c.pgo.flags(ctx, flags)
1529 }
Colin Crossca860ac2016-01-04 14:34:37 -08001530 for _, feature := range c.features {
1531 flags = feature.flags(ctx, flags)
1532 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001533 if ctx.Failed() {
1534 return
1535 }
1536
Colin Cross4af21ed2019-11-04 09:37:55 -08001537 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1538 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1539 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001540
Colin Cross4af21ed2019-11-04 09:37:55 -08001541 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001542
1543 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001544 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001545 }
1546 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001547 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001548 }
1549
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001550 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001551 // We need access to all the flags seen by a source file.
1552 if c.sabi != nil {
1553 flags = c.sabi.flags(ctx, flags)
1554 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001555
Colin Cross4af21ed2019-11-04 09:37:55 -08001556 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001557
Colin Crossca860ac2016-01-04 14:34:37 -08001558 // Optimization to reduce size of build.ninja
1559 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001560 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1561 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1562 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1563 flags.Local.CFlags = []string{"$cflags"}
1564 flags.Local.CppFlags = []string{"$cppflags"}
1565 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001566
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001567 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001568 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001569 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001570 if ctx.Failed() {
1571 return
1572 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001573 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001574 }
1575
Colin Crossca860ac2016-01-04 14:34:37 -08001576 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001577 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001578 if ctx.Failed() {
1579 return
1580 }
Colin Cross635c3b02016-05-18 15:37:25 -07001581 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001582
1583 // If a lib is directly included in any of the APEXes, unhide the stubs
1584 // variant having the latest version gets visible to make. In addition,
1585 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1586 // force anything in the make world to link against the stubs library.
1587 // (unless it is explicitly referenced via .bootstrap suffix or the
1588 // module is marked with 'bootstrap: true').
Colin Cross56a83212020-09-15 18:30:11 -07001589 if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001590 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001591 c.IsStubs() && !c.InVendorRamdisk() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001592 c.Properties.HideFromMake = false // unhide
1593 // Note: this is still non-installable
1594 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001595
1596 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1597 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
Inseob Kimde5744a2020-12-02 13:14:28 +09001598 if shouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001599 i.collectHeadersForSnapshot(ctx)
1600 }
1601 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001602 }
Colin Cross5049f022015-03-18 13:28:46 -07001603
Colin Cross56a83212020-09-15 18:30:11 -07001604 if c.installable(apexInfo) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001605 c.installer.install(ctx, c.outputFile.Path())
1606 if ctx.Failed() {
1607 return
Colin Crossca860ac2016-01-04 14:34:37 -08001608 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001609 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1610 // If the module has been specifically configure to not be installed then
1611 // skip the installation as otherwise it will break when running inside make
1612 // as the output path to install will not be specified. Not all uninstallable
1613 // modules can skip installation as some are needed for resolving make side
1614 // dependencies.
1615 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001616 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001617}
1618
Colin Cross0ea8ba82019-06-06 14:33:29 -07001619func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001620 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001621 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001622 }
Colin Crossca860ac2016-01-04 14:34:37 -08001623 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001624}
1625
Colin Crossca860ac2016-01-04 14:34:37 -08001626func (c *Module) begin(ctx BaseModuleContext) {
1627 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001628 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001629 }
Colin Crossca860ac2016-01-04 14:34:37 -08001630 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001631 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001632 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001633 if c.stl != nil {
1634 c.stl.begin(ctx)
1635 }
Colin Cross16b23492016-01-06 14:41:07 -08001636 if c.sanitize != nil {
1637 c.sanitize.begin(ctx)
1638 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001639 if c.coverage != nil {
1640 c.coverage.begin(ctx)
1641 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001642 if c.sabi != nil {
1643 c.sabi.begin(ctx)
1644 }
Justin Yun8effde42017-06-23 19:24:43 +09001645 if c.vndkdep != nil {
1646 c.vndkdep.begin(ctx)
1647 }
Stephen Craneba090d12017-05-09 15:44:35 -07001648 if c.lto != nil {
1649 c.lto.begin(ctx)
1650 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001651 if c.pgo != nil {
1652 c.pgo.begin(ctx)
1653 }
Colin Crossca860ac2016-01-04 14:34:37 -08001654 for _, feature := range c.features {
1655 feature.begin(ctx)
1656 }
Dan Albert92fe7402020-07-15 13:33:30 -07001657 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001658 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001659 if err != nil {
1660 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001661 c.Properties.Sdk_version = nil
1662 } else {
1663 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001664 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001665 }
Colin Crossca860ac2016-01-04 14:34:37 -08001666}
1667
Colin Cross37047f12016-12-13 17:06:13 -08001668func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001669 deps := Deps{}
1670
1671 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001672 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001673 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001674 // Add the PGO dependency (the clang_rt.profile runtime library), which
1675 // sometimes depends on symbols from libgcc, before libgcc gets added
1676 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001677 if c.pgo != nil {
1678 deps = c.pgo.deps(ctx, deps)
1679 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001680 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001681 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001682 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001683 if c.stl != nil {
1684 deps = c.stl.deps(ctx, deps)
1685 }
Colin Cross16b23492016-01-06 14:41:07 -08001686 if c.sanitize != nil {
1687 deps = c.sanitize.deps(ctx, deps)
1688 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001689 if c.coverage != nil {
1690 deps = c.coverage.deps(ctx, deps)
1691 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001692 if c.sabi != nil {
1693 deps = c.sabi.deps(ctx, deps)
1694 }
Justin Yun8effde42017-06-23 19:24:43 +09001695 if c.vndkdep != nil {
1696 deps = c.vndkdep.deps(ctx, deps)
1697 }
Stephen Craneba090d12017-05-09 15:44:35 -07001698 if c.lto != nil {
1699 deps = c.lto.deps(ctx, deps)
1700 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001701 for _, feature := range c.features {
1702 deps = feature.deps(ctx, deps)
1703 }
1704
Colin Crossb6715442017-10-24 11:13:31 -07001705 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1706 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1707 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1708 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1709 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1710 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001711 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001712
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001713 for _, lib := range deps.ReexportSharedLibHeaders {
1714 if !inList(lib, deps.SharedLibs) {
1715 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1716 }
1717 }
1718
1719 for _, lib := range deps.ReexportStaticLibHeaders {
1720 if !inList(lib, deps.StaticLibs) {
1721 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1722 }
1723 }
1724
Colin Cross5950f382016-12-13 12:50:57 -08001725 for _, lib := range deps.ReexportHeaderLibHeaders {
1726 if !inList(lib, deps.HeaderLibs) {
1727 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1728 }
1729 }
1730
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001731 for _, gen := range deps.ReexportGeneratedHeaders {
1732 if !inList(gen, deps.GeneratedHeaders) {
1733 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1734 }
1735 }
1736
Colin Crossc99deeb2016-04-11 15:06:20 -07001737 return deps
1738}
1739
Dan Albert7e9d2952016-08-04 13:02:36 -07001740func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001741 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001742 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001743 moduleContextImpl: moduleContextImpl{
1744 mod: c,
1745 },
1746 }
1747 ctx.ctx = ctx
1748
Colin Crossca860ac2016-01-04 14:34:37 -08001749 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001750}
1751
Jiyong Park7ed9de32018-10-15 22:25:07 +09001752// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001753func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001754 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1755 version := name[sharp+1:]
1756 libname := name[:sharp]
1757 return libname, version
1758 }
1759 return name, ""
1760}
1761
Dan Albert92fe7402020-07-15 13:33:30 -07001762func GetCrtVariations(ctx android.BottomUpMutatorContext,
1763 m LinkableInterface) []blueprint.Variation {
1764 if ctx.Os() != android.Android {
1765 return nil
1766 }
1767 if m.UseSdk() {
1768 return []blueprint.Variation{
1769 {Mutator: "sdk", Variation: "sdk"},
Colin Crossbbc941b2020-09-30 12:27:01 -07001770 {Mutator: "version", Variation: m.SdkVersion()},
Dan Albert92fe7402020-07-15 13:33:30 -07001771 }
1772 }
1773 return []blueprint.Variation{
1774 {Mutator: "sdk", Variation: ""},
1775 }
1776}
1777
Colin Crosse7257d22020-09-24 09:56:18 -07001778func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1779 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1780
1781 variations = append([]blueprint.Variation(nil), variations...)
1782
Colin Cross3146c5c2020-09-30 15:34:40 -07001783 if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001784 // Version is explicitly specified. i.e. libFoo#30
1785 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1786 depTag.explicitlyVersioned = true
1787 }
Colin Crosse7257d22020-09-24 09:56:18 -07001788
Colin Cross0de8a1e2020-09-18 14:15:30 -07001789 if far {
1790 ctx.AddFarVariationDependencies(variations, depTag, name)
1791 } else {
1792 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07001793 }
1794}
1795
Colin Cross1e676be2016-10-12 14:38:15 -07001796func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001797 if !c.Enabled() {
1798 return
1799 }
1800
Colin Cross37047f12016-12-13 17:06:13 -08001801 ctx := &depsContext{
1802 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001803 moduleContextImpl: moduleContextImpl{
1804 mod: c,
1805 },
1806 }
1807 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001808
Colin Crossc99deeb2016-04-11 15:06:20 -07001809 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001810
Yo Chiang219968c2020-09-22 18:45:04 +08001811 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1812
Dan Albert914449f2016-06-17 16:45:24 -07001813 variantNdkLibs := []string{}
1814 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001815 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001816 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001817 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001818 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001819 // 1. Name of an NDK library that refers to a prebuilt module.
1820 // For each of these, it adds the name of the prebuilt module (which will be in
1821 // prebuilts/ndk) to the list of nonvariant libs.
1822 // 2. Name of an NDK library that refers to an ndk_library module.
1823 // For each of these, it adds the name of the ndk_library module to the list of
1824 // variant libs.
1825 // 3. Anything else (so anything that isn't an NDK library).
1826 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001827 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001828 // The caller can then know to add the variantLibs dependencies differently from the
1829 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001830
Inseob Kim9516ee92019-05-09 10:56:13 +09001831 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001832 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1833
1834 rewriteVendorLibs := func(lib string) string {
1835 if isLlndkLibrary(lib, ctx.Config()) {
1836 return lib + llndkLibrarySuffix
1837 }
1838
1839 // only modules with BOARD_VNDK_VERSION uses snapshot.
1840 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1841 return lib
1842 }
1843
1844 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1845 return snapshot
1846 }
1847
1848 return lib
1849 }
1850
1851 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001852 variantLibs = []string{}
1853 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001854 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001855 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001856 name, _ := StubsLibNameAndVersion(entry)
Colin Cross95f1ca02020-10-29 20:47:22 -07001857 if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) {
Dan Albertde5aade2020-06-30 12:32:51 -07001858 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001859 } else if ctx.useVndk() {
1860 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001861 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001862 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001863 if actx.OtherModuleExists(vendorPublicLib) {
1864 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1865 } else {
1866 // This can happen if vendor_public_library module is defined in a
1867 // namespace that isn't visible to the current module. In that case,
1868 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001869 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001870 }
Dan Albert914449f2016-06-17 16:45:24 -07001871 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001872 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001873 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001874 }
1875 }
Dan Albert914449f2016-06-17 16:45:24 -07001876 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001877 }
1878
Inseob Kimeec88e12020-01-22 11:11:29 +09001879 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1880 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1881 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1882 if ctx.useVndk() {
1883 for idx, lib := range deps.RuntimeLibs {
1884 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1885 }
1886 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001887 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001888
Jiyong Park7e636d02019-01-28 16:16:54 +09001889 buildStubs := false
Colin Crossc88c2722020-09-28 17:32:47 -07001890 if versioned, ok := c.linker.(versionedInterface); ok {
1891 if versioned.buildStubs() {
1892 buildStubs = true
Colin Crossd48fe732020-09-23 20:37:24 -07001893 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001894 }
1895
Inseob Kimeec88e12020-01-22 11:11:29 +09001896 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1897 // only modules with BOARD_VNDK_VERSION uses snapshot.
1898 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1899 return lib
1900 }
1901
1902 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1903 return snapshot
1904 }
1905
1906 return lib
1907 }
1908
1909 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001910 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001911 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001912 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001913 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001914 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001915
1916 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1917
Jiyong Park7e636d02019-01-28 16:16:54 +09001918 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001919 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001920 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001921 } else {
1922 actx.AddVariationDependencies(nil, depTag, lib)
1923 }
1924 }
1925
1926 if buildStubs {
1927 // Stubs lib does not have dependency to other static/shared libraries.
1928 // Don't proceed.
1929 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001930 }
Colin Cross5950f382016-12-13 12:50:57 -08001931
Inseob Kim07def122020-11-23 14:43:02 +09001932 // sysprop_library has to support both C++ and Java. So sysprop_library internally creates one
1933 // C++ implementation library and one Java implementation library. When a module links against
1934 // sysprop_library, the C++ implementation library has to be linked. syspropImplLibraries is a
1935 // map from sysprop_library to implementation library; it will be used in whole_static_libs,
1936 // static_libs, and shared_libs.
Inseob Kimc0907f12019-02-08 21:00:45 +09001937 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001938 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001939
Jiyong Park5d1598f2019-02-25 22:14:17 +09001940 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001941 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001942 if impl, ok := syspropImplLibraries[lib]; ok {
1943 lib = impl
1944 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001945
1946 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1947
Jiyong Park5d1598f2019-02-25 22:14:17 +09001948 actx.AddVariationDependencies([]blueprint.Variation{
1949 {Mutator: "link", Variation: "static"},
1950 }, depTag, lib)
1951 }
1952
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001953 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001954 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001955 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001956 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001957 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001958
1959 if impl, ok := syspropImplLibraries[lib]; ok {
1960 lib = impl
1961 }
1962
Inseob Kimeec88e12020-01-22 11:11:29 +09001963 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1964
Dan Willemsen59339a22018-07-22 21:18:45 -07001965 actx.AddVariationDependencies([]blueprint.Variation{
1966 {Mutator: "link", Variation: "static"},
1967 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001968 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001969
Jooyung Han75568392020-03-20 04:29:24 +09001970 // staticUnwinderDep is treated as staticDep for Q apexes
1971 // so that native libraries/binaries are linked with static unwinder
1972 // because Q libc doesn't have unwinder APIs
1973 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001974 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001975 actx.AddVariationDependencies([]blueprint.Variation{
1976 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001977 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001978 }
1979
Inseob Kimeec88e12020-01-22 11:11:29 +09001980 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001981 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001982 actx.AddVariationDependencies([]blueprint.Variation{
1983 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001984 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001985 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001986
Jiyong Park7ed9de32018-10-15 22:25:07 +09001987 // shared lib names without the #version suffix
1988 var sharedLibNames []string
1989
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001990 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001991 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001992 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001993 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001994 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001995
1996 if impl, ok := syspropImplLibraries[lib]; ok {
1997 lib = impl
1998 }
1999
Jiyong Park73c54ee2019-10-22 20:31:18 +09002000 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002001 sharedLibNames = append(sharedLibNames, name)
2002
Colin Crosse7257d22020-09-24 09:56:18 -07002003 variations := []blueprint.Variation{
2004 {Mutator: "link", Variation: "shared"},
2005 }
2006 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002007 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002008
Jiyong Park7ed9de32018-10-15 22:25:07 +09002009 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002010 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002011 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2012 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2013 // linking against both the stubs lib and the non-stubs lib at the same time.
2014 continue
2015 }
Colin Cross6e511a92020-07-27 21:26:48 -07002016 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002017 variations := []blueprint.Variation{
2018 {Mutator: "link", Variation: "shared"},
2019 }
2020 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002021 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002022
Dan Willemsen59339a22018-07-22 21:18:45 -07002023 actx.AddVariationDependencies([]blueprint.Variation{
2024 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002025 }, dataLibDepTag, deps.DataLibs...)
2026
2027 actx.AddVariationDependencies([]blueprint.Variation{
2028 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002029 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002030
Colin Cross68861832016-07-08 10:41:41 -07002031 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002032
2033 for _, gen := range deps.GeneratedHeaders {
2034 depTag := genHeaderDepTag
2035 if inList(gen, deps.ReexportGeneratedHeaders) {
2036 depTag = genHeaderExportDepTag
2037 }
2038 actx.AddDependency(c, depTag, gen)
2039 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002040
Inseob Kim1042d292020-06-01 23:23:05 +09002041 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2042
Dan Albert92fe7402020-07-15 13:33:30 -07002043 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07002044 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002045 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002046 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2047 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002048 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002049 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002050 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2051 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002052 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002053 if deps.LinkerFlagsFile != "" {
2054 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2055 }
2056 if deps.DynamicLinker != "" {
2057 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002058 }
Dan Albert914449f2016-06-17 16:45:24 -07002059
2060 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002061
2062 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002063 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002064 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002065 {Mutator: "link", Variation: "shared"},
2066 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002067
2068 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002069 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002070 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002071 {Mutator: "link", Variation: "shared"},
2072 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002073
2074 if vndkdep := c.vndkdep; vndkdep != nil {
2075 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002076 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002077 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002078 {Mutator: "link", Variation: "shared"},
2079 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002080 }
2081 }
Colin Cross6362e272015-10-29 15:25:03 -07002082}
Colin Cross21b9a242015-03-24 14:15:58 -07002083
Colin Crosse40b4ea2018-10-02 22:25:58 -07002084func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002085 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2086 c.beginMutator(ctx)
2087 }
2088}
2089
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002090// Whether a module can link to another module, taking into
2091// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002092func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002093 tag blueprint.DependencyTag) {
2094
2095 switch t := tag.(type) {
2096 case dependencyTag:
2097 if t != vndkExtDepTag {
2098 return
2099 }
2100 case libraryDependencyTag:
2101 default:
2102 return
2103 }
2104
Ivan Lozano52767be2019-10-18 14:49:46 -07002105 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002106 // Host code is not restricted
2107 return
2108 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002109
2110 // VNDK is cc.Module supported only for now.
2111 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Justin Yun63e9ec72020-10-29 16:49:43 +09002112 // Though allowed dependency is limited by the image mutator,
2113 // each vendor and product module needs to check link-type
2114 // for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002115 if ccTo, ok := to.(*Module); ok {
2116 if ccFrom.vndkdep != nil {
2117 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2118 }
2119 } else {
2120 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002121 }
2122 return
2123 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002124 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002125 // Platform code can link to anything
2126 return
2127 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002128 if from.InRamdisk() {
2129 // Ramdisk code is not NDK
2130 return
2131 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002132 if from.InVendorRamdisk() {
2133 // Vendor ramdisk code is not NDK
2134 return
2135 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002136 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002137 // Recovery code is not NDK
2138 return
2139 }
Colin Cross31076b32020-10-23 17:22:06 -07002140 if c, ok := to.(*Module); ok {
2141 if c.ToolchainLibrary() {
2142 // These are always allowed
2143 return
2144 }
2145 if c.NdkPrebuiltStl() {
2146 // These are allowed, but they don't set sdk_version
2147 return
2148 }
2149 if c.StubDecorator() {
2150 // These aren't real libraries, but are the stub shared libraries that are included in
2151 // the NDK.
2152 return
2153 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 }
Logan Chien834b9a62019-01-14 15:39:03 +08002155
Ivan Lozano52767be2019-10-18 14:49:46 -07002156 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002157 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2158 // to link to libc++ (non-NDK and without sdk_version).
2159 return
2160 }
2161
Ivan Lozano52767be2019-10-18 14:49:46 -07002162 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002163 // NDK code linking to platform code is never okay.
2164 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002165 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002166 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002167 }
2168
2169 // At this point we know we have two NDK libraries, but we need to
2170 // check that we're not linking against anything built against a higher
2171 // API level, as it is only valid to link against older or equivalent
2172 // APIs.
2173
Inseob Kim01a28722018-04-11 09:48:45 +09002174 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002175 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002176 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002178 // Current can't be linked against by anything else.
2179 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002180 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002181 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002182 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002183 if err != nil {
2184 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002185 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002186 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002187 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002188 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002189 if err != nil {
2190 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002191 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002192 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002193 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002194
Inseob Kim01a28722018-04-11 09:48:45 +09002195 if toApi > fromApi {
2196 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002198 }
2199 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002200 }
Dan Albert202fe492017-12-15 13:56:59 -08002201
2202 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 fromStl := from.SelectedStl()
2204 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002205 if fromStl == "" || toStl == "" {
2206 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002207 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002208 // We can be permissive with the system "STL" since it is only the C++
2209 // ABI layer, but in the future we should make sure that everyone is
2210 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002211 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002212 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002213 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2214 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002215 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002216}
2217
Jooyung Han479ca172020-10-19 18:51:07 +09002218func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2219 if c, ok := ctx.Module().(*Module); ok {
2220 ctx.VisitDirectDeps(func(dep android.Module) {
2221 depTag := ctx.OtherModuleDependencyTag(dep)
2222 ccDep, ok := dep.(LinkableInterface)
2223 if ok {
2224 checkLinkType(ctx, c, ccDep, depTag)
2225 }
2226 })
2227 }
2228}
2229
Jiyong Park5fb8c102018-04-09 12:03:06 +09002230// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002231// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2232// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002233// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002234func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2235 check := func(child, parent android.Module) bool {
2236 to, ok := child.(*Module)
2237 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002238 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002239 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002240
Jooyung Hana70f0672019-01-18 15:20:43 +09002241 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2242 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002243 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002244
Justin Yun63e9ec72020-10-29 16:49:43 +09002245 // Even if target lib has no vendor variant, keep checking dependency
2246 // graph in case it depends on vendor_available or product_available
2247 // but not double_loadable transtively.
2248 if !to.HasNonSystemVariants() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002249 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002250 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002251
Jooyung Han0302a842019-10-30 18:43:49 +09002252 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002253 return false
2254 }
2255
2256 var stringPath []string
2257 for _, m := range ctx.GetWalkPath() {
2258 stringPath = append(stringPath, m.Name())
2259 }
2260 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2261 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2262 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2263 return false
2264 }
2265 if module, ok := ctx.Module().(*Module); ok {
2266 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002267 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002268 ctx.WalkDeps(check)
2269 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002270 }
2271 }
2272}
2273
Colin Cross0de8a1e2020-09-18 14:15:30 -07002274// Returns the highest version which is <= maxSdkVersion.
2275// For example, with maxSdkVersion is 10 and versionList is [9,11]
2276// it returns 9 as string. The list of stubs must be in order from
2277// oldest to newest.
Chris Parsons3c27ca32020-11-20 12:42:07 -05002278func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedStubLibrary,
2279 maxSdkVersion android.ApiLevel) (SharedStubLibrary, error) {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002280
2281 for i := range stubsInfo {
2282 stubInfo := stubsInfo[len(stubsInfo)-i-1]
2283 var ver android.ApiLevel
2284 if stubInfo.Version == "" {
2285 ver = android.FutureApiLevel
2286 } else {
2287 var err error
2288 ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
2289 if err != nil {
Chris Parsons3c27ca32020-11-20 12:42:07 -05002290 return SharedStubLibrary{}, err
Colin Cross0de8a1e2020-09-18 14:15:30 -07002291 }
2292 }
2293 if ver.LessThanOrEqualTo(maxSdkVersion) {
2294 return stubInfo, nil
2295 }
2296 }
2297 var versionList []string
2298 for _, stubInfo := range stubsInfo {
2299 versionList = append(versionList, stubInfo.Version)
2300 }
Chris Parsons3c27ca32020-11-20 12:42:07 -05002301 return SharedStubLibrary{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002302}
2303
Colin Crossc99deeb2016-04-11 15:06:20 -07002304// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002305func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002306 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002307
Colin Cross0de8a1e2020-09-18 14:15:30 -07002308 var directStaticDeps []StaticLibraryInfo
2309 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07002310
Colin Cross0de8a1e2020-09-18 14:15:30 -07002311 reexportExporter := func(exporter FlagExporterInfo) {
2312 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
2313 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
2314 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
2315 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
2316 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09002317 }
2318
Jooyung Hande34d232020-07-23 13:04:15 +09002319 // For the dependency from platform to apex, use the latest stubs
2320 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002321 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2322 if !apexInfo.IsForPlatform() {
2323 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002324 }
2325
2326 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2327 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2328 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2329 // (b/144430859)
2330 c.apexSdkVersion = android.FutureApiLevel
2331 }
2332
Colin Crossd11fcda2017-10-23 17:59:01 -07002333 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002334 depName := ctx.OtherModuleName(dep)
2335 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002336
Ivan Lozano52767be2019-10-18 14:49:46 -07002337 ccDep, ok := dep.(LinkableInterface)
2338 if !ok {
2339
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002340 // handling for a few module types that aren't cc Module but that are also supported
2341 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002342 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002343 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002344 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2345 genRule.GeneratedSourceFiles()...)
2346 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002347 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002348 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002349 // Support exported headers from a generated_sources dependency
2350 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002351 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002352 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002353 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002354 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002355 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002356 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002357 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002358 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002359 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2360 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002361 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002362 // 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 +09002363 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002364
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002365 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002366 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002367 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002368 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002369 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002370 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002371 files := genRule.GeneratedSourceFiles()
2372 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002373 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002374 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002375 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 -07002376 }
2377 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002378 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002379 }
Colin Crossca860ac2016-01-04 14:34:37 -08002380 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002381 return
2382 }
2383
Colin Crossfe17f6f2019-03-28 19:30:56 -07002384 if depTag == android.ProtoPluginDepTag {
2385 return
2386 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002387 if depTag == llndkImplDep {
2388 return
2389 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002390
Colin Crossd11fcda2017-10-23 17:59:01 -07002391 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002392 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2393 return
2394 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002395 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002396 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2397 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002398 return
2399 }
2400
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002401 if depTag == reuseObjTag {
Colin Crossa717db72020-10-23 14:53:06 -07002402 // Skip reused objects for stub libraries, they use their own stub object file instead.
2403 // The reuseObjTag dependency still exists because the LinkageMutator runs before the
2404 // version mutator, so the stubs variant is created from the shared variant that
2405 // already has the reuseObjTag dependency on the static variant.
Colin Cross31076b32020-10-23 17:22:06 -07002406 if !c.library.buildStubs() {
Colin Crossa717db72020-10-23 14:53:06 -07002407 staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2408 objs := staticAnalogue.ReuseObjects
2409 depPaths.Objs = depPaths.Objs.Append(objs)
2410 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
2411 reexportExporter(depExporterInfo)
2412 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07002413 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09002414 }
2415
Colin Cross6e511a92020-07-27 21:26:48 -07002416 linkFile := ccDep.OutputFile()
2417
2418 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2419 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002420 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002421 return
2422 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002423
Colin Cross0de8a1e2020-09-18 14:15:30 -07002424 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
Colin Crossc99deeb2016-04-11 15:06:20 -07002425
Colin Cross6e511a92020-07-27 21:26:48 -07002426 var ptr *android.Paths
2427 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002428
Colin Cross6e511a92020-07-27 21:26:48 -07002429 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002430
Colin Cross6e511a92020-07-27 21:26:48 -07002431 switch {
2432 case libDepTag.header():
2433 // nothing
2434 case libDepTag.shared():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002435 if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
2436 if !ctx.Config().AllowMissingDependencies() {
2437 ctx.ModuleErrorf("module %q is not a shared library", depName)
2438 } else {
2439 ctx.AddMissingDependencies([]string{depName})
2440 }
2441 return
2442 }
2443 sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
Chris Parsons3c27ca32020-11-20 12:42:07 -05002444 sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryStubsProvider).(SharedLibraryStubsInfo)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002445
Chris Parsons3c27ca32020-11-20 12:42:07 -05002446 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002447 useStubs := false
Colin Cross31076b32020-10-23 17:22:06 -07002448
2449 if lib := moduleLibraryInterface(dep); lib.buildStubs() && c.UseVndk() { // LLNDK
Colin Cross0de8a1e2020-09-18 14:15:30 -07002450 if !apexInfo.IsForPlatform() {
2451 // For platform libraries, use current version of LLNDK
2452 // If this is for use_vendor apex we will apply the same rules
2453 // of apex sdk enforcement below to choose right version.
2454 useStubs = true
2455 }
2456 } else if apexInfo.IsForPlatform() {
2457 // If not building for APEX, use stubs only when it is from
2458 // an APEX (and not from platform)
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002459 // However, for host, ramdisk, vendor_ramdisk, recovery or bootstrap modules,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002460 // always link to non-stub variant
2461 useStubs = dep.(android.ApexModule).AnyVariantDirectlyInAnyApex() && !c.bootstrap()
2462 // Another exception: if this module is bundled with an APEX, then
2463 // it is linked with the non-stub variant of a module in the APEX
2464 // as if this is part of the APEX.
2465 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2466 for _, apexContents := range testFor.ApexContents {
2467 if apexContents.DirectlyInApex(depName) {
2468 useStubs = false
2469 break
2470 }
2471 }
2472 } else {
2473 // If building for APEX, use stubs when the parent is in any APEX that
2474 // the child is not in.
2475 useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
2476 }
2477
2478 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2479 if useStubs {
2480 sharedLibraryStubsInfo, err :=
Chris Parsons3c27ca32020-11-20 12:42:07 -05002481 c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedStubLibraries, c.apexSdkVersion)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002482 if err != nil {
2483 ctx.OtherModuleErrorf(dep, err.Error())
2484 return
2485 }
2486 sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
2487 depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
2488 }
2489 }
2490
2491 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
2492 depFile = sharedLibraryInfo.TableOfContents
2493
Colin Cross6e511a92020-07-27 21:26:48 -07002494 ptr = &depPaths.SharedLibs
2495 switch libDepTag.Order {
2496 case earlyLibraryDependency:
2497 ptr = &depPaths.EarlySharedLibs
2498 depPtr = &depPaths.EarlySharedLibsDeps
2499 case normalLibraryDependency:
2500 ptr = &depPaths.SharedLibs
2501 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07002502 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002503 case lateLibraryDependency:
2504 ptr = &depPaths.LateSharedLibs
2505 depPtr = &depPaths.LateSharedLibsDeps
2506 default:
2507 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002508 }
Colin Cross6e511a92020-07-27 21:26:48 -07002509 case libDepTag.static():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002510 if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
2511 if !ctx.Config().AllowMissingDependencies() {
2512 ctx.ModuleErrorf("module %q is not a static library", depName)
2513 } else {
2514 ctx.AddMissingDependencies([]string{depName})
2515 }
2516 return
2517 }
2518 staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2519 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
Colin Cross6e511a92020-07-27 21:26:48 -07002520 if libDepTag.wholeStatic {
2521 ptr = &depPaths.WholeStaticLibs
Colin Cross0de8a1e2020-09-18 14:15:30 -07002522 if len(staticLibraryInfo.Objects.objFiles) > 0 {
2523 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
Inseob Kimeec88e12020-01-22 11:11:29 +09002524 } else {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002525 // This case normally catches prebuilt static
2526 // libraries, but it can also occur when
2527 // AllowMissingDependencies is on and the
2528 // dependencies has no sources of its own
2529 // but has a whole_static_libs dependency
2530 // on a missing library. We want to depend
2531 // on the .a file so that there is something
2532 // in the dependency tree that contains the
2533 // error rule for the missing transitive
2534 // dependency.
2535 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002536 }
Colin Cross6e511a92020-07-27 21:26:48 -07002537 } else {
2538 switch libDepTag.Order {
2539 case earlyLibraryDependency:
2540 panic(fmt.Errorf("early static libs not suppported"))
2541 case normalLibraryDependency:
2542 // static dependencies will be handled separately so they can be ordered
2543 // using transitive dependencies.
2544 ptr = nil
Colin Cross0de8a1e2020-09-18 14:15:30 -07002545 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002546 case lateLibraryDependency:
2547 ptr = &depPaths.LateStaticLibs
2548 default:
2549 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002550 }
2551 }
2552 }
2553
Colin Cross6e511a92020-07-27 21:26:48 -07002554 if libDepTag.static() && !libDepTag.wholeStatic {
2555 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2556 ctx.ModuleErrorf("module %q not a static library", depName)
2557 return
2558 }
Logan Chien43d34c32017-12-20 01:17:32 +08002559
Colin Cross6e511a92020-07-27 21:26:48 -07002560 // When combining coverage files for shared libraries and executables, coverage files
2561 // in static libraries act as if they were whole static libraries. The same goes for
2562 // source based Abi dump files.
2563 if c, ok := ccDep.(*Module); ok {
2564 staticLib := c.linker.(libraryInterface)
2565 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2566 staticLib.objs().coverageFiles...)
2567 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2568 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002569 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002570 // Handle non-CC modules here
2571 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002572 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002573 }
2574 }
2575
Colin Cross6e511a92020-07-27 21:26:48 -07002576 if ptr != nil {
2577 if !linkFile.Valid() {
2578 if !ctx.Config().AllowMissingDependencies() {
2579 ctx.ModuleErrorf("module %q missing output file", depName)
2580 } else {
2581 ctx.AddMissingDependencies([]string{depName})
2582 }
2583 return
2584 }
2585 *ptr = append(*ptr, linkFile.Path())
2586 }
2587
2588 if depPtr != nil {
2589 dep := depFile
2590 if !dep.Valid() {
2591 dep = linkFile
2592 }
2593 *depPtr = append(*depPtr, dep.Path())
2594 }
2595
Colin Cross0de8a1e2020-09-18 14:15:30 -07002596 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
2597 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
2598 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
2599 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
2600
2601 if libDepTag.reexportFlags {
2602 reexportExporter(depExporterInfo)
2603 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2604 // Re-exported shared library headers must be included as well since they can help us with type information
2605 // about template instantiations (instantiated from their headers).
2606 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2607 // scripts.
2608 c.sabi.Properties.ReexportedIncludes = append(
2609 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
2610 }
2611
Colin Cross6e511a92020-07-27 21:26:48 -07002612 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2613 switch {
2614 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002615 c.Properties.AndroidMkHeaderLibs = append(
2616 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002617 case libDepTag.shared():
Colin Cross31076b32020-10-23 17:22:06 -07002618 if lib := moduleLibraryInterface(dep); lib != nil {
2619 if lib.buildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002620 // Add the dependency to the APEX(es) providing the library so that
2621 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002622 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2623 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002624 c.Properties.ApexesProvidingSharedLibs = append(
2625 c.Properties.ApexesProvidingSharedLibs, an)
2626 }
2627 }
2628 }
2629
2630 // Note: the order of libs in this list is not important because
2631 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002632 c.Properties.AndroidMkSharedLibs = append(
2633 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002634 // Record baseLibName for snapshots.
2635 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2636 case libDepTag.static():
2637 if libDepTag.wholeStatic {
2638 c.Properties.AndroidMkWholeStaticLibs = append(
2639 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2640 } else {
2641 c.Properties.AndroidMkStaticLibs = append(
2642 c.Properties.AndroidMkStaticLibs, makeLibName)
2643 }
2644 }
2645 } else {
2646 switch depTag {
2647 case runtimeDepTag:
2648 c.Properties.AndroidMkRuntimeLibs = append(
2649 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2650 // Record baseLibName for snapshots.
2651 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2652 case objDepTag:
2653 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2654 case CrtBeginDepTag:
2655 depPaths.CrtBegin = linkFile
2656 case CrtEndDepTag:
2657 depPaths.CrtEnd = linkFile
2658 case dynamicLinkerDepTag:
2659 depPaths.DynamicLinker = linkFile
2660 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002661 }
Colin Crossca860ac2016-01-04 14:34:37 -08002662 })
2663
Jeff Gaston294356f2017-09-27 17:05:30 -07002664 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07002665 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
2666 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
2667 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002668
Colin Crossdd84e052017-05-17 13:44:16 -07002669 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002670 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002671 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2672 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002673 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002674 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2675 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002676 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002677 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002678 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002679
2680 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002681 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002682 }
Colin Crossdd84e052017-05-17 13:44:16 -07002683
Colin Crossca860ac2016-01-04 14:34:37 -08002684 return depPaths
2685}
2686
Colin Cross0de8a1e2020-09-18 14:15:30 -07002687// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
2688// to match the topological order of the dependency tree, including any static analogues of
2689// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
2690// of the transitive dependencies.
2691func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
2692 transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
2693 var staticPaths android.Paths
2694 for _, staticDep := range staticDeps {
2695 staticPaths = append(staticPaths, staticDep.StaticLibrary)
2696 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
2697 }
2698 for _, sharedDep := range sharedDeps {
2699 if sharedDep.StaticAnalogue != nil {
2700 transitiveStaticLibsBuilder.Transitive(sharedDep.StaticAnalogue.TransitiveStaticLibrariesForOrdering)
2701 }
2702 }
2703 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
2704
2705 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
2706
2707 // reorder the dependencies based on transitive dependencies
2708 staticPaths = android.FirstUniquePaths(staticPaths)
2709 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
2710
2711 if len(orderedStaticPaths) != len(staticPaths) {
2712 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
2713 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
2714 }
2715
2716 return orderedStaticPaths, transitiveStaticLibs
2717}
2718
Colin Cross6e511a92020-07-27 21:26:48 -07002719// baseLibName trims known prefixes and suffixes
2720func baseLibName(depName string) string {
2721 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2722 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2723 libName = strings.TrimPrefix(libName, "prebuilt_")
2724 return libName
2725}
2726
2727func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2728 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2729 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2730
2731 libName := baseLibName(depName)
2732 isLLndk := isLlndkLibrary(libName, ctx.Config())
2733 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2734 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2735
2736 if c, ok := ccDep.(*Module); ok {
2737 // Use base module name for snapshots when exporting to Makefile.
2738 if c.isSnapshotPrebuilt() {
2739 baseName := c.BaseModuleName()
2740
2741 if c.IsVndk() {
2742 return baseName + ".vendor"
2743 }
2744
2745 if vendorSuffixModules[baseName] {
2746 return baseName + ".vendor"
2747 } else {
2748 return baseName
2749 }
2750 }
2751 }
2752
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002753 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() &&
2754 !c.InRamdisk() && !c.InVendorRamdisk() && !c.InRecovery() {
Colin Cross6e511a92020-07-27 21:26:48 -07002755 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2756 // core module instead.
2757 return libName
2758 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2759 // The vendor module in Make will have been renamed to not conflict with the core
2760 // module, so update the dependency name here accordingly.
2761 return libName + c.getNameSuffixWithVndkVersion(ctx)
2762 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2763 return libName + vendorPublicLibrarySuffix
2764 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2765 return libName + ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002766 } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
2767 return libName + vendorRamdiskSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07002768 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2769 return libName + recoverySuffix
2770 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2771 return libName + nativeBridgeSuffix
2772 } else {
2773 return libName
2774 }
2775}
2776
Colin Crossca860ac2016-01-04 14:34:37 -08002777func (c *Module) InstallInData() bool {
2778 if c.installer == nil {
2779 return false
2780 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002781 return c.installer.inData()
2782}
2783
2784func (c *Module) InstallInSanitizerDir() bool {
2785 if c.installer == nil {
2786 return false
2787 }
2788 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002789 return true
2790 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002791 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002792}
2793
Yifan Hong1b3348d2020-01-21 15:53:22 -08002794func (c *Module) InstallInRamdisk() bool {
2795 return c.InRamdisk()
2796}
2797
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002798func (c *Module) InstallInVendorRamdisk() bool {
2799 return c.InVendorRamdisk()
2800}
2801
Jiyong Parkf9332f12018-02-01 00:54:12 +09002802func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002803 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002804}
2805
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002806func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002807 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002808 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002809 return
2810 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002811 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002812}
2813
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002814func (c *Module) HostToolPath() android.OptionalPath {
2815 if c.installer == nil {
2816 return android.OptionalPath{}
2817 }
2818 return c.installer.hostToolPath()
2819}
2820
Nan Zhangd4e641b2017-07-12 12:55:28 -07002821func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2822 return c.outputFile
2823}
2824
Colin Cross41955e82019-05-29 14:40:35 -07002825func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2826 switch tag {
2827 case "":
2828 if c.outputFile.Valid() {
2829 return android.Paths{c.outputFile.Path()}, nil
2830 }
2831 return android.Paths{}, nil
2832 default:
2833 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002834 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002835}
2836
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002837func (c *Module) static() bool {
2838 if static, ok := c.linker.(interface {
2839 static() bool
2840 }); ok {
2841 return static.static()
2842 }
2843 return false
2844}
2845
Jiyong Park379de2f2018-12-19 02:47:14 +09002846func (c *Module) staticBinary() bool {
2847 if static, ok := c.linker.(interface {
2848 staticBinary() bool
2849 }); ok {
2850 return static.staticBinary()
2851 }
2852 return false
2853}
2854
Jiyong Park1d1119f2019-07-29 21:27:18 +09002855func (c *Module) header() bool {
2856 if h, ok := c.linker.(interface {
2857 header() bool
2858 }); ok {
2859 return h.header()
2860 }
2861 return false
2862}
2863
Inseob Kim7f283f42020-06-01 21:53:49 +09002864func (c *Module) binary() bool {
2865 if b, ok := c.linker.(interface {
2866 binary() bool
2867 }); ok {
2868 return b.binary()
2869 }
2870 return false
2871}
2872
Inseob Kim1042d292020-06-01 23:23:05 +09002873func (c *Module) object() bool {
2874 if o, ok := c.linker.(interface {
2875 object() bool
2876 }); ok {
2877 return o.object()
2878 }
2879 return false
2880}
2881
Jooyung Han38002912019-05-16 04:01:54 +09002882func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002883 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002884 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2885 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002886 return "native:vndk"
2887 }
Jooyung Han38002912019-05-16 04:01:54 +09002888 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002889 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002890 if c.IsVndk() && !c.isVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +09002891 // Product_available, if defined, must have the same value with Vendor_available.
Jooyung Han38002912019-05-16 04:01:54 +09002892 if Bool(c.VendorProperties.Vendor_available) {
2893 return "native:vndk"
2894 }
2895 return "native:vndk_private"
2896 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002897 if c.inProduct() {
2898 return "native:product"
2899 }
Jooyung Han38002912019-05-16 04:01:54 +09002900 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002901 } else if c.InRamdisk() {
2902 return "native:ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002903 } else if c.InVendorRamdisk() {
2904 return "native:vendor_ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002905 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002906 return "native:recovery"
2907 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2908 return "native:ndk:none:none"
2909 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2910 //family, link := getNdkStlFamilyAndLinkType(c)
2911 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002912 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002913 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002914 } else {
2915 return "native:platform"
2916 }
2917}
2918
Jiyong Park9d452992018-10-03 00:38:19 +09002919// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002920// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002921func (c *Module) IsInstallableToApex() bool {
Colin Cross31076b32020-10-23 17:22:06 -07002922 if lib := c.library; lib != nil {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002923 // Stub libs and prebuilt libs in a versioned SDK are not
2924 // installable to APEX even though they are shared libs.
Colin Cross31076b32020-10-23 17:22:06 -07002925 return lib.shared() && !lib.buildStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002926 } else if _, ok := c.linker.(testPerSrc); ok {
2927 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002928 }
2929 return false
2930}
2931
Jiyong Parka90ca002019-10-07 15:47:24 +09002932func (c *Module) AvailableFor(what string) bool {
2933 if linker, ok := c.linker.(interface {
2934 availableFor(string) bool
2935 }); ok {
2936 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2937 } else {
2938 return c.ApexModuleBase.AvailableFor(what)
2939 }
2940}
2941
Jiyong Park62304bb2020-04-13 16:19:48 +09002942func (c *Module) TestFor() []string {
Jiyong Park46a512f2020-12-04 18:02:13 +09002943 return c.Properties.Test_for
Jiyong Park62304bb2020-04-13 16:19:48 +09002944}
2945
Colin Crossaede88c2020-08-11 12:17:01 -07002946func (c *Module) UniqueApexVariations() bool {
2947 if u, ok := c.compiler.(interface {
2948 uniqueApexVariations() bool
2949 }); ok {
2950 return u.uniqueApexVariations()
2951 } else {
2952 return false
2953 }
2954}
2955
Paul Duffin0cb37b92020-03-04 14:52:46 +00002956// Return true if the module is ever installable.
2957func (c *Module) EverInstallable() bool {
2958 return c.installer != nil &&
2959 // Check to see whether the module is actually ever installable.
2960 c.installer.everInstallable()
2961}
2962
Colin Cross56a83212020-09-15 18:30:11 -07002963func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002964 ret := c.EverInstallable() &&
2965 // Check to see whether the module has been configured to not be installed.
2966 proptools.BoolDefault(c.Properties.Installable, true) &&
2967 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002968
2969 // The platform variant doesn't need further condition. Apex variants however might not
2970 // be installable because it will likely to be included in the APEX and won't appear
2971 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07002972 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002973 return ret
2974 }
2975
2976 // Special case for modules that are configured to be installed to /data, which includes
2977 // test modules. For these modules, both APEX and non-APEX variants are considered as
2978 // installable. This is because even the APEX variants won't be included in the APEX, but
2979 // will anyway be installed to /data/*.
2980 // See b/146995717
2981 if c.InstallInData() {
2982 return ret
2983 }
2984
2985 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002986}
2987
Logan Chien41eabe62019-04-10 13:33:58 +08002988func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2989 if c.linker != nil {
2990 if library, ok := c.linker.(*libraryDecorator); ok {
2991 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2992 }
2993 }
2994}
2995
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002996func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002997 depTag := ctx.OtherModuleDependencyTag(dep)
2998 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2999
3000 if cc, ok := dep.(*Module); ok {
3001 if cc.HasStubsVariants() {
3002 if isLibDepTag && libDepTag.shared() {
3003 // dynamic dep to a stubs lib crosses APEX boundary
3004 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003005 }
Colin Cross6e511a92020-07-27 21:26:48 -07003006 if IsRuntimeDepTag(depTag) {
3007 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003008 return false
3009 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003010 }
Colin Crossaac32222020-07-29 12:51:56 -07003011 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003012 // shared_lib dependency from a static lib is considered as crossing
3013 // the APEX boundary because the dependency doesn't actually is
3014 // linked; the dependency is used only during the compilation phase.
3015 return false
3016 }
3017 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07003018 if depTag == stubImplDepTag || depTag == llndkImplDep {
3019 // We don't track beyond LLNDK or from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09003020 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003021 }
3022 return true
3023}
3024
Dan Albertc8060532020-07-22 22:32:17 -07003025func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3026 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003027 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3028 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3029 return nil
3030 }
3031 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3032 if c.ToolchainLibrary() {
3033 return nil
3034 }
3035 // We don't check for prebuilt modules
3036 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3037 return nil
3038 }
3039 minSdkVersion := c.MinSdkVersion()
3040 if minSdkVersion == "apex_inherit" {
3041 return nil
3042 }
3043 if minSdkVersion == "" {
3044 // JNI libs within APK-in-APEX fall into here
3045 // Those are okay to set sdk_version instead
3046 // We don't have to check if this is a SDK variant because
3047 // non-SDK variant resets sdk_version, which works too.
3048 minSdkVersion = c.SdkVersion()
3049 }
Dan Albertc8060532020-07-22 22:32:17 -07003050 if minSdkVersion == "" {
3051 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3052 }
3053 // Not using nativeApiLevelFromUser because the context here is not
3054 // necessarily a native context.
3055 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003056 if err != nil {
3057 return err
3058 }
Dan Albertc8060532020-07-22 22:32:17 -07003059
3060 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003061 return fmt.Errorf("newer SDK(%v)", ver)
3062 }
3063 return nil
3064}
3065
Colin Cross2ba19d92015-05-07 15:44:20 -07003066//
Colin Crosscfad1192015-11-02 16:43:11 -08003067// Defaults
3068//
Colin Crossca860ac2016-01-04 14:34:37 -08003069type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003070 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003071 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003072 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003073}
3074
Patrice Arrudac249c712019-03-19 17:00:29 -07003075// cc_defaults provides a set of properties that can be inherited by other cc
3076// modules. A module can use the properties from a cc_defaults using
3077// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3078// merged (when possible) by prepending the default module's values to the
3079// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003080func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003081 return DefaultsFactory()
3082}
3083
Colin Cross36242852017-06-23 15:06:31 -07003084func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003085 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003086
Colin Cross36242852017-06-23 15:06:31 -07003087 module.AddProperties(props...)
3088 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003089 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003090 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003091 &BaseCompilerProperties{},
3092 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003093 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003094 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003095 &StaticProperties{},
3096 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003097 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003098 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003099 &TestProperties{},
3100 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003101 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003102 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003103 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003104 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003105 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003106 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003107 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003108 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003109 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003110 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003111 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003112 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003113 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003114 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3115 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003116 )
Colin Crosscfad1192015-11-02 16:43:11 -08003117
Jooyung Hancc372c52019-09-25 15:18:44 +09003118 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003119
3120 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003121}
3122
Jiyong Park2286afd2020-06-16 21:58:53 +09003123func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003124 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003125}
3126
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003127func kytheExtractAllFactory() android.Singleton {
3128 return &kytheExtractAllSingleton{}
3129}
3130
3131type kytheExtractAllSingleton struct {
3132}
3133
3134func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3135 var xrefTargets android.Paths
3136 ctx.VisitAllModules(func(module android.Module) {
3137 if ccModule, ok := module.(xref); ok {
3138 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3139 }
3140 })
3141 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3142 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003143 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003144 }
3145}
3146
Colin Cross06a931b2015-10-28 17:23:31 -07003147var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003148var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003149var BoolPtr = proptools.BoolPtr
3150var String = proptools.String
3151var StringPtr = proptools.StringPtr