blob: 9a5f6b2d69878716d293637dd3f3123d36c18d78 [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()
Jose Galmes6f843bc2020-12-11 13:36:29 -080055 ctx.BottomUp("recovery_snapshot", RecoverySnapshotMutator).Parallel()
56 ctx.BottomUp("recovery_snapshot_source", RecoverySnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070057 })
Colin Cross16b23492016-01-06 14:41:07 -080058
Paul Duffin036e7002019-12-19 19:16:28 +000059 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070060 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
61 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080062
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070063 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
64 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
65
Mitch Phillipsbfeade62019-05-01 14:42:05 -070066 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
67 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
68
Jiyong Park1d1119f2019-07-29 21:27:18 +090069 // cfi mutator shouldn't run before sanitizers that return true for
70 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000071 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
72 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
73
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080074 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
75 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
76
Colin Cross1e676be2016-10-12 14:38:15 -070077 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
78 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080079
Colin Cross0b908332019-06-19 23:00:20 -070080 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090081 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080082
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080083 ctx.BottomUp("coverage", coverageMutator).Parallel()
Stephen Craneba090d12017-05-09 15:44:35 -070084
85 ctx.TopDown("lto_deps", ltoDepsMutator)
86 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090087
Jooyung Han479ca172020-10-19 18:51:07 +090088 ctx.BottomUp("check_linktype", checkLinkTypeMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090089 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070090 })
Colin Crossb98c8b02016-07-29 13:44:28 -070091
Yo Chiang8aa4e3f2020-11-19 16:30:49 +080092 ctx.FinalDepsMutators(func(ctx android.RegisterMutatorsContext) {
93 // sabi mutator needs to be run after apex mutator finishes.
94 ctx.TopDown("sabi_deps", sabiDepsMutator)
95 })
96
Colin Cross57898582020-10-29 18:25:19 -070097 ctx.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070098}
99
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500100// Deps is a struct containing module names of dependencies, separated by the kind of dependency.
101// Mutators should use `AddVariationDependencies` or its sibling methods to add actual dependency
102// edges to these modules.
103// This object is constructed in DepsMutator, by calling to various module delegates to set
104// relevant fields. For example, `module.compiler.compilerDeps()` may append type-specific
105// dependencies.
106// This is then consumed by the same DepsMutator, which will call `ctx.AddVariationDependencies()`
107// (or its sibling methods) to set real dependencies on the given modules.
Colin Crossca860ac2016-01-04 14:34:37 -0800108type Deps struct {
109 SharedLibs, LateSharedLibs []string
110 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -0800111 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +0800112 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -0700113
Chris Parsons79d66a52020-06-05 17:26:16 -0400114 // Used for data dependencies adjacent to tests
115 DataLibs []string
116
Yo Chiang219968c2020-09-22 18:45:04 +0800117 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
118 SystemSharedLibs []string
119
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500120 // If true, statically link the unwinder into native libraries/binaries.
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800121 StaticUnwinderIfLegacy bool
122
Colin Cross5950f382016-12-13 12:50:57 -0800123 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700124
Colin Cross81413472016-04-11 14:37:39 -0700125 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700126
Dan Willemsenb40aab62016-04-20 14:21:14 -0700127 GeneratedSources []string
128 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900129 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700130
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700131 ReexportGeneratedHeaders []string
132
Colin Cross97ba0732015-03-23 17:50:24 -0700133 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700134
135 // Used for host bionic
136 LinkerFlagsFile string
137 DynamicLinker string
Jiyong Parke3867542020-12-03 17:28:25 +0900138
139 // List of libs that need to be excluded for APEX variant
140 ExcludeLibsForApex []string
Colin Crossc472d572015-03-17 15:06:21 -0700141}
142
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500143// PathDeps is a struct containing file paths to dependencies of a module.
144// It's constructed in depsToPath() by traversing the direct dependencies of the current module.
145// It's used to construct flags for various build statements (such as for compiling and linking).
146// It is then passed to module decorator functions responsible for registering build statements
147// (such as `module.compiler.compile()`).`
Colin Crossca860ac2016-01-04 14:34:37 -0800148type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700149 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900150 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700151 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900152 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700153 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700154 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700155
Colin Cross0de8a1e2020-09-18 14:15:30 -0700156 // Transitive static library dependencies of static libraries for use in ordering.
157 TranstiveStaticLibrariesForOrdering *android.DepSet
158
Colin Cross26c34ed2016-09-30 17:10:16 -0700159 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100160 Objs Objects
161 // Paths to .o files in dependencies that provide them. Note that these lists
162 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800163 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700164 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700165
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100166 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
167 // the libs from all whole_static_lib dependencies.
168 WholeStaticLibsFromPrebuilts android.Paths
169
Colin Cross26c34ed2016-09-30 17:10:16 -0700170 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700171 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900172 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700173
Inseob Kimd110f872019-12-06 13:15:38 +0900174 Flags []string
175 IncludeDirs android.Paths
176 SystemIncludeDirs android.Paths
177 ReexportedDirs android.Paths
178 ReexportedSystemDirs android.Paths
179 ReexportedFlags []string
180 ReexportedGeneratedHeaders android.Paths
181 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700182
Colin Cross26c34ed2016-09-30 17:10:16 -0700183 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700184 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700185
186 // Path to the file container flags to use with the linker
187 LinkerFlagsFile android.OptionalPath
188
189 // Path to the dynamic linker binary
190 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700191}
192
Colin Cross4af21ed2019-11-04 09:37:55 -0800193// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
194// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
195// command line so they can be overridden by the local module flags).
196type LocalOrGlobalFlags struct {
197 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700198 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800199 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700200 CFlags []string // Flags that apply to C and C++ source files
201 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
202 ConlyFlags []string // Flags that apply to C source files
203 CppFlags []string // Flags that apply to C++ source files
204 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700205 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800206}
207
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500208// Flags contains various types of command line flags (and settings) for use in building build
209// statements related to C++.
Colin Cross4af21ed2019-11-04 09:37:55 -0800210type Flags struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500211 // Local flags (which individual modules are responsible for). These may override global flags.
212 Local LocalOrGlobalFlags
213 // Global flags (which build system or toolchain is responsible for).
Colin Cross4af21ed2019-11-04 09:37:55 -0800214 Global LocalOrGlobalFlags
215
216 aidlFlags []string // Flags that apply to aidl source files
217 rsFlags []string // Flags that apply to renderscript source files
218 libFlags []string // Flags to add libraries early to the link order
219 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
220 TidyFlags []string // Flags that apply to clang-tidy
221 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700222
Colin Crossc3199482017-03-30 15:03:04 -0700223 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800224 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700225 SystemIncludeFlags []string
226
Oliver Nguyen04526782020-04-21 12:40:27 -0700227 Toolchain config.Toolchain
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500228 Tidy bool // True if clang-tidy is enabled.
229 GcovCoverage bool // True if coverage files should be generated.
230 SAbiDump bool // True if header abi dumps should be generated.
Oliver Nguyen04526782020-04-21 12:40:27 -0700231 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800232
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500233 // The instruction set required for clang ("arm" or "thumb").
Colin Crossca860ac2016-01-04 14:34:37 -0800234 RequiredInstructionSet string
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500235 // The target-device system path to the dynamic linker.
236 DynamicLinker string
Colin Cross16b23492016-01-06 14:41:07 -0800237
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700238 CFlagsDeps android.Paths // Files depended on by compiler flags
239 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800240
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500241 // True if .s files should be processed with the c preprocessor.
Dan Willemsen98ab3112019-08-27 21:20:40 -0700242 AssemblerWithCpp bool
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500243 // True if static libraries should be grouped (using `-Wl,--start-group` and `-Wl,--end-group`).
244 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800245
Colin Cross19878da2019-03-28 14:45:07 -0700246 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700247 protoC bool // Whether to use C instead of C++
248 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700249
250 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200251 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700252}
253
Colin Crossca860ac2016-01-04 14:34:37 -0800254// Properties used to compile all C or C++ modules
255type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700256 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800257 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700258
Colin Crossc511bc52020-04-07 16:50:32 +0000259 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
260 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800261 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700262
Jooyung Han379660c2020-04-21 15:24:00 +0900263 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
264 Min_sdk_version *string
265
Colin Crossc511bc52020-04-07 16:50:32 +0000266 // If true, always create an sdk variant and don't create a platform variant.
267 Sdk_variant_only *bool
268
Jiyong Parkde866cb2018-12-07 23:08:36 +0900269 AndroidMkSharedLibs []string `blueprint:"mutated"`
270 AndroidMkStaticLibs []string `blueprint:"mutated"`
271 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
272 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700273 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900274 HideFromMake bool `blueprint:"mutated"`
275 PreventInstall bool `blueprint:"mutated"`
276 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700277
Yo Chiang219968c2020-09-22 18:45:04 +0800278 // Set by DepsMutator.
279 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
280
Justin Yun5f7f7e82019-11-18 19:52:14 +0900281 ImageVariationPrefix string `blueprint:"mutated"`
282 VndkVersion string `blueprint:"mutated"`
283 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800284
285 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
286 // file
287 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900288
Yifan Hong39143a92020-10-26 12:43:12 -0700289 // Make this module available when building for ramdisk.
290 // On device without a dedicated recovery partition, the module is only
291 // available after switching root into
292 // /first_stage_ramdisk. To expose the module before switching root, install
293 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -0800294 Ramdisk_available *bool
295
Yifan Hong39143a92020-10-26 12:43:12 -0700296 // Make this module available when building for vendor ramdisk.
297 // On device without a dedicated recovery partition, the module is only
298 // available after switching root into
299 // /first_stage_ramdisk. To expose the module before switching root, install
300 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700301 Vendor_ramdisk_available *bool
302
Jiyong Parkf9332f12018-02-01 00:54:12 +0900303 // Make this module available when building for recovery
304 Recovery_available *bool
305
Colin Crossae6c5202019-11-20 13:35:50 -0800306 // Set by imageMutator
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700307 CoreVariantNeeded bool `blueprint:"mutated"`
308 RamdiskVariantNeeded bool `blueprint:"mutated"`
309 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
310 RecoveryVariantNeeded bool `blueprint:"mutated"`
311 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900312
313 // Allows this module to use non-APEX version of libraries. Useful
314 // for building binaries that are started before APEXes are activated.
315 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900316
317 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
318 // see soong/cc/config/vndk.go
319 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900320
321 // Used by vendor snapshot to record dependencies from snapshot modules.
322 SnapshotSharedLibs []string `blueprint:"mutated"`
323 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000324
325 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000326
327 // Set by factories of module types that can only be referenced from variants compiled against
328 // the SDK.
329 AlwaysSdk bool `blueprint:"mutated"`
330
331 // Variant is an SDK variant created by sdkMutator
332 IsSdkVariant bool `blueprint:"mutated"`
333 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
334 // variant to have a ".sdk" suffix.
335 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700336
337 // Normally Soong uses the directory structure to decide which modules
338 // should be included (framework) or excluded (non-framework) from the
Jose Galmes6f843bc2020-12-11 13:36:29 -0800339 // different snapshots (vendor, recovery, etc.), but this property
340 // allows a partner to exclude a module normally thought of as a
341 // framework module from the vendor snapshot.
342 Exclude_from_vendor_snapshot *bool
343
344 // Normally Soong uses the directory structure to decide which modules
345 // should be included (framework) or excluded (non-framework) from the
346 // different snapshots (vendor, recovery, etc.), but this property
347 // allows a partner to exclude a module normally thought of as a
348 // framework module from the recovery snapshot.
Jose Galmesf7294582020-11-13 12:07:36 -0800349 Exclude_from_recovery_snapshot *bool
Jiyong Park46a512f2020-12-04 18:02:13 +0900350
351 // List of APEXes that this module has private access to for testing purpose. The module
352 // can depend on libraries that are not exported by the APEXes and use private symbols
353 // from the exported libraries.
354 Test_for []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700355}
356
357type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900358 // whether this module should be allowed to be directly depended by other
359 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun63e9ec72020-10-29 16:49:43 +0900360 // If set to true, two variants will be built separately, one like
361 // normal, and the other limited to the set of libraries and headers
362 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700363 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900364 // The vendor variant may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700365 // so it shouldn't have any unversioned runtime dependencies, or
366 // make assumptions about the system that may not be true in the
367 // future.
368 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900369 // If set to false, this module becomes inaccessible from /vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900370 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900371 // The modules with vndk: {enabled: true} must define 'vendor_available'
372 // to either 'true' or 'false'. In this case, 'vendor_available: false' has
373 // a different meaning than that of non-VNDK modules.
374 // 'vendor_available: false' for a VNDK module means 'VNDK-private' that
375 // can only be depended on by VNDK libraries, not by non-VNDK vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900376 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700377 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
378 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900379
Justin Yun63e9ec72020-10-29 16:49:43 +0900380 // whether this module should be allowed to be directly depended by other
381 // modules with `product_specific: true` or `product_available: true`.
382 // If set to true, an additional product variant will be built separately
383 // that is limited to the set of libraries and headers that are exposed to
384 // /product modules.
385 //
386 // The product variant may be used with a different (newer) /system,
387 // so it shouldn't have any unversioned runtime dependencies, or
388 // make assumptions about the system that may not be true in the
389 // future.
390 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900391 // If set to false, this module becomes inaccessible from /product modules.
392 //
393 // Different from the 'vendor_available' property, the modules with
394 // vndk: {enabled: true} don't have to define 'product_available'. The VNDK
395 // library without 'product_available' may not be depended on by any other
396 // modules that has product variants including the product available VNDKs.
397 // However, for the modules with vndk: {enabled: true},
398 // 'product_available: false' creates the product variant that is available
399 // only for the other product available VNDK modules but not by non-VNDK
400 // product modules.
401 // In the case of the modules with vndk: {enabled: true}, if
402 // 'product_available' is defined, it must have the same value with the
403 // 'vendor_available'.
Justin Yun63e9ec72020-10-29 16:49:43 +0900404 //
405 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
406 // and PRODUCT_PRODUCT_VNDK_VERSION isn't set.
407 Product_available *bool
408
Jiyong Park5fb8c102018-04-09 12:03:06 +0900409 // whether this module is capable of being loaded with other instance
410 // (possibly an older version) of the same module in the same process.
411 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
412 // can be double loaded in a vendor process if the library is also a
413 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
414 // explicitly marked as `double_loadable: true` by the owner, or the dependency
415 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
416 Double_loadable *bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800417
418 // IsLLNDK is set to true for the vendor variant of a cc_library module that has LLNDK stubs.
419 IsLLNDK bool `blueprint:"mutated"`
420
Colin Cross78212242021-01-06 14:51:30 -0800421 // IsVNDKUsingCoreVariant is true for VNDK modules if the global VndkUseCoreVariant option is
422 // set and the module is not listed in VndkMustUseVendorVariantList.
423 IsVNDKUsingCoreVariant bool `blueprint:"mutated"`
424
425 // IsVNDKCore is set if a VNDK module does not set the vndk.support_system_process property.
426 IsVNDKCore bool `blueprint:"mutated"`
427
428 // IsVNDKSP is set if a VNDK module sets the vndk.support_system_process property.
429 IsVNDKSP bool `blueprint:"mutated"`
430
431 // IsVNDKPrivate is set if a VNDK module sets the vndk.private property or an LLNDK
432 // module sets the llndk.private property.
433 IsVNDKPrivate bool `blueprint:"mutated"`
434
435 // IsVNDKProduct is set if a VNDK module sets the product_available property.
436 IsVNDKProduct bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800437}
438
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500439// ModuleContextIntf is an interface (on a module context helper) consisting of functions related
440// to understanding details about the type of the current module.
441// For example, one might call these functions to determine whether the current module is a static
442// library and/or is installed in vendor directories.
Colin Crossca860ac2016-01-04 14:34:37 -0800443type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800444 static() bool
445 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900446 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900447 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900448 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700449 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900450 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700451 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800452 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700453 useVndk() bool
Colin Cross95f1ca02020-10-29 20:47:22 -0700454 isNdk(config android.Config) bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800455 IsLlndk() bool
456 IsLlndkPublic() bool
457 isImplementationForLLNDKPublic() bool
458 IsVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900459 isVndk() bool
460 isVndkSp() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500461 IsVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900462 inProduct() bool
463 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800464 inRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700465 inVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900466 inRecovery() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700467 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700468 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800469 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800470 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800471 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800472 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800473 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700474 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700475 apexSdkVersion() android.ApiLevel
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900476 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800477 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700478 nativeCoverage() bool
Colin Cross56a83212020-09-15 18:30:11 -0700479 directlyInAnyApex() bool
Colin Cross95b07f22020-12-16 11:06:50 -0800480 isPreventInstall() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800481}
482
483type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700484 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800485 ModuleContextIntf
486}
487
488type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700489 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800490 ModuleContextIntf
491}
492
Colin Cross37047f12016-12-13 17:06:13 -0800493type DepsContext interface {
494 android.BottomUpMutatorContext
495 ModuleContextIntf
496}
497
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500498// feature represents additional (optional) steps to building cc-related modules, such as invocation
499// of clang-tidy.
Colin Crossca860ac2016-01-04 14:34:37 -0800500type feature interface {
501 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800502 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800503 flags(ctx ModuleContext, flags Flags) Flags
504 props() []interface{}
505}
506
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500507// compiler is the interface for a compiler helper object. Different module decorators may implement
508// this helper differently. For example, compiling a `cc_library` may use a different build
509// statement than building a `toolchain_library`.
Colin Crossca860ac2016-01-04 14:34:37 -0800510type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700511 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800512 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800513 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700514 compilerProps() []interface{}
515
Colin Cross76fada02016-07-27 10:31:13 -0700516 appendCflags([]string)
517 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700518 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800519}
520
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500521// linker is the interface for a linker decorator object. Individual module types can provide
522// their own implementation for this decorator, and thus specify custom logic regarding build
523// statements pertaining to linking.
Colin Crossca860ac2016-01-04 14:34:37 -0800524type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700525 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800526 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700527 linkerFlags(ctx ModuleContext, flags Flags) Flags
528 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800529 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700530
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700531 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700532 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900533 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700534
535 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900536 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000537
538 // Get the deps that have been explicitly specified in the properties.
Paul Duffin13f02712020-03-06 12:30:43 +0000539 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
540}
541
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500542// specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
Paul Duffin13f02712020-03-06 12:30:43 +0000543type specifiedDeps struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500544 sharedLibs []string
545 // Note nil and [] are semantically distinct. [] prevents linking against the defaults (usually
546 // libc, libm, etc.)
547 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800548}
549
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500550// installer is the interface for an installer helper object. This helper is responsible for
551// copying build outputs to the appropriate locations so that they may be installed on device.
Colin Crossca860ac2016-01-04 14:34:37 -0800552type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700553 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700554 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000555 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800556 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700557 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700558 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900559 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100560 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800561}
562
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800563type xref interface {
564 XrefCcFiles() android.Paths
565}
566
Colin Cross6e511a92020-07-27 21:26:48 -0700567type libraryDependencyKind int
568
569const (
570 headerLibraryDependency = iota
571 sharedLibraryDependency
572 staticLibraryDependency
573)
574
575func (k libraryDependencyKind) String() string {
576 switch k {
577 case headerLibraryDependency:
578 return "headerLibraryDependency"
579 case sharedLibraryDependency:
580 return "sharedLibraryDependency"
581 case staticLibraryDependency:
582 return "staticLibraryDependency"
583 default:
584 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
585 }
586}
587
588type libraryDependencyOrder int
589
590const (
591 earlyLibraryDependency = -1
592 normalLibraryDependency = 0
593 lateLibraryDependency = 1
594)
595
596func (o libraryDependencyOrder) String() string {
597 switch o {
598 case earlyLibraryDependency:
599 return "earlyLibraryDependency"
600 case normalLibraryDependency:
601 return "normalLibraryDependency"
602 case lateLibraryDependency:
603 return "lateLibraryDependency"
604 default:
605 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
606 }
607}
608
609// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
610// tags that have a set of predefined tag objects that are reused for each dependency, a
611// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
612// That means that comparing a libraryDependencyTag for equality will only be equal if all
613// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
614// then check individual metadata fields instead.
615type libraryDependencyTag struct {
616 blueprint.BaseDependencyTag
617
618 // These are exported so that fmt.Printf("%#v") can call their String methods.
619 Kind libraryDependencyKind
620 Order libraryDependencyOrder
621
622 wholeStatic bool
623
624 reexportFlags bool
625 explicitlyVersioned bool
626 dataLib bool
627 ndk bool
628
629 staticUnwinder bool
630
631 makeSuffix string
Jiyong Parke3867542020-12-03 17:28:25 +0900632
Cindy Zhou18417cb2020-12-10 07:12:38 -0800633 // Whether or not this dependency should skip the apex dependency check
634 skipApexAllowedDependenciesCheck bool
635
Jiyong Parke3867542020-12-03 17:28:25 +0900636 // Whether or not this dependency has to be followed for the apex variants
637 excludeInApex bool
Colin Cross6e511a92020-07-27 21:26:48 -0700638}
639
640// header returns true if the libraryDependencyTag is tagging a header lib dependency.
641func (d libraryDependencyTag) header() bool {
642 return d.Kind == headerLibraryDependency
643}
644
645// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
646func (d libraryDependencyTag) shared() bool {
647 return d.Kind == sharedLibraryDependency
648}
649
650// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
651func (d libraryDependencyTag) static() bool {
652 return d.Kind == staticLibraryDependency
653}
654
Colin Crosse9fe2942020-11-10 18:12:15 -0800655// InstallDepNeeded returns true for shared libraries so that shared library dependencies of
656// binaries or other shared libraries are installed as dependencies.
657func (d libraryDependencyTag) InstallDepNeeded() bool {
658 return d.shared()
659}
660
661var _ android.InstallNeededDependencyTag = libraryDependencyTag{}
662
663// dependencyTag is used for tagging miscellaneous dependency types that don't fit into
Colin Cross6e511a92020-07-27 21:26:48 -0700664// libraryDependencyTag. Each tag object is created globally and reused for multiple
665// dependencies (although since the object contains no references, assigning a tag to a
666// variable and modifying it will not modify the original). Users can compare the tag
667// returned by ctx.OtherModuleDependencyTag against the global original
668type dependencyTag struct {
669 blueprint.BaseDependencyTag
670 name string
671}
672
Colin Crosse9fe2942020-11-10 18:12:15 -0800673// installDependencyTag is used for tagging miscellaneous dependency types that don't fit into
674// libraryDependencyTag, but where the dependency needs to be installed when the parent is
675// installed.
676type installDependencyTag struct {
677 blueprint.BaseDependencyTag
678 android.InstallAlwaysNeededDependencyTag
679 name string
680}
681
Colin Crossc99deeb2016-04-11 15:06:20 -0700682var (
Colin Cross6e511a92020-07-27 21:26:48 -0700683 genSourceDepTag = dependencyTag{name: "gen source"}
684 genHeaderDepTag = dependencyTag{name: "gen header"}
685 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
686 objDepTag = dependencyTag{name: "obj"}
687 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
Jiyong Parkd630bdd2020-11-25 11:47:24 +0900688 dynamicLinkerDepTag = installDependencyTag{name: "dynamic linker"}
Colin Cross6e511a92020-07-27 21:26:48 -0700689 reuseObjTag = dependencyTag{name: "reuse objects"}
690 staticVariantTag = dependencyTag{name: "static variant"}
691 vndkExtDepTag = dependencyTag{name: "vndk extends"}
692 dataLibDepTag = dependencyTag{name: "data lib"}
Colin Crosse9fe2942020-11-10 18:12:15 -0800693 runtimeDepTag = installDependencyTag{name: "runtime lib"}
Colin Cross6e511a92020-07-27 21:26:48 -0700694 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700695 stubImplDepTag = dependencyTag{name: "stub_impl"}
Colin Cross127bb8b2020-12-16 16:46:01 -0800696 llndkStubDepTag = dependencyTag{name: "llndk stub"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700697)
698
Colin Cross56a83212020-09-15 18:30:11 -0700699type copyDirectlyInAnyApexDependencyTag dependencyTag
700
701func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
702
703var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
704
Roland Levillainf89cd092019-07-29 16:22:59 +0100705func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700706 ccLibDepTag, ok := depTag.(libraryDependencyTag)
707 return ok && ccLibDepTag.shared()
708}
709
710func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
711 ccLibDepTag, ok := depTag.(libraryDependencyTag)
712 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100713}
714
Zach Johnson3df4e632020-11-06 11:56:27 -0800715func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
716 ccLibDepTag, ok := depTag.(libraryDependencyTag)
717 return ok && ccLibDepTag.header()
718}
719
Roland Levillainf89cd092019-07-29 16:22:59 +0100720func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Crosse9fe2942020-11-10 18:12:15 -0800721 return depTag == runtimeDepTag
Roland Levillainf89cd092019-07-29 16:22:59 +0100722}
723
724func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700725 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100726 return ok && ccDepTag == testPerSrcDepTag
727}
728
Colin Crossca860ac2016-01-04 14:34:37 -0800729// Module contains the properties and members used by all C/C++ module types, and implements
730// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500731// to construct the output file. Behavior can be customized with a Customizer, or "decorator",
732// interface.
733//
734// To define a C/C++ related module, construct a new Module object and point its delegates to
735// type-specific structs. These delegates will be invoked to register module-specific build
736// statements which may be unique to the module type. For example, module.compiler.compile() should
737// be defined so as to register build statements which are responsible for compiling the module.
738//
739// Another example: to construct a cc_binary module, one can create a `cc.binaryDecorator` struct
740// which implements the `linker` and `installer` interfaces, and points the `linker` and `installer`
741// members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
742// installer logic.
Colin Crossca860ac2016-01-04 14:34:37 -0800743type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700744 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700745 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900746 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900747 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700748
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700749 Properties BaseProperties
750 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700751
Colin Crossca860ac2016-01-04 14:34:37 -0800752 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700753 hod android.HostOrDeviceSupported
754 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700755
Paul Duffina0843f62019-12-13 19:50:38 +0000756 // Allowable SdkMemberTypes of this module type.
757 sdkMemberTypes []android.SdkMemberType
758
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500759 // decorator delegates, initialize before calling Init
760 // these may contain module-specific implementations, and effectively allow for custom
761 // type-specific logic. These members may reference different objects or the same object.
762 // Functions of these decorators will be invoked to initialize and register type-specific
763 // build statements.
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700764 compiler compiler
765 linker linker
766 installer installer
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500767
768 features []feature
769 stl *stl
770 sanitize *sanitize
771 coverage *coverage
772 sabi *sabi
773 vndkdep *vndkdep
774 lto *lto
775 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800776
Colin Cross31076b32020-10-23 17:22:06 -0700777 library libraryInterface
778
Colin Cross635c3b02016-05-18 15:37:25 -0700779 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800780
Colin Crossb98c8b02016-07-29 13:44:28 -0700781 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700782
783 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800784
785 // Flags used to compile this module
786 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700787
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800788 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700789 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900790
791 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800792 // Kythe (source file indexer) paths for this compilation module
793 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900794
795 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700796 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700797
798 hideApexVariantFromMake bool
Colin Crossc472d572015-03-17 15:06:21 -0700799}
800
Ivan Lozano52767be2019-10-18 14:49:46 -0700801func (c *Module) Toc() android.OptionalPath {
802 if c.linker != nil {
803 if library, ok := c.linker.(libraryInterface); ok {
804 return library.toc()
805 }
806 }
807 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
808}
809
810func (c *Module) ApiLevel() string {
811 if c.linker != nil {
812 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700813 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700814 }
815 }
816 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
817}
818
819func (c *Module) Static() bool {
820 if c.linker != nil {
821 if library, ok := c.linker.(libraryInterface); ok {
822 return library.static()
823 }
824 }
825 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
826}
827
828func (c *Module) Shared() bool {
829 if c.linker != nil {
830 if library, ok := c.linker.(libraryInterface); ok {
831 return library.shared()
832 }
833 }
834 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
835}
836
837func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000838 if c.stl != nil {
839 return c.stl.Properties.SelectedStl
840 }
841 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700842}
843
844func (c *Module) ToolchainLibrary() bool {
845 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
846 return true
847 }
848 return false
849}
850
851func (c *Module) NdkPrebuiltStl() bool {
852 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
853 return true
854 }
855 return false
856}
857
858func (c *Module) StubDecorator() bool {
859 if _, ok := c.linker.(*stubDecorator); ok {
860 return true
861 }
862 return false
863}
864
865func (c *Module) SdkVersion() string {
866 return String(c.Properties.Sdk_version)
867}
868
Artur Satayev480e25b2020-04-27 18:53:18 +0100869func (c *Module) MinSdkVersion() string {
870 return String(c.Properties.Min_sdk_version)
871}
872
Dan Albert92fe7402020-07-15 13:33:30 -0700873func (c *Module) SplitPerApiLevel() bool {
Colin Cross1348ce32020-10-01 13:37:16 -0700874 if !c.canUseSdk() {
875 return false
876 }
Dan Albert92fe7402020-07-15 13:33:30 -0700877 if linker, ok := c.linker.(*objectLinker); ok {
878 return linker.isCrt()
879 }
880 return false
881}
882
Colin Crossc511bc52020-04-07 16:50:32 +0000883func (c *Module) AlwaysSdk() bool {
884 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
885}
886
Ivan Lozano183a3212019-10-18 14:18:45 -0700887func (c *Module) CcLibrary() bool {
888 if c.linker != nil {
889 if _, ok := c.linker.(*libraryDecorator); ok {
890 return true
891 }
Colin Crossd48fe732020-09-23 20:37:24 -0700892 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
893 return true
894 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700895 }
896 return false
897}
898
899func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700900 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700901 return true
902 }
903 return false
904}
905
Ivan Lozano2b262972019-11-21 12:30:50 -0800906func (c *Module) NonCcVariants() bool {
907 return false
908}
909
Ivan Lozano183a3212019-10-18 14:18:45 -0700910func (c *Module) SetStatic() {
911 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700912 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700913 library.setStatic()
914 return
915 }
916 }
917 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
918}
919
920func (c *Module) SetShared() {
921 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700922 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700923 library.setShared()
924 return
925 }
926 }
927 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
928}
929
930func (c *Module) BuildStaticVariant() bool {
931 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700932 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700933 return library.buildStatic()
934 }
935 }
936 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
937}
938
939func (c *Module) BuildSharedVariant() bool {
940 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700941 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700942 return library.buildShared()
943 }
944 }
945 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
946}
947
948func (c *Module) Module() android.Module {
949 return c
950}
951
Jiyong Parkc20eee32018-09-05 22:36:17 +0900952func (c *Module) OutputFile() android.OptionalPath {
953 return c.outputFile
954}
955
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400956func (c *Module) CoverageFiles() android.Paths {
957 if c.linker != nil {
958 if library, ok := c.linker.(libraryInterface); ok {
959 return library.objs().coverageFiles
960 }
961 }
962 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
963}
964
Ivan Lozano183a3212019-10-18 14:18:45 -0700965var _ LinkableInterface = (*Module)(nil)
966
Jiyong Park719b4462019-01-13 00:39:51 +0900967func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900968 if c.linker != nil {
969 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900970 }
971 return nil
972}
973
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900974func (c *Module) CoverageOutputFile() android.OptionalPath {
975 if c.linker != nil {
976 return c.linker.coverageOutputFilePath()
977 }
978 return android.OptionalPath{}
979}
980
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900981func (c *Module) RelativeInstallPath() string {
982 if c.installer != nil {
983 return c.installer.relativeInstallPath()
984 }
985 return ""
986}
987
Jooyung Han344d5432019-08-23 11:17:39 +0900988func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900989 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900990}
991
Colin Cross36242852017-06-23 15:06:31 -0700992func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700993 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800994 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700995 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800996 }
997 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700998 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800999 }
1000 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -07001001 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001002 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001003 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -07001004 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -07001005 }
Colin Cross16b23492016-01-06 14:41:07 -08001006 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -07001007 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -08001008 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001009 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -07001010 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001011 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001012 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -07001013 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001014 }
Justin Yun8effde42017-06-23 19:24:43 +09001015 if c.vndkdep != nil {
1016 c.AddProperties(c.vndkdep.props()...)
1017 }
Stephen Craneba090d12017-05-09 15:44:35 -07001018 if c.lto != nil {
1019 c.AddProperties(c.lto.props()...)
1020 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001021 if c.pgo != nil {
1022 c.AddProperties(c.pgo.props()...)
1023 }
Colin Crossca860ac2016-01-04 14:34:37 -08001024 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -07001025 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001026 }
Colin Crossc472d572015-03-17 15:06:21 -07001027
Jiyong Park1613e552020-09-14 19:43:17 +09001028 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -07001029 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +09001030 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -07001031 })
Colin Cross36242852017-06-23 15:06:31 -07001032 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +09001033 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001034 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +09001035 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +09001036
Colin Cross36242852017-06-23 15:06:31 -07001037 return c
Colin Crossc472d572015-03-17 15:06:21 -07001038}
1039
Colin Crossb916a382016-07-29 17:28:03 -07001040// Returns true for dependency roots (binaries)
1041// TODO(ccross): also handle dlopenable libraries
1042func (c *Module) isDependencyRoot() bool {
1043 if root, ok := c.linker.(interface {
1044 isDependencyRoot() bool
1045 }); ok {
1046 return root.isDependencyRoot()
1047 }
1048 return false
1049}
1050
Justin Yun5f7f7e82019-11-18 19:52:14 +09001051// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
1052// "product" and "vendor" variant modules return true for this function.
1053// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
1054// "soc_specific: true" and more vendor installed modules are included here.
Justin Yun63e9ec72020-10-29 16:49:43 +09001055// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "product_available: true" or
Justin Yun5f7f7e82019-11-18 19:52:14 +09001056// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -07001057func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001058 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001059}
1060
Colin Crossc511bc52020-04-07 16:50:32 +00001061func (c *Module) canUseSdk() bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001062 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
Colin Crossc511bc52020-04-07 16:50:32 +00001063}
1064
1065func (c *Module) UseSdk() bool {
1066 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001067 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001068 }
1069 return false
1070}
1071
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001072func (c *Module) isCoverageVariant() bool {
1073 return c.coverage.Properties.IsCoverageVariant
1074}
1075
Colin Cross95f1ca02020-10-29 20:47:22 -07001076func (c *Module) IsNdk(config android.Config) bool {
1077 return inList(c.BaseModuleName(), *getNDKKnownLibs(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001078}
1079
Colin Cross127bb8b2020-12-16 16:46:01 -08001080// isLLndk returns true for both LLNDK (public) and LLNDK-private libs.
1081func (c *Module) IsLlndk() bool {
1082 return c.VendorProperties.IsLLNDK
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001083}
1084
Colin Cross127bb8b2020-12-16 16:46:01 -08001085// IsLlndkPublic returns true only for LLNDK (public) libs.
1086func (c *Module) IsLlndkPublic() bool {
Colin Cross78212242021-01-06 14:51:30 -08001087 return c.VendorProperties.IsLLNDK && !c.VendorProperties.IsVNDKPrivate
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001088}
1089
Colin Cross127bb8b2020-12-16 16:46:01 -08001090// isImplementationForLLNDKPublic returns true for any variant of a cc_library that has LLNDK stubs
1091// and does not set llndk.vendor_available: false.
1092func (c *Module) isImplementationForLLNDKPublic() bool {
1093 library, _ := c.library.(*libraryDecorator)
1094 return library != nil && library.hasLLNDKStubs() &&
Justin Yunc0d8c492021-01-07 17:45:31 +09001095 (!Bool(library.Properties.Llndk.Private) ||
Colin Cross127bb8b2020-12-16 16:46:01 -08001096 // TODO(b/170784825): until the LLNDK properties are moved into the cc_library,
1097 // the non-Vendor variants of the cc_library don't know if the corresponding
Justin Yunc0d8c492021-01-07 17:45:31 +09001098 // llndk_library set private: true. Since libft2 is the only private LLNDK
1099 // library, hardcode it during the transition.
Colin Cross127bb8b2020-12-16 16:46:01 -08001100 c.BaseModuleName() != "libft2")
1101}
1102
Justin Yunfd9e8042020-12-23 18:23:14 +09001103// Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Colin Cross127bb8b2020-12-16 16:46:01 -08001104func (c *Module) IsVndkPrivate() bool {
Justin Yunfd9e8042020-12-23 18:23:14 +09001105 // Check if VNDK-core-private or VNDK-SP-private
1106 if c.IsVndk() {
Justin Yunc0d8c492021-01-07 17:45:31 +09001107 return Bool(c.vndkdep.Properties.Vndk.Private)
Justin Yunfd9e8042020-12-23 18:23:14 +09001108 }
1109
1110 // Check if LLNDK-private
1111 if library, ok := c.library.(*libraryDecorator); ok && c.IsLlndk() {
Justin Yunc0d8c492021-01-07 17:45:31 +09001112 return Bool(library.Properties.Llndk.Private)
Justin Yunfd9e8042020-12-23 18:23:14 +09001113 }
1114
1115 return false
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001116}
1117
Ivan Lozano52767be2019-10-18 14:49:46 -07001118func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001119 if vndkdep := c.vndkdep; vndkdep != nil {
1120 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001121 }
1122 return false
1123}
1124
Yi Kong7e53c572018-02-14 18:16:12 +08001125func (c *Module) isPgoCompile() bool {
1126 if pgo := c.pgo; pgo != nil {
1127 return pgo.Properties.PgoCompile
1128 }
1129 return false
1130}
1131
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001132func (c *Module) isNDKStubLibrary() bool {
1133 if _, ok := c.compiler.(*stubDecorator); ok {
1134 return true
1135 }
1136 return false
1137}
1138
Logan Chienf3511742017-10-31 18:04:35 +08001139func (c *Module) isVndkSp() bool {
1140 if vndkdep := c.vndkdep; vndkdep != nil {
1141 return vndkdep.isVndkSp()
1142 }
1143 return false
1144}
1145
Ivan Lozanof9e21722020-12-02 09:00:51 -05001146func (c *Module) IsVndkExt() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001147 if vndkdep := c.vndkdep; vndkdep != nil {
1148 return vndkdep.isVndkExt()
1149 }
1150 return false
1151}
1152
Ivan Lozano52767be2019-10-18 14:49:46 -07001153func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001154 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001155}
1156
Logan Chienf3511742017-10-31 18:04:35 +08001157func (c *Module) getVndkExtendsModuleName() string {
1158 if vndkdep := c.vndkdep; vndkdep != nil {
1159 return vndkdep.getVndkExtendsModuleName()
1160 }
1161 return ""
1162}
1163
Jiyong Park25fc6a92018-11-18 18:02:45 +09001164func (c *Module) IsStubs() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001165 if lib := c.library; lib != nil {
1166 return lib.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001167 }
1168 return false
1169}
1170
1171func (c *Module) HasStubsVariants() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001172 if lib := c.library; lib != nil {
1173 return lib.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001174 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001175 return false
1176}
1177
Colin Cross0477b422020-10-13 18:43:54 -07001178// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
1179// the implementation. If it is an implementation library it returns its own name.
1180func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
1181 name := ctx.OtherModuleName(c)
1182 if versioned, ok := c.linker.(versionedInterface); ok {
1183 name = versioned.implementationModuleName(name)
1184 }
1185 return name
1186}
1187
Martin Stjernholm2856c662020-12-02 15:03:42 +00001188// Similar to ImplementationModuleName, but uses the Make variant of the module
1189// name as base name, for use in AndroidMk output. E.g. for a prebuilt module
1190// where the Soong name is prebuilt_foo, this returns foo (which works in Make
1191// under the premise that the prebuilt module overrides its source counterpart
1192// if it is exposed to Make).
1193func (c *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string {
1194 name := c.BaseModuleName()
1195 if versioned, ok := c.linker.(versionedInterface); ok {
1196 name = versioned.implementationModuleName(name)
1197 }
1198 return name
1199}
1200
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001201func (c *Module) bootstrap() bool {
1202 return Bool(c.Properties.Bootstrap)
1203}
1204
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001205func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001206 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1207 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1208 return false
1209 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001210 return c.linker != nil && c.linker.nativeCoverage()
1211}
1212
Inseob Kim8471cda2019-11-15 09:59:12 +09001213func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001214 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1215 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001216 }
1217 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001218}
1219
Bill Peckham945441c2020-08-31 16:07:58 -07001220func (c *Module) ExcludeFromVendorSnapshot() bool {
1221 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1222}
1223
Jose Galmesf7294582020-11-13 12:07:36 -08001224func (c *Module) ExcludeFromRecoverySnapshot() bool {
1225 return Bool(c.Properties.Exclude_from_recovery_snapshot)
1226}
1227
Jiyong Parkf1194352019-02-25 11:05:47 +09001228func isBionic(name string) bool {
1229 switch name {
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09001230 case "libc", "libm", "libdl", "libdl_android", "linker", "linkerconfig":
Jiyong Parkf1194352019-02-25 11:05:47 +09001231 return true
1232 }
1233 return false
1234}
1235
Martin Stjernholm279de572019-09-10 23:18:20 +01001236func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001237 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001238 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001239 }
1240 return isBionic(name)
1241}
1242
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001243func (c *Module) XrefCcFiles() android.Paths {
1244 return c.kytheFiles
1245}
1246
Colin Crossca860ac2016-01-04 14:34:37 -08001247type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001248 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001249 moduleContextImpl
1250}
1251
Colin Cross37047f12016-12-13 17:06:13 -08001252type depsContext struct {
1253 android.BottomUpMutatorContext
1254 moduleContextImpl
1255}
1256
Colin Crossca860ac2016-01-04 14:34:37 -08001257type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001258 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001259 moduleContextImpl
1260}
1261
1262type moduleContextImpl struct {
1263 mod *Module
1264 ctx BaseModuleContext
1265}
1266
Colin Crossb98c8b02016-07-29 13:44:28 -07001267func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001268 return ctx.mod.toolchain(ctx.ctx)
1269}
1270
1271func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001272 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001273}
1274
1275func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001276 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001277}
1278
Jiyong Park1d1119f2019-07-29 21:27:18 +09001279func (ctx *moduleContextImpl) header() bool {
1280 return ctx.mod.header()
1281}
1282
Inseob Kim7f283f42020-06-01 21:53:49 +09001283func (ctx *moduleContextImpl) binary() bool {
1284 return ctx.mod.binary()
1285}
1286
Inseob Kim1042d292020-06-01 23:23:05 +09001287func (ctx *moduleContextImpl) object() bool {
1288 return ctx.mod.object()
1289}
1290
Jooyung Hanccce2f22020-03-07 03:45:53 +09001291func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001292 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001293}
1294
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001295func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001296 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001297}
1298
1299func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001300 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001301 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001302 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001303 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001304 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001305 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001306 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001307 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001308 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001309 }
1310 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001311}
1312
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001313func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001314 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001315}
Justin Yun8effde42017-06-23 19:24:43 +09001316
Colin Cross95f1ca02020-10-29 20:47:22 -07001317func (ctx *moduleContextImpl) isNdk(config android.Config) bool {
1318 return ctx.mod.IsNdk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001319}
1320
Colin Cross127bb8b2020-12-16 16:46:01 -08001321func (ctx *moduleContextImpl) IsLlndk() bool {
1322 return ctx.mod.IsLlndk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001323}
1324
Colin Cross127bb8b2020-12-16 16:46:01 -08001325func (ctx *moduleContextImpl) IsLlndkPublic() bool {
1326 return ctx.mod.IsLlndkPublic()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001327}
1328
Colin Cross127bb8b2020-12-16 16:46:01 -08001329func (ctx *moduleContextImpl) isImplementationForLLNDKPublic() bool {
1330 return ctx.mod.isImplementationForLLNDKPublic()
1331}
1332
1333func (ctx *moduleContextImpl) IsVndkPrivate() bool {
1334 return ctx.mod.IsVndkPrivate()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001335}
1336
Logan Chienf3511742017-10-31 18:04:35 +08001337func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001338 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001339}
1340
Yi Kong7e53c572018-02-14 18:16:12 +08001341func (ctx *moduleContextImpl) isPgoCompile() bool {
1342 return ctx.mod.isPgoCompile()
1343}
1344
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001345func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1346 return ctx.mod.isNDKStubLibrary()
1347}
1348
Justin Yun8effde42017-06-23 19:24:43 +09001349func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001350 return ctx.mod.isVndkSp()
1351}
1352
Ivan Lozanof9e21722020-12-02 09:00:51 -05001353func (ctx *moduleContextImpl) IsVndkExt() bool {
1354 return ctx.mod.IsVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001355}
1356
Vic Yangefd249e2018-11-12 20:19:56 -08001357func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001358 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001359}
1360
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001361func (ctx *moduleContextImpl) selectedStl() string {
1362 if stl := ctx.mod.stl; stl != nil {
1363 return stl.Properties.SelectedStl
1364 }
1365 return ""
1366}
1367
Ivan Lozanobd721262018-11-27 14:33:03 -08001368func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1369 return ctx.mod.linker.useClangLld(actx)
1370}
1371
Colin Crossce75d2c2016-10-06 16:12:58 -07001372func (ctx *moduleContextImpl) baseModuleName() string {
1373 return ctx.mod.ModuleBase.BaseModuleName()
1374}
1375
Logan Chienf3511742017-10-31 18:04:35 +08001376func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1377 return ctx.mod.getVndkExtendsModuleName()
1378}
1379
Logan Chiene274fc92019-12-03 11:18:32 -08001380func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Cross56a83212020-09-15 18:30:11 -07001381 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001382}
1383
Colin Crosse07f2312020-08-13 11:24:56 -07001384func (ctx *moduleContextImpl) apexVariationName() string {
Colin Cross56a83212020-09-15 18:30:11 -07001385 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001386}
1387
Dan Albertc8060532020-07-22 22:32:17 -07001388func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001389 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001390}
1391
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001392func (ctx *moduleContextImpl) bootstrap() bool {
1393 return ctx.mod.bootstrap()
1394}
1395
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001396func (ctx *moduleContextImpl) nativeCoverage() bool {
1397 return ctx.mod.nativeCoverage()
1398}
1399
Colin Cross56a83212020-09-15 18:30:11 -07001400func (ctx *moduleContextImpl) directlyInAnyApex() bool {
1401 return ctx.mod.DirectlyInAnyApex()
1402}
1403
Colin Cross95b07f22020-12-16 11:06:50 -08001404func (ctx *moduleContextImpl) isPreventInstall() bool {
1405 return ctx.mod.Properties.PreventInstall
1406}
1407
Colin Cross635c3b02016-05-18 15:37:25 -07001408func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001409 return &Module{
1410 hod: hod,
1411 multilib: multilib,
1412 }
1413}
1414
Colin Cross635c3b02016-05-18 15:37:25 -07001415func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001416 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001417 module.features = []feature{
1418 &tidyFeature{},
1419 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001420 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001421 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001422 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001423 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001424 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001425 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001426 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001427 return module
1428}
1429
Colin Crossce75d2c2016-10-06 16:12:58 -07001430func (c *Module) Prebuilt() *android.Prebuilt {
1431 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1432 return p.prebuilt()
1433 }
1434 return nil
1435}
1436
1437func (c *Module) Name() string {
1438 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001439 if p, ok := c.linker.(interface {
1440 Name(string) string
1441 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001442 name = p.Name(name)
1443 }
1444 return name
1445}
1446
Alex Light3d673592019-01-18 14:37:31 -08001447func (c *Module) Symlinks() []string {
1448 if p, ok := c.installer.(interface {
1449 symlinkList() []string
1450 }); ok {
1451 return p.symlinkList()
1452 }
1453 return nil
1454}
1455
Roland Levillainf89cd092019-07-29 16:22:59 +01001456func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1457 test, ok := c.linker.(testPerSrc)
1458 return ok && test.isAllTestsVariation()
1459}
1460
Chris Parsons216e10a2020-07-09 17:12:52 -04001461func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001462 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001463 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001464 }); ok {
1465 return p.dataPaths()
1466 }
1467 return nil
1468}
1469
Justin Yun5f7f7e82019-11-18 19:52:14 +09001470func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1471 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1472 // "current", it will append the VNDK version to the name suffix.
1473 var vndkVersion string
1474 var nameSuffix string
Ivan Lozanof9e21722020-12-02 09:00:51 -05001475 if c.InProduct() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001476 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1477 nameSuffix = productSuffix
1478 } else {
1479 vndkVersion = ctx.DeviceConfig().VndkVersion()
1480 nameSuffix = vendorSuffix
1481 }
1482 if vndkVersion == "current" {
1483 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1484 }
Colin Cross127bb8b2020-12-16 16:46:01 -08001485 if c.Properties.VndkVersion != vndkVersion && c.Properties.VndkVersion != "" {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001486 // add version suffix only if the module is using different vndk version than the
1487 // version in product or vendor partition.
1488 nameSuffix += "." + c.Properties.VndkVersion
1489 }
1490 return nameSuffix
1491}
1492
Colin Cross635c3b02016-05-18 15:37:25 -07001493func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001494 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001495 //
1496 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1497 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1498 // module and return early, as this module does not produce an output file per se.
1499 if c.IsTestPerSrcAllTestsVariation() {
1500 c.outputFile = android.OptionalPath{}
1501 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001502 }
1503
Colin Cross56a83212020-09-15 18:30:11 -07001504 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1505 if !apexInfo.IsForPlatform() {
1506 c.hideApexVariantFromMake = true
1507 }
1508
Ivan Lozanof9e21722020-12-02 09:00:51 -05001509 c.makeLinkType = GetMakeLinkType(actx, c)
Inseob Kim9516ee92019-05-09 10:56:13 +09001510
Inseob Kim64c43952019-08-26 16:52:35 +09001511 c.Properties.SubName = ""
1512
1513 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1514 c.Properties.SubName += nativeBridgeSuffix
1515 }
1516
Colin Cross127bb8b2020-12-16 16:46:01 -08001517 llndk := c.IsLlndk()
Justin Yun5f7f7e82019-11-18 19:52:14 +09001518 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
Justin Yun63e9ec72020-10-29 16:49:43 +09001519 if llndk || llndkHeader || (c.UseVndk() && c.HasNonSystemVariants()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001520 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1521 // added for product variant only when we have vendor and product variants with core
1522 // variant. The suffix is not added for vendor-only or product-only module.
1523 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1524 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001525 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1526 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1527 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001528 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1529 c.Properties.SubName += ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001530 } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
1531 c.Properties.SubName += vendorRamdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001532 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001533 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001534 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001535 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001536 if c.SplitPerApiLevel() {
1537 c.Properties.SubName += "." + c.SdkVersion()
1538 }
Inseob Kim64c43952019-08-26 16:52:35 +09001539 }
1540
Colin Crossca860ac2016-01-04 14:34:37 -08001541 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001542 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001543 moduleContextImpl: moduleContextImpl{
1544 mod: c,
1545 },
1546 }
1547 ctx.ctx = ctx
1548
Colin Crossf18e1102017-11-16 14:33:08 -08001549 deps := c.depsToPaths(ctx)
1550 if ctx.Failed() {
1551 return
1552 }
1553
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001554 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1555 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1556 }
1557
Colin Crossca860ac2016-01-04 14:34:37 -08001558 flags := Flags{
1559 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001560 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001561 }
Colin Crossca860ac2016-01-04 14:34:37 -08001562 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001563 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001564 }
1565 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001566 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001567 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001568 if c.stl != nil {
1569 flags = c.stl.flags(ctx, flags)
1570 }
Colin Cross16b23492016-01-06 14:41:07 -08001571 if c.sanitize != nil {
1572 flags = c.sanitize.flags(ctx, flags)
1573 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001574 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001575 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001576 }
Stephen Craneba090d12017-05-09 15:44:35 -07001577 if c.lto != nil {
1578 flags = c.lto.flags(ctx, flags)
1579 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001580 if c.pgo != nil {
1581 flags = c.pgo.flags(ctx, flags)
1582 }
Colin Crossca860ac2016-01-04 14:34:37 -08001583 for _, feature := range c.features {
1584 flags = feature.flags(ctx, flags)
1585 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001586 if ctx.Failed() {
1587 return
1588 }
1589
Colin Cross4af21ed2019-11-04 09:37:55 -08001590 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1591 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1592 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001593
Colin Cross4af21ed2019-11-04 09:37:55 -08001594 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001595
1596 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001597 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001598 }
1599 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001600 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001601 }
1602
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001603 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001604 // We need access to all the flags seen by a source file.
1605 if c.sabi != nil {
1606 flags = c.sabi.flags(ctx, flags)
1607 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001608
Colin Cross4af21ed2019-11-04 09:37:55 -08001609 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001610
Colin Crossca860ac2016-01-04 14:34:37 -08001611 // Optimization to reduce size of build.ninja
1612 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001613 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1614 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1615 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1616 flags.Local.CFlags = []string{"$cflags"}
1617 flags.Local.CppFlags = []string{"$cppflags"}
1618 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001619
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001620 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001621 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001622 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001623 if ctx.Failed() {
1624 return
1625 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001626 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001627 }
1628
Colin Crossca860ac2016-01-04 14:34:37 -08001629 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001630 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001631 if ctx.Failed() {
1632 return
1633 }
Colin Cross635c3b02016-05-18 15:37:25 -07001634 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001635
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09001636 // If a lib is directly included in any of the APEXes or is not available to the
1637 // platform (which is often the case when the stub is provided as a prebuilt),
1638 // unhide the stubs variant having the latest version gets visible to make. In
1639 // addition, the non-stubs variant is renamed to <libname>.bootstrap. This is to
1640 // force anything in the make world to link against the stubs library. (unless it
1641 // is explicitly referenced via .bootstrap suffix or the module is marked with
1642 // 'bootstrap: true').
1643 if c.HasStubsVariants() && c.NotInPlatform() && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001644 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001645 c.IsStubs() && !c.InVendorRamdisk() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001646 c.Properties.HideFromMake = false // unhide
1647 // Note: this is still non-installable
1648 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001649
Jose Galmes6f843bc2020-12-11 13:36:29 -08001650 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
1651 // RECOVERY_SNAPSHOT_VERSION is current.
1652 if i, ok := c.linker.(snapshotLibraryInterface); ok {
Inseob Kimde5744a2020-12-02 13:14:28 +09001653 if shouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001654 i.collectHeadersForSnapshot(ctx)
1655 }
1656 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001657 }
Colin Cross5049f022015-03-18 13:28:46 -07001658
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001659 if !proptools.BoolDefault(c.Properties.Installable, true) {
1660 // If the module has been specifically configure to not be installed then
1661 // hide from make as otherwise it will break when running inside make
1662 // as the output path to install will not be specified. Not all uninstallable
1663 // modules can be hidden from make as some are needed for resolving make side
1664 // dependencies.
1665 c.HideFromMake()
1666 } else if !c.installable(apexInfo) {
1667 c.SkipInstall()
1668 }
1669
1670 // Still call c.installer.install though, the installs will be stored as PackageSpecs
1671 // to allow using the outputs in a genrule.
1672 if c.installer != nil && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001673 c.installer.install(ctx, c.outputFile.Path())
1674 if ctx.Failed() {
1675 return
Colin Crossca860ac2016-01-04 14:34:37 -08001676 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001677 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001678}
1679
Colin Cross0ea8ba82019-06-06 14:33:29 -07001680func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001681 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001682 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001683 }
Colin Crossca860ac2016-01-04 14:34:37 -08001684 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001685}
1686
Colin Crossca860ac2016-01-04 14:34:37 -08001687func (c *Module) begin(ctx BaseModuleContext) {
1688 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001689 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001690 }
Colin Crossca860ac2016-01-04 14:34:37 -08001691 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001692 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001693 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001694 if c.stl != nil {
1695 c.stl.begin(ctx)
1696 }
Colin Cross16b23492016-01-06 14:41:07 -08001697 if c.sanitize != nil {
1698 c.sanitize.begin(ctx)
1699 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001700 if c.coverage != nil {
1701 c.coverage.begin(ctx)
1702 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001703 if c.sabi != nil {
1704 c.sabi.begin(ctx)
1705 }
Justin Yun8effde42017-06-23 19:24:43 +09001706 if c.vndkdep != nil {
1707 c.vndkdep.begin(ctx)
1708 }
Stephen Craneba090d12017-05-09 15:44:35 -07001709 if c.lto != nil {
1710 c.lto.begin(ctx)
1711 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001712 if c.pgo != nil {
1713 c.pgo.begin(ctx)
1714 }
Colin Crossca860ac2016-01-04 14:34:37 -08001715 for _, feature := range c.features {
1716 feature.begin(ctx)
1717 }
Dan Albert92fe7402020-07-15 13:33:30 -07001718 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001719 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001720 if err != nil {
1721 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001722 c.Properties.Sdk_version = nil
1723 } else {
1724 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001725 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001726 }
Colin Crossca860ac2016-01-04 14:34:37 -08001727}
1728
Colin Cross37047f12016-12-13 17:06:13 -08001729func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001730 deps := Deps{}
1731
1732 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001733 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001734 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001735 // Add the PGO dependency (the clang_rt.profile runtime library), which
1736 // sometimes depends on symbols from libgcc, before libgcc gets added
1737 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001738 if c.pgo != nil {
1739 deps = c.pgo.deps(ctx, deps)
1740 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001741 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001742 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001743 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001744 if c.stl != nil {
1745 deps = c.stl.deps(ctx, deps)
1746 }
Colin Cross16b23492016-01-06 14:41:07 -08001747 if c.sanitize != nil {
1748 deps = c.sanitize.deps(ctx, deps)
1749 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001750 if c.coverage != nil {
1751 deps = c.coverage.deps(ctx, deps)
1752 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001753 if c.sabi != nil {
1754 deps = c.sabi.deps(ctx, deps)
1755 }
Justin Yun8effde42017-06-23 19:24:43 +09001756 if c.vndkdep != nil {
1757 deps = c.vndkdep.deps(ctx, deps)
1758 }
Stephen Craneba090d12017-05-09 15:44:35 -07001759 if c.lto != nil {
1760 deps = c.lto.deps(ctx, deps)
1761 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001762 for _, feature := range c.features {
1763 deps = feature.deps(ctx, deps)
1764 }
1765
Colin Crossb6715442017-10-24 11:13:31 -07001766 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1767 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1768 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1769 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1770 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1771 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001772 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001773
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001774 for _, lib := range deps.ReexportSharedLibHeaders {
1775 if !inList(lib, deps.SharedLibs) {
1776 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1777 }
1778 }
1779
1780 for _, lib := range deps.ReexportStaticLibHeaders {
1781 if !inList(lib, deps.StaticLibs) {
1782 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1783 }
1784 }
1785
Colin Cross5950f382016-12-13 12:50:57 -08001786 for _, lib := range deps.ReexportHeaderLibHeaders {
1787 if !inList(lib, deps.HeaderLibs) {
1788 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1789 }
1790 }
1791
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001792 for _, gen := range deps.ReexportGeneratedHeaders {
1793 if !inList(gen, deps.GeneratedHeaders) {
1794 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1795 }
1796 }
1797
Colin Crossc99deeb2016-04-11 15:06:20 -07001798 return deps
1799}
1800
Dan Albert7e9d2952016-08-04 13:02:36 -07001801func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001802 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001803 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001804 moduleContextImpl: moduleContextImpl{
1805 mod: c,
1806 },
1807 }
1808 ctx.ctx = ctx
1809
Colin Crossca860ac2016-01-04 14:34:37 -08001810 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001811}
1812
Jiyong Park7ed9de32018-10-15 22:25:07 +09001813// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001814func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001815 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1816 version := name[sharp+1:]
1817 libname := name[:sharp]
1818 return libname, version
1819 }
1820 return name, ""
1821}
1822
Dan Albert92fe7402020-07-15 13:33:30 -07001823func GetCrtVariations(ctx android.BottomUpMutatorContext,
1824 m LinkableInterface) []blueprint.Variation {
1825 if ctx.Os() != android.Android {
1826 return nil
1827 }
1828 if m.UseSdk() {
1829 return []blueprint.Variation{
1830 {Mutator: "sdk", Variation: "sdk"},
Colin Crossbbc941b2020-09-30 12:27:01 -07001831 {Mutator: "version", Variation: m.SdkVersion()},
Dan Albert92fe7402020-07-15 13:33:30 -07001832 }
1833 }
1834 return []blueprint.Variation{
1835 {Mutator: "sdk", Variation: ""},
1836 }
1837}
1838
Colin Crosse7257d22020-09-24 09:56:18 -07001839func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1840 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1841
1842 variations = append([]blueprint.Variation(nil), variations...)
1843
Colin Cross3146c5c2020-09-30 15:34:40 -07001844 if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001845 // Version is explicitly specified. i.e. libFoo#30
1846 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1847 depTag.explicitlyVersioned = true
1848 }
Colin Crosse7257d22020-09-24 09:56:18 -07001849
Colin Cross0de8a1e2020-09-18 14:15:30 -07001850 if far {
1851 ctx.AddFarVariationDependencies(variations, depTag, name)
1852 } else {
1853 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07001854 }
1855}
1856
Colin Cross1e676be2016-10-12 14:38:15 -07001857func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001858 if !c.Enabled() {
1859 return
1860 }
1861
Colin Cross37047f12016-12-13 17:06:13 -08001862 ctx := &depsContext{
1863 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001864 moduleContextImpl: moduleContextImpl{
1865 mod: c,
1866 },
1867 }
1868 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001869
Colin Crossc99deeb2016-04-11 15:06:20 -07001870 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001871
Yo Chiang219968c2020-09-22 18:45:04 +08001872 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1873
Dan Albert914449f2016-06-17 16:45:24 -07001874 variantNdkLibs := []string{}
1875 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001876 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001877 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001878 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001879 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001880 // 1. Name of an NDK library that refers to a prebuilt module.
1881 // For each of these, it adds the name of the prebuilt module (which will be in
1882 // prebuilts/ndk) to the list of nonvariant libs.
1883 // 2. Name of an NDK library that refers to an ndk_library module.
1884 // For each of these, it adds the name of the ndk_library module to the list of
1885 // variant libs.
1886 // 3. Anything else (so anything that isn't an NDK library).
1887 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001888 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001889 // The caller can then know to add the variantLibs dependencies differently from the
1890 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001891
Inseob Kim9516ee92019-05-09 10:56:13 +09001892 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001893 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
Jose Galmes6f843bc2020-12-11 13:36:29 -08001894 recoverySnapshotSharedLibs := recoverySnapshotSharedLibs(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001895
1896 rewriteVendorLibs := func(lib string) string {
Inseob Kimeec88e12020-01-22 11:11:29 +09001897 // only modules with BOARD_VNDK_VERSION uses snapshot.
1898 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1899 return lib
1900 }
1901
1902 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1903 return snapshot
1904 }
1905
1906 return lib
1907 }
1908
1909 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001910 variantLibs = []string{}
1911 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001912 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001913 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001914 name, _ := StubsLibNameAndVersion(entry)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001915 if c.InRecovery() {
1916 recoverySnapshotVersion :=
1917 actx.DeviceConfig().RecoverySnapshotVersion()
1918 if recoverySnapshotVersion == "current" ||
1919 recoverySnapshotVersion == "" {
1920 nonvariantLibs = append(nonvariantLibs, name)
1921 } else if snapshot, ok := recoverySnapshotSharedLibs.get(
1922 name, actx.Arch().ArchType); ok {
1923 nonvariantLibs = append(nonvariantLibs, snapshot)
1924 } else {
1925 nonvariantLibs = append(nonvariantLibs, name)
1926 }
1927 } else if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) {
Dan Albertde5aade2020-06-30 12:32:51 -07001928 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001929 } else if ctx.useVndk() {
1930 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001931 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001932 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001933 if actx.OtherModuleExists(vendorPublicLib) {
1934 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1935 } else {
1936 // This can happen if vendor_public_library module is defined in a
1937 // namespace that isn't visible to the current module. In that case,
1938 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001939 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001940 }
Dan Albert914449f2016-06-17 16:45:24 -07001941 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001942 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001943 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001944 }
1945 }
Dan Albert914449f2016-06-17 16:45:24 -07001946 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001947 }
1948
Inseob Kimeec88e12020-01-22 11:11:29 +09001949 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1950 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1951 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1952 if ctx.useVndk() {
1953 for idx, lib := range deps.RuntimeLibs {
1954 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1955 }
1956 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001957 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001958
Inseob Kimeec88e12020-01-22 11:11:29 +09001959 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1960 // only modules with BOARD_VNDK_VERSION uses snapshot.
1961 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1962 return lib
1963 }
1964
1965 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1966 return snapshot
1967 }
1968
1969 return lib
1970 }
1971
Jose Galmes6f843bc2020-12-11 13:36:29 -08001972 snapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
1973 snapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
1974 snapshotObjects := vendorSnapshotObjects(actx.Config())
1975
1976 if c.InRecovery() {
1977 rewriteSnapshotLibs = func(lib string, snapshotMap *snapshotMap) string {
1978 recoverySnapshotVersion :=
1979 actx.DeviceConfig().RecoverySnapshotVersion()
1980 if recoverySnapshotVersion == "current" ||
1981 recoverySnapshotVersion == "" {
1982 return lib
1983 } else if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1984 return snapshot
1985 }
1986
1987 return lib
1988 }
1989
1990 snapshotHeaderLibs = recoverySnapshotHeaderLibs(actx.Config())
1991 snapshotStaticLibs = recoverySnapshotStaticLibs(actx.Config())
1992 snapshotObjects = recoverySnapshotObjects(actx.Config())
1993 }
1994
Colin Cross32ec36c2016-12-15 07:39:51 -08001995 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001996 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001997 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001998 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001999 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002000
Jose Galmes6f843bc2020-12-11 13:36:29 -08002001 lib = rewriteSnapshotLibs(lib, snapshotHeaderLibs)
Inseob Kimeec88e12020-01-22 11:11:29 +09002002
Jiyong Park1ad8e162020-12-01 23:40:09 +09002003 if c.IsStubs() {
Colin Cross7228ecd2019-11-18 16:00:16 -08002004 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002005 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09002006 } else {
2007 actx.AddVariationDependencies(nil, depTag, lib)
2008 }
2009 }
2010
Inseob Kim07def122020-11-23 14:43:02 +09002011 // sysprop_library has to support both C++ and Java. So sysprop_library internally creates one
2012 // C++ implementation library and one Java implementation library. When a module links against
2013 // sysprop_library, the C++ implementation library has to be linked. syspropImplLibraries is a
2014 // map from sysprop_library to implementation library; it will be used in whole_static_libs,
2015 // static_libs, and shared_libs.
Inseob Kimc0907f12019-02-08 21:00:45 +09002016 syspropImplLibraries := syspropImplLibraries(actx.Config())
2017
Jiyong Park5d1598f2019-02-25 22:14:17 +09002018 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002019 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09002020 if impl, ok := syspropImplLibraries[lib]; ok {
2021 lib = impl
2022 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002023
Jose Galmes6f843bc2020-12-11 13:36:29 -08002024 lib = rewriteSnapshotLibs(lib, snapshotStaticLibs)
Inseob Kimeec88e12020-01-22 11:11:29 +09002025
Jiyong Park5d1598f2019-02-25 22:14:17 +09002026 actx.AddVariationDependencies([]blueprint.Variation{
2027 {Mutator: "link", Variation: "static"},
2028 }, depTag, lib)
2029 }
2030
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002031 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002032 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002033 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002034 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002035 }
Jiyong Parke3867542020-12-03 17:28:25 +09002036 if inList(lib, deps.ExcludeLibsForApex) {
2037 depTag.excludeInApex = true
2038 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002039
2040 if impl, ok := syspropImplLibraries[lib]; ok {
2041 lib = impl
2042 }
2043
Jose Galmes6f843bc2020-12-11 13:36:29 -08002044 lib = rewriteSnapshotLibs(lib, snapshotStaticLibs)
Inseob Kimeec88e12020-01-22 11:11:29 +09002045
Dan Willemsen59339a22018-07-22 21:18:45 -07002046 actx.AddVariationDependencies([]blueprint.Variation{
2047 {Mutator: "link", Variation: "static"},
2048 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002049 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002050
Jooyung Han75568392020-03-20 04:29:24 +09002051 // staticUnwinderDep is treated as staticDep for Q apexes
2052 // so that native libraries/binaries are linked with static unwinder
2053 // because Q libc doesn't have unwinder APIs
2054 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002055 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002056 actx.AddVariationDependencies([]blueprint.Variation{
2057 {Mutator: "link", Variation: "static"},
Jose Galmes6f843bc2020-12-11 13:36:29 -08002058 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), snapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002059 }
2060
Inseob Kimeec88e12020-01-22 11:11:29 +09002061 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002062 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002063 actx.AddVariationDependencies([]blueprint.Variation{
2064 {Mutator: "link", Variation: "static"},
Jose Galmes6f843bc2020-12-11 13:36:29 -08002065 }, depTag, rewriteSnapshotLibs(lib, snapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002066 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002067
Jiyong Park7ed9de32018-10-15 22:25:07 +09002068 // shared lib names without the #version suffix
2069 var sharedLibNames []string
2070
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002071 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002072 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002073 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002074 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002075 }
Jiyong Parke3867542020-12-03 17:28:25 +09002076 if inList(lib, deps.ExcludeLibsForApex) {
2077 depTag.excludeInApex = true
2078 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002079
2080 if impl, ok := syspropImplLibraries[lib]; ok {
2081 lib = impl
2082 }
2083
Jiyong Park73c54ee2019-10-22 20:31:18 +09002084 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002085 sharedLibNames = append(sharedLibNames, name)
2086
Colin Crosse7257d22020-09-24 09:56:18 -07002087 variations := []blueprint.Variation{
2088 {Mutator: "link", Variation: "shared"},
2089 }
2090 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002091 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002092
Jiyong Park7ed9de32018-10-15 22:25:07 +09002093 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002094 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002095 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2096 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2097 // linking against both the stubs lib and the non-stubs lib at the same time.
2098 continue
2099 }
Colin Cross6e511a92020-07-27 21:26:48 -07002100 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002101 variations := []blueprint.Variation{
2102 {Mutator: "link", Variation: "shared"},
2103 }
2104 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002105 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002106
Dan Willemsen59339a22018-07-22 21:18:45 -07002107 actx.AddVariationDependencies([]blueprint.Variation{
2108 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002109 }, dataLibDepTag, deps.DataLibs...)
2110
2111 actx.AddVariationDependencies([]blueprint.Variation{
2112 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002113 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002114
Colin Cross68861832016-07-08 10:41:41 -07002115 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002116
2117 for _, gen := range deps.GeneratedHeaders {
2118 depTag := genHeaderDepTag
2119 if inList(gen, deps.ReexportGeneratedHeaders) {
2120 depTag = genHeaderExportDepTag
2121 }
2122 actx.AddDependency(c, depTag, gen)
2123 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002124
Dan Albert92fe7402020-07-15 13:33:30 -07002125 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07002126 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002127 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002128 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
Jose Galmes6f843bc2020-12-11 13:36:29 -08002129 rewriteSnapshotLibs(deps.CrtBegin, snapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002130 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002131 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002132 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
Jose Galmes6f843bc2020-12-11 13:36:29 -08002133 rewriteSnapshotLibs(deps.CrtEnd, snapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002134 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002135 if deps.LinkerFlagsFile != "" {
2136 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2137 }
2138 if deps.DynamicLinker != "" {
2139 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002140 }
Dan Albert914449f2016-06-17 16:45:24 -07002141
2142 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002143
2144 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002145 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002146 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002147 {Mutator: "link", Variation: "shared"},
2148 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002149
2150 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002151 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002152 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002153 {Mutator: "link", Variation: "shared"},
2154 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002155
2156 if vndkdep := c.vndkdep; vndkdep != nil {
2157 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002158 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002159 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002160 {Mutator: "link", Variation: "shared"},
2161 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002162 }
2163 }
Colin Cross6362e272015-10-29 15:25:03 -07002164}
Colin Cross21b9a242015-03-24 14:15:58 -07002165
Colin Crosse40b4ea2018-10-02 22:25:58 -07002166func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002167 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2168 c.beginMutator(ctx)
2169 }
2170}
2171
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002172// Whether a module can link to another module, taking into
2173// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002174func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002175 tag blueprint.DependencyTag) {
2176
2177 switch t := tag.(type) {
2178 case dependencyTag:
2179 if t != vndkExtDepTag {
2180 return
2181 }
2182 case libraryDependencyTag:
2183 default:
2184 return
2185 }
2186
Ivan Lozanof9e21722020-12-02 09:00:51 -05002187 if from.Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002188 // Host code is not restricted
2189 return
2190 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002191
2192 // VNDK is cc.Module supported only for now.
2193 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Justin Yun63e9ec72020-10-29 16:49:43 +09002194 // Though allowed dependency is limited by the image mutator,
2195 // each vendor and product module needs to check link-type
2196 // for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 if ccTo, ok := to.(*Module); ok {
2198 if ccFrom.vndkdep != nil {
2199 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2200 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05002201 } else if linkableMod, ok := to.(LinkableInterface); ok {
2202 // Static libraries from other languages can be linked
2203 if !linkableMod.Static() {
2204 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
2205 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002206 } else {
2207 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002208 }
2209 return
2210 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002211 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002212 // Platform code can link to anything
2213 return
2214 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002215 if from.InRamdisk() {
2216 // Ramdisk code is not NDK
2217 return
2218 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002219 if from.InVendorRamdisk() {
2220 // Vendor ramdisk code is not NDK
2221 return
2222 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002223 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002224 // Recovery code is not NDK
2225 return
2226 }
Colin Cross31076b32020-10-23 17:22:06 -07002227 if c, ok := to.(*Module); ok {
2228 if c.ToolchainLibrary() {
2229 // These are always allowed
2230 return
2231 }
2232 if c.NdkPrebuiltStl() {
2233 // These are allowed, but they don't set sdk_version
2234 return
2235 }
2236 if c.StubDecorator() {
2237 // These aren't real libraries, but are the stub shared libraries that are included in
2238 // the NDK.
2239 return
2240 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002241 }
Logan Chien834b9a62019-01-14 15:39:03 +08002242
Ivan Lozano52767be2019-10-18 14:49:46 -07002243 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002244 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2245 // to link to libc++ (non-NDK and without sdk_version).
2246 return
2247 }
2248
Ivan Lozano52767be2019-10-18 14:49:46 -07002249 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002250 // NDK code linking to platform code is never okay.
2251 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002252 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002253 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002254 }
2255
2256 // At this point we know we have two NDK libraries, but we need to
2257 // check that we're not linking against anything built against a higher
2258 // API level, as it is only valid to link against older or equivalent
2259 // APIs.
2260
Inseob Kim01a28722018-04-11 09:48:45 +09002261 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002262 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002263 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002264 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002265 // Current can't be linked against by anything else.
2266 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002267 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002268 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002269 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002270 if err != nil {
2271 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002272 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002273 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002274 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002275 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002276 if err != nil {
2277 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002278 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002279 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002280 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002281
Inseob Kim01a28722018-04-11 09:48:45 +09002282 if toApi > fromApi {
2283 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002284 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002285 }
2286 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002287 }
Dan Albert202fe492017-12-15 13:56:59 -08002288
2289 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002290 fromStl := from.SelectedStl()
2291 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002292 if fromStl == "" || toStl == "" {
2293 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002294 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002295 // We can be permissive with the system "STL" since it is only the C++
2296 // ABI layer, but in the future we should make sure that everyone is
2297 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002298 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002299 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002300 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2301 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002302 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002303}
2304
Jooyung Han479ca172020-10-19 18:51:07 +09002305func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2306 if c, ok := ctx.Module().(*Module); ok {
2307 ctx.VisitDirectDeps(func(dep android.Module) {
2308 depTag := ctx.OtherModuleDependencyTag(dep)
2309 ccDep, ok := dep.(LinkableInterface)
2310 if ok {
2311 checkLinkType(ctx, c, ccDep, depTag)
2312 }
2313 })
2314 }
2315}
2316
Jiyong Park5fb8c102018-04-09 12:03:06 +09002317// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002318// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2319// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002320// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002321func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2322 check := func(child, parent android.Module) bool {
2323 to, ok := child.(*Module)
2324 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002325 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002326 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002327
Jooyung Hana70f0672019-01-18 15:20:43 +09002328 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2329 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002330 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002331
Jiyong Park1ad8e162020-12-01 23:40:09 +09002332 depTag := ctx.OtherModuleDependencyTag(child)
2333 if IsHeaderDepTag(depTag) {
2334 return false
2335 }
2336
Justin Yun63e9ec72020-10-29 16:49:43 +09002337 // Even if target lib has no vendor variant, keep checking dependency
2338 // graph in case it depends on vendor_available or product_available
2339 // but not double_loadable transtively.
2340 if !to.HasNonSystemVariants() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002341 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002342 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002343
Colin Cross127bb8b2020-12-16 16:46:01 -08002344 if to.isVndkSp() || to.IsLlndk() || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002345 return false
2346 }
2347
2348 var stringPath []string
2349 for _, m := range ctx.GetWalkPath() {
2350 stringPath = append(stringPath, m.Name())
2351 }
2352 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2353 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2354 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2355 return false
2356 }
2357 if module, ok := ctx.Module().(*Module); ok {
2358 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Colin Cross127bb8b2020-12-16 16:46:01 -08002359 if lib.hasLLNDKStubs() || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002360 ctx.WalkDeps(check)
2361 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002362 }
2363 }
2364}
2365
Colin Cross0de8a1e2020-09-18 14:15:30 -07002366// Returns the highest version which is <= maxSdkVersion.
2367// For example, with maxSdkVersion is 10 and versionList is [9,11]
2368// it returns 9 as string. The list of stubs must be in order from
2369// oldest to newest.
Chris Parsons3c27ca32020-11-20 12:42:07 -05002370func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedStubLibrary,
2371 maxSdkVersion android.ApiLevel) (SharedStubLibrary, error) {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002372
2373 for i := range stubsInfo {
2374 stubInfo := stubsInfo[len(stubsInfo)-i-1]
2375 var ver android.ApiLevel
2376 if stubInfo.Version == "" {
2377 ver = android.FutureApiLevel
2378 } else {
2379 var err error
2380 ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
2381 if err != nil {
Chris Parsons3c27ca32020-11-20 12:42:07 -05002382 return SharedStubLibrary{}, err
Colin Cross0de8a1e2020-09-18 14:15:30 -07002383 }
2384 }
2385 if ver.LessThanOrEqualTo(maxSdkVersion) {
2386 return stubInfo, nil
2387 }
2388 }
2389 var versionList []string
2390 for _, stubInfo := range stubsInfo {
2391 versionList = append(versionList, stubInfo.Version)
2392 }
Chris Parsons3c27ca32020-11-20 12:42:07 -05002393 return SharedStubLibrary{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002394}
2395
Colin Crossc99deeb2016-04-11 15:06:20 -07002396// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002397func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002398 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002399
Colin Cross0de8a1e2020-09-18 14:15:30 -07002400 var directStaticDeps []StaticLibraryInfo
2401 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07002402
Colin Cross0de8a1e2020-09-18 14:15:30 -07002403 reexportExporter := func(exporter FlagExporterInfo) {
2404 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
2405 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
2406 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
2407 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
2408 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09002409 }
2410
Jooyung Hande34d232020-07-23 13:04:15 +09002411 // For the dependency from platform to apex, use the latest stubs
2412 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002413 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2414 if !apexInfo.IsForPlatform() {
2415 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002416 }
2417
2418 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2419 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2420 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2421 // (b/144430859)
2422 c.apexSdkVersion = android.FutureApiLevel
2423 }
2424
Colin Crossd11fcda2017-10-23 17:59:01 -07002425 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002426 depName := ctx.OtherModuleName(dep)
2427 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002428
Ivan Lozano52767be2019-10-18 14:49:46 -07002429 ccDep, ok := dep.(LinkableInterface)
2430 if !ok {
2431
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002432 // handling for a few module types that aren't cc Module but that are also supported
2433 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002434 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002435 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002436 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2437 genRule.GeneratedSourceFiles()...)
2438 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002439 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002440 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002441 // Support exported headers from a generated_sources dependency
2442 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002443 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002444 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002445 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002446 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002447 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002448 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002449 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002450 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002451 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2452 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002453 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002454 // 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 +09002455 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002456
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002457 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002458 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002459 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002460 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002461 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002462 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002463 files := genRule.GeneratedSourceFiles()
2464 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002465 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002466 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002467 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 -07002468 }
2469 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002470 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002471 }
Colin Crossca860ac2016-01-04 14:34:37 -08002472 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002473 return
2474 }
2475
Colin Crossfe17f6f2019-03-28 19:30:56 -07002476 if depTag == android.ProtoPluginDepTag {
2477 return
2478 }
2479
Colin Crossd11fcda2017-10-23 17:59:01 -07002480 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002481 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2482 return
2483 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002484 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002485 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2486 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002487 return
2488 }
2489
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002490 if depTag == reuseObjTag {
Colin Crossa717db72020-10-23 14:53:06 -07002491 // Skip reused objects for stub libraries, they use their own stub object file instead.
2492 // The reuseObjTag dependency still exists because the LinkageMutator runs before the
2493 // version mutator, so the stubs variant is created from the shared variant that
2494 // already has the reuseObjTag dependency on the static variant.
Colin Cross31076b32020-10-23 17:22:06 -07002495 if !c.library.buildStubs() {
Colin Crossa717db72020-10-23 14:53:06 -07002496 staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2497 objs := staticAnalogue.ReuseObjects
2498 depPaths.Objs = depPaths.Objs.Append(objs)
2499 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
2500 reexportExporter(depExporterInfo)
2501 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07002502 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09002503 }
2504
Colin Cross6e511a92020-07-27 21:26:48 -07002505 linkFile := ccDep.OutputFile()
2506
2507 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2508 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002509 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002510 return
2511 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002512
Jiyong Parke3867542020-12-03 17:28:25 +09002513 if !apexInfo.IsForPlatform() && libDepTag.excludeInApex {
2514 return
2515 }
2516
Colin Cross0de8a1e2020-09-18 14:15:30 -07002517 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
Colin Crossc99deeb2016-04-11 15:06:20 -07002518
Colin Cross6e511a92020-07-27 21:26:48 -07002519 var ptr *android.Paths
2520 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002521
Colin Cross6e511a92020-07-27 21:26:48 -07002522 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002523
Colin Cross6e511a92020-07-27 21:26:48 -07002524 switch {
2525 case libDepTag.header():
Colin Cross649d8172020-12-10 12:30:21 -08002526 if !ctx.OtherModuleHasProvider(dep, HeaderLibraryInfoProvider) {
2527 if !ctx.Config().AllowMissingDependencies() {
2528 ctx.ModuleErrorf("module %q is not a header library", depName)
2529 } else {
2530 ctx.AddMissingDependencies([]string{depName})
2531 }
2532 return
2533 }
Colin Cross6e511a92020-07-27 21:26:48 -07002534 case libDepTag.shared():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002535 if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
2536 if !ctx.Config().AllowMissingDependencies() {
2537 ctx.ModuleErrorf("module %q is not a shared library", depName)
2538 } else {
2539 ctx.AddMissingDependencies([]string{depName})
2540 }
2541 return
2542 }
Jiyong Parke3867542020-12-03 17:28:25 +09002543
Colin Cross0de8a1e2020-09-18 14:15:30 -07002544 sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
Chris Parsons3c27ca32020-11-20 12:42:07 -05002545 sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryStubsProvider).(SharedLibraryStubsInfo)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002546
Chris Parsons3c27ca32020-11-20 12:42:07 -05002547 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002548 useStubs := false
Colin Cross31076b32020-10-23 17:22:06 -07002549
2550 if lib := moduleLibraryInterface(dep); lib.buildStubs() && c.UseVndk() { // LLNDK
Colin Cross0de8a1e2020-09-18 14:15:30 -07002551 if !apexInfo.IsForPlatform() {
2552 // For platform libraries, use current version of LLNDK
2553 // If this is for use_vendor apex we will apply the same rules
2554 // of apex sdk enforcement below to choose right version.
2555 useStubs = true
2556 }
2557 } else if apexInfo.IsForPlatform() {
2558 // If not building for APEX, use stubs only when it is from
2559 // an APEX (and not from platform)
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002560 // However, for host, ramdisk, vendor_ramdisk, recovery or bootstrap modules,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002561 // always link to non-stub variant
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09002562 useStubs = dep.(android.ApexModule).NotInPlatform() && !c.bootstrap()
Colin Cross0de8a1e2020-09-18 14:15:30 -07002563 // Another exception: if this module is bundled with an APEX, then
2564 // it is linked with the non-stub variant of a module in the APEX
2565 // as if this is part of the APEX.
2566 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2567 for _, apexContents := range testFor.ApexContents {
2568 if apexContents.DirectlyInApex(depName) {
2569 useStubs = false
2570 break
2571 }
2572 }
2573 } else {
2574 // If building for APEX, use stubs when the parent is in any APEX that
2575 // the child is not in.
2576 useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
2577 }
2578
2579 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2580 if useStubs {
2581 sharedLibraryStubsInfo, err :=
Chris Parsons3c27ca32020-11-20 12:42:07 -05002582 c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedStubLibraries, c.apexSdkVersion)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002583 if err != nil {
2584 ctx.OtherModuleErrorf(dep, err.Error())
2585 return
2586 }
2587 sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
2588 depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
2589 }
2590 }
2591
Jiyong Park1ad8e162020-12-01 23:40:09 +09002592 // Stubs lib doesn't link to the shared lib dependencies. Don't set
2593 // linkFile, depFile, and ptr.
2594 if c.IsStubs() {
2595 break
2596 }
2597
Colin Cross0de8a1e2020-09-18 14:15:30 -07002598 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
2599 depFile = sharedLibraryInfo.TableOfContents
2600
Colin Cross6e511a92020-07-27 21:26:48 -07002601 ptr = &depPaths.SharedLibs
2602 switch libDepTag.Order {
2603 case earlyLibraryDependency:
2604 ptr = &depPaths.EarlySharedLibs
2605 depPtr = &depPaths.EarlySharedLibsDeps
2606 case normalLibraryDependency:
2607 ptr = &depPaths.SharedLibs
2608 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07002609 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002610 case lateLibraryDependency:
2611 ptr = &depPaths.LateSharedLibs
2612 depPtr = &depPaths.LateSharedLibsDeps
2613 default:
2614 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002615 }
Colin Cross6e511a92020-07-27 21:26:48 -07002616 case libDepTag.static():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002617 if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
2618 if !ctx.Config().AllowMissingDependencies() {
2619 ctx.ModuleErrorf("module %q is not a static library", depName)
2620 } else {
2621 ctx.AddMissingDependencies([]string{depName})
2622 }
2623 return
2624 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002625
2626 // Stubs lib doesn't link to the static lib dependencies. Don't set
2627 // linkFile, depFile, and ptr.
2628 if c.IsStubs() {
2629 break
2630 }
2631
Colin Cross0de8a1e2020-09-18 14:15:30 -07002632 staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2633 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
Colin Cross6e511a92020-07-27 21:26:48 -07002634 if libDepTag.wholeStatic {
2635 ptr = &depPaths.WholeStaticLibs
Colin Cross0de8a1e2020-09-18 14:15:30 -07002636 if len(staticLibraryInfo.Objects.objFiles) > 0 {
2637 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
Inseob Kimeec88e12020-01-22 11:11:29 +09002638 } else {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002639 // This case normally catches prebuilt static
2640 // libraries, but it can also occur when
2641 // AllowMissingDependencies is on and the
2642 // dependencies has no sources of its own
2643 // but has a whole_static_libs dependency
2644 // on a missing library. We want to depend
2645 // on the .a file so that there is something
2646 // in the dependency tree that contains the
2647 // error rule for the missing transitive
2648 // dependency.
2649 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002650 }
Colin Cross6e511a92020-07-27 21:26:48 -07002651 } else {
2652 switch libDepTag.Order {
2653 case earlyLibraryDependency:
2654 panic(fmt.Errorf("early static libs not suppported"))
2655 case normalLibraryDependency:
2656 // static dependencies will be handled separately so they can be ordered
2657 // using transitive dependencies.
2658 ptr = nil
Colin Cross0de8a1e2020-09-18 14:15:30 -07002659 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002660 case lateLibraryDependency:
2661 ptr = &depPaths.LateStaticLibs
2662 default:
2663 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002664 }
2665 }
2666 }
2667
Colin Cross6e511a92020-07-27 21:26:48 -07002668 if libDepTag.static() && !libDepTag.wholeStatic {
2669 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2670 ctx.ModuleErrorf("module %q not a static library", depName)
2671 return
2672 }
Logan Chien43d34c32017-12-20 01:17:32 +08002673
Colin Cross6e511a92020-07-27 21:26:48 -07002674 // When combining coverage files for shared libraries and executables, coverage files
2675 // in static libraries act as if they were whole static libraries. The same goes for
2676 // source based Abi dump files.
2677 if c, ok := ccDep.(*Module); ok {
2678 staticLib := c.linker.(libraryInterface)
2679 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2680 staticLib.objs().coverageFiles...)
2681 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2682 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002683 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002684 // Handle non-CC modules here
2685 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002686 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002687 }
2688 }
2689
Colin Cross6e511a92020-07-27 21:26:48 -07002690 if ptr != nil {
2691 if !linkFile.Valid() {
2692 if !ctx.Config().AllowMissingDependencies() {
2693 ctx.ModuleErrorf("module %q missing output file", depName)
2694 } else {
2695 ctx.AddMissingDependencies([]string{depName})
2696 }
2697 return
2698 }
2699 *ptr = append(*ptr, linkFile.Path())
2700 }
2701
2702 if depPtr != nil {
2703 dep := depFile
2704 if !dep.Valid() {
2705 dep = linkFile
2706 }
2707 *depPtr = append(*depPtr, dep.Path())
2708 }
2709
Colin Cross0de8a1e2020-09-18 14:15:30 -07002710 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
2711 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
2712 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
2713 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
2714
2715 if libDepTag.reexportFlags {
2716 reexportExporter(depExporterInfo)
2717 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2718 // Re-exported shared library headers must be included as well since they can help us with type information
2719 // about template instantiations (instantiated from their headers).
2720 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2721 // scripts.
2722 c.sabi.Properties.ReexportedIncludes = append(
2723 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
2724 }
2725
Colin Cross6e511a92020-07-27 21:26:48 -07002726 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2727 switch {
2728 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002729 c.Properties.AndroidMkHeaderLibs = append(
2730 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002731 case libDepTag.shared():
Colin Cross31076b32020-10-23 17:22:06 -07002732 if lib := moduleLibraryInterface(dep); lib != nil {
2733 if lib.buildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002734 // Add the dependency to the APEX(es) providing the library so that
2735 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002736 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2737 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002738 c.Properties.ApexesProvidingSharedLibs = append(
2739 c.Properties.ApexesProvidingSharedLibs, an)
2740 }
2741 }
2742 }
2743
2744 // Note: the order of libs in this list is not important because
2745 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002746 c.Properties.AndroidMkSharedLibs = append(
2747 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002748 // Record baseLibName for snapshots.
2749 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2750 case libDepTag.static():
2751 if libDepTag.wholeStatic {
2752 c.Properties.AndroidMkWholeStaticLibs = append(
2753 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2754 } else {
2755 c.Properties.AndroidMkStaticLibs = append(
2756 c.Properties.AndroidMkStaticLibs, makeLibName)
2757 }
2758 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002759 } else if !c.IsStubs() {
2760 // Stubs lib doesn't link to the runtime lib, object, crt, etc. dependencies.
2761
Colin Cross6e511a92020-07-27 21:26:48 -07002762 switch depTag {
2763 case runtimeDepTag:
2764 c.Properties.AndroidMkRuntimeLibs = append(
2765 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2766 // Record baseLibName for snapshots.
2767 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2768 case objDepTag:
2769 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2770 case CrtBeginDepTag:
2771 depPaths.CrtBegin = linkFile
2772 case CrtEndDepTag:
2773 depPaths.CrtEnd = linkFile
2774 case dynamicLinkerDepTag:
2775 depPaths.DynamicLinker = linkFile
2776 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002777 }
Colin Crossca860ac2016-01-04 14:34:37 -08002778 })
2779
Jeff Gaston294356f2017-09-27 17:05:30 -07002780 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07002781 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
2782 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
2783 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002784
Colin Crossdd84e052017-05-17 13:44:16 -07002785 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002786 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002787 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2788 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002789 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002790 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2791 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002792 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002793 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002794 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002795
2796 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002797 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002798 }
Colin Crossdd84e052017-05-17 13:44:16 -07002799
Colin Crossca860ac2016-01-04 14:34:37 -08002800 return depPaths
2801}
2802
Colin Cross0de8a1e2020-09-18 14:15:30 -07002803// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
2804// to match the topological order of the dependency tree, including any static analogues of
2805// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
2806// of the transitive dependencies.
2807func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
2808 transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
2809 var staticPaths android.Paths
2810 for _, staticDep := range staticDeps {
2811 staticPaths = append(staticPaths, staticDep.StaticLibrary)
2812 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
2813 }
2814 for _, sharedDep := range sharedDeps {
2815 if sharedDep.StaticAnalogue != nil {
2816 transitiveStaticLibsBuilder.Transitive(sharedDep.StaticAnalogue.TransitiveStaticLibrariesForOrdering)
2817 }
2818 }
2819 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
2820
2821 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
2822
2823 // reorder the dependencies based on transitive dependencies
2824 staticPaths = android.FirstUniquePaths(staticPaths)
2825 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
2826
2827 if len(orderedStaticPaths) != len(staticPaths) {
2828 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
2829 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
2830 }
2831
2832 return orderedStaticPaths, transitiveStaticLibs
2833}
2834
Colin Cross6e511a92020-07-27 21:26:48 -07002835// baseLibName trims known prefixes and suffixes
2836func baseLibName(depName string) string {
2837 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2838 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Paul Duffind23c7262020-12-11 18:13:08 +00002839 libName = android.RemoveOptionalPrebuiltPrefix(libName)
Colin Cross6e511a92020-07-27 21:26:48 -07002840 return libName
2841}
2842
2843func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2844 vendorSuffixModules := vendorSuffixModules(ctx.Config())
Jose Galmes6f843bc2020-12-11 13:36:29 -08002845 recoverySuffixModules := recoverySuffixModules(ctx.Config())
Colin Cross6e511a92020-07-27 21:26:48 -07002846 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2847
2848 libName := baseLibName(depName)
Colin Cross127bb8b2020-12-16 16:46:01 -08002849 ccDepModule, _ := ccDep.(*Module)
2850 isLLndk := ccDepModule != nil && ccDepModule.IsLlndk()
Colin Cross6e511a92020-07-27 21:26:48 -07002851 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2852 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2853
2854 if c, ok := ccDep.(*Module); ok {
2855 // Use base module name for snapshots when exporting to Makefile.
2856 if c.isSnapshotPrebuilt() {
2857 baseName := c.BaseModuleName()
2858
2859 if c.IsVndk() {
2860 return baseName + ".vendor"
2861 }
2862
Jose Galmes6f843bc2020-12-11 13:36:29 -08002863 if c.inVendor() && vendorSuffixModules[baseName] {
Colin Cross6e511a92020-07-27 21:26:48 -07002864 return baseName + ".vendor"
Jose Galmes6f843bc2020-12-11 13:36:29 -08002865 } else if c.InRecovery() && recoverySuffixModules[baseName] {
2866 return baseName + ".recovery"
Colin Cross6e511a92020-07-27 21:26:48 -07002867 } else {
2868 return baseName
2869 }
2870 }
2871 }
2872
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002873 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() &&
2874 !c.InRamdisk() && !c.InVendorRamdisk() && !c.InRecovery() {
Colin Cross6e511a92020-07-27 21:26:48 -07002875 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2876 // core module instead.
2877 return libName
2878 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2879 // The vendor module in Make will have been renamed to not conflict with the core
2880 // module, so update the dependency name here accordingly.
2881 return libName + c.getNameSuffixWithVndkVersion(ctx)
2882 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2883 return libName + vendorPublicLibrarySuffix
2884 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2885 return libName + ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002886 } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
2887 return libName + vendorRamdiskSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07002888 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2889 return libName + recoverySuffix
Ivan Lozanof9e21722020-12-02 09:00:51 -05002890 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
Colin Cross6e511a92020-07-27 21:26:48 -07002891 return libName + nativeBridgeSuffix
2892 } else {
2893 return libName
2894 }
2895}
2896
Colin Crossca860ac2016-01-04 14:34:37 -08002897func (c *Module) InstallInData() bool {
2898 if c.installer == nil {
2899 return false
2900 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002901 return c.installer.inData()
2902}
2903
2904func (c *Module) InstallInSanitizerDir() bool {
2905 if c.installer == nil {
2906 return false
2907 }
2908 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002909 return true
2910 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002911 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002912}
2913
Yifan Hong1b3348d2020-01-21 15:53:22 -08002914func (c *Module) InstallInRamdisk() bool {
2915 return c.InRamdisk()
2916}
2917
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002918func (c *Module) InstallInVendorRamdisk() bool {
2919 return c.InVendorRamdisk()
2920}
2921
Jiyong Parkf9332f12018-02-01 00:54:12 +09002922func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002923 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002924}
2925
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002926func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002927 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002928 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002929 return
2930 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002931 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002932}
2933
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002934func (c *Module) HostToolPath() android.OptionalPath {
2935 if c.installer == nil {
2936 return android.OptionalPath{}
2937 }
2938 return c.installer.hostToolPath()
2939}
2940
Nan Zhangd4e641b2017-07-12 12:55:28 -07002941func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2942 return c.outputFile
2943}
2944
Colin Cross41955e82019-05-29 14:40:35 -07002945func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2946 switch tag {
2947 case "":
2948 if c.outputFile.Valid() {
2949 return android.Paths{c.outputFile.Path()}, nil
2950 }
2951 return android.Paths{}, nil
2952 default:
2953 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002954 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002955}
2956
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002957func (c *Module) static() bool {
2958 if static, ok := c.linker.(interface {
2959 static() bool
2960 }); ok {
2961 return static.static()
2962 }
2963 return false
2964}
2965
Jiyong Park379de2f2018-12-19 02:47:14 +09002966func (c *Module) staticBinary() bool {
2967 if static, ok := c.linker.(interface {
2968 staticBinary() bool
2969 }); ok {
2970 return static.staticBinary()
2971 }
2972 return false
2973}
2974
Jiyong Park1d1119f2019-07-29 21:27:18 +09002975func (c *Module) header() bool {
2976 if h, ok := c.linker.(interface {
2977 header() bool
2978 }); ok {
2979 return h.header()
2980 }
2981 return false
2982}
2983
Inseob Kim7f283f42020-06-01 21:53:49 +09002984func (c *Module) binary() bool {
2985 if b, ok := c.linker.(interface {
2986 binary() bool
2987 }); ok {
2988 return b.binary()
2989 }
2990 return false
2991}
2992
Inseob Kim1042d292020-06-01 23:23:05 +09002993func (c *Module) object() bool {
2994 if o, ok := c.linker.(interface {
2995 object() bool
2996 }); ok {
2997 return o.object()
2998 }
2999 return false
3000}
3001
Ivan Lozanof9e21722020-12-02 09:00:51 -05003002func GetMakeLinkType(actx android.ModuleContext, c LinkableInterface) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07003003 if c.UseVndk() {
Colin Cross127bb8b2020-12-16 16:46:01 -08003004 if c.IsLlndk() {
3005 if !c.IsLlndkPublic() {
Ivan Lozanof9e21722020-12-02 09:00:51 -05003006 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07003007 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003008 return "native:vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07003009 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003010 if c.IsVndk() && !c.IsVndkExt() {
Colin Cross127bb8b2020-12-16 16:46:01 -08003011 if c.IsVndkPrivate() {
Ivan Lozanof9e21722020-12-02 09:00:51 -05003012 return "native:vndk_private"
Jooyung Han38002912019-05-16 04:01:54 +09003013 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003014 return "native:vndk"
Jooyung Han38002912019-05-16 04:01:54 +09003015 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003016 if c.InProduct() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003017 return "native:product"
3018 }
Jooyung Han38002912019-05-16 04:01:54 +09003019 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08003020 } else if c.InRamdisk() {
3021 return "native:ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003022 } else if c.InVendorRamdisk() {
3023 return "native:vendor_ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07003024 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07003025 return "native:recovery"
Ivan Lozanof9e21722020-12-02 09:00:51 -05003026 } else if c.Target().Os == android.Android && c.SdkVersion() != "" {
Colin Crossb60190a2018-09-04 16:28:17 -07003027 return "native:ndk:none:none"
3028 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
3029 //family, link := getNdkStlFamilyAndLinkType(c)
3030 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07003031 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08003032 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07003033 } else {
3034 return "native:platform"
3035 }
3036}
3037
Jiyong Park9d452992018-10-03 00:38:19 +09003038// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01003039// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09003040func (c *Module) IsInstallableToApex() bool {
Colin Cross31076b32020-10-23 17:22:06 -07003041 if lib := c.library; lib != nil {
Jiyong Park73c54ee2019-10-22 20:31:18 +09003042 // Stub libs and prebuilt libs in a versioned SDK are not
3043 // installable to APEX even though they are shared libs.
Colin Cross31076b32020-10-23 17:22:06 -07003044 return lib.shared() && !lib.buildStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01003045 } else if _, ok := c.linker.(testPerSrc); ok {
3046 return true
Jiyong Park9d452992018-10-03 00:38:19 +09003047 }
3048 return false
3049}
3050
Jiyong Parka90ca002019-10-07 15:47:24 +09003051func (c *Module) AvailableFor(what string) bool {
3052 if linker, ok := c.linker.(interface {
3053 availableFor(string) bool
3054 }); ok {
3055 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
3056 } else {
3057 return c.ApexModuleBase.AvailableFor(what)
3058 }
3059}
3060
Jiyong Park62304bb2020-04-13 16:19:48 +09003061func (c *Module) TestFor() []string {
Jiyong Park46a512f2020-12-04 18:02:13 +09003062 return c.Properties.Test_for
Jiyong Park62304bb2020-04-13 16:19:48 +09003063}
3064
Colin Crossaede88c2020-08-11 12:17:01 -07003065func (c *Module) UniqueApexVariations() bool {
3066 if u, ok := c.compiler.(interface {
3067 uniqueApexVariations() bool
3068 }); ok {
3069 return u.uniqueApexVariations()
3070 } else {
3071 return false
3072 }
3073}
3074
Paul Duffin0cb37b92020-03-04 14:52:46 +00003075// Return true if the module is ever installable.
3076func (c *Module) EverInstallable() bool {
3077 return c.installer != nil &&
3078 // Check to see whether the module is actually ever installable.
3079 c.installer.everInstallable()
3080}
3081
Colin Cross56a83212020-09-15 18:30:11 -07003082func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003083 ret := c.EverInstallable() &&
3084 // Check to see whether the module has been configured to not be installed.
3085 proptools.BoolDefault(c.Properties.Installable, true) &&
3086 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003087
3088 // The platform variant doesn't need further condition. Apex variants however might not
3089 // be installable because it will likely to be included in the APEX and won't appear
3090 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07003091 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003092 return ret
3093 }
3094
3095 // Special case for modules that are configured to be installed to /data, which includes
3096 // test modules. For these modules, both APEX and non-APEX variants are considered as
3097 // installable. This is because even the APEX variants won't be included in the APEX, but
3098 // will anyway be installed to /data/*.
3099 // See b/146995717
3100 if c.InstallInData() {
3101 return ret
3102 }
3103
3104 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003105}
3106
Logan Chien41eabe62019-04-10 13:33:58 +08003107func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3108 if c.linker != nil {
3109 if library, ok := c.linker.(*libraryDecorator); ok {
3110 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3111 }
3112 }
3113}
3114
Jiyong Park45bf82e2020-12-15 22:29:02 +09003115var _ android.ApexModule = (*Module)(nil)
3116
3117// Implements android.ApexModule
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003118func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07003119 depTag := ctx.OtherModuleDependencyTag(dep)
3120 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3121
3122 if cc, ok := dep.(*Module); ok {
3123 if cc.HasStubsVariants() {
3124 if isLibDepTag && libDepTag.shared() {
3125 // dynamic dep to a stubs lib crosses APEX boundary
3126 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003127 }
Colin Cross6e511a92020-07-27 21:26:48 -07003128 if IsRuntimeDepTag(depTag) {
3129 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003130 return false
3131 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003132 }
Colin Crossaac32222020-07-29 12:51:56 -07003133 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003134 // shared_lib dependency from a static lib is considered as crossing
3135 // the APEX boundary because the dependency doesn't actually is
3136 // linked; the dependency is used only during the compilation phase.
3137 return false
3138 }
Jiyong Parke3867542020-12-03 17:28:25 +09003139
3140 if isLibDepTag && libDepTag.excludeInApex {
3141 return false
3142 }
Colin Cross6e511a92020-07-27 21:26:48 -07003143 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003144 if depTag == stubImplDepTag || depTag == llndkStubDepTag {
Colin Cross0de8a1e2020-09-18 14:15:30 -07003145 // We don't track beyond LLNDK or from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09003146 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003147 }
Jiyong Park12177fc2021-01-05 14:37:15 +09003148 if depTag == staticVariantTag {
3149 // This dependency is for optimization (reuse *.o from the static lib). It doesn't
3150 // actually mean that the static lib (and its dependencies) are copied into the
3151 // APEX.
3152 return false
3153 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003154 return true
3155}
3156
Jiyong Park45bf82e2020-12-15 22:29:02 +09003157// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07003158func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3159 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003160 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3161 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3162 return nil
3163 }
3164 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3165 if c.ToolchainLibrary() {
3166 return nil
3167 }
3168 // We don't check for prebuilt modules
3169 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3170 return nil
3171 }
3172 minSdkVersion := c.MinSdkVersion()
3173 if minSdkVersion == "apex_inherit" {
3174 return nil
3175 }
3176 if minSdkVersion == "" {
3177 // JNI libs within APK-in-APEX fall into here
3178 // Those are okay to set sdk_version instead
3179 // We don't have to check if this is a SDK variant because
3180 // non-SDK variant resets sdk_version, which works too.
3181 minSdkVersion = c.SdkVersion()
3182 }
Dan Albertc8060532020-07-22 22:32:17 -07003183 if minSdkVersion == "" {
3184 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3185 }
3186 // Not using nativeApiLevelFromUser because the context here is not
3187 // necessarily a native context.
3188 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003189 if err != nil {
3190 return err
3191 }
Dan Albertc8060532020-07-22 22:32:17 -07003192
3193 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003194 return fmt.Errorf("newer SDK(%v)", ver)
3195 }
3196 return nil
3197}
3198
Colin Cross2ba19d92015-05-07 15:44:20 -07003199//
Colin Crosscfad1192015-11-02 16:43:11 -08003200// Defaults
3201//
Colin Crossca860ac2016-01-04 14:34:37 -08003202type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003203 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003204 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003205 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003206}
3207
Patrice Arrudac249c712019-03-19 17:00:29 -07003208// cc_defaults provides a set of properties that can be inherited by other cc
3209// modules. A module can use the properties from a cc_defaults using
3210// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3211// merged (when possible) by prepending the default module's values to the
3212// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003213func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003214 return DefaultsFactory()
3215}
3216
Colin Cross36242852017-06-23 15:06:31 -07003217func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003218 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003219
Colin Cross36242852017-06-23 15:06:31 -07003220 module.AddProperties(props...)
3221 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003222 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003223 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003224 &BaseCompilerProperties{},
3225 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003226 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003227 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003228 &StaticProperties{},
3229 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003230 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003231 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003232 &TestProperties{},
3233 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003234 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003235 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003236 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003237 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003238 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003239 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003240 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003241 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003242 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003243 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003244 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003245 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003246 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003247 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3248 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003249 )
Colin Crosscfad1192015-11-02 16:43:11 -08003250
Jooyung Hancc372c52019-09-25 15:18:44 +09003251 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003252
3253 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003254}
3255
Jiyong Park2286afd2020-06-16 21:58:53 +09003256func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003257 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003258}
3259
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003260func kytheExtractAllFactory() android.Singleton {
3261 return &kytheExtractAllSingleton{}
3262}
3263
3264type kytheExtractAllSingleton struct {
3265}
3266
3267func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3268 var xrefTargets android.Paths
3269 ctx.VisitAllModules(func(module android.Module) {
3270 if ccModule, ok := module.(xref); ok {
3271 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3272 }
3273 })
3274 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3275 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003276 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003277 }
3278}
3279
Colin Cross06a931b2015-10-28 17:23:31 -07003280var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003281var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003282var BoolPtr = proptools.BoolPtr
3283var String = proptools.String
3284var StringPtr = proptools.StringPtr