blob: e69cff52f0f5dcec95af6b292cb2ab9c39695d52 [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) {
Ivan Lozano3968d8f2020-12-14 11:27:52 -050060 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
Ivan Lozano3968d8f2020-12-14 11:27:52 -050066 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(Fuzzer))
67 ctx.BottomUp("fuzzer", sanitizerMutator(Fuzzer)).Parallel()
Mitch Phillipsbfeade62019-05-01 14:42:05 -070068
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
Jiyong Parkb35a8192020-08-10 15:59:36 +0900259 // The API level that this module is built against. The APIs of this API level will be
260 // visible at build time, but use of any APIs newer than min_sdk_version will render the
261 // module unloadable on older devices. In the future it will be possible to weakly-link new
262 // APIs, making the behavior match Java: such modules will load on older devices, but
263 // calling new APIs on devices that do not support them will result in a crash.
264 //
265 // This property has the same behavior as sdk_version does for Java modules. For those
266 // familiar with Android Gradle, the property behaves similarly to how compileSdkVersion
267 // does for Java code.
268 //
269 // In addition, setting this property causes two variants to be built, one for the platform
270 // and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800271 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700272
Jiyong Parkb35a8192020-08-10 15:59:36 +0900273 // Minimum OS API level supported by this C or C++ module. This property becomes the value
274 // of the __ANDROID_API__ macro. When the C or C++ module is included in an APEX or an APK,
275 // this property is also used to ensure that the min_sdk_version of the containing module is
276 // not older (i.e. less) than this module's min_sdk_version. When not set, this property
277 // defaults to the value of sdk_version. When this is set to "apex_inherit", this tracks
278 // min_sdk_version of the containing APEX. When the module
279 // is not built for an APEX, "apex_inherit" defaults to sdk_version.
Jooyung Han379660c2020-04-21 15:24:00 +0900280 Min_sdk_version *string
281
Colin Crossc511bc52020-04-07 16:50:32 +0000282 // If true, always create an sdk variant and don't create a platform variant.
283 Sdk_variant_only *bool
284
Jiyong Parkde866cb2018-12-07 23:08:36 +0900285 AndroidMkSharedLibs []string `blueprint:"mutated"`
286 AndroidMkStaticLibs []string `blueprint:"mutated"`
287 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
288 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700289 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900290 HideFromMake bool `blueprint:"mutated"`
291 PreventInstall bool `blueprint:"mutated"`
292 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700293
Yo Chiang219968c2020-09-22 18:45:04 +0800294 // Set by DepsMutator.
295 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
296
Justin Yun5f7f7e82019-11-18 19:52:14 +0900297 ImageVariationPrefix string `blueprint:"mutated"`
298 VndkVersion string `blueprint:"mutated"`
299 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800300
301 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
302 // file
303 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900304
Yifan Hong39143a92020-10-26 12:43:12 -0700305 // Make this module available when building for ramdisk.
306 // On device without a dedicated recovery partition, the module is only
307 // available after switching root into
308 // /first_stage_ramdisk. To expose the module before switching root, install
309 // the recovery variant instead.
Yifan Hong1b3348d2020-01-21 15:53:22 -0800310 Ramdisk_available *bool
311
Yifan Hong39143a92020-10-26 12:43:12 -0700312 // Make this module available when building for vendor ramdisk.
313 // On device without a dedicated recovery partition, the module is only
314 // available after switching root into
315 // /first_stage_ramdisk. To expose the module before switching root, install
316 // the recovery variant instead.
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700317 Vendor_ramdisk_available *bool
318
Jiyong Parkf9332f12018-02-01 00:54:12 +0900319 // Make this module available when building for recovery
320 Recovery_available *bool
321
Colin Crossae6c5202019-11-20 13:35:50 -0800322 // Set by imageMutator
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700323 CoreVariantNeeded bool `blueprint:"mutated"`
324 RamdiskVariantNeeded bool `blueprint:"mutated"`
325 VendorRamdiskVariantNeeded bool `blueprint:"mutated"`
326 RecoveryVariantNeeded bool `blueprint:"mutated"`
327 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900328
329 // Allows this module to use non-APEX version of libraries. Useful
330 // for building binaries that are started before APEXes are activated.
331 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900332
333 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
334 // see soong/cc/config/vndk.go
335 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900336
337 // Used by vendor snapshot to record dependencies from snapshot modules.
338 SnapshotSharedLibs []string `blueprint:"mutated"`
339 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000340
341 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000342
343 // Set by factories of module types that can only be referenced from variants compiled against
344 // the SDK.
345 AlwaysSdk bool `blueprint:"mutated"`
346
347 // Variant is an SDK variant created by sdkMutator
348 IsSdkVariant bool `blueprint:"mutated"`
349 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
350 // variant to have a ".sdk" suffix.
351 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700352
353 // Normally Soong uses the directory structure to decide which modules
354 // should be included (framework) or excluded (non-framework) from the
Jose Galmes6f843bc2020-12-11 13:36:29 -0800355 // different snapshots (vendor, recovery, etc.), but this property
356 // allows a partner to exclude a module normally thought of as a
357 // framework module from the vendor snapshot.
358 Exclude_from_vendor_snapshot *bool
359
360 // Normally Soong uses the directory structure to decide which modules
361 // should be included (framework) or excluded (non-framework) from the
362 // different snapshots (vendor, recovery, etc.), but this property
363 // allows a partner to exclude a module normally thought of as a
364 // framework module from the recovery snapshot.
Jose Galmesf7294582020-11-13 12:07:36 -0800365 Exclude_from_recovery_snapshot *bool
Jiyong Park46a512f2020-12-04 18:02:13 +0900366
367 // List of APEXes that this module has private access to for testing purpose. The module
368 // can depend on libraries that are not exported by the APEXes and use private symbols
369 // from the exported libraries.
370 Test_for []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700371}
372
373type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900374 // whether this module should be allowed to be directly depended by other
375 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun63e9ec72020-10-29 16:49:43 +0900376 // If set to true, two variants will be built separately, one like
377 // normal, and the other limited to the set of libraries and headers
378 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700379 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900380 // The vendor variant may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700381 // so it shouldn't have any unversioned runtime dependencies, or
382 // make assumptions about the system that may not be true in the
383 // future.
384 //
Justin Yun63e9ec72020-10-29 16:49:43 +0900385 // If set to false, this module becomes inaccessible from /vendor modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900386 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900387 // The modules with vndk: {enabled: true} must define 'vendor_available'
Justin Yun0b1db6d2021-01-08 15:22:34 +0900388 // to 'true'.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900389 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700390 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
391 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900392
Justin Yun63e9ec72020-10-29 16:49:43 +0900393 // whether this module should be allowed to be directly depended by other
394 // modules with `product_specific: true` or `product_available: true`.
395 // If set to true, an additional product variant will be built separately
396 // that is limited to the set of libraries and headers that are exposed to
397 // /product modules.
398 //
399 // The product variant may be used with a different (newer) /system,
400 // so it shouldn't have any unversioned runtime dependencies, or
401 // make assumptions about the system that may not be true in the
402 // future.
403 //
Justin Yun6977e8a2020-10-29 18:24:11 +0900404 // If set to false, this module becomes inaccessible from /product modules.
405 //
406 // Different from the 'vendor_available' property, the modules with
407 // vndk: {enabled: true} don't have to define 'product_available'. The VNDK
408 // library without 'product_available' may not be depended on by any other
409 // modules that has product variants including the product available VNDKs.
Justin Yun63e9ec72020-10-29 16:49:43 +0900410 //
411 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
412 // and PRODUCT_PRODUCT_VNDK_VERSION isn't set.
413 Product_available *bool
414
Jiyong Park5fb8c102018-04-09 12:03:06 +0900415 // whether this module is capable of being loaded with other instance
416 // (possibly an older version) of the same module in the same process.
417 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
418 // can be double loaded in a vendor process if the library is also a
419 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
420 // explicitly marked as `double_loadable: true` by the owner, or the dependency
421 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
422 Double_loadable *bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800423
424 // IsLLNDK is set to true for the vendor variant of a cc_library module that has LLNDK stubs.
425 IsLLNDK bool `blueprint:"mutated"`
426
427 // IsLLNDKPrivate is set to true for the vendor variant of a cc_library module that has LLNDK
Justin Yunc0d8c492021-01-07 17:45:31 +0900428 // stubs and also sets llndk.private: true.
Colin Cross127bb8b2020-12-16 16:46:01 -0800429 IsLLNDKPrivate bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800430}
431
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500432// ModuleContextIntf is an interface (on a module context helper) consisting of functions related
433// to understanding details about the type of the current module.
434// For example, one might call these functions to determine whether the current module is a static
435// library and/or is installed in vendor directories.
Colin Crossca860ac2016-01-04 14:34:37 -0800436type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800437 static() bool
438 staticBinary() bool
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -0700439 testBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900440 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900441 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900442 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700443 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900444 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700445 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800446 sdkVersion() string
Jiyong Parkb35a8192020-08-10 15:59:36 +0900447 minSdkVersion() string
448 isSdkVariant() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700449 useVndk() bool
Colin Cross95f1ca02020-10-29 20:47:22 -0700450 isNdk(config android.Config) bool
Colin Cross127bb8b2020-12-16 16:46:01 -0800451 IsLlndk() bool
452 IsLlndkPublic() bool
453 isImplementationForLLNDKPublic() bool
454 IsVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900455 isVndk() bool
456 isVndkSp() bool
Ivan Lozanof9e21722020-12-02 09:00:51 -0500457 IsVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900458 inProduct() bool
459 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800460 inRamdisk() bool
Yifan Hong60e0cfb2020-10-21 15:17:56 -0700461 inVendorRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900462 inRecovery() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700463 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700464 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800465 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800466 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800467 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800468 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800469 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700470 apexVariationName() string
Dan Albertc8060532020-07-22 22:32:17 -0700471 apexSdkVersion() android.ApiLevel
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900472 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800473 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700474 nativeCoverage() bool
Colin Cross56a83212020-09-15 18:30:11 -0700475 directlyInAnyApex() bool
Colin Cross95b07f22020-12-16 11:06:50 -0800476 isPreventInstall() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800477}
478
479type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700480 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800481 ModuleContextIntf
482}
483
484type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700485 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800486 ModuleContextIntf
487}
488
Colin Cross37047f12016-12-13 17:06:13 -0800489type DepsContext interface {
490 android.BottomUpMutatorContext
491 ModuleContextIntf
492}
493
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500494// feature represents additional (optional) steps to building cc-related modules, such as invocation
495// of clang-tidy.
Colin Crossca860ac2016-01-04 14:34:37 -0800496type feature interface {
497 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800498 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800499 flags(ctx ModuleContext, flags Flags) Flags
500 props() []interface{}
501}
502
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500503// compiler is the interface for a compiler helper object. Different module decorators may implement
504// this helper differently. For example, compiling a `cc_library` may use a different build
505// statement than building a `toolchain_library`.
Colin Crossca860ac2016-01-04 14:34:37 -0800506type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700507 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800508 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800509 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700510 compilerProps() []interface{}
511
Colin Cross76fada02016-07-27 10:31:13 -0700512 appendCflags([]string)
513 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700514 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800515}
516
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500517// linker is the interface for a linker decorator object. Individual module types can provide
518// their own implementation for this decorator, and thus specify custom logic regarding build
519// statements pertaining to linking.
Colin Crossca860ac2016-01-04 14:34:37 -0800520type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700521 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800522 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700523 linkerFlags(ctx ModuleContext, flags Flags) Flags
524 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800525 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700526
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700527 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700528 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900529 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700530
531 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900532 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000533
534 // Get the deps that have been explicitly specified in the properties.
Paul Duffin13f02712020-03-06 12:30:43 +0000535 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
536}
537
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500538// specifiedDeps is a tuple struct representing dependencies of a linked binary owned by the linker.
Paul Duffin13f02712020-03-06 12:30:43 +0000539type specifiedDeps struct {
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500540 sharedLibs []string
541 // Note nil and [] are semantically distinct. [] prevents linking against the defaults (usually
542 // libc, libm, etc.)
543 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800544}
545
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500546// installer is the interface for an installer helper object. This helper is responsible for
547// copying build outputs to the appropriate locations so that they may be installed on device.
Colin Crossca860ac2016-01-04 14:34:37 -0800548type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700549 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700550 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000551 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800552 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700553 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700554 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900555 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100556 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800557}
558
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800559type xref interface {
560 XrefCcFiles() android.Paths
561}
562
Colin Cross6e511a92020-07-27 21:26:48 -0700563type libraryDependencyKind int
564
565const (
566 headerLibraryDependency = iota
567 sharedLibraryDependency
568 staticLibraryDependency
569)
570
571func (k libraryDependencyKind) String() string {
572 switch k {
573 case headerLibraryDependency:
574 return "headerLibraryDependency"
575 case sharedLibraryDependency:
576 return "sharedLibraryDependency"
577 case staticLibraryDependency:
578 return "staticLibraryDependency"
579 default:
580 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
581 }
582}
583
584type libraryDependencyOrder int
585
586const (
587 earlyLibraryDependency = -1
588 normalLibraryDependency = 0
589 lateLibraryDependency = 1
590)
591
592func (o libraryDependencyOrder) String() string {
593 switch o {
594 case earlyLibraryDependency:
595 return "earlyLibraryDependency"
596 case normalLibraryDependency:
597 return "normalLibraryDependency"
598 case lateLibraryDependency:
599 return "lateLibraryDependency"
600 default:
601 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
602 }
603}
604
605// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
606// tags that have a set of predefined tag objects that are reused for each dependency, a
607// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
608// That means that comparing a libraryDependencyTag for equality will only be equal if all
609// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
610// then check individual metadata fields instead.
611type libraryDependencyTag struct {
612 blueprint.BaseDependencyTag
613
614 // These are exported so that fmt.Printf("%#v") can call their String methods.
615 Kind libraryDependencyKind
616 Order libraryDependencyOrder
617
618 wholeStatic bool
619
620 reexportFlags bool
621 explicitlyVersioned bool
622 dataLib bool
623 ndk bool
624
625 staticUnwinder bool
626
627 makeSuffix string
Jiyong Parke3867542020-12-03 17:28:25 +0900628
Cindy Zhou18417cb2020-12-10 07:12:38 -0800629 // Whether or not this dependency should skip the apex dependency check
630 skipApexAllowedDependenciesCheck bool
631
Jiyong Parke3867542020-12-03 17:28:25 +0900632 // Whether or not this dependency has to be followed for the apex variants
633 excludeInApex bool
Colin Cross6e511a92020-07-27 21:26:48 -0700634}
635
636// header returns true if the libraryDependencyTag is tagging a header lib dependency.
637func (d libraryDependencyTag) header() bool {
638 return d.Kind == headerLibraryDependency
639}
640
641// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
642func (d libraryDependencyTag) shared() bool {
643 return d.Kind == sharedLibraryDependency
644}
645
646// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
647func (d libraryDependencyTag) static() bool {
648 return d.Kind == staticLibraryDependency
649}
650
Colin Crosse9fe2942020-11-10 18:12:15 -0800651// InstallDepNeeded returns true for shared libraries so that shared library dependencies of
652// binaries or other shared libraries are installed as dependencies.
653func (d libraryDependencyTag) InstallDepNeeded() bool {
654 return d.shared()
655}
656
657var _ android.InstallNeededDependencyTag = libraryDependencyTag{}
658
659// dependencyTag is used for tagging miscellaneous dependency types that don't fit into
Colin Cross6e511a92020-07-27 21:26:48 -0700660// libraryDependencyTag. Each tag object is created globally and reused for multiple
661// dependencies (although since the object contains no references, assigning a tag to a
662// variable and modifying it will not modify the original). Users can compare the tag
663// returned by ctx.OtherModuleDependencyTag against the global original
664type dependencyTag struct {
665 blueprint.BaseDependencyTag
666 name string
667}
668
Colin Crosse9fe2942020-11-10 18:12:15 -0800669// installDependencyTag is used for tagging miscellaneous dependency types that don't fit into
670// libraryDependencyTag, but where the dependency needs to be installed when the parent is
671// installed.
672type installDependencyTag struct {
673 blueprint.BaseDependencyTag
674 android.InstallAlwaysNeededDependencyTag
675 name string
676}
677
Colin Crossc99deeb2016-04-11 15:06:20 -0700678var (
Colin Cross6e511a92020-07-27 21:26:48 -0700679 genSourceDepTag = dependencyTag{name: "gen source"}
680 genHeaderDepTag = dependencyTag{name: "gen header"}
681 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
682 objDepTag = dependencyTag{name: "obj"}
683 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
Jiyong Parkd630bdd2020-11-25 11:47:24 +0900684 dynamicLinkerDepTag = installDependencyTag{name: "dynamic linker"}
Colin Cross6e511a92020-07-27 21:26:48 -0700685 reuseObjTag = dependencyTag{name: "reuse objects"}
686 staticVariantTag = dependencyTag{name: "static variant"}
687 vndkExtDepTag = dependencyTag{name: "vndk extends"}
688 dataLibDepTag = dependencyTag{name: "data lib"}
Colin Crosse9fe2942020-11-10 18:12:15 -0800689 runtimeDepTag = installDependencyTag{name: "runtime lib"}
Colin Cross6e511a92020-07-27 21:26:48 -0700690 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Cross0de8a1e2020-09-18 14:15:30 -0700691 stubImplDepTag = dependencyTag{name: "stub_impl"}
Colin Cross127bb8b2020-12-16 16:46:01 -0800692 llndkStubDepTag = dependencyTag{name: "llndk stub"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700693)
694
Colin Cross56a83212020-09-15 18:30:11 -0700695type copyDirectlyInAnyApexDependencyTag dependencyTag
696
697func (copyDirectlyInAnyApexDependencyTag) CopyDirectlyInAnyApex() {}
698
699var _ android.CopyDirectlyInAnyApexTag = copyDirectlyInAnyApexDependencyTag{}
700
Roland Levillainf89cd092019-07-29 16:22:59 +0100701func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700702 ccLibDepTag, ok := depTag.(libraryDependencyTag)
703 return ok && ccLibDepTag.shared()
704}
705
706func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
707 ccLibDepTag, ok := depTag.(libraryDependencyTag)
708 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100709}
710
Zach Johnson3df4e632020-11-06 11:56:27 -0800711func IsHeaderDepTag(depTag blueprint.DependencyTag) bool {
712 ccLibDepTag, ok := depTag.(libraryDependencyTag)
713 return ok && ccLibDepTag.header()
714}
715
Roland Levillainf89cd092019-07-29 16:22:59 +0100716func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Crosse9fe2942020-11-10 18:12:15 -0800717 return depTag == runtimeDepTag
Roland Levillainf89cd092019-07-29 16:22:59 +0100718}
719
720func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700721 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100722 return ok && ccDepTag == testPerSrcDepTag
723}
724
Colin Crossca860ac2016-01-04 14:34:37 -0800725// Module contains the properties and members used by all C/C++ module types, and implements
726// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500727// to construct the output file. Behavior can be customized with a Customizer, or "decorator",
728// interface.
729//
730// To define a C/C++ related module, construct a new Module object and point its delegates to
731// type-specific structs. These delegates will be invoked to register module-specific build
732// statements which may be unique to the module type. For example, module.compiler.compile() should
733// be defined so as to register build statements which are responsible for compiling the module.
734//
735// Another example: to construct a cc_binary module, one can create a `cc.binaryDecorator` struct
736// which implements the `linker` and `installer` interfaces, and points the `linker` and `installer`
737// members of the cc.Module to this decorator. Thus, a cc_binary module has custom linker and
738// installer logic.
Colin Crossca860ac2016-01-04 14:34:37 -0800739type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700740 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700741 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900742 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900743 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700744
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700745 Properties BaseProperties
746 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700747
Colin Crossca860ac2016-01-04 14:34:37 -0800748 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700749 hod android.HostOrDeviceSupported
750 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700751
Paul Duffina0843f62019-12-13 19:50:38 +0000752 // Allowable SdkMemberTypes of this module type.
753 sdkMemberTypes []android.SdkMemberType
754
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500755 // decorator delegates, initialize before calling Init
756 // these may contain module-specific implementations, and effectively allow for custom
757 // type-specific logic. These members may reference different objects or the same object.
758 // Functions of these decorators will be invoked to initialize and register type-specific
759 // build statements.
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700760 compiler compiler
761 linker linker
762 installer installer
Chris Parsonsef6e0cf2020-12-01 18:26:21 -0500763
764 features []feature
765 stl *stl
766 sanitize *sanitize
767 coverage *coverage
768 sabi *sabi
769 vndkdep *vndkdep
770 lto *lto
771 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800772
Colin Cross31076b32020-10-23 17:22:06 -0700773 library libraryInterface
774
Colin Cross635c3b02016-05-18 15:37:25 -0700775 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800776
Colin Crossb98c8b02016-07-29 13:44:28 -0700777 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700778
779 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800780
781 // Flags used to compile this module
782 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700783
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800784 // only non-nil when this is a shared library that reuses the objects of a static library
Colin Cross0de8a1e2020-09-18 14:15:30 -0700785 staticAnalogue *StaticLibraryInfo
Inseob Kim9516ee92019-05-09 10:56:13 +0900786
787 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800788 // Kythe (source file indexer) paths for this compilation module
789 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900790
791 // For apex variants, this is set as apex.min_sdk_version
Dan Albertc8060532020-07-22 22:32:17 -0700792 apexSdkVersion android.ApiLevel
Colin Cross56a83212020-09-15 18:30:11 -0700793
794 hideApexVariantFromMake bool
Colin Crossc472d572015-03-17 15:06:21 -0700795}
796
Ivan Lozano3968d8f2020-12-14 11:27:52 -0500797func (c *Module) SetPreventInstall() {
798 c.Properties.PreventInstall = true
799}
800
801func (c *Module) SetHideFromMake() {
802 c.Properties.HideFromMake = true
803}
804
Ivan Lozano52767be2019-10-18 14:49:46 -0700805func (c *Module) Toc() android.OptionalPath {
806 if c.linker != nil {
807 if library, ok := c.linker.(libraryInterface); ok {
808 return library.toc()
809 }
810 }
811 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
812}
813
814func (c *Module) ApiLevel() string {
815 if c.linker != nil {
816 if stub, ok := c.linker.(*stubDecorator); ok {
Dan Albert1a246272020-07-06 14:49:35 -0700817 return stub.apiLevel.String()
Ivan Lozano52767be2019-10-18 14:49:46 -0700818 }
819 }
820 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
821}
822
823func (c *Module) Static() bool {
824 if c.linker != nil {
825 if library, ok := c.linker.(libraryInterface); ok {
826 return library.static()
827 }
828 }
829 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
830}
831
832func (c *Module) Shared() bool {
833 if c.linker != nil {
834 if library, ok := c.linker.(libraryInterface); ok {
835 return library.shared()
836 }
837 }
838 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
839}
840
841func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000842 if c.stl != nil {
843 return c.stl.Properties.SelectedStl
844 }
845 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700846}
847
848func (c *Module) ToolchainLibrary() bool {
849 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
850 return true
851 }
852 return false
853}
854
855func (c *Module) NdkPrebuiltStl() bool {
856 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
857 return true
858 }
859 return false
860}
861
862func (c *Module) StubDecorator() bool {
863 if _, ok := c.linker.(*stubDecorator); ok {
864 return true
865 }
866 return false
867}
868
869func (c *Module) SdkVersion() string {
870 return String(c.Properties.Sdk_version)
871}
872
Artur Satayev480e25b2020-04-27 18:53:18 +0100873func (c *Module) MinSdkVersion() string {
874 return String(c.Properties.Min_sdk_version)
875}
876
Dan Albert92fe7402020-07-15 13:33:30 -0700877func (c *Module) SplitPerApiLevel() bool {
Colin Cross1348ce32020-10-01 13:37:16 -0700878 if !c.canUseSdk() {
879 return false
880 }
Dan Albert92fe7402020-07-15 13:33:30 -0700881 if linker, ok := c.linker.(*objectLinker); ok {
882 return linker.isCrt()
883 }
884 return false
885}
886
Colin Crossc511bc52020-04-07 16:50:32 +0000887func (c *Module) AlwaysSdk() bool {
888 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
889}
890
Ivan Lozano183a3212019-10-18 14:18:45 -0700891func (c *Module) CcLibrary() bool {
892 if c.linker != nil {
893 if _, ok := c.linker.(*libraryDecorator); ok {
894 return true
895 }
Colin Crossd48fe732020-09-23 20:37:24 -0700896 if _, ok := c.linker.(*prebuiltLibraryLinker); ok {
897 return true
898 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700899 }
900 return false
901}
902
903func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700904 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700905 return true
906 }
907 return false
908}
909
Ivan Lozano2b262972019-11-21 12:30:50 -0800910func (c *Module) NonCcVariants() bool {
911 return false
912}
913
Ivan Lozano183a3212019-10-18 14:18:45 -0700914func (c *Module) SetStatic() {
915 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700916 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700917 library.setStatic()
918 return
919 }
920 }
921 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
922}
923
924func (c *Module) SetShared() {
925 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700926 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700927 library.setShared()
928 return
929 }
930 }
931 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
932}
933
934func (c *Module) BuildStaticVariant() bool {
935 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700936 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700937 return library.buildStatic()
938 }
939 }
940 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
941}
942
943func (c *Module) BuildSharedVariant() bool {
944 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700945 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700946 return library.buildShared()
947 }
948 }
949 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
950}
951
952func (c *Module) Module() android.Module {
953 return c
954}
955
Jiyong Parkc20eee32018-09-05 22:36:17 +0900956func (c *Module) OutputFile() android.OptionalPath {
957 return c.outputFile
958}
959
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400960func (c *Module) CoverageFiles() android.Paths {
961 if c.linker != nil {
962 if library, ok := c.linker.(libraryInterface); ok {
963 return library.objs().coverageFiles
964 }
965 }
966 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
967}
968
Ivan Lozano183a3212019-10-18 14:18:45 -0700969var _ LinkableInterface = (*Module)(nil)
970
Jiyong Park719b4462019-01-13 00:39:51 +0900971func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900972 if c.linker != nil {
973 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900974 }
975 return nil
976}
977
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900978func (c *Module) CoverageOutputFile() android.OptionalPath {
979 if c.linker != nil {
980 return c.linker.coverageOutputFilePath()
981 }
982 return android.OptionalPath{}
983}
984
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900985func (c *Module) RelativeInstallPath() string {
986 if c.installer != nil {
987 return c.installer.relativeInstallPath()
988 }
989 return ""
990}
991
Jooyung Han344d5432019-08-23 11:17:39 +0900992func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900993 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900994}
995
Colin Cross36242852017-06-23 15:06:31 -0700996func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700997 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800998 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700999 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001000 }
1001 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -07001002 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001003 }
1004 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -07001005 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001006 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001007 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -07001008 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -07001009 }
Colin Cross16b23492016-01-06 14:41:07 -08001010 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -07001011 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -08001012 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001013 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -07001014 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001015 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001016 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -07001017 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001018 }
Justin Yun8effde42017-06-23 19:24:43 +09001019 if c.vndkdep != nil {
1020 c.AddProperties(c.vndkdep.props()...)
1021 }
Stephen Craneba090d12017-05-09 15:44:35 -07001022 if c.lto != nil {
1023 c.AddProperties(c.lto.props()...)
1024 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001025 if c.pgo != nil {
1026 c.AddProperties(c.pgo.props()...)
1027 }
Colin Crossca860ac2016-01-04 14:34:37 -08001028 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -07001029 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -08001030 }
Colin Crossc472d572015-03-17 15:06:21 -07001031
Jiyong Park1613e552020-09-14 19:43:17 +09001032 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, os android.OsType) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -07001033 // Windows builds always prefer 32-bit
Jiyong Park1613e552020-09-14 19:43:17 +09001034 return os == android.Windows
Colin Crossa9d8bee2018-10-02 13:59:46 -07001035 })
Colin Cross36242852017-06-23 15:06:31 -07001036 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +09001037 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +09001038 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +09001039 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +09001040
Colin Cross36242852017-06-23 15:06:31 -07001041 return c
Colin Crossc472d572015-03-17 15:06:21 -07001042}
1043
Colin Crossb916a382016-07-29 17:28:03 -07001044// Returns true for dependency roots (binaries)
1045// TODO(ccross): also handle dlopenable libraries
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001046func (c *Module) IsDependencyRoot() bool {
Colin Crossb916a382016-07-29 17:28:03 -07001047 if root, ok := c.linker.(interface {
1048 isDependencyRoot() bool
1049 }); ok {
1050 return root.isDependencyRoot()
1051 }
1052 return false
1053}
1054
Justin Yun5f7f7e82019-11-18 19:52:14 +09001055// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
1056// "product" and "vendor" variant modules return true for this function.
1057// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
1058// "soc_specific: true" and more vendor installed modules are included here.
Justin Yun63e9ec72020-10-29 16:49:43 +09001059// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "product_available: true" or
Justin Yun5f7f7e82019-11-18 19:52:14 +09001060// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -07001061func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +09001062 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001063}
1064
Colin Crossc511bc52020-04-07 16:50:32 +00001065func (c *Module) canUseSdk() bool {
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001066 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery() && !c.InVendorRamdisk()
Colin Crossc511bc52020-04-07 16:50:32 +00001067}
1068
1069func (c *Module) UseSdk() bool {
1070 if c.canUseSdk() {
Colin Cross1348ce32020-10-01 13:37:16 -07001071 return String(c.Properties.Sdk_version) != ""
Colin Crossc511bc52020-04-07 16:50:32 +00001072 }
1073 return false
1074}
1075
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001076func (c *Module) isCoverageVariant() bool {
1077 return c.coverage.Properties.IsCoverageVariant
1078}
1079
Colin Cross95f1ca02020-10-29 20:47:22 -07001080func (c *Module) IsNdk(config android.Config) bool {
1081 return inList(c.BaseModuleName(), *getNDKKnownLibs(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001082}
1083
Colin Cross127bb8b2020-12-16 16:46:01 -08001084// isLLndk returns true for both LLNDK (public) and LLNDK-private libs.
1085func (c *Module) IsLlndk() bool {
1086 return c.VendorProperties.IsLLNDK
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001087}
1088
Colin Cross127bb8b2020-12-16 16:46:01 -08001089// IsLlndkPublic returns true only for LLNDK (public) libs.
1090func (c *Module) IsLlndkPublic() bool {
1091 return c.VendorProperties.IsLLNDK && !c.VendorProperties.IsLLNDKPrivate
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001092}
1093
Colin Cross127bb8b2020-12-16 16:46:01 -08001094// isImplementationForLLNDKPublic returns true for any variant of a cc_library that has LLNDK stubs
1095// and does not set llndk.vendor_available: false.
1096func (c *Module) isImplementationForLLNDKPublic() bool {
1097 library, _ := c.library.(*libraryDecorator)
1098 return library != nil && library.hasLLNDKStubs() &&
Justin Yunc0d8c492021-01-07 17:45:31 +09001099 (!Bool(library.Properties.Llndk.Private) ||
Colin Cross127bb8b2020-12-16 16:46:01 -08001100 // TODO(b/170784825): until the LLNDK properties are moved into the cc_library,
1101 // the non-Vendor variants of the cc_library don't know if the corresponding
Justin Yunc0d8c492021-01-07 17:45:31 +09001102 // llndk_library set private: true. Since libft2 is the only private LLNDK
1103 // library, hardcode it during the transition.
Colin Cross127bb8b2020-12-16 16:46:01 -08001104 c.BaseModuleName() != "libft2")
1105}
1106
Justin Yunfd9e8042020-12-23 18:23:14 +09001107// Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Colin Cross127bb8b2020-12-16 16:46:01 -08001108func (c *Module) IsVndkPrivate() bool {
Justin Yunfd9e8042020-12-23 18:23:14 +09001109 // Check if VNDK-core-private or VNDK-SP-private
1110 if c.IsVndk() {
Justin Yunc0d8c492021-01-07 17:45:31 +09001111 return Bool(c.vndkdep.Properties.Vndk.Private)
Justin Yunfd9e8042020-12-23 18:23:14 +09001112 }
1113
1114 // Check if LLNDK-private
1115 if library, ok := c.library.(*libraryDecorator); ok && c.IsLlndk() {
Justin Yunc0d8c492021-01-07 17:45:31 +09001116 return Bool(library.Properties.Llndk.Private)
Justin Yunfd9e8042020-12-23 18:23:14 +09001117 }
1118
1119 return false
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001120}
1121
Ivan Lozano52767be2019-10-18 14:49:46 -07001122func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001123 if vndkdep := c.vndkdep; vndkdep != nil {
1124 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001125 }
1126 return false
1127}
1128
Yi Kong7e53c572018-02-14 18:16:12 +08001129func (c *Module) isPgoCompile() bool {
1130 if pgo := c.pgo; pgo != nil {
1131 return pgo.Properties.PgoCompile
1132 }
1133 return false
1134}
1135
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001136func (c *Module) isNDKStubLibrary() bool {
1137 if _, ok := c.compiler.(*stubDecorator); ok {
1138 return true
1139 }
1140 return false
1141}
1142
Logan Chienf3511742017-10-31 18:04:35 +08001143func (c *Module) isVndkSp() bool {
1144 if vndkdep := c.vndkdep; vndkdep != nil {
1145 return vndkdep.isVndkSp()
1146 }
1147 return false
1148}
1149
Ivan Lozanof9e21722020-12-02 09:00:51 -05001150func (c *Module) IsVndkExt() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001151 if vndkdep := c.vndkdep; vndkdep != nil {
1152 return vndkdep.isVndkExt()
1153 }
1154 return false
1155}
1156
Ivan Lozano52767be2019-10-18 14:49:46 -07001157func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001158 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001159}
1160
Logan Chienf3511742017-10-31 18:04:35 +08001161func (c *Module) getVndkExtendsModuleName() string {
1162 if vndkdep := c.vndkdep; vndkdep != nil {
1163 return vndkdep.getVndkExtendsModuleName()
1164 }
1165 return ""
1166}
1167
Jiyong Park25fc6a92018-11-18 18:02:45 +09001168func (c *Module) IsStubs() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001169 if lib := c.library; lib != nil {
1170 return lib.buildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001171 }
1172 return false
1173}
1174
1175func (c *Module) HasStubsVariants() bool {
Colin Cross31076b32020-10-23 17:22:06 -07001176 if lib := c.library; lib != nil {
1177 return lib.hasStubsVariants()
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001178 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001179 return false
1180}
1181
Colin Cross0477b422020-10-13 18:43:54 -07001182// If this is a stubs library, ImplementationModuleName returns the name of the module that contains
1183// the implementation. If it is an implementation library it returns its own name.
1184func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string {
1185 name := ctx.OtherModuleName(c)
1186 if versioned, ok := c.linker.(versionedInterface); ok {
1187 name = versioned.implementationModuleName(name)
1188 }
1189 return name
1190}
1191
Martin Stjernholm2856c662020-12-02 15:03:42 +00001192// Similar to ImplementationModuleName, but uses the Make variant of the module
1193// name as base name, for use in AndroidMk output. E.g. for a prebuilt module
1194// where the Soong name is prebuilt_foo, this returns foo (which works in Make
1195// under the premise that the prebuilt module overrides its source counterpart
1196// if it is exposed to Make).
1197func (c *Module) ImplementationModuleNameForMake(ctx android.BaseModuleContext) string {
1198 name := c.BaseModuleName()
1199 if versioned, ok := c.linker.(versionedInterface); ok {
1200 name = versioned.implementationModuleName(name)
1201 }
1202 return name
1203}
1204
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001205func (c *Module) bootstrap() bool {
1206 return Bool(c.Properties.Bootstrap)
1207}
1208
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001209func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001210 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1211 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1212 return false
1213 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001214 return c.linker != nil && c.linker.nativeCoverage()
1215}
1216
Inseob Kim8471cda2019-11-15 09:59:12 +09001217func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001218 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1219 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001220 }
1221 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001222}
1223
Bill Peckham945441c2020-08-31 16:07:58 -07001224func (c *Module) ExcludeFromVendorSnapshot() bool {
1225 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1226}
1227
Jose Galmesf7294582020-11-13 12:07:36 -08001228func (c *Module) ExcludeFromRecoverySnapshot() bool {
1229 return Bool(c.Properties.Exclude_from_recovery_snapshot)
1230}
1231
Jiyong Parkf1194352019-02-25 11:05:47 +09001232func isBionic(name string) bool {
1233 switch name {
Kiyoung Kim4098c7e2020-11-30 14:42:14 +09001234 case "libc", "libm", "libdl", "libdl_android", "linker", "linkerconfig":
Jiyong Parkf1194352019-02-25 11:05:47 +09001235 return true
1236 }
1237 return false
1238}
1239
Martin Stjernholm279de572019-09-10 23:18:20 +01001240func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001241 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001242 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001243 }
1244 return isBionic(name)
1245}
1246
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001247func (c *Module) XrefCcFiles() android.Paths {
1248 return c.kytheFiles
1249}
1250
Colin Crossca860ac2016-01-04 14:34:37 -08001251type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001252 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001253 moduleContextImpl
1254}
1255
Colin Cross37047f12016-12-13 17:06:13 -08001256type depsContext struct {
1257 android.BottomUpMutatorContext
1258 moduleContextImpl
1259}
1260
Colin Crossca860ac2016-01-04 14:34:37 -08001261type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001262 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001263 moduleContextImpl
1264}
1265
1266type moduleContextImpl struct {
1267 mod *Module
1268 ctx BaseModuleContext
1269}
1270
Colin Crossb98c8b02016-07-29 13:44:28 -07001271func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001272 return ctx.mod.toolchain(ctx.ctx)
1273}
1274
1275func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001276 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001277}
1278
1279func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001280 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001281}
1282
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07001283func (ctx *moduleContextImpl) testBinary() bool {
1284 return ctx.mod.testBinary()
1285}
1286
Jiyong Park1d1119f2019-07-29 21:27:18 +09001287func (ctx *moduleContextImpl) header() bool {
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001288 return ctx.mod.Header()
Jiyong Park1d1119f2019-07-29 21:27:18 +09001289}
1290
Inseob Kim7f283f42020-06-01 21:53:49 +09001291func (ctx *moduleContextImpl) binary() bool {
1292 return ctx.mod.binary()
1293}
1294
Inseob Kim1042d292020-06-01 23:23:05 +09001295func (ctx *moduleContextImpl) object() bool {
1296 return ctx.mod.object()
1297}
1298
Jooyung Hanccce2f22020-03-07 03:45:53 +09001299func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001300 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001301}
1302
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001303func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001304 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001305}
1306
1307func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001308 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001309 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001310 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001311 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001312 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001313 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001314 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001315 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001316 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001317 }
1318 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001319}
1320
Jiyong Parkb35a8192020-08-10 15:59:36 +09001321func (ctx *moduleContextImpl) minSdkVersion() string {
1322 ver := ctx.mod.MinSdkVersion()
1323 if ver == "apex_inherit" && !ctx.isForPlatform() {
1324 ver = ctx.apexSdkVersion().String()
1325 }
1326 if ver == "apex_inherit" || ver == "" {
1327 ver = ctx.sdkVersion()
1328 }
1329 // Also make sure that minSdkVersion is not greater than sdkVersion, if they are both numbers
1330 sdkVersionInt, err := strconv.Atoi(ctx.sdkVersion())
1331 minSdkVersionInt, err2 := strconv.Atoi(ver)
1332 if err == nil && err2 == nil {
1333 if sdkVersionInt < minSdkVersionInt {
1334 return strconv.Itoa(sdkVersionInt)
1335 }
1336 }
1337 return ver
1338}
1339
1340func (ctx *moduleContextImpl) isSdkVariant() bool {
1341 return ctx.mod.IsSdkVariant()
1342}
1343
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001344func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001345 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001346}
Justin Yun8effde42017-06-23 19:24:43 +09001347
Colin Cross95f1ca02020-10-29 20:47:22 -07001348func (ctx *moduleContextImpl) isNdk(config android.Config) bool {
1349 return ctx.mod.IsNdk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001350}
1351
Colin Cross127bb8b2020-12-16 16:46:01 -08001352func (ctx *moduleContextImpl) IsLlndk() bool {
1353 return ctx.mod.IsLlndk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001354}
1355
Colin Cross127bb8b2020-12-16 16:46:01 -08001356func (ctx *moduleContextImpl) IsLlndkPublic() bool {
1357 return ctx.mod.IsLlndkPublic()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001358}
1359
Colin Cross127bb8b2020-12-16 16:46:01 -08001360func (ctx *moduleContextImpl) isImplementationForLLNDKPublic() bool {
1361 return ctx.mod.isImplementationForLLNDKPublic()
1362}
1363
1364func (ctx *moduleContextImpl) IsVndkPrivate() bool {
1365 return ctx.mod.IsVndkPrivate()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001366}
1367
Logan Chienf3511742017-10-31 18:04:35 +08001368func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001369 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001370}
1371
Yi Kong7e53c572018-02-14 18:16:12 +08001372func (ctx *moduleContextImpl) isPgoCompile() bool {
1373 return ctx.mod.isPgoCompile()
1374}
1375
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001376func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1377 return ctx.mod.isNDKStubLibrary()
1378}
1379
Justin Yun8effde42017-06-23 19:24:43 +09001380func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001381 return ctx.mod.isVndkSp()
1382}
1383
Ivan Lozanof9e21722020-12-02 09:00:51 -05001384func (ctx *moduleContextImpl) IsVndkExt() bool {
1385 return ctx.mod.IsVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001386}
1387
Vic Yangefd249e2018-11-12 20:19:56 -08001388func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001389 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001390}
1391
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001392func (ctx *moduleContextImpl) selectedStl() string {
1393 if stl := ctx.mod.stl; stl != nil {
1394 return stl.Properties.SelectedStl
1395 }
1396 return ""
1397}
1398
Ivan Lozanobd721262018-11-27 14:33:03 -08001399func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1400 return ctx.mod.linker.useClangLld(actx)
1401}
1402
Colin Crossce75d2c2016-10-06 16:12:58 -07001403func (ctx *moduleContextImpl) baseModuleName() string {
1404 return ctx.mod.ModuleBase.BaseModuleName()
1405}
1406
Logan Chienf3511742017-10-31 18:04:35 +08001407func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1408 return ctx.mod.getVndkExtendsModuleName()
1409}
1410
Logan Chiene274fc92019-12-03 11:18:32 -08001411func (ctx *moduleContextImpl) isForPlatform() bool {
Colin Cross56a83212020-09-15 18:30:11 -07001412 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).IsForPlatform()
Logan Chiene274fc92019-12-03 11:18:32 -08001413}
1414
Colin Crosse07f2312020-08-13 11:24:56 -07001415func (ctx *moduleContextImpl) apexVariationName() string {
Colin Cross56a83212020-09-15 18:30:11 -07001416 return ctx.ctx.Provider(android.ApexInfoProvider).(android.ApexInfo).ApexVariationName
Jiyong Park25fc6a92018-11-18 18:02:45 +09001417}
1418
Dan Albertc8060532020-07-22 22:32:17 -07001419func (ctx *moduleContextImpl) apexSdkVersion() android.ApiLevel {
Jooyung Han75568392020-03-20 04:29:24 +09001420 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001421}
1422
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001423func (ctx *moduleContextImpl) bootstrap() bool {
1424 return ctx.mod.bootstrap()
1425}
1426
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001427func (ctx *moduleContextImpl) nativeCoverage() bool {
1428 return ctx.mod.nativeCoverage()
1429}
1430
Colin Cross56a83212020-09-15 18:30:11 -07001431func (ctx *moduleContextImpl) directlyInAnyApex() bool {
1432 return ctx.mod.DirectlyInAnyApex()
1433}
1434
Colin Cross95b07f22020-12-16 11:06:50 -08001435func (ctx *moduleContextImpl) isPreventInstall() bool {
1436 return ctx.mod.Properties.PreventInstall
1437}
1438
Colin Cross635c3b02016-05-18 15:37:25 -07001439func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001440 return &Module{
1441 hod: hod,
1442 multilib: multilib,
1443 }
1444}
1445
Colin Cross635c3b02016-05-18 15:37:25 -07001446func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001447 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001448 module.features = []feature{
1449 &tidyFeature{},
1450 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001451 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001452 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001453 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001454 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001455 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001456 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001457 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001458 return module
1459}
1460
Colin Crossce75d2c2016-10-06 16:12:58 -07001461func (c *Module) Prebuilt() *android.Prebuilt {
1462 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1463 return p.prebuilt()
1464 }
1465 return nil
1466}
1467
Ivan Lozano3968d8f2020-12-14 11:27:52 -05001468func (c *Module) IsPrebuilt() bool {
1469 return c.Prebuilt() != nil
1470}
1471
Colin Crossce75d2c2016-10-06 16:12:58 -07001472func (c *Module) Name() string {
1473 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001474 if p, ok := c.linker.(interface {
1475 Name(string) string
1476 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001477 name = p.Name(name)
1478 }
1479 return name
1480}
1481
Alex Light3d673592019-01-18 14:37:31 -08001482func (c *Module) Symlinks() []string {
1483 if p, ok := c.installer.(interface {
1484 symlinkList() []string
1485 }); ok {
1486 return p.symlinkList()
1487 }
1488 return nil
1489}
1490
Roland Levillainf89cd092019-07-29 16:22:59 +01001491func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1492 test, ok := c.linker.(testPerSrc)
1493 return ok && test.isAllTestsVariation()
1494}
1495
Chris Parsons216e10a2020-07-09 17:12:52 -04001496func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001497 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001498 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001499 }); ok {
1500 return p.dataPaths()
1501 }
1502 return nil
1503}
1504
Justin Yun5f7f7e82019-11-18 19:52:14 +09001505func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1506 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1507 // "current", it will append the VNDK version to the name suffix.
1508 var vndkVersion string
1509 var nameSuffix string
Ivan Lozanof9e21722020-12-02 09:00:51 -05001510 if c.InProduct() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001511 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1512 nameSuffix = productSuffix
1513 } else {
1514 vndkVersion = ctx.DeviceConfig().VndkVersion()
1515 nameSuffix = vendorSuffix
1516 }
1517 if vndkVersion == "current" {
1518 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1519 }
Colin Cross127bb8b2020-12-16 16:46:01 -08001520 if c.Properties.VndkVersion != vndkVersion && c.Properties.VndkVersion != "" {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001521 // add version suffix only if the module is using different vndk version than the
1522 // version in product or vendor partition.
1523 nameSuffix += "." + c.Properties.VndkVersion
1524 }
1525 return nameSuffix
1526}
1527
Colin Cross635c3b02016-05-18 15:37:25 -07001528func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001529 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001530 //
1531 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1532 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1533 // module and return early, as this module does not produce an output file per se.
1534 if c.IsTestPerSrcAllTestsVariation() {
1535 c.outputFile = android.OptionalPath{}
1536 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001537 }
1538
Colin Cross56a83212020-09-15 18:30:11 -07001539 apexInfo := actx.Provider(android.ApexInfoProvider).(android.ApexInfo)
1540 if !apexInfo.IsForPlatform() {
1541 c.hideApexVariantFromMake = true
1542 }
1543
Ivan Lozanof9e21722020-12-02 09:00:51 -05001544 c.makeLinkType = GetMakeLinkType(actx, c)
Inseob Kim9516ee92019-05-09 10:56:13 +09001545
Inseob Kim64c43952019-08-26 16:52:35 +09001546 c.Properties.SubName = ""
1547
1548 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1549 c.Properties.SubName += nativeBridgeSuffix
1550 }
1551
Colin Cross127bb8b2020-12-16 16:46:01 -08001552 llndk := c.IsLlndk()
Justin Yun5f7f7e82019-11-18 19:52:14 +09001553 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
Justin Yun63e9ec72020-10-29 16:49:43 +09001554 if llndk || llndkHeader || (c.UseVndk() && c.HasNonSystemVariants()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001555 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1556 // added for product variant only when we have vendor and product variants with core
1557 // variant. The suffix is not added for vendor-only or product-only module.
1558 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1559 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001560 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1561 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1562 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001563 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1564 c.Properties.SubName += ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001565 } else if c.InVendorRamdisk() && !c.OnlyInVendorRamdisk() {
1566 c.Properties.SubName += vendorRamdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001567 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001568 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001569 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001570 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001571 if c.SplitPerApiLevel() {
1572 c.Properties.SubName += "." + c.SdkVersion()
1573 }
Inseob Kim64c43952019-08-26 16:52:35 +09001574 }
1575
Colin Crossca860ac2016-01-04 14:34:37 -08001576 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001577 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001578 moduleContextImpl: moduleContextImpl{
1579 mod: c,
1580 },
1581 }
1582 ctx.ctx = ctx
1583
Colin Crossf18e1102017-11-16 14:33:08 -08001584 deps := c.depsToPaths(ctx)
1585 if ctx.Failed() {
1586 return
1587 }
1588
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001589 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1590 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1591 }
1592
Colin Crossca860ac2016-01-04 14:34:37 -08001593 flags := Flags{
1594 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001595 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001596 }
Colin Crossca860ac2016-01-04 14:34:37 -08001597 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001598 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001599 }
1600 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001601 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001602 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001603 if c.stl != nil {
1604 flags = c.stl.flags(ctx, flags)
1605 }
Colin Cross16b23492016-01-06 14:41:07 -08001606 if c.sanitize != nil {
1607 flags = c.sanitize.flags(ctx, flags)
1608 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001609 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001610 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001611 }
Stephen Craneba090d12017-05-09 15:44:35 -07001612 if c.lto != nil {
1613 flags = c.lto.flags(ctx, flags)
1614 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001615 if c.pgo != nil {
1616 flags = c.pgo.flags(ctx, flags)
1617 }
Colin Crossca860ac2016-01-04 14:34:37 -08001618 for _, feature := range c.features {
1619 flags = feature.flags(ctx, flags)
1620 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001621 if ctx.Failed() {
1622 return
1623 }
1624
Colin Cross4af21ed2019-11-04 09:37:55 -08001625 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1626 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1627 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001628
Colin Cross4af21ed2019-11-04 09:37:55 -08001629 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001630
1631 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001632 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001633 }
1634 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001635 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001636 }
1637
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001638 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001639 // We need access to all the flags seen by a source file.
1640 if c.sabi != nil {
1641 flags = c.sabi.flags(ctx, flags)
1642 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001643
Colin Cross4af21ed2019-11-04 09:37:55 -08001644 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001645
Colin Crossca860ac2016-01-04 14:34:37 -08001646 // Optimization to reduce size of build.ninja
1647 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001648 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1649 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1650 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1651 flags.Local.CFlags = []string{"$cflags"}
1652 flags.Local.CppFlags = []string{"$cppflags"}
1653 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001654
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001655 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001656 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001657 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001658 if ctx.Failed() {
1659 return
1660 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001661 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001662 }
1663
Colin Crossca860ac2016-01-04 14:34:37 -08001664 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001665 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001666 if ctx.Failed() {
1667 return
1668 }
Colin Cross635c3b02016-05-18 15:37:25 -07001669 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001670
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09001671 // If a lib is directly included in any of the APEXes or is not available to the
1672 // platform (which is often the case when the stub is provided as a prebuilt),
1673 // unhide the stubs variant having the latest version gets visible to make. In
1674 // addition, the non-stubs variant is renamed to <libname>.bootstrap. This is to
1675 // force anything in the make world to link against the stubs library. (unless it
1676 // is explicitly referenced via .bootstrap suffix or the module is marked with
1677 // 'bootstrap: true').
1678 if c.HasStubsVariants() && c.NotInPlatform() && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001679 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Yifan Hong60e0cfb2020-10-21 15:17:56 -07001680 c.IsStubs() && !c.InVendorRamdisk() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001681 c.Properties.HideFromMake = false // unhide
1682 // Note: this is still non-installable
1683 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001684
Jose Galmes6f843bc2020-12-11 13:36:29 -08001685 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current or
1686 // RECOVERY_SNAPSHOT_VERSION is current.
1687 if i, ok := c.linker.(snapshotLibraryInterface); ok {
Inseob Kimde5744a2020-12-02 13:14:28 +09001688 if shouldCollectHeadersForSnapshot(ctx, c, apexInfo) {
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001689 i.collectHeadersForSnapshot(ctx)
1690 }
1691 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001692 }
Colin Cross5049f022015-03-18 13:28:46 -07001693
Colin Crossa9c8c9f2020-12-16 10:20:23 -08001694 if !proptools.BoolDefault(c.Properties.Installable, true) {
1695 // If the module has been specifically configure to not be installed then
1696 // hide from make as otherwise it will break when running inside make
1697 // as the output path to install will not be specified. Not all uninstallable
1698 // modules can be hidden from make as some are needed for resolving make side
1699 // dependencies.
1700 c.HideFromMake()
1701 } else if !c.installable(apexInfo) {
1702 c.SkipInstall()
1703 }
1704
1705 // Still call c.installer.install though, the installs will be stored as PackageSpecs
1706 // to allow using the outputs in a genrule.
1707 if c.installer != nil && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001708 c.installer.install(ctx, c.outputFile.Path())
1709 if ctx.Failed() {
1710 return
Colin Crossca860ac2016-01-04 14:34:37 -08001711 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001712 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001713}
1714
Colin Cross0ea8ba82019-06-06 14:33:29 -07001715func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001716 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001717 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001718 }
Colin Crossca860ac2016-01-04 14:34:37 -08001719 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001720}
1721
Colin Crossca860ac2016-01-04 14:34:37 -08001722func (c *Module) begin(ctx BaseModuleContext) {
1723 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001724 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001725 }
Colin Crossca860ac2016-01-04 14:34:37 -08001726 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001727 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001728 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001729 if c.stl != nil {
1730 c.stl.begin(ctx)
1731 }
Colin Cross16b23492016-01-06 14:41:07 -08001732 if c.sanitize != nil {
1733 c.sanitize.begin(ctx)
1734 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001735 if c.coverage != nil {
1736 c.coverage.begin(ctx)
1737 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001738 if c.sabi != nil {
1739 c.sabi.begin(ctx)
1740 }
Justin Yun8effde42017-06-23 19:24:43 +09001741 if c.vndkdep != nil {
1742 c.vndkdep.begin(ctx)
1743 }
Stephen Craneba090d12017-05-09 15:44:35 -07001744 if c.lto != nil {
1745 c.lto.begin(ctx)
1746 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001747 if c.pgo != nil {
1748 c.pgo.begin(ctx)
1749 }
Colin Crossca860ac2016-01-04 14:34:37 -08001750 for _, feature := range c.features {
1751 feature.begin(ctx)
1752 }
Dan Albert92fe7402020-07-15 13:33:30 -07001753 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albert1a246272020-07-06 14:49:35 -07001754 version, err := nativeApiLevelFromUser(ctx, ctx.sdkVersion())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001755 if err != nil {
1756 ctx.PropertyErrorf("sdk_version", err.Error())
Dan Albert1a246272020-07-06 14:49:35 -07001757 c.Properties.Sdk_version = nil
1758 } else {
1759 c.Properties.Sdk_version = StringPtr(version.String())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001760 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001761 }
Colin Crossca860ac2016-01-04 14:34:37 -08001762}
1763
Colin Cross37047f12016-12-13 17:06:13 -08001764func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001765 deps := Deps{}
1766
1767 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001768 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001769 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001770 // Add the PGO dependency (the clang_rt.profile runtime library), which
1771 // sometimes depends on symbols from libgcc, before libgcc gets added
1772 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001773 if c.pgo != nil {
1774 deps = c.pgo.deps(ctx, deps)
1775 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001776 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001777 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001778 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001779 if c.stl != nil {
1780 deps = c.stl.deps(ctx, deps)
1781 }
Colin Cross16b23492016-01-06 14:41:07 -08001782 if c.sanitize != nil {
1783 deps = c.sanitize.deps(ctx, deps)
1784 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001785 if c.coverage != nil {
1786 deps = c.coverage.deps(ctx, deps)
1787 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001788 if c.sabi != nil {
1789 deps = c.sabi.deps(ctx, deps)
1790 }
Justin Yun8effde42017-06-23 19:24:43 +09001791 if c.vndkdep != nil {
1792 deps = c.vndkdep.deps(ctx, deps)
1793 }
Stephen Craneba090d12017-05-09 15:44:35 -07001794 if c.lto != nil {
1795 deps = c.lto.deps(ctx, deps)
1796 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001797 for _, feature := range c.features {
1798 deps = feature.deps(ctx, deps)
1799 }
1800
Colin Crossb6715442017-10-24 11:13:31 -07001801 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1802 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1803 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1804 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1805 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1806 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001807 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001808
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001809 for _, lib := range deps.ReexportSharedLibHeaders {
1810 if !inList(lib, deps.SharedLibs) {
1811 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1812 }
1813 }
1814
1815 for _, lib := range deps.ReexportStaticLibHeaders {
1816 if !inList(lib, deps.StaticLibs) {
1817 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1818 }
1819 }
1820
Colin Cross5950f382016-12-13 12:50:57 -08001821 for _, lib := range deps.ReexportHeaderLibHeaders {
1822 if !inList(lib, deps.HeaderLibs) {
1823 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1824 }
1825 }
1826
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001827 for _, gen := range deps.ReexportGeneratedHeaders {
1828 if !inList(gen, deps.GeneratedHeaders) {
1829 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1830 }
1831 }
1832
Colin Crossc99deeb2016-04-11 15:06:20 -07001833 return deps
1834}
1835
Dan Albert7e9d2952016-08-04 13:02:36 -07001836func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001837 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001838 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001839 moduleContextImpl: moduleContextImpl{
1840 mod: c,
1841 },
1842 }
1843 ctx.ctx = ctx
1844
Colin Crossca860ac2016-01-04 14:34:37 -08001845 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001846}
1847
Jiyong Park7ed9de32018-10-15 22:25:07 +09001848// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001849func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001850 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1851 version := name[sharp+1:]
1852 libname := name[:sharp]
1853 return libname, version
1854 }
1855 return name, ""
1856}
1857
Dan Albert92fe7402020-07-15 13:33:30 -07001858func GetCrtVariations(ctx android.BottomUpMutatorContext,
1859 m LinkableInterface) []blueprint.Variation {
1860 if ctx.Os() != android.Android {
1861 return nil
1862 }
1863 if m.UseSdk() {
1864 return []blueprint.Variation{
1865 {Mutator: "sdk", Variation: "sdk"},
Colin Crossbbc941b2020-09-30 12:27:01 -07001866 {Mutator: "version", Variation: m.SdkVersion()},
Dan Albert92fe7402020-07-15 13:33:30 -07001867 }
1868 }
1869 return []blueprint.Variation{
1870 {Mutator: "sdk", Variation: ""},
1871 }
1872}
1873
Colin Crosse7257d22020-09-24 09:56:18 -07001874func (c *Module) addSharedLibDependenciesWithVersions(ctx android.BottomUpMutatorContext,
1875 variations []blueprint.Variation, depTag libraryDependencyTag, name, version string, far bool) {
1876
1877 variations = append([]blueprint.Variation(nil), variations...)
1878
Colin Cross3146c5c2020-09-30 15:34:40 -07001879 if version != "" && CanBeOrLinkAgainstVersionVariants(c) {
Colin Crosse7257d22020-09-24 09:56:18 -07001880 // Version is explicitly specified. i.e. libFoo#30
1881 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1882 depTag.explicitlyVersioned = true
1883 }
Colin Crosse7257d22020-09-24 09:56:18 -07001884
Colin Cross0de8a1e2020-09-18 14:15:30 -07001885 if far {
1886 ctx.AddFarVariationDependencies(variations, depTag, name)
1887 } else {
1888 ctx.AddVariationDependencies(variations, depTag, name)
Colin Crosse7257d22020-09-24 09:56:18 -07001889 }
1890}
1891
Colin Cross1e676be2016-10-12 14:38:15 -07001892func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001893 if !c.Enabled() {
1894 return
1895 }
1896
Colin Cross37047f12016-12-13 17:06:13 -08001897 ctx := &depsContext{
1898 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001899 moduleContextImpl: moduleContextImpl{
1900 mod: c,
1901 },
1902 }
1903 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001904
Colin Crossc99deeb2016-04-11 15:06:20 -07001905 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001906
Yo Chiang219968c2020-09-22 18:45:04 +08001907 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1908
Dan Albert914449f2016-06-17 16:45:24 -07001909 variantNdkLibs := []string{}
1910 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001911 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001912 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001913 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001914 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001915 // 1. Name of an NDK library that refers to a prebuilt module.
1916 // For each of these, it adds the name of the prebuilt module (which will be in
1917 // prebuilts/ndk) to the list of nonvariant libs.
1918 // 2. Name of an NDK library that refers to an ndk_library module.
1919 // For each of these, it adds the name of the ndk_library module to the list of
1920 // variant libs.
1921 // 3. Anything else (so anything that isn't an NDK library).
1922 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001923 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001924 // The caller can then know to add the variantLibs dependencies differently from the
1925 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001926
Inseob Kim9516ee92019-05-09 10:56:13 +09001927 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001928 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
Jose Galmes6f843bc2020-12-11 13:36:29 -08001929 recoverySnapshotSharedLibs := recoverySnapshotSharedLibs(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001930
1931 rewriteVendorLibs := func(lib string) string {
Inseob Kimeec88e12020-01-22 11:11:29 +09001932 // only modules with BOARD_VNDK_VERSION uses snapshot.
1933 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1934 return lib
1935 }
1936
1937 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1938 return snapshot
1939 }
1940
1941 return lib
1942 }
1943
1944 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001945 variantLibs = []string{}
1946 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001947 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001948 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001949 name, _ := StubsLibNameAndVersion(entry)
Jose Galmes6f843bc2020-12-11 13:36:29 -08001950 if c.InRecovery() {
1951 recoverySnapshotVersion :=
1952 actx.DeviceConfig().RecoverySnapshotVersion()
1953 if recoverySnapshotVersion == "current" ||
1954 recoverySnapshotVersion == "" {
1955 nonvariantLibs = append(nonvariantLibs, name)
1956 } else if snapshot, ok := recoverySnapshotSharedLibs.get(
1957 name, actx.Arch().ArchType); ok {
1958 nonvariantLibs = append(nonvariantLibs, snapshot)
1959 } else {
1960 nonvariantLibs = append(nonvariantLibs, name)
1961 }
1962 } else if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) {
Dan Albertde5aade2020-06-30 12:32:51 -07001963 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001964 } else if ctx.useVndk() {
1965 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001966 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001967 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001968 if actx.OtherModuleExists(vendorPublicLib) {
1969 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1970 } else {
1971 // This can happen if vendor_public_library module is defined in a
1972 // namespace that isn't visible to the current module. In that case,
1973 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001974 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001975 }
Dan Albert914449f2016-06-17 16:45:24 -07001976 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001977 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001978 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001979 }
1980 }
Dan Albert914449f2016-06-17 16:45:24 -07001981 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001982 }
1983
Inseob Kimeec88e12020-01-22 11:11:29 +09001984 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1985 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1986 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1987 if ctx.useVndk() {
1988 for idx, lib := range deps.RuntimeLibs {
1989 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1990 }
1991 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001992 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001993
Inseob Kimeec88e12020-01-22 11:11:29 +09001994 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1995 // only modules with BOARD_VNDK_VERSION uses snapshot.
1996 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1997 return lib
1998 }
1999
2000 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
2001 return snapshot
2002 }
2003
2004 return lib
2005 }
2006
Jose Galmes6f843bc2020-12-11 13:36:29 -08002007 snapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
2008 snapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
2009 snapshotObjects := vendorSnapshotObjects(actx.Config())
2010
2011 if c.InRecovery() {
2012 rewriteSnapshotLibs = func(lib string, snapshotMap *snapshotMap) string {
2013 recoverySnapshotVersion :=
2014 actx.DeviceConfig().RecoverySnapshotVersion()
2015 if recoverySnapshotVersion == "current" ||
2016 recoverySnapshotVersion == "" {
2017 return lib
2018 } else if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
2019 return snapshot
2020 }
2021
2022 return lib
2023 }
2024
2025 snapshotHeaderLibs = recoverySnapshotHeaderLibs(actx.Config())
2026 snapshotStaticLibs = recoverySnapshotStaticLibs(actx.Config())
2027 snapshotObjects = recoverySnapshotObjects(actx.Config())
2028 }
2029
Colin Cross32ec36c2016-12-15 07:39:51 -08002030 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002031 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08002032 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002033 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08002034 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002035
Jose Galmes6f843bc2020-12-11 13:36:29 -08002036 lib = rewriteSnapshotLibs(lib, snapshotHeaderLibs)
Inseob Kimeec88e12020-01-22 11:11:29 +09002037
Jiyong Park1ad8e162020-12-01 23:40:09 +09002038 if c.IsStubs() {
Colin Cross7228ecd2019-11-18 16:00:16 -08002039 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07002040 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09002041 } else {
2042 actx.AddVariationDependencies(nil, depTag, lib)
2043 }
2044 }
2045
Inseob Kim07def122020-11-23 14:43:02 +09002046 // sysprop_library has to support both C++ and Java. So sysprop_library internally creates one
2047 // C++ implementation library and one Java implementation library. When a module links against
2048 // sysprop_library, the C++ implementation library has to be linked. syspropImplLibraries is a
2049 // map from sysprop_library to implementation library; it will be used in whole_static_libs,
2050 // static_libs, and shared_libs.
Inseob Kimc0907f12019-02-08 21:00:45 +09002051 syspropImplLibraries := syspropImplLibraries(actx.Config())
2052
Jiyong Park5d1598f2019-02-25 22:14:17 +09002053 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002054 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09002055 if impl, ok := syspropImplLibraries[lib]; ok {
2056 lib = impl
2057 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002058
Jose Galmes6f843bc2020-12-11 13:36:29 -08002059 lib = rewriteSnapshotLibs(lib, snapshotStaticLibs)
Inseob Kimeec88e12020-01-22 11:11:29 +09002060
Jiyong Park5d1598f2019-02-25 22:14:17 +09002061 actx.AddVariationDependencies([]blueprint.Variation{
2062 {Mutator: "link", Variation: "static"},
2063 }, depTag, lib)
2064 }
2065
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002066 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002067 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002068 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002069 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002070 }
Jiyong Parke3867542020-12-03 17:28:25 +09002071 if inList(lib, deps.ExcludeLibsForApex) {
2072 depTag.excludeInApex = true
2073 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002074
2075 if impl, ok := syspropImplLibraries[lib]; ok {
2076 lib = impl
2077 }
2078
Jose Galmes6f843bc2020-12-11 13:36:29 -08002079 lib = rewriteSnapshotLibs(lib, snapshotStaticLibs)
Inseob Kimeec88e12020-01-22 11:11:29 +09002080
Dan Willemsen59339a22018-07-22 21:18:45 -07002081 actx.AddVariationDependencies([]blueprint.Variation{
2082 {Mutator: "link", Variation: "static"},
2083 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002084 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002085
Jooyung Han75568392020-03-20 04:29:24 +09002086 // staticUnwinderDep is treated as staticDep for Q apexes
2087 // so that native libraries/binaries are linked with static unwinder
2088 // because Q libc doesn't have unwinder APIs
2089 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07002090 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002091 actx.AddVariationDependencies([]blueprint.Variation{
2092 {Mutator: "link", Variation: "static"},
Jose Galmes6f843bc2020-12-11 13:36:29 -08002093 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), snapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002094 }
2095
Inseob Kimeec88e12020-01-22 11:11:29 +09002096 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002097 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09002098 actx.AddVariationDependencies([]blueprint.Variation{
2099 {Mutator: "link", Variation: "static"},
Jose Galmes6f843bc2020-12-11 13:36:29 -08002100 }, depTag, rewriteSnapshotLibs(lib, snapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09002101 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002102
Jiyong Park7ed9de32018-10-15 22:25:07 +09002103 // shared lib names without the #version suffix
2104 var sharedLibNames []string
2105
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002106 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002107 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002108 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002109 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002110 }
Jiyong Parke3867542020-12-03 17:28:25 +09002111 if inList(lib, deps.ExcludeLibsForApex) {
2112 depTag.excludeInApex = true
2113 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002114
2115 if impl, ok := syspropImplLibraries[lib]; ok {
2116 lib = impl
2117 }
2118
Jiyong Park73c54ee2019-10-22 20:31:18 +09002119 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002120 sharedLibNames = append(sharedLibNames, name)
2121
Colin Crosse7257d22020-09-24 09:56:18 -07002122 variations := []blueprint.Variation{
2123 {Mutator: "link", Variation: "shared"},
2124 }
2125 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, name, version, false)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002126 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002127
Jiyong Park7ed9de32018-10-15 22:25:07 +09002128 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002129 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002130 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2131 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2132 // linking against both the stubs lib and the non-stubs lib at the same time.
2133 continue
2134 }
Colin Cross6e511a92020-07-27 21:26:48 -07002135 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
Colin Crosse7257d22020-09-24 09:56:18 -07002136 variations := []blueprint.Variation{
2137 {Mutator: "link", Variation: "shared"},
2138 }
2139 c.addSharedLibDependenciesWithVersions(ctx, variations, depTag, lib, "", false)
Jiyong Park7ed9de32018-10-15 22:25:07 +09002140 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002141
Dan Willemsen59339a22018-07-22 21:18:45 -07002142 actx.AddVariationDependencies([]blueprint.Variation{
2143 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002144 }, dataLibDepTag, deps.DataLibs...)
2145
2146 actx.AddVariationDependencies([]blueprint.Variation{
2147 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002148 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002149
Colin Cross68861832016-07-08 10:41:41 -07002150 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002151
2152 for _, gen := range deps.GeneratedHeaders {
2153 depTag := genHeaderDepTag
2154 if inList(gen, deps.ReexportGeneratedHeaders) {
2155 depTag = genHeaderExportDepTag
2156 }
2157 actx.AddDependency(c, depTag, gen)
2158 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002159
Dan Albert92fe7402020-07-15 13:33:30 -07002160 crtVariations := GetCrtVariations(ctx, c)
Colin Crossbbc941b2020-09-30 12:27:01 -07002161 actx.AddVariationDependencies(crtVariations, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002162 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002163 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
Jose Galmes6f843bc2020-12-11 13:36:29 -08002164 rewriteSnapshotLibs(deps.CrtBegin, snapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002165 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002166 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002167 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
Jose Galmes6f843bc2020-12-11 13:36:29 -08002168 rewriteSnapshotLibs(deps.CrtEnd, snapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002169 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002170 if deps.LinkerFlagsFile != "" {
2171 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2172 }
2173 if deps.DynamicLinker != "" {
2174 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002175 }
Dan Albert914449f2016-06-17 16:45:24 -07002176
2177 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002178
2179 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002180 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002181 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002182 {Mutator: "link", Variation: "shared"},
2183 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002184
2185 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002186 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross5ec407b2020-09-30 11:41:33 -07002187 {Mutator: "version", Variation: version},
Dan Willemsen59339a22018-07-22 21:18:45 -07002188 {Mutator: "link", Variation: "shared"},
2189 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002190
2191 if vndkdep := c.vndkdep; vndkdep != nil {
2192 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002193 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002194 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002195 {Mutator: "link", Variation: "shared"},
2196 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002197 }
2198 }
Colin Cross6362e272015-10-29 15:25:03 -07002199}
Colin Cross21b9a242015-03-24 14:15:58 -07002200
Colin Crosse40b4ea2018-10-02 22:25:58 -07002201func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002202 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2203 c.beginMutator(ctx)
2204 }
2205}
2206
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002207// Whether a module can link to another module, taking into
2208// account NDK linking.
Jooyung Han479ca172020-10-19 18:51:07 +09002209func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
Colin Cross6e511a92020-07-27 21:26:48 -07002210 tag blueprint.DependencyTag) {
2211
2212 switch t := tag.(type) {
2213 case dependencyTag:
2214 if t != vndkExtDepTag {
2215 return
2216 }
2217 case libraryDependencyTag:
2218 default:
2219 return
2220 }
2221
Ivan Lozanof9e21722020-12-02 09:00:51 -05002222 if from.Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002223 // Host code is not restricted
2224 return
2225 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002226
2227 // VNDK is cc.Module supported only for now.
2228 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Justin Yun63e9ec72020-10-29 16:49:43 +09002229 // Though allowed dependency is limited by the image mutator,
2230 // each vendor and product module needs to check link-type
2231 // for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002232 if ccTo, ok := to.(*Module); ok {
2233 if ccFrom.vndkdep != nil {
2234 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2235 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05002236 } else if linkableMod, ok := to.(LinkableInterface); ok {
2237 // Static libraries from other languages can be linked
2238 if !linkableMod.Static() {
2239 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
2240 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002241 } else {
2242 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002243 }
2244 return
2245 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002246 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002247 // Platform code can link to anything
2248 return
2249 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002250 if from.InRamdisk() {
2251 // Ramdisk code is not NDK
2252 return
2253 }
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002254 if from.InVendorRamdisk() {
2255 // Vendor ramdisk code is not NDK
2256 return
2257 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002258 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002259 // Recovery code is not NDK
2260 return
2261 }
Colin Cross31076b32020-10-23 17:22:06 -07002262 if c, ok := to.(*Module); ok {
2263 if c.ToolchainLibrary() {
2264 // These are always allowed
2265 return
2266 }
2267 if c.NdkPrebuiltStl() {
2268 // These are allowed, but they don't set sdk_version
2269 return
2270 }
2271 if c.StubDecorator() {
2272 // These aren't real libraries, but are the stub shared libraries that are included in
2273 // the NDK.
2274 return
2275 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002276 }
Logan Chien834b9a62019-01-14 15:39:03 +08002277
Ivan Lozano52767be2019-10-18 14:49:46 -07002278 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002279 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2280 // to link to libc++ (non-NDK and without sdk_version).
2281 return
2282 }
2283
Ivan Lozano52767be2019-10-18 14:49:46 -07002284 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002285 // NDK code linking to platform code is never okay.
2286 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002287 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002288 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002289 }
2290
2291 // At this point we know we have two NDK libraries, but we need to
2292 // check that we're not linking against anything built against a higher
2293 // API level, as it is only valid to link against older or equivalent
2294 // APIs.
2295
Inseob Kim01a28722018-04-11 09:48:45 +09002296 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002297 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002298 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002299 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002300 // Current can't be linked against by anything else.
2301 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002302 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002303 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002304 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002305 if err != nil {
2306 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002307 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002308 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002309 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002310 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002311 if err != nil {
2312 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002313 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002314 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002315 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002316
Inseob Kim01a28722018-04-11 09:48:45 +09002317 if toApi > fromApi {
2318 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002319 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002320 }
2321 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002322 }
Dan Albert202fe492017-12-15 13:56:59 -08002323
2324 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002325 fromStl := from.SelectedStl()
2326 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002327 if fromStl == "" || toStl == "" {
2328 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002329 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002330 // We can be permissive with the system "STL" since it is only the C++
2331 // ABI layer, but in the future we should make sure that everyone is
2332 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002333 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002334 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002335 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2336 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002337 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002338}
2339
Jooyung Han479ca172020-10-19 18:51:07 +09002340func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
2341 if c, ok := ctx.Module().(*Module); ok {
2342 ctx.VisitDirectDeps(func(dep android.Module) {
2343 depTag := ctx.OtherModuleDependencyTag(dep)
2344 ccDep, ok := dep.(LinkableInterface)
2345 if ok {
2346 checkLinkType(ctx, c, ccDep, depTag)
2347 }
2348 })
2349 }
2350}
2351
Jiyong Park5fb8c102018-04-09 12:03:06 +09002352// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002353// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2354// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002355// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002356func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2357 check := func(child, parent android.Module) bool {
2358 to, ok := child.(*Module)
2359 if !ok {
Jooyung Han479ca172020-10-19 18:51:07 +09002360 return false
Jooyung Hana70f0672019-01-18 15:20:43 +09002361 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002362
Jooyung Hana70f0672019-01-18 15:20:43 +09002363 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2364 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002365 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002366
Jiyong Park1ad8e162020-12-01 23:40:09 +09002367 depTag := ctx.OtherModuleDependencyTag(child)
2368 if IsHeaderDepTag(depTag) {
2369 return false
2370 }
2371
Justin Yun63e9ec72020-10-29 16:49:43 +09002372 // Even if target lib has no vendor variant, keep checking dependency
2373 // graph in case it depends on vendor_available or product_available
2374 // but not double_loadable transtively.
2375 if !to.HasNonSystemVariants() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002376 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002377 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002378
Colin Cross127bb8b2020-12-16 16:46:01 -08002379 if to.isVndkSp() || to.IsLlndk() || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002380 return false
2381 }
2382
2383 var stringPath []string
2384 for _, m := range ctx.GetWalkPath() {
2385 stringPath = append(stringPath, m.Name())
2386 }
2387 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2388 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2389 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2390 return false
2391 }
2392 if module, ok := ctx.Module().(*Module); ok {
2393 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Colin Cross127bb8b2020-12-16 16:46:01 -08002394 if lib.hasLLNDKStubs() || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002395 ctx.WalkDeps(check)
2396 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002397 }
2398 }
2399}
2400
Colin Cross0de8a1e2020-09-18 14:15:30 -07002401// Returns the highest version which is <= maxSdkVersion.
2402// For example, with maxSdkVersion is 10 and versionList is [9,11]
2403// it returns 9 as string. The list of stubs must be in order from
2404// oldest to newest.
Chris Parsons3c27ca32020-11-20 12:42:07 -05002405func (c *Module) chooseSdkVersion(ctx android.PathContext, stubsInfo []SharedStubLibrary,
2406 maxSdkVersion android.ApiLevel) (SharedStubLibrary, error) {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002407
2408 for i := range stubsInfo {
2409 stubInfo := stubsInfo[len(stubsInfo)-i-1]
2410 var ver android.ApiLevel
2411 if stubInfo.Version == "" {
2412 ver = android.FutureApiLevel
2413 } else {
2414 var err error
2415 ver, err = android.ApiLevelFromUser(ctx, stubInfo.Version)
2416 if err != nil {
Chris Parsons3c27ca32020-11-20 12:42:07 -05002417 return SharedStubLibrary{}, err
Colin Cross0de8a1e2020-09-18 14:15:30 -07002418 }
2419 }
2420 if ver.LessThanOrEqualTo(maxSdkVersion) {
2421 return stubInfo, nil
2422 }
2423 }
2424 var versionList []string
2425 for _, stubInfo := range stubsInfo {
2426 versionList = append(versionList, stubInfo.Version)
2427 }
Chris Parsons3c27ca32020-11-20 12:42:07 -05002428 return SharedStubLibrary{}, fmt.Errorf("not found a version(<=%s) in versionList: %v", maxSdkVersion.String(), versionList)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002429}
2430
Colin Crossc99deeb2016-04-11 15:06:20 -07002431// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002432func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002433 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002434
Colin Cross0de8a1e2020-09-18 14:15:30 -07002435 var directStaticDeps []StaticLibraryInfo
2436 var directSharedDeps []SharedLibraryInfo
Jeff Gaston294356f2017-09-27 17:05:30 -07002437
Colin Cross0de8a1e2020-09-18 14:15:30 -07002438 reexportExporter := func(exporter FlagExporterInfo) {
2439 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.IncludeDirs...)
2440 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.SystemIncludeDirs...)
2441 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.Flags...)
2442 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.Deps...)
2443 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.GeneratedHeaders...)
Inseob Kim69378442019-06-03 19:10:47 +09002444 }
2445
Jooyung Hande34d232020-07-23 13:04:15 +09002446 // For the dependency from platform to apex, use the latest stubs
2447 c.apexSdkVersion = android.FutureApiLevel
Colin Cross56a83212020-09-15 18:30:11 -07002448 apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
2449 if !apexInfo.IsForPlatform() {
2450 c.apexSdkVersion = apexInfo.MinSdkVersion(ctx)
Jooyung Hande34d232020-07-23 13:04:15 +09002451 }
2452
2453 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2454 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2455 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2456 // (b/144430859)
2457 c.apexSdkVersion = android.FutureApiLevel
2458 }
2459
Colin Crossd11fcda2017-10-23 17:59:01 -07002460 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002461 depName := ctx.OtherModuleName(dep)
2462 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002463
Ivan Lozano52767be2019-10-18 14:49:46 -07002464 ccDep, ok := dep.(LinkableInterface)
2465 if !ok {
2466
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002467 // handling for a few module types that aren't cc Module but that are also supported
2468 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002469 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002470 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002471 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2472 genRule.GeneratedSourceFiles()...)
2473 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002474 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002475 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002476 // Support exported headers from a generated_sources dependency
2477 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002478 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002479 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002480 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002481 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002482 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002483 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002484 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002485 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002486 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2487 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002488 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002489 // 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 +09002490 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002491
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002492 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002493 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002494 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002495 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002496 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002497 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002498 files := genRule.GeneratedSourceFiles()
2499 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002500 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002501 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002502 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 -07002503 }
2504 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002505 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002506 }
Colin Crossca860ac2016-01-04 14:34:37 -08002507 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002508 return
2509 }
2510
Colin Crossfe17f6f2019-03-28 19:30:56 -07002511 if depTag == android.ProtoPluginDepTag {
2512 return
2513 }
2514
Colin Crossd11fcda2017-10-23 17:59:01 -07002515 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002516 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2517 return
2518 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002519 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002520 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2521 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002522 return
2523 }
2524
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002525 if depTag == reuseObjTag {
Colin Crossa717db72020-10-23 14:53:06 -07002526 // Skip reused objects for stub libraries, they use their own stub object file instead.
2527 // The reuseObjTag dependency still exists because the LinkageMutator runs before the
2528 // version mutator, so the stubs variant is created from the shared variant that
2529 // already has the reuseObjTag dependency on the static variant.
Colin Cross31076b32020-10-23 17:22:06 -07002530 if !c.library.buildStubs() {
Colin Crossa717db72020-10-23 14:53:06 -07002531 staticAnalogue := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2532 objs := staticAnalogue.ReuseObjects
2533 depPaths.Objs = depPaths.Objs.Append(objs)
2534 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
2535 reexportExporter(depExporterInfo)
2536 }
Colin Cross0de8a1e2020-09-18 14:15:30 -07002537 return
Jiyong Parke4bb9862019-02-01 00:31:10 +09002538 }
2539
Colin Cross6e511a92020-07-27 21:26:48 -07002540 linkFile := ccDep.OutputFile()
2541
2542 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2543 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
Dan Albertc8060532020-07-22 22:32:17 -07002544 if libDepTag.staticUnwinder && c.apexSdkVersion.GreaterThan(android.SdkVersion_Android10) {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002545 return
2546 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002547
Jiyong Parke3867542020-12-03 17:28:25 +09002548 if !apexInfo.IsForPlatform() && libDepTag.excludeInApex {
2549 return
2550 }
2551
Colin Cross0de8a1e2020-09-18 14:15:30 -07002552 depExporterInfo := ctx.OtherModuleProvider(dep, FlagExporterInfoProvider).(FlagExporterInfo)
Colin Crossc99deeb2016-04-11 15:06:20 -07002553
Colin Cross6e511a92020-07-27 21:26:48 -07002554 var ptr *android.Paths
2555 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002556
Colin Cross6e511a92020-07-27 21:26:48 -07002557 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002558
Colin Cross6e511a92020-07-27 21:26:48 -07002559 switch {
2560 case libDepTag.header():
Colin Cross649d8172020-12-10 12:30:21 -08002561 if !ctx.OtherModuleHasProvider(dep, HeaderLibraryInfoProvider) {
2562 if !ctx.Config().AllowMissingDependencies() {
2563 ctx.ModuleErrorf("module %q is not a header library", depName)
2564 } else {
2565 ctx.AddMissingDependencies([]string{depName})
2566 }
2567 return
2568 }
Colin Cross6e511a92020-07-27 21:26:48 -07002569 case libDepTag.shared():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002570 if !ctx.OtherModuleHasProvider(dep, SharedLibraryInfoProvider) {
2571 if !ctx.Config().AllowMissingDependencies() {
2572 ctx.ModuleErrorf("module %q is not a shared library", depName)
2573 } else {
2574 ctx.AddMissingDependencies([]string{depName})
2575 }
2576 return
2577 }
Jiyong Parke3867542020-12-03 17:28:25 +09002578
Colin Cross0de8a1e2020-09-18 14:15:30 -07002579 sharedLibraryInfo := ctx.OtherModuleProvider(dep, SharedLibraryInfoProvider).(SharedLibraryInfo)
Chris Parsons3c27ca32020-11-20 12:42:07 -05002580 sharedLibraryStubsInfo := ctx.OtherModuleProvider(dep, SharedLibraryStubsProvider).(SharedLibraryStubsInfo)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002581
Chris Parsons3c27ca32020-11-20 12:42:07 -05002582 if !libDepTag.explicitlyVersioned && len(sharedLibraryStubsInfo.SharedStubLibraries) > 0 {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002583 useStubs := false
Colin Cross31076b32020-10-23 17:22:06 -07002584
2585 if lib := moduleLibraryInterface(dep); lib.buildStubs() && c.UseVndk() { // LLNDK
Colin Cross0de8a1e2020-09-18 14:15:30 -07002586 if !apexInfo.IsForPlatform() {
2587 // For platform libraries, use current version of LLNDK
2588 // If this is for use_vendor apex we will apply the same rules
2589 // of apex sdk enforcement below to choose right version.
2590 useStubs = true
2591 }
2592 } else if apexInfo.IsForPlatform() {
2593 // If not building for APEX, use stubs only when it is from
2594 // an APEX (and not from platform)
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002595 // However, for host, ramdisk, vendor_ramdisk, recovery or bootstrap modules,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002596 // always link to non-stub variant
Jiyong Parkf7c3bbe2020-12-09 21:18:56 +09002597 useStubs = dep.(android.ApexModule).NotInPlatform() && !c.bootstrap()
Colin Cross0de8a1e2020-09-18 14:15:30 -07002598 // Another exception: if this module is bundled with an APEX, then
2599 // it is linked with the non-stub variant of a module in the APEX
2600 // as if this is part of the APEX.
2601 testFor := ctx.Provider(android.ApexTestForInfoProvider).(android.ApexTestForInfo)
2602 for _, apexContents := range testFor.ApexContents {
2603 if apexContents.DirectlyInApex(depName) {
2604 useStubs = false
2605 break
2606 }
2607 }
2608 } else {
2609 // If building for APEX, use stubs when the parent is in any APEX that
2610 // the child is not in.
2611 useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
2612 }
2613
2614 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2615 if useStubs {
2616 sharedLibraryStubsInfo, err :=
Chris Parsons3c27ca32020-11-20 12:42:07 -05002617 c.chooseSdkVersion(ctx, sharedLibraryStubsInfo.SharedStubLibraries, c.apexSdkVersion)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002618 if err != nil {
2619 ctx.OtherModuleErrorf(dep, err.Error())
2620 return
2621 }
2622 sharedLibraryInfo = sharedLibraryStubsInfo.SharedLibraryInfo
2623 depExporterInfo = sharedLibraryStubsInfo.FlagExporterInfo
2624 }
2625 }
2626
Jiyong Park1ad8e162020-12-01 23:40:09 +09002627 // Stubs lib doesn't link to the shared lib dependencies. Don't set
2628 // linkFile, depFile, and ptr.
2629 if c.IsStubs() {
2630 break
2631 }
2632
Colin Cross0de8a1e2020-09-18 14:15:30 -07002633 linkFile = android.OptionalPathForPath(sharedLibraryInfo.SharedLibrary)
2634 depFile = sharedLibraryInfo.TableOfContents
2635
Colin Cross6e511a92020-07-27 21:26:48 -07002636 ptr = &depPaths.SharedLibs
2637 switch libDepTag.Order {
2638 case earlyLibraryDependency:
2639 ptr = &depPaths.EarlySharedLibs
2640 depPtr = &depPaths.EarlySharedLibsDeps
2641 case normalLibraryDependency:
2642 ptr = &depPaths.SharedLibs
2643 depPtr = &depPaths.SharedLibsDeps
Colin Cross0de8a1e2020-09-18 14:15:30 -07002644 directSharedDeps = append(directSharedDeps, sharedLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002645 case lateLibraryDependency:
2646 ptr = &depPaths.LateSharedLibs
2647 depPtr = &depPaths.LateSharedLibsDeps
2648 default:
2649 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002650 }
Colin Cross6e511a92020-07-27 21:26:48 -07002651 case libDepTag.static():
Colin Cross0de8a1e2020-09-18 14:15:30 -07002652 if !ctx.OtherModuleHasProvider(dep, StaticLibraryInfoProvider) {
2653 if !ctx.Config().AllowMissingDependencies() {
2654 ctx.ModuleErrorf("module %q is not a static library", depName)
2655 } else {
2656 ctx.AddMissingDependencies([]string{depName})
2657 }
2658 return
2659 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002660
2661 // Stubs lib doesn't link to the static lib dependencies. Don't set
2662 // linkFile, depFile, and ptr.
2663 if c.IsStubs() {
2664 break
2665 }
2666
Colin Cross0de8a1e2020-09-18 14:15:30 -07002667 staticLibraryInfo := ctx.OtherModuleProvider(dep, StaticLibraryInfoProvider).(StaticLibraryInfo)
2668 linkFile = android.OptionalPathForPath(staticLibraryInfo.StaticLibrary)
Colin Cross6e511a92020-07-27 21:26:48 -07002669 if libDepTag.wholeStatic {
2670 ptr = &depPaths.WholeStaticLibs
Colin Cross0de8a1e2020-09-18 14:15:30 -07002671 if len(staticLibraryInfo.Objects.objFiles) > 0 {
2672 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLibraryInfo.Objects)
Inseob Kimeec88e12020-01-22 11:11:29 +09002673 } else {
Colin Cross0de8a1e2020-09-18 14:15:30 -07002674 // This case normally catches prebuilt static
2675 // libraries, but it can also occur when
2676 // AllowMissingDependencies is on and the
2677 // dependencies has no sources of its own
2678 // but has a whole_static_libs dependency
2679 // on a missing library. We want to depend
2680 // on the .a file so that there is something
2681 // in the dependency tree that contains the
2682 // error rule for the missing transitive
2683 // dependency.
2684 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
Colin Cross6e511a92020-07-27 21:26:48 -07002685 }
Colin Cross6e511a92020-07-27 21:26:48 -07002686 } else {
2687 switch libDepTag.Order {
2688 case earlyLibraryDependency:
2689 panic(fmt.Errorf("early static libs not suppported"))
2690 case normalLibraryDependency:
2691 // static dependencies will be handled separately so they can be ordered
2692 // using transitive dependencies.
2693 ptr = nil
Colin Cross0de8a1e2020-09-18 14:15:30 -07002694 directStaticDeps = append(directStaticDeps, staticLibraryInfo)
Colin Cross6e511a92020-07-27 21:26:48 -07002695 case lateLibraryDependency:
2696 ptr = &depPaths.LateStaticLibs
2697 default:
2698 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002699 }
2700 }
2701 }
2702
Colin Cross6e511a92020-07-27 21:26:48 -07002703 if libDepTag.static() && !libDepTag.wholeStatic {
2704 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2705 ctx.ModuleErrorf("module %q not a static library", depName)
2706 return
2707 }
Logan Chien43d34c32017-12-20 01:17:32 +08002708
Colin Cross6e511a92020-07-27 21:26:48 -07002709 // When combining coverage files for shared libraries and executables, coverage files
2710 // in static libraries act as if they were whole static libraries. The same goes for
2711 // source based Abi dump files.
2712 if c, ok := ccDep.(*Module); ok {
2713 staticLib := c.linker.(libraryInterface)
2714 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2715 staticLib.objs().coverageFiles...)
2716 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2717 staticLib.objs().sAbiDumpFiles...)
Colin Cross0de8a1e2020-09-18 14:15:30 -07002718 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002719 // Handle non-CC modules here
2720 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
Colin Cross0de8a1e2020-09-18 14:15:30 -07002721 ccDep.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002722 }
2723 }
2724
Colin Cross6e511a92020-07-27 21:26:48 -07002725 if ptr != nil {
2726 if !linkFile.Valid() {
2727 if !ctx.Config().AllowMissingDependencies() {
2728 ctx.ModuleErrorf("module %q missing output file", depName)
2729 } else {
2730 ctx.AddMissingDependencies([]string{depName})
2731 }
2732 return
2733 }
2734 *ptr = append(*ptr, linkFile.Path())
2735 }
2736
2737 if depPtr != nil {
2738 dep := depFile
2739 if !dep.Valid() {
2740 dep = linkFile
2741 }
2742 *depPtr = append(*depPtr, dep.Path())
2743 }
2744
Colin Cross0de8a1e2020-09-18 14:15:30 -07002745 depPaths.IncludeDirs = append(depPaths.IncludeDirs, depExporterInfo.IncludeDirs...)
2746 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, depExporterInfo.SystemIncludeDirs...)
2747 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, depExporterInfo.Deps...)
2748 depPaths.Flags = append(depPaths.Flags, depExporterInfo.Flags...)
2749
2750 if libDepTag.reexportFlags {
2751 reexportExporter(depExporterInfo)
2752 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2753 // Re-exported shared library headers must be included as well since they can help us with type information
2754 // about template instantiations (instantiated from their headers).
2755 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2756 // scripts.
2757 c.sabi.Properties.ReexportedIncludes = append(
2758 c.sabi.Properties.ReexportedIncludes, depExporterInfo.IncludeDirs.Strings()...)
2759 }
2760
Colin Cross6e511a92020-07-27 21:26:48 -07002761 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2762 switch {
2763 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002764 c.Properties.AndroidMkHeaderLibs = append(
2765 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002766 case libDepTag.shared():
Colin Cross31076b32020-10-23 17:22:06 -07002767 if lib := moduleLibraryInterface(dep); lib != nil {
2768 if lib.buildStubs() && dep.(android.ApexModule).InAnyApex() {
Colin Cross6e511a92020-07-27 21:26:48 -07002769 // Add the dependency to the APEX(es) providing the library so that
2770 // m <module> can trigger building the APEXes as well.
Colin Cross56a83212020-09-15 18:30:11 -07002771 depApexInfo := ctx.OtherModuleProvider(dep, android.ApexInfoProvider).(android.ApexInfo)
2772 for _, an := range depApexInfo.InApexes {
Colin Cross6e511a92020-07-27 21:26:48 -07002773 c.Properties.ApexesProvidingSharedLibs = append(
2774 c.Properties.ApexesProvidingSharedLibs, an)
2775 }
2776 }
2777 }
2778
2779 // Note: the order of libs in this list is not important because
2780 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002781 c.Properties.AndroidMkSharedLibs = append(
2782 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002783 // Record baseLibName for snapshots.
2784 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2785 case libDepTag.static():
2786 if libDepTag.wholeStatic {
2787 c.Properties.AndroidMkWholeStaticLibs = append(
2788 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2789 } else {
2790 c.Properties.AndroidMkStaticLibs = append(
2791 c.Properties.AndroidMkStaticLibs, makeLibName)
2792 }
2793 }
Jiyong Park1ad8e162020-12-01 23:40:09 +09002794 } else if !c.IsStubs() {
2795 // Stubs lib doesn't link to the runtime lib, object, crt, etc. dependencies.
2796
Colin Cross6e511a92020-07-27 21:26:48 -07002797 switch depTag {
2798 case runtimeDepTag:
2799 c.Properties.AndroidMkRuntimeLibs = append(
2800 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2801 // Record baseLibName for snapshots.
2802 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2803 case objDepTag:
2804 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2805 case CrtBeginDepTag:
2806 depPaths.CrtBegin = linkFile
2807 case CrtEndDepTag:
2808 depPaths.CrtEnd = linkFile
2809 case dynamicLinkerDepTag:
2810 depPaths.DynamicLinker = linkFile
2811 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002812 }
Colin Crossca860ac2016-01-04 14:34:37 -08002813 })
2814
Jeff Gaston294356f2017-09-27 17:05:30 -07002815 // use the ordered dependencies as this module's dependencies
Colin Cross0de8a1e2020-09-18 14:15:30 -07002816 orderedStaticPaths, transitiveStaticLibs := orderStaticModuleDeps(directStaticDeps, directSharedDeps)
2817 depPaths.TranstiveStaticLibrariesForOrdering = transitiveStaticLibs
2818 depPaths.StaticLibs = append(depPaths.StaticLibs, orderedStaticPaths...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002819
Colin Crossdd84e052017-05-17 13:44:16 -07002820 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002821 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002822 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2823 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002824 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002825 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2826 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002827 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002828 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002829 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002830
2831 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002832 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002833 }
Colin Crossdd84e052017-05-17 13:44:16 -07002834
Colin Crossca860ac2016-01-04 14:34:37 -08002835 return depPaths
2836}
2837
Colin Cross0de8a1e2020-09-18 14:15:30 -07002838// orderStaticModuleDeps rearranges the order of the static library dependencies of the module
2839// to match the topological order of the dependency tree, including any static analogues of
2840// direct shared libraries. It returns the ordered static dependencies, and an android.DepSet
2841// of the transitive dependencies.
2842func orderStaticModuleDeps(staticDeps []StaticLibraryInfo, sharedDeps []SharedLibraryInfo) (ordered android.Paths, transitive *android.DepSet) {
2843 transitiveStaticLibsBuilder := android.NewDepSetBuilder(android.TOPOLOGICAL)
2844 var staticPaths android.Paths
2845 for _, staticDep := range staticDeps {
2846 staticPaths = append(staticPaths, staticDep.StaticLibrary)
2847 transitiveStaticLibsBuilder.Transitive(staticDep.TransitiveStaticLibrariesForOrdering)
2848 }
2849 for _, sharedDep := range sharedDeps {
2850 if sharedDep.StaticAnalogue != nil {
2851 transitiveStaticLibsBuilder.Transitive(sharedDep.StaticAnalogue.TransitiveStaticLibrariesForOrdering)
2852 }
2853 }
2854 transitiveStaticLibs := transitiveStaticLibsBuilder.Build()
2855
2856 orderedTransitiveStaticLibs := transitiveStaticLibs.ToList()
2857
2858 // reorder the dependencies based on transitive dependencies
2859 staticPaths = android.FirstUniquePaths(staticPaths)
2860 _, orderedStaticPaths := android.FilterPathList(orderedTransitiveStaticLibs, staticPaths)
2861
2862 if len(orderedStaticPaths) != len(staticPaths) {
2863 missing, _ := android.FilterPathList(staticPaths, orderedStaticPaths)
2864 panic(fmt.Errorf("expected %d ordered static paths , got %d, missing %q %q %q", len(staticPaths), len(orderedStaticPaths), missing, orderedStaticPaths, staticPaths))
2865 }
2866
2867 return orderedStaticPaths, transitiveStaticLibs
2868}
2869
Colin Cross6e511a92020-07-27 21:26:48 -07002870// baseLibName trims known prefixes and suffixes
2871func baseLibName(depName string) string {
2872 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2873 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Paul Duffind23c7262020-12-11 18:13:08 +00002874 libName = android.RemoveOptionalPrebuiltPrefix(libName)
Colin Cross6e511a92020-07-27 21:26:48 -07002875 return libName
2876}
2877
2878func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2879 vendorSuffixModules := vendorSuffixModules(ctx.Config())
Jose Galmes6f843bc2020-12-11 13:36:29 -08002880 recoverySuffixModules := recoverySuffixModules(ctx.Config())
Colin Cross6e511a92020-07-27 21:26:48 -07002881 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2882
2883 libName := baseLibName(depName)
Colin Cross127bb8b2020-12-16 16:46:01 -08002884 ccDepModule, _ := ccDep.(*Module)
2885 isLLndk := ccDepModule != nil && ccDepModule.IsLlndk()
Colin Cross6e511a92020-07-27 21:26:48 -07002886 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2887 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2888
2889 if c, ok := ccDep.(*Module); ok {
2890 // Use base module name for snapshots when exporting to Makefile.
2891 if c.isSnapshotPrebuilt() {
2892 baseName := c.BaseModuleName()
2893
2894 if c.IsVndk() {
2895 return baseName + ".vendor"
2896 }
2897
Ivan Lozano3968d8f2020-12-14 11:27:52 -05002898 if c.InVendor() && vendorSuffixModules[baseName] {
Colin Cross6e511a92020-07-27 21:26:48 -07002899 return baseName + ".vendor"
Jose Galmes6f843bc2020-12-11 13:36:29 -08002900 } else if c.InRecovery() && recoverySuffixModules[baseName] {
2901 return baseName + ".recovery"
Colin Cross6e511a92020-07-27 21:26:48 -07002902 } else {
2903 return baseName
2904 }
2905 }
2906 }
2907
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002908 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() &&
2909 !c.InRamdisk() && !c.InVendorRamdisk() && !c.InRecovery() {
Colin Cross6e511a92020-07-27 21:26:48 -07002910 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2911 // core module instead.
2912 return libName
2913 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2914 // The vendor module in Make will have been renamed to not conflict with the core
2915 // module, so update the dependency name here accordingly.
2916 return libName + c.getNameSuffixWithVndkVersion(ctx)
2917 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2918 return libName + vendorPublicLibrarySuffix
2919 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2920 return libName + ramdiskSuffix
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002921 } else if ccDep.InVendorRamdisk() && !ccDep.OnlyInVendorRamdisk() {
2922 return libName + vendorRamdiskSuffix
Colin Cross6e511a92020-07-27 21:26:48 -07002923 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2924 return libName + recoverySuffix
Ivan Lozanof9e21722020-12-02 09:00:51 -05002925 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
Colin Cross6e511a92020-07-27 21:26:48 -07002926 return libName + nativeBridgeSuffix
2927 } else {
2928 return libName
2929 }
2930}
2931
Colin Crossca860ac2016-01-04 14:34:37 -08002932func (c *Module) InstallInData() bool {
2933 if c.installer == nil {
2934 return false
2935 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002936 return c.installer.inData()
2937}
2938
2939func (c *Module) InstallInSanitizerDir() bool {
2940 if c.installer == nil {
2941 return false
2942 }
2943 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002944 return true
2945 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002946 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002947}
2948
Yifan Hong1b3348d2020-01-21 15:53:22 -08002949func (c *Module) InstallInRamdisk() bool {
2950 return c.InRamdisk()
2951}
2952
Yifan Hong60e0cfb2020-10-21 15:17:56 -07002953func (c *Module) InstallInVendorRamdisk() bool {
2954 return c.InVendorRamdisk()
2955}
2956
Jiyong Parkf9332f12018-02-01 00:54:12 +09002957func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002958 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002959}
2960
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002961func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002962 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002963 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002964 return
2965 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002966 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002967}
2968
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002969func (c *Module) HostToolPath() android.OptionalPath {
2970 if c.installer == nil {
2971 return android.OptionalPath{}
2972 }
2973 return c.installer.hostToolPath()
2974}
2975
Nan Zhangd4e641b2017-07-12 12:55:28 -07002976func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2977 return c.outputFile
2978}
2979
Colin Cross41955e82019-05-29 14:40:35 -07002980func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2981 switch tag {
2982 case "":
2983 if c.outputFile.Valid() {
2984 return android.Paths{c.outputFile.Path()}, nil
2985 }
2986 return android.Paths{}, nil
2987 default:
2988 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002989 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002990}
2991
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002992func (c *Module) static() bool {
2993 if static, ok := c.linker.(interface {
2994 static() bool
2995 }); ok {
2996 return static.static()
2997 }
2998 return false
2999}
3000
Jiyong Park379de2f2018-12-19 02:47:14 +09003001func (c *Module) staticBinary() bool {
3002 if static, ok := c.linker.(interface {
3003 staticBinary() bool
3004 }); ok {
3005 return static.staticBinary()
3006 }
3007 return false
3008}
3009
Evgenii Stepanov193ac2e2020-04-28 15:09:12 -07003010func (c *Module) testBinary() bool {
3011 if test, ok := c.linker.(interface {
3012 testBinary() bool
3013 }); ok {
3014 return test.testBinary()
3015 }
3016 return false
3017}
3018
Ivan Lozano3968d8f2020-12-14 11:27:52 -05003019// Header returns true if the module is a header-only variant. (See cc/library.go header()).
3020func (c *Module) Header() bool {
Jiyong Park1d1119f2019-07-29 21:27:18 +09003021 if h, ok := c.linker.(interface {
3022 header() bool
3023 }); ok {
3024 return h.header()
3025 }
3026 return false
3027}
3028
Inseob Kim7f283f42020-06-01 21:53:49 +09003029func (c *Module) binary() bool {
3030 if b, ok := c.linker.(interface {
3031 binary() bool
3032 }); ok {
3033 return b.binary()
3034 }
3035 return false
3036}
3037
Inseob Kim1042d292020-06-01 23:23:05 +09003038func (c *Module) object() bool {
3039 if o, ok := c.linker.(interface {
3040 object() bool
3041 }); ok {
3042 return o.object()
3043 }
3044 return false
3045}
3046
Ivan Lozanof9e21722020-12-02 09:00:51 -05003047func GetMakeLinkType(actx android.ModuleContext, c LinkableInterface) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07003048 if c.UseVndk() {
Colin Cross127bb8b2020-12-16 16:46:01 -08003049 if c.IsLlndk() {
3050 if !c.IsLlndkPublic() {
Ivan Lozanof9e21722020-12-02 09:00:51 -05003051 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07003052 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003053 return "native:vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07003054 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003055 if c.IsVndk() && !c.IsVndkExt() {
Colin Cross127bb8b2020-12-16 16:46:01 -08003056 if c.IsVndkPrivate() {
Ivan Lozanof9e21722020-12-02 09:00:51 -05003057 return "native:vndk_private"
Jooyung Han38002912019-05-16 04:01:54 +09003058 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003059 return "native:vndk"
Jooyung Han38002912019-05-16 04:01:54 +09003060 }
Ivan Lozanof9e21722020-12-02 09:00:51 -05003061 if c.InProduct() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003062 return "native:product"
3063 }
Jooyung Han38002912019-05-16 04:01:54 +09003064 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08003065 } else if c.InRamdisk() {
3066 return "native:ramdisk"
Yifan Hong60e0cfb2020-10-21 15:17:56 -07003067 } else if c.InVendorRamdisk() {
3068 return "native:vendor_ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07003069 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07003070 return "native:recovery"
Ivan Lozanof9e21722020-12-02 09:00:51 -05003071 } else if c.Target().Os == android.Android && c.SdkVersion() != "" {
Colin Crossb60190a2018-09-04 16:28:17 -07003072 return "native:ndk:none:none"
3073 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
3074 //family, link := getNdkStlFamilyAndLinkType(c)
3075 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07003076 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08003077 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07003078 } else {
3079 return "native:platform"
3080 }
3081}
3082
Jiyong Park9d452992018-10-03 00:38:19 +09003083// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01003084// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09003085func (c *Module) IsInstallableToApex() bool {
Colin Cross31076b32020-10-23 17:22:06 -07003086 if lib := c.library; lib != nil {
Jiyong Park73c54ee2019-10-22 20:31:18 +09003087 // Stub libs and prebuilt libs in a versioned SDK are not
3088 // installable to APEX even though they are shared libs.
Colin Cross31076b32020-10-23 17:22:06 -07003089 return lib.shared() && !lib.buildStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01003090 } else if _, ok := c.linker.(testPerSrc); ok {
3091 return true
Jiyong Park9d452992018-10-03 00:38:19 +09003092 }
3093 return false
3094}
3095
Jiyong Parka90ca002019-10-07 15:47:24 +09003096func (c *Module) AvailableFor(what string) bool {
3097 if linker, ok := c.linker.(interface {
3098 availableFor(string) bool
3099 }); ok {
3100 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
3101 } else {
3102 return c.ApexModuleBase.AvailableFor(what)
3103 }
3104}
3105
Jiyong Park62304bb2020-04-13 16:19:48 +09003106func (c *Module) TestFor() []string {
Jiyong Park46a512f2020-12-04 18:02:13 +09003107 return c.Properties.Test_for
Jiyong Park62304bb2020-04-13 16:19:48 +09003108}
3109
Colin Crossaede88c2020-08-11 12:17:01 -07003110func (c *Module) UniqueApexVariations() bool {
3111 if u, ok := c.compiler.(interface {
3112 uniqueApexVariations() bool
3113 }); ok {
3114 return u.uniqueApexVariations()
3115 } else {
3116 return false
3117 }
3118}
3119
Paul Duffin0cb37b92020-03-04 14:52:46 +00003120// Return true if the module is ever installable.
3121func (c *Module) EverInstallable() bool {
3122 return c.installer != nil &&
3123 // Check to see whether the module is actually ever installable.
3124 c.installer.everInstallable()
3125}
3126
Colin Cross56a83212020-09-15 18:30:11 -07003127func (c *Module) installable(apexInfo android.ApexInfo) bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00003128 ret := c.EverInstallable() &&
3129 // Check to see whether the module has been configured to not be installed.
3130 proptools.BoolDefault(c.Properties.Installable, true) &&
3131 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003132
3133 // The platform variant doesn't need further condition. Apex variants however might not
3134 // be installable because it will likely to be included in the APEX and won't appear
3135 // in the system partition.
Colin Cross56a83212020-09-15 18:30:11 -07003136 if apexInfo.IsForPlatform() {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09003137 return ret
3138 }
3139
3140 // Special case for modules that are configured to be installed to /data, which includes
3141 // test modules. For these modules, both APEX and non-APEX variants are considered as
3142 // installable. This is because even the APEX variants won't be included in the APEX, but
3143 // will anyway be installed to /data/*.
3144 // See b/146995717
3145 if c.InstallInData() {
3146 return ret
3147 }
3148
3149 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09003150}
3151
Logan Chien41eabe62019-04-10 13:33:58 +08003152func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
3153 if c.linker != nil {
3154 if library, ok := c.linker.(*libraryDecorator); ok {
3155 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
3156 }
3157 }
3158}
3159
Jiyong Park45bf82e2020-12-15 22:29:02 +09003160var _ android.ApexModule = (*Module)(nil)
3161
3162// Implements android.ApexModule
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003163func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07003164 depTag := ctx.OtherModuleDependencyTag(dep)
3165 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
3166
3167 if cc, ok := dep.(*Module); ok {
3168 if cc.HasStubsVariants() {
3169 if isLibDepTag && libDepTag.shared() {
3170 // dynamic dep to a stubs lib crosses APEX boundary
3171 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003172 }
Colin Cross6e511a92020-07-27 21:26:48 -07003173 if IsRuntimeDepTag(depTag) {
3174 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09003175 return false
3176 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003177 }
Colin Crossaac32222020-07-29 12:51:56 -07003178 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07003179 // shared_lib dependency from a static lib is considered as crossing
3180 // the APEX boundary because the dependency doesn't actually is
3181 // linked; the dependency is used only during the compilation phase.
3182 return false
3183 }
Jiyong Parke3867542020-12-03 17:28:25 +09003184
3185 if isLibDepTag && libDepTag.excludeInApex {
3186 return false
3187 }
Colin Cross6e511a92020-07-27 21:26:48 -07003188 }
Colin Cross127bb8b2020-12-16 16:46:01 -08003189 if depTag == stubImplDepTag || depTag == llndkStubDepTag {
Colin Cross0de8a1e2020-09-18 14:15:30 -07003190 // We don't track beyond LLNDK or from an implementation library to its stubs.
Jiyong Park7d95a512020-05-10 15:16:24 +09003191 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003192 }
Jiyong Park12177fc2021-01-05 14:37:15 +09003193 if depTag == staticVariantTag {
3194 // This dependency is for optimization (reuse *.o from the static lib). It doesn't
3195 // actually mean that the static lib (and its dependencies) are copied into the
3196 // APEX.
3197 return false
3198 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09003199 return true
3200}
3201
Jiyong Park45bf82e2020-12-15 22:29:02 +09003202// Implements android.ApexModule
Dan Albertc8060532020-07-22 22:32:17 -07003203func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext,
3204 sdkVersion android.ApiLevel) error {
Jooyung Han749dc692020-04-15 11:03:39 +09003205 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3206 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3207 return nil
3208 }
3209 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3210 if c.ToolchainLibrary() {
3211 return nil
3212 }
3213 // We don't check for prebuilt modules
3214 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3215 return nil
3216 }
3217 minSdkVersion := c.MinSdkVersion()
3218 if minSdkVersion == "apex_inherit" {
3219 return nil
3220 }
3221 if minSdkVersion == "" {
3222 // JNI libs within APK-in-APEX fall into here
3223 // Those are okay to set sdk_version instead
3224 // We don't have to check if this is a SDK variant because
3225 // non-SDK variant resets sdk_version, which works too.
3226 minSdkVersion = c.SdkVersion()
3227 }
Dan Albertc8060532020-07-22 22:32:17 -07003228 if minSdkVersion == "" {
3229 return fmt.Errorf("neither min_sdk_version nor sdk_version specificed")
3230 }
3231 // Not using nativeApiLevelFromUser because the context here is not
3232 // necessarily a native context.
3233 ver, err := android.ApiLevelFromUser(ctx, minSdkVersion)
Jooyung Han749dc692020-04-15 11:03:39 +09003234 if err != nil {
3235 return err
3236 }
Dan Albertc8060532020-07-22 22:32:17 -07003237
3238 if ver.GreaterThan(sdkVersion) {
Jooyung Han749dc692020-04-15 11:03:39 +09003239 return fmt.Errorf("newer SDK(%v)", ver)
3240 }
3241 return nil
3242}
3243
Colin Cross2ba19d92015-05-07 15:44:20 -07003244//
Colin Crosscfad1192015-11-02 16:43:11 -08003245// Defaults
3246//
Colin Crossca860ac2016-01-04 14:34:37 -08003247type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003248 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003249 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003250 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003251}
3252
Patrice Arrudac249c712019-03-19 17:00:29 -07003253// cc_defaults provides a set of properties that can be inherited by other cc
3254// modules. A module can use the properties from a cc_defaults using
3255// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3256// merged (when possible) by prepending the default module's values to the
3257// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003258func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003259 return DefaultsFactory()
3260}
3261
Colin Cross36242852017-06-23 15:06:31 -07003262func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003263 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003264
Colin Cross36242852017-06-23 15:06:31 -07003265 module.AddProperties(props...)
3266 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003267 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003268 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003269 &BaseCompilerProperties{},
3270 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003271 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003272 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003273 &StaticProperties{},
3274 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003275 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003276 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003277 &TestProperties{},
3278 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003279 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003280 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003281 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003282 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003283 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003284 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003285 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003286 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003287 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003288 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003289 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003290 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003291 &android.ProtoProperties{},
Ivan Lozanobc9e4212020-09-25 16:08:34 -04003292 // RustBindgenProperties is included here so that cc_defaults can be used for rust_bindgen modules.
3293 &RustBindgenClangProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003294 )
Colin Crosscfad1192015-11-02 16:43:11 -08003295
Jooyung Hancc372c52019-09-25 15:18:44 +09003296 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003297
3298 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003299}
3300
Jiyong Park2286afd2020-06-16 21:58:53 +09003301func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003302 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003303}
3304
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003305func kytheExtractAllFactory() android.Singleton {
3306 return &kytheExtractAllSingleton{}
3307}
3308
3309type kytheExtractAllSingleton struct {
3310}
3311
3312func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3313 var xrefTargets android.Paths
3314 ctx.VisitAllModules(func(module android.Module) {
3315 if ccModule, ok := module.(xref); ok {
3316 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3317 }
3318 })
3319 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3320 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003321 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003322 }
3323}
3324
Colin Cross06a931b2015-10-28 17:23:31 -07003325var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003326var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003327var BoolPtr = proptools.BoolPtr
3328var String = proptools.String
3329var StringPtr = proptools.StringPtr