blob: 82321173c704d2fb568179cafd833bcaf3c6a2d5 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Crossc511bc52020-04-07 16:50:32 +000045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070051 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090052 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090053 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
54 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070055 })
Colin Cross16b23492016-01-06 14:41:07 -080056
Paul Duffin036e7002019-12-19 19:16:28 +000057 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070058 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
59 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080060
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070061 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
62 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
63
Mitch Phillipsbfeade62019-05-01 14:42:05 -070064 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
65 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
66
Jiyong Park1d1119f2019-07-29 21:27:18 +090067 // cfi mutator shouldn't run before sanitizers that return true for
68 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000069 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
70 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
71
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080072 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
73 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
74
Colin Cross1e676be2016-10-12 14:38:15 -070075 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
76 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080077
Colin Cross0b908332019-06-19 23:00:20 -070078 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090079 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080080
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080081 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080082 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070083
84 ctx.TopDown("lto_deps", ltoDepsMutator)
85 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090086
87 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070088 })
Colin Crossb98c8b02016-07-29 13:44:28 -070089
Sasha Smundak2a4549e2018-11-05 16:49:08 -080090 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070091}
92
Colin Crossca860ac2016-01-04 14:34:37 -080093type Deps struct {
94 SharedLibs, LateSharedLibs []string
95 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080096 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080097 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070098
Chris Parsons79d66a52020-06-05 17:26:16 -040099 // Used for data dependencies adjacent to tests
100 DataLibs []string
101
Yo Chiang219968c2020-09-22 18:45:04 +0800102 // Used by DepsMutator to pass system_shared_libs information to check_elf_file.py.
103 SystemSharedLibs []string
104
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800105 StaticUnwinderIfLegacy bool
106
Colin Cross5950f382016-12-13 12:50:57 -0800107 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700108
Colin Cross81413472016-04-11 14:37:39 -0700109 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700110
Dan Willemsenb40aab62016-04-20 14:21:14 -0700111 GeneratedSources []string
112 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900113 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700114
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700115 ReexportGeneratedHeaders []string
116
Colin Cross97ba0732015-03-23 17:50:24 -0700117 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700118
119 // Used for host bionic
120 LinkerFlagsFile string
121 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700122}
123
Colin Crossca860ac2016-01-04 14:34:37 -0800124type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900126 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700127 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900128 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700129 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700130 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700131
Colin Cross26c34ed2016-09-30 17:10:16 -0700132 // Paths to .o files
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100133 Objs Objects
134 // Paths to .o files in dependencies that provide them. Note that these lists
135 // aren't complete since prebuilt modules don't provide the .o files.
Dan Willemsen581341d2017-02-09 16:16:31 -0800136 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700137 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700138
Martin Stjernholm391d94c2020-04-17 17:34:31 +0100139 // Paths to .a files in prebuilts. Complements WholeStaticLibObjs to contain
140 // the libs from all whole_static_lib dependencies.
141 WholeStaticLibsFromPrebuilts android.Paths
142
Colin Cross26c34ed2016-09-30 17:10:16 -0700143 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700144 GeneratedSources android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900145 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700146
Inseob Kimd110f872019-12-06 13:15:38 +0900147 Flags []string
148 IncludeDirs android.Paths
149 SystemIncludeDirs android.Paths
150 ReexportedDirs android.Paths
151 ReexportedSystemDirs android.Paths
152 ReexportedFlags []string
153 ReexportedGeneratedHeaders android.Paths
154 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700155
Colin Cross26c34ed2016-09-30 17:10:16 -0700156 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700157 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700158
159 // Path to the file container flags to use with the linker
160 LinkerFlagsFile android.OptionalPath
161
162 // Path to the dynamic linker binary
163 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700164}
165
Colin Cross4af21ed2019-11-04 09:37:55 -0800166// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
167// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
168// command line so they can be overridden by the local module flags).
169type LocalOrGlobalFlags struct {
170 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700171 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800172 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700173 CFlags []string // Flags that apply to C and C++ source files
174 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
175 ConlyFlags []string // Flags that apply to C source files
176 CppFlags []string // Flags that apply to C++ source files
177 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700178 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800179}
180
181type Flags struct {
182 Local LocalOrGlobalFlags
183 Global LocalOrGlobalFlags
184
185 aidlFlags []string // Flags that apply to aidl source files
186 rsFlags []string // Flags that apply to renderscript source files
187 libFlags []string // Flags to add libraries early to the link order
188 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
189 TidyFlags []string // Flags that apply to clang-tidy
190 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700191
Colin Crossc3199482017-03-30 15:03:04 -0700192 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800193 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700194 SystemIncludeFlags []string
195
Oliver Nguyen04526782020-04-21 12:40:27 -0700196 Toolchain config.Toolchain
197 Tidy bool
198 GcovCoverage bool
199 SAbiDump bool
200 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800201
202 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800203 DynamicLinker string
204
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700205 CFlagsDeps android.Paths // Files depended on by compiler flags
206 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800207
Dan Willemsen98ab3112019-08-27 21:20:40 -0700208 AssemblerWithCpp bool
209 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800210
Colin Cross19878da2019-03-28 14:45:07 -0700211 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700212 protoC bool // Whether to use C instead of C++
213 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700214
215 Yacc *YaccProperties
Matthias Maennich22fd4d12020-07-15 10:58:56 +0200216 Lex *LexProperties
Colin Crossc472d572015-03-17 15:06:21 -0700217}
218
Colin Crossca860ac2016-01-04 14:34:37 -0800219// Properties used to compile all C or C++ modules
220type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700221 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800222 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700223
Colin Crossc511bc52020-04-07 16:50:32 +0000224 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
225 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800226 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700227
Jooyung Han379660c2020-04-21 15:24:00 +0900228 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
229 Min_sdk_version *string
230
Colin Crossc511bc52020-04-07 16:50:32 +0000231 // If true, always create an sdk variant and don't create a platform variant.
232 Sdk_variant_only *bool
233
Jiyong Parkde866cb2018-12-07 23:08:36 +0900234 AndroidMkSharedLibs []string `blueprint:"mutated"`
235 AndroidMkStaticLibs []string `blueprint:"mutated"`
236 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
237 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
Bill Peckhama46de702020-04-21 17:23:37 -0700238 AndroidMkHeaderLibs []string `blueprint:"mutated"`
Jiyong Parkde866cb2018-12-07 23:08:36 +0900239 HideFromMake bool `blueprint:"mutated"`
240 PreventInstall bool `blueprint:"mutated"`
241 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700242
Yo Chiang219968c2020-09-22 18:45:04 +0800243 // Set by DepsMutator.
244 AndroidMkSystemSharedLibs []string `blueprint:"mutated"`
245
Justin Yun5f7f7e82019-11-18 19:52:14 +0900246 ImageVariationPrefix string `blueprint:"mutated"`
247 VndkVersion string `blueprint:"mutated"`
248 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800249
250 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
251 // file
252 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900253
Yifan Hong1b3348d2020-01-21 15:53:22 -0800254 // Make this module available when building for ramdisk
255 Ramdisk_available *bool
256
Jiyong Parkf9332f12018-02-01 00:54:12 +0900257 // Make this module available when building for recovery
258 Recovery_available *bool
259
Colin Crossae6c5202019-11-20 13:35:50 -0800260 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800261 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800262 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800263 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900264 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900265
266 // Allows this module to use non-APEX version of libraries. Useful
267 // for building binaries that are started before APEXes are activated.
268 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900269
270 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
271 // see soong/cc/config/vndk.go
272 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900273
274 // Used by vendor snapshot to record dependencies from snapshot modules.
275 SnapshotSharedLibs []string `blueprint:"mutated"`
276 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000277
278 Installable *bool
Colin Crossc511bc52020-04-07 16:50:32 +0000279
280 // Set by factories of module types that can only be referenced from variants compiled against
281 // the SDK.
282 AlwaysSdk bool `blueprint:"mutated"`
283
284 // Variant is an SDK variant created by sdkMutator
285 IsSdkVariant bool `blueprint:"mutated"`
286 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
287 // variant to have a ".sdk" suffix.
288 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Bill Peckham945441c2020-08-31 16:07:58 -0700289
290 // Normally Soong uses the directory structure to decide which modules
291 // should be included (framework) or excluded (non-framework) from the
292 // vendor snapshot, but this property allows a partner to exclude a
293 // module normally thought of as a framework module from the vendor
294 // snapshot.
295 Exclude_from_vendor_snapshot *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700296}
297
298type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900299 // whether this module should be allowed to be directly depended by other
300 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900301 // In addition, this module should be allowed to be directly depended by
302 // product modules with `product_specific: true`.
303 // If set to true, three variants will be built separately, one like
304 // normal, another limited to the set of libraries and headers
305 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700306 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900307 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700308 // so it shouldn't have any unversioned runtime dependencies, or
309 // make assumptions about the system that may not be true in the
310 // future.
311 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900312 // If set to false, this module becomes inaccessible from /vendor or /product
313 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900314 //
315 // Default value is true when vndk: {enabled: true} or vendor: true.
316 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700317 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900318 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700319 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900320
321 // whether this module is capable of being loaded with other instance
322 // (possibly an older version) of the same module in the same process.
323 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
324 // can be double loaded in a vendor process if the library is also a
325 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
326 // explicitly marked as `double_loadable: true` by the owner, or the dependency
327 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
328 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800329}
330
Colin Crossca860ac2016-01-04 14:34:37 -0800331type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800332 static() bool
333 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900334 header() bool
Inseob Kim7f283f42020-06-01 21:53:49 +0900335 binary() bool
Inseob Kim1042d292020-06-01 23:23:05 +0900336 object() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700337 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900338 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700339 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800340 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700341 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800342 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900343 isLlndk(config android.Config) bool
344 isLlndkPublic(config android.Config) bool
345 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900346 isVndk() bool
347 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800348 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900349 inProduct() bool
350 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800351 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900352 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800353 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700354 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700355 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800356 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800357 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800358 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800359 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800360 isForPlatform() bool
Colin Crosse07f2312020-08-13 11:24:56 -0700361 apexVariationName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900362 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900363 hasStubsVariants() bool
364 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900365 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800366 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700367 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800368}
369
370type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700371 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800372 ModuleContextIntf
373}
374
375type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700376 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800377 ModuleContextIntf
378}
379
Colin Cross37047f12016-12-13 17:06:13 -0800380type DepsContext interface {
381 android.BottomUpMutatorContext
382 ModuleContextIntf
383}
384
Colin Crossca860ac2016-01-04 14:34:37 -0800385type feature interface {
386 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800387 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800388 flags(ctx ModuleContext, flags Flags) Flags
389 props() []interface{}
390}
391
392type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700393 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800394 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800395 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700396 compilerProps() []interface{}
397
Colin Cross76fada02016-07-27 10:31:13 -0700398 appendCflags([]string)
399 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700400 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800401}
402
403type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700404 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800405 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700406 linkerFlags(ctx ModuleContext, flags Flags) Flags
407 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800408 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700409
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700410 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700411 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900412 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700413
414 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900415 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000416
417 // Get the deps that have been explicitly specified in the properties.
418 // Only updates the
419 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
420}
421
422type specifiedDeps struct {
423 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000424 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800425}
426
427type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700428 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700429 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000430 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800431 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700432 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700433 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900434 relativeInstallPath() string
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +0100435 makeUninstallable(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800436}
437
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800438type xref interface {
439 XrefCcFiles() android.Paths
440}
441
Colin Cross6e511a92020-07-27 21:26:48 -0700442type libraryDependencyKind int
443
444const (
445 headerLibraryDependency = iota
446 sharedLibraryDependency
447 staticLibraryDependency
448)
449
450func (k libraryDependencyKind) String() string {
451 switch k {
452 case headerLibraryDependency:
453 return "headerLibraryDependency"
454 case sharedLibraryDependency:
455 return "sharedLibraryDependency"
456 case staticLibraryDependency:
457 return "staticLibraryDependency"
458 default:
459 panic(fmt.Errorf("unknown libraryDependencyKind %d", k))
460 }
461}
462
463type libraryDependencyOrder int
464
465const (
466 earlyLibraryDependency = -1
467 normalLibraryDependency = 0
468 lateLibraryDependency = 1
469)
470
471func (o libraryDependencyOrder) String() string {
472 switch o {
473 case earlyLibraryDependency:
474 return "earlyLibraryDependency"
475 case normalLibraryDependency:
476 return "normalLibraryDependency"
477 case lateLibraryDependency:
478 return "lateLibraryDependency"
479 default:
480 panic(fmt.Errorf("unknown libraryDependencyOrder %d", o))
481 }
482}
483
484// libraryDependencyTag is used to tag dependencies on libraries. Unlike many dependency
485// tags that have a set of predefined tag objects that are reused for each dependency, a
486// libraryDependencyTag is designed to contain extra metadata and is constructed as needed.
487// That means that comparing a libraryDependencyTag for equality will only be equal if all
488// of the metadata is equal. Most usages will want to type assert to libraryDependencyTag and
489// then check individual metadata fields instead.
490type libraryDependencyTag struct {
491 blueprint.BaseDependencyTag
492
493 // These are exported so that fmt.Printf("%#v") can call their String methods.
494 Kind libraryDependencyKind
495 Order libraryDependencyOrder
496
497 wholeStatic bool
498
499 reexportFlags bool
500 explicitlyVersioned bool
501 dataLib bool
502 ndk bool
503
504 staticUnwinder bool
505
506 makeSuffix string
507}
508
509// header returns true if the libraryDependencyTag is tagging a header lib dependency.
510func (d libraryDependencyTag) header() bool {
511 return d.Kind == headerLibraryDependency
512}
513
514// shared returns true if the libraryDependencyTag is tagging a shared lib dependency.
515func (d libraryDependencyTag) shared() bool {
516 return d.Kind == sharedLibraryDependency
517}
518
519// shared returns true if the libraryDependencyTag is tagging a static lib dependency.
520func (d libraryDependencyTag) static() bool {
521 return d.Kind == staticLibraryDependency
522}
523
524// dependencyTag is used for tagging miscellanous dependency types that don't fit into
525// libraryDependencyTag. Each tag object is created globally and reused for multiple
526// dependencies (although since the object contains no references, assigning a tag to a
527// variable and modifying it will not modify the original). Users can compare the tag
528// returned by ctx.OtherModuleDependencyTag against the global original
529type dependencyTag struct {
530 blueprint.BaseDependencyTag
531 name string
532}
533
Colin Crossc99deeb2016-04-11 15:06:20 -0700534var (
Colin Cross6e511a92020-07-27 21:26:48 -0700535 genSourceDepTag = dependencyTag{name: "gen source"}
536 genHeaderDepTag = dependencyTag{name: "gen header"}
537 genHeaderExportDepTag = dependencyTag{name: "gen header export"}
538 objDepTag = dependencyTag{name: "obj"}
539 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
540 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
541 reuseObjTag = dependencyTag{name: "reuse objects"}
542 staticVariantTag = dependencyTag{name: "static variant"}
543 vndkExtDepTag = dependencyTag{name: "vndk extends"}
544 dataLibDepTag = dependencyTag{name: "data lib"}
545 runtimeDepTag = dependencyTag{name: "runtime lib"}
546 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700547)
548
Roland Levillainf89cd092019-07-29 16:22:59 +0100549func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700550 ccLibDepTag, ok := depTag.(libraryDependencyTag)
551 return ok && ccLibDepTag.shared()
552}
553
554func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
555 ccLibDepTag, ok := depTag.(libraryDependencyTag)
556 return ok && ccLibDepTag.static()
Roland Levillainf89cd092019-07-29 16:22:59 +0100557}
558
559func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700560 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100561 return ok && ccDepTag == runtimeDepTag
562}
563
564func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Colin Cross6e511a92020-07-27 21:26:48 -0700565 ccDepTag, ok := depTag.(dependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100566 return ok && ccDepTag == testPerSrcDepTag
567}
568
Colin Crossca860ac2016-01-04 14:34:37 -0800569// Module contains the properties and members used by all C/C++ module types, and implements
570// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
571// to construct the output file. Behavior can be customized with a Customizer interface
572type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700573 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700574 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900575 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900576 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700577
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700578 Properties BaseProperties
579 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700580
Colin Crossca860ac2016-01-04 14:34:37 -0800581 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700582 hod android.HostOrDeviceSupported
583 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700584
Paul Duffina0843f62019-12-13 19:50:38 +0000585 // Allowable SdkMemberTypes of this module type.
586 sdkMemberTypes []android.SdkMemberType
587
Colin Crossca860ac2016-01-04 14:34:37 -0800588 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700589 features []feature
590 compiler compiler
591 linker linker
592 installer installer
593 stl *stl
594 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800595 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800596 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900597 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700598 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700599 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800600
Colin Cross635c3b02016-05-18 15:37:25 -0700601 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800602
Colin Crossb98c8b02016-07-29 13:44:28 -0700603 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700604
605 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800606
607 // Flags used to compile this module
608 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700609
610 // When calling a linker, if module A depends on module B, then A must precede B in its command
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800611 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700612 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800613 depsInLinkOrder android.Paths
614
615 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700616 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900617
618 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800619 // Kythe (source file indexer) paths for this compilation module
620 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900621
622 // For apex variants, this is set as apex.min_sdk_version
623 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700624}
625
Ivan Lozano52767be2019-10-18 14:49:46 -0700626func (c *Module) Toc() android.OptionalPath {
627 if c.linker != nil {
628 if library, ok := c.linker.(libraryInterface); ok {
629 return library.toc()
630 }
631 }
632 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
633}
634
635func (c *Module) ApiLevel() string {
636 if c.linker != nil {
637 if stub, ok := c.linker.(*stubDecorator); ok {
638 return stub.properties.ApiLevel
639 }
640 }
641 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
642}
643
644func (c *Module) Static() bool {
645 if c.linker != nil {
646 if library, ok := c.linker.(libraryInterface); ok {
647 return library.static()
648 }
649 }
650 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
651}
652
653func (c *Module) Shared() bool {
654 if c.linker != nil {
655 if library, ok := c.linker.(libraryInterface); ok {
656 return library.shared()
657 }
658 }
659 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
660}
661
662func (c *Module) SelectedStl() string {
Colin Crossc511bc52020-04-07 16:50:32 +0000663 if c.stl != nil {
664 return c.stl.Properties.SelectedStl
665 }
666 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700667}
668
669func (c *Module) ToolchainLibrary() bool {
670 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
671 return true
672 }
673 return false
674}
675
676func (c *Module) NdkPrebuiltStl() bool {
677 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
678 return true
679 }
680 return false
681}
682
683func (c *Module) StubDecorator() bool {
684 if _, ok := c.linker.(*stubDecorator); ok {
685 return true
686 }
687 return false
688}
689
690func (c *Module) SdkVersion() string {
691 return String(c.Properties.Sdk_version)
692}
693
Artur Satayev480e25b2020-04-27 18:53:18 +0100694func (c *Module) MinSdkVersion() string {
695 return String(c.Properties.Min_sdk_version)
696}
697
Dan Albert92fe7402020-07-15 13:33:30 -0700698func (c *Module) SplitPerApiLevel() bool {
699 if linker, ok := c.linker.(*objectLinker); ok {
700 return linker.isCrt()
701 }
702 return false
703}
704
Colin Crossc511bc52020-04-07 16:50:32 +0000705func (c *Module) AlwaysSdk() bool {
706 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
707}
708
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800709func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700710 if c.linker != nil {
711 if library, ok := c.linker.(exportedFlagsProducer); ok {
712 return library.exportedDirs()
713 }
714 }
715 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
716}
717
718func (c *Module) HasStaticVariant() bool {
719 if c.staticVariant != nil {
720 return true
721 }
722 return false
723}
724
725func (c *Module) GetStaticVariant() LinkableInterface {
726 return c.staticVariant
727}
728
729func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
730 c.depsInLinkOrder = depsInLinkOrder
731}
732
733func (c *Module) GetDepsInLinkOrder() []android.Path {
734 return c.depsInLinkOrder
735}
736
737func (c *Module) StubsVersions() []string {
738 if c.linker != nil {
739 if library, ok := c.linker.(*libraryDecorator); ok {
740 return library.Properties.Stubs.Versions
741 }
742 }
743 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
744}
745
746func (c *Module) CcLibrary() bool {
747 if c.linker != nil {
748 if _, ok := c.linker.(*libraryDecorator); ok {
749 return true
750 }
751 }
752 return false
753}
754
755func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700756 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700757 return true
758 }
759 return false
760}
761
Ivan Lozano2b262972019-11-21 12:30:50 -0800762func (c *Module) NonCcVariants() bool {
763 return false
764}
765
Ivan Lozano183a3212019-10-18 14:18:45 -0700766func (c *Module) SetBuildStubs() {
767 if c.linker != nil {
768 if library, ok := c.linker.(*libraryDecorator); ok {
769 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700770 c.Properties.HideFromMake = true
771 c.sanitize = nil
772 c.stl = nil
773 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700774 return
775 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000776 if _, ok := c.linker.(*llndkStubDecorator); ok {
777 c.Properties.HideFromMake = true
778 return
779 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700780 }
781 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
782}
783
Ivan Lozano52767be2019-10-18 14:49:46 -0700784func (c *Module) BuildStubs() bool {
785 if c.linker != nil {
786 if library, ok := c.linker.(*libraryDecorator); ok {
787 return library.buildStubs()
788 }
789 }
790 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
791}
792
Ivan Lozano183a3212019-10-18 14:18:45 -0700793func (c *Module) SetStubsVersions(version string) {
794 if c.linker != nil {
795 if library, ok := c.linker.(*libraryDecorator); ok {
796 library.MutatedProperties.StubsVersion = version
797 return
798 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000799 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
800 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
801 return
802 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700803 }
804 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
805}
806
Jooyung Han03b51852020-02-26 22:45:42 +0900807func (c *Module) StubsVersion() string {
808 if c.linker != nil {
809 if library, ok := c.linker.(*libraryDecorator); ok {
810 return library.MutatedProperties.StubsVersion
811 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000812 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
813 return llndk.libraryDecorator.MutatedProperties.StubsVersion
814 }
Jooyung Han03b51852020-02-26 22:45:42 +0900815 }
816 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
817}
818
Ivan Lozano183a3212019-10-18 14:18:45 -0700819func (c *Module) SetStatic() {
820 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700821 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700822 library.setStatic()
823 return
824 }
825 }
826 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
827}
828
829func (c *Module) SetShared() {
830 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700831 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700832 library.setShared()
833 return
834 }
835 }
836 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
837}
838
839func (c *Module) BuildStaticVariant() bool {
840 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700841 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700842 return library.buildStatic()
843 }
844 }
845 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
846}
847
848func (c *Module) BuildSharedVariant() bool {
849 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700850 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700851 return library.buildShared()
852 }
853 }
854 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
855}
856
857func (c *Module) Module() android.Module {
858 return c
859}
860
Jiyong Parkc20eee32018-09-05 22:36:17 +0900861func (c *Module) OutputFile() android.OptionalPath {
862 return c.outputFile
863}
864
Ivan Lozanoa0cd8f92020-04-09 09:56:02 -0400865func (c *Module) CoverageFiles() android.Paths {
866 if c.linker != nil {
867 if library, ok := c.linker.(libraryInterface); ok {
868 return library.objs().coverageFiles
869 }
870 }
871 panic(fmt.Errorf("CoverageFiles called on non-library module: %q", c.BaseModuleName()))
872}
873
Ivan Lozano183a3212019-10-18 14:18:45 -0700874var _ LinkableInterface = (*Module)(nil)
875
Jiyong Park719b4462019-01-13 00:39:51 +0900876func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900877 if c.linker != nil {
878 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900879 }
880 return nil
881}
882
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900883func (c *Module) CoverageOutputFile() android.OptionalPath {
884 if c.linker != nil {
885 return c.linker.coverageOutputFilePath()
886 }
887 return android.OptionalPath{}
888}
889
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900890func (c *Module) RelativeInstallPath() string {
891 if c.installer != nil {
892 return c.installer.relativeInstallPath()
893 }
894 return ""
895}
896
Jooyung Han344d5432019-08-23 11:17:39 +0900897func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900898 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900899}
900
Colin Cross36242852017-06-23 15:06:31 -0700901func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700902 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800903 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700904 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800905 }
906 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700907 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800908 }
909 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700910 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800911 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700912 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700913 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700914 }
Colin Cross16b23492016-01-06 14:41:07 -0800915 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700916 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800917 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800918 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700919 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800920 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800921 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700922 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800923 }
Justin Yun8effde42017-06-23 19:24:43 +0900924 if c.vndkdep != nil {
925 c.AddProperties(c.vndkdep.props()...)
926 }
Stephen Craneba090d12017-05-09 15:44:35 -0700927 if c.lto != nil {
928 c.AddProperties(c.lto.props()...)
929 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700930 if c.pgo != nil {
931 c.AddProperties(c.pgo.props()...)
932 }
Colin Crossca860ac2016-01-04 14:34:37 -0800933 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700934 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800935 }
Colin Crossc472d572015-03-17 15:06:21 -0700936
Colin Crossa9d8bee2018-10-02 13:59:46 -0700937 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
Elliott Hughes79ae3412020-04-17 15:49:49 -0700938 // Windows builds always prefer 32-bit
939 return class == android.HostCross
Colin Crossa9d8bee2018-10-02 13:59:46 -0700940 })
Colin Cross36242852017-06-23 15:06:31 -0700941 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900942 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900943 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900944 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900945
Colin Cross36242852017-06-23 15:06:31 -0700946 return c
Colin Crossc472d572015-03-17 15:06:21 -0700947}
948
Colin Crossb916a382016-07-29 17:28:03 -0700949// Returns true for dependency roots (binaries)
950// TODO(ccross): also handle dlopenable libraries
951func (c *Module) isDependencyRoot() bool {
952 if root, ok := c.linker.(interface {
953 isDependencyRoot() bool
954 }); ok {
955 return root.isDependencyRoot()
956 }
957 return false
958}
959
Justin Yun5f7f7e82019-11-18 19:52:14 +0900960// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
961// "product" and "vendor" variant modules return true for this function.
962// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
963// "soc_specific: true" and more vendor installed modules are included here.
964// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
965// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700966func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900967 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700968}
969
Colin Crossc511bc52020-04-07 16:50:32 +0000970func (c *Module) canUseSdk() bool {
971 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
972}
973
974func (c *Module) UseSdk() bool {
975 if c.canUseSdk() {
Dan Albert92fe7402020-07-15 13:33:30 -0700976 return String(c.Properties.Sdk_version) != "" || c.SplitPerApiLevel()
Colin Crossc511bc52020-04-07 16:50:32 +0000977 }
978 return false
979}
980
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800981func (c *Module) isCoverageVariant() bool {
982 return c.coverage.Properties.IsCoverageVariant
983}
984
Peter Collingbournead84f972019-12-17 16:46:18 -0800985func (c *Module) IsNdk() bool {
Colin Crossf0913fb2020-07-29 12:59:39 -0700986 return inList(c.BaseModuleName(), ndkKnownLibs)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800987}
988
Inseob Kim9516ee92019-05-09 10:56:13 +0900989func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800990 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900991 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800992}
993
Inseob Kim9516ee92019-05-09 10:56:13 +0900994func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800995 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900996 name := c.BaseModuleName()
997 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800998}
999
Inseob Kim9516ee92019-05-09 10:56:13 +09001000func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001001 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +09001002 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001003}
1004
Ivan Lozano52767be2019-10-18 14:49:46 -07001005func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001006 if vndkdep := c.vndkdep; vndkdep != nil {
1007 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +09001008 }
1009 return false
1010}
1011
Yi Kong7e53c572018-02-14 18:16:12 +08001012func (c *Module) isPgoCompile() bool {
1013 if pgo := c.pgo; pgo != nil {
1014 return pgo.Properties.PgoCompile
1015 }
1016 return false
1017}
1018
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001019func (c *Module) isNDKStubLibrary() bool {
1020 if _, ok := c.compiler.(*stubDecorator); ok {
1021 return true
1022 }
1023 return false
1024}
1025
Logan Chienf3511742017-10-31 18:04:35 +08001026func (c *Module) isVndkSp() bool {
1027 if vndkdep := c.vndkdep; vndkdep != nil {
1028 return vndkdep.isVndkSp()
1029 }
1030 return false
1031}
1032
1033func (c *Module) isVndkExt() bool {
1034 if vndkdep := c.vndkdep; vndkdep != nil {
1035 return vndkdep.isVndkExt()
1036 }
1037 return false
1038}
1039
Ivan Lozano52767be2019-10-18 14:49:46 -07001040func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +09001041 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -08001042}
1043
Logan Chienf3511742017-10-31 18:04:35 +08001044func (c *Module) getVndkExtendsModuleName() string {
1045 if vndkdep := c.vndkdep; vndkdep != nil {
1046 return vndkdep.getVndkExtendsModuleName()
1047 }
1048 return ""
1049}
1050
Jiyong Park25fc6a92018-11-18 18:02:45 +09001051func (c *Module) IsStubs() bool {
1052 if library, ok := c.linker.(*libraryDecorator); ok {
1053 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +09001054 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
1055 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001056 }
1057 return false
1058}
1059
1060func (c *Module) HasStubsVariants() bool {
1061 if library, ok := c.linker.(*libraryDecorator); ok {
1062 return len(library.Properties.Stubs.Versions) > 0
1063 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001064 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
1065 return len(library.Properties.Stubs.Versions) > 0
1066 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001067 return false
1068}
1069
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001070func (c *Module) bootstrap() bool {
1071 return Bool(c.Properties.Bootstrap)
1072}
1073
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001074func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -07001075 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
1076 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1077 return false
1078 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001079 return c.linker != nil && c.linker.nativeCoverage()
1080}
1081
Inseob Kim8471cda2019-11-15 09:59:12 +09001082func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kim1042d292020-06-01 23:23:05 +09001083 if p, ok := c.linker.(interface{ isSnapshotPrebuilt() bool }); ok {
1084 return p.isSnapshotPrebuilt()
Inseob Kimeec88e12020-01-22 11:11:29 +09001085 }
1086 return false
Inseob Kim8471cda2019-11-15 09:59:12 +09001087}
1088
Jiyong Park73c54ee2019-10-22 20:31:18 +09001089func (c *Module) ExportedIncludeDirs() android.Paths {
1090 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1091 return flagsProducer.exportedDirs()
1092 }
Jiyong Park232e7852019-11-04 12:23:40 +09001093 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001094}
1095
1096func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1097 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1098 return flagsProducer.exportedSystemDirs()
1099 }
Jiyong Park232e7852019-11-04 12:23:40 +09001100 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001101}
1102
1103func (c *Module) ExportedFlags() []string {
1104 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1105 return flagsProducer.exportedFlags()
1106 }
Jiyong Park232e7852019-11-04 12:23:40 +09001107 return nil
1108}
1109
1110func (c *Module) ExportedDeps() android.Paths {
1111 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1112 return flagsProducer.exportedDeps()
1113 }
1114 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001115}
1116
Inseob Kimd110f872019-12-06 13:15:38 +09001117func (c *Module) ExportedGeneratedHeaders() android.Paths {
1118 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1119 return flagsProducer.exportedGeneratedHeaders()
1120 }
1121 return nil
1122}
1123
Bill Peckham945441c2020-08-31 16:07:58 -07001124func (c *Module) ExcludeFromVendorSnapshot() bool {
1125 return Bool(c.Properties.Exclude_from_vendor_snapshot)
1126}
1127
Jiyong Parkf1194352019-02-25 11:05:47 +09001128func isBionic(name string) bool {
1129 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001130 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001131 return true
1132 }
1133 return false
1134}
1135
Martin Stjernholm279de572019-09-10 23:18:20 +01001136func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001137 if name == "libclang_rt.hwasan-aarch64-android" {
Jooyung Han8ce8db92020-05-15 19:05:05 +09001138 return true
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001139 }
1140 return isBionic(name)
1141}
1142
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001143func (c *Module) XrefCcFiles() android.Paths {
1144 return c.kytheFiles
1145}
1146
Colin Crossca860ac2016-01-04 14:34:37 -08001147type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001148 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001149 moduleContextImpl
1150}
1151
Colin Cross37047f12016-12-13 17:06:13 -08001152type depsContext struct {
1153 android.BottomUpMutatorContext
1154 moduleContextImpl
1155}
1156
Colin Crossca860ac2016-01-04 14:34:37 -08001157type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001158 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001159 moduleContextImpl
1160}
1161
1162type moduleContextImpl struct {
1163 mod *Module
1164 ctx BaseModuleContext
1165}
1166
Colin Crossb98c8b02016-07-29 13:44:28 -07001167func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001168 return ctx.mod.toolchain(ctx.ctx)
1169}
1170
1171func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001172 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001173}
1174
1175func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001176 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001177}
1178
Jiyong Park1d1119f2019-07-29 21:27:18 +09001179func (ctx *moduleContextImpl) header() bool {
1180 return ctx.mod.header()
1181}
1182
Inseob Kim7f283f42020-06-01 21:53:49 +09001183func (ctx *moduleContextImpl) binary() bool {
1184 return ctx.mod.binary()
1185}
1186
Inseob Kim1042d292020-06-01 23:23:05 +09001187func (ctx *moduleContextImpl) object() bool {
1188 return ctx.mod.object()
1189}
1190
Jooyung Hanccce2f22020-03-07 03:45:53 +09001191func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001192 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001193}
1194
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001195func (ctx *moduleContextImpl) useSdk() bool {
Colin Crossc511bc52020-04-07 16:50:32 +00001196 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001197}
1198
1199func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001200 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001201 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001202 vndkVer := ctx.mod.VndkVersion()
Jooyung Han03302ee2020-04-08 09:22:26 +09001203 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001204 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001205 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001206 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001207 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001208 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001209 }
1210 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001211}
1212
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001213func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001214 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001215}
Justin Yun8effde42017-06-23 19:24:43 +09001216
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001217func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001218 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001219}
1220
Inseob Kim9516ee92019-05-09 10:56:13 +09001221func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1222 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001223}
1224
Inseob Kim9516ee92019-05-09 10:56:13 +09001225func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1226 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001227}
1228
Inseob Kim9516ee92019-05-09 10:56:13 +09001229func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1230 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001231}
1232
Logan Chienf3511742017-10-31 18:04:35 +08001233func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001234 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001235}
1236
Yi Kong7e53c572018-02-14 18:16:12 +08001237func (ctx *moduleContextImpl) isPgoCompile() bool {
1238 return ctx.mod.isPgoCompile()
1239}
1240
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001241func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1242 return ctx.mod.isNDKStubLibrary()
1243}
1244
Justin Yun8effde42017-06-23 19:24:43 +09001245func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001246 return ctx.mod.isVndkSp()
1247}
1248
1249func (ctx *moduleContextImpl) isVndkExt() bool {
1250 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001251}
1252
Vic Yangefd249e2018-11-12 20:19:56 -08001253func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001254 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001255}
1256
Logan Chien2f2b8902018-07-10 15:01:19 +08001257// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001258func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001259 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1260 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001261 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001262
Hsin-Yi Chenf81bb652020-04-07 21:42:19 +08001263 // Coverage builds have extra symbols.
1264 if ctx.mod.isCoverageVariant() {
1265 return false
1266 }
1267
Doug Hornc32c6b02019-01-17 14:44:05 -08001268 if ctx.ctx.Fuchsia() {
1269 return false
1270 }
1271
Logan Chien2f2b8902018-07-10 15:01:19 +08001272 if sanitize := ctx.mod.sanitize; sanitize != nil {
1273 if !sanitize.isVariantOnProductionDevice() {
1274 return false
1275 }
1276 }
1277 if !ctx.ctx.Device() {
1278 // Host modules do not need ABI dumps.
1279 return false
1280 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001281 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001282 // Stubs do not need ABI dumps.
1283 return false
1284 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001285 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001286}
1287
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001288func (ctx *moduleContextImpl) selectedStl() string {
1289 if stl := ctx.mod.stl; stl != nil {
1290 return stl.Properties.SelectedStl
1291 }
1292 return ""
1293}
1294
Ivan Lozanobd721262018-11-27 14:33:03 -08001295func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1296 return ctx.mod.linker.useClangLld(actx)
1297}
1298
Colin Crossce75d2c2016-10-06 16:12:58 -07001299func (ctx *moduleContextImpl) baseModuleName() string {
1300 return ctx.mod.ModuleBase.BaseModuleName()
1301}
1302
Logan Chienf3511742017-10-31 18:04:35 +08001303func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1304 return ctx.mod.getVndkExtendsModuleName()
1305}
1306
Logan Chiene274fc92019-12-03 11:18:32 -08001307func (ctx *moduleContextImpl) isForPlatform() bool {
1308 return ctx.mod.IsForPlatform()
1309}
1310
Colin Crosse07f2312020-08-13 11:24:56 -07001311func (ctx *moduleContextImpl) apexVariationName() string {
1312 return ctx.mod.ApexVariationName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001313}
1314
Jooyung Hanccce2f22020-03-07 03:45:53 +09001315func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001316 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001317}
1318
Jiyong Parkb0788572018-12-20 22:10:17 +09001319func (ctx *moduleContextImpl) hasStubsVariants() bool {
1320 return ctx.mod.HasStubsVariants()
1321}
1322
1323func (ctx *moduleContextImpl) isStubs() bool {
1324 return ctx.mod.IsStubs()
1325}
1326
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001327func (ctx *moduleContextImpl) bootstrap() bool {
1328 return ctx.mod.bootstrap()
1329}
1330
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001331func (ctx *moduleContextImpl) nativeCoverage() bool {
1332 return ctx.mod.nativeCoverage()
1333}
1334
Colin Cross635c3b02016-05-18 15:37:25 -07001335func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001336 return &Module{
1337 hod: hod,
1338 multilib: multilib,
1339 }
1340}
1341
Colin Cross635c3b02016-05-18 15:37:25 -07001342func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001343 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001344 module.features = []feature{
1345 &tidyFeature{},
1346 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001347 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001348 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001349 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001350 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001351 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001352 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001353 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001354 return module
1355}
1356
Colin Crossce75d2c2016-10-06 16:12:58 -07001357func (c *Module) Prebuilt() *android.Prebuilt {
1358 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1359 return p.prebuilt()
1360 }
1361 return nil
1362}
1363
1364func (c *Module) Name() string {
1365 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001366 if p, ok := c.linker.(interface {
1367 Name(string) string
1368 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001369 name = p.Name(name)
1370 }
1371 return name
1372}
1373
Alex Light3d673592019-01-18 14:37:31 -08001374func (c *Module) Symlinks() []string {
1375 if p, ok := c.installer.(interface {
1376 symlinkList() []string
1377 }); ok {
1378 return p.symlinkList()
1379 }
1380 return nil
1381}
1382
Jeff Gaston294356f2017-09-27 17:05:30 -07001383// orderDeps reorders dependencies into a list such that if module A depends on B, then
1384// A will precede B in the resultant list.
1385// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001386// Note that directSharedDeps should be the analogous static library for each shared lib dep
1387func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) {
Jeff Gaston294356f2017-09-27 17:05:30 -07001388 // If A depends on B, then
1389 // Every list containing A will also contain B later in the list
1390 // So, after concatenating all lists, the final instance of B will have come from the same
1391 // original list as the final instance of A
1392 // So, the final instance of B will be later in the concatenation than the final A
1393 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1394 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001395 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001396 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001397 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1398 }
1399 for _, dep := range directSharedDeps {
1400 orderedAllDeps = append(orderedAllDeps, dep)
1401 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001402 }
1403
Colin Crossb6715442017-10-24 11:13:31 -07001404 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001405
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001406 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001407 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001408 // resultant list to only what the caller has chosen to include in directStaticDeps
1409 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001410
1411 return orderedAllDeps, orderedDeclaredDeps
1412}
1413
Ivan Lozano183a3212019-10-18 14:18:45 -07001414func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001415 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001416 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001417 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1418 staticDepFiles := []android.Path{}
1419 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001420 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1421 if dep.OutputFile().Valid() {
1422 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1423 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1424 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001425 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001426 sharedDepFiles := []android.Path{}
1427 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001428 if sharedDep.HasStaticVariant() {
1429 staticAnalogue := sharedDep.GetStaticVariant()
1430 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1431 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001432 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001433 }
1434
1435 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001436 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1437 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001438
1439 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001440}
1441
Roland Levillainf89cd092019-07-29 16:22:59 +01001442func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1443 test, ok := c.linker.(testPerSrc)
1444 return ok && test.isAllTestsVariation()
1445}
1446
Chris Parsons216e10a2020-07-09 17:12:52 -04001447func (c *Module) DataPaths() []android.DataPath {
Liz Kammer1c14a212020-05-12 15:26:55 -07001448 if p, ok := c.installer.(interface {
Chris Parsons216e10a2020-07-09 17:12:52 -04001449 dataPaths() []android.DataPath
Liz Kammer1c14a212020-05-12 15:26:55 -07001450 }); ok {
1451 return p.dataPaths()
1452 }
1453 return nil
1454}
1455
Justin Yun5f7f7e82019-11-18 19:52:14 +09001456func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1457 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1458 // "current", it will append the VNDK version to the name suffix.
1459 var vndkVersion string
1460 var nameSuffix string
1461 if c.inProduct() {
1462 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1463 nameSuffix = productSuffix
1464 } else {
1465 vndkVersion = ctx.DeviceConfig().VndkVersion()
1466 nameSuffix = vendorSuffix
1467 }
1468 if vndkVersion == "current" {
1469 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1470 }
1471 if c.Properties.VndkVersion != vndkVersion {
1472 // add version suffix only if the module is using different vndk version than the
1473 // version in product or vendor partition.
1474 nameSuffix += "." + c.Properties.VndkVersion
1475 }
1476 return nameSuffix
1477}
1478
Colin Cross635c3b02016-05-18 15:37:25 -07001479func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001480 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001481 //
1482 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1483 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1484 // module and return early, as this module does not produce an output file per se.
1485 if c.IsTestPerSrcAllTestsVariation() {
1486 c.outputFile = android.OptionalPath{}
1487 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001488 }
1489
Jooyung Han38002912019-05-16 04:01:54 +09001490 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001491
Inseob Kim64c43952019-08-26 16:52:35 +09001492 c.Properties.SubName = ""
1493
1494 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1495 c.Properties.SubName += nativeBridgeSuffix
1496 }
1497
Justin Yun5f7f7e82019-11-18 19:52:14 +09001498 _, llndk := c.linker.(*llndkStubDecorator)
1499 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1500 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1501 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1502 // added for product variant only when we have vendor and product variants with core
1503 // variant. The suffix is not added for vendor-only or product-only module.
1504 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1505 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001506 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1507 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1508 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001509 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1510 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001511 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001512 c.Properties.SubName += recoverySuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001513 } else if c.IsSdkVariant() && (c.Properties.SdkAndPlatformVariantVisibleToMake || c.SplitPerApiLevel()) {
Colin Crossc511bc52020-04-07 16:50:32 +00001514 c.Properties.SubName += sdkSuffix
Dan Albert92fe7402020-07-15 13:33:30 -07001515 if c.SplitPerApiLevel() {
1516 c.Properties.SubName += "." + c.SdkVersion()
1517 }
Inseob Kim64c43952019-08-26 16:52:35 +09001518 }
1519
Colin Crossca860ac2016-01-04 14:34:37 -08001520 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001521 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001522 moduleContextImpl: moduleContextImpl{
1523 mod: c,
1524 },
1525 }
1526 ctx.ctx = ctx
1527
Colin Crossf18e1102017-11-16 14:33:08 -08001528 deps := c.depsToPaths(ctx)
1529 if ctx.Failed() {
1530 return
1531 }
1532
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001533 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1534 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1535 }
1536
Colin Crossca860ac2016-01-04 14:34:37 -08001537 flags := Flags{
1538 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001539 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001540 }
Colin Crossca860ac2016-01-04 14:34:37 -08001541 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001542 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001543 }
1544 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001545 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001546 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001547 if c.stl != nil {
1548 flags = c.stl.flags(ctx, flags)
1549 }
Colin Cross16b23492016-01-06 14:41:07 -08001550 if c.sanitize != nil {
1551 flags = c.sanitize.flags(ctx, flags)
1552 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001553 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001554 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001555 }
Stephen Craneba090d12017-05-09 15:44:35 -07001556 if c.lto != nil {
1557 flags = c.lto.flags(ctx, flags)
1558 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001559 if c.pgo != nil {
1560 flags = c.pgo.flags(ctx, flags)
1561 }
Colin Crossca860ac2016-01-04 14:34:37 -08001562 for _, feature := range c.features {
1563 flags = feature.flags(ctx, flags)
1564 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001565 if ctx.Failed() {
1566 return
1567 }
1568
Colin Cross4af21ed2019-11-04 09:37:55 -08001569 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1570 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1571 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001572
Colin Cross4af21ed2019-11-04 09:37:55 -08001573 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001574
1575 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001576 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001577 }
1578 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001579 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001580 }
1581
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001582 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001583 // We need access to all the flags seen by a source file.
1584 if c.sabi != nil {
1585 flags = c.sabi.flags(ctx, flags)
1586 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001587
Colin Cross4af21ed2019-11-04 09:37:55 -08001588 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001589
Colin Crossca860ac2016-01-04 14:34:37 -08001590 // Optimization to reduce size of build.ninja
1591 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001592 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1593 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1594 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1595 flags.Local.CFlags = []string{"$cflags"}
1596 flags.Local.CppFlags = []string{"$cppflags"}
1597 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001598
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001599 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001600 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001601 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001602 if ctx.Failed() {
1603 return
1604 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001605 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001606 }
1607
Colin Crossca860ac2016-01-04 14:34:37 -08001608 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001609 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001610 if ctx.Failed() {
1611 return
1612 }
Colin Cross635c3b02016-05-18 15:37:25 -07001613 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001614
1615 // If a lib is directly included in any of the APEXes, unhide the stubs
1616 // variant having the latest version gets visible to make. In addition,
1617 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1618 // force anything in the make world to link against the stubs library.
1619 // (unless it is explicitly referenced via .bootstrap suffix or the
1620 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001621 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001622 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001623 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001624 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001625 c.Properties.HideFromMake = false // unhide
1626 // Note: this is still non-installable
1627 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001628
1629 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1630 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1631 if isSnapshotAware(ctx, c) {
1632 i.collectHeadersForSnapshot(ctx)
1633 }
1634 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001635 }
Colin Cross5049f022015-03-18 13:28:46 -07001636
Inseob Kim1f086e22019-05-09 13:29:15 +09001637 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001638 c.installer.install(ctx, c.outputFile.Path())
1639 if ctx.Failed() {
1640 return
Colin Crossca860ac2016-01-04 14:34:37 -08001641 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001642 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1643 // If the module has been specifically configure to not be installed then
1644 // skip the installation as otherwise it will break when running inside make
1645 // as the output path to install will not be specified. Not all uninstallable
1646 // modules can skip installation as some are needed for resolving make side
1647 // dependencies.
1648 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001649 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001650}
1651
Colin Cross0ea8ba82019-06-06 14:33:29 -07001652func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001653 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001654 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001655 }
Colin Crossca860ac2016-01-04 14:34:37 -08001656 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001657}
1658
Colin Crossca860ac2016-01-04 14:34:37 -08001659func (c *Module) begin(ctx BaseModuleContext) {
1660 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001661 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001662 }
Colin Crossca860ac2016-01-04 14:34:37 -08001663 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001664 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001665 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001666 if c.stl != nil {
1667 c.stl.begin(ctx)
1668 }
Colin Cross16b23492016-01-06 14:41:07 -08001669 if c.sanitize != nil {
1670 c.sanitize.begin(ctx)
1671 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001672 if c.coverage != nil {
1673 c.coverage.begin(ctx)
1674 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001675 if c.sabi != nil {
1676 c.sabi.begin(ctx)
1677 }
Justin Yun8effde42017-06-23 19:24:43 +09001678 if c.vndkdep != nil {
1679 c.vndkdep.begin(ctx)
1680 }
Stephen Craneba090d12017-05-09 15:44:35 -07001681 if c.lto != nil {
1682 c.lto.begin(ctx)
1683 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001684 if c.pgo != nil {
1685 c.pgo.begin(ctx)
1686 }
Colin Crossca860ac2016-01-04 14:34:37 -08001687 for _, feature := range c.features {
1688 feature.begin(ctx)
1689 }
Dan Albert92fe7402020-07-15 13:33:30 -07001690 if ctx.useSdk() && c.IsSdkVariant() {
Dan Albertf5415d72017-08-17 16:19:59 -07001691 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001692 if err != nil {
1693 ctx.PropertyErrorf("sdk_version", err.Error())
1694 }
Nan Zhang0007d812017-11-07 10:57:05 -08001695 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001696 }
Colin Crossca860ac2016-01-04 14:34:37 -08001697}
1698
Colin Cross37047f12016-12-13 17:06:13 -08001699func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001700 deps := Deps{}
1701
1702 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001703 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001704 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001705 // Add the PGO dependency (the clang_rt.profile runtime library), which
1706 // sometimes depends on symbols from libgcc, before libgcc gets added
1707 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001708 if c.pgo != nil {
1709 deps = c.pgo.deps(ctx, deps)
1710 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001711 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001712 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001713 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001714 if c.stl != nil {
1715 deps = c.stl.deps(ctx, deps)
1716 }
Colin Cross16b23492016-01-06 14:41:07 -08001717 if c.sanitize != nil {
1718 deps = c.sanitize.deps(ctx, deps)
1719 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001720 if c.coverage != nil {
1721 deps = c.coverage.deps(ctx, deps)
1722 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001723 if c.sabi != nil {
1724 deps = c.sabi.deps(ctx, deps)
1725 }
Justin Yun8effde42017-06-23 19:24:43 +09001726 if c.vndkdep != nil {
1727 deps = c.vndkdep.deps(ctx, deps)
1728 }
Stephen Craneba090d12017-05-09 15:44:35 -07001729 if c.lto != nil {
1730 deps = c.lto.deps(ctx, deps)
1731 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001732 for _, feature := range c.features {
1733 deps = feature.deps(ctx, deps)
1734 }
1735
Colin Crossb6715442017-10-24 11:13:31 -07001736 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1737 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1738 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1739 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1740 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1741 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001742 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001743
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001744 for _, lib := range deps.ReexportSharedLibHeaders {
1745 if !inList(lib, deps.SharedLibs) {
1746 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1747 }
1748 }
1749
1750 for _, lib := range deps.ReexportStaticLibHeaders {
1751 if !inList(lib, deps.StaticLibs) {
1752 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1753 }
1754 }
1755
Colin Cross5950f382016-12-13 12:50:57 -08001756 for _, lib := range deps.ReexportHeaderLibHeaders {
1757 if !inList(lib, deps.HeaderLibs) {
1758 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1759 }
1760 }
1761
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001762 for _, gen := range deps.ReexportGeneratedHeaders {
1763 if !inList(gen, deps.GeneratedHeaders) {
1764 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1765 }
1766 }
1767
Colin Crossc99deeb2016-04-11 15:06:20 -07001768 return deps
1769}
1770
Dan Albert7e9d2952016-08-04 13:02:36 -07001771func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001772 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001773 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001774 moduleContextImpl: moduleContextImpl{
1775 mod: c,
1776 },
1777 }
1778 ctx.ctx = ctx
1779
Colin Crossca860ac2016-01-04 14:34:37 -08001780 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001781}
1782
Jiyong Park7ed9de32018-10-15 22:25:07 +09001783// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001784func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001785 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1786 version := name[sharp+1:]
1787 libname := name[:sharp]
1788 return libname, version
1789 }
1790 return name, ""
1791}
1792
Dan Albert92fe7402020-07-15 13:33:30 -07001793func GetCrtVariations(ctx android.BottomUpMutatorContext,
1794 m LinkableInterface) []blueprint.Variation {
1795 if ctx.Os() != android.Android {
1796 return nil
1797 }
1798 if m.UseSdk() {
1799 return []blueprint.Variation{
1800 {Mutator: "sdk", Variation: "sdk"},
1801 {Mutator: "ndk_api", Variation: m.SdkVersion()},
1802 }
1803 }
1804 return []blueprint.Variation{
1805 {Mutator: "sdk", Variation: ""},
1806 }
1807}
1808
Colin Cross1e676be2016-10-12 14:38:15 -07001809func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001810 if !c.Enabled() {
1811 return
1812 }
1813
Colin Cross37047f12016-12-13 17:06:13 -08001814 ctx := &depsContext{
1815 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001816 moduleContextImpl: moduleContextImpl{
1817 mod: c,
1818 },
1819 }
1820 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001821
Colin Crossc99deeb2016-04-11 15:06:20 -07001822 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001823
Yo Chiang219968c2020-09-22 18:45:04 +08001824 c.Properties.AndroidMkSystemSharedLibs = deps.SystemSharedLibs
1825
Dan Albert914449f2016-06-17 16:45:24 -07001826 variantNdkLibs := []string{}
1827 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001828 if ctx.Os() == android.Android {
Inseob Kimeec88e12020-01-22 11:11:29 +09001829 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001830 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001831 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001832 // 1. Name of an NDK library that refers to a prebuilt module.
1833 // For each of these, it adds the name of the prebuilt module (which will be in
1834 // prebuilts/ndk) to the list of nonvariant libs.
1835 // 2. Name of an NDK library that refers to an ndk_library module.
1836 // For each of these, it adds the name of the ndk_library module to the list of
1837 // variant libs.
1838 // 3. Anything else (so anything that isn't an NDK library).
1839 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001840 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001841 // The caller can then know to add the variantLibs dependencies differently from the
1842 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001843
Inseob Kim9516ee92019-05-09 10:56:13 +09001844 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001845 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1846
1847 rewriteVendorLibs := func(lib string) string {
1848 if isLlndkLibrary(lib, ctx.Config()) {
1849 return lib + llndkLibrarySuffix
1850 }
1851
1852 // only modules with BOARD_VNDK_VERSION uses snapshot.
1853 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1854 return lib
1855 }
1856
1857 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1858 return snapshot
1859 }
1860
1861 return lib
1862 }
1863
1864 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865 variantLibs = []string{}
1866 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001867 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001868 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001869 name, _ := StubsLibNameAndVersion(entry)
Dan Albertde5aade2020-06-30 12:32:51 -07001870 if ctx.useSdk() && inList(name, ndkKnownLibs) {
1871 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Inseob Kimeec88e12020-01-22 11:11:29 +09001872 } else if ctx.useVndk() {
1873 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001874 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001875 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001876 if actx.OtherModuleExists(vendorPublicLib) {
1877 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1878 } else {
1879 // This can happen if vendor_public_library module is defined in a
1880 // namespace that isn't visible to the current module. In that case,
1881 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001882 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001883 }
Dan Albert914449f2016-06-17 16:45:24 -07001884 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001885 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001886 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001887 }
1888 }
Dan Albert914449f2016-06-17 16:45:24 -07001889 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001890 }
1891
Inseob Kimeec88e12020-01-22 11:11:29 +09001892 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1893 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1894 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1895 if ctx.useVndk() {
1896 for idx, lib := range deps.RuntimeLibs {
1897 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1898 }
1899 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001900 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001901
Jiyong Park7e636d02019-01-28 16:16:54 +09001902 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001903 if c.linker != nil {
1904 if library, ok := c.linker.(*libraryDecorator); ok {
1905 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001906 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001907 }
1908 }
1909 }
1910
Inseob Kimeec88e12020-01-22 11:11:29 +09001911 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1912 // only modules with BOARD_VNDK_VERSION uses snapshot.
1913 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1914 return lib
1915 }
1916
1917 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1918 return snapshot
1919 }
1920
1921 return lib
1922 }
1923
1924 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001925 for _, lib := range deps.HeaderLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001926 depTag := libraryDependencyTag{Kind: headerLibraryDependency}
Colin Cross32ec36c2016-12-15 07:39:51 -08001927 if inList(lib, deps.ReexportHeaderLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001928 depTag.reexportFlags = true
Colin Cross32ec36c2016-12-15 07:39:51 -08001929 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001930
1931 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1932
Jiyong Park7e636d02019-01-28 16:16:54 +09001933 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001934 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001935 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001936 } else {
1937 actx.AddVariationDependencies(nil, depTag, lib)
1938 }
1939 }
1940
1941 if buildStubs {
1942 // Stubs lib does not have dependency to other static/shared libraries.
1943 // Don't proceed.
1944 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001945 }
Colin Cross5950f382016-12-13 12:50:57 -08001946
Inseob Kimc0907f12019-02-08 21:00:45 +09001947 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001948 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001949
Jiyong Park5d1598f2019-02-25 22:14:17 +09001950 for _, lib := range deps.WholeStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001951 depTag := libraryDependencyTag{Kind: staticLibraryDependency, wholeStatic: true, reexportFlags: true}
Jiyong Park5d1598f2019-02-25 22:14:17 +09001952 if impl, ok := syspropImplLibraries[lib]; ok {
1953 lib = impl
1954 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001955
1956 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1957
Jiyong Park5d1598f2019-02-25 22:14:17 +09001958 actx.AddVariationDependencies([]blueprint.Variation{
1959 {Mutator: "link", Variation: "static"},
1960 }, depTag, lib)
1961 }
1962
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001963 for _, lib := range deps.StaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001964 depTag := libraryDependencyTag{Kind: staticLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001965 if inList(lib, deps.ReexportStaticLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07001966 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001967 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001968
1969 if impl, ok := syspropImplLibraries[lib]; ok {
1970 lib = impl
1971 }
1972
Inseob Kimeec88e12020-01-22 11:11:29 +09001973 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1974
Dan Willemsen59339a22018-07-22 21:18:45 -07001975 actx.AddVariationDependencies([]blueprint.Variation{
1976 {Mutator: "link", Variation: "static"},
1977 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001978 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001979
Jooyung Han75568392020-03-20 04:29:24 +09001980 // staticUnwinderDep is treated as staticDep for Q apexes
1981 // so that native libraries/binaries are linked with static unwinder
1982 // because Q libc doesn't have unwinder APIs
1983 if deps.StaticUnwinderIfLegacy {
Colin Cross6e511a92020-07-27 21:26:48 -07001984 depTag := libraryDependencyTag{Kind: staticLibraryDependency, staticUnwinder: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001985 actx.AddVariationDependencies([]blueprint.Variation{
1986 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001987 }, depTag, rewriteSnapshotLibs(staticUnwinder(actx), vendorSnapshotStaticLibs))
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001988 }
1989
Inseob Kimeec88e12020-01-22 11:11:29 +09001990 for _, lib := range deps.LateStaticLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07001991 depTag := libraryDependencyTag{Kind: staticLibraryDependency, Order: lateLibraryDependency}
Inseob Kimeec88e12020-01-22 11:11:29 +09001992 actx.AddVariationDependencies([]blueprint.Variation{
1993 {Mutator: "link", Variation: "static"},
Colin Cross6e511a92020-07-27 21:26:48 -07001994 }, depTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
Inseob Kimeec88e12020-01-22 11:11:29 +09001995 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001996
Colin Cross6e511a92020-07-27 21:26:48 -07001997 addSharedLibDependencies := func(depTag libraryDependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001998 var variations []blueprint.Variation
1999 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han624d35c2020-04-10 12:57:24 +09002000 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002001 // Version is explicitly specified. i.e. libFoo#30
2002 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Colin Cross6e511a92020-07-27 21:26:48 -07002003 depTag.explicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09002004 }
2005 actx.AddVariationDependencies(variations, depTag, name)
2006
Jooyung Han03b51852020-02-26 22:45:42 +09002007 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002008 // The stubs library will be used when the depending module is built for APEX and
2009 // the dependent module is not in the same APEX.
Jooyung Han624d35c2020-04-10 12:57:24 +09002010 if version == "" && VersionVariantAvailable(c) {
Jooyung Han03b51852020-02-26 22:45:42 +09002011 for _, ver := range stubsVersionsFor(actx.Config())[name] {
2012 // Note that depTag.ExplicitlyVersioned is false in this case.
2013 actx.AddVariationDependencies([]blueprint.Variation{
2014 {Mutator: "link", Variation: "shared"},
2015 {Mutator: "version", Variation: ver},
2016 }, depTag, name)
2017 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002018 }
2019 }
2020
Jiyong Park7ed9de32018-10-15 22:25:07 +09002021 // shared lib names without the #version suffix
2022 var sharedLibNames []string
2023
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002024 for _, lib := range deps.SharedLibs {
Colin Cross6e511a92020-07-27 21:26:48 -07002025 depTag := libraryDependencyTag{Kind: sharedLibraryDependency}
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002026 if inList(lib, deps.ReexportSharedLibHeaders) {
Colin Cross6e511a92020-07-27 21:26:48 -07002027 depTag.reexportFlags = true
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002028 }
Inseob Kimc0907f12019-02-08 21:00:45 +09002029
2030 if impl, ok := syspropImplLibraries[lib]; ok {
2031 lib = impl
2032 }
2033
Jiyong Park73c54ee2019-10-22 20:31:18 +09002034 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09002035 sharedLibNames = append(sharedLibNames, name)
2036
Jiyong Park25fc6a92018-11-18 18:02:45 +09002037 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002038 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002039
Jiyong Park7ed9de32018-10-15 22:25:07 +09002040 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002041 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09002042 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
2043 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
2044 // linking against both the stubs lib and the non-stubs lib at the same time.
2045 continue
2046 }
Colin Cross6e511a92020-07-27 21:26:48 -07002047 depTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency}
2048 addSharedLibDependencies(depTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09002049 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002050
Dan Willemsen59339a22018-07-22 21:18:45 -07002051 actx.AddVariationDependencies([]blueprint.Variation{
2052 {Mutator: "link", Variation: "shared"},
Chris Parsons79d66a52020-06-05 17:26:16 -04002053 }, dataLibDepTag, deps.DataLibs...)
2054
2055 actx.AddVariationDependencies([]blueprint.Variation{
2056 {Mutator: "link", Variation: "shared"},
Dan Willemsen59339a22018-07-22 21:18:45 -07002057 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08002058
Colin Cross68861832016-07-08 10:41:41 -07002059 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002060
2061 for _, gen := range deps.GeneratedHeaders {
2062 depTag := genHeaderDepTag
2063 if inList(gen, deps.ReexportGeneratedHeaders) {
2064 depTag = genHeaderExportDepTag
2065 }
2066 actx.AddDependency(c, depTag, gen)
2067 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002068
Colin Cross42d48b72018-08-29 14:10:52 -07002069 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07002070
Inseob Kim1042d292020-06-01 23:23:05 +09002071 vendorSnapshotObjects := vendorSnapshotObjects(actx.Config())
2072
Dan Albert92fe7402020-07-15 13:33:30 -07002073 crtVariations := GetCrtVariations(ctx, c)
Colin Crossc99deeb2016-04-11 15:06:20 -07002074 if deps.CrtBegin != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002075 actx.AddVariationDependencies(crtVariations, CrtBeginDepTag,
2076 rewriteSnapshotLibs(deps.CrtBegin, vendorSnapshotObjects))
Colin Crossca860ac2016-01-04 14:34:37 -08002077 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002078 if deps.CrtEnd != "" {
Dan Albert92fe7402020-07-15 13:33:30 -07002079 actx.AddVariationDependencies(crtVariations, CrtEndDepTag,
2080 rewriteSnapshotLibs(deps.CrtEnd, vendorSnapshotObjects))
Colin Cross21b9a242015-03-24 14:15:58 -07002081 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002082 if deps.LinkerFlagsFile != "" {
2083 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
2084 }
2085 if deps.DynamicLinker != "" {
2086 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002087 }
Dan Albert914449f2016-06-17 16:45:24 -07002088
2089 version := ctx.sdkVersion()
Colin Cross6e511a92020-07-27 21:26:48 -07002090
2091 ndkStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002092 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002093 {Mutator: "ndk_api", Variation: version},
2094 {Mutator: "link", Variation: "shared"},
2095 }, ndkStubDepTag, variantNdkLibs...)
Colin Cross6e511a92020-07-27 21:26:48 -07002096
2097 ndkLateStubDepTag := libraryDependencyTag{Kind: sharedLibraryDependency, Order: lateLibraryDependency, ndk: true, makeSuffix: "." + version}
Dan Albert914449f2016-06-17 16:45:24 -07002098 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07002099 {Mutator: "ndk_api", Variation: version},
2100 {Mutator: "link", Variation: "shared"},
2101 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08002102
2103 if vndkdep := c.vndkdep; vndkdep != nil {
2104 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08002105 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08002106 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07002107 {Mutator: "link", Variation: "shared"},
2108 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002109 }
2110 }
Colin Cross6362e272015-10-29 15:25:03 -07002111}
Colin Cross21b9a242015-03-24 14:15:58 -07002112
Colin Crosse40b4ea2018-10-02 22:25:58 -07002113func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07002114 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
2115 c.beginMutator(ctx)
2116 }
2117}
2118
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002119// Whether a module can link to another module, taking into
2120// account NDK linking.
Colin Cross6e511a92020-07-27 21:26:48 -07002121func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
2122 tag blueprint.DependencyTag) {
2123
2124 switch t := tag.(type) {
2125 case dependencyTag:
2126 if t != vndkExtDepTag {
2127 return
2128 }
2129 case libraryDependencyTag:
2130 default:
2131 return
2132 }
2133
Ivan Lozano52767be2019-10-18 14:49:46 -07002134 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002135 // Host code is not restricted
2136 return
2137 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002138
2139 // VNDK is cc.Module supported only for now.
2140 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002141 // Though vendor code is limited by the vendor mutator,
2142 // each vendor-available module needs to check
2143 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002144 if ccTo, ok := to.(*Module); ok {
2145 if ccFrom.vndkdep != nil {
2146 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2147 }
2148 } else {
2149 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002150 }
2151 return
2152 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002153 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 // Platform code can link to anything
2155 return
2156 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002157 if from.InRamdisk() {
2158 // Ramdisk code is not NDK
2159 return
2160 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002161 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002162 // Recovery code is not NDK
2163 return
2164 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002165 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002166 // These are always allowed
2167 return
2168 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002169 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 // These are allowed, but they don't set sdk_version
2171 return
2172 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002173 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002174 // These aren't real libraries, but are the stub shared libraries that are included in
2175 // the NDK.
2176 return
2177 }
Logan Chien834b9a62019-01-14 15:39:03 +08002178
Ivan Lozano52767be2019-10-18 14:49:46 -07002179 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002180 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2181 // to link to libc++ (non-NDK and without sdk_version).
2182 return
2183 }
2184
Ivan Lozano52767be2019-10-18 14:49:46 -07002185 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002186 // NDK code linking to platform code is never okay.
2187 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002188 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002189 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002190 }
2191
2192 // At this point we know we have two NDK libraries, but we need to
2193 // check that we're not linking against anything built against a higher
2194 // API level, as it is only valid to link against older or equivalent
2195 // APIs.
2196
Inseob Kim01a28722018-04-11 09:48:45 +09002197 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002198 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002199 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002200 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002201 // Current can't be linked against by anything else.
2202 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002204 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002205 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002206 if err != nil {
2207 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002208 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002209 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002210 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002211 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002212 if err != nil {
2213 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002214 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002215 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002216 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002217
Inseob Kim01a28722018-04-11 09:48:45 +09002218 if toApi > fromApi {
2219 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002220 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002221 }
2222 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002223 }
Dan Albert202fe492017-12-15 13:56:59 -08002224
2225 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002226 fromStl := from.SelectedStl()
2227 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002228 if fromStl == "" || toStl == "" {
2229 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002230 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002231 // We can be permissive with the system "STL" since it is only the C++
2232 // ABI layer, but in the future we should make sure that everyone is
2233 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002234 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002235 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002236 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2237 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002238 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002239}
2240
Jiyong Park5fb8c102018-04-09 12:03:06 +09002241// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002242// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2243// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002244// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002245func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2246 check := func(child, parent android.Module) bool {
2247 to, ok := child.(*Module)
2248 if !ok {
2249 // follow thru cc.Defaults, etc.
2250 return true
2251 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002252
Jooyung Hana70f0672019-01-18 15:20:43 +09002253 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2254 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002255 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002256
2257 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002258 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002259 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002260 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002261
Jooyung Han0302a842019-10-30 18:43:49 +09002262 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002263 return false
2264 }
2265
2266 var stringPath []string
2267 for _, m := range ctx.GetWalkPath() {
2268 stringPath = append(stringPath, m.Name())
2269 }
2270 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2271 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2272 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2273 return false
2274 }
2275 if module, ok := ctx.Module().(*Module); ok {
2276 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002277 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002278 ctx.WalkDeps(check)
2279 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002280 }
2281 }
2282}
2283
Colin Crossc99deeb2016-04-11 15:06:20 -07002284// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002285func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002286 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002287
Ivan Lozano183a3212019-10-18 14:18:45 -07002288 directStaticDeps := []LinkableInterface{}
2289 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002290
Inseob Kim69378442019-06-03 19:10:47 +09002291 reexportExporter := func(exporter exportedFlagsProducer) {
2292 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2293 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2294 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2295 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002296 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002297 }
2298
Jooyung Hande34d232020-07-23 13:04:15 +09002299 // For the dependency from platform to apex, use the latest stubs
2300 c.apexSdkVersion = android.FutureApiLevel
2301 if !c.IsForPlatform() {
2302 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2303 }
2304
2305 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2306 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2307 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2308 // (b/144430859)
2309 c.apexSdkVersion = android.FutureApiLevel
2310 }
2311
Colin Crossd11fcda2017-10-23 17:59:01 -07002312 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002313 depName := ctx.OtherModuleName(dep)
2314 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002315
Ivan Lozano52767be2019-10-18 14:49:46 -07002316 ccDep, ok := dep.(LinkableInterface)
2317 if !ok {
2318
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002319 // handling for a few module types that aren't cc Module but that are also supported
2320 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002321 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002322 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002323 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2324 genRule.GeneratedSourceFiles()...)
2325 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002326 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002327 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002328 // Support exported headers from a generated_sources dependency
2329 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002330 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002331 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Inseob Kimd110f872019-12-06 13:15:38 +09002332 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002333 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002334 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002335 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002336 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002337 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002338 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2339 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002340 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002341 // 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 +09002342 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002343
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002344 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002345 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002346 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002347 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002348 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002349 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002350 files := genRule.GeneratedSourceFiles()
2351 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002352 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002353 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002354 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 -07002355 }
2356 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002357 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002358 }
Colin Crossca860ac2016-01-04 14:34:37 -08002359 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002360 return
2361 }
2362
Colin Crossfe17f6f2019-03-28 19:30:56 -07002363 if depTag == android.ProtoPluginDepTag {
2364 return
2365 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002366 if depTag == llndkImplDep {
2367 return
2368 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002369
Colin Crossd11fcda2017-10-23 17:59:01 -07002370 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002371 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2372 return
2373 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002374 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002375 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2376 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002377 return
2378 }
2379
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002380 // re-exporting flags
2381 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002382 // reusing objects only make sense for cc.Modules.
2383 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002384 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002385 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002386 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002387 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002388 return
2389 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002390 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002391
Jiyong Parke4bb9862019-02-01 00:31:10 +09002392 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002393 // staticVariants are a cc.Module specific concept.
2394 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002395 c.staticVariant = ccDep
2396 return
2397 }
2398 }
2399
Colin Cross6e511a92020-07-27 21:26:48 -07002400 checkLinkType(ctx, c, ccDep, depTag)
2401
2402 linkFile := ccDep.OutputFile()
2403
2404 if libDepTag, ok := depTag.(libraryDependencyTag); ok {
2405 // Only use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2406 if libDepTag.staticUnwinder && c.apexSdkVersion > android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002407 return
2408 }
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002409
Colin Cross6e511a92020-07-27 21:26:48 -07002410 if ccDep.CcLibrary() && !libDepTag.static() {
Ivan Lozano52767be2019-10-18 14:49:46 -07002411 depIsStubs := ccDep.BuildStubs()
Jooyung Han624d35c2020-04-10 12:57:24 +09002412 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Colin Crossaede88c2020-08-11 12:17:01 -07002413 depInSameApexes := android.DirectlyInAllApexes(c.InApexes(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002414 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002415
2416 var useThisDep bool
Colin Cross6e511a92020-07-27 21:26:48 -07002417 if depIsStubs && libDepTag.explicitlyVersioned {
Jiyong Park25fc6a92018-11-18 18:02:45 +09002418 // Always respect dependency to the versioned stubs (i.e. libX#10)
2419 useThisDep = true
2420 } else if !depHasStubs {
2421 // Use non-stub variant if that is the only choice
2422 // (i.e. depending on a lib without stubs.version property)
2423 useThisDep = true
2424 } else if c.IsForPlatform() {
2425 // If not building for APEX, use stubs only when it is from
2426 // an APEX (and not from platform)
2427 useThisDep = (depInPlatform != depIsStubs)
Jooyung Han624d35c2020-04-10 12:57:24 +09002428 if c.bootstrap() {
2429 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002430 // always link to non-stub variant
2431 useThisDep = !depIsStubs
2432 }
Jiyong Park62304bb2020-04-13 16:19:48 +09002433 for _, testFor := range c.TestFor() {
2434 // Another exception: if this module is bundled with an APEX, then
2435 // it is linked with the non-stub variant of a module in the APEX
2436 // as if this is part of the APEX.
2437 if android.DirectlyInApex(testFor, depName) {
2438 useThisDep = !depIsStubs
2439 break
2440 }
2441 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002442 } else {
Colin Crossaede88c2020-08-11 12:17:01 -07002443 // If building for APEX, use stubs when the parent is in any APEX that
2444 // the child is not in.
2445 useThisDep = (depInSameApexes != depIsStubs)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002446 }
2447
Jooyung Han03b51852020-02-26 22:45:42 +09002448 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
Colin Cross6e511a92020-07-27 21:26:48 -07002449 if useThisDep && depIsStubs && !libDepTag.explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002450 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002451 if err != nil {
2452 ctx.OtherModuleErrorf(dep, err.Error())
2453 return
2454 }
2455 if versionToUse != ccDep.StubsVersion() {
2456 useThisDep = false
2457 }
2458 }
2459
Jiyong Park25fc6a92018-11-18 18:02:45 +09002460 if !useThisDep {
2461 return // stop processing this dep
2462 }
2463 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002464 if c.UseVndk() {
2465 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2466 // by default, use current version of LLNDK
2467 versionToUse := ""
2468 versions := stubsVersionsFor(ctx.Config())[depName]
Colin Crosse07f2312020-08-13 11:24:56 -07002469 if c.ApexVariationName() != "" && len(versions) > 0 {
Jooyung Han61b66e92020-03-21 14:21:46 +00002470 // if this is for use_vendor apex && dep has stubsVersions
2471 // apply the same rule of apex sdk enforcement to choose right version
2472 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002473 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002474 if err != nil {
2475 ctx.OtherModuleErrorf(dep, err.Error())
2476 return
2477 }
2478 }
2479 if versionToUse != ccDep.StubsVersion() {
2480 return
2481 }
2482 }
2483 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002484
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002485 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2486
Ivan Lozano52767be2019-10-18 14:49:46 -07002487 // Exporting flags only makes sense for cc.Modules
2488 if _, ok := ccDep.(*Module); ok {
2489 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002490 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002491 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002492 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002493
Colin Cross6e511a92020-07-27 21:26:48 -07002494 if libDepTag.reexportFlags {
Ivan Lozano52767be2019-10-18 14:49:46 -07002495 reexportExporter(i)
2496 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2497 // Re-exported shared library headers must be included as well since they can help us with type information
2498 // about template instantiations (instantiated from their headers).
2499 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2500 // scripts.
2501 c.sabi.Properties.ReexportedIncludes = append(
2502 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2503 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002504 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002505 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002506
Colin Cross6e511a92020-07-27 21:26:48 -07002507 var ptr *android.Paths
2508 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002509
Colin Cross6e511a92020-07-27 21:26:48 -07002510 depFile := android.OptionalPath{}
Colin Cross26c34ed2016-09-30 17:10:16 -07002511
Colin Cross6e511a92020-07-27 21:26:48 -07002512 switch {
2513 case libDepTag.header():
2514 // nothing
2515 case libDepTag.shared():
2516 ptr = &depPaths.SharedLibs
2517 switch libDepTag.Order {
2518 case earlyLibraryDependency:
2519 ptr = &depPaths.EarlySharedLibs
2520 depPtr = &depPaths.EarlySharedLibsDeps
2521 case normalLibraryDependency:
2522 ptr = &depPaths.SharedLibs
2523 depPtr = &depPaths.SharedLibsDeps
2524 directSharedDeps = append(directSharedDeps, ccDep)
2525 case lateLibraryDependency:
2526 ptr = &depPaths.LateSharedLibs
2527 depPtr = &depPaths.LateSharedLibsDeps
2528 default:
2529 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Colin Crossc99deeb2016-04-11 15:06:20 -07002530 }
Colin Cross6e511a92020-07-27 21:26:48 -07002531 depFile = ccDep.Toc()
2532 case libDepTag.static():
2533 if libDepTag.wholeStatic {
2534 ptr = &depPaths.WholeStaticLibs
2535 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2536 ctx.ModuleErrorf("module %q not a static library", depName)
2537 return
Inseob Kim752edec2020-03-14 01:30:34 +09002538 }
2539
Colin Cross6e511a92020-07-27 21:26:48 -07002540 // Because the static library objects are included, this only makes sense
2541 // in the context of proper cc.Modules.
2542 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2543 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2544 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2545 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2546 for i := range missingDeps {
2547 missingDeps[i] += postfix
2548 }
2549 ctx.AddMissingDependencies(missingDeps)
2550 }
2551 if _, ok := ccWholeStaticLib.linker.(prebuiltLinkerInterface); ok {
2552 depPaths.WholeStaticLibsFromPrebuilts = append(depPaths.WholeStaticLibsFromPrebuilts, linkFile.Path())
2553 } else {
2554 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2555 }
Inseob Kimeec88e12020-01-22 11:11:29 +09002556 } else {
Colin Cross6e511a92020-07-27 21:26:48 -07002557 ctx.ModuleErrorf(
2558 "non-cc.Modules cannot be included as whole static libraries.", depName)
2559 return
2560 }
2561
2562 } else {
2563 switch libDepTag.Order {
2564 case earlyLibraryDependency:
2565 panic(fmt.Errorf("early static libs not suppported"))
2566 case normalLibraryDependency:
2567 // static dependencies will be handled separately so they can be ordered
2568 // using transitive dependencies.
2569 ptr = nil
2570 directStaticDeps = append(directStaticDeps, ccDep)
2571 case lateLibraryDependency:
2572 ptr = &depPaths.LateStaticLibs
2573 default:
2574 panic(fmt.Errorf("unexpected library dependency order %d", libDepTag.Order))
Inseob Kimeec88e12020-01-22 11:11:29 +09002575 }
2576 }
2577 }
2578
Colin Cross6e511a92020-07-27 21:26:48 -07002579 if libDepTag.static() && !libDepTag.wholeStatic {
2580 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
2581 ctx.ModuleErrorf("module %q not a static library", depName)
2582 return
2583 }
Logan Chien43d34c32017-12-20 01:17:32 +08002584
Colin Cross6e511a92020-07-27 21:26:48 -07002585 // When combining coverage files for shared libraries and executables, coverage files
2586 // in static libraries act as if they were whole static libraries. The same goes for
2587 // source based Abi dump files.
2588 if c, ok := ccDep.(*Module); ok {
2589 staticLib := c.linker.(libraryInterface)
2590 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2591 staticLib.objs().coverageFiles...)
2592 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2593 staticLib.objs().sAbiDumpFiles...)
2594 } else if c, ok := ccDep.(LinkableInterface); ok {
2595 // Handle non-CC modules here
2596 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2597 c.CoverageFiles()...)
Jiyong Parkde866cb2018-12-07 23:08:36 +09002598 }
2599 }
2600
Colin Cross6e511a92020-07-27 21:26:48 -07002601 if ptr != nil {
2602 if !linkFile.Valid() {
2603 if !ctx.Config().AllowMissingDependencies() {
2604 ctx.ModuleErrorf("module %q missing output file", depName)
2605 } else {
2606 ctx.AddMissingDependencies([]string{depName})
2607 }
2608 return
2609 }
2610 *ptr = append(*ptr, linkFile.Path())
2611 }
2612
2613 if depPtr != nil {
2614 dep := depFile
2615 if !dep.Valid() {
2616 dep = linkFile
2617 }
2618 *depPtr = append(*depPtr, dep.Path())
2619 }
2620
2621 makeLibName := c.makeLibName(ctx, ccDep, depName) + libDepTag.makeSuffix
2622 switch {
2623 case libDepTag.header():
Colin Cross370173e2020-07-29 12:48:33 -07002624 c.Properties.AndroidMkHeaderLibs = append(
2625 c.Properties.AndroidMkHeaderLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002626 case libDepTag.shared():
2627 if ccDep.CcLibrary() {
2628 if ccDep.BuildStubs() && android.InAnyApex(depName) {
2629 // Add the dependency to the APEX(es) providing the library so that
2630 // m <module> can trigger building the APEXes as well.
2631 for _, an := range android.GetApexesForModule(depName) {
2632 c.Properties.ApexesProvidingSharedLibs = append(
2633 c.Properties.ApexesProvidingSharedLibs, an)
2634 }
2635 }
2636 }
2637
2638 // Note: the order of libs in this list is not important because
2639 // they merely serve as Make dependencies and do not affect this lib itself.
Colin Cross370173e2020-07-29 12:48:33 -07002640 c.Properties.AndroidMkSharedLibs = append(
2641 c.Properties.AndroidMkSharedLibs, makeLibName)
Colin Cross6e511a92020-07-27 21:26:48 -07002642 // Record baseLibName for snapshots.
2643 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
2644 case libDepTag.static():
2645 if libDepTag.wholeStatic {
2646 c.Properties.AndroidMkWholeStaticLibs = append(
2647 c.Properties.AndroidMkWholeStaticLibs, makeLibName)
2648 } else {
2649 c.Properties.AndroidMkStaticLibs = append(
2650 c.Properties.AndroidMkStaticLibs, makeLibName)
2651 }
2652 }
2653 } else {
2654 switch depTag {
2655 case runtimeDepTag:
2656 c.Properties.AndroidMkRuntimeLibs = append(
2657 c.Properties.AndroidMkRuntimeLibs, c.makeLibName(ctx, ccDep, depName)+libDepTag.makeSuffix)
2658 // Record baseLibName for snapshots.
2659 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
2660 case objDepTag:
2661 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
2662 case CrtBeginDepTag:
2663 depPaths.CrtBegin = linkFile
2664 case CrtEndDepTag:
2665 depPaths.CrtEnd = linkFile
2666 case dynamicLinkerDepTag:
2667 depPaths.DynamicLinker = linkFile
2668 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002669 }
Colin Crossca860ac2016-01-04 14:34:37 -08002670 })
2671
Jeff Gaston294356f2017-09-27 17:05:30 -07002672 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002673 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002674
Colin Crossdd84e052017-05-17 13:44:16 -07002675 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002676 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002677 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2678 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Inseob Kimd110f872019-12-06 13:15:38 +09002679 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002680 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2681 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002682 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002683 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002684 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002685
2686 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002687 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002688 }
Colin Crossdd84e052017-05-17 13:44:16 -07002689
Colin Crossca860ac2016-01-04 14:34:37 -08002690 return depPaths
2691}
2692
Colin Cross6e511a92020-07-27 21:26:48 -07002693// baseLibName trims known prefixes and suffixes
2694func baseLibName(depName string) string {
2695 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
2696 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
2697 libName = strings.TrimPrefix(libName, "prebuilt_")
2698 return libName
2699}
2700
2701func (c *Module) makeLibName(ctx android.ModuleContext, ccDep LinkableInterface, depName string) string {
2702 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2703 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2704
2705 libName := baseLibName(depName)
2706 isLLndk := isLlndkLibrary(libName, ctx.Config())
2707 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
2708 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
2709
2710 if c, ok := ccDep.(*Module); ok {
2711 // Use base module name for snapshots when exporting to Makefile.
2712 if c.isSnapshotPrebuilt() {
2713 baseName := c.BaseModuleName()
2714
2715 if c.IsVndk() {
2716 return baseName + ".vendor"
2717 }
2718
2719 if vendorSuffixModules[baseName] {
2720 return baseName + ".vendor"
2721 } else {
2722 return baseName
2723 }
2724 }
2725 }
2726
2727 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
2728 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2729 // core module instead.
2730 return libName
2731 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
2732 // The vendor module in Make will have been renamed to not conflict with the core
2733 // module, so update the dependency name here accordingly.
2734 return libName + c.getNameSuffixWithVndkVersion(ctx)
2735 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
2736 return libName + vendorPublicLibrarySuffix
2737 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2738 return libName + ramdiskSuffix
2739 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
2740 return libName + recoverySuffix
2741 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
2742 return libName + nativeBridgeSuffix
2743 } else {
2744 return libName
2745 }
2746}
2747
Colin Crossca860ac2016-01-04 14:34:37 -08002748func (c *Module) InstallInData() bool {
2749 if c.installer == nil {
2750 return false
2751 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002752 return c.installer.inData()
2753}
2754
2755func (c *Module) InstallInSanitizerDir() bool {
2756 if c.installer == nil {
2757 return false
2758 }
2759 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002760 return true
2761 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002762 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002763}
2764
Yifan Hong1b3348d2020-01-21 15:53:22 -08002765func (c *Module) InstallInRamdisk() bool {
2766 return c.InRamdisk()
2767}
2768
Jiyong Parkf9332f12018-02-01 00:54:12 +09002769func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002770 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002771}
2772
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002773func (c *Module) MakeUninstallable() {
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002774 if c.installer == nil {
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002775 c.ModuleBase.MakeUninstallable()
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002776 return
2777 }
Martin Stjernholm9e9bb7f2020-08-06 22:34:42 +01002778 c.installer.makeUninstallable(c)
Martin Stjernholmbf37d162020-03-31 16:05:34 +01002779}
2780
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002781func (c *Module) HostToolPath() android.OptionalPath {
2782 if c.installer == nil {
2783 return android.OptionalPath{}
2784 }
2785 return c.installer.hostToolPath()
2786}
2787
Nan Zhangd4e641b2017-07-12 12:55:28 -07002788func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2789 return c.outputFile
2790}
2791
Colin Cross41955e82019-05-29 14:40:35 -07002792func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2793 switch tag {
2794 case "":
2795 if c.outputFile.Valid() {
2796 return android.Paths{c.outputFile.Path()}, nil
2797 }
2798 return android.Paths{}, nil
2799 default:
2800 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002801 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002802}
2803
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002804func (c *Module) static() bool {
2805 if static, ok := c.linker.(interface {
2806 static() bool
2807 }); ok {
2808 return static.static()
2809 }
2810 return false
2811}
2812
Jiyong Park379de2f2018-12-19 02:47:14 +09002813func (c *Module) staticBinary() bool {
2814 if static, ok := c.linker.(interface {
2815 staticBinary() bool
2816 }); ok {
2817 return static.staticBinary()
2818 }
2819 return false
2820}
2821
Jiyong Park1d1119f2019-07-29 21:27:18 +09002822func (c *Module) header() bool {
2823 if h, ok := c.linker.(interface {
2824 header() bool
2825 }); ok {
2826 return h.header()
2827 }
2828 return false
2829}
2830
Inseob Kim7f283f42020-06-01 21:53:49 +09002831func (c *Module) binary() bool {
2832 if b, ok := c.linker.(interface {
2833 binary() bool
2834 }); ok {
2835 return b.binary()
2836 }
2837 return false
2838}
2839
Inseob Kim1042d292020-06-01 23:23:05 +09002840func (c *Module) object() bool {
2841 if o, ok := c.linker.(interface {
2842 object() bool
2843 }); ok {
2844 return o.object()
2845 }
2846 return false
2847}
2848
Jooyung Han38002912019-05-16 04:01:54 +09002849func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002850 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002851 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2852 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002853 return "native:vndk"
2854 }
Jooyung Han38002912019-05-16 04:01:54 +09002855 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002856 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002857 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002858 if Bool(c.VendorProperties.Vendor_available) {
2859 return "native:vndk"
2860 }
2861 return "native:vndk_private"
2862 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002863 if c.inProduct() {
2864 return "native:product"
2865 }
Jooyung Han38002912019-05-16 04:01:54 +09002866 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002867 } else if c.InRamdisk() {
2868 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002869 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002870 return "native:recovery"
2871 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2872 return "native:ndk:none:none"
2873 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2874 //family, link := getNdkStlFamilyAndLinkType(c)
2875 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002876 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002877 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002878 } else {
2879 return "native:platform"
2880 }
2881}
2882
Jiyong Park9d452992018-10-03 00:38:19 +09002883// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002884// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002885func (c *Module) IsInstallableToApex() bool {
2886 if shared, ok := c.linker.(interface {
2887 shared() bool
2888 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002889 // Stub libs and prebuilt libs in a versioned SDK are not
2890 // installable to APEX even though they are shared libs.
2891 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002892 } else if _, ok := c.linker.(testPerSrc); ok {
2893 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002894 }
2895 return false
2896}
2897
Jiyong Parka90ca002019-10-07 15:47:24 +09002898func (c *Module) AvailableFor(what string) bool {
2899 if linker, ok := c.linker.(interface {
2900 availableFor(string) bool
2901 }); ok {
2902 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2903 } else {
2904 return c.ApexModuleBase.AvailableFor(what)
2905 }
2906}
2907
Jiyong Park62304bb2020-04-13 16:19:48 +09002908func (c *Module) TestFor() []string {
2909 if test, ok := c.linker.(interface {
2910 testFor() []string
2911 }); ok {
2912 return test.testFor()
2913 } else {
2914 return c.ApexModuleBase.TestFor()
2915 }
2916}
2917
Colin Crossaede88c2020-08-11 12:17:01 -07002918func (c *Module) UniqueApexVariations() bool {
2919 if u, ok := c.compiler.(interface {
2920 uniqueApexVariations() bool
2921 }); ok {
2922 return u.uniqueApexVariations()
2923 } else {
2924 return false
2925 }
2926}
2927
Paul Duffin0cb37b92020-03-04 14:52:46 +00002928// Return true if the module is ever installable.
2929func (c *Module) EverInstallable() bool {
2930 return c.installer != nil &&
2931 // Check to see whether the module is actually ever installable.
2932 c.installer.everInstallable()
2933}
2934
Inseob Kim1f086e22019-05-09 13:29:15 +09002935func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002936 ret := c.EverInstallable() &&
2937 // Check to see whether the module has been configured to not be installed.
2938 proptools.BoolDefault(c.Properties.Installable, true) &&
2939 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002940
2941 // The platform variant doesn't need further condition. Apex variants however might not
2942 // be installable because it will likely to be included in the APEX and won't appear
2943 // in the system partition.
2944 if c.IsForPlatform() {
2945 return ret
2946 }
2947
2948 // Special case for modules that are configured to be installed to /data, which includes
2949 // test modules. For these modules, both APEX and non-APEX variants are considered as
2950 // installable. This is because even the APEX variants won't be included in the APEX, but
2951 // will anyway be installed to /data/*.
2952 // See b/146995717
2953 if c.InstallInData() {
2954 return ret
2955 }
2956
2957 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002958}
2959
Logan Chien41eabe62019-04-10 13:33:58 +08002960func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2961 if c.linker != nil {
2962 if library, ok := c.linker.(*libraryDecorator); ok {
2963 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2964 }
2965 }
2966}
2967
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002968func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Colin Cross6e511a92020-07-27 21:26:48 -07002969 depTag := ctx.OtherModuleDependencyTag(dep)
2970 libDepTag, isLibDepTag := depTag.(libraryDependencyTag)
2971
2972 if cc, ok := dep.(*Module); ok {
2973 if cc.HasStubsVariants() {
2974 if isLibDepTag && libDepTag.shared() {
2975 // dynamic dep to a stubs lib crosses APEX boundary
2976 return false
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002977 }
Colin Cross6e511a92020-07-27 21:26:48 -07002978 if IsRuntimeDepTag(depTag) {
2979 // runtime dep to a stubs lib also crosses APEX boundary
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002980 return false
2981 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002982 }
Colin Crossaac32222020-07-29 12:51:56 -07002983 if isLibDepTag && c.static() && libDepTag.shared() {
Colin Cross6e511a92020-07-27 21:26:48 -07002984 // shared_lib dependency from a static lib is considered as crossing
2985 // the APEX boundary because the dependency doesn't actually is
2986 // linked; the dependency is used only during the compilation phase.
2987 return false
2988 }
2989 }
2990 if depTag == llndkImplDep {
Jiyong Park7d95a512020-05-10 15:16:24 +09002991 // We don't track beyond LLNDK
2992 return false
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002993 }
2994 return true
2995}
2996
Jooyung Han749dc692020-04-15 11:03:39 +09002997// b/154667674: refactor this to handle "current" in a consistent way
2998func decodeSdkVersionString(ctx android.BaseModuleContext, versionString string) (int, error) {
2999 if versionString == "" {
3000 return 0, fmt.Errorf("not specified")
3001 }
3002 if versionString == "current" {
3003 if ctx.Config().PlatformSdkCodename() == "REL" {
3004 return ctx.Config().PlatformSdkVersionInt(), nil
3005 }
3006 return android.FutureApiLevel, nil
3007 }
3008 return android.ApiStrToNum(ctx, versionString)
3009}
3010
3011func (c *Module) ShouldSupportSdkVersion(ctx android.BaseModuleContext, sdkVersion int) error {
3012 // We ignore libclang_rt.* prebuilt libs since they declare sdk_version: 14(b/121358700)
3013 if strings.HasPrefix(ctx.OtherModuleName(c), "libclang_rt") {
3014 return nil
3015 }
3016 // b/154569636: set min_sdk_version correctly for toolchain_libraries
3017 if c.ToolchainLibrary() {
3018 return nil
3019 }
3020 // We don't check for prebuilt modules
3021 if _, ok := c.linker.(prebuiltLinkerInterface); ok {
3022 return nil
3023 }
3024 minSdkVersion := c.MinSdkVersion()
3025 if minSdkVersion == "apex_inherit" {
3026 return nil
3027 }
3028 if minSdkVersion == "" {
3029 // JNI libs within APK-in-APEX fall into here
3030 // Those are okay to set sdk_version instead
3031 // We don't have to check if this is a SDK variant because
3032 // non-SDK variant resets sdk_version, which works too.
3033 minSdkVersion = c.SdkVersion()
3034 }
3035 ver, err := decodeSdkVersionString(ctx, minSdkVersion)
3036 if err != nil {
3037 return err
3038 }
3039 if ver > sdkVersion {
3040 return fmt.Errorf("newer SDK(%v)", ver)
3041 }
3042 return nil
3043}
3044
Colin Cross2ba19d92015-05-07 15:44:20 -07003045//
Colin Crosscfad1192015-11-02 16:43:11 -08003046// Defaults
3047//
Colin Crossca860ac2016-01-04 14:34:37 -08003048type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07003049 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07003050 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09003051 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08003052}
3053
Patrice Arrudac249c712019-03-19 17:00:29 -07003054// cc_defaults provides a set of properties that can be inherited by other cc
3055// modules. A module can use the properties from a cc_defaults using
3056// `defaults: ["<:default_module_name>"]`. Properties of both modules are
3057// merged (when possible) by prepending the default module's values to the
3058// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07003059func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07003060 return DefaultsFactory()
3061}
3062
Colin Cross36242852017-06-23 15:06:31 -07003063func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08003064 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08003065
Colin Cross36242852017-06-23 15:06:31 -07003066 module.AddProperties(props...)
3067 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08003068 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07003069 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003070 &BaseCompilerProperties{},
3071 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01003072 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003073 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07003074 &StaticProperties{},
3075 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07003076 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003077 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07003078 &TestProperties{},
3079 &TestBinaryProperties{},
Colin Cross43287652020-06-30 10:15:07 -07003080 &BenchmarkProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07003081 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08003082 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08003083 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07003084 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07003085 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07003086 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08003087 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08003088 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09003089 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07003090 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07003091 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08003092 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07003093 )
Colin Crosscfad1192015-11-02 16:43:11 -08003094
Jooyung Hancc372c52019-09-25 15:18:44 +09003095 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07003096
3097 return module
Colin Crosscfad1192015-11-02 16:43:11 -08003098}
3099
Jiyong Park6a43f042017-10-12 23:05:00 +09003100func squashVendorSrcs(m *Module) {
3101 if lib, ok := m.compiler.(*libraryDecorator); ok {
3102 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3103 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
3104
3105 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3106 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003107
3108 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3109 lib.baseCompiler.Properties.Target.Vendor.Exclude_generated_sources...)
Jiyong Park6a43f042017-10-12 23:05:00 +09003110 }
3111}
3112
Jiyong Parkf9332f12018-02-01 00:54:12 +09003113func squashRecoverySrcs(m *Module) {
3114 if lib, ok := m.compiler.(*libraryDecorator); ok {
3115 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
3116 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
3117
3118 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
3119 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
Jooyung Hanac07f882020-07-05 03:54:35 +09003120
3121 lib.baseCompiler.Properties.Exclude_generated_sources = append(lib.baseCompiler.Properties.Exclude_generated_sources,
3122 lib.baseCompiler.Properties.Target.Recovery.Exclude_generated_sources...)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003123 }
3124}
3125
Jiyong Park2286afd2020-06-16 21:58:53 +09003126func (c *Module) IsSdkVariant() bool {
Dan Albert92fe7402020-07-15 13:33:30 -07003127 return c.Properties.IsSdkVariant || c.AlwaysSdk()
Jiyong Park2286afd2020-06-16 21:58:53 +09003128}
3129
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003130func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003131 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003132 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3133 }
Colin Cross6510f912017-11-29 00:27:14 -08003134 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003135}
3136
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003137func kytheExtractAllFactory() android.Singleton {
3138 return &kytheExtractAllSingleton{}
3139}
3140
3141type kytheExtractAllSingleton struct {
3142}
3143
3144func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3145 var xrefTargets android.Paths
3146 ctx.VisitAllModules(func(module android.Module) {
3147 if ccModule, ok := module.(xref); ok {
3148 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3149 }
3150 })
3151 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3152 if len(xrefTargets) > 0 {
Colin Crossc3d87d32020-06-04 13:25:17 -07003153 ctx.Phony("xref_cxx", xrefTargets...)
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003154 }
3155}
3156
Colin Cross06a931b2015-10-28 17:23:31 -07003157var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003158var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003159var BoolPtr = proptools.BoolPtr
3160var String = proptools.String
3161var StringPtr = proptools.StringPtr