blob: 5cd3b04dc03c6430f7d747803b62e9ac49d8926e [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
Jiyong Parke3867542020-12-03 17:28:25 +0900132
133 // List of libs that need to be excluded for APEX variant
134 ExcludeLibsForApex []string
Colin Crossc472d572015-03-17 15:06:21 -0700135}
136
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500137// PathDeps is a struct containing file paths to dependencies of a module.
138// It's constructed in depsToPath() by traversing the direct dependencies of the current module.
139// It's used to construct flags for various build statements (such as for compiling and linking).
140// It is then passed to module decorator functions responsible for registering build statements
141// (such as `module.compiler.compile()`).`
Colin Crossca860ac2016-01-04 14:34:37 -0800142type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700143 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900144 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700145 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900146 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700147 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700148 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700149
Colin Cross0de8a1e2020-09-18 14:15:30 -0700150 // Transitive static library dependencies of static libraries for use in ordering.
151 TranstiveStaticLibrariesForOrdering *android.DepSet
152
Colin Cross26c34ed2016-09-30 17:10:16 -0700153 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100154 Objs Objects
155 // Paths to .o files in dependencies that provide them. Note that these lists
156 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800157 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700158 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700159
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100160 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
161 // the libs from all whole_static_lib dependencies.
162 WholeStaticLibsFromPrebuilts android.Paths
163
Colin Cross26c34ed2016-09-30 17:10:16 -0700164 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700165 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900166 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700167
Inseob Kimd110f872019-12-06 13:15:38 +0900168 Flags []string
169 IncludeDirs android.Paths
170 SystemIncludeDirs android.Paths
171 ReexportedDirs android.Paths
172 ReexportedSystemDirs android.Paths
173 ReexportedFlags []string
174 ReexportedGeneratedHeaders android.Paths
175 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700176
Colin Cross26c34ed2016-09-30 17:10:16 -0700177 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700178 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700179
180 // Path to the file container flags to use with the linker
181 LinkerFlagsFile android.OptionalPath
182
183 // Path to the dynamic linker binary
184 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700185}
186
Colin Cross4af21ed2019-11-04 09:37:55 -0800187// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
188// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
189// command line so they can be overridden by the local module flags).
190type LocalOrGlobalFlags struct {
191 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700192 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800193 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700194 CFlags []string // Flags that apply to C and C++ source files
195 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
196 ConlyFlags []string // Flags that apply to C source files
197 CppFlags []string // Flags that apply to C++ source files
198 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700199 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800200}
201
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500202// Flags contains various types of command line flags (and settings) for use in building build
203// statements related to C++.
Colin Cross4af21ed2019-11-04 09:37:55 -0800204type Flags struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500205 // Local flags (which individual modules are responsible for). These may override global flags.
206 Local LocalOrGlobalFlags
207 // Global flags (which build system or toolchain is responsible for).
Colin Cross4af21ed2019-11-04 09:37:55 -0800208 Global LocalOrGlobalFlags
209
210 aidlFlags []string // Flags that apply to aidl source files
211 rsFlags []string // Flags that apply to renderscript source files
212 libFlags []string // Flags to add libraries early to the link order
213 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
214 TidyFlags []string // Flags that apply to clang-tidy
215 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700216
Colin Crossc3199482017-03-30 15:03:04 -0700217 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800218 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700219 SystemIncludeFlags []string
220
Oliver Nguyen04526782020-04-21 12:40:27 -0700221 Toolchain config.Toolchain
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500222 Tidy bool // True if clang-tidy is enabled.
223 GcovCoverage bool // True if coverage files should be generated.
224 SAbiDump bool // True if header abi dumps should be generated.
Oliver Nguyen04526782020-04-21 12:40:27 -0700225 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800226
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500227 // The instruction set required for clang ("arm" or "thumb").
Colin Crossca860ac2016-01-04 14:34:37 -0800228 RequiredInstructionSet string
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500229 // The target-device system path to the dynamic linker.
230 DynamicLinker string
Colin Cross16b23492016-01-06 14:41:07 -0800231
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700232 CFlagsDeps android.Paths // Files depended on by compiler flags
233 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800234
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500235 // True if .s files should be processed with the c preprocessor.
Dan Willemsen98ab3112019-08-27 21:20:40 -0700236 AssemblerWithCpp bool
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500237 // True if static libraries should be grouped (using `-Wl,--start-group` and `-Wl,--end-group`).
238 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800239
Colin Cross19878da2019-03-28 14:45:07 -0700240 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700241 protoC bool // Whether to use C instead of C++
242 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700243
244 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200245 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700246}
247
Colin Crossca860ac2016-01-04 14:34:37 -0800248// Properties used to compile all C or C++ modules
249type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700250 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800251 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700252
Colin Crossc511bc52020-04-07 16:50:32 +0000253 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
254 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800255 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700256
Jooyung Han379660c2020-04-21 15:24:00 +0900257 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
258 Min_sdk_version *string
259
Colin Crossc511bc52020-04-07 16:50:32 +0000260 // If true, always create an sdk variant and don't create a platform variant.
261 Sdk_variant_only *bool
262
Jiyong Parkde866cb2018-12-07 23:08:36 +0900263 AndroidMkSharedLibs []string `blueprint:"mutated"`
264 AndroidMkStaticLibs []string `blueprint:"mutated"`
265 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
266 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700267 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900268 HideFromMake bool `blueprint:"mutated"`
269 PreventInstall bool `blueprint:"mutated"`
270 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700271
Yo Chiang219968c2020-09-22 18:45:04 +0800272 // Set by DepsMutator.
273 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
274
Justin Yun5f7f7e82019-11-18 19:52:14 +0900275 ImageVariationPrefix string `blueprint:"mutated"`
276 VndkVersion string `blueprint:"mutated"`
277 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800278
279 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
280 // file
281 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900282
Yifan Hong39143a92020-10-26 12:43:12 -0700283 // Make this module available when building for ramdisk.
284 // On device without a dedicated recovery partition, the module is only
285 // available after switching root into
286 // /first_stage_ramdisk. To expose the module before switching root, install
287 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -0800288 Ramdisk_available *bool
289
Yifan Hong39143a92020-10-26 12:43:12 -0700290 // Make this module available when building for vendor ramdisk.
291 // On device without a dedicated recovery partition, the module is only
292 // available after switching root into
293 // /first_stage_ramdisk. To expose the module before switching root, install
294 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700295 Vendor_ramdisk_available *bool
296
Jiyong Parkf9332f12018-02-01 00:54:12 +0900297 // Make this module available when building for recovery
298 Recovery_available *bool
299
Colin Crossae6c5202019-11-20 13:35:50 -0800300 // Set by imageMutator
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700301 CoreVariantNeeded bool `blueprint:"mutated"`
302 RamdiskVariantNeeded bool `blueprint:"mutated"`
303 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
304 RecoveryVariantNeeded bool `blueprint:"mutated"`
305 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900306
307 // Allows this module to use non-APEX version of libraries. Useful
308 // for building binaries that are started before APEXes are activated.
309 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900310
311 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
312 // see soong/cc/config/vndk.go
313 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900314
315 // Used by vendor snapshot to record dependencies from snapshot modules.
316 SnapshotSharedLibs []string `blueprint:"mutated"`
317 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000318
319 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000320
321 // Set by factories of module types that can only be referenced from variants compiled against
322 // the SDK.
323 AlwaysSdk bool `blueprint:"mutated"`
324
325 // Variant is an SDK variant created by sdkMutator
326 IsSdkVariant bool `blueprint:"mutated"`
327 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
328 // variant to have a ".sdk" suffix.
329 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700330
331 // Normally Soong uses the directory structure to decide which modules
332 // should be included (framework) or excluded (non-framework) from the
Jose Galmesf7294582020-11-13 12:07:36 -0800333 // different snapshots (vendor, recovery, etc.), but these properties
334 // allow a partner to exclude a module normally thought of as a
335 // framework module from a snapshot.
336 Exclude_from_vendor_snapshot *bool
337 Exclude_from_recovery_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700338}
339
340type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900341 // whether this module should be allowed to be directly depended by other
342 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun63e9ec72020-10-29 16:49:43 +0900343 // If set to true, two variants will be built separately, one like
344 // normal, and the other limited to the set of libraries and headers
345 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700346 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900347 // The vendor variant may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700348 // so it shouldn't have any unversioned runtime dependencies, or
349 // make assumptions about the system that may not be true in the
350 // future.
351 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900352 // If set to false, this module becomes inaccessible from /vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900353 //
354 // Default value is true when vndk: {enabled: true} or vendor: true.
355 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700356 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
357 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900358
Justin Yun63e9ec72020-10-29 16:49:43 +0900359 // whether this module should be allowed to be directly depended by other
360 // modules with `product_specific: true` or `product_available: true`.
361 // If set to true, an additional product variant will be built separately
362 // that is limited to the set of libraries and headers that are exposed to
363 // /product modules.
364 //
365 // The product variant may be used with a different (newer) /system,
366 // so it shouldn't have any unversioned runtime dependencies, or
367 // make assumptions about the system that may not be true in the
368 // future.
369 //
370 // It must be set to true by default for vndk: {enabled: true} modules.
371 //
372 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
373 // and PRODUCT_PRODUCT_VNDK_VERSION isn't set.
374 Product_available *bool
375
Jiyong Park5fb8c102018-04-09 12:03:06 +0900376 // whether this module is capable of being loaded with other instance
377 // (possibly an older version) of the same module in the same process.
378 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
379 // can be double loaded in a vendor process if the library is also a
380 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
381 // explicitly marked as `double_loadable: true` by the owner, or the dependency
382 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
383 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800384}
385
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500386// ModuleContextIntf is an interface (on a module context helper) consisting of functions related
387// to understanding details about the type of the current module.
388// For example, one might call these functions to determine whether the current module is a static
389// library and/or is installed in vendor directories.
Colin Crossca860ac2016-01-04 14:34:37 -0800390type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800391 static() bool
392 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900393 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900394 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900395 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700396 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900397 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700398 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800399 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700400 useVndk() bool
Colin Cross95f1ca02020-10-29 20:47:22 -0700401 isNdk(config android.Config) bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900402 isLlndk(config android.Config) bool
403 isLlndkPublic(config android.Config) bool
404 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900405 isVndk() bool
406 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800407 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900408 inProduct() bool
409 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800410 inRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700411 inVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900412 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800413 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700414 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700415 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800416 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800417 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800418 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800419 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800420 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700421 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700422 apexSdkVersion() android.ApiLevel
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900423 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800424 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700425 nativeCoverage() bool
Colin Cross56a83212020-09-15 18:30:11 -0700426 directlyInAnyApex() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800427}
428
429type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700430 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800431 ModuleContextIntf
432}
433
434type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700435 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800436 ModuleContextIntf
437}
438
Colin Cross37047f12016-12-13 17:06:13 -0800439type DepsContext interface {
440 android.BottomUpMutatorContext
441 ModuleContextIntf
442}
443
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500444// feature represents additional (optional) steps to building cc-related modules, such as invocation
445// of clang-tidy.
Colin Crossca860ac2016-01-04 14:34:37 -0800446type feature interface {
447 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800448 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800449 flags(ctx ModuleContext, flags Flags) Flags
450 props() []interface{}
451}
452
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500453// compiler is the interface for a compiler helper object. Different module decorators may implement
454// this helper differently. For example, compiling a `cc_library` may use a different build
455// statement than building a `toolchain_library`.
Colin Crossca860ac2016-01-04 14:34:37 -0800456type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700457 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800458 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800459 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700460 compilerProps() []interface{}
461
Colin Cross76fada02016-07-27 10:31:13 -0700462 appendCflags([]string)
463 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700464 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800465}
466
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500467// linker is the interface for a linker decorator object. Individual module types can provide
468// their own implementation for this decorator, and thus specify custom logic regarding build
469// statements pertaining to linking.
Colin Crossca860ac2016-01-04 14:34:37 -0800470type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700471 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800472 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700473 linkerFlags(ctx ModuleContext, flags Flags) Flags
474 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800475 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700476
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700477 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700478 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900479 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700480
481 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900482 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000483
484 // Get the deps that have been explicitly specified in the properties.
Paul Duffin13f02712020-03-06 12:30:43 +0000485 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
486}
487
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500488// specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
Paul Duffin13f02712020-03-06 12:30:43 +0000489type specifiedDeps struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500490 sharedLibs []string
491 // Note nil and [] are semantically distinct. [] prevents linking against the defaults (usually
492 // libc, libm, etc.)
493 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800494}
495
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500496// installer is the interface for an installer helper object. This helper is responsible for
497// copying build outputs to the appropriate locations so that they may be installed on device.
Colin Crossca860ac2016-01-04 14:34:37 -0800498type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700499 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700500 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000501 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800502 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700503 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700504 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900505 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100506 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800507}
508
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800509type xref interface {
510 XrefCcFiles() android.Paths
511}
512
Colin Cross6e511a92020-07-27 21:26:48 -0700513type libraryDependencyKind int
514
515const (
516 headerLibraryDependency = iota
517 sharedLibraryDependency
518 staticLibraryDependency
519)
520
521func (k libraryDependencyKind) String() string {
522 switch k {
523 case headerLibraryDependency:
524 return "headerLibraryDependency"
525 case sharedLibraryDependency:
526 return "sharedLibraryDependency"
527 case staticLibraryDependency:
528 return "staticLibraryDependency"
529 default:
530 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
531 }
532}
533
534type libraryDependencyOrder int
535
536const (
537 earlyLibraryDependency = -1
538 normalLibraryDependency = 0
539 lateLibraryDependency = 1
540)
541
542func (o libraryDependencyOrder) String() string {
543 switch o {
544 case earlyLibraryDependency:
545 return "earlyLibraryDependency"
546 case normalLibraryDependency:
547 return "normalLibraryDependency"
548 case lateLibraryDependency:
549 return "lateLibraryDependency"
550 default:
551 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
552 }
553}
554
555// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
556// tags that have a set of predefined tag objects that are reused for each dependency, a
557// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
558// That means that comparing a libraryDependencyTag for equality will only be equal if all
559// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
560// then check individual metadata fields instead.
561type libraryDependencyTag struct {
562 blueprint.BaseDependencyTag
563
564 // These are exported so that fmt.Printf("%#v") can call their String methods.
565 Kind libraryDependencyKind
566 Order libraryDependencyOrder
567
568 wholeStatic bool
569
570 reexportFlags bool
571 explicitlyVersioned bool
572 dataLib bool
573 ndk bool
574
575 staticUnwinder bool
576
577 makeSuffix string
Jiyong Parke3867542020-12-03 17:28:25 +0900578
579 // Whether or not this dependency has to be followed for the apex variants
580 excludeInApex bool
Colin Cross6e511a92020-07-27 21:26:48 -0700581}
582
583// header returns true if the libraryDependencyTag is tagging a header lib dependency.
584func (d libraryDependencyTag) header() bool {
585 return d.Kind == headerLibraryDependency
586}
587
588// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
589func (d libraryDependencyTag) shared() bool {
590 return d.Kind == sharedLibraryDependency
591}
592
593// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
594func (d libraryDependencyTag) static() bool {
595 return d.Kind == staticLibraryDependency
596}
597
Colin Crosse9fe2942020-11-10 18:12:15 -0800598// InstallDepNeeded returns true for shared libraries so that shared library dependencies of
599// binaries or other shared libraries are installed as dependencies.
600func (d libraryDependencyTag) InstallDepNeeded() bool {
601 return d.shared()
602}
603
604var _ android.InstallNeededDependencyTag = libraryDependencyTag{}
605
606// dependencyTag is used for tagging miscellaneous dependency types that don't fit into
Colin Cross6e511a92020-07-27 21:26:48 -0700607// libraryDependencyTag. Each tag object is created globally and reused for multiple
608// dependencies (although since the object contains no references, assigning a tag to a
609// variable and modifying it will not modify the original). Users can compare the tag
610// returned by ctx.OtherModuleDependencyTag against the global original
611type dependencyTag struct {
612 blueprint.BaseDependencyTag
613 name string
614}
615
Colin Crosse9fe2942020-11-10 18:12:15 -0800616// installDependencyTag is used for tagging miscellaneous dependency types that don't fit into
617// libraryDependencyTag, but where the dependency needs to be installed when the parent is
618// installed.
619type installDependencyTag struct {
620 blueprint.BaseDependencyTag
621 android.InstallAlwaysNeededDependencyTag
622 name string
623}
624
Colin Crossc99deeb2016-04-11 15:06:20 -0700625var (
Colin Cross6e511a92020-07-27 21:26:48 -0700626 genSourceDepTag = dependencyTag{name: "gen source"}
627 genHeaderDepTag = dependencyTag{name: "gen header"}
628 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
629 objDepTag = dependencyTag{name: "obj"}
630 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
Jiyong Parkd630bdd2020-11-25 11:47:24 +0900631 dynamicLinkerDepTag = installDependencyTag{name: "dynamic linker"}
Colin Cross6e511a92020-07-27 21:26:48 -0700632 reuseObjTag = dependencyTag{name: "reuse objects"}
633 staticVariantTag = dependencyTag{name: "static variant"}
634 vndkExtDepTag = dependencyTag{name: "vndk extends"}
635 dataLibDepTag = dependencyTag{name: "data lib"}
Colin Crosse9fe2942020-11-10 18:12:15 -0800636 runtimeDepTag = installDependencyTag{name: "runtime lib"}
Colin Cross6e511a92020-07-27 21:26:48 -0700637 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700638 stubImplDepTag = dependencyTag{name: "stub_impl"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700639)
640
Colin Cross56a83212020-09-15 18:30:11 -0700641type copyDirectlyInAnyApexDependencyTag dependencyTag
642
643func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
644
645var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
646
Roland Levillainf89cd092019-07-29 16:22:59 +0100647func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700648 ccLibDepTag, ok := depTag.(libraryDependencyTag)
649 return ok && ccLibDepTag.shared()
650}
651
652func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
653 ccLibDepTag, ok := depTag.(libraryDependencyTag)
654 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100655}
656
Zach Johnson3df4e632020-11-06 11:56:27 -0800657func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
658 ccLibDepTag, ok := depTag.(libraryDependencyTag)
659 return ok && ccLibDepTag.header()
660}
661
Roland Levillainf89cd092019-07-29 16:22:59 +0100662func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Crosse9fe2942020-11-10 18:12:15 -0800663 return depTag == runtimeDepTag
Roland Levillainf89cd092019-07-29 16:22:59 +0100664}
665
666func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700667 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100668 return ok && ccDepTag == testPerSrcDepTag
669}
670
Colin Crossca860ac2016-01-04 14:34:37 -0800671// Module contains the properties and members used by all C/C++ module types, and implements
672// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500673// to construct the output file. Behavior can be customized with a Customizer, or "decorator",
674// interface.
675//
676// To define a C/C++ related module, construct a new Module object and point its delegates to
677// type-specific structs. These delegates will be invoked to register module-specific build
678// statements which may be unique to the module type. For example, module.compiler.compile() should
679// be defined so as to register build statements which are responsible for compiling the module.
680//
681// Another example: to construct a cc_binary module, one can create a `cc.binaryDecorator` struct
682// which implements the `linker` and `installer` interfaces, and points the `linker` and `installer`
683// members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
684// installer logic.
Colin Crossca860ac2016-01-04 14:34:37 -0800685type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700686 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700687 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900688 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900689 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700690
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700691 Properties BaseProperties
692 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700693
Colin Crossca860ac2016-01-04 14:34:37 -0800694 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700695 hod android.HostOrDeviceSupported
696 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700697
Paul Duffina0843f62019-12-13 19:50:38 +0000698 // Allowable SdkMemberTypes of this module type.
699 sdkMemberTypes []android.SdkMemberType
700
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500701 // decorator delegates, initialize before calling Init
702 // these may contain module-specific implementations, and effectively allow for custom
703 // type-specific logic. These members may reference different objects or the same object.
704 // Functions of these decorators will be invoked to initialize and register type-specific
705 // build statements.
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700706 compiler compiler
707 linker linker
708 installer installer
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500709
710 features []feature
711 stl *stl
712 sanitize *sanitize
713 coverage *coverage
714 sabi *sabi
715 vndkdep *vndkdep
716 lto *lto
717 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800718
Colin Cross31076b32020-10-23 17:22:06 -0700719 library libraryInterface
720
Colin Cross635c3b02016-05-18 15:37:25 -0700721 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800722
Colin Crossb98c8b02016-07-29 13:44:28 -0700723 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700724
725 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800726
727 // Flags used to compile this module
728 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700729
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800730 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700731 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900732
733 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800734 // Kythe (source file indexer) paths for this compilation module
735 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900736
737 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700738 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700739
740 hideApexVariantFromMake bool
Colin Crossc472d572015-03-17 15:06:21 -0700741}
742
Ivan Lozano52767be2019-10-18 14:49:46 -0700743func (c *Module) Toc() android.OptionalPath {
744 if c.linker != nil {
745 if library, ok := c.linker.(libraryInterface); ok {
746 return library.toc()
747 }
748 }
749 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
750}
751
752func (c *Module) ApiLevel() string {
753 if c.linker != nil {
754 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700755 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700756 }
757 }
758 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
759}
760
761func (c *Module) Static() bool {
762 if c.linker != nil {
763 if library, ok := c.linker.(libraryInterface); ok {
764 return library.static()
765 }
766 }
767 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
768}
769
770func (c *Module) Shared() bool {
771 if c.linker != nil {
772 if library, ok := c.linker.(libraryInterface); ok {
773 return library.shared()
774 }
775 }
776 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
777}
778
779func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000780 if c.stl != nil {
781 return c.stl.Properties.SelectedStl
782 }
783 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700784}
785
786func (c *Module) ToolchainLibrary() bool {
787 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
788 return true
789 }
790 return false
791}
792
793func (c *Module) NdkPrebuiltStl() bool {
794 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
795 return true
796 }
797 return false
798}
799
800func (c *Module) StubDecorator() bool {
801 if _, ok := c.linker.(*stubDecorator); ok {
802 return true
803 }
804 return false
805}
806
807func (c *Module) SdkVersion() string {
808 return String(c.Properties.Sdk_version)
809}
810
Artur Satayev480e25b2020-04-27 18:53:18 +0100811func (c *Module) MinSdkVersion() string {
812 return String(c.Properties.Min_sdk_version)
813}
814
Dan Albert92fe7402020-07-15 13:33:30 -0700815func (c *Module) SplitPerApiLevel() bool {
Colin Cross1348ce32020-10-01 13:37:16 -0700816 if !c.canUseSdk() {
817 return false
818 }
Dan Albert92fe7402020-07-15 13:33:30 -0700819 if linker, ok := c.linker.(*objectLinker); ok {
820 return linker.isCrt()
821 }
822 return false
823}
824
Colin Crossc511bc52020-04-07 16:50:32 +0000825func (c *Module) AlwaysSdk() bool {
826 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
827}
828
Ivan Lozano183a3212019-10-18 14:18:45 -0700829func (c *Module) CcLibrary() bool {
830 if c.linker != nil {
831 if _, ok := c.linker.(*libraryDecorator); ok {
832 return true
833 }
Colin Crossd48fe732020-09-23 20:37:24 -0700834 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
835 return true
836 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700837 }
838 return false
839}
840
841func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700842 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700843 return true
844 }
845 return false
846}
847
Ivan Lozano2b262972019-11-21 12:30:50 -0800848func (c *Module) NonCcVariants() bool {
849 return false
850}
851
Ivan Lozano183a3212019-10-18 14:18:45 -0700852func (c *Module) SetStatic() {
853 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700854 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700855 library.setStatic()
856 return
857 }
858 }
859 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
860}
861
862func (c *Module) SetShared() {
863 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700864 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700865 library.setShared()
866 return
867 }
868 }
869 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
870}
871
872func (c *Module) BuildStaticVariant() bool {
873 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700874 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700875 return library.buildStatic()
876 }
877 }
878 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
879}
880
881func (c *Module) BuildSharedVariant() bool {
882 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700883 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700884 return library.buildShared()
885 }
886 }
887 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
888}
889
890func (c *Module) Module() android.Module {
891 return c
892}
893
Jiyong Parkc20eee32018-09-05 22:36:17 +0900894func (c *Module) OutputFile() android.OptionalPath {
895 return c.outputFile
896}
897
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400898func (c *Module) CoverageFiles() android.Paths {
899 if c.linker != nil {
900 if library, ok := c.linker.(libraryInterface); ok {
901 return library.objs().coverageFiles
902 }
903 }
904 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
905}
906
Ivan Lozano183a3212019-10-18 14:18:45 -0700907var _ LinkableInterface = (*Module)(nil)
908
Jiyong Park719b4462019-01-13 00:39:51 +0900909func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900910 if c.linker != nil {
911 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900912 }
913 return nil
914}
915
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900916func (c *Module) CoverageOutputFile() android.OptionalPath {
917 if c.linker != nil {
918 return c.linker.coverageOutputFilePath()
919 }
920 return android.OptionalPath{}
921}
922
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900923func (c *Module) RelativeInstallPath() string {
924 if c.installer != nil {
925 return c.installer.relativeInstallPath()
926 }
927 return ""
928}
929
Jooyung Han344d5432019-08-23 11:17:39 +0900930func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900931 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900932}
933
Colin Cross36242852017-06-23 15:06:31 -0700934func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700935 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800936 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700937 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800938 }
939 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700940 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800941 }
942 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700943 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800944 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700945 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700946 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700947 }
Colin Cross16b23492016-01-06 14:41:07 -0800948 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700949 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800950 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800951 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700952 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800953 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800954 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700955 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800956 }
Justin Yun8effde42017-06-23 19:24:43 +0900957 if c.vndkdep != nil {
958 c.AddProperties(c.vndkdep.props()...)
959 }
Stephen Craneba090d12017-05-09 15:44:35 -0700960 if c.lto != nil {
961 c.AddProperties(c.lto.props()...)
962 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700963 if c.pgo != nil {
964 c.AddProperties(c.pgo.props()...)
965 }
Colin Crossca860ac2016-01-04 14:34:37 -0800966 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700967 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800968 }
Colin Crossc472d572015-03-17 15:06:21 -0700969
Jiyong Park1613e552020-09-14 19:43:17 +0900970 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700971 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +0900972 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -0700973 })
Colin Cross36242852017-06-23 15:06:31 -0700974 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900975 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900976 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900977 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900978
Colin Cross36242852017-06-23 15:06:31 -0700979 return c
Colin Crossc472d572015-03-17 15:06:21 -0700980}
981
Colin Crossb916a382016-07-29 17:28:03 -0700982// Returns true for dependency roots (binaries)
983// TODO(ccross): also handle dlopenable libraries
984func (c *Module) isDependencyRoot() bool {
985 if root, ok := c.linker.(interface {
986 isDependencyRoot() bool
987 }); ok {
988 return root.isDependencyRoot()
989 }
990 return false
991}
992
Justin Yun5f7f7e82019-11-18 19:52:14 +0900993// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
994// "product" and "vendor" variant modules return true for this function.
995// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
996// "soc_specific: true" and more vendor installed modules are included here.
Justin Yun63e9ec72020-10-29 16:49:43 +0900997// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "product_available: true" or
Justin Yun5f7f7e82019-11-18 19:52:14 +0900998// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700999func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001000 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001001}
1002
Colin Crossc511bc52020-04-07 16:50:32 +00001003func (c *Module) canUseSdk() bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001004 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
Colin Crossc511bc52020-04-07 16:50:32 +00001005}
1006
1007func (c *Module) UseSdk() bool {
1008 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001009 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001010 }
1011 return false
1012}
1013
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001014func (c *Module) isCoverageVariant() bool {
1015 return c.coverage.Properties.IsCoverageVariant
1016}
1017
Colin Cross95f1ca02020-10-29 20:47:22 -07001018func (c *Module) IsNdk(config android.Config) bool {
1019 return inList(c.BaseModuleName(), *getNDKKnownLibs(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001020}
1021
Inseob Kim9516ee92019-05-09 10:56:13 +09001022func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001023 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001024 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001025}
1026
Inseob Kim9516ee92019-05-09 10:56:13 +09001027func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001028 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +09001029 name := c.BaseModuleName()
1030 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001031}
1032
Inseob Kim9516ee92019-05-09 10:56:13 +09001033func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001034 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001035 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001036}
1037
Ivan Lozano52767be2019-10-18 14:49:46 -07001038func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001039 if vndkdep := c.vndkdep; vndkdep != nil {
1040 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001041 }
1042 return false
1043}
1044
Yi Kong7e53c572018-02-14 18:16:12 +08001045func (c *Module) isPgoCompile() bool {
1046 if pgo := c.pgo; pgo != nil {
1047 return pgo.Properties.PgoCompile
1048 }
1049 return false
1050}
1051
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001052func (c *Module) isNDKStubLibrary() bool {
1053 if _, ok := c.compiler.(*stubDecorator); ok {
1054 return true
1055 }
1056 return false
1057}
1058
Logan Chienf3511742017-10-31 18:04:35 +08001059func (c *Module) isVndkSp() bool {
1060 if vndkdep := c.vndkdep; vndkdep != nil {
1061 return vndkdep.isVndkSp()
1062 }
1063 return false
1064}
1065
1066func (c *Module) isVndkExt() bool {
1067 if vndkdep := c.vndkdep; vndkdep != nil {
1068 return vndkdep.isVndkExt()
1069 }
1070 return false
1071}
1072
Ivan Lozano52767be2019-10-18 14:49:46 -07001073func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001074 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001075}
1076
Logan Chienf3511742017-10-31 18:04:35 +08001077func (c *Module) getVndkExtendsModuleName() string {
1078 if vndkdep := c.vndkdep; vndkdep != nil {
1079 return vndkdep.getVndkExtendsModuleName()
1080 }
1081 return ""
1082}
1083
Jiyong Park25fc6a92018-11-18 18:02:45 +09001084func (c *Module) IsStubs() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001085 if lib := c.library; lib != nil {
1086 return lib.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001087 }
1088 return false
1089}
1090
1091func (c *Module) HasStubsVariants() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001092 if lib := c.library; lib != nil {
1093 return lib.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001094 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001095 return false
1096}
1097
Colin Cross0477b422020-10-13 18:43:54 -07001098// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
1099// the implementation. If it is an implementation library it returns its own name.
1100func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
1101 name := ctx.OtherModuleName(c)
1102 if versioned, ok := c.linker.(versionedInterface); ok {
1103 name = versioned.implementationModuleName(name)
1104 }
1105 return name
1106}
1107
Martin Stjernholm2856c662020-12-02 15:03:42 +00001108// Similar to ImplementationModuleName, but uses the Make variant of the module
1109// name as base name, for use in AndroidMk output. E.g. for a prebuilt module
1110// where the Soong name is prebuilt_foo, this returns foo (which works in Make
1111// under the premise that the prebuilt module overrides its source counterpart
1112// if it is exposed to Make).
1113func (c *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string {
1114 name := c.BaseModuleName()
1115 if versioned, ok := c.linker.(versionedInterface); ok {
1116 name = versioned.implementationModuleName(name)
1117 }
1118 return name
1119}
1120
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001121func (c *Module) bootstrap() bool {
1122 return Bool(c.Properties.Bootstrap)
1123}
1124
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001125func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001126 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1127 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1128 return false
1129 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001130 return c.linker != nil && c.linker.nativeCoverage()
1131}
1132
Inseob Kim8471cda2019-11-15 09:59:12 +09001133func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001134 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1135 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001136 }
1137 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001138}
1139
Bill Peckham945441c2020-08-31 16:07:58 -07001140func (c *Module) ExcludeFromVendorSnapshot() bool {
1141 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1142}
1143
Jose Galmesf7294582020-11-13 12:07:36 -08001144func (c *Module) ExcludeFromRecoverySnapshot() bool {
1145 return Bool(c.Properties.Exclude_from_recovery_snapshot)
1146}
1147
Jiyong Parkf1194352019-02-25 11:05:47 +09001148func isBionic(name string) bool {
1149 switch name {
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09001150 case "libc", "libm", "libdl", "libdl_android", "linker", "linkerconfig":
Jiyong Parkf1194352019-02-25 11:05:47 +09001151 return true
1152 }
1153 return false
1154}
1155
Martin Stjernholm279de572019-09-10 23:18:20 +01001156func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001157 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001158 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001159 }
1160 return isBionic(name)
1161}
1162
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001163func (c *Module) XrefCcFiles() android.Paths {
1164 return c.kytheFiles
1165}
1166
Colin Crossca860ac2016-01-04 14:34:37 -08001167type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001168 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001169 moduleContextImpl
1170}
1171
Colin Cross37047f12016-12-13 17:06:13 -08001172type depsContext struct {
1173 android.BottomUpMutatorContext
1174 moduleContextImpl
1175}
1176
Colin Crossca860ac2016-01-04 14:34:37 -08001177type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001178 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001179 moduleContextImpl
1180}
1181
1182type moduleContextImpl struct {
1183 mod *Module
1184 ctx BaseModuleContext
1185}
1186
Colin Crossb98c8b02016-07-29 13:44:28 -07001187func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001188 return ctx.mod.toolchain(ctx.ctx)
1189}
1190
1191func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001192 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001193}
1194
1195func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001196 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001197}
1198
Jiyong Park1d1119f2019-07-29 21:27:18 +09001199func (ctx *moduleContextImpl) header() bool {
1200 return ctx.mod.header()
1201}
1202
Inseob Kim7f283f42020-06-01 21:53:49 +09001203func (ctx *moduleContextImpl) binary() bool {
1204 return ctx.mod.binary()
1205}
1206
Inseob Kim1042d292020-06-01 23:23:05 +09001207func (ctx *moduleContextImpl) object() bool {
1208 return ctx.mod.object()
1209}
1210
Jooyung Hanccce2f22020-03-07 03:45:53 +09001211func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001212 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001213}
1214
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001215func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001216 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001217}
1218
1219func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001220 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001221 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001222 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001223 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001224 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001225 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001226 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001227 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001228 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001229 }
1230 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001231}
1232
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001233func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001234 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001235}
Justin Yun8effde42017-06-23 19:24:43 +09001236
Colin Cross95f1ca02020-10-29 20:47:22 -07001237func (ctx *moduleContextImpl) isNdk(config android.Config) bool {
1238 return ctx.mod.IsNdk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001239}
1240
Inseob Kim9516ee92019-05-09 10:56:13 +09001241func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1242 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001243}
1244
Inseob Kim9516ee92019-05-09 10:56:13 +09001245func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1246 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001247}
1248
Inseob Kim9516ee92019-05-09 10:56:13 +09001249func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1250 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001251}
1252
Logan Chienf3511742017-10-31 18:04:35 +08001253func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001254 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001255}
1256
Yi Kong7e53c572018-02-14 18:16:12 +08001257func (ctx *moduleContextImpl) isPgoCompile() bool {
1258 return ctx.mod.isPgoCompile()
1259}
1260
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001261func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1262 return ctx.mod.isNDKStubLibrary()
1263}
1264
Justin Yun8effde42017-06-23 19:24:43 +09001265func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001266 return ctx.mod.isVndkSp()
1267}
1268
1269func (ctx *moduleContextImpl) isVndkExt() bool {
1270 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001271}
1272
Vic Yangefd249e2018-11-12 20:19:56 -08001273func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001274 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001275}
1276
Logan Chien2f2b8902018-07-10 15:01:19 +08001277// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001278func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001279 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1280 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001281 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001282
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001283 // Coverage builds have extra symbols.
1284 if ctx.mod.isCoverageVariant() {
1285 return false
1286 }
1287
Doug Hornc32c6b02019-01-17 14:44:05 -08001288 if ctx.ctx.Fuchsia() {
1289 return false
1290 }
1291
Logan Chien2f2b8902018-07-10 15:01:19 +08001292 if sanitize := ctx.mod.sanitize; sanitize != nil {
1293 if !sanitize.isVariantOnProductionDevice() {
1294 return false
1295 }
1296 }
1297 if !ctx.ctx.Device() {
1298 // Host modules do not need ABI dumps.
1299 return false
1300 }
Colin Cross31076b32020-10-23 17:22:06 -07001301 if ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001302 // Stubs do not need ABI dumps.
1303 return false
1304 }
Colin Cross31076b32020-10-23 17:22:06 -07001305 if lib := ctx.mod.library; lib != nil && lib.buildStubs() {
1306 // Stubs do not need ABI dumps.
1307 return false
1308 }
1309
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001310 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001311}
1312
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001313func (ctx *moduleContextImpl) selectedStl() string {
1314 if stl := ctx.mod.stl; stl != nil {
1315 return stl.Properties.SelectedStl
1316 }
1317 return ""
1318}
1319
Ivan Lozanobd721262018-11-27 14:33:03 -08001320func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1321 return ctx.mod.linker.useClangLld(actx)
1322}
1323
Colin Crossce75d2c2016-10-06 16:12:58 -07001324func (ctx *moduleContextImpl) baseModuleName() string {
1325 return ctx.mod.ModuleBase.BaseModuleName()
1326}
1327
Logan Chienf3511742017-10-31 18:04:35 +08001328func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1329 return ctx.mod.getVndkExtendsModuleName()
1330}
1331
Logan Chiene274fc92019-12-03 11:18:32 -08001332func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Cross56a83212020-09-15 18:30:11 -07001333 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001334}
1335
Colin Crosse07f2312020-08-13 11:24:56 -07001336func (ctx *moduleContextImpl) apexVariationName() string {
Colin Cross56a83212020-09-15 18:30:11 -07001337 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001338}
1339
Dan Albertc8060532020-07-22 22:32:17 -07001340func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001341 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001342}
1343
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001344func (ctx *moduleContextImpl) bootstrap() bool {
1345 return ctx.mod.bootstrap()
1346}
1347
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001348func (ctx *moduleContextImpl) nativeCoverage() bool {
1349 return ctx.mod.nativeCoverage()
1350}
1351
Colin Cross56a83212020-09-15 18:30:11 -07001352func (ctx *moduleContextImpl) directlyInAnyApex() bool {
1353 return ctx.mod.DirectlyInAnyApex()
1354}
1355
Colin Cross635c3b02016-05-18 15:37:25 -07001356func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001357 return &Module{
1358 hod: hod,
1359 multilib: multilib,
1360 }
1361}
1362
Colin Cross635c3b02016-05-18 15:37:25 -07001363func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001364 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001365 module.features = []feature{
1366 &tidyFeature{},
1367 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001368 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001369 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001370 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001371 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001372 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001373 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001374 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001375 return module
1376}
1377
Colin Crossce75d2c2016-10-06 16:12:58 -07001378func (c *Module) Prebuilt() *android.Prebuilt {
1379 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1380 return p.prebuilt()
1381 }
1382 return nil
1383}
1384
1385func (c *Module) Name() string {
1386 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001387 if p, ok := c.linker.(interface {
1388 Name(string) string
1389 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001390 name = p.Name(name)
1391 }
1392 return name
1393}
1394
Alex Light3d673592019-01-18 14:37:31 -08001395func (c *Module) Symlinks() []string {
1396 if p, ok := c.installer.(interface {
1397 symlinkList() []string
1398 }); ok {
1399 return p.symlinkList()
1400 }
1401 return nil
1402}
1403
Roland Levillainf89cd092019-07-29 16:22:59 +01001404func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1405 test, ok := c.linker.(testPerSrc)
1406 return ok && test.isAllTestsVariation()
1407}
1408
Chris Parsons216e10a2020-07-09 17:12:52 -04001409func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001410 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001411 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001412 }); ok {
1413 return p.dataPaths()
1414 }
1415 return nil
1416}
1417
Justin Yun5f7f7e82019-11-18 19:52:14 +09001418func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1419 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1420 // "current", it will append the VNDK version to the name suffix.
1421 var vndkVersion string
1422 var nameSuffix string
1423 if c.inProduct() {
1424 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1425 nameSuffix = productSuffix
1426 } else {
1427 vndkVersion = ctx.DeviceConfig().VndkVersion()
1428 nameSuffix = vendorSuffix
1429 }
1430 if vndkVersion == "current" {
1431 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1432 }
1433 if c.Properties.VndkVersion != vndkVersion {
1434 // add version suffix only if the module is using different vndk version than the
1435 // version in product or vendor partition.
1436 nameSuffix += "." + c.Properties.VndkVersion
1437 }
1438 return nameSuffix
1439}
1440
Colin Cross635c3b02016-05-18 15:37:25 -07001441func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001442 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001443 //
1444 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1445 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1446 // module and return early, as this module does not produce an output file per se.
1447 if c.IsTestPerSrcAllTestsVariation() {
1448 c.outputFile = android.OptionalPath{}
1449 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001450 }
1451
Colin Cross56a83212020-09-15 18:30:11 -07001452 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1453 if !apexInfo.IsForPlatform() {
1454 c.hideApexVariantFromMake = true
1455 }
1456
Jooyung Han38002912019-05-16 04:01:54 +09001457 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001458
Inseob Kim64c43952019-08-26 16:52:35 +09001459 c.Properties.SubName = ""
1460
1461 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1462 c.Properties.SubName += nativeBridgeSuffix
1463 }
1464
Justin Yun5f7f7e82019-11-18 19:52:14 +09001465 _, llndk := c.linker.(*llndkStubDecorator)
1466 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
Justin Yun63e9ec72020-10-29 16:49:43 +09001467 if llndk || llndkHeader || (c.UseVndk() && c.HasNonSystemVariants()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001468 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1469 // added for product variant only when we have vendor and product variants with core
1470 // variant. The suffix is not added for vendor-only or product-only module.
1471 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1472 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001473 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1474 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1475 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001476 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1477 c.Properties.SubName += ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001478 } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
1479 c.Properties.SubName += vendorRamdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001480 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001481 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001482 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001483 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001484 if c.SplitPerApiLevel() {
1485 c.Properties.SubName += "." + c.SdkVersion()
1486 }
Inseob Kim64c43952019-08-26 16:52:35 +09001487 }
1488
Colin Crossca860ac2016-01-04 14:34:37 -08001489 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001490 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001491 moduleContextImpl: moduleContextImpl{
1492 mod: c,
1493 },
1494 }
1495 ctx.ctx = ctx
1496
Colin Crossf18e1102017-11-16 14:33:08 -08001497 deps := c.depsToPaths(ctx)
1498 if ctx.Failed() {
1499 return
1500 }
1501
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001502 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1503 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1504 }
1505
Colin Crossca860ac2016-01-04 14:34:37 -08001506 flags := Flags{
1507 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001508 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001509 }
Colin Crossca860ac2016-01-04 14:34:37 -08001510 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001511 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001512 }
1513 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001514 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001515 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001516 if c.stl != nil {
1517 flags = c.stl.flags(ctx, flags)
1518 }
Colin Cross16b23492016-01-06 14:41:07 -08001519 if c.sanitize != nil {
1520 flags = c.sanitize.flags(ctx, flags)
1521 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001522 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001523 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001524 }
Stephen Craneba090d12017-05-09 15:44:35 -07001525 if c.lto != nil {
1526 flags = c.lto.flags(ctx, flags)
1527 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001528 if c.pgo != nil {
1529 flags = c.pgo.flags(ctx, flags)
1530 }
Colin Crossca860ac2016-01-04 14:34:37 -08001531 for _, feature := range c.features {
1532 flags = feature.flags(ctx, flags)
1533 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001534 if ctx.Failed() {
1535 return
1536 }
1537
Colin Cross4af21ed2019-11-04 09:37:55 -08001538 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1539 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1540 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001541
Colin Cross4af21ed2019-11-04 09:37:55 -08001542 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001543
1544 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001545 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001546 }
1547 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001548 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001549 }
1550
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001551 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001552 // We need access to all the flags seen by a source file.
1553 if c.sabi != nil {
1554 flags = c.sabi.flags(ctx, flags)
1555 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001556
Colin Cross4af21ed2019-11-04 09:37:55 -08001557 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001558
Colin Crossca860ac2016-01-04 14:34:37 -08001559 // Optimization to reduce size of build.ninja
1560 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001561 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1562 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1563 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1564 flags.Local.CFlags = []string{"$cflags"}
1565 flags.Local.CppFlags = []string{"$cppflags"}
1566 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001567
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001568 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001569 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001570 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001571 if ctx.Failed() {
1572 return
1573 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001574 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001575 }
1576
Colin Crossca860ac2016-01-04 14:34:37 -08001577 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001578 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001579 if ctx.Failed() {
1580 return
1581 }
Colin Cross635c3b02016-05-18 15:37:25 -07001582 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001583
1584 // If a lib is directly included in any of the APEXes, unhide the stubs
1585 // variant having the latest version gets visible to make. In addition,
1586 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1587 // force anything in the make world to link against the stubs library.
1588 // (unless it is explicitly referenced via .bootstrap suffix or the
1589 // module is marked with 'bootstrap: true').
Colin Cross56a83212020-09-15 18:30:11 -07001590 if c.HasStubsVariants() && c.AnyVariantDirectlyInAnyApex() && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001591 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001592 c.IsStubs() && !c.InVendorRamdisk() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001593 c.Properties.HideFromMake = false // unhide
1594 // Note: this is still non-installable
1595 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001596
1597 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1598 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
Colin Cross56a83212020-09-15 18:30:11 -07001599 if isSnapshotAware(ctx, c, apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001600 i.collectHeadersForSnapshot(ctx)
1601 }
1602 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001603 }
Colin Cross5049f022015-03-18 13:28:46 -07001604
Colin Cross56a83212020-09-15 18:30:11 -07001605 if c.installable(apexInfo) {
Colin Crossce75d2c2016-10-06 16:12:58 -07001606 c.installer.install(ctx, c.outputFile.Path())
1607 if ctx.Failed() {
1608 return
Colin Crossca860ac2016-01-04 14:34:37 -08001609 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001610 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1611 // If the module has been specifically configure to not be installed then
1612 // skip the installation as otherwise it will break when running inside make
1613 // as the output path to install will not be specified. Not all uninstallable
1614 // modules can skip installation as some are needed for resolving make side
1615 // dependencies.
1616 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001617 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001618}
1619
Colin Cross0ea8ba82019-06-06 14:33:29 -07001620func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001621 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001622 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001623 }
Colin Crossca860ac2016-01-04 14:34:37 -08001624 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001625}
1626
Colin Crossca860ac2016-01-04 14:34:37 -08001627func (c *Module) begin(ctx BaseModuleContext) {
1628 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001629 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001630 }
Colin Crossca860ac2016-01-04 14:34:37 -08001631 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001632 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001633 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001634 if c.stl != nil {
1635 c.stl.begin(ctx)
1636 }
Colin Cross16b23492016-01-06 14:41:07 -08001637 if c.sanitize != nil {
1638 c.sanitize.begin(ctx)
1639 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001640 if c.coverage != nil {
1641 c.coverage.begin(ctx)
1642 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001643 if c.sabi != nil {
1644 c.sabi.begin(ctx)
1645 }
Justin Yun8effde42017-06-23 19:24:43 +09001646 if c.vndkdep != nil {
1647 c.vndkdep.begin(ctx)
1648 }
Stephen Craneba090d12017-05-09 15:44:35 -07001649 if c.lto != nil {
1650 c.lto.begin(ctx)
1651 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001652 if c.pgo != nil {
1653 c.pgo.begin(ctx)
1654 }
Colin Crossca860ac2016-01-04 14:34:37 -08001655 for _, feature := range c.features {
1656 feature.begin(ctx)
1657 }
Dan Albert92fe7402020-07-15 13:33:30 -07001658 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001659 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001660 if err != nil {
1661 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001662 c.Properties.Sdk_version = nil
1663 } else {
1664 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001665 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001666 }
Colin Crossca860ac2016-01-04 14:34:37 -08001667}
1668
Colin Cross37047f12016-12-13 17:06:13 -08001669func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001670 deps := Deps{}
1671
1672 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001673 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001674 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001675 // Add the PGO dependency (the clang_rt.profile runtime library), which
1676 // sometimes depends on symbols from libgcc, before libgcc gets added
1677 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001678 if c.pgo != nil {
1679 deps = c.pgo.deps(ctx, deps)
1680 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001681 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001682 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001683 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001684 if c.stl != nil {
1685 deps = c.stl.deps(ctx, deps)
1686 }
Colin Cross16b23492016-01-06 14:41:07 -08001687 if c.sanitize != nil {
1688 deps = c.sanitize.deps(ctx, deps)
1689 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001690 if c.coverage != nil {
1691 deps = c.coverage.deps(ctx, deps)
1692 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001693 if c.sabi != nil {
1694 deps = c.sabi.deps(ctx, deps)
1695 }
Justin Yun8effde42017-06-23 19:24:43 +09001696 if c.vndkdep != nil {
1697 deps = c.vndkdep.deps(ctx, deps)
1698 }
Stephen Craneba090d12017-05-09 15:44:35 -07001699 if c.lto != nil {
1700 deps = c.lto.deps(ctx, deps)
1701 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001702 for _, feature := range c.features {
1703 deps = feature.deps(ctx, deps)
1704 }
1705
Colin Crossb6715442017-10-24 11:13:31 -07001706 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1707 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1708 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1709 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1710 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1711 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001712 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001713
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001714 for _, lib := range deps.ReexportSharedLibHeaders {
1715 if !inList(lib, deps.SharedLibs) {
1716 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1717 }
1718 }
1719
1720 for _, lib := range deps.ReexportStaticLibHeaders {
1721 if !inList(lib, deps.StaticLibs) {
1722 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1723 }
1724 }
1725
Colin Cross5950f382016-12-13 12:50:57 -08001726 for _, lib := range deps.ReexportHeaderLibHeaders {
1727 if !inList(lib, deps.HeaderLibs) {
1728 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1729 }
1730 }
1731
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001732 for _, gen := range deps.ReexportGeneratedHeaders {
1733 if !inList(gen, deps.GeneratedHeaders) {
1734 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1735 }
1736 }
1737
Colin Crossc99deeb2016-04-11 15:06:20 -07001738 return deps
1739}
1740
Dan Albert7e9d2952016-08-04 13:02:36 -07001741func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001742 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001743 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001744 moduleContextImpl: moduleContextImpl{
1745 mod: c,
1746 },
1747 }
1748 ctx.ctx = ctx
1749
Colin Crossca860ac2016-01-04 14:34:37 -08001750 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001751}
1752
Jiyong Park7ed9de32018-10-15 22:25:07 +09001753// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001754func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001755 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1756 version := name[sharp+1:]
1757 libname := name[:sharp]
1758 return libname, version
1759 }
1760 return name, ""
1761}
1762
Dan Albert92fe7402020-07-15 13:33:30 -07001763func GetCrtVariations(ctx android.BottomUpMutatorContext,
1764 m LinkableInterface) []blueprint.Variation {
1765 if ctx.Os() != android.Android {
1766 return nil
1767 }
1768 if m.UseSdk() {
1769 return []blueprint.Variation{
1770 {Mutator: "sdk", Variation: "sdk"},
Colin Crossbbc941b2020-09-30 12:27:01 -07001771 {Mutator: "version", Variation: m.SdkVersion()},
Dan Albert92fe7402020-07-15 13:33:30 -07001772 }
1773 }
1774 return []blueprint.Variation{
1775 {Mutator: "sdk", Variation: ""},
1776 }
1777}
1778
Colin Crosse7257d22020-09-24 09:56:18 -07001779func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1780 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1781
1782 variations = append([]blueprint.Variation(nil), variations...)
1783
Colin Cross3146c5c2020-09-30 15:34:40 -07001784 if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001785 // Version is explicitly specified. i.e. libFoo#30
1786 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1787 depTag.explicitlyVersioned = true
1788 }
Colin Crosse7257d22020-09-24 09:56:18 -07001789
Colin Cross0de8a1e2020-09-18 14:15:30 -07001790 if far {
1791 ctx.AddFarVariationDependencies(variations, depTag, name)
1792 } else {
1793 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07001794 }
1795}
1796
Colin Cross1e676be2016-10-12 14:38:15 -07001797func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001798 if !c.Enabled() {
1799 return
1800 }
1801
Colin Cross37047f12016-12-13 17:06:13 -08001802 ctx := &depsContext{
1803 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001804 moduleContextImpl: moduleContextImpl{
1805 mod: c,
1806 },
1807 }
1808 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001809
Colin Crossc99deeb2016-04-11 15:06:20 -07001810 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001811
Yo Chiang219968c2020-09-22 18:45:04 +08001812 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1813
Dan Albert914449f2016-06-17 16:45:24 -07001814 variantNdkLibs := []string{}
1815 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001816 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001817 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001818 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001819 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001820 // 1. Name of an NDK library that refers to a prebuilt module.
1821 // For each of these, it adds the name of the prebuilt module (which will be in
1822 // prebuilts/ndk) to the list of nonvariant libs.
1823 // 2. Name of an NDK library that refers to an ndk_library module.
1824 // For each of these, it adds the name of the ndk_library module to the list of
1825 // variant libs.
1826 // 3. Anything else (so anything that isn't an NDK library).
1827 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001828 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001829 // The caller can then know to add the variantLibs dependencies differently from the
1830 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001831
Inseob Kim9516ee92019-05-09 10:56:13 +09001832 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001833 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1834
1835 rewriteVendorLibs := func(lib string) string {
1836 if isLlndkLibrary(lib, ctx.Config()) {
1837 return lib + llndkLibrarySuffix
1838 }
1839
1840 // only modules with BOARD_VNDK_VERSION uses snapshot.
1841 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1842 return lib
1843 }
1844
1845 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1846 return snapshot
1847 }
1848
1849 return lib
1850 }
1851
1852 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001853 variantLibs = []string{}
1854 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001855 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001856 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001857 name, _ := StubsLibNameAndVersion(entry)
Colin Cross95f1ca02020-10-29 20:47:22 -07001858 if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) {
Dan Albertde5aade2020-06-30 12:32:51 -07001859 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001860 } else if ctx.useVndk() {
1861 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001862 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001863 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001864 if actx.OtherModuleExists(vendorPublicLib) {
1865 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1866 } else {
1867 // This can happen if vendor_public_library module is defined in a
1868 // namespace that isn't visible to the current module. In that case,
1869 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001870 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001871 }
Dan Albert914449f2016-06-17 16:45:24 -07001872 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001873 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001874 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001875 }
1876 }
Dan Albert914449f2016-06-17 16:45:24 -07001877 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001878 }
1879
Inseob Kimeec88e12020-01-22 11:11:29 +09001880 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1881 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1882 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1883 if ctx.useVndk() {
1884 for idx, lib := range deps.RuntimeLibs {
1885 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1886 }
1887 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001888 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001889
Jiyong Park7e636d02019-01-28 16:16:54 +09001890 buildStubs := false
Colin Crossc88c2722020-09-28 17:32:47 -07001891 if versioned, ok := c.linker.(versionedInterface); ok {
1892 if versioned.buildStubs() {
1893 buildStubs = true
Colin Crossd48fe732020-09-23 20:37:24 -07001894 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001895 }
1896
Inseob Kimeec88e12020-01-22 11:11:29 +09001897 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1898 // only modules with BOARD_VNDK_VERSION uses snapshot.
1899 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1900 return lib
1901 }
1902
1903 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1904 return snapshot
1905 }
1906
1907 return lib
1908 }
1909
1910 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001911 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001912 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001913 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001914 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001915 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001916
1917 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1918
Jiyong Park7e636d02019-01-28 16:16:54 +09001919 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001920 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001921 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001922 } else {
1923 actx.AddVariationDependencies(nil, depTag, lib)
1924 }
1925 }
1926
1927 if buildStubs {
1928 // Stubs lib does not have dependency to other static/shared libraries.
1929 // Don't proceed.
1930 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001931 }
Colin Cross5950f382016-12-13 12:50:57 -08001932
Inseob Kim07def122020-11-23 14:43:02 +09001933 // sysprop_library has to support both C++ and Java. So sysprop_library internally creates one
1934 // C++ implementation library and one Java implementation library. When a module links against
1935 // sysprop_library, the C++ implementation library has to be linked. syspropImplLibraries is a
1936 // map from sysprop_library to implementation library; it will be used in whole_static_libs,
1937 // static_libs, and shared_libs.
Inseob Kimc0907f12019-02-08 21:00:45 +09001938 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001939 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001940
Jiyong Park5d1598f2019-02-25 22:14:17 +09001941 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001942 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001943 if impl, ok := syspropImplLibraries[lib]; ok {
1944 lib = impl
1945 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001946
1947 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1948
Jiyong Park5d1598f2019-02-25 22:14:17 +09001949 actx.AddVariationDependencies([]blueprint.Variation{
1950 {Mutator: "link", Variation: "static"},
1951 }, depTag, lib)
1952 }
1953
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001954 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001955 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001956 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001957 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001958 }
Jiyong Parke3867542020-12-03 17:28:25 +09001959 if inList(lib, deps.ExcludeLibsForApex) {
1960 depTag.excludeInApex = true
1961 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001962
1963 if impl, ok := syspropImplLibraries[lib]; ok {
1964 lib = impl
1965 }
1966
Inseob Kimeec88e12020-01-22 11:11:29 +09001967 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1968
Dan Willemsen59339a22018-07-22 21:18:45 -07001969 actx.AddVariationDependencies([]blueprint.Variation{
1970 {Mutator: "link", Variation: "static"},
1971 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001972 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001973
Jooyung Han75568392020-03-20 04:29:24 +09001974 // staticUnwinderDep is treated as staticDep for Q apexes
1975 // so that native libraries/binaries are linked with static unwinder
1976 // because Q libc doesn't have unwinder APIs
1977 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001978 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001979 actx.AddVariationDependencies([]blueprint.Variation{
1980 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001981 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001982 }
1983
Inseob Kimeec88e12020-01-22 11:11:29 +09001984 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001985 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001986 actx.AddVariationDependencies([]blueprint.Variation{
1987 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001988 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001989 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001990
Jiyong Park7ed9de32018-10-15 22:25:07 +09001991 // shared lib names without the #version suffix
1992 var sharedLibNames []string
1993
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001994 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001995 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001996 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001997 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001998 }
Jiyong Parke3867542020-12-03 17:28:25 +09001999 if inList(lib, deps.ExcludeLibsForApex) {
2000 depTag.excludeInApex = true
2001 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002002
2003 if impl, ok := syspropImplLibraries[lib]; ok {
2004 lib = impl
2005 }
2006
Jiyong Park73c54ee2019-10-22 20:31:18 +09002007 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002008 sharedLibNames = append(sharedLibNames, name)
2009
Colin Crosse7257d22020-09-24 09:56:18 -07002010 variations := []blueprint.Variation{
2011 {Mutator: "link", Variation: "shared"},
2012 }
2013 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002014 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002015
Jiyong Park7ed9de32018-10-15 22:25:07 +09002016 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002017 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002018 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2019 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2020 // linking against both the stubs lib and the non-stubs lib at the same time.
2021 continue
2022 }
Colin Cross6e511a92020-07-27 21:26:48 -07002023 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002024 variations := []blueprint.Variation{
2025 {Mutator: "link", Variation: "shared"},
2026 }
2027 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002028 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002029
Dan Willemsen59339a22018-07-22 21:18:45 -07002030 actx.AddVariationDependencies([]blueprint.Variation{
2031 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002032 }, dataLibDepTag, deps.DataLibs...)
2033
2034 actx.AddVariationDependencies([]blueprint.Variation{
2035 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002036 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002037
Colin Cross68861832016-07-08 10:41:41 -07002038 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002039
2040 for _, gen := range deps.GeneratedHeaders {
2041 depTag := genHeaderDepTag
2042 if inList(gen, deps.ReexportGeneratedHeaders) {
2043 depTag = genHeaderExportDepTag
2044 }
2045 actx.AddDependency(c, depTag, gen)
2046 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002047
Inseob Kim1042d292020-06-01 23:23:05 +09002048 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2049
Dan Albert92fe7402020-07-15 13:33:30 -07002050 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07002051 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002052 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002053 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2054 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002055 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002056 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002057 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2058 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002059 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002060 if deps.LinkerFlagsFile != "" {
2061 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2062 }
2063 if deps.DynamicLinker != "" {
2064 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002065 }
Dan Albert914449f2016-06-17 16:45:24 -07002066
2067 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002068
2069 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002070 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002071 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002072 {Mutator: "link", Variation: "shared"},
2073 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002074
2075 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002076 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002077 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002078 {Mutator: "link", Variation: "shared"},
2079 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002080
2081 if vndkdep := c.vndkdep; vndkdep != nil {
2082 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002083 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002084 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002085 {Mutator: "link", Variation: "shared"},
2086 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002087 }
2088 }
Colin Cross6362e272015-10-29 15:25:03 -07002089}
Colin Cross21b9a242015-03-24 14:15:58 -07002090
Colin Crosse40b4ea2018-10-02 22:25:58 -07002091func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002092 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2093 c.beginMutator(ctx)
2094 }
2095}
2096
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002097// Whether a module can link to another module, taking into
2098// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002099func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002100 tag blueprint.DependencyTag) {
2101
2102 switch t := tag.(type) {
2103 case dependencyTag:
2104 if t != vndkExtDepTag {
2105 return
2106 }
2107 case libraryDependencyTag:
2108 default:
2109 return
2110 }
2111
Ivan Lozano52767be2019-10-18 14:49:46 -07002112 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002113 // Host code is not restricted
2114 return
2115 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002116
2117 // VNDK is cc.Module supported only for now.
2118 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Justin Yun63e9ec72020-10-29 16:49:43 +09002119 // Though allowed dependency is limited by the image mutator,
2120 // each vendor and product module needs to check link-type
2121 // for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002122 if ccTo, ok := to.(*Module); ok {
2123 if ccFrom.vndkdep != nil {
2124 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2125 }
2126 } else {
2127 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002128 }
2129 return
2130 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002131 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002132 // Platform code can link to anything
2133 return
2134 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002135 if from.InRamdisk() {
2136 // Ramdisk code is not NDK
2137 return
2138 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002139 if from.InVendorRamdisk() {
2140 // Vendor ramdisk code is not NDK
2141 return
2142 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002143 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002144 // Recovery code is not NDK
2145 return
2146 }
Colin Cross31076b32020-10-23 17:22:06 -07002147 if c, ok := to.(*Module); ok {
2148 if c.ToolchainLibrary() {
2149 // These are always allowed
2150 return
2151 }
2152 if c.NdkPrebuiltStl() {
2153 // These are allowed, but they don't set sdk_version
2154 return
2155 }
2156 if c.StubDecorator() {
2157 // These aren't real libraries, but are the stub shared libraries that are included in
2158 // the NDK.
2159 return
2160 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002161 }
Logan Chien834b9a62019-01-14 15:39:03 +08002162
Ivan Lozano52767be2019-10-18 14:49:46 -07002163 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002164 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2165 // to link to libc++ (non-NDK and without sdk_version).
2166 return
2167 }
2168
Ivan Lozano52767be2019-10-18 14:49:46 -07002169 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 // NDK code linking to platform code is never okay.
2171 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002172 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002173 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002174 }
2175
2176 // At this point we know we have two NDK libraries, but we need to
2177 // check that we're not linking against anything built against a higher
2178 // API level, as it is only valid to link against older or equivalent
2179 // APIs.
2180
Inseob Kim01a28722018-04-11 09:48:45 +09002181 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002182 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002183 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002184 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002185 // Current can't be linked against by anything else.
2186 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002187 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002188 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002189 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002190 if err != nil {
2191 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002192 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002193 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002194 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002195 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002196 if err != nil {
2197 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002198 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002199 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002200 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002201
Inseob Kim01a28722018-04-11 09:48:45 +09002202 if toApi > fromApi {
2203 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002204 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002205 }
2206 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002207 }
Dan Albert202fe492017-12-15 13:56:59 -08002208
2209 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002210 fromStl := from.SelectedStl()
2211 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002212 if fromStl == "" || toStl == "" {
2213 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002214 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002215 // We can be permissive with the system "STL" since it is only the C++
2216 // ABI layer, but in the future we should make sure that everyone is
2217 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002218 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002219 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002220 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2221 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002222 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002223}
2224
Jooyung Han479ca172020-10-19 18:51:07 +09002225func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2226 if c, ok := ctx.Module().(*Module); ok {
2227 ctx.VisitDirectDeps(func(dep android.Module) {
2228 depTag := ctx.OtherModuleDependencyTag(dep)
2229 ccDep, ok := dep.(LinkableInterface)
2230 if ok {
2231 checkLinkType(ctx, c, ccDep, depTag)
2232 }
2233 })
2234 }
2235}
2236
Jiyong Park5fb8c102018-04-09 12:03:06 +09002237// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002238// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2239// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002240// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002241func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2242 check := func(child, parent android.Module) bool {
2243 to, ok := child.(*Module)
2244 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002245 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002246 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002247
Jooyung Hana70f0672019-01-18 15:20:43 +09002248 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2249 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002250 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002251
Justin Yun63e9ec72020-10-29 16:49:43 +09002252 // Even if target lib has no vendor variant, keep checking dependency
2253 // graph in case it depends on vendor_available or product_available
2254 // but not double_loadable transtively.
2255 if !to.HasNonSystemVariants() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002256 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002257 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002258
Jooyung Han0302a842019-10-30 18:43:49 +09002259 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002260 return false
2261 }
2262
2263 var stringPath []string
2264 for _, m := range ctx.GetWalkPath() {
2265 stringPath = append(stringPath, m.Name())
2266 }
2267 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2268 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2269 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2270 return false
2271 }
2272 if module, ok := ctx.Module().(*Module); ok {
2273 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002274 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002275 ctx.WalkDeps(check)
2276 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002277 }
2278 }
2279}
2280
Colin Cross0de8a1e2020-09-18 14:15:30 -07002281// Returns the highest version which is <= maxSdkVersion.
2282// For example, with maxSdkVersion is 10 and versionList is [9,11]
2283// it returns 9 as string. The list of stubs must be in order from
2284// oldest to newest.
2285func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedLibraryStubsInfo,
2286 maxSdkVersion android.ApiLevel) (SharedLibraryStubsInfo, error) {
2287
2288 for i := range stubsInfo {
2289 stubInfo := stubsInfo[len(stubsInfo)-i-1]
2290 var ver android.ApiLevel
2291 if stubInfo.Version == "" {
2292 ver = android.FutureApiLevel
2293 } else {
2294 var err error
2295 ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
2296 if err != nil {
2297 return SharedLibraryStubsInfo{}, err
2298 }
2299 }
2300 if ver.LessThanOrEqualTo(maxSdkVersion) {
2301 return stubInfo, nil
2302 }
2303 }
2304 var versionList []string
2305 for _, stubInfo := range stubsInfo {
2306 versionList = append(versionList, stubInfo.Version)
2307 }
2308 return SharedLibraryStubsInfo{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
2309}
2310
Colin Crossc99deeb2016-04-11 15:06:20 -07002311// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002312func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002313 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002314
Colin Cross0de8a1e2020-09-18 14:15:30 -07002315 var directStaticDeps []StaticLibraryInfo
2316 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07002317
Colin Cross0de8a1e2020-09-18 14:15:30 -07002318 reexportExporter := func(exporter FlagExporterInfo) {
2319 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
2320 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
2321 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
2322 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
2323 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09002324 }
2325
Jooyung Hande34d232020-07-23 13:04:15 +09002326 // For the dependency from platform to apex, use the latest stubs
2327 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002328 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2329 if !apexInfo.IsForPlatform() {
2330 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002331 }
2332
2333 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2334 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2335 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2336 // (b/144430859)
2337 c.apexSdkVersion = android.FutureApiLevel
2338 }
2339
Colin Crossd11fcda2017-10-23 17:59:01 -07002340 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002341 depName := ctx.OtherModuleName(dep)
2342 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002343
Ivan Lozano52767be2019-10-18 14:49:46 -07002344 ccDep, ok := dep.(LinkableInterface)
2345 if !ok {
2346
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002347 // handling for a few module types that aren't cc Module but that are also supported
2348 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002349 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002350 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002351 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2352 genRule.GeneratedSourceFiles()...)
2353 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002354 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002355 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002356 // Support exported headers from a generated_sources dependency
2357 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002358 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002359 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002360 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002361 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002362 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002363 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002364 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002365 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002366 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2367 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002368 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002369 // 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 +09002370 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002371
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002372 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002373 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002374 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002375 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002376 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002377 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002378 files := genRule.GeneratedSourceFiles()
2379 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002380 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002381 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002382 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 -07002383 }
2384 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002385 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002386 }
Colin Crossca860ac2016-01-04 14:34:37 -08002387 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002388 return
2389 }
2390
Colin Crossfe17f6f2019-03-28 19:30:56 -07002391 if depTag == android.ProtoPluginDepTag {
2392 return
2393 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002394 if depTag == llndkImplDep {
2395 return
2396 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002397
Colin Crossd11fcda2017-10-23 17:59:01 -07002398 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002399 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2400 return
2401 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002402 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002403 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2404 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002405 return
2406 }
2407
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002408 if depTag == reuseObjTag {
Colin Crossa717db72020-10-23 14:53:06 -07002409 // Skip reused objects for stub libraries, they use their own stub object file instead.
2410 // The reuseObjTag dependency still exists because the LinkageMutator runs before the
2411 // version mutator, so the stubs variant is created from the shared variant that
2412 // already has the reuseObjTag dependency on the static variant.
Colin Cross31076b32020-10-23 17:22:06 -07002413 if !c.library.buildStubs() {
Colin Crossa717db72020-10-23 14:53:06 -07002414 staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2415 objs := staticAnalogue.ReuseObjects
2416 depPaths.Objs = depPaths.Objs.Append(objs)
2417 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
2418 reexportExporter(depExporterInfo)
2419 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07002420 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09002421 }
2422
Colin Cross6e511a92020-07-27 21:26:48 -07002423 linkFile := ccDep.OutputFile()
2424
2425 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2426 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002427 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002428 return
2429 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002430
Jiyong Parke3867542020-12-03 17:28:25 +09002431 if !apexInfo.IsForPlatform() && libDepTag.excludeInApex {
2432 return
2433 }
2434
Colin Cross0de8a1e2020-09-18 14:15:30 -07002435 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
Colin Crossc99deeb2016-04-11 15:06:20 -07002436
Colin Cross6e511a92020-07-27 21:26:48 -07002437 var ptr *android.Paths
2438 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002439
Colin Cross6e511a92020-07-27 21:26:48 -07002440 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002441
Colin Cross6e511a92020-07-27 21:26:48 -07002442 switch {
2443 case libDepTag.header():
2444 // nothing
2445 case libDepTag.shared():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002446 if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
2447 if !ctx.Config().AllowMissingDependencies() {
2448 ctx.ModuleErrorf("module %q is not a shared library", depName)
2449 } else {
2450 ctx.AddMissingDependencies([]string{depName})
2451 }
2452 return
2453 }
Jiyong Parke3867542020-12-03 17:28:25 +09002454
Colin Cross0de8a1e2020-09-18 14:15:30 -07002455 sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
2456 sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryImplementationStubsInfoProvider).(SharedLibraryImplementationStubsInfo)
2457
2458 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedLibraryStubsInfos) > 0 {
2459 useStubs := false
Colin Cross31076b32020-10-23 17:22:06 -07002460
2461 if lib := moduleLibraryInterface(dep); lib.buildStubs() && c.UseVndk() { // LLNDK
Colin Cross0de8a1e2020-09-18 14:15:30 -07002462 if !apexInfo.IsForPlatform() {
2463 // For platform libraries, use current version of LLNDK
2464 // If this is for use_vendor apex we will apply the same rules
2465 // of apex sdk enforcement below to choose right version.
2466 useStubs = true
2467 }
2468 } else if apexInfo.IsForPlatform() {
2469 // If not building for APEX, use stubs only when it is from
2470 // an APEX (and not from platform)
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002471 // However, for host, ramdisk, vendor_ramdisk, recovery or bootstrap modules,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002472 // always link to non-stub variant
2473 useStubs = dep.(android.ApexModule).AnyVariantDirectlyInAnyApex() && !c.bootstrap()
2474 // Another exception: if this module is bundled with an APEX, then
2475 // it is linked with the non-stub variant of a module in the APEX
2476 // as if this is part of the APEX.
2477 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2478 for _, apexContents := range testFor.ApexContents {
2479 if apexContents.DirectlyInApex(depName) {
2480 useStubs = false
2481 break
2482 }
2483 }
2484 } else {
2485 // If building for APEX, use stubs when the parent is in any APEX that
2486 // the child is not in.
2487 useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
2488 }
2489
2490 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2491 if useStubs {
2492 sharedLibraryStubsInfo, err :=
2493 c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedLibraryStubsInfos, c.apexSdkVersion)
2494 if err != nil {
2495 ctx.OtherModuleErrorf(dep, err.Error())
2496 return
2497 }
2498 sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
2499 depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
2500 }
2501 }
2502
2503 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
2504 depFile = sharedLibraryInfo.TableOfContents
2505
Colin Cross6e511a92020-07-27 21:26:48 -07002506 ptr = &depPaths.SharedLibs
2507 switch libDepTag.Order {
2508 case earlyLibraryDependency:
2509 ptr = &depPaths.EarlySharedLibs
2510 depPtr = &depPaths.EarlySharedLibsDeps
2511 case normalLibraryDependency:
2512 ptr = &depPaths.SharedLibs
2513 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07002514 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002515 case lateLibraryDependency:
2516 ptr = &depPaths.LateSharedLibs
2517 depPtr = &depPaths.LateSharedLibsDeps
2518 default:
2519 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002520 }
Colin Cross6e511a92020-07-27 21:26:48 -07002521 case libDepTag.static():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002522 if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
2523 if !ctx.Config().AllowMissingDependencies() {
2524 ctx.ModuleErrorf("module %q is not a static library", depName)
2525 } else {
2526 ctx.AddMissingDependencies([]string{depName})
2527 }
2528 return
2529 }
2530 staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2531 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
Colin Cross6e511a92020-07-27 21:26:48 -07002532 if libDepTag.wholeStatic {
2533 ptr = &depPaths.WholeStaticLibs
Colin Cross0de8a1e2020-09-18 14:15:30 -07002534 if len(staticLibraryInfo.Objects.objFiles) > 0 {
2535 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
Inseob Kimeec88e12020-01-22 11:11:29 +09002536 } else {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002537 // This case normally catches prebuilt static
2538 // libraries, but it can also occur when
2539 // AllowMissingDependencies is on and the
2540 // dependencies has no sources of its own
2541 // but has a whole_static_libs dependency
2542 // on a missing library. We want to depend
2543 // on the .a file so that there is something
2544 // in the dependency tree that contains the
2545 // error rule for the missing transitive
2546 // dependency.
2547 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002548 }
Colin Cross6e511a92020-07-27 21:26:48 -07002549 } else {
2550 switch libDepTag.Order {
2551 case earlyLibraryDependency:
2552 panic(fmt.Errorf("early static libs not suppported"))
2553 case normalLibraryDependency:
2554 // static dependencies will be handled separately so they can be ordered
2555 // using transitive dependencies.
2556 ptr = nil
Colin Cross0de8a1e2020-09-18 14:15:30 -07002557 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002558 case lateLibraryDependency:
2559 ptr = &depPaths.LateStaticLibs
2560 default:
2561 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002562 }
2563 }
2564 }
2565
Colin Cross6e511a92020-07-27 21:26:48 -07002566 if libDepTag.static() && !libDepTag.wholeStatic {
2567 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2568 ctx.ModuleErrorf("module %q not a static library", depName)
2569 return
2570 }
Logan Chien43d34c32017-12-20 01:17:32 +08002571
Colin Cross6e511a92020-07-27 21:26:48 -07002572 // When combining coverage files for shared libraries and executables, coverage files
2573 // in static libraries act as if they were whole static libraries. The same goes for
2574 // source based Abi dump files.
2575 if c, ok := ccDep.(*Module); ok {
2576 staticLib := c.linker.(libraryInterface)
2577 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2578 staticLib.objs().coverageFiles...)
2579 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2580 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002581 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002582 // Handle non-CC modules here
2583 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002584 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002585 }
2586 }
2587
Colin Cross6e511a92020-07-27 21:26:48 -07002588 if ptr != nil {
2589 if !linkFile.Valid() {
2590 if !ctx.Config().AllowMissingDependencies() {
2591 ctx.ModuleErrorf("module %q missing output file", depName)
2592 } else {
2593 ctx.AddMissingDependencies([]string{depName})
2594 }
2595 return
2596 }
2597 *ptr = append(*ptr, linkFile.Path())
2598 }
2599
2600 if depPtr != nil {
2601 dep := depFile
2602 if !dep.Valid() {
2603 dep = linkFile
2604 }
2605 *depPtr = append(*depPtr, dep.Path())
2606 }
2607
Colin Cross0de8a1e2020-09-18 14:15:30 -07002608 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
2609 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
2610 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
2611 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
2612
2613 if libDepTag.reexportFlags {
2614 reexportExporter(depExporterInfo)
2615 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2616 // Re-exported shared library headers must be included as well since they can help us with type information
2617 // about template instantiations (instantiated from their headers).
2618 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2619 // scripts.
2620 c.sabi.Properties.ReexportedIncludes = append(
2621 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
2622 }
2623
Colin Cross6e511a92020-07-27 21:26:48 -07002624 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2625 switch {
2626 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002627 c.Properties.AndroidMkHeaderLibs = append(
2628 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002629 case libDepTag.shared():
Colin Cross31076b32020-10-23 17:22:06 -07002630 if lib := moduleLibraryInterface(dep); lib != nil {
2631 if lib.buildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002632 // Add the dependency to the APEX(es) providing the library so that
2633 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002634 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2635 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002636 c.Properties.ApexesProvidingSharedLibs = append(
2637 c.Properties.ApexesProvidingSharedLibs, an)
2638 }
2639 }
2640 }
2641
2642 // Note: the order of libs in this list is not important because
2643 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002644 c.Properties.AndroidMkSharedLibs = append(
2645 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002646 // Record baseLibName for snapshots.
2647 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2648 case libDepTag.static():
2649 if libDepTag.wholeStatic {
2650 c.Properties.AndroidMkWholeStaticLibs = append(
2651 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2652 } else {
2653 c.Properties.AndroidMkStaticLibs = append(
2654 c.Properties.AndroidMkStaticLibs, makeLibName)
2655 }
2656 }
2657 } else {
2658 switch depTag {
2659 case runtimeDepTag:
2660 c.Properties.AndroidMkRuntimeLibs = append(
2661 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2662 // Record baseLibName for snapshots.
2663 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2664 case objDepTag:
2665 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2666 case CrtBeginDepTag:
2667 depPaths.CrtBegin = linkFile
2668 case CrtEndDepTag:
2669 depPaths.CrtEnd = linkFile
2670 case dynamicLinkerDepTag:
2671 depPaths.DynamicLinker = linkFile
2672 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002673 }
Colin Crossca860ac2016-01-04 14:34:37 -08002674 })
2675
Jeff Gaston294356f2017-09-27 17:05:30 -07002676 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07002677 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
2678 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
2679 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002680
Colin Crossdd84e052017-05-17 13:44:16 -07002681 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002682 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002683 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2684 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002685 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002686 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2687 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002688 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002689 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002690 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002691
2692 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002693 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002694 }
Colin Crossdd84e052017-05-17 13:44:16 -07002695
Colin Crossca860ac2016-01-04 14:34:37 -08002696 return depPaths
2697}
2698
Colin Cross0de8a1e2020-09-18 14:15:30 -07002699// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
2700// to match the topological order of the dependency tree, including any static analogues of
2701// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
2702// of the transitive dependencies.
2703func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
2704 transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
2705 var staticPaths android.Paths
2706 for _, staticDep := range staticDeps {
2707 staticPaths = append(staticPaths, staticDep.StaticLibrary)
2708 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
2709 }
2710 for _, sharedDep := range sharedDeps {
2711 if sharedDep.StaticAnalogue != nil {
2712 transitiveStaticLibsBuilder.Transitive(sharedDep.StaticAnalogue.TransitiveStaticLibrariesForOrdering)
2713 }
2714 }
2715 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
2716
2717 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
2718
2719 // reorder the dependencies based on transitive dependencies
2720 staticPaths = android.FirstUniquePaths(staticPaths)
2721 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
2722
2723 if len(orderedStaticPaths) != len(staticPaths) {
2724 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
2725 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
2726 }
2727
2728 return orderedStaticPaths, transitiveStaticLibs
2729}
2730
Colin Cross6e511a92020-07-27 21:26:48 -07002731// baseLibName trims known prefixes and suffixes
2732func baseLibName(depName string) string {
2733 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2734 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2735 libName = strings.TrimPrefix(libName, "prebuilt_")
2736 return libName
2737}
2738
2739func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2740 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2741 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2742
2743 libName := baseLibName(depName)
2744 isLLndk := isLlndkLibrary(libName, ctx.Config())
2745 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2746 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2747
2748 if c, ok := ccDep.(*Module); ok {
2749 // Use base module name for snapshots when exporting to Makefile.
2750 if c.isSnapshotPrebuilt() {
2751 baseName := c.BaseModuleName()
2752
2753 if c.IsVndk() {
2754 return baseName + ".vendor"
2755 }
2756
2757 if vendorSuffixModules[baseName] {
2758 return baseName + ".vendor"
2759 } else {
2760 return baseName
2761 }
2762 }
2763 }
2764
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002765 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() &&
2766 !c.InRamdisk() && !c.InVendorRamdisk() && !c.InRecovery() {
Colin Cross6e511a92020-07-27 21:26:48 -07002767 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2768 // core module instead.
2769 return libName
2770 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2771 // The vendor module in Make will have been renamed to not conflict with the core
2772 // module, so update the dependency name here accordingly.
2773 return libName + c.getNameSuffixWithVndkVersion(ctx)
2774 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2775 return libName + vendorPublicLibrarySuffix
2776 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2777 return libName + ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002778 } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
2779 return libName + vendorRamdiskSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07002780 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2781 return libName + recoverySuffix
2782 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2783 return libName + nativeBridgeSuffix
2784 } else {
2785 return libName
2786 }
2787}
2788
Colin Crossca860ac2016-01-04 14:34:37 -08002789func (c *Module) InstallInData() bool {
2790 if c.installer == nil {
2791 return false
2792 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002793 return c.installer.inData()
2794}
2795
2796func (c *Module) InstallInSanitizerDir() bool {
2797 if c.installer == nil {
2798 return false
2799 }
2800 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002801 return true
2802 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002803 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002804}
2805
Yifan Hong1b3348d2020-01-21 15:53:22 -08002806func (c *Module) InstallInRamdisk() bool {
2807 return c.InRamdisk()
2808}
2809
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002810func (c *Module) InstallInVendorRamdisk() bool {
2811 return c.InVendorRamdisk()
2812}
2813
Jiyong Parkf9332f12018-02-01 00:54:12 +09002814func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002815 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002816}
2817
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002818func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002819 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002820 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002821 return
2822 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002823 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002824}
2825
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002826func (c *Module) HostToolPath() android.OptionalPath {
2827 if c.installer == nil {
2828 return android.OptionalPath{}
2829 }
2830 return c.installer.hostToolPath()
2831}
2832
Nan Zhangd4e641b2017-07-12 12:55:28 -07002833func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2834 return c.outputFile
2835}
2836
Colin Cross41955e82019-05-29 14:40:35 -07002837func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2838 switch tag {
2839 case "":
2840 if c.outputFile.Valid() {
2841 return android.Paths{c.outputFile.Path()}, nil
2842 }
2843 return android.Paths{}, nil
2844 default:
2845 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002846 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002847}
2848
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002849func (c *Module) static() bool {
2850 if static, ok := c.linker.(interface {
2851 static() bool
2852 }); ok {
2853 return static.static()
2854 }
2855 return false
2856}
2857
Jiyong Park379de2f2018-12-19 02:47:14 +09002858func (c *Module) staticBinary() bool {
2859 if static, ok := c.linker.(interface {
2860 staticBinary() bool
2861 }); ok {
2862 return static.staticBinary()
2863 }
2864 return false
2865}
2866
Jiyong Park1d1119f2019-07-29 21:27:18 +09002867func (c *Module) header() bool {
2868 if h, ok := c.linker.(interface {
2869 header() bool
2870 }); ok {
2871 return h.header()
2872 }
2873 return false
2874}
2875
Inseob Kim7f283f42020-06-01 21:53:49 +09002876func (c *Module) binary() bool {
2877 if b, ok := c.linker.(interface {
2878 binary() bool
2879 }); ok {
2880 return b.binary()
2881 }
2882 return false
2883}
2884
Inseob Kim1042d292020-06-01 23:23:05 +09002885func (c *Module) object() bool {
2886 if o, ok := c.linker.(interface {
2887 object() bool
2888 }); ok {
2889 return o.object()
2890 }
2891 return false
2892}
2893
Jooyung Han38002912019-05-16 04:01:54 +09002894func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002895 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002896 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2897 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002898 return "native:vndk"
2899 }
Jooyung Han38002912019-05-16 04:01:54 +09002900 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002901 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002902 if c.IsVndk() && !c.isVndkExt() {
Justin Yun63e9ec72020-10-29 16:49:43 +09002903 // Product_available, if defined, must have the same value with Vendor_available.
Jooyung Han38002912019-05-16 04:01:54 +09002904 if Bool(c.VendorProperties.Vendor_available) {
2905 return "native:vndk"
2906 }
2907 return "native:vndk_private"
2908 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002909 if c.inProduct() {
2910 return "native:product"
2911 }
Jooyung Han38002912019-05-16 04:01:54 +09002912 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002913 } else if c.InRamdisk() {
2914 return "native:ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002915 } else if c.InVendorRamdisk() {
2916 return "native:vendor_ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002917 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002918 return "native:recovery"
2919 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2920 return "native:ndk:none:none"
2921 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2922 //family, link := getNdkStlFamilyAndLinkType(c)
2923 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002924 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002925 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002926 } else {
2927 return "native:platform"
2928 }
2929}
2930
Jiyong Park9d452992018-10-03 00:38:19 +09002931// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002932// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002933func (c *Module) IsInstallableToApex() bool {
Colin Cross31076b32020-10-23 17:22:06 -07002934 if lib := c.library; lib != nil {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002935 // Stub libs and prebuilt libs in a versioned SDK are not
2936 // installable to APEX even though they are shared libs.
Colin Cross31076b32020-10-23 17:22:06 -07002937 return lib.shared() && !lib.buildStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002938 } else if _, ok := c.linker.(testPerSrc); ok {
2939 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002940 }
2941 return false
2942}
2943
Jiyong Parka90ca002019-10-07 15:47:24 +09002944func (c *Module) AvailableFor(what string) bool {
2945 if linker, ok := c.linker.(interface {
2946 availableFor(string) bool
2947 }); ok {
2948 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2949 } else {
2950 return c.ApexModuleBase.AvailableFor(what)
2951 }
2952}
2953
Jiyong Park62304bb2020-04-13 16:19:48 +09002954func (c *Module) TestFor() []string {
2955 if test, ok := c.linker.(interface {
2956 testFor() []string
2957 }); ok {
2958 return test.testFor()
2959 } else {
2960 return c.ApexModuleBase.TestFor()
2961 }
2962}
2963
Colin Crossaede88c2020-08-11 12:17:01 -07002964func (c *Module) UniqueApexVariations() bool {
2965 if u, ok := c.compiler.(interface {
2966 uniqueApexVariations() bool
2967 }); ok {
2968 return u.uniqueApexVariations()
2969 } else {
2970 return false
2971 }
2972}
2973
Paul Duffin0cb37b92020-03-04 14:52:46 +00002974// Return true if the module is ever installable.
2975func (c *Module) EverInstallable() bool {
2976 return c.installer != nil &&
2977 // Check to see whether the module is actually ever installable.
2978 c.installer.everInstallable()
2979}
2980
Colin Cross56a83212020-09-15 18:30:11 -07002981func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002982 ret := c.EverInstallable() &&
2983 // Check to see whether the module has been configured to not be installed.
2984 proptools.BoolDefault(c.Properties.Installable, true) &&
2985 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002986
2987 // The platform variant doesn't need further condition. Apex variants however might not
2988 // be installable because it will likely to be included in the APEX and won't appear
2989 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07002990 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002991 return ret
2992 }
2993
2994 // Special case for modules that are configured to be installed to /data, which includes
2995 // test modules. For these modules, both APEX and non-APEX variants are considered as
2996 // installable. This is because even the APEX variants won't be included in the APEX, but
2997 // will anyway be installed to /data/*.
2998 // See b/146995717
2999 if c.InstallInData() {
3000 return ret
3001 }
3002
3003 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003004}
3005
Logan Chien41eabe62019-04-10 13:33:58 +08003006func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3007 if c.linker != nil {
3008 if library, ok := c.linker.(*libraryDecorator); ok {
3009 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3010 }
3011 }
3012}
3013
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003014func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07003015 depTag := ctx.OtherModuleDependencyTag(dep)
3016 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3017
3018 if cc, ok := dep.(*Module); ok {
3019 if cc.HasStubsVariants() {
3020 if isLibDepTag && libDepTag.shared() {
3021 // dynamic dep to a stubs lib crosses APEX boundary
3022 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003023 }
Colin Cross6e511a92020-07-27 21:26:48 -07003024 if IsRuntimeDepTag(depTag) {
3025 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003026 return false
3027 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003028 }
Colin Crossaac32222020-07-29 12:51:56 -07003029 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003030 // shared_lib dependency from a static lib is considered as crossing
3031 // the APEX boundary because the dependency doesn't actually is
3032 // linked; the dependency is used only during the compilation phase.
3033 return false
3034 }
Jiyong Parke3867542020-12-03 17:28:25 +09003035
3036 if isLibDepTag && libDepTag.excludeInApex {
3037 return false
3038 }
Colin Cross6e511a92020-07-27 21:26:48 -07003039 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07003040 if depTag == stubImplDepTag || depTag == llndkImplDep {
3041 // We don't track beyond LLNDK or from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09003042 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003043 }
3044 return true
3045}
3046
Dan Albertc8060532020-07-22 22:32:17 -07003047func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3048 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003049 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3050 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3051 return nil
3052 }
3053 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3054 if c.ToolchainLibrary() {
3055 return nil
3056 }
3057 // We don't check for prebuilt modules
3058 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3059 return nil
3060 }
3061 minSdkVersion := c.MinSdkVersion()
3062 if minSdkVersion == "apex_inherit" {
3063 return nil
3064 }
3065 if minSdkVersion == "" {
3066 // JNI libs within APK-in-APEX fall into here
3067 // Those are okay to set sdk_version instead
3068 // We don't have to check if this is a SDK variant because
3069 // non-SDK variant resets sdk_version, which works too.
3070 minSdkVersion = c.SdkVersion()
3071 }
Dan Albertc8060532020-07-22 22:32:17 -07003072 if minSdkVersion == "" {
3073 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3074 }
3075 // Not using nativeApiLevelFromUser because the context here is not
3076 // necessarily a native context.
3077 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003078 if err != nil {
3079 return err
3080 }
Dan Albertc8060532020-07-22 22:32:17 -07003081
3082 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003083 return fmt.Errorf("newer SDK(%v)", ver)
3084 }
3085 return nil
3086}
3087
Colin Cross2ba19d92015-05-07 15:44:20 -07003088//
Colin Crosscfad1192015-11-02 16:43:11 -08003089// Defaults
3090//
Colin Crossca860ac2016-01-04 14:34:37 -08003091type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003092 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003093 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003094 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003095}
3096
Patrice Arrudac249c712019-03-19 17:00:29 -07003097// cc_defaults provides a set of properties that can be inherited by other cc
3098// modules. A module can use the properties from a cc_defaults using
3099// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3100// merged (when possible) by prepending the default module's values to the
3101// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003102func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003103 return DefaultsFactory()
3104}
3105
Colin Cross36242852017-06-23 15:06:31 -07003106func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003107 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003108
Colin Cross36242852017-06-23 15:06:31 -07003109 module.AddProperties(props...)
3110 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003111 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003112 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003113 &BaseCompilerProperties{},
3114 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003115 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003116 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003117 &StaticProperties{},
3118 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003119 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003120 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003121 &TestProperties{},
3122 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003123 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003124 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003125 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003126 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003127 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003128 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003129 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003130 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003131 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003132 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003133 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003134 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003135 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003136 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3137 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003138 )
Colin Crosscfad1192015-11-02 16:43:11 -08003139
Jooyung Hancc372c52019-09-25 15:18:44 +09003140 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003141
3142 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003143}
3144
Jiyong Park2286afd2020-06-16 21:58:53 +09003145func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003146 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003147}
3148
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003149func kytheExtractAllFactory() android.Singleton {
3150 return &kytheExtractAllSingleton{}
3151}
3152
3153type kytheExtractAllSingleton struct {
3154}
3155
3156func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3157 var xrefTargets android.Paths
3158 ctx.VisitAllModules(func(module android.Module) {
3159 if ccModule, ok := module.(xref); ok {
3160 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3161 }
3162 })
3163 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3164 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003165 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003166 }
3167}
3168
Colin Cross06a931b2015-10-28 17:23:31 -07003169var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003170var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003171var BoolPtr = proptools.BoolPtr
3172var String = proptools.String
3173var StringPtr = proptools.StringPtr