blob: c7639bfa8c6209e49558d13de68f2977b9697077 [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
Colin Crossb98c8b02016-07-29 13:44:28 -0700184 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700185 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800186 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800187 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800188 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
Jiyong Parkde866cb2018-12-07 23:08:36 +0900214 AndroidMkSharedLibs []string `blueprint:"mutated"`
215 AndroidMkStaticLibs []string `blueprint:"mutated"`
216 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
217 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
218 HideFromMake bool `blueprint:"mutated"`
219 PreventInstall bool `blueprint:"mutated"`
220 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700221
Justin Yun5f7f7e82019-11-18 19:52:14 +0900222 ImageVariationPrefix string `blueprint:"mutated"`
223 VndkVersion string `blueprint:"mutated"`
224 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800225
226 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
227 // file
228 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900229
Yifan Hong1b3348d2020-01-21 15:53:22 -0800230 // Make this module available when building for ramdisk
231 Ramdisk_available *bool
232
Jiyong Parkf9332f12018-02-01 00:54:12 +0900233 // Make this module available when building for recovery
234 Recovery_available *bool
235
Colin Crossae6c5202019-11-20 13:35:50 -0800236 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800237 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800238 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800239 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900240 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900241
242 // Allows this module to use non-APEX version of libraries. Useful
243 // for building binaries that are started before APEXes are activated.
244 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900245
246 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
247 // see soong/cc/config/vndk.go
248 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900249
250 // Used by vendor snapshot to record dependencies from snapshot modules.
251 SnapshotSharedLibs []string `blueprint:"mutated"`
252 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700253}
254
255type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900256 // whether this module should be allowed to be directly depended by other
257 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900258 // In addition, this module should be allowed to be directly depended by
259 // product modules with `product_specific: true`.
260 // If set to true, three variants will be built separately, one like
261 // normal, another limited to the set of libraries and headers
262 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700263 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900264 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700265 // so it shouldn't have any unversioned runtime dependencies, or
266 // make assumptions about the system that may not be true in the
267 // future.
268 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900269 // If set to false, this module becomes inaccessible from /vendor or /product
270 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900271 //
272 // Default value is true when vndk: {enabled: true} or vendor: true.
273 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700274 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900275 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700276 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900277
278 // whether this module is capable of being loaded with other instance
279 // (possibly an older version) of the same module in the same process.
280 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
281 // can be double loaded in a vendor process if the library is also a
282 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
283 // explicitly marked as `double_loadable: true` by the owner, or the dependency
284 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
285 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800286}
287
Colin Crossca860ac2016-01-04 14:34:37 -0800288type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800289 static() bool
290 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900291 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700292 toolchain() config.Toolchain
Jooyung Han61c41542020-03-07 03:45:53 +0900293 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700294 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800295 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700296 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800297 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900298 isLlndk(config android.Config) bool
299 isLlndkPublic(config android.Config) bool
300 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900301 isVndk() bool
302 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800303 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900304 inProduct() bool
305 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800306 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900307 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800308 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700309 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700310 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800311 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800312 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800313 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800314 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800315 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900316 apexName() string
Jooyung Han61c41542020-03-07 03:45:53 +0900317 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900318 hasStubsVariants() bool
319 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900320 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800321 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700322 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
325type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700326 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800327 ModuleContextIntf
328}
329
330type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700331 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800332 ModuleContextIntf
333}
334
Colin Cross37047f12016-12-13 17:06:13 -0800335type DepsContext interface {
336 android.BottomUpMutatorContext
337 ModuleContextIntf
338}
339
Colin Crossca860ac2016-01-04 14:34:37 -0800340type feature interface {
341 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800342 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800343 flags(ctx ModuleContext, flags Flags) Flags
344 props() []interface{}
345}
346
347type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700348 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800349 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800350 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700351 compilerProps() []interface{}
352
Colin Cross76fada02016-07-27 10:31:13 -0700353 appendCflags([]string)
354 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700355 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800356}
357
358type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700359 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800360 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700361 linkerFlags(ctx ModuleContext, flags Flags) Flags
362 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800363 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700364
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700365 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700366 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900367 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700368
369 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900370 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800371}
372
373type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700374 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700375 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800376 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700377 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700378 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900379 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800380}
381
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800382type xref interface {
383 XrefCcFiles() android.Paths
384}
385
Colin Crossc99deeb2016-04-11 15:06:20 -0700386var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700387 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
388 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
389 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
390 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
391 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800392 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700393 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
394 headerDepTag = DependencyTag{Name: "header", Library: true}
395 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
396 genSourceDepTag = DependencyTag{Name: "gen source"}
397 genHeaderDepTag = DependencyTag{Name: "gen header"}
398 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
399 objDepTag = DependencyTag{Name: "obj"}
400 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
401 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
402 reuseObjTag = DependencyTag{Name: "reuse objects"}
403 staticVariantTag = DependencyTag{Name: "static variant"}
404 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
405 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
406 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
407 runtimeDepTag = DependencyTag{Name: "runtime lib"}
408 coverageDepTag = DependencyTag{Name: "coverage"}
409 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700410)
411
Roland Levillainf89cd092019-07-29 16:22:59 +0100412func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700413 ccDepTag, ok := depTag.(DependencyTag)
414 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100415}
416
417func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700418 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100419 return ok && ccDepTag == runtimeDepTag
420}
421
422func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700423 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100424 return ok && ccDepTag == testPerSrcDepTag
425}
426
Colin Crossca860ac2016-01-04 14:34:37 -0800427// Module contains the properties and members used by all C/C++ module types, and implements
428// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
429// to construct the output file. Behavior can be customized with a Customizer interface
430type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700431 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700432 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900433 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900434 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700435
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700436 Properties BaseProperties
437 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700438
Colin Crossca860ac2016-01-04 14:34:37 -0800439 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700440 hod android.HostOrDeviceSupported
441 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700442
Paul Duffina0843f62019-12-13 19:50:38 +0000443 // Allowable SdkMemberTypes of this module type.
444 sdkMemberTypes []android.SdkMemberType
445
Colin Crossca860ac2016-01-04 14:34:37 -0800446 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700447 features []feature
448 compiler compiler
449 linker linker
450 installer installer
451 stl *stl
452 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800453 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800454 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900455 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700456 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700457 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800458
Colin Cross635c3b02016-05-18 15:37:25 -0700459 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800460
Colin Crossb98c8b02016-07-29 13:44:28 -0700461 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700462
463 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800464
465 // Flags used to compile this module
466 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700467
468 // 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 -0800469 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700470 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800471 depsInLinkOrder android.Paths
472
473 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700474 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900475
476 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800477 // Kythe (source file indexer) paths for this compilation module
478 kytheFiles android.Paths
Jooyung Han74066602020-03-20 04:29:24 +0900479
480 // For apex variants, this is set as apex.min_sdk_version
481 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700482}
483
Ivan Lozano52767be2019-10-18 14:49:46 -0700484func (c *Module) Toc() android.OptionalPath {
485 if c.linker != nil {
486 if library, ok := c.linker.(libraryInterface); ok {
487 return library.toc()
488 }
489 }
490 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
491}
492
493func (c *Module) ApiLevel() string {
494 if c.linker != nil {
495 if stub, ok := c.linker.(*stubDecorator); ok {
496 return stub.properties.ApiLevel
497 }
498 }
499 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
500}
501
502func (c *Module) Static() bool {
503 if c.linker != nil {
504 if library, ok := c.linker.(libraryInterface); ok {
505 return library.static()
506 }
507 }
508 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
509}
510
511func (c *Module) Shared() bool {
512 if c.linker != nil {
513 if library, ok := c.linker.(libraryInterface); ok {
514 return library.shared()
515 }
516 }
517 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
518}
519
520func (c *Module) SelectedStl() string {
521 return c.stl.Properties.SelectedStl
522}
523
524func (c *Module) ToolchainLibrary() bool {
525 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
526 return true
527 }
528 return false
529}
530
531func (c *Module) NdkPrebuiltStl() bool {
532 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
533 return true
534 }
535 return false
536}
537
538func (c *Module) StubDecorator() bool {
539 if _, ok := c.linker.(*stubDecorator); ok {
540 return true
541 }
542 return false
543}
544
545func (c *Module) SdkVersion() string {
546 return String(c.Properties.Sdk_version)
547}
548
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800549func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700550 if c.linker != nil {
551 if library, ok := c.linker.(exportedFlagsProducer); ok {
552 return library.exportedDirs()
553 }
554 }
555 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
556}
557
558func (c *Module) HasStaticVariant() bool {
559 if c.staticVariant != nil {
560 return true
561 }
562 return false
563}
564
565func (c *Module) GetStaticVariant() LinkableInterface {
566 return c.staticVariant
567}
568
569func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
570 c.depsInLinkOrder = depsInLinkOrder
571}
572
573func (c *Module) GetDepsInLinkOrder() []android.Path {
574 return c.depsInLinkOrder
575}
576
577func (c *Module) StubsVersions() []string {
578 if c.linker != nil {
579 if library, ok := c.linker.(*libraryDecorator); ok {
580 return library.Properties.Stubs.Versions
581 }
582 }
583 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
584}
585
586func (c *Module) CcLibrary() bool {
587 if c.linker != nil {
588 if _, ok := c.linker.(*libraryDecorator); ok {
589 return true
590 }
591 }
592 return false
593}
594
595func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700596 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700597 return true
598 }
599 return false
600}
601
Ivan Lozano2b262972019-11-21 12:30:50 -0800602func (c *Module) NonCcVariants() bool {
603 return false
604}
605
Ivan Lozano183a3212019-10-18 14:18:45 -0700606func (c *Module) SetBuildStubs() {
607 if c.linker != nil {
608 if library, ok := c.linker.(*libraryDecorator); ok {
609 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700610 c.Properties.HideFromMake = true
611 c.sanitize = nil
612 c.stl = nil
613 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700614 return
615 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900616 if _, ok := c.linker.(*llndkStubDecorator); ok {
617 c.Properties.HideFromMake = true
618 return
619 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700620 }
621 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
622}
623
Ivan Lozano52767be2019-10-18 14:49:46 -0700624func (c *Module) BuildStubs() bool {
625 if c.linker != nil {
626 if library, ok := c.linker.(*libraryDecorator); ok {
627 return library.buildStubs()
628 }
629 }
630 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
631}
632
Ivan Lozano183a3212019-10-18 14:18:45 -0700633func (c *Module) SetStubsVersions(version string) {
634 if c.linker != nil {
635 if library, ok := c.linker.(*libraryDecorator); ok {
636 library.MutatedProperties.StubsVersion = version
637 return
638 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900639 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
640 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
641 return
642 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700643 }
644 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
645}
646
Jooyung Han0c4e0162020-02-26 22:45:42 +0900647func (c *Module) StubsVersion() string {
648 if c.linker != nil {
649 if library, ok := c.linker.(*libraryDecorator); ok {
650 return library.MutatedProperties.StubsVersion
651 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900652 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
653 return llndk.libraryDecorator.MutatedProperties.StubsVersion
654 }
Jooyung Han0c4e0162020-02-26 22:45:42 +0900655 }
656 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
657}
658
Ivan Lozano183a3212019-10-18 14:18:45 -0700659func (c *Module) SetStatic() {
660 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700661 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700662 library.setStatic()
663 return
664 }
665 }
666 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
667}
668
669func (c *Module) SetShared() {
670 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700671 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700672 library.setShared()
673 return
674 }
675 }
676 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
677}
678
679func (c *Module) BuildStaticVariant() bool {
680 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700681 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700682 return library.buildStatic()
683 }
684 }
685 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
686}
687
688func (c *Module) BuildSharedVariant() bool {
689 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700690 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700691 return library.buildShared()
692 }
693 }
694 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
695}
696
697func (c *Module) Module() android.Module {
698 return c
699}
700
Jiyong Parkc20eee32018-09-05 22:36:17 +0900701func (c *Module) OutputFile() android.OptionalPath {
702 return c.outputFile
703}
704
Ivan Lozano183a3212019-10-18 14:18:45 -0700705var _ LinkableInterface = (*Module)(nil)
706
Jiyong Park719b4462019-01-13 00:39:51 +0900707func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900708 if c.linker != nil {
709 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900710 }
711 return nil
712}
713
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900714func (c *Module) CoverageOutputFile() android.OptionalPath {
715 if c.linker != nil {
716 return c.linker.coverageOutputFilePath()
717 }
718 return android.OptionalPath{}
719}
720
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900721func (c *Module) RelativeInstallPath() string {
722 if c.installer != nil {
723 return c.installer.relativeInstallPath()
724 }
725 return ""
726}
727
Jooyung Han344d5432019-08-23 11:17:39 +0900728func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900729 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900730}
731
Colin Cross36242852017-06-23 15:06:31 -0700732func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700733 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800734 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700735 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800736 }
737 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700738 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800739 }
740 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700741 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800742 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700743 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700744 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700745 }
Colin Cross16b23492016-01-06 14:41:07 -0800746 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700747 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800748 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800749 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700750 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800751 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800752 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700753 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800754 }
Justin Yun8effde42017-06-23 19:24:43 +0900755 if c.vndkdep != nil {
756 c.AddProperties(c.vndkdep.props()...)
757 }
Stephen Craneba090d12017-05-09 15:44:35 -0700758 if c.lto != nil {
759 c.AddProperties(c.lto.props()...)
760 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700761 if c.pgo != nil {
762 c.AddProperties(c.pgo.props()...)
763 }
Colin Crossca860ac2016-01-04 14:34:37 -0800764 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700765 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800766 }
Colin Crossc472d572015-03-17 15:06:21 -0700767
Colin Crossa9d8bee2018-10-02 13:59:46 -0700768 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
769 switch class {
770 case android.Device:
771 return ctx.Config().DevicePrefer32BitExecutables()
772 case android.HostCross:
773 // Windows builds always prefer 32-bit
774 return true
775 default:
776 return false
777 }
778 })
Colin Cross36242852017-06-23 15:06:31 -0700779 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900780 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900781 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900782 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900783
Colin Cross36242852017-06-23 15:06:31 -0700784 return c
Colin Crossc472d572015-03-17 15:06:21 -0700785}
786
Colin Crossb916a382016-07-29 17:28:03 -0700787// Returns true for dependency roots (binaries)
788// TODO(ccross): also handle dlopenable libraries
789func (c *Module) isDependencyRoot() bool {
790 if root, ok := c.linker.(interface {
791 isDependencyRoot() bool
792 }); ok {
793 return root.isDependencyRoot()
794 }
795 return false
796}
797
Justin Yun5f7f7e82019-11-18 19:52:14 +0900798// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
799// "product" and "vendor" variant modules return true for this function.
800// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
801// "soc_specific: true" and more vendor installed modules are included here.
802// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
803// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700804func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900805 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700806}
807
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800808func (c *Module) isCoverageVariant() bool {
809 return c.coverage.Properties.IsCoverageVariant
810}
811
Peter Collingbournead84f972019-12-17 16:46:18 -0800812func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800813 return inList(c.Name(), ndkMigratedLibs)
814}
815
Inseob Kim9516ee92019-05-09 10:56:13 +0900816func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800817 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900818 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800819}
820
Inseob Kim9516ee92019-05-09 10:56:13 +0900821func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800822 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900823 name := c.BaseModuleName()
824 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800825}
826
Inseob Kim9516ee92019-05-09 10:56:13 +0900827func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800828 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900829 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800830}
831
Ivan Lozano52767be2019-10-18 14:49:46 -0700832func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800833 if vndkdep := c.vndkdep; vndkdep != nil {
834 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900835 }
836 return false
837}
838
Yi Kong7e53c572018-02-14 18:16:12 +0800839func (c *Module) isPgoCompile() bool {
840 if pgo := c.pgo; pgo != nil {
841 return pgo.Properties.PgoCompile
842 }
843 return false
844}
845
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800846func (c *Module) isNDKStubLibrary() bool {
847 if _, ok := c.compiler.(*stubDecorator); ok {
848 return true
849 }
850 return false
851}
852
Logan Chienf3511742017-10-31 18:04:35 +0800853func (c *Module) isVndkSp() bool {
854 if vndkdep := c.vndkdep; vndkdep != nil {
855 return vndkdep.isVndkSp()
856 }
857 return false
858}
859
860func (c *Module) isVndkExt() bool {
861 if vndkdep := c.vndkdep; vndkdep != nil {
862 return vndkdep.isVndkExt()
863 }
864 return false
865}
866
Ivan Lozano52767be2019-10-18 14:49:46 -0700867func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900868 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800869}
870
Logan Chienf3511742017-10-31 18:04:35 +0800871func (c *Module) getVndkExtendsModuleName() string {
872 if vndkdep := c.vndkdep; vndkdep != nil {
873 return vndkdep.getVndkExtendsModuleName()
874 }
875 return ""
876}
877
Justin Yun5f7f7e82019-11-18 19:52:14 +0900878// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900879// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700880func (c *Module) HasVendorVariant() bool {
881 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900882}
883
Justin Yun5f7f7e82019-11-18 19:52:14 +0900884const (
885 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
886 // against the VNDK.
887 VendorVariationPrefix = "vendor."
888
889 // ProductVariationPrefix is the variant prefix used for /product code that compiles
890 // against the VNDK.
891 ProductVariationPrefix = "product."
892)
893
894// Returns true if the module is "product" variant. Usually these modules are installed in /product
895func (c *Module) inProduct() bool {
896 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
897}
898
899// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
900func (c *Module) inVendor() bool {
901 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
902}
903
Yifan Hong1b3348d2020-01-21 15:53:22 -0800904func (c *Module) InRamdisk() bool {
905 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
906}
907
Ivan Lozano52767be2019-10-18 14:49:46 -0700908func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800909 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900910}
911
Yifan Hong1b3348d2020-01-21 15:53:22 -0800912func (c *Module) OnlyInRamdisk() bool {
913 return c.ModuleBase.InstallInRamdisk()
914}
915
Ivan Lozano52767be2019-10-18 14:49:46 -0700916func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900917 return c.ModuleBase.InstallInRecovery()
918}
919
Jiyong Park25fc6a92018-11-18 18:02:45 +0900920func (c *Module) IsStubs() bool {
921 if library, ok := c.linker.(*libraryDecorator); ok {
922 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900923 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
924 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900925 }
926 return false
927}
928
929func (c *Module) HasStubsVariants() bool {
930 if library, ok := c.linker.(*libraryDecorator); ok {
931 return len(library.Properties.Stubs.Versions) > 0
932 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700933 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
934 return len(library.Properties.Stubs.Versions) > 0
935 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900936 return false
937}
938
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900939func (c *Module) bootstrap() bool {
940 return Bool(c.Properties.Bootstrap)
941}
942
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700943func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700944 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
945 if c.Target().NativeBridge == android.NativeBridgeEnabled {
946 return false
947 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700948 return c.linker != nil && c.linker.nativeCoverage()
949}
950
Inseob Kim8471cda2019-11-15 09:59:12 +0900951func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900952 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
953 return true
954 }
955 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
956 return true
957 }
958 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
959 return true
960 }
961 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900962}
963
Jiyong Park73c54ee2019-10-22 20:31:18 +0900964func (c *Module) ExportedIncludeDirs() android.Paths {
965 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
966 return flagsProducer.exportedDirs()
967 }
Jiyong Park232e7852019-11-04 12:23:40 +0900968 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900969}
970
971func (c *Module) ExportedSystemIncludeDirs() android.Paths {
972 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
973 return flagsProducer.exportedSystemDirs()
974 }
Jiyong Park232e7852019-11-04 12:23:40 +0900975 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900976}
977
978func (c *Module) ExportedFlags() []string {
979 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
980 return flagsProducer.exportedFlags()
981 }
Jiyong Park232e7852019-11-04 12:23:40 +0900982 return nil
983}
984
985func (c *Module) ExportedDeps() android.Paths {
986 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
987 return flagsProducer.exportedDeps()
988 }
989 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900990}
991
Inseob Kimd110f872019-12-06 13:15:38 +0900992func (c *Module) ExportedGeneratedHeaders() android.Paths {
993 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
994 return flagsProducer.exportedGeneratedHeaders()
995 }
996 return nil
997}
998
Jiyong Parkf1194352019-02-25 11:05:47 +0900999func isBionic(name string) bool {
1000 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001001 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001002 return true
1003 }
1004 return false
1005}
1006
Martin Stjernholm279de572019-09-10 23:18:20 +01001007func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001008 if name == "libclang_rt.hwasan-aarch64-android" {
1009 return inList("hwaddress", config.SanitizeDevice())
1010 }
1011 return isBionic(name)
1012}
1013
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001014func (c *Module) XrefCcFiles() android.Paths {
1015 return c.kytheFiles
1016}
1017
Colin Crossca860ac2016-01-04 14:34:37 -08001018type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001019 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001020 moduleContextImpl
1021}
1022
Colin Cross37047f12016-12-13 17:06:13 -08001023type depsContext struct {
1024 android.BottomUpMutatorContext
1025 moduleContextImpl
1026}
1027
Colin Crossca860ac2016-01-04 14:34:37 -08001028type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001029 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001030 moduleContextImpl
1031}
1032
Justin Yun5f7f7e82019-11-18 19:52:14 +09001033func (ctx *moduleContext) ProductSpecific() bool {
1034 return ctx.ModuleContext.ProductSpecific() ||
1035 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1036}
1037
Jiyong Park2db76922017-11-08 16:03:48 +09001038func (ctx *moduleContext) SocSpecific() bool {
1039 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001040 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001041}
1042
Colin Crossca860ac2016-01-04 14:34:37 -08001043type moduleContextImpl struct {
1044 mod *Module
1045 ctx BaseModuleContext
1046}
1047
Colin Crossb98c8b02016-07-29 13:44:28 -07001048func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001049 return ctx.mod.toolchain(ctx.ctx)
1050}
1051
1052func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001053 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001054}
1055
1056func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001057 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001058}
1059
Jiyong Park1d1119f2019-07-29 21:27:18 +09001060func (ctx *moduleContextImpl) header() bool {
1061 return ctx.mod.header()
1062}
1063
Jooyung Han61c41542020-03-07 03:45:53 +09001064func (ctx *moduleContextImpl) canUseSdk() bool {
1065 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1066}
1067
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001068func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Han61c41542020-03-07 03:45:53 +09001069 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001070 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001071 }
1072 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001073}
1074
1075func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001076 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001077 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001078 vndkVer := ctx.mod.VndkVersion()
Jooyung Han424175d2020-04-08 09:22:26 +09001079 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001080 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001081 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001082 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001083 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001084 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001085 }
1086 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001087}
1088
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001090 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001091}
Justin Yun8effde42017-06-23 19:24:43 +09001092
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001093func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001094 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001095}
1096
Inseob Kim9516ee92019-05-09 10:56:13 +09001097func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1098 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001099}
1100
Inseob Kim9516ee92019-05-09 10:56:13 +09001101func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1102 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001103}
1104
Inseob Kim9516ee92019-05-09 10:56:13 +09001105func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1106 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001107}
1108
Logan Chienf3511742017-10-31 18:04:35 +08001109func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001110 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001111}
1112
Yi Kong7e53c572018-02-14 18:16:12 +08001113func (ctx *moduleContextImpl) isPgoCompile() bool {
1114 return ctx.mod.isPgoCompile()
1115}
1116
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001117func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1118 return ctx.mod.isNDKStubLibrary()
1119}
1120
Justin Yun8effde42017-06-23 19:24:43 +09001121func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001122 return ctx.mod.isVndkSp()
1123}
1124
1125func (ctx *moduleContextImpl) isVndkExt() bool {
1126 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001127}
1128
Vic Yangefd249e2018-11-12 20:19:56 -08001129func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001130 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001131}
1132
Justin Yun5f7f7e82019-11-18 19:52:14 +09001133func (ctx *moduleContextImpl) inProduct() bool {
1134 return ctx.mod.inProduct()
1135}
1136
1137func (ctx *moduleContextImpl) inVendor() bool {
1138 return ctx.mod.inVendor()
1139}
1140
Yifan Hong1b3348d2020-01-21 15:53:22 -08001141func (ctx *moduleContextImpl) inRamdisk() bool {
1142 return ctx.mod.InRamdisk()
1143}
1144
Jiyong Parkf9332f12018-02-01 00:54:12 +09001145func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001146 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001147}
1148
Logan Chien2f2b8902018-07-10 15:01:19 +08001149// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001150func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001151 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1152 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001153 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001154
1155 if ctx.ctx.Fuchsia() {
1156 return false
1157 }
1158
Logan Chien2f2b8902018-07-10 15:01:19 +08001159 if sanitize := ctx.mod.sanitize; sanitize != nil {
1160 if !sanitize.isVariantOnProductionDevice() {
1161 return false
1162 }
1163 }
1164 if !ctx.ctx.Device() {
1165 // Host modules do not need ABI dumps.
1166 return false
1167 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001168 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001169 // Stubs do not need ABI dumps.
1170 return false
1171 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001172 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001173}
1174
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001175func (ctx *moduleContextImpl) selectedStl() string {
1176 if stl := ctx.mod.stl; stl != nil {
1177 return stl.Properties.SelectedStl
1178 }
1179 return ""
1180}
1181
Ivan Lozanobd721262018-11-27 14:33:03 -08001182func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1183 return ctx.mod.linker.useClangLld(actx)
1184}
1185
Colin Crossce75d2c2016-10-06 16:12:58 -07001186func (ctx *moduleContextImpl) baseModuleName() string {
1187 return ctx.mod.ModuleBase.BaseModuleName()
1188}
1189
Logan Chienf3511742017-10-31 18:04:35 +08001190func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1191 return ctx.mod.getVndkExtendsModuleName()
1192}
1193
Logan Chiene274fc92019-12-03 11:18:32 -08001194func (ctx *moduleContextImpl) isForPlatform() bool {
1195 return ctx.mod.IsForPlatform()
1196}
1197
Jiyong Park58e364a2019-01-19 19:24:06 +09001198func (ctx *moduleContextImpl) apexName() string {
1199 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001200}
1201
Jooyung Han61c41542020-03-07 03:45:53 +09001202func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han74066602020-03-20 04:29:24 +09001203 return ctx.mod.apexSdkVersion
Jooyung Han61c41542020-03-07 03:45:53 +09001204}
1205
Jiyong Parkb0788572018-12-20 22:10:17 +09001206func (ctx *moduleContextImpl) hasStubsVariants() bool {
1207 return ctx.mod.HasStubsVariants()
1208}
1209
1210func (ctx *moduleContextImpl) isStubs() bool {
1211 return ctx.mod.IsStubs()
1212}
1213
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001214func (ctx *moduleContextImpl) bootstrap() bool {
1215 return ctx.mod.bootstrap()
1216}
1217
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001218func (ctx *moduleContextImpl) nativeCoverage() bool {
1219 return ctx.mod.nativeCoverage()
1220}
1221
Colin Cross635c3b02016-05-18 15:37:25 -07001222func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001223 return &Module{
1224 hod: hod,
1225 multilib: multilib,
1226 }
1227}
1228
Colin Cross635c3b02016-05-18 15:37:25 -07001229func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001230 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001231 module.features = []feature{
1232 &tidyFeature{},
1233 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001234 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001235 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001236 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001237 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001238 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001239 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001240 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001241 return module
1242}
1243
Colin Crossce75d2c2016-10-06 16:12:58 -07001244func (c *Module) Prebuilt() *android.Prebuilt {
1245 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1246 return p.prebuilt()
1247 }
1248 return nil
1249}
1250
1251func (c *Module) Name() string {
1252 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001253 if p, ok := c.linker.(interface {
1254 Name(string) string
1255 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001256 name = p.Name(name)
1257 }
1258 return name
1259}
1260
Alex Light3d673592019-01-18 14:37:31 -08001261func (c *Module) Symlinks() []string {
1262 if p, ok := c.installer.(interface {
1263 symlinkList() []string
1264 }); ok {
1265 return p.symlinkList()
1266 }
1267 return nil
1268}
1269
Jeff Gaston294356f2017-09-27 17:05:30 -07001270// orderDeps reorders dependencies into a list such that if module A depends on B, then
1271// A will precede B in the resultant list.
1272// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001273// Note that directSharedDeps should be the analogous static library for each shared lib dep
1274func 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 -07001275 // If A depends on B, then
1276 // Every list containing A will also contain B later in the list
1277 // So, after concatenating all lists, the final instance of B will have come from the same
1278 // original list as the final instance of A
1279 // So, the final instance of B will be later in the concatenation than the final A
1280 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1281 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001282 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001283 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001284 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1285 }
1286 for _, dep := range directSharedDeps {
1287 orderedAllDeps = append(orderedAllDeps, dep)
1288 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001289 }
1290
Colin Crossb6715442017-10-24 11:13:31 -07001291 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001292
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001293 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001294 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001295 // resultant list to only what the caller has chosen to include in directStaticDeps
1296 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001297
1298 return orderedAllDeps, orderedDeclaredDeps
1299}
1300
Ivan Lozano183a3212019-10-18 14:18:45 -07001301func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001302 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001303 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001304 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1305 staticDepFiles := []android.Path{}
1306 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001307 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1308 if dep.OutputFile().Valid() {
1309 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1310 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1311 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001312 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001313 sharedDepFiles := []android.Path{}
1314 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001315 if sharedDep.HasStaticVariant() {
1316 staticAnalogue := sharedDep.GetStaticVariant()
1317 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1318 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001319 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001320 }
1321
1322 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001323 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1324 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001325
1326 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001327}
1328
Roland Levillainf89cd092019-07-29 16:22:59 +01001329func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1330 test, ok := c.linker.(testPerSrc)
1331 return ok && test.isAllTestsVariation()
1332}
1333
Justin Yun5f7f7e82019-11-18 19:52:14 +09001334func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1335 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1336 // "current", it will append the VNDK version to the name suffix.
1337 var vndkVersion string
1338 var nameSuffix string
1339 if c.inProduct() {
1340 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1341 nameSuffix = productSuffix
1342 } else {
1343 vndkVersion = ctx.DeviceConfig().VndkVersion()
1344 nameSuffix = vendorSuffix
1345 }
1346 if vndkVersion == "current" {
1347 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1348 }
1349 if c.Properties.VndkVersion != vndkVersion {
1350 // add version suffix only if the module is using different vndk version than the
1351 // version in product or vendor partition.
1352 nameSuffix += "." + c.Properties.VndkVersion
1353 }
1354 return nameSuffix
1355}
1356
Colin Cross635c3b02016-05-18 15:37:25 -07001357func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001358 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001359 //
1360 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1361 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1362 // module and return early, as this module does not produce an output file per se.
1363 if c.IsTestPerSrcAllTestsVariation() {
1364 c.outputFile = android.OptionalPath{}
1365 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001366 }
1367
Jooyung Han38002912019-05-16 04:01:54 +09001368 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001369
Inseob Kim64c43952019-08-26 16:52:35 +09001370 c.Properties.SubName = ""
1371
1372 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1373 c.Properties.SubName += nativeBridgeSuffix
1374 }
1375
Justin Yun5f7f7e82019-11-18 19:52:14 +09001376 _, llndk := c.linker.(*llndkStubDecorator)
1377 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1378 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1379 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1380 // added for product variant only when we have vendor and product variants with core
1381 // variant. The suffix is not added for vendor-only or product-only module.
1382 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1383 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001384 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1385 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1386 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001387 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1388 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001389 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001390 c.Properties.SubName += recoverySuffix
1391 }
1392
Colin Crossca860ac2016-01-04 14:34:37 -08001393 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001394 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001395 moduleContextImpl: moduleContextImpl{
1396 mod: c,
1397 },
1398 }
1399 ctx.ctx = ctx
1400
Colin Crossf18e1102017-11-16 14:33:08 -08001401 deps := c.depsToPaths(ctx)
1402 if ctx.Failed() {
1403 return
1404 }
1405
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001406 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1407 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1408 }
1409
Colin Crossca860ac2016-01-04 14:34:37 -08001410 flags := Flags{
1411 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001412 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001413 }
Colin Crossca860ac2016-01-04 14:34:37 -08001414 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001415 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001416 }
1417 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001418 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001419 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001420 if c.stl != nil {
1421 flags = c.stl.flags(ctx, flags)
1422 }
Colin Cross16b23492016-01-06 14:41:07 -08001423 if c.sanitize != nil {
1424 flags = c.sanitize.flags(ctx, flags)
1425 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001426 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001427 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001428 }
Stephen Craneba090d12017-05-09 15:44:35 -07001429 if c.lto != nil {
1430 flags = c.lto.flags(ctx, flags)
1431 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001432 if c.pgo != nil {
1433 flags = c.pgo.flags(ctx, flags)
1434 }
Colin Crossca860ac2016-01-04 14:34:37 -08001435 for _, feature := range c.features {
1436 flags = feature.flags(ctx, flags)
1437 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001438 if ctx.Failed() {
1439 return
1440 }
1441
Colin Cross4af21ed2019-11-04 09:37:55 -08001442 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1443 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1444 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001445
Colin Cross4af21ed2019-11-04 09:37:55 -08001446 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001447
1448 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001449 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001450 }
1451 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001452 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001453 }
1454
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001455 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001456 // We need access to all the flags seen by a source file.
1457 if c.sabi != nil {
1458 flags = c.sabi.flags(ctx, flags)
1459 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001460
Colin Cross4af21ed2019-11-04 09:37:55 -08001461 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001462
Colin Crossca860ac2016-01-04 14:34:37 -08001463 // Optimization to reduce size of build.ninja
1464 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001465 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1466 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1467 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1468 flags.Local.CFlags = []string{"$cflags"}
1469 flags.Local.CppFlags = []string{"$cppflags"}
1470 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001471
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001472 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001473 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001474 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001475 if ctx.Failed() {
1476 return
1477 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001478 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001479 }
1480
Colin Crossca860ac2016-01-04 14:34:37 -08001481 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001482 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001483 if ctx.Failed() {
1484 return
1485 }
Colin Cross635c3b02016-05-18 15:37:25 -07001486 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001487
1488 // If a lib is directly included in any of the APEXes, unhide the stubs
1489 // variant having the latest version gets visible to make. In addition,
1490 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1491 // force anything in the make world to link against the stubs library.
1492 // (unless it is explicitly referenced via .bootstrap suffix or the
1493 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001494 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001495 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001496 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001497 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001498 c.Properties.HideFromMake = false // unhide
1499 // Note: this is still non-installable
1500 }
Inseob Kimac775b22020-03-03 22:06:32 +09001501
1502 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1503 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1504 if isSnapshotAware(ctx, c) {
1505 i.collectHeadersForSnapshot(ctx)
1506 }
1507 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001508 }
Colin Cross5049f022015-03-18 13:28:46 -07001509
Inseob Kim1f086e22019-05-09 13:29:15 +09001510 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001511 c.installer.install(ctx, c.outputFile.Path())
1512 if ctx.Failed() {
1513 return
Colin Crossca860ac2016-01-04 14:34:37 -08001514 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001515 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001516}
1517
Colin Cross0ea8ba82019-06-06 14:33:29 -07001518func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001519 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001520 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001521 }
Colin Crossca860ac2016-01-04 14:34:37 -08001522 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001523}
1524
Colin Crossca860ac2016-01-04 14:34:37 -08001525func (c *Module) begin(ctx BaseModuleContext) {
1526 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001527 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001528 }
Colin Crossca860ac2016-01-04 14:34:37 -08001529 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001530 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001531 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001532 if c.stl != nil {
1533 c.stl.begin(ctx)
1534 }
Colin Cross16b23492016-01-06 14:41:07 -08001535 if c.sanitize != nil {
1536 c.sanitize.begin(ctx)
1537 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001538 if c.coverage != nil {
1539 c.coverage.begin(ctx)
1540 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001541 if c.sabi != nil {
1542 c.sabi.begin(ctx)
1543 }
Justin Yun8effde42017-06-23 19:24:43 +09001544 if c.vndkdep != nil {
1545 c.vndkdep.begin(ctx)
1546 }
Stephen Craneba090d12017-05-09 15:44:35 -07001547 if c.lto != nil {
1548 c.lto.begin(ctx)
1549 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001550 if c.pgo != nil {
1551 c.pgo.begin(ctx)
1552 }
Colin Crossca860ac2016-01-04 14:34:37 -08001553 for _, feature := range c.features {
1554 feature.begin(ctx)
1555 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001556 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001557 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001558 if err != nil {
1559 ctx.PropertyErrorf("sdk_version", err.Error())
1560 }
Nan Zhang0007d812017-11-07 10:57:05 -08001561 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001562 }
Colin Crossca860ac2016-01-04 14:34:37 -08001563}
1564
Colin Cross37047f12016-12-13 17:06:13 -08001565func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001566 deps := Deps{}
1567
1568 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001569 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001570 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001571 // Add the PGO dependency (the clang_rt.profile runtime library), which
1572 // sometimes depends on symbols from libgcc, before libgcc gets added
1573 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001574 if c.pgo != nil {
1575 deps = c.pgo.deps(ctx, deps)
1576 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001577 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001578 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001579 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001580 if c.stl != nil {
1581 deps = c.stl.deps(ctx, deps)
1582 }
Colin Cross16b23492016-01-06 14:41:07 -08001583 if c.sanitize != nil {
1584 deps = c.sanitize.deps(ctx, deps)
1585 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001586 if c.coverage != nil {
1587 deps = c.coverage.deps(ctx, deps)
1588 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001589 if c.sabi != nil {
1590 deps = c.sabi.deps(ctx, deps)
1591 }
Justin Yun8effde42017-06-23 19:24:43 +09001592 if c.vndkdep != nil {
1593 deps = c.vndkdep.deps(ctx, deps)
1594 }
Stephen Craneba090d12017-05-09 15:44:35 -07001595 if c.lto != nil {
1596 deps = c.lto.deps(ctx, deps)
1597 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001598 for _, feature := range c.features {
1599 deps = feature.deps(ctx, deps)
1600 }
1601
Colin Crossb6715442017-10-24 11:13:31 -07001602 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1603 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1604 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1605 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1606 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1607 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001608 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001609
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001610 for _, lib := range deps.ReexportSharedLibHeaders {
1611 if !inList(lib, deps.SharedLibs) {
1612 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1613 }
1614 }
1615
1616 for _, lib := range deps.ReexportStaticLibHeaders {
1617 if !inList(lib, deps.StaticLibs) {
1618 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1619 }
1620 }
1621
Colin Cross5950f382016-12-13 12:50:57 -08001622 for _, lib := range deps.ReexportHeaderLibHeaders {
1623 if !inList(lib, deps.HeaderLibs) {
1624 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1625 }
1626 }
1627
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001628 for _, gen := range deps.ReexportGeneratedHeaders {
1629 if !inList(gen, deps.GeneratedHeaders) {
1630 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1631 }
1632 }
1633
Colin Crossc99deeb2016-04-11 15:06:20 -07001634 return deps
1635}
1636
Dan Albert7e9d2952016-08-04 13:02:36 -07001637func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001638 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001639 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001640 moduleContextImpl: moduleContextImpl{
1641 mod: c,
1642 },
1643 }
1644 ctx.ctx = ctx
1645
Colin Crossca860ac2016-01-04 14:34:37 -08001646 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001647}
1648
Jiyong Park7ed9de32018-10-15 22:25:07 +09001649// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001650func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001651 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1652 version := name[sharp+1:]
1653 libname := name[:sharp]
1654 return libname, version
1655 }
1656 return name, ""
1657}
1658
Colin Cross1e676be2016-10-12 14:38:15 -07001659func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001660 if !c.Enabled() {
1661 return
1662 }
1663
Colin Cross37047f12016-12-13 17:06:13 -08001664 ctx := &depsContext{
1665 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001666 moduleContextImpl: moduleContextImpl{
1667 mod: c,
1668 },
1669 }
1670 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001671
Colin Crossc99deeb2016-04-11 15:06:20 -07001672 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001673
Dan Albert914449f2016-06-17 16:45:24 -07001674 variantNdkLibs := []string{}
1675 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001676 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001677 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001678
Inseob Kimeec88e12020-01-22 11:11:29 +09001679 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001680 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001681 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001682 // 1. Name of an NDK library that refers to a prebuilt module.
1683 // For each of these, it adds the name of the prebuilt module (which will be in
1684 // prebuilts/ndk) to the list of nonvariant libs.
1685 // 2. Name of an NDK library that refers to an ndk_library module.
1686 // For each of these, it adds the name of the ndk_library module to the list of
1687 // variant libs.
1688 // 3. Anything else (so anything that isn't an NDK library).
1689 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001690 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001691 // The caller can then know to add the variantLibs dependencies differently from the
1692 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001693
Inseob Kim9516ee92019-05-09 10:56:13 +09001694 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001695 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1696
1697 rewriteVendorLibs := func(lib string) string {
1698 if isLlndkLibrary(lib, ctx.Config()) {
1699 return lib + llndkLibrarySuffix
1700 }
1701
1702 // only modules with BOARD_VNDK_VERSION uses snapshot.
1703 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1704 return lib
1705 }
1706
1707 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1708 return snapshot
1709 }
1710
1711 return lib
1712 }
1713
1714 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001715 variantLibs = []string{}
1716 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001717 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001718 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001719 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001720 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1721 if !inList(name, ndkMigratedLibs) {
1722 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001723 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001724 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001725 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001726 } else if ctx.useVndk() {
1727 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001728 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001729 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001730 if actx.OtherModuleExists(vendorPublicLib) {
1731 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1732 } else {
1733 // This can happen if vendor_public_library module is defined in a
1734 // namespace that isn't visible to the current module. In that case,
1735 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001736 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001737 }
Dan Albert914449f2016-06-17 16:45:24 -07001738 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001739 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001740 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001741 }
1742 }
Dan Albert914449f2016-06-17 16:45:24 -07001743 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001744 }
1745
Inseob Kimeec88e12020-01-22 11:11:29 +09001746 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1747 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1748 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1749 if ctx.useVndk() {
1750 for idx, lib := range deps.RuntimeLibs {
1751 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1752 }
1753 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001754 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001755
Jiyong Park7e636d02019-01-28 16:16:54 +09001756 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001757 if c.linker != nil {
1758 if library, ok := c.linker.(*libraryDecorator); ok {
1759 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001760 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001761 }
1762 }
1763 }
1764
Inseob Kimeec88e12020-01-22 11:11:29 +09001765 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1766 // only modules with BOARD_VNDK_VERSION uses snapshot.
1767 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1768 return lib
1769 }
1770
1771 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1772 return snapshot
1773 }
1774
1775 return lib
1776 }
1777
1778 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001779 for _, lib := range deps.HeaderLibs {
1780 depTag := headerDepTag
1781 if inList(lib, deps.ReexportHeaderLibHeaders) {
1782 depTag = headerExportDepTag
1783 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001784
1785 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1786
Jiyong Park7e636d02019-01-28 16:16:54 +09001787 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001788 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001789 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001790 } else {
1791 actx.AddVariationDependencies(nil, depTag, lib)
1792 }
1793 }
1794
1795 if buildStubs {
1796 // Stubs lib does not have dependency to other static/shared libraries.
1797 // Don't proceed.
1798 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001799 }
Colin Cross5950f382016-12-13 12:50:57 -08001800
Inseob Kimc0907f12019-02-08 21:00:45 +09001801 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001802 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001803
Jiyong Park5d1598f2019-02-25 22:14:17 +09001804 for _, lib := range deps.WholeStaticLibs {
1805 depTag := wholeStaticDepTag
1806 if impl, ok := syspropImplLibraries[lib]; ok {
1807 lib = impl
1808 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001809
1810 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1811
Jiyong Park5d1598f2019-02-25 22:14:17 +09001812 actx.AddVariationDependencies([]blueprint.Variation{
1813 {Mutator: "link", Variation: "static"},
1814 }, depTag, lib)
1815 }
1816
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001817 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001818 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001819 if inList(lib, deps.ReexportStaticLibHeaders) {
1820 depTag = staticExportDepTag
1821 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001822
1823 if impl, ok := syspropImplLibraries[lib]; ok {
1824 lib = impl
1825 }
1826
Inseob Kimeec88e12020-01-22 11:11:29 +09001827 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1828
Dan Willemsen59339a22018-07-22 21:18:45 -07001829 actx.AddVariationDependencies([]blueprint.Variation{
1830 {Mutator: "link", Variation: "static"},
1831 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001832 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001833
Jooyung Han74066602020-03-20 04:29:24 +09001834 // staticUnwinderDep is treated as staticDep for Q apexes
1835 // so that native libraries/binaries are linked with static unwinder
1836 // because Q libc doesn't have unwinder APIs
1837 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001838 actx.AddVariationDependencies([]blueprint.Variation{
1839 {Mutator: "link", Variation: "static"},
1840 }, staticUnwinderDepTag, staticUnwinder(actx))
1841 }
1842
Inseob Kimeec88e12020-01-22 11:11:29 +09001843 for _, lib := range deps.LateStaticLibs {
1844 actx.AddVariationDependencies([]blueprint.Variation{
1845 {Mutator: "link", Variation: "static"},
1846 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1847 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001848
Ivan Lozano183a3212019-10-18 14:18:45 -07001849 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001850 var variations []blueprint.Variation
1851 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Hanc40b5192020-04-10 12:57:24 +09001852 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001853 // Version is explicitly specified. i.e. libFoo#30
1854 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001855 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001856 }
1857 actx.AddVariationDependencies(variations, depTag, name)
1858
Jooyung Han0c4e0162020-02-26 22:45:42 +09001859 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001860 // The stubs library will be used when the depending module is built for APEX and
1861 // the dependent module is not in the same APEX.
Jooyung Hanc40b5192020-04-10 12:57:24 +09001862 if version == "" && VersionVariantAvailable(c) {
Jooyung Han0c4e0162020-02-26 22:45:42 +09001863 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1864 // Note that depTag.ExplicitlyVersioned is false in this case.
1865 actx.AddVariationDependencies([]blueprint.Variation{
1866 {Mutator: "link", Variation: "shared"},
1867 {Mutator: "version", Variation: ver},
1868 }, depTag, name)
1869 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001870 }
1871 }
1872
Jiyong Park7ed9de32018-10-15 22:25:07 +09001873 // shared lib names without the #version suffix
1874 var sharedLibNames []string
1875
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001876 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001877 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001878 if c.static() {
1879 depTag = SharedFromStaticDepTag
1880 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001881 if inList(lib, deps.ReexportSharedLibHeaders) {
1882 depTag = sharedExportDepTag
1883 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001884
1885 if impl, ok := syspropImplLibraries[lib]; ok {
1886 lib = impl
1887 }
1888
Jiyong Park73c54ee2019-10-22 20:31:18 +09001889 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001890 sharedLibNames = append(sharedLibNames, name)
1891
Jiyong Park25fc6a92018-11-18 18:02:45 +09001892 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001893 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001894
Jiyong Park7ed9de32018-10-15 22:25:07 +09001895 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001896 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001897 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1898 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1899 // linking against both the stubs lib and the non-stubs lib at the same time.
1900 continue
1901 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001902 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001903 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001904
Dan Willemsen59339a22018-07-22 21:18:45 -07001905 actx.AddVariationDependencies([]blueprint.Variation{
1906 {Mutator: "link", Variation: "shared"},
1907 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001908
Colin Cross68861832016-07-08 10:41:41 -07001909 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001910
1911 for _, gen := range deps.GeneratedHeaders {
1912 depTag := genHeaderDepTag
1913 if inList(gen, deps.ReexportGeneratedHeaders) {
1914 depTag = genHeaderExportDepTag
1915 }
1916 actx.AddDependency(c, depTag, gen)
1917 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001918
Colin Cross42d48b72018-08-29 14:10:52 -07001919 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001920
1921 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001922 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001923 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001924 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001925 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001926 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001927 if deps.LinkerFlagsFile != "" {
1928 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1929 }
1930 if deps.DynamicLinker != "" {
1931 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001932 }
Dan Albert914449f2016-06-17 16:45:24 -07001933
1934 version := ctx.sdkVersion()
1935 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001936 {Mutator: "ndk_api", Variation: version},
1937 {Mutator: "link", Variation: "shared"},
1938 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001939 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001940 {Mutator: "ndk_api", Variation: version},
1941 {Mutator: "link", Variation: "shared"},
1942 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001943
1944 if vndkdep := c.vndkdep; vndkdep != nil {
1945 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001946 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001947 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001948 {Mutator: "link", Variation: "shared"},
1949 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001950 }
1951 }
Colin Cross6362e272015-10-29 15:25:03 -07001952}
Colin Cross21b9a242015-03-24 14:15:58 -07001953
Colin Crosse40b4ea2018-10-02 22:25:58 -07001954func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001955 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1956 c.beginMutator(ctx)
1957 }
1958}
1959
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001960// Whether a module can link to another module, taking into
1961// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001962func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1963 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001964 // Host code is not restricted
1965 return
1966 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001967
1968 // VNDK is cc.Module supported only for now.
1969 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001970 // Though vendor code is limited by the vendor mutator,
1971 // each vendor-available module needs to check
1972 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001973 if ccTo, ok := to.(*Module); ok {
1974 if ccFrom.vndkdep != nil {
1975 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1976 }
1977 } else {
1978 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001979 }
1980 return
1981 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001982 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001983 // Platform code can link to anything
1984 return
1985 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001986 if from.InRamdisk() {
1987 // Ramdisk code is not NDK
1988 return
1989 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001990 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001991 // Recovery code is not NDK
1992 return
1993 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001994 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001995 // These are always allowed
1996 return
1997 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001998 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001999 // These are allowed, but they don't set sdk_version
2000 return
2001 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002002 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002003 // These aren't real libraries, but are the stub shared libraries that are included in
2004 // the NDK.
2005 return
2006 }
Logan Chien834b9a62019-01-14 15:39:03 +08002007
Ivan Lozano52767be2019-10-18 14:49:46 -07002008 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002009 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2010 // to link to libc++ (non-NDK and without sdk_version).
2011 return
2012 }
2013
Ivan Lozano52767be2019-10-18 14:49:46 -07002014 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002015 // NDK code linking to platform code is never okay.
2016 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002017 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002018 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002019 }
2020
2021 // At this point we know we have two NDK libraries, but we need to
2022 // check that we're not linking against anything built against a higher
2023 // API level, as it is only valid to link against older or equivalent
2024 // APIs.
2025
Inseob Kim01a28722018-04-11 09:48:45 +09002026 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002027 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002028 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002029 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002030 // Current can't be linked against by anything else.
2031 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002032 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002033 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002034 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002035 if err != nil {
2036 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002037 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002038 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002039 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002040 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002041 if err != nil {
2042 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002043 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002044 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002045 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002046
Inseob Kim01a28722018-04-11 09:48:45 +09002047 if toApi > fromApi {
2048 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002049 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002050 }
2051 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002052 }
Dan Albert202fe492017-12-15 13:56:59 -08002053
2054 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002055 fromStl := from.SelectedStl()
2056 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002057 if fromStl == "" || toStl == "" {
2058 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002059 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002060 // We can be permissive with the system "STL" since it is only the C++
2061 // ABI layer, but in the future we should make sure that everyone is
2062 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002063 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002064 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002065 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2066 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002067 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002068}
2069
Jiyong Park5fb8c102018-04-09 12:03:06 +09002070// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002071// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2072// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002073// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002074func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2075 check := func(child, parent android.Module) bool {
2076 to, ok := child.(*Module)
2077 if !ok {
2078 // follow thru cc.Defaults, etc.
2079 return true
2080 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002081
Jooyung Hana70f0672019-01-18 15:20:43 +09002082 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2083 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002084 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002085
2086 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002087 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002088 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002089 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002090
Jooyung Han0302a842019-10-30 18:43:49 +09002091 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002092 return false
2093 }
2094
2095 var stringPath []string
2096 for _, m := range ctx.GetWalkPath() {
2097 stringPath = append(stringPath, m.Name())
2098 }
2099 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2100 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2101 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2102 return false
2103 }
2104 if module, ok := ctx.Module().(*Module); ok {
2105 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002106 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002107 ctx.WalkDeps(check)
2108 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002109 }
2110 }
2111}
2112
Colin Crossc99deeb2016-04-11 15:06:20 -07002113// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002114func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002115 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002116
Ivan Lozano183a3212019-10-18 14:18:45 -07002117 directStaticDeps := []LinkableInterface{}
2118 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002119
Inseob Kim9516ee92019-05-09 10:56:13 +09002120 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2121
Inseob Kim69378442019-06-03 19:10:47 +09002122 reexportExporter := func(exporter exportedFlagsProducer) {
2123 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2124 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2125 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2126 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002127 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002128 }
2129
Colin Crossd11fcda2017-10-23 17:59:01 -07002130 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002131 depName := ctx.OtherModuleName(dep)
2132 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002133
Ivan Lozano52767be2019-10-18 14:49:46 -07002134 ccDep, ok := dep.(LinkableInterface)
2135 if !ok {
2136
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002137 // handling for a few module types that aren't cc Module but that are also supported
2138 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002139 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002140 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002141 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2142 genRule.GeneratedSourceFiles()...)
2143 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002144 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002145 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002146 // Support exported headers from a generated_sources dependency
2147 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002148 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002149 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002150 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002151 genRule.GeneratedSourceFiles()...)
2152 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002153 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002154 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002155 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002156 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002157 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002158 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2159 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002160 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002161 // 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 +09002162 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002163
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002164 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002165 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002166 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002167 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002168 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002169 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002170 files := genRule.GeneratedSourceFiles()
2171 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002172 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002173 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002174 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 -07002175 }
2176 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002177 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002178 }
Colin Crossca860ac2016-01-04 14:34:37 -08002179 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002180 return
2181 }
2182
Colin Crossfe17f6f2019-03-28 19:30:56 -07002183 if depTag == android.ProtoPluginDepTag {
2184 return
2185 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002186 if depTag == llndkImplDep {
2187 return
2188 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002189
Colin Crossd11fcda2017-10-23 17:59:01 -07002190 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002191 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2192 return
2193 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002194 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002195 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2196 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002197 return
2198 }
2199
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002200 // re-exporting flags
2201 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002202 // reusing objects only make sense for cc.Modules.
2203 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002204 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002205 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002206 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002207 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002208 return
2209 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002210 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002211
Jiyong Parke4bb9862019-02-01 00:31:10 +09002212 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002213 // staticVariants are a cc.Module specific concept.
2214 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002215 c.staticVariant = ccDep
2216 return
2217 }
2218 }
2219
Jooyung Han74066602020-03-20 04:29:24 +09002220 // For the dependency from platform to apex, use the latest stubs
2221 c.apexSdkVersion = android.FutureApiLevel
2222 if !c.IsForPlatform() {
2223 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2224 }
2225
2226 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2227 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2228 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2229 // (b/144430859)
2230 c.apexSdkVersion = android.FutureApiLevel
2231 }
2232
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002233 if depTag == staticUnwinderDepTag {
Jooyung Han74066602020-03-20 04:29:24 +09002234 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2235 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002236 depTag = StaticDepTag
2237 } else {
2238 return
2239 }
2240 }
2241
Ivan Lozano183a3212019-10-18 14:18:45 -07002242 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2243 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2244 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002245 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002246 if t, ok := depTag.(DependencyTag); ok {
2247 explicitlyVersioned = t.ExplicitlyVersioned
2248 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002249 depTag = t
2250 }
2251
Ivan Lozano183a3212019-10-18 14:18:45 -07002252 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002253 depIsStatic := false
2254 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002255 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002256 depIsStatic = true
2257 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002258 if ccDep.CcLibrary() && !depIsStatic {
2259 depIsStubs := ccDep.BuildStubs()
Jooyung Hanc40b5192020-04-10 12:57:24 +09002260 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002261 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002262 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002263
2264 var useThisDep bool
2265 if depIsStubs && explicitlyVersioned {
2266 // Always respect dependency to the versioned stubs (i.e. libX#10)
2267 useThisDep = true
2268 } else if !depHasStubs {
2269 // Use non-stub variant if that is the only choice
2270 // (i.e. depending on a lib without stubs.version property)
2271 useThisDep = true
2272 } else if c.IsForPlatform() {
2273 // If not building for APEX, use stubs only when it is from
2274 // an APEX (and not from platform)
2275 useThisDep = (depInPlatform != depIsStubs)
Jooyung Hanc40b5192020-04-10 12:57:24 +09002276 if c.bootstrap() {
2277 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002278 // always link to non-stub variant
2279 useThisDep = !depIsStubs
2280 }
2281 } else {
2282 // If building for APEX, use stubs only when it is not from
2283 // the same APEX
2284 useThisDep = (depInSameApex != depIsStubs)
2285 }
2286
Jooyung Han0c4e0162020-02-26 22:45:42 +09002287 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2288 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han74066602020-03-20 04:29:24 +09002289 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han0c4e0162020-02-26 22:45:42 +09002290 if err != nil {
2291 ctx.OtherModuleErrorf(dep, err.Error())
2292 return
2293 }
2294 if versionToUse != ccDep.StubsVersion() {
2295 useThisDep = false
2296 }
2297 }
2298
Jiyong Park25fc6a92018-11-18 18:02:45 +09002299 if !useThisDep {
2300 return // stop processing this dep
2301 }
2302 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002303 if c.UseVndk() {
2304 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2305 // by default, use current version of LLNDK
2306 versionToUse := ""
2307 versions := stubsVersionsFor(ctx.Config())[depName]
2308 if c.ApexName() != "" && len(versions) > 0 {
2309 // if this is for use_vendor apex && dep has stubsVersions
2310 // apply the same rule of apex sdk enforcement to choose right version
2311 var err error
Jooyung Han74066602020-03-20 04:29:24 +09002312 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han67a96cd2020-03-13 15:23:36 +09002313 if err != nil {
2314 ctx.OtherModuleErrorf(dep, err.Error())
2315 return
2316 }
2317 }
2318 if versionToUse != ccDep.StubsVersion() {
2319 return
2320 }
2321 }
2322 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002323
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002324 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2325
Ivan Lozano52767be2019-10-18 14:49:46 -07002326 // Exporting flags only makes sense for cc.Modules
2327 if _, ok := ccDep.(*Module); ok {
2328 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002329 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002330 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2331 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002332 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002333
Ivan Lozano52767be2019-10-18 14:49:46 -07002334 if t.ReexportFlags {
2335 reexportExporter(i)
2336 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2337 // Re-exported shared library headers must be included as well since they can help us with type information
2338 // about template instantiations (instantiated from their headers).
2339 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2340 // scripts.
2341 c.sabi.Properties.ReexportedIncludes = append(
2342 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2343 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002344 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002345 }
Logan Chienf3511742017-10-31 18:04:35 +08002346 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002347 }
2348
Colin Cross26c34ed2016-09-30 17:10:16 -07002349 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002350 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002351
Ivan Lozano52767be2019-10-18 14:49:46 -07002352 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002353 depFile := android.OptionalPath{}
2354
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002355 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002356 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002357 ptr = &depPaths.SharedLibs
2358 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002359 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002360 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002361
Jiyong Park64a44f22019-01-18 14:37:08 +09002362 case earlySharedDepTag:
2363 ptr = &depPaths.EarlySharedLibs
2364 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002365 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002366 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002367 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002368 ptr = &depPaths.LateSharedLibs
2369 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002370 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002371 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002372 ptr = nil
2373 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002374 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002375 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002376 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002377 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002378 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002379 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002380 return
2381 }
2382
Ivan Lozano52767be2019-10-18 14:49:46 -07002383 // Because the static library objects are included, this only makes sense
2384 // in the context of proper cc.Modules.
2385 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2386 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2387 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2388 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2389 for i := range missingDeps {
2390 missingDeps[i] += postfix
2391 }
2392 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002393 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002394 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2395 } else {
2396 ctx.ModuleErrorf(
2397 "non-cc.Modules cannot be included as whole static libraries.", depName)
2398 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002399 }
Colin Cross5950f382016-12-13 12:50:57 -08002400 case headerDepTag:
2401 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002402 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002403 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002404 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002405 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002406 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002407 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002408 case dynamicLinkerDepTag:
2409 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002410 }
2411
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002412 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002413 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002414 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002415 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002416 return
2417 }
2418
2419 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002420 // in static libraries act as if they were whole static libraries. The same goes for
2421 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002422 // This should only be done for cc.Modules
2423 if c, ok := ccDep.(*Module); ok {
2424 staticLib := c.linker.(libraryInterface)
2425 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2426 staticLib.objs().coverageFiles...)
2427 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2428 staticLib.objs().sAbiDumpFiles...)
2429 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002430 }
2431
Colin Cross26c34ed2016-09-30 17:10:16 -07002432 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002433 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002434 if !ctx.Config().AllowMissingDependencies() {
2435 ctx.ModuleErrorf("module %q missing output file", depName)
2436 } else {
2437 ctx.AddMissingDependencies([]string{depName})
2438 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002439 return
2440 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002441 *ptr = append(*ptr, linkFile.Path())
2442 }
2443
Colin Crossc99deeb2016-04-11 15:06:20 -07002444 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002445 dep := depFile
2446 if !dep.Valid() {
2447 dep = linkFile
2448 }
2449 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002450 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002451
Inseob Kimeec88e12020-01-22 11:11:29 +09002452 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2453
2454 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002455 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002456 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002457 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002458 return libName
2459 }
2460
2461 makeLibName := func(depName string) string {
2462 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002463 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002464 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002465 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002466
Inseob Kimeec88e12020-01-22 11:11:29 +09002467 if c, ok := ccDep.(*Module); ok {
2468 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002469 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002470 baseName := c.BaseModuleName()
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002471
2472 if c.IsVndk() {
2473 return baseName + ".vendor"
2474 }
2475
Inseob Kimeec88e12020-01-22 11:11:29 +09002476 if vendorSuffixModules[baseName] {
2477 return baseName + ".vendor"
2478 } else {
2479 return baseName
2480 }
2481 }
2482 }
2483
Yifan Hong1b3348d2020-01-21 15:53:22 -08002484 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002485 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2486 // core module instead.
2487 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002488 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002489 // The vendor module in Make will have been renamed to not conflict with the core
2490 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002491 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002492 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002493 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002494 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2495 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002496 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002497 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002498 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002499 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002500 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002501 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002502 }
Logan Chien43d34c32017-12-20 01:17:32 +08002503 }
2504
2505 // Export the shared libs to Make.
2506 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002507 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002508 if ccDep.CcLibrary() {
2509 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002510 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002511 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002512 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002513 c.Properties.ApexesProvidingSharedLibs = append(
2514 c.Properties.ApexesProvidingSharedLibs, an)
2515 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002516 }
2517 }
2518
Jiyong Park27b188b2017-07-18 13:23:39 +09002519 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002520 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002521 c.Properties.AndroidMkSharedLibs = append(
2522 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002523 // Record baseLibName for snapshots.
2524 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002525 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002526 c.Properties.AndroidMkSharedLibs = append(
2527 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002528 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002529 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002530 c.Properties.AndroidMkStaticLibs = append(
2531 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002532 case runtimeDepTag:
2533 c.Properties.AndroidMkRuntimeLibs = append(
2534 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002535 // Record baseLibName for snapshots.
2536 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002537 case wholeStaticDepTag:
2538 c.Properties.AndroidMkWholeStaticLibs = append(
2539 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002540 }
Colin Crossca860ac2016-01-04 14:34:37 -08002541 })
2542
Jeff Gaston294356f2017-09-27 17:05:30 -07002543 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002544 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002545
Colin Crossdd84e052017-05-17 13:44:16 -07002546 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002547 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002548 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2549 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002550 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002551 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002552 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2553 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002554 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002555 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002556 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002557
2558 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002559 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002560 }
Colin Crossdd84e052017-05-17 13:44:16 -07002561
Colin Crossca860ac2016-01-04 14:34:37 -08002562 return depPaths
2563}
2564
2565func (c *Module) InstallInData() bool {
2566 if c.installer == nil {
2567 return false
2568 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002569 return c.installer.inData()
2570}
2571
2572func (c *Module) InstallInSanitizerDir() bool {
2573 if c.installer == nil {
2574 return false
2575 }
2576 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002577 return true
2578 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002579 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002580}
2581
Yifan Hong1b3348d2020-01-21 15:53:22 -08002582func (c *Module) InstallInRamdisk() bool {
2583 return c.InRamdisk()
2584}
2585
Jiyong Parkf9332f12018-02-01 00:54:12 +09002586func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002587 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002588}
2589
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002590func (c *Module) HostToolPath() android.OptionalPath {
2591 if c.installer == nil {
2592 return android.OptionalPath{}
2593 }
2594 return c.installer.hostToolPath()
2595}
2596
Nan Zhangd4e641b2017-07-12 12:55:28 -07002597func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2598 return c.outputFile
2599}
2600
Colin Cross41955e82019-05-29 14:40:35 -07002601func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2602 switch tag {
2603 case "":
2604 if c.outputFile.Valid() {
2605 return android.Paths{c.outputFile.Path()}, nil
2606 }
2607 return android.Paths{}, nil
2608 default:
2609 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002610 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002611}
2612
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002613func (c *Module) static() bool {
2614 if static, ok := c.linker.(interface {
2615 static() bool
2616 }); ok {
2617 return static.static()
2618 }
2619 return false
2620}
2621
Jiyong Park379de2f2018-12-19 02:47:14 +09002622func (c *Module) staticBinary() bool {
2623 if static, ok := c.linker.(interface {
2624 staticBinary() bool
2625 }); ok {
2626 return static.staticBinary()
2627 }
2628 return false
2629}
2630
Jiyong Park1d1119f2019-07-29 21:27:18 +09002631func (c *Module) header() bool {
2632 if h, ok := c.linker.(interface {
2633 header() bool
2634 }); ok {
2635 return h.header()
2636 }
2637 return false
2638}
2639
Jooyung Han38002912019-05-16 04:01:54 +09002640func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002641 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002642 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2643 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002644 return "native:vndk"
2645 }
Jooyung Han38002912019-05-16 04:01:54 +09002646 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002647 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002648 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002649 if Bool(c.VendorProperties.Vendor_available) {
2650 return "native:vndk"
2651 }
2652 return "native:vndk_private"
2653 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002654 if c.inProduct() {
2655 return "native:product"
2656 }
Jooyung Han38002912019-05-16 04:01:54 +09002657 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002658 } else if c.InRamdisk() {
2659 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002660 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002661 return "native:recovery"
2662 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2663 return "native:ndk:none:none"
2664 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2665 //family, link := getNdkStlFamilyAndLinkType(c)
2666 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002667 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002668 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002669 } else {
2670 return "native:platform"
2671 }
2672}
2673
Jiyong Park9d452992018-10-03 00:38:19 +09002674// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002675// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002676func (c *Module) IsInstallableToApex() bool {
2677 if shared, ok := c.linker.(interface {
2678 shared() bool
2679 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002680 // Stub libs and prebuilt libs in a versioned SDK are not
2681 // installable to APEX even though they are shared libs.
2682 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002683 } else if _, ok := c.linker.(testPerSrc); ok {
2684 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002685 }
2686 return false
2687}
2688
Jiyong Parka90ca002019-10-07 15:47:24 +09002689func (c *Module) AvailableFor(what string) bool {
2690 if linker, ok := c.linker.(interface {
2691 availableFor(string) bool
2692 }); ok {
2693 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2694 } else {
2695 return c.ApexModuleBase.AvailableFor(what)
2696 }
2697}
2698
Inseob Kim1f086e22019-05-09 13:29:15 +09002699func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002700 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2701
2702 // The platform variant doesn't need further condition. Apex variants however might not
2703 // be installable because it will likely to be included in the APEX and won't appear
2704 // in the system partition.
2705 if c.IsForPlatform() {
2706 return ret
2707 }
2708
2709 // Special case for modules that are configured to be installed to /data, which includes
2710 // test modules. For these modules, both APEX and non-APEX variants are considered as
2711 // installable. This is because even the APEX variants won't be included in the APEX, but
2712 // will anyway be installed to /data/*.
2713 // See b/146995717
2714 if c.InstallInData() {
2715 return ret
2716 }
2717
2718 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002719}
2720
Logan Chien41eabe62019-04-10 13:33:58 +08002721func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2722 if c.linker != nil {
2723 if library, ok := c.linker.(*libraryDecorator); ok {
2724 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2725 }
2726 }
2727}
2728
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002729func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002730 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002731 if cc, ok := dep.(*Module); ok {
Jiyong Park9f14b9b2020-03-01 17:29:06 +09002732 if cc.HasStubsVariants() {
2733 if depTag.Shared && depTag.Library {
2734 // dynamic dep to a stubs lib crosses APEX boundary
2735 return false
2736 }
2737 if IsRuntimeDepTag(depTag) {
2738 // runtime dep to a stubs lib also crosses APEX boundary
2739 return false
2740 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002741 }
2742 if depTag.FromStatic {
2743 // shared_lib dependency from a static lib is considered as crossing
2744 // the APEX boundary because the dependency doesn't actually is
2745 // linked; the dependency is used only during the compilation phase.
2746 return false
2747 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002748 }
2749 }
2750 return true
2751}
2752
Colin Cross2ba19d92015-05-07 15:44:20 -07002753//
Colin Crosscfad1192015-11-02 16:43:11 -08002754// Defaults
2755//
Colin Crossca860ac2016-01-04 14:34:37 -08002756type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002757 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002758 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002759 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002760}
2761
Patrice Arrudac249c712019-03-19 17:00:29 -07002762// cc_defaults provides a set of properties that can be inherited by other cc
2763// modules. A module can use the properties from a cc_defaults using
2764// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2765// merged (when possible) by prepending the default module's values to the
2766// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002767func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002768 return DefaultsFactory()
2769}
2770
Colin Cross36242852017-06-23 15:06:31 -07002771func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002772 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002773
Colin Cross36242852017-06-23 15:06:31 -07002774 module.AddProperties(props...)
2775 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002776 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002777 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002778 &BaseCompilerProperties{},
2779 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002780 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002781 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002782 &StaticProperties{},
2783 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002784 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002785 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002786 &TestProperties{},
2787 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002788 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002789 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002790 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002791 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002792 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002793 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002794 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002795 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002796 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002797 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002798 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002799 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002800 )
Colin Crosscfad1192015-11-02 16:43:11 -08002801
Jooyung Hancc372c52019-09-25 15:18:44 +09002802 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002803
2804 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002805}
2806
Jiyong Park6a43f042017-10-12 23:05:00 +09002807func squashVendorSrcs(m *Module) {
2808 if lib, ok := m.compiler.(*libraryDecorator); ok {
2809 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2810 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2811
2812 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2813 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2814 }
2815}
2816
Jiyong Parkf9332f12018-02-01 00:54:12 +09002817func squashRecoverySrcs(m *Module) {
2818 if lib, ok := m.compiler.(*libraryDecorator); ok {
2819 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2820 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2821
2822 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2823 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2824 }
2825}
2826
Colin Cross7228ecd2019-11-18 16:00:16 -08002827var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002828
Colin Cross7228ecd2019-11-18 16:00:16 -08002829func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002830 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002831 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002832 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002833
2834 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002835 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002836 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002837 }
Logan Chienf3511742017-10-31 18:04:35 +08002838
2839 if vndkdep := m.vndkdep; vndkdep != nil {
2840 if vndkdep.isVndk() {
Justin Yun98df0d12020-02-28 15:07:59 +09002841 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002842 if !vndkdep.isVndkExt() {
2843 mctx.PropertyErrorf("vndk",
2844 "must set `extends: \"...\"` to vndk extension")
Justin Yun98df0d12020-02-28 15:07:59 +09002845 } else if m.VendorProperties.Vendor_available != nil {
2846 mctx.PropertyErrorf("vendor_available",
2847 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002848 }
2849 } else {
2850 if vndkdep.isVndkExt() {
2851 mctx.PropertyErrorf("vndk",
Justin Yun98df0d12020-02-28 15:07:59 +09002852 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002853 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002854 }
2855 if m.VendorProperties.Vendor_available == nil {
2856 mctx.PropertyErrorf("vndk",
2857 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002858 }
2859 }
2860 } else {
2861 if vndkdep.isVndkSp() {
2862 mctx.PropertyErrorf("vndk",
2863 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002864 }
2865 if vndkdep.isVndkExt() {
2866 mctx.PropertyErrorf("vndk",
2867 "must set `enabled: true` to set `extends: %q`",
2868 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002869 }
Justin Yun8effde42017-06-23 19:24:43 +09002870 }
2871 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002872
Jiyong Parkf9332f12018-02-01 00:54:12 +09002873 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002874 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002875 var recoveryVariantNeeded bool = false
2876
Inseob Kim64c43952019-08-26 16:52:35 +09002877 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002878 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002879
2880 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002881 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2882 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2883 if boardVndkVersion == "current" {
2884 boardVndkVersion = platformVndkVersion
2885 }
2886 if productVndkVersion == "current" {
2887 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002888 }
2889
Justin Yun5f7f7e82019-11-18 19:52:14 +09002890 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002891 // If the device isn't compiling against the VNDK, we always
2892 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002893 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002894 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002895 // LL-NDK stubs only exist in the vendor and product variants,
2896 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002897 vendorVariants = append(vendorVariants,
2898 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002899 boardVndkVersion,
2900 )
2901 productVariants = append(productVariants,
2902 platformVndkVersion,
2903 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002904 )
Jiyong Park2a454122017-10-19 15:59:33 +09002905 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2906 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002907 vendorVariants = append(vendorVariants,
2908 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002909 boardVndkVersion,
2910 )
2911 productVariants = append(productVariants,
2912 platformVndkVersion,
2913 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002914 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002915 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002916 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2917 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002918 if snapshot, ok := m.linker.(interface {
2919 version() string
2920 }); ok {
2921 vendorVariants = append(vendorVariants, snapshot.version())
2922 } else {
2923 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2924 }
Justin Yun98df0d12020-02-28 15:07:59 +09002925 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002926 // This will be available in /system, /vendor and /product
2927 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002928 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002929 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002930 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002931 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2932 // code is PLATFORM_VNDK_VERSION.
2933 // On the other hand, vendor_available modules which are not VNDK should
2934 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002935 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002936 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002937 vendorVariants = append(vendorVariants, boardVndkVersion)
2938 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002939 }
Logan Chienf3511742017-10-31 18:04:35 +08002940 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002941 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002942 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002943 } else {
2944 // This is either in /system (or similar: /data), or is a
2945 // modules built with the NDK. Modules built with the NDK
2946 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002947 coreVariantNeeded = true
2948 }
2949
Justin Yun5f7f7e82019-11-18 19:52:14 +09002950 if boardVndkVersion != "" && productVndkVersion != "" {
2951 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2952 // The module has "product_specific: true" that does not create core variant.
2953 coreVariantNeeded = false
2954 productVariants = append(productVariants, productVndkVersion)
2955 }
2956 } else {
2957 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2958 // restriction to use system libs.
2959 // No product variants defined in this case.
2960 productVariants = []string{}
2961 }
2962
Yifan Hong1b3348d2020-01-21 15:53:22 -08002963 if Bool(m.Properties.Ramdisk_available) {
2964 ramdiskVariantNeeded = true
2965 }
2966
2967 if m.ModuleBase.InstallInRamdisk() {
2968 ramdiskVariantNeeded = true
2969 coreVariantNeeded = false
2970 }
2971
Jiyong Parkf9332f12018-02-01 00:54:12 +09002972 if Bool(m.Properties.Recovery_available) {
2973 recoveryVariantNeeded = true
2974 }
2975
2976 if m.ModuleBase.InstallInRecovery() {
2977 recoveryVariantNeeded = true
2978 coreVariantNeeded = false
2979 }
2980
Inseob Kim64c43952019-08-26 16:52:35 +09002981 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002982 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2983 }
2984
2985 for _, variant := range android.FirstUniqueStrings(productVariants) {
2986 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002987 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002988
Yifan Hong1b3348d2020-01-21 15:53:22 -08002989 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002990 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2991 m.Properties.CoreVariantNeeded = coreVariantNeeded
2992}
2993
2994func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2995 return c.Properties.CoreVariantNeeded
2996}
2997
Yifan Hong1b3348d2020-01-21 15:53:22 -08002998func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
2999 return c.Properties.RamdiskVariantNeeded
3000}
3001
Colin Cross7228ecd2019-11-18 16:00:16 -08003002func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3003 return c.Properties.RecoveryVariantNeeded
3004}
3005
3006func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003007 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003008}
3009
3010func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3011 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003012 if variant == android.RamdiskVariation {
3013 m.MakeAsPlatform()
3014 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003015 m.MakeAsPlatform()
3016 squashRecoverySrcs(m)
3017 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003018 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003019 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3020 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003021
3022 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3023 // Hide other vendor variants to avoid collision.
3024 vndkVersion := ctx.DeviceConfig().VndkVersion()
3025 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3026 m.Properties.HideFromMake = true
3027 m.SkipInstall()
3028 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003029 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3030 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3031 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3032 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003033 }
3034}
3035
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003036func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003037 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003038 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3039 }
Colin Cross6510f912017-11-29 00:27:14 -08003040 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003041}
3042
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003043func kytheExtractAllFactory() android.Singleton {
3044 return &kytheExtractAllSingleton{}
3045}
3046
3047type kytheExtractAllSingleton struct {
3048}
3049
3050func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3051 var xrefTargets android.Paths
3052 ctx.VisitAllModules(func(module android.Module) {
3053 if ccModule, ok := module.(xref); ok {
3054 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3055 }
3056 })
3057 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3058 if len(xrefTargets) > 0 {
3059 ctx.Build(pctx, android.BuildParams{
3060 Rule: blueprint.Phony,
3061 Output: android.PathForPhony(ctx, "xref_cxx"),
3062 Inputs: xrefTargets,
3063 //Default: true,
3064 })
3065 }
3066}
3067
Colin Cross06a931b2015-10-28 17:23:31 -07003068var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003069var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003070var BoolPtr = proptools.BoolPtr
3071var String = proptools.String
3072var StringPtr = proptools.StringPtr