blob: a92495c3b8292b862767c95c4d506b0766c864ac [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) {
Inseob Kim64c43952019-08-26 16:52:35 +090045 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070046 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090047 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090049 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070050 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090051 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090052 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
53 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070054 })
Colin Cross16b23492016-01-06 14:41:07 -080055
Paul Duffin036e7002019-12-19 19:16:28 +000056 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070057 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
58 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080059
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070060 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
61 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
62
Mitch Phillipsbfeade62019-05-01 14:42:05 -070063 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
64 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
65
Jiyong Park1d1119f2019-07-29 21:27:18 +090066 // cfi mutator shouldn't run before sanitizers that return true for
67 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000068 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
69 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
70
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080071 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
72 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
73
Colin Cross1e676be2016-10-12 14:38:15 -070074 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
75 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080076
Colin Cross0b908332019-06-19 23:00:20 -070077 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090078 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080079
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080080 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080081 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070082
83 ctx.TopDown("lto_deps", ltoDepsMutator)
84 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090085
86 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070087 })
Colin Crossb98c8b02016-07-29 13:44:28 -070088
Sasha Smundak2a4549e2018-11-05 16:49:08 -080089 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070090}
91
Colin Crossca860ac2016-01-04 14:34:37 -080092type Deps struct {
93 SharedLibs, LateSharedLibs []string
94 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080095 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080096 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070097
Peter Collingbournedc4f9862020-02-12 17:13:25 -080098 StaticUnwinderIfLegacy bool
99
Colin Cross5950f382016-12-13 12:50:57 -0800100 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700101
Colin Cross81413472016-04-11 14:37:39 -0700102 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Dan Willemsenb40aab62016-04-20 14:21:14 -0700104 GeneratedSources []string
105 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900106 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700107
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700108 ReexportGeneratedHeaders []string
109
Colin Cross97ba0732015-03-23 17:50:24 -0700110 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700111
112 // Used for host bionic
113 LinkerFlagsFile string
114 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700115}
116
Colin Crossca860ac2016-01-04 14:34:37 -0800117type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900119 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900121 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700123 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700126 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800127 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700128 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 GeneratedSources android.Paths
132 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900133 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700134
Inseob Kimd110f872019-12-06 13:15:38 +0900135 Flags []string
136 IncludeDirs android.Paths
137 SystemIncludeDirs android.Paths
138 ReexportedDirs android.Paths
139 ReexportedSystemDirs android.Paths
140 ReexportedFlags []string
141 ReexportedGeneratedHeaders android.Paths
142 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700146
147 // Path to the file container flags to use with the linker
148 LinkerFlagsFile android.OptionalPath
149
150 // Path to the dynamic linker binary
151 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152}
153
Colin Cross4af21ed2019-11-04 09:37:55 -0800154// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
155// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
156// command line so they can be overridden by the local module flags).
157type LocalOrGlobalFlags struct {
158 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700159 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800160 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700161 CFlags []string // Flags that apply to C and C++ source files
162 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
163 ConlyFlags []string // Flags that apply to C source files
164 CppFlags []string // Flags that apply to C++ source files
165 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700166 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800167}
168
169type Flags struct {
170 Local LocalOrGlobalFlags
171 Global LocalOrGlobalFlags
172
173 aidlFlags []string // Flags that apply to aidl source files
174 rsFlags []string // Flags that apply to renderscript source files
175 libFlags []string // Flags to add libraries early to the link order
176 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
177 TidyFlags []string // Flags that apply to clang-tidy
178 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700179
Colin Crossc3199482017-03-30 15:03:04 -0700180 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800181 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700182 SystemIncludeFlags []string
183
Oliver Nguyen6f641c12020-04-21 12:40:27 -0700184 Toolchain config.Toolchain
185 Tidy bool
186 GcovCoverage bool
187 SAbiDump bool
188 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800189
190 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800191 DynamicLinker string
192
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700193 CFlagsDeps android.Paths // Files depended on by compiler flags
194 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800195
Dan Willemsen98ab3112019-08-27 21:20:40 -0700196 AssemblerWithCpp bool
197 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800198
Colin Cross19878da2019-03-28 14:45:07 -0700199 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700200 protoC bool // Whether to use C instead of C++
201 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700202
203 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700204}
205
Colin Crossca860ac2016-01-04 14:34:37 -0800206// Properties used to compile all C or C++ modules
207type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700208 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800209 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700210
211 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800212 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700213
Jooyung Hanba118122020-04-21 15:24:00 +0900214 // Minimum sdk version that the artifact should support when it runs as part of mainline modules(APEX).
215 Min_sdk_version *string
216
Jiyong Parkde866cb2018-12-07 23:08:36 +0900217 AndroidMkSharedLibs []string `blueprint:"mutated"`
218 AndroidMkStaticLibs []string `blueprint:"mutated"`
219 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
220 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
221 HideFromMake bool `blueprint:"mutated"`
222 PreventInstall bool `blueprint:"mutated"`
223 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700224
Justin Yun5f7f7e82019-11-18 19:52:14 +0900225 ImageVariationPrefix string `blueprint:"mutated"`
226 VndkVersion string `blueprint:"mutated"`
227 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800228
229 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
230 // file
231 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900232
Yifan Hong1b3348d2020-01-21 15:53:22 -0800233 // Make this module available when building for ramdisk
234 Ramdisk_available *bool
235
Jiyong Parkf9332f12018-02-01 00:54:12 +0900236 // Make this module available when building for recovery
237 Recovery_available *bool
238
Colin Crossae6c5202019-11-20 13:35:50 -0800239 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800240 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800241 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800242 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900243 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900244
245 // Allows this module to use non-APEX version of libraries. Useful
246 // for building binaries that are started before APEXes are activated.
247 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900248
249 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
250 // see soong/cc/config/vndk.go
251 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900252
253 // Used by vendor snapshot to record dependencies from snapshot modules.
254 SnapshotSharedLibs []string `blueprint:"mutated"`
255 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffinf51768a2020-03-04 14:52:46 +0000256
257 Installable *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700258}
259
260type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900261 // whether this module should be allowed to be directly depended by other
262 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900263 // In addition, this module should be allowed to be directly depended by
264 // product modules with `product_specific: true`.
265 // If set to true, three variants will be built separately, one like
266 // normal, another limited to the set of libraries and headers
267 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700268 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900269 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700270 // so it shouldn't have any unversioned runtime dependencies, or
271 // make assumptions about the system that may not be true in the
272 // future.
273 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900274 // If set to false, this module becomes inaccessible from /vendor or /product
275 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900276 //
277 // Default value is true when vndk: {enabled: true} or vendor: true.
278 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700279 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900280 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700281 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900282
283 // whether this module is capable of being loaded with other instance
284 // (possibly an older version) of the same module in the same process.
285 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
286 // can be double loaded in a vendor process if the library is also a
287 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
288 // explicitly marked as `double_loadable: true` by the owner, or the dependency
289 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
290 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800291}
292
Colin Crossca860ac2016-01-04 14:34:37 -0800293type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800294 static() bool
295 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900296 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700297 toolchain() config.Toolchain
Jooyung Han61c41542020-03-07 03:45:53 +0900298 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700299 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800300 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700301 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800302 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900303 isLlndk(config android.Config) bool
304 isLlndkPublic(config android.Config) bool
305 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900306 isVndk() bool
307 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800308 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900309 inProduct() bool
310 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800311 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900312 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800313 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700314 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700315 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800316 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800317 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800318 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800319 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800320 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900321 apexName() string
Jooyung Han61c41542020-03-07 03:45:53 +0900322 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900323 hasStubsVariants() bool
324 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900325 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800326 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700327 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800328}
329
330type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700331 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800332 ModuleContextIntf
333}
334
335type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700336 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800337 ModuleContextIntf
338}
339
Colin Cross37047f12016-12-13 17:06:13 -0800340type DepsContext interface {
341 android.BottomUpMutatorContext
342 ModuleContextIntf
343}
344
Colin Crossca860ac2016-01-04 14:34:37 -0800345type feature interface {
346 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800347 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800348 flags(ctx ModuleContext, flags Flags) Flags
349 props() []interface{}
350}
351
352type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700353 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800354 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800355 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700356 compilerProps() []interface{}
357
Colin Cross76fada02016-07-27 10:31:13 -0700358 appendCflags([]string)
359 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700360 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800361}
362
363type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700364 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800365 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700366 linkerFlags(ctx ModuleContext, flags Flags) Flags
367 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800368 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700369
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700370 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700371 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900372 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700373
374 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900375 coverageOutputFilePath() android.OptionalPath
Paul Duffin206433a2020-03-06 12:30:43 +0000376
377 // Get the deps that have been explicitly specified in the properties.
378 // Only updates the
379 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
380}
381
382type specifiedDeps struct {
383 sharedLibs []string
384 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800385}
386
387type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700388 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700389 install(ctx ModuleContext, path android.Path)
Paul Duffinf51768a2020-03-04 14:52:46 +0000390 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800391 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700392 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700393 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900394 relativeInstallPath() string
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +0100395 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800396}
397
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800398type xref interface {
399 XrefCcFiles() android.Paths
400}
401
Colin Crossc99deeb2016-04-11 15:06:20 -0700402var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700403 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
404 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
405 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
406 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
407 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800408 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700409 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
410 headerDepTag = DependencyTag{Name: "header", Library: true}
411 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
412 genSourceDepTag = DependencyTag{Name: "gen source"}
413 genHeaderDepTag = DependencyTag{Name: "gen header"}
414 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
415 objDepTag = DependencyTag{Name: "obj"}
416 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
417 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
418 reuseObjTag = DependencyTag{Name: "reuse objects"}
419 staticVariantTag = DependencyTag{Name: "static variant"}
420 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
421 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
422 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
423 runtimeDepTag = DependencyTag{Name: "runtime lib"}
424 coverageDepTag = DependencyTag{Name: "coverage"}
425 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700426)
427
Roland Levillainf89cd092019-07-29 16:22:59 +0100428func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700429 ccDepTag, ok := depTag.(DependencyTag)
430 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100431}
432
433func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700434 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100435 return ok && ccDepTag == runtimeDepTag
436}
437
438func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700439 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100440 return ok && ccDepTag == testPerSrcDepTag
441}
442
Colin Crossca860ac2016-01-04 14:34:37 -0800443// Module contains the properties and members used by all C/C++ module types, and implements
444// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
445// to construct the output file. Behavior can be customized with a Customizer interface
446type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700447 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700448 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900449 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900450 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700451
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700452 Properties BaseProperties
453 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700454
Colin Crossca860ac2016-01-04 14:34:37 -0800455 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700456 hod android.HostOrDeviceSupported
457 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700458
Paul Duffina0843f62019-12-13 19:50:38 +0000459 // Allowable SdkMemberTypes of this module type.
460 sdkMemberTypes []android.SdkMemberType
461
Colin Crossca860ac2016-01-04 14:34:37 -0800462 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700463 features []feature
464 compiler compiler
465 linker linker
466 installer installer
467 stl *stl
468 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800469 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800470 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900471 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700472 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700473 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800474
Colin Cross635c3b02016-05-18 15:37:25 -0700475 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800476
Colin Crossb98c8b02016-07-29 13:44:28 -0700477 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700478
479 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800480
481 // Flags used to compile this module
482 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700483
484 // 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 -0800485 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700486 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800487 depsInLinkOrder android.Paths
488
489 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700490 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900491
492 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800493 // Kythe (source file indexer) paths for this compilation module
494 kytheFiles android.Paths
Jooyung Han74066602020-03-20 04:29:24 +0900495
496 // For apex variants, this is set as apex.min_sdk_version
497 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700498}
499
Ivan Lozano52767be2019-10-18 14:49:46 -0700500func (c *Module) Toc() android.OptionalPath {
501 if c.linker != nil {
502 if library, ok := c.linker.(libraryInterface); ok {
503 return library.toc()
504 }
505 }
506 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
507}
508
509func (c *Module) ApiLevel() string {
510 if c.linker != nil {
511 if stub, ok := c.linker.(*stubDecorator); ok {
512 return stub.properties.ApiLevel
513 }
514 }
515 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
516}
517
518func (c *Module) Static() bool {
519 if c.linker != nil {
520 if library, ok := c.linker.(libraryInterface); ok {
521 return library.static()
522 }
523 }
524 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
525}
526
527func (c *Module) Shared() bool {
528 if c.linker != nil {
529 if library, ok := c.linker.(libraryInterface); ok {
530 return library.shared()
531 }
532 }
533 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
534}
535
536func (c *Module) SelectedStl() string {
537 return c.stl.Properties.SelectedStl
538}
539
540func (c *Module) ToolchainLibrary() bool {
541 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
542 return true
543 }
544 return false
545}
546
547func (c *Module) NdkPrebuiltStl() bool {
548 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
549 return true
550 }
551 return false
552}
553
554func (c *Module) StubDecorator() bool {
555 if _, ok := c.linker.(*stubDecorator); ok {
556 return true
557 }
558 return false
559}
560
561func (c *Module) SdkVersion() string {
562 return String(c.Properties.Sdk_version)
563}
564
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800565func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700566 if c.linker != nil {
567 if library, ok := c.linker.(exportedFlagsProducer); ok {
568 return library.exportedDirs()
569 }
570 }
571 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
572}
573
574func (c *Module) HasStaticVariant() bool {
575 if c.staticVariant != nil {
576 return true
577 }
578 return false
579}
580
581func (c *Module) GetStaticVariant() LinkableInterface {
582 return c.staticVariant
583}
584
585func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
586 c.depsInLinkOrder = depsInLinkOrder
587}
588
589func (c *Module) GetDepsInLinkOrder() []android.Path {
590 return c.depsInLinkOrder
591}
592
593func (c *Module) StubsVersions() []string {
594 if c.linker != nil {
595 if library, ok := c.linker.(*libraryDecorator); ok {
596 return library.Properties.Stubs.Versions
597 }
598 }
599 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
600}
601
602func (c *Module) CcLibrary() bool {
603 if c.linker != nil {
604 if _, ok := c.linker.(*libraryDecorator); ok {
605 return true
606 }
607 }
608 return false
609}
610
611func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700612 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700613 return true
614 }
615 return false
616}
617
Ivan Lozano2b262972019-11-21 12:30:50 -0800618func (c *Module) NonCcVariants() bool {
619 return false
620}
621
Ivan Lozano183a3212019-10-18 14:18:45 -0700622func (c *Module) SetBuildStubs() {
623 if c.linker != nil {
624 if library, ok := c.linker.(*libraryDecorator); ok {
625 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700626 c.Properties.HideFromMake = true
627 c.sanitize = nil
628 c.stl = nil
629 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700630 return
631 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900632 if _, ok := c.linker.(*llndkStubDecorator); ok {
633 c.Properties.HideFromMake = true
634 return
635 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700636 }
637 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
638}
639
Ivan Lozano52767be2019-10-18 14:49:46 -0700640func (c *Module) BuildStubs() bool {
641 if c.linker != nil {
642 if library, ok := c.linker.(*libraryDecorator); ok {
643 return library.buildStubs()
644 }
645 }
646 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
647}
648
Ivan Lozano183a3212019-10-18 14:18:45 -0700649func (c *Module) SetStubsVersions(version string) {
650 if c.linker != nil {
651 if library, ok := c.linker.(*libraryDecorator); ok {
652 library.MutatedProperties.StubsVersion = version
653 return
654 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900655 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
656 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
657 return
658 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700659 }
660 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
661}
662
Jooyung Han0c4e0162020-02-26 22:45:42 +0900663func (c *Module) StubsVersion() string {
664 if c.linker != nil {
665 if library, ok := c.linker.(*libraryDecorator); ok {
666 return library.MutatedProperties.StubsVersion
667 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900668 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
669 return llndk.libraryDecorator.MutatedProperties.StubsVersion
670 }
Jooyung Han0c4e0162020-02-26 22:45:42 +0900671 }
672 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
673}
674
Ivan Lozano183a3212019-10-18 14:18:45 -0700675func (c *Module) SetStatic() {
676 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700677 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700678 library.setStatic()
679 return
680 }
681 }
682 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
683}
684
685func (c *Module) SetShared() {
686 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700687 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700688 library.setShared()
689 return
690 }
691 }
692 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
693}
694
695func (c *Module) BuildStaticVariant() bool {
696 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700697 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700698 return library.buildStatic()
699 }
700 }
701 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
702}
703
704func (c *Module) BuildSharedVariant() bool {
705 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700706 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700707 return library.buildShared()
708 }
709 }
710 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
711}
712
713func (c *Module) Module() android.Module {
714 return c
715}
716
Jiyong Parkc20eee32018-09-05 22:36:17 +0900717func (c *Module) OutputFile() android.OptionalPath {
718 return c.outputFile
719}
720
Ivan Lozano183a3212019-10-18 14:18:45 -0700721var _ LinkableInterface = (*Module)(nil)
722
Jiyong Park719b4462019-01-13 00:39:51 +0900723func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900724 if c.linker != nil {
725 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900726 }
727 return nil
728}
729
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900730func (c *Module) CoverageOutputFile() android.OptionalPath {
731 if c.linker != nil {
732 return c.linker.coverageOutputFilePath()
733 }
734 return android.OptionalPath{}
735}
736
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900737func (c *Module) RelativeInstallPath() string {
738 if c.installer != nil {
739 return c.installer.relativeInstallPath()
740 }
741 return ""
742}
743
Jooyung Han344d5432019-08-23 11:17:39 +0900744func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900745 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900746}
747
Colin Cross36242852017-06-23 15:06:31 -0700748func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700749 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800750 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700751 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800752 }
753 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700754 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800755 }
756 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700757 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800758 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700759 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700760 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700761 }
Colin Cross16b23492016-01-06 14:41:07 -0800762 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700763 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800764 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800765 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700766 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800767 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800768 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700769 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800770 }
Justin Yun8effde42017-06-23 19:24:43 +0900771 if c.vndkdep != nil {
772 c.AddProperties(c.vndkdep.props()...)
773 }
Stephen Craneba090d12017-05-09 15:44:35 -0700774 if c.lto != nil {
775 c.AddProperties(c.lto.props()...)
776 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700777 if c.pgo != nil {
778 c.AddProperties(c.pgo.props()...)
779 }
Colin Crossca860ac2016-01-04 14:34:37 -0800780 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700781 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800782 }
Colin Crossc472d572015-03-17 15:06:21 -0700783
Colin Crossa9d8bee2018-10-02 13:59:46 -0700784 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
785 switch class {
786 case android.Device:
787 return ctx.Config().DevicePrefer32BitExecutables()
788 case android.HostCross:
789 // Windows builds always prefer 32-bit
790 return true
791 default:
792 return false
793 }
794 })
Colin Cross36242852017-06-23 15:06:31 -0700795 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900796 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900797 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900798 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900799
Colin Cross36242852017-06-23 15:06:31 -0700800 return c
Colin Crossc472d572015-03-17 15:06:21 -0700801}
802
Colin Crossb916a382016-07-29 17:28:03 -0700803// Returns true for dependency roots (binaries)
804// TODO(ccross): also handle dlopenable libraries
805func (c *Module) isDependencyRoot() bool {
806 if root, ok := c.linker.(interface {
807 isDependencyRoot() bool
808 }); ok {
809 return root.isDependencyRoot()
810 }
811 return false
812}
813
Justin Yun5f7f7e82019-11-18 19:52:14 +0900814// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
815// "product" and "vendor" variant modules return true for this function.
816// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
817// "soc_specific: true" and more vendor installed modules are included here.
818// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
819// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700820func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900821 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700822}
823
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800824func (c *Module) isCoverageVariant() bool {
825 return c.coverage.Properties.IsCoverageVariant
826}
827
Peter Collingbournead84f972019-12-17 16:46:18 -0800828func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800829 return inList(c.Name(), ndkMigratedLibs)
830}
831
Inseob Kim9516ee92019-05-09 10:56:13 +0900832func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800833 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900834 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800835}
836
Inseob Kim9516ee92019-05-09 10:56:13 +0900837func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800838 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900839 name := c.BaseModuleName()
840 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800841}
842
Inseob Kim9516ee92019-05-09 10:56:13 +0900843func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800844 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900845 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800846}
847
Ivan Lozano52767be2019-10-18 14:49:46 -0700848func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800849 if vndkdep := c.vndkdep; vndkdep != nil {
850 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900851 }
852 return false
853}
854
Yi Kong7e53c572018-02-14 18:16:12 +0800855func (c *Module) isPgoCompile() bool {
856 if pgo := c.pgo; pgo != nil {
857 return pgo.Properties.PgoCompile
858 }
859 return false
860}
861
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800862func (c *Module) isNDKStubLibrary() bool {
863 if _, ok := c.compiler.(*stubDecorator); ok {
864 return true
865 }
866 return false
867}
868
Logan Chienf3511742017-10-31 18:04:35 +0800869func (c *Module) isVndkSp() bool {
870 if vndkdep := c.vndkdep; vndkdep != nil {
871 return vndkdep.isVndkSp()
872 }
873 return false
874}
875
876func (c *Module) isVndkExt() bool {
877 if vndkdep := c.vndkdep; vndkdep != nil {
878 return vndkdep.isVndkExt()
879 }
880 return false
881}
882
Ivan Lozano52767be2019-10-18 14:49:46 -0700883func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900884 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800885}
886
Logan Chienf3511742017-10-31 18:04:35 +0800887func (c *Module) getVndkExtendsModuleName() string {
888 if vndkdep := c.vndkdep; vndkdep != nil {
889 return vndkdep.getVndkExtendsModuleName()
890 }
891 return ""
892}
893
Justin Yun5f7f7e82019-11-18 19:52:14 +0900894// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900895// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700896func (c *Module) HasVendorVariant() bool {
897 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900898}
899
Justin Yun5f7f7e82019-11-18 19:52:14 +0900900const (
901 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
902 // against the VNDK.
903 VendorVariationPrefix = "vendor."
904
905 // ProductVariationPrefix is the variant prefix used for /product code that compiles
906 // against the VNDK.
907 ProductVariationPrefix = "product."
908)
909
910// Returns true if the module is "product" variant. Usually these modules are installed in /product
911func (c *Module) inProduct() bool {
912 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
913}
914
915// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
916func (c *Module) inVendor() bool {
917 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
918}
919
Yifan Hong1b3348d2020-01-21 15:53:22 -0800920func (c *Module) InRamdisk() bool {
921 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
922}
923
Ivan Lozano52767be2019-10-18 14:49:46 -0700924func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800925 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900926}
927
Yifan Hong1b3348d2020-01-21 15:53:22 -0800928func (c *Module) OnlyInRamdisk() bool {
929 return c.ModuleBase.InstallInRamdisk()
930}
931
Ivan Lozano52767be2019-10-18 14:49:46 -0700932func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900933 return c.ModuleBase.InstallInRecovery()
934}
935
Jiyong Park25fc6a92018-11-18 18:02:45 +0900936func (c *Module) IsStubs() bool {
937 if library, ok := c.linker.(*libraryDecorator); ok {
938 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900939 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
940 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900941 }
942 return false
943}
944
945func (c *Module) HasStubsVariants() bool {
946 if library, ok := c.linker.(*libraryDecorator); ok {
947 return len(library.Properties.Stubs.Versions) > 0
948 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700949 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
950 return len(library.Properties.Stubs.Versions) > 0
951 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900952 return false
953}
954
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900955func (c *Module) bootstrap() bool {
956 return Bool(c.Properties.Bootstrap)
957}
958
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700959func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700960 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
961 if c.Target().NativeBridge == android.NativeBridgeEnabled {
962 return false
963 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700964 return c.linker != nil && c.linker.nativeCoverage()
965}
966
Inseob Kim8471cda2019-11-15 09:59:12 +0900967func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900968 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
969 return true
970 }
971 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
972 return true
973 }
974 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
975 return true
976 }
977 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900978}
979
Jiyong Park73c54ee2019-10-22 20:31:18 +0900980func (c *Module) ExportedIncludeDirs() android.Paths {
981 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
982 return flagsProducer.exportedDirs()
983 }
Jiyong Park232e7852019-11-04 12:23:40 +0900984 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900985}
986
987func (c *Module) ExportedSystemIncludeDirs() android.Paths {
988 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
989 return flagsProducer.exportedSystemDirs()
990 }
Jiyong Park232e7852019-11-04 12:23:40 +0900991 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900992}
993
994func (c *Module) ExportedFlags() []string {
995 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
996 return flagsProducer.exportedFlags()
997 }
Jiyong Park232e7852019-11-04 12:23:40 +0900998 return nil
999}
1000
1001func (c *Module) ExportedDeps() android.Paths {
1002 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1003 return flagsProducer.exportedDeps()
1004 }
1005 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001006}
1007
Inseob Kimd110f872019-12-06 13:15:38 +09001008func (c *Module) ExportedGeneratedHeaders() android.Paths {
1009 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1010 return flagsProducer.exportedGeneratedHeaders()
1011 }
1012 return nil
1013}
1014
Jiyong Parkf1194352019-02-25 11:05:47 +09001015func isBionic(name string) bool {
1016 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001017 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001018 return true
1019 }
1020 return false
1021}
1022
Martin Stjernholm279de572019-09-10 23:18:20 +01001023func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001024 if name == "libclang_rt.hwasan-aarch64-android" {
1025 return inList("hwaddress", config.SanitizeDevice())
1026 }
1027 return isBionic(name)
1028}
1029
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001030func (c *Module) XrefCcFiles() android.Paths {
1031 return c.kytheFiles
1032}
1033
Colin Crossca860ac2016-01-04 14:34:37 -08001034type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001035 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001036 moduleContextImpl
1037}
1038
Colin Cross37047f12016-12-13 17:06:13 -08001039type depsContext struct {
1040 android.BottomUpMutatorContext
1041 moduleContextImpl
1042}
1043
Colin Crossca860ac2016-01-04 14:34:37 -08001044type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001045 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001046 moduleContextImpl
1047}
1048
Justin Yun5f7f7e82019-11-18 19:52:14 +09001049func (ctx *moduleContext) ProductSpecific() bool {
1050 return ctx.ModuleContext.ProductSpecific() ||
1051 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1052}
1053
Jiyong Park2db76922017-11-08 16:03:48 +09001054func (ctx *moduleContext) SocSpecific() bool {
1055 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001056 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001057}
1058
Colin Crossca860ac2016-01-04 14:34:37 -08001059type moduleContextImpl struct {
1060 mod *Module
1061 ctx BaseModuleContext
1062}
1063
Colin Crossb98c8b02016-07-29 13:44:28 -07001064func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001065 return ctx.mod.toolchain(ctx.ctx)
1066}
1067
1068func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001069 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001070}
1071
1072func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001073 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001074}
1075
Jiyong Park1d1119f2019-07-29 21:27:18 +09001076func (ctx *moduleContextImpl) header() bool {
1077 return ctx.mod.header()
1078}
1079
Jooyung Han61c41542020-03-07 03:45:53 +09001080func (ctx *moduleContextImpl) canUseSdk() bool {
1081 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1082}
1083
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001084func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Han61c41542020-03-07 03:45:53 +09001085 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001086 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001087 }
1088 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001089}
1090
1091func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001092 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001093 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001094 vndkVer := ctx.mod.VndkVersion()
Jooyung Han424175d2020-04-08 09:22:26 +09001095 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001096 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001097 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001098 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001099 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001100 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001101 }
1102 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001103}
1104
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001105func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001106 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001107}
Justin Yun8effde42017-06-23 19:24:43 +09001108
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001109func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001110 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001111}
1112
Inseob Kim9516ee92019-05-09 10:56:13 +09001113func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1114 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001115}
1116
Inseob Kim9516ee92019-05-09 10:56:13 +09001117func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1118 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001119}
1120
Inseob Kim9516ee92019-05-09 10:56:13 +09001121func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1122 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001123}
1124
Logan Chienf3511742017-10-31 18:04:35 +08001125func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001126 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001127}
1128
Yi Kong7e53c572018-02-14 18:16:12 +08001129func (ctx *moduleContextImpl) isPgoCompile() bool {
1130 return ctx.mod.isPgoCompile()
1131}
1132
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001133func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1134 return ctx.mod.isNDKStubLibrary()
1135}
1136
Justin Yun8effde42017-06-23 19:24:43 +09001137func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001138 return ctx.mod.isVndkSp()
1139}
1140
1141func (ctx *moduleContextImpl) isVndkExt() bool {
1142 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001143}
1144
Vic Yangefd249e2018-11-12 20:19:56 -08001145func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001146 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001147}
1148
Justin Yun5f7f7e82019-11-18 19:52:14 +09001149func (ctx *moduleContextImpl) inProduct() bool {
1150 return ctx.mod.inProduct()
1151}
1152
1153func (ctx *moduleContextImpl) inVendor() bool {
1154 return ctx.mod.inVendor()
1155}
1156
Yifan Hong1b3348d2020-01-21 15:53:22 -08001157func (ctx *moduleContextImpl) inRamdisk() bool {
1158 return ctx.mod.InRamdisk()
1159}
1160
Jiyong Parkf9332f12018-02-01 00:54:12 +09001161func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001162 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001163}
1164
Logan Chien2f2b8902018-07-10 15:01:19 +08001165// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001166func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001167 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1168 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001169 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001170
1171 if ctx.ctx.Fuchsia() {
1172 return false
1173 }
1174
Logan Chien2f2b8902018-07-10 15:01:19 +08001175 if sanitize := ctx.mod.sanitize; sanitize != nil {
1176 if !sanitize.isVariantOnProductionDevice() {
1177 return false
1178 }
1179 }
1180 if !ctx.ctx.Device() {
1181 // Host modules do not need ABI dumps.
1182 return false
1183 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001184 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001185 // Stubs do not need ABI dumps.
1186 return false
1187 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001188 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001189}
1190
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001191func (ctx *moduleContextImpl) selectedStl() string {
1192 if stl := ctx.mod.stl; stl != nil {
1193 return stl.Properties.SelectedStl
1194 }
1195 return ""
1196}
1197
Ivan Lozanobd721262018-11-27 14:33:03 -08001198func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1199 return ctx.mod.linker.useClangLld(actx)
1200}
1201
Colin Crossce75d2c2016-10-06 16:12:58 -07001202func (ctx *moduleContextImpl) baseModuleName() string {
1203 return ctx.mod.ModuleBase.BaseModuleName()
1204}
1205
Logan Chienf3511742017-10-31 18:04:35 +08001206func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1207 return ctx.mod.getVndkExtendsModuleName()
1208}
1209
Logan Chiene274fc92019-12-03 11:18:32 -08001210func (ctx *moduleContextImpl) isForPlatform() bool {
1211 return ctx.mod.IsForPlatform()
1212}
1213
Jiyong Park58e364a2019-01-19 19:24:06 +09001214func (ctx *moduleContextImpl) apexName() string {
1215 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001216}
1217
Jooyung Han61c41542020-03-07 03:45:53 +09001218func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han74066602020-03-20 04:29:24 +09001219 return ctx.mod.apexSdkVersion
Jooyung Han61c41542020-03-07 03:45:53 +09001220}
1221
Jiyong Parkb0788572018-12-20 22:10:17 +09001222func (ctx *moduleContextImpl) hasStubsVariants() bool {
1223 return ctx.mod.HasStubsVariants()
1224}
1225
1226func (ctx *moduleContextImpl) isStubs() bool {
1227 return ctx.mod.IsStubs()
1228}
1229
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001230func (ctx *moduleContextImpl) bootstrap() bool {
1231 return ctx.mod.bootstrap()
1232}
1233
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001234func (ctx *moduleContextImpl) nativeCoverage() bool {
1235 return ctx.mod.nativeCoverage()
1236}
1237
Colin Cross635c3b02016-05-18 15:37:25 -07001238func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001239 return &Module{
1240 hod: hod,
1241 multilib: multilib,
1242 }
1243}
1244
Colin Cross635c3b02016-05-18 15:37:25 -07001245func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001246 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001247 module.features = []feature{
1248 &tidyFeature{},
1249 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001250 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001251 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001252 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001253 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001254 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001255 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001256 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001257 return module
1258}
1259
Colin Crossce75d2c2016-10-06 16:12:58 -07001260func (c *Module) Prebuilt() *android.Prebuilt {
1261 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1262 return p.prebuilt()
1263 }
1264 return nil
1265}
1266
1267func (c *Module) Name() string {
1268 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001269 if p, ok := c.linker.(interface {
1270 Name(string) string
1271 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001272 name = p.Name(name)
1273 }
1274 return name
1275}
1276
Alex Light3d673592019-01-18 14:37:31 -08001277func (c *Module) Symlinks() []string {
1278 if p, ok := c.installer.(interface {
1279 symlinkList() []string
1280 }); ok {
1281 return p.symlinkList()
1282 }
1283 return nil
1284}
1285
Jeff Gaston294356f2017-09-27 17:05:30 -07001286// orderDeps reorders dependencies into a list such that if module A depends on B, then
1287// A will precede B in the resultant list.
1288// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001289// Note that directSharedDeps should be the analogous static library for each shared lib dep
1290func 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 -07001291 // If A depends on B, then
1292 // Every list containing A will also contain B later in the list
1293 // So, after concatenating all lists, the final instance of B will have come from the same
1294 // original list as the final instance of A
1295 // So, the final instance of B will be later in the concatenation than the final A
1296 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1297 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001298 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001299 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001300 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1301 }
1302 for _, dep := range directSharedDeps {
1303 orderedAllDeps = append(orderedAllDeps, dep)
1304 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001305 }
1306
Colin Crossb6715442017-10-24 11:13:31 -07001307 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001308
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001309 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001310 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001311 // resultant list to only what the caller has chosen to include in directStaticDeps
1312 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001313
1314 return orderedAllDeps, orderedDeclaredDeps
1315}
1316
Ivan Lozano183a3212019-10-18 14:18:45 -07001317func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001318 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001319 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001320 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1321 staticDepFiles := []android.Path{}
1322 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001323 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1324 if dep.OutputFile().Valid() {
1325 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1326 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1327 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001328 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001329 sharedDepFiles := []android.Path{}
1330 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001331 if sharedDep.HasStaticVariant() {
1332 staticAnalogue := sharedDep.GetStaticVariant()
1333 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1334 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001335 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001336 }
1337
1338 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001339 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1340 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001341
1342 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001343}
1344
Roland Levillainf89cd092019-07-29 16:22:59 +01001345func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1346 test, ok := c.linker.(testPerSrc)
1347 return ok && test.isAllTestsVariation()
1348}
1349
Justin Yun5f7f7e82019-11-18 19:52:14 +09001350func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1351 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1352 // "current", it will append the VNDK version to the name suffix.
1353 var vndkVersion string
1354 var nameSuffix string
1355 if c.inProduct() {
1356 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1357 nameSuffix = productSuffix
1358 } else {
1359 vndkVersion = ctx.DeviceConfig().VndkVersion()
1360 nameSuffix = vendorSuffix
1361 }
1362 if vndkVersion == "current" {
1363 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1364 }
1365 if c.Properties.VndkVersion != vndkVersion {
1366 // add version suffix only if the module is using different vndk version than the
1367 // version in product or vendor partition.
1368 nameSuffix += "." + c.Properties.VndkVersion
1369 }
1370 return nameSuffix
1371}
1372
Colin Cross635c3b02016-05-18 15:37:25 -07001373func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001374 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001375 //
1376 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1377 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1378 // module and return early, as this module does not produce an output file per se.
1379 if c.IsTestPerSrcAllTestsVariation() {
1380 c.outputFile = android.OptionalPath{}
1381 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001382 }
1383
Jooyung Han38002912019-05-16 04:01:54 +09001384 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001385
Inseob Kim64c43952019-08-26 16:52:35 +09001386 c.Properties.SubName = ""
1387
1388 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1389 c.Properties.SubName += nativeBridgeSuffix
1390 }
1391
Justin Yun5f7f7e82019-11-18 19:52:14 +09001392 _, llndk := c.linker.(*llndkStubDecorator)
1393 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1394 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1395 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1396 // added for product variant only when we have vendor and product variants with core
1397 // variant. The suffix is not added for vendor-only or product-only module.
1398 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1399 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001400 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1401 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1402 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001403 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1404 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001405 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001406 c.Properties.SubName += recoverySuffix
1407 }
1408
Colin Crossca860ac2016-01-04 14:34:37 -08001409 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001410 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001411 moduleContextImpl: moduleContextImpl{
1412 mod: c,
1413 },
1414 }
1415 ctx.ctx = ctx
1416
Colin Crossf18e1102017-11-16 14:33:08 -08001417 deps := c.depsToPaths(ctx)
1418 if ctx.Failed() {
1419 return
1420 }
1421
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001422 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1423 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1424 }
1425
Colin Crossca860ac2016-01-04 14:34:37 -08001426 flags := Flags{
1427 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001428 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001429 }
Colin Crossca860ac2016-01-04 14:34:37 -08001430 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001431 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001432 }
1433 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001434 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001435 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001436 if c.stl != nil {
1437 flags = c.stl.flags(ctx, flags)
1438 }
Colin Cross16b23492016-01-06 14:41:07 -08001439 if c.sanitize != nil {
1440 flags = c.sanitize.flags(ctx, flags)
1441 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001442 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001443 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001444 }
Stephen Craneba090d12017-05-09 15:44:35 -07001445 if c.lto != nil {
1446 flags = c.lto.flags(ctx, flags)
1447 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001448 if c.pgo != nil {
1449 flags = c.pgo.flags(ctx, flags)
1450 }
Colin Crossca860ac2016-01-04 14:34:37 -08001451 for _, feature := range c.features {
1452 flags = feature.flags(ctx, flags)
1453 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001454 if ctx.Failed() {
1455 return
1456 }
1457
Colin Cross4af21ed2019-11-04 09:37:55 -08001458 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1459 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1460 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001461
Colin Cross4af21ed2019-11-04 09:37:55 -08001462 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001463
1464 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001465 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001466 }
1467 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001468 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001469 }
1470
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001471 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001472 // We need access to all the flags seen by a source file.
1473 if c.sabi != nil {
1474 flags = c.sabi.flags(ctx, flags)
1475 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001476
Colin Cross4af21ed2019-11-04 09:37:55 -08001477 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001478
Colin Crossca860ac2016-01-04 14:34:37 -08001479 // Optimization to reduce size of build.ninja
1480 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001481 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1482 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1483 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1484 flags.Local.CFlags = []string{"$cflags"}
1485 flags.Local.CppFlags = []string{"$cppflags"}
1486 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001487
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001488 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001489 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001490 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001491 if ctx.Failed() {
1492 return
1493 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001494 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001495 }
1496
Colin Crossca860ac2016-01-04 14:34:37 -08001497 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001498 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001499 if ctx.Failed() {
1500 return
1501 }
Colin Cross635c3b02016-05-18 15:37:25 -07001502 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001503
1504 // If a lib is directly included in any of the APEXes, unhide the stubs
1505 // variant having the latest version gets visible to make. In addition,
1506 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1507 // force anything in the make world to link against the stubs library.
1508 // (unless it is explicitly referenced via .bootstrap suffix or the
1509 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001510 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001511 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001512 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001513 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001514 c.Properties.HideFromMake = false // unhide
1515 // Note: this is still non-installable
1516 }
Inseob Kimac775b22020-03-03 22:06:32 +09001517
1518 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1519 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1520 if isSnapshotAware(ctx, c) {
1521 i.collectHeadersForSnapshot(ctx)
1522 }
1523 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001524 }
Colin Cross5049f022015-03-18 13:28:46 -07001525
Inseob Kim1f086e22019-05-09 13:29:15 +09001526 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001527 c.installer.install(ctx, c.outputFile.Path())
1528 if ctx.Failed() {
1529 return
Colin Crossca860ac2016-01-04 14:34:37 -08001530 }
Paul Duffinf51768a2020-03-04 14:52:46 +00001531 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1532 // If the module has been specifically configure to not be installed then
1533 // skip the installation as otherwise it will break when running inside make
1534 // as the output path to install will not be specified. Not all uninstallable
1535 // modules can skip installation as some are needed for resolving make side
1536 // dependencies.
1537 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001538 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001539}
1540
Colin Cross0ea8ba82019-06-06 14:33:29 -07001541func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001542 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001543 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001544 }
Colin Crossca860ac2016-01-04 14:34:37 -08001545 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001546}
1547
Colin Crossca860ac2016-01-04 14:34:37 -08001548func (c *Module) begin(ctx BaseModuleContext) {
1549 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001550 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001551 }
Colin Crossca860ac2016-01-04 14:34:37 -08001552 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001553 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001554 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001555 if c.stl != nil {
1556 c.stl.begin(ctx)
1557 }
Colin Cross16b23492016-01-06 14:41:07 -08001558 if c.sanitize != nil {
1559 c.sanitize.begin(ctx)
1560 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001561 if c.coverage != nil {
1562 c.coverage.begin(ctx)
1563 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001564 if c.sabi != nil {
1565 c.sabi.begin(ctx)
1566 }
Justin Yun8effde42017-06-23 19:24:43 +09001567 if c.vndkdep != nil {
1568 c.vndkdep.begin(ctx)
1569 }
Stephen Craneba090d12017-05-09 15:44:35 -07001570 if c.lto != nil {
1571 c.lto.begin(ctx)
1572 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001573 if c.pgo != nil {
1574 c.pgo.begin(ctx)
1575 }
Colin Crossca860ac2016-01-04 14:34:37 -08001576 for _, feature := range c.features {
1577 feature.begin(ctx)
1578 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001579 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001580 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001581 if err != nil {
1582 ctx.PropertyErrorf("sdk_version", err.Error())
1583 }
Nan Zhang0007d812017-11-07 10:57:05 -08001584 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001585 }
Colin Crossca860ac2016-01-04 14:34:37 -08001586}
1587
Colin Cross37047f12016-12-13 17:06:13 -08001588func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001589 deps := Deps{}
1590
1591 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001592 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001593 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001594 // Add the PGO dependency (the clang_rt.profile runtime library), which
1595 // sometimes depends on symbols from libgcc, before libgcc gets added
1596 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001597 if c.pgo != nil {
1598 deps = c.pgo.deps(ctx, deps)
1599 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001600 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001601 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001602 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001603 if c.stl != nil {
1604 deps = c.stl.deps(ctx, deps)
1605 }
Colin Cross16b23492016-01-06 14:41:07 -08001606 if c.sanitize != nil {
1607 deps = c.sanitize.deps(ctx, deps)
1608 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001609 if c.coverage != nil {
1610 deps = c.coverage.deps(ctx, deps)
1611 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001612 if c.sabi != nil {
1613 deps = c.sabi.deps(ctx, deps)
1614 }
Justin Yun8effde42017-06-23 19:24:43 +09001615 if c.vndkdep != nil {
1616 deps = c.vndkdep.deps(ctx, deps)
1617 }
Stephen Craneba090d12017-05-09 15:44:35 -07001618 if c.lto != nil {
1619 deps = c.lto.deps(ctx, deps)
1620 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001621 for _, feature := range c.features {
1622 deps = feature.deps(ctx, deps)
1623 }
1624
Colin Crossb6715442017-10-24 11:13:31 -07001625 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1626 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1627 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1628 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1629 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1630 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001631 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001632
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001633 for _, lib := range deps.ReexportSharedLibHeaders {
1634 if !inList(lib, deps.SharedLibs) {
1635 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1636 }
1637 }
1638
1639 for _, lib := range deps.ReexportStaticLibHeaders {
1640 if !inList(lib, deps.StaticLibs) {
1641 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1642 }
1643 }
1644
Colin Cross5950f382016-12-13 12:50:57 -08001645 for _, lib := range deps.ReexportHeaderLibHeaders {
1646 if !inList(lib, deps.HeaderLibs) {
1647 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1648 }
1649 }
1650
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001651 for _, gen := range deps.ReexportGeneratedHeaders {
1652 if !inList(gen, deps.GeneratedHeaders) {
1653 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1654 }
1655 }
1656
Colin Crossc99deeb2016-04-11 15:06:20 -07001657 return deps
1658}
1659
Dan Albert7e9d2952016-08-04 13:02:36 -07001660func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001661 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001662 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001663 moduleContextImpl: moduleContextImpl{
1664 mod: c,
1665 },
1666 }
1667 ctx.ctx = ctx
1668
Colin Crossca860ac2016-01-04 14:34:37 -08001669 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001670}
1671
Jiyong Park7ed9de32018-10-15 22:25:07 +09001672// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001673func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001674 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1675 version := name[sharp+1:]
1676 libname := name[:sharp]
1677 return libname, version
1678 }
1679 return name, ""
1680}
1681
Colin Cross1e676be2016-10-12 14:38:15 -07001682func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001683 if !c.Enabled() {
1684 return
1685 }
1686
Colin Cross37047f12016-12-13 17:06:13 -08001687 ctx := &depsContext{
1688 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001689 moduleContextImpl: moduleContextImpl{
1690 mod: c,
1691 },
1692 }
1693 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001694
Colin Crossc99deeb2016-04-11 15:06:20 -07001695 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001696
Dan Albert914449f2016-06-17 16:45:24 -07001697 variantNdkLibs := []string{}
1698 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001699 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001700 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001701
Inseob Kimeec88e12020-01-22 11:11:29 +09001702 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001703 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001704 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001705 // 1. Name of an NDK library that refers to a prebuilt module.
1706 // For each of these, it adds the name of the prebuilt module (which will be in
1707 // prebuilts/ndk) to the list of nonvariant libs.
1708 // 2. Name of an NDK library that refers to an ndk_library module.
1709 // For each of these, it adds the name of the ndk_library module to the list of
1710 // variant libs.
1711 // 3. Anything else (so anything that isn't an NDK library).
1712 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001713 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001714 // The caller can then know to add the variantLibs dependencies differently from the
1715 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001716
Inseob Kim9516ee92019-05-09 10:56:13 +09001717 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001718 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1719
1720 rewriteVendorLibs := func(lib string) string {
1721 if isLlndkLibrary(lib, ctx.Config()) {
1722 return lib + llndkLibrarySuffix
1723 }
1724
1725 // only modules with BOARD_VNDK_VERSION uses snapshot.
1726 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1727 return lib
1728 }
1729
1730 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1731 return snapshot
1732 }
1733
1734 return lib
1735 }
1736
1737 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001738 variantLibs = []string{}
1739 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001740 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001741 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001742 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001743 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1744 if !inList(name, ndkMigratedLibs) {
1745 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001746 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001747 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001748 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001749 } else if ctx.useVndk() {
1750 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001751 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001752 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001753 if actx.OtherModuleExists(vendorPublicLib) {
1754 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1755 } else {
1756 // This can happen if vendor_public_library module is defined in a
1757 // namespace that isn't visible to the current module. In that case,
1758 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001759 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001760 }
Dan Albert914449f2016-06-17 16:45:24 -07001761 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001762 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001763 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001764 }
1765 }
Dan Albert914449f2016-06-17 16:45:24 -07001766 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001767 }
1768
Inseob Kimeec88e12020-01-22 11:11:29 +09001769 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1770 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1771 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1772 if ctx.useVndk() {
1773 for idx, lib := range deps.RuntimeLibs {
1774 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1775 }
1776 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001777 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001778
Jiyong Park7e636d02019-01-28 16:16:54 +09001779 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001780 if c.linker != nil {
1781 if library, ok := c.linker.(*libraryDecorator); ok {
1782 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001783 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001784 }
1785 }
1786 }
1787
Inseob Kimeec88e12020-01-22 11:11:29 +09001788 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1789 // only modules with BOARD_VNDK_VERSION uses snapshot.
1790 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1791 return lib
1792 }
1793
1794 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1795 return snapshot
1796 }
1797
1798 return lib
1799 }
1800
1801 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001802 for _, lib := range deps.HeaderLibs {
1803 depTag := headerDepTag
1804 if inList(lib, deps.ReexportHeaderLibHeaders) {
1805 depTag = headerExportDepTag
1806 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001807
1808 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1809
Jiyong Park7e636d02019-01-28 16:16:54 +09001810 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001811 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001812 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001813 } else {
1814 actx.AddVariationDependencies(nil, depTag, lib)
1815 }
1816 }
1817
1818 if buildStubs {
1819 // Stubs lib does not have dependency to other static/shared libraries.
1820 // Don't proceed.
1821 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001822 }
Colin Cross5950f382016-12-13 12:50:57 -08001823
Inseob Kimc0907f12019-02-08 21:00:45 +09001824 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001825 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001826
Jiyong Park5d1598f2019-02-25 22:14:17 +09001827 for _, lib := range deps.WholeStaticLibs {
1828 depTag := wholeStaticDepTag
1829 if impl, ok := syspropImplLibraries[lib]; ok {
1830 lib = impl
1831 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001832
1833 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1834
Jiyong Park5d1598f2019-02-25 22:14:17 +09001835 actx.AddVariationDependencies([]blueprint.Variation{
1836 {Mutator: "link", Variation: "static"},
1837 }, depTag, lib)
1838 }
1839
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001840 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001841 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001842 if inList(lib, deps.ReexportStaticLibHeaders) {
1843 depTag = staticExportDepTag
1844 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001845
1846 if impl, ok := syspropImplLibraries[lib]; ok {
1847 lib = impl
1848 }
1849
Inseob Kimeec88e12020-01-22 11:11:29 +09001850 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1851
Dan Willemsen59339a22018-07-22 21:18:45 -07001852 actx.AddVariationDependencies([]blueprint.Variation{
1853 {Mutator: "link", Variation: "static"},
1854 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001855 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001856
Jooyung Han74066602020-03-20 04:29:24 +09001857 // staticUnwinderDep is treated as staticDep for Q apexes
1858 // so that native libraries/binaries are linked with static unwinder
1859 // because Q libc doesn't have unwinder APIs
1860 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001861 actx.AddVariationDependencies([]blueprint.Variation{
1862 {Mutator: "link", Variation: "static"},
1863 }, staticUnwinderDepTag, staticUnwinder(actx))
1864 }
1865
Inseob Kimeec88e12020-01-22 11:11:29 +09001866 for _, lib := range deps.LateStaticLibs {
1867 actx.AddVariationDependencies([]blueprint.Variation{
1868 {Mutator: "link", Variation: "static"},
1869 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1870 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001871
Ivan Lozano183a3212019-10-18 14:18:45 -07001872 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001873 var variations []blueprint.Variation
1874 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Hanc40b5192020-04-10 12:57:24 +09001875 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001876 // Version is explicitly specified. i.e. libFoo#30
1877 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001878 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001879 }
1880 actx.AddVariationDependencies(variations, depTag, name)
1881
Jooyung Han0c4e0162020-02-26 22:45:42 +09001882 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001883 // The stubs library will be used when the depending module is built for APEX and
1884 // the dependent module is not in the same APEX.
Jooyung Hanc40b5192020-04-10 12:57:24 +09001885 if version == "" && VersionVariantAvailable(c) {
Jooyung Han0c4e0162020-02-26 22:45:42 +09001886 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1887 // Note that depTag.ExplicitlyVersioned is false in this case.
1888 actx.AddVariationDependencies([]blueprint.Variation{
1889 {Mutator: "link", Variation: "shared"},
1890 {Mutator: "version", Variation: ver},
1891 }, depTag, name)
1892 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001893 }
1894 }
1895
Jiyong Park7ed9de32018-10-15 22:25:07 +09001896 // shared lib names without the #version suffix
1897 var sharedLibNames []string
1898
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001899 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001900 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001901 if c.static() {
1902 depTag = SharedFromStaticDepTag
1903 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001904 if inList(lib, deps.ReexportSharedLibHeaders) {
1905 depTag = sharedExportDepTag
1906 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001907
1908 if impl, ok := syspropImplLibraries[lib]; ok {
1909 lib = impl
1910 }
1911
Jiyong Park73c54ee2019-10-22 20:31:18 +09001912 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001913 sharedLibNames = append(sharedLibNames, name)
1914
Jiyong Park25fc6a92018-11-18 18:02:45 +09001915 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001916 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001917
Jiyong Park7ed9de32018-10-15 22:25:07 +09001918 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001919 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001920 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1921 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1922 // linking against both the stubs lib and the non-stubs lib at the same time.
1923 continue
1924 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001925 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001926 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001927
Dan Willemsen59339a22018-07-22 21:18:45 -07001928 actx.AddVariationDependencies([]blueprint.Variation{
1929 {Mutator: "link", Variation: "shared"},
1930 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001931
Colin Cross68861832016-07-08 10:41:41 -07001932 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001933
1934 for _, gen := range deps.GeneratedHeaders {
1935 depTag := genHeaderDepTag
1936 if inList(gen, deps.ReexportGeneratedHeaders) {
1937 depTag = genHeaderExportDepTag
1938 }
1939 actx.AddDependency(c, depTag, gen)
1940 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001941
Colin Cross42d48b72018-08-29 14:10:52 -07001942 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001943
1944 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001945 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001946 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001947 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001948 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001949 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001950 if deps.LinkerFlagsFile != "" {
1951 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1952 }
1953 if deps.DynamicLinker != "" {
1954 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001955 }
Dan Albert914449f2016-06-17 16:45:24 -07001956
1957 version := ctx.sdkVersion()
1958 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001959 {Mutator: "ndk_api", Variation: version},
1960 {Mutator: "link", Variation: "shared"},
1961 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001962 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001963 {Mutator: "ndk_api", Variation: version},
1964 {Mutator: "link", Variation: "shared"},
1965 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001966
1967 if vndkdep := c.vndkdep; vndkdep != nil {
1968 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001969 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001970 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001971 {Mutator: "link", Variation: "shared"},
1972 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001973 }
1974 }
Colin Cross6362e272015-10-29 15:25:03 -07001975}
Colin Cross21b9a242015-03-24 14:15:58 -07001976
Colin Crosse40b4ea2018-10-02 22:25:58 -07001977func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001978 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1979 c.beginMutator(ctx)
1980 }
1981}
1982
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001983// Whether a module can link to another module, taking into
1984// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001985func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1986 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001987 // Host code is not restricted
1988 return
1989 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001990
1991 // VNDK is cc.Module supported only for now.
1992 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001993 // Though vendor code is limited by the vendor mutator,
1994 // each vendor-available module needs to check
1995 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001996 if ccTo, ok := to.(*Module); ok {
1997 if ccFrom.vndkdep != nil {
1998 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1999 }
2000 } else {
2001 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002002 }
2003 return
2004 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002005 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002006 // Platform code can link to anything
2007 return
2008 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002009 if from.InRamdisk() {
2010 // Ramdisk code is not NDK
2011 return
2012 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002013 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002014 // Recovery code is not NDK
2015 return
2016 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002017 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002018 // These are always allowed
2019 return
2020 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002021 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002022 // These are allowed, but they don't set sdk_version
2023 return
2024 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002025 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002026 // These aren't real libraries, but are the stub shared libraries that are included in
2027 // the NDK.
2028 return
2029 }
Logan Chien834b9a62019-01-14 15:39:03 +08002030
Ivan Lozano52767be2019-10-18 14:49:46 -07002031 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002032 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2033 // to link to libc++ (non-NDK and without sdk_version).
2034 return
2035 }
2036
Ivan Lozano52767be2019-10-18 14:49:46 -07002037 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002038 // NDK code linking to platform code is never okay.
2039 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002040 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002041 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002042 }
2043
2044 // At this point we know we have two NDK libraries, but we need to
2045 // check that we're not linking against anything built against a higher
2046 // API level, as it is only valid to link against older or equivalent
2047 // APIs.
2048
Inseob Kim01a28722018-04-11 09:48:45 +09002049 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002050 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002051 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002052 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002053 // Current can't be linked against by anything else.
2054 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002055 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002056 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002057 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002058 if err != nil {
2059 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002060 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002061 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002062 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002063 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002064 if err != nil {
2065 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002066 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002067 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002068 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002069
Inseob Kim01a28722018-04-11 09:48:45 +09002070 if toApi > fromApi {
2071 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002072 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002073 }
2074 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002075 }
Dan Albert202fe492017-12-15 13:56:59 -08002076
2077 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002078 fromStl := from.SelectedStl()
2079 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002080 if fromStl == "" || toStl == "" {
2081 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002082 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002083 // We can be permissive with the system "STL" since it is only the C++
2084 // ABI layer, but in the future we should make sure that everyone is
2085 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002086 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002087 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002088 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2089 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002090 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002091}
2092
Jiyong Park5fb8c102018-04-09 12:03:06 +09002093// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002094// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2095// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002096// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002097func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2098 check := func(child, parent android.Module) bool {
2099 to, ok := child.(*Module)
2100 if !ok {
2101 // follow thru cc.Defaults, etc.
2102 return true
2103 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002104
Jooyung Hana70f0672019-01-18 15:20:43 +09002105 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2106 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002107 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002108
2109 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002110 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002111 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002112 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002113
Jooyung Han0302a842019-10-30 18:43:49 +09002114 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002115 return false
2116 }
2117
2118 var stringPath []string
2119 for _, m := range ctx.GetWalkPath() {
2120 stringPath = append(stringPath, m.Name())
2121 }
2122 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2123 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2124 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2125 return false
2126 }
2127 if module, ok := ctx.Module().(*Module); ok {
2128 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002129 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002130 ctx.WalkDeps(check)
2131 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002132 }
2133 }
2134}
2135
Colin Crossc99deeb2016-04-11 15:06:20 -07002136// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002137func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002138 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002139
Ivan Lozano183a3212019-10-18 14:18:45 -07002140 directStaticDeps := []LinkableInterface{}
2141 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002142
Inseob Kim9516ee92019-05-09 10:56:13 +09002143 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2144
Inseob Kim69378442019-06-03 19:10:47 +09002145 reexportExporter := func(exporter exportedFlagsProducer) {
2146 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2147 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2148 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2149 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002150 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002151 }
2152
Colin Crossd11fcda2017-10-23 17:59:01 -07002153 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 depName := ctx.OtherModuleName(dep)
2155 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002156
Ivan Lozano52767be2019-10-18 14:49:46 -07002157 ccDep, ok := dep.(LinkableInterface)
2158 if !ok {
2159
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002160 // handling for a few module types that aren't cc Module but that are also supported
2161 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002162 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002163 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002164 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2165 genRule.GeneratedSourceFiles()...)
2166 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002167 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002168 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002169 // Support exported headers from a generated_sources dependency
2170 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002171 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002172 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002173 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002174 genRule.GeneratedSourceFiles()...)
2175 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002176 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002177 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002178 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002179 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002180 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002181 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2182 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002183 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002184 // 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 +09002185 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002186
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002187 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002188 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002189 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002190 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002191 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002192 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002193 files := genRule.GeneratedSourceFiles()
2194 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002195 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002196 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002197 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 -07002198 }
2199 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002200 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002201 }
Colin Crossca860ac2016-01-04 14:34:37 -08002202 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002203 return
2204 }
2205
Colin Crossfe17f6f2019-03-28 19:30:56 -07002206 if depTag == android.ProtoPluginDepTag {
2207 return
2208 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002209 if depTag == llndkImplDep {
2210 return
2211 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002212
Colin Crossd11fcda2017-10-23 17:59:01 -07002213 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002214 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2215 return
2216 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002217 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002218 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2219 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002220 return
2221 }
2222
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002223 // re-exporting flags
2224 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 // reusing objects only make sense for cc.Modules.
2226 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002227 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002228 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002229 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002230 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002231 return
2232 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002233 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002234
Jiyong Parke4bb9862019-02-01 00:31:10 +09002235 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002236 // staticVariants are a cc.Module specific concept.
2237 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002238 c.staticVariant = ccDep
2239 return
2240 }
2241 }
2242
Jooyung Han74066602020-03-20 04:29:24 +09002243 // For the dependency from platform to apex, use the latest stubs
2244 c.apexSdkVersion = android.FutureApiLevel
2245 if !c.IsForPlatform() {
2246 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2247 }
2248
2249 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2250 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2251 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2252 // (b/144430859)
2253 c.apexSdkVersion = android.FutureApiLevel
2254 }
2255
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002256 if depTag == staticUnwinderDepTag {
Jooyung Han74066602020-03-20 04:29:24 +09002257 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2258 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002259 depTag = StaticDepTag
2260 } else {
2261 return
2262 }
2263 }
2264
Ivan Lozano183a3212019-10-18 14:18:45 -07002265 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2266 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2267 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002268 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002269 if t, ok := depTag.(DependencyTag); ok {
2270 explicitlyVersioned = t.ExplicitlyVersioned
2271 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002272 depTag = t
2273 }
2274
Ivan Lozano183a3212019-10-18 14:18:45 -07002275 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002276 depIsStatic := false
2277 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002278 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002279 depIsStatic = true
2280 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002281 if ccDep.CcLibrary() && !depIsStatic {
2282 depIsStubs := ccDep.BuildStubs()
Jooyung Hanc40b5192020-04-10 12:57:24 +09002283 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002284 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002285 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002286
2287 var useThisDep bool
2288 if depIsStubs && explicitlyVersioned {
2289 // Always respect dependency to the versioned stubs (i.e. libX#10)
2290 useThisDep = true
2291 } else if !depHasStubs {
2292 // Use non-stub variant if that is the only choice
2293 // (i.e. depending on a lib without stubs.version property)
2294 useThisDep = true
2295 } else if c.IsForPlatform() {
2296 // If not building for APEX, use stubs only when it is from
2297 // an APEX (and not from platform)
2298 useThisDep = (depInPlatform != depIsStubs)
Jooyung Hanc40b5192020-04-10 12:57:24 +09002299 if c.bootstrap() {
2300 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002301 // always link to non-stub variant
2302 useThisDep = !depIsStubs
2303 }
Jiyong Parkf0d01b72020-04-13 16:19:48 +09002304 for _, testFor := range c.TestFor() {
2305 // Another exception: if this module is bundled with an APEX, then
2306 // it is linked with the non-stub variant of a module in the APEX
2307 // as if this is part of the APEX.
2308 if android.DirectlyInApex(testFor, depName) {
2309 useThisDep = !depIsStubs
2310 break
2311 }
2312 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002313 } else {
2314 // If building for APEX, use stubs only when it is not from
2315 // the same APEX
2316 useThisDep = (depInSameApex != depIsStubs)
2317 }
2318
Jooyung Han0c4e0162020-02-26 22:45:42 +09002319 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2320 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han74066602020-03-20 04:29:24 +09002321 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han0c4e0162020-02-26 22:45:42 +09002322 if err != nil {
2323 ctx.OtherModuleErrorf(dep, err.Error())
2324 return
2325 }
2326 if versionToUse != ccDep.StubsVersion() {
2327 useThisDep = false
2328 }
2329 }
2330
Jiyong Park25fc6a92018-11-18 18:02:45 +09002331 if !useThisDep {
2332 return // stop processing this dep
2333 }
2334 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002335 if c.UseVndk() {
2336 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2337 // by default, use current version of LLNDK
2338 versionToUse := ""
2339 versions := stubsVersionsFor(ctx.Config())[depName]
2340 if c.ApexName() != "" && len(versions) > 0 {
2341 // if this is for use_vendor apex && dep has stubsVersions
2342 // apply the same rule of apex sdk enforcement to choose right version
2343 var err error
Jooyung Han74066602020-03-20 04:29:24 +09002344 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han67a96cd2020-03-13 15:23:36 +09002345 if err != nil {
2346 ctx.OtherModuleErrorf(dep, err.Error())
2347 return
2348 }
2349 }
2350 if versionToUse != ccDep.StubsVersion() {
2351 return
2352 }
2353 }
2354 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002355
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002356 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2357
Ivan Lozano52767be2019-10-18 14:49:46 -07002358 // Exporting flags only makes sense for cc.Modules
2359 if _, ok := ccDep.(*Module); ok {
2360 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002361 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002362 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2363 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002364 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002365
Ivan Lozano52767be2019-10-18 14:49:46 -07002366 if t.ReexportFlags {
2367 reexportExporter(i)
2368 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2369 // Re-exported shared library headers must be included as well since they can help us with type information
2370 // about template instantiations (instantiated from their headers).
2371 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2372 // scripts.
2373 c.sabi.Properties.ReexportedIncludes = append(
2374 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2375 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002376 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002377 }
Logan Chienf3511742017-10-31 18:04:35 +08002378 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002379 }
2380
Colin Cross26c34ed2016-09-30 17:10:16 -07002381 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002382 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002383
Ivan Lozano52767be2019-10-18 14:49:46 -07002384 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002385 depFile := android.OptionalPath{}
2386
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002387 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002388 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002389 ptr = &depPaths.SharedLibs
2390 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002391 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002392 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002393
Jiyong Park64a44f22019-01-18 14:37:08 +09002394 case earlySharedDepTag:
2395 ptr = &depPaths.EarlySharedLibs
2396 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002397 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002398 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002399 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002400 ptr = &depPaths.LateSharedLibs
2401 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002402 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002403 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002404 ptr = nil
2405 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002406 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002407 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002408 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002409 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002410 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002411 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002412 return
2413 }
2414
Ivan Lozano52767be2019-10-18 14:49:46 -07002415 // Because the static library objects are included, this only makes sense
2416 // in the context of proper cc.Modules.
2417 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2418 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2419 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2420 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2421 for i := range missingDeps {
2422 missingDeps[i] += postfix
2423 }
2424 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002425 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002426 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2427 } else {
2428 ctx.ModuleErrorf(
2429 "non-cc.Modules cannot be included as whole static libraries.", depName)
2430 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002431 }
Colin Cross5950f382016-12-13 12:50:57 -08002432 case headerDepTag:
2433 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002434 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002435 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002436 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002437 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002438 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002439 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002440 case dynamicLinkerDepTag:
2441 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002442 }
2443
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002444 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002445 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002446 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002447 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002448 return
2449 }
2450
2451 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002452 // in static libraries act as if they were whole static libraries. The same goes for
2453 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002454 // This should only be done for cc.Modules
2455 if c, ok := ccDep.(*Module); ok {
2456 staticLib := c.linker.(libraryInterface)
2457 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2458 staticLib.objs().coverageFiles...)
2459 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2460 staticLib.objs().sAbiDumpFiles...)
2461 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002462 }
2463
Colin Cross26c34ed2016-09-30 17:10:16 -07002464 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002465 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002466 if !ctx.Config().AllowMissingDependencies() {
2467 ctx.ModuleErrorf("module %q missing output file", depName)
2468 } else {
2469 ctx.AddMissingDependencies([]string{depName})
2470 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002471 return
2472 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002473 *ptr = append(*ptr, linkFile.Path())
2474 }
2475
Colin Crossc99deeb2016-04-11 15:06:20 -07002476 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002477 dep := depFile
2478 if !dep.Valid() {
2479 dep = linkFile
2480 }
2481 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002482 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002483
Inseob Kimeec88e12020-01-22 11:11:29 +09002484 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2485
2486 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002487 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002488 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002489 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002490 return libName
2491 }
2492
2493 makeLibName := func(depName string) string {
2494 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002495 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002496 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002497 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002498
Inseob Kimeec88e12020-01-22 11:11:29 +09002499 if c, ok := ccDep.(*Module); ok {
2500 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002501 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002502 baseName := c.BaseModuleName()
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002503
2504 if c.IsVndk() {
2505 return baseName + ".vendor"
2506 }
2507
Inseob Kimeec88e12020-01-22 11:11:29 +09002508 if vendorSuffixModules[baseName] {
2509 return baseName + ".vendor"
2510 } else {
2511 return baseName
2512 }
2513 }
2514 }
2515
Yifan Hong1b3348d2020-01-21 15:53:22 -08002516 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002517 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2518 // core module instead.
2519 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002520 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002521 // The vendor module in Make will have been renamed to not conflict with the core
2522 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002523 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002524 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002525 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002526 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2527 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002528 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002529 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002530 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002531 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002532 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002533 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002534 }
Logan Chien43d34c32017-12-20 01:17:32 +08002535 }
2536
2537 // Export the shared libs to Make.
2538 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002539 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002540 if ccDep.CcLibrary() {
2541 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002542 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002543 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002544 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002545 c.Properties.ApexesProvidingSharedLibs = append(
2546 c.Properties.ApexesProvidingSharedLibs, an)
2547 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002548 }
2549 }
2550
Jiyong Park27b188b2017-07-18 13:23:39 +09002551 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002552 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002553 c.Properties.AndroidMkSharedLibs = append(
2554 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002555 // Record baseLibName for snapshots.
2556 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002557 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002558 c.Properties.AndroidMkSharedLibs = append(
2559 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002560 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002561 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002562 c.Properties.AndroidMkStaticLibs = append(
2563 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002564 case runtimeDepTag:
2565 c.Properties.AndroidMkRuntimeLibs = append(
2566 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002567 // Record baseLibName for snapshots.
2568 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002569 case wholeStaticDepTag:
2570 c.Properties.AndroidMkWholeStaticLibs = append(
2571 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002572 }
Colin Crossca860ac2016-01-04 14:34:37 -08002573 })
2574
Jeff Gaston294356f2017-09-27 17:05:30 -07002575 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002576 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002577
Colin Crossdd84e052017-05-17 13:44:16 -07002578 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002579 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002580 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2581 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002582 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002583 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002584 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2585 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002586 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002587 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002588 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002589
2590 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002591 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002592 }
Colin Crossdd84e052017-05-17 13:44:16 -07002593
Colin Crossca860ac2016-01-04 14:34:37 -08002594 return depPaths
2595}
2596
2597func (c *Module) InstallInData() bool {
2598 if c.installer == nil {
2599 return false
2600 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002601 return c.installer.inData()
2602}
2603
2604func (c *Module) InstallInSanitizerDir() bool {
2605 if c.installer == nil {
2606 return false
2607 }
2608 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002609 return true
2610 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002611 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002612}
2613
Yifan Hong1b3348d2020-01-21 15:53:22 -08002614func (c *Module) InstallInRamdisk() bool {
2615 return c.InRamdisk()
2616}
2617
Jiyong Parkf9332f12018-02-01 00:54:12 +09002618func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002619 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002620}
2621
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +01002622func (c *Module) SkipInstall() {
2623 if c.installer == nil {
2624 c.ModuleBase.SkipInstall()
2625 return
2626 }
2627 c.installer.skipInstall(c)
2628}
2629
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002630func (c *Module) HostToolPath() android.OptionalPath {
2631 if c.installer == nil {
2632 return android.OptionalPath{}
2633 }
2634 return c.installer.hostToolPath()
2635}
2636
Nan Zhangd4e641b2017-07-12 12:55:28 -07002637func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2638 return c.outputFile
2639}
2640
Colin Cross41955e82019-05-29 14:40:35 -07002641func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2642 switch tag {
2643 case "":
2644 if c.outputFile.Valid() {
2645 return android.Paths{c.outputFile.Path()}, nil
2646 }
2647 return android.Paths{}, nil
2648 default:
2649 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002650 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002651}
2652
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002653func (c *Module) static() bool {
2654 if static, ok := c.linker.(interface {
2655 static() bool
2656 }); ok {
2657 return static.static()
2658 }
2659 return false
2660}
2661
Jiyong Park379de2f2018-12-19 02:47:14 +09002662func (c *Module) staticBinary() bool {
2663 if static, ok := c.linker.(interface {
2664 staticBinary() bool
2665 }); ok {
2666 return static.staticBinary()
2667 }
2668 return false
2669}
2670
Jiyong Park1d1119f2019-07-29 21:27:18 +09002671func (c *Module) header() bool {
2672 if h, ok := c.linker.(interface {
2673 header() bool
2674 }); ok {
2675 return h.header()
2676 }
2677 return false
2678}
2679
Jooyung Han38002912019-05-16 04:01:54 +09002680func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002681 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002682 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2683 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002684 return "native:vndk"
2685 }
Jooyung Han38002912019-05-16 04:01:54 +09002686 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002687 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002688 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002689 if Bool(c.VendorProperties.Vendor_available) {
2690 return "native:vndk"
2691 }
2692 return "native:vndk_private"
2693 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002694 if c.inProduct() {
2695 return "native:product"
2696 }
Jooyung Han38002912019-05-16 04:01:54 +09002697 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002698 } else if c.InRamdisk() {
2699 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002700 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002701 return "native:recovery"
2702 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2703 return "native:ndk:none:none"
2704 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2705 //family, link := getNdkStlFamilyAndLinkType(c)
2706 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002707 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002708 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002709 } else {
2710 return "native:platform"
2711 }
2712}
2713
Jiyong Park9d452992018-10-03 00:38:19 +09002714// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002715// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002716func (c *Module) IsInstallableToApex() bool {
2717 if shared, ok := c.linker.(interface {
2718 shared() bool
2719 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002720 // Stub libs and prebuilt libs in a versioned SDK are not
2721 // installable to APEX even though they are shared libs.
2722 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002723 } else if _, ok := c.linker.(testPerSrc); ok {
2724 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002725 }
2726 return false
2727}
2728
Jiyong Parka90ca002019-10-07 15:47:24 +09002729func (c *Module) AvailableFor(what string) bool {
2730 if linker, ok := c.linker.(interface {
2731 availableFor(string) bool
2732 }); ok {
2733 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2734 } else {
2735 return c.ApexModuleBase.AvailableFor(what)
2736 }
2737}
2738
Jiyong Parkf0d01b72020-04-13 16:19:48 +09002739func (c *Module) TestFor() []string {
2740 if test, ok := c.linker.(interface {
2741 testFor() []string
2742 }); ok {
2743 return test.testFor()
2744 } else {
2745 return c.ApexModuleBase.TestFor()
2746 }
2747}
2748
Paul Duffinf51768a2020-03-04 14:52:46 +00002749// Return true if the module is ever installable.
2750func (c *Module) EverInstallable() bool {
2751 return c.installer != nil &&
2752 // Check to see whether the module is actually ever installable.
2753 c.installer.everInstallable()
2754}
2755
Inseob Kim1f086e22019-05-09 13:29:15 +09002756func (c *Module) installable() bool {
Paul Duffinf51768a2020-03-04 14:52:46 +00002757 ret := c.EverInstallable() &&
2758 // Check to see whether the module has been configured to not be installed.
2759 proptools.BoolDefault(c.Properties.Installable, true) &&
2760 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002761
2762 // The platform variant doesn't need further condition. Apex variants however might not
2763 // be installable because it will likely to be included in the APEX and won't appear
2764 // in the system partition.
2765 if c.IsForPlatform() {
2766 return ret
2767 }
2768
2769 // Special case for modules that are configured to be installed to /data, which includes
2770 // test modules. For these modules, both APEX and non-APEX variants are considered as
2771 // installable. This is because even the APEX variants won't be included in the APEX, but
2772 // will anyway be installed to /data/*.
2773 // See b/146995717
2774 if c.InstallInData() {
2775 return ret
2776 }
2777
2778 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002779}
2780
Logan Chien41eabe62019-04-10 13:33:58 +08002781func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2782 if c.linker != nil {
2783 if library, ok := c.linker.(*libraryDecorator); ok {
2784 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2785 }
2786 }
2787}
2788
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002789func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002790 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002791 if cc, ok := dep.(*Module); ok {
Jiyong Park9f14b9b2020-03-01 17:29:06 +09002792 if cc.HasStubsVariants() {
2793 if depTag.Shared && depTag.Library {
2794 // dynamic dep to a stubs lib crosses APEX boundary
2795 return false
2796 }
2797 if IsRuntimeDepTag(depTag) {
2798 // runtime dep to a stubs lib also crosses APEX boundary
2799 return false
2800 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002801 }
2802 if depTag.FromStatic {
2803 // shared_lib dependency from a static lib is considered as crossing
2804 // the APEX boundary because the dependency doesn't actually is
2805 // linked; the dependency is used only during the compilation phase.
2806 return false
2807 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002808 }
2809 }
2810 return true
2811}
2812
Colin Cross2ba19d92015-05-07 15:44:20 -07002813//
Colin Crosscfad1192015-11-02 16:43:11 -08002814// Defaults
2815//
Colin Crossca860ac2016-01-04 14:34:37 -08002816type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002817 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002818 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002819 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002820}
2821
Patrice Arrudac249c712019-03-19 17:00:29 -07002822// cc_defaults provides a set of properties that can be inherited by other cc
2823// modules. A module can use the properties from a cc_defaults using
2824// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2825// merged (when possible) by prepending the default module's values to the
2826// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002827func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002828 return DefaultsFactory()
2829}
2830
Colin Cross36242852017-06-23 15:06:31 -07002831func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002832 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002833
Colin Cross36242852017-06-23 15:06:31 -07002834 module.AddProperties(props...)
2835 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002836 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002837 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002838 &BaseCompilerProperties{},
2839 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002840 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002841 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002842 &StaticProperties{},
2843 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002844 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002845 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002846 &TestProperties{},
2847 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002848 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002849 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002850 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002851 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002852 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002853 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002854 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002855 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002856 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002857 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002858 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002859 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002860 )
Colin Crosscfad1192015-11-02 16:43:11 -08002861
Jooyung Hancc372c52019-09-25 15:18:44 +09002862 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002863
2864 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002865}
2866
Jiyong Park6a43f042017-10-12 23:05:00 +09002867func squashVendorSrcs(m *Module) {
2868 if lib, ok := m.compiler.(*libraryDecorator); ok {
2869 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2870 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2871
2872 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2873 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2874 }
2875}
2876
Jiyong Parkf9332f12018-02-01 00:54:12 +09002877func squashRecoverySrcs(m *Module) {
2878 if lib, ok := m.compiler.(*libraryDecorator); ok {
2879 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2880 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2881
2882 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2883 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2884 }
2885}
2886
Colin Cross7228ecd2019-11-18 16:00:16 -08002887var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002888
Colin Cross7228ecd2019-11-18 16:00:16 -08002889func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002890 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002891 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002892 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002893
2894 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002895 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002896 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002897 }
Logan Chienf3511742017-10-31 18:04:35 +08002898
2899 if vndkdep := m.vndkdep; vndkdep != nil {
2900 if vndkdep.isVndk() {
Justin Yun98df0d12020-02-28 15:07:59 +09002901 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002902 if !vndkdep.isVndkExt() {
2903 mctx.PropertyErrorf("vndk",
2904 "must set `extends: \"...\"` to vndk extension")
Justin Yun98df0d12020-02-28 15:07:59 +09002905 } else if m.VendorProperties.Vendor_available != nil {
2906 mctx.PropertyErrorf("vendor_available",
2907 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002908 }
2909 } else {
2910 if vndkdep.isVndkExt() {
2911 mctx.PropertyErrorf("vndk",
Justin Yun98df0d12020-02-28 15:07:59 +09002912 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002913 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002914 }
2915 if m.VendorProperties.Vendor_available == nil {
2916 mctx.PropertyErrorf("vndk",
2917 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002918 }
2919 }
2920 } else {
2921 if vndkdep.isVndkSp() {
2922 mctx.PropertyErrorf("vndk",
2923 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002924 }
2925 if vndkdep.isVndkExt() {
2926 mctx.PropertyErrorf("vndk",
2927 "must set `enabled: true` to set `extends: %q`",
2928 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002929 }
Justin Yun8effde42017-06-23 19:24:43 +09002930 }
2931 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002932
Jiyong Parkf9332f12018-02-01 00:54:12 +09002933 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002934 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002935 var recoveryVariantNeeded bool = false
2936
Inseob Kim64c43952019-08-26 16:52:35 +09002937 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002938 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002939
2940 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002941 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2942 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2943 if boardVndkVersion == "current" {
2944 boardVndkVersion = platformVndkVersion
2945 }
2946 if productVndkVersion == "current" {
2947 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002948 }
2949
Justin Yun5f7f7e82019-11-18 19:52:14 +09002950 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002951 // If the device isn't compiling against the VNDK, we always
2952 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002953 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002954 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002955 // LL-NDK stubs only exist in the vendor and product variants,
2956 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002957 vendorVariants = append(vendorVariants,
2958 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002959 boardVndkVersion,
2960 )
2961 productVariants = append(productVariants,
2962 platformVndkVersion,
2963 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002964 )
Jiyong Park2a454122017-10-19 15:59:33 +09002965 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2966 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002967 vendorVariants = append(vendorVariants,
2968 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002969 boardVndkVersion,
2970 )
2971 productVariants = append(productVariants,
2972 platformVndkVersion,
2973 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002974 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002975 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002976 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2977 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002978 if snapshot, ok := m.linker.(interface {
2979 version() string
2980 }); ok {
2981 vendorVariants = append(vendorVariants, snapshot.version())
2982 } else {
2983 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2984 }
Justin Yun98df0d12020-02-28 15:07:59 +09002985 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002986 // This will be available in /system, /vendor and /product
2987 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002988 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002989 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002990 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002991 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2992 // code is PLATFORM_VNDK_VERSION.
2993 // On the other hand, vendor_available modules which are not VNDK should
2994 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002995 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002996 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002997 vendorVariants = append(vendorVariants, boardVndkVersion)
2998 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002999 }
Logan Chienf3511742017-10-31 18:04:35 +08003000 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09003001 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09003002 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003003 } else {
3004 // This is either in /system (or similar: /data), or is a
3005 // modules built with the NDK. Modules built with the NDK
3006 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09003007 coreVariantNeeded = true
3008 }
3009
Justin Yun5f7f7e82019-11-18 19:52:14 +09003010 if boardVndkVersion != "" && productVndkVersion != "" {
3011 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
3012 // The module has "product_specific: true" that does not create core variant.
3013 coreVariantNeeded = false
3014 productVariants = append(productVariants, productVndkVersion)
3015 }
3016 } else {
3017 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
3018 // restriction to use system libs.
3019 // No product variants defined in this case.
3020 productVariants = []string{}
3021 }
3022
Yifan Hong1b3348d2020-01-21 15:53:22 -08003023 if Bool(m.Properties.Ramdisk_available) {
3024 ramdiskVariantNeeded = true
3025 }
3026
3027 if m.ModuleBase.InstallInRamdisk() {
3028 ramdiskVariantNeeded = true
3029 coreVariantNeeded = false
3030 }
3031
Jiyong Parkf9332f12018-02-01 00:54:12 +09003032 if Bool(m.Properties.Recovery_available) {
3033 recoveryVariantNeeded = true
3034 }
3035
3036 if m.ModuleBase.InstallInRecovery() {
3037 recoveryVariantNeeded = true
3038 coreVariantNeeded = false
3039 }
3040
Inseob Kim64c43952019-08-26 16:52:35 +09003041 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003042 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3043 }
3044
3045 for _, variant := range android.FirstUniqueStrings(productVariants) {
3046 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003047 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003048
Yifan Hong1b3348d2020-01-21 15:53:22 -08003049 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003050 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3051 m.Properties.CoreVariantNeeded = coreVariantNeeded
3052}
3053
3054func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3055 return c.Properties.CoreVariantNeeded
3056}
3057
Yifan Hong1b3348d2020-01-21 15:53:22 -08003058func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3059 return c.Properties.RamdiskVariantNeeded
3060}
3061
Colin Cross7228ecd2019-11-18 16:00:16 -08003062func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3063 return c.Properties.RecoveryVariantNeeded
3064}
3065
3066func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003067 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003068}
3069
3070func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3071 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003072 if variant == android.RamdiskVariation {
3073 m.MakeAsPlatform()
3074 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003075 m.MakeAsPlatform()
3076 squashRecoverySrcs(m)
3077 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003078 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003079 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3080 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003081
3082 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3083 // Hide other vendor variants to avoid collision.
3084 vndkVersion := ctx.DeviceConfig().VndkVersion()
3085 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3086 m.Properties.HideFromMake = true
3087 m.SkipInstall()
3088 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003089 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3090 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3091 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3092 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003093 }
3094}
3095
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003096func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003097 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003098 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3099 }
Colin Cross6510f912017-11-29 00:27:14 -08003100 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003101}
3102
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003103func kytheExtractAllFactory() android.Singleton {
3104 return &kytheExtractAllSingleton{}
3105}
3106
3107type kytheExtractAllSingleton struct {
3108}
3109
3110func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3111 var xrefTargets android.Paths
3112 ctx.VisitAllModules(func(module android.Module) {
3113 if ccModule, ok := module.(xref); ok {
3114 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3115 }
3116 })
3117 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3118 if len(xrefTargets) > 0 {
3119 ctx.Build(pctx, android.BuildParams{
3120 Rule: blueprint.Phony,
3121 Output: android.PathForPhony(ctx, "xref_cxx"),
3122 Inputs: xrefTargets,
3123 //Default: true,
3124 })
3125 }
3126}
3127
Colin Cross06a931b2015-10-28 17:23:31 -07003128var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003129var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003130var BoolPtr = proptools.BoolPtr
3131var String = proptools.String
3132var StringPtr = proptools.StringPtr