blob: 88fede4100b2ff7427088e7d390cc9706ddb657b [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"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000253
254 Installable *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700255}
256
257type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900258 // whether this module should be allowed to be directly depended by other
259 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900260 // In addition, this module should be allowed to be directly depended by
261 // product modules with `product_specific: true`.
262 // If set to true, three variants will be built separately, one like
263 // normal, another limited to the set of libraries and headers
264 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700265 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900266 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700267 // so it shouldn't have any unversioned runtime dependencies, or
268 // make assumptions about the system that may not be true in the
269 // future.
270 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900271 // If set to false, this module becomes inaccessible from /vendor or /product
272 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900273 //
274 // Default value is true when vndk: {enabled: true} or vendor: true.
275 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700276 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900277 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700278 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900279
280 // whether this module is capable of being loaded with other instance
281 // (possibly an older version) of the same module in the same process.
282 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
283 // can be double loaded in a vendor process if the library is also a
284 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
285 // explicitly marked as `double_loadable: true` by the owner, or the dependency
286 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
287 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800288}
289
Colin Crossca860ac2016-01-04 14:34:37 -0800290type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800291 static() bool
292 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900293 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700294 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900295 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700296 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800297 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700298 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800299 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900300 isLlndk(config android.Config) bool
301 isLlndkPublic(config android.Config) bool
302 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900303 isVndk() bool
304 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800305 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900306 inProduct() bool
307 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800308 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900309 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800310 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700311 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700312 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800313 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800314 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800315 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800316 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800317 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900318 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900319 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900320 hasStubsVariants() bool
321 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900322 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800323 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700324 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800325}
326
327type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700328 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800329 ModuleContextIntf
330}
331
332type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700333 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800334 ModuleContextIntf
335}
336
Colin Cross37047f12016-12-13 17:06:13 -0800337type DepsContext interface {
338 android.BottomUpMutatorContext
339 ModuleContextIntf
340}
341
Colin Crossca860ac2016-01-04 14:34:37 -0800342type feature interface {
343 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800344 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800345 flags(ctx ModuleContext, flags Flags) Flags
346 props() []interface{}
347}
348
349type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700350 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800351 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800352 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700353 compilerProps() []interface{}
354
Colin Cross76fada02016-07-27 10:31:13 -0700355 appendCflags([]string)
356 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700357 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800358}
359
360type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700361 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800362 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700363 linkerFlags(ctx ModuleContext, flags Flags) Flags
364 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800365 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700366
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700367 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700368 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900369 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700370
371 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900372 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000373
374 // Get the deps that have been explicitly specified in the properties.
375 // Only updates the
376 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
377}
378
379type specifiedDeps struct {
380 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000381 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800382}
383
384type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700385 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700386 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000387 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800388 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700389 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700390 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900391 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800392}
393
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800394type xref interface {
395 XrefCcFiles() android.Paths
396}
397
Colin Crossc99deeb2016-04-11 15:06:20 -0700398var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700399 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
400 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
401 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
402 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
403 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800404 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700405 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
406 headerDepTag = DependencyTag{Name: "header", Library: true}
407 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
408 genSourceDepTag = DependencyTag{Name: "gen source"}
409 genHeaderDepTag = DependencyTag{Name: "gen header"}
410 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
411 objDepTag = DependencyTag{Name: "obj"}
412 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
413 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
414 reuseObjTag = DependencyTag{Name: "reuse objects"}
415 staticVariantTag = DependencyTag{Name: "static variant"}
416 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
417 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
418 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
419 runtimeDepTag = DependencyTag{Name: "runtime lib"}
420 coverageDepTag = DependencyTag{Name: "coverage"}
421 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700422)
423
Roland Levillainf89cd092019-07-29 16:22:59 +0100424func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700425 ccDepTag, ok := depTag.(DependencyTag)
426 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100427}
428
429func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700430 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100431 return ok && ccDepTag == runtimeDepTag
432}
433
434func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700435 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100436 return ok && ccDepTag == testPerSrcDepTag
437}
438
Colin Crossca860ac2016-01-04 14:34:37 -0800439// Module contains the properties and members used by all C/C++ module types, and implements
440// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
441// to construct the output file. Behavior can be customized with a Customizer interface
442type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700443 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700444 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900445 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900446 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700447
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700448 Properties BaseProperties
449 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700450
Colin Crossca860ac2016-01-04 14:34:37 -0800451 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700452 hod android.HostOrDeviceSupported
453 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700454
Paul Duffina0843f62019-12-13 19:50:38 +0000455 // Allowable SdkMemberTypes of this module type.
456 sdkMemberTypes []android.SdkMemberType
457
Colin Crossca860ac2016-01-04 14:34:37 -0800458 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700459 features []feature
460 compiler compiler
461 linker linker
462 installer installer
463 stl *stl
464 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800465 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800466 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900467 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700468 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700469 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800470
Colin Cross635c3b02016-05-18 15:37:25 -0700471 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800472
Colin Crossb98c8b02016-07-29 13:44:28 -0700473 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700474
475 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800476
477 // Flags used to compile this module
478 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700479
480 // 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 -0800481 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700482 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800483 depsInLinkOrder android.Paths
484
485 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700486 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900487
488 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800489 // Kythe (source file indexer) paths for this compilation module
490 kytheFiles android.Paths
Jooyung Han75568392020-03-20 04:29:24 +0900491
492 // For apex variants, this is set as apex.min_sdk_version
493 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700494}
495
Ivan Lozano52767be2019-10-18 14:49:46 -0700496func (c *Module) Toc() android.OptionalPath {
497 if c.linker != nil {
498 if library, ok := c.linker.(libraryInterface); ok {
499 return library.toc()
500 }
501 }
502 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
503}
504
505func (c *Module) ApiLevel() string {
506 if c.linker != nil {
507 if stub, ok := c.linker.(*stubDecorator); ok {
508 return stub.properties.ApiLevel
509 }
510 }
511 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
512}
513
514func (c *Module) Static() bool {
515 if c.linker != nil {
516 if library, ok := c.linker.(libraryInterface); ok {
517 return library.static()
518 }
519 }
520 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
521}
522
523func (c *Module) Shared() bool {
524 if c.linker != nil {
525 if library, ok := c.linker.(libraryInterface); ok {
526 return library.shared()
527 }
528 }
529 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
530}
531
532func (c *Module) SelectedStl() string {
533 return c.stl.Properties.SelectedStl
534}
535
536func (c *Module) ToolchainLibrary() bool {
537 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
538 return true
539 }
540 return false
541}
542
543func (c *Module) NdkPrebuiltStl() bool {
544 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
545 return true
546 }
547 return false
548}
549
550func (c *Module) StubDecorator() bool {
551 if _, ok := c.linker.(*stubDecorator); ok {
552 return true
553 }
554 return false
555}
556
557func (c *Module) SdkVersion() string {
558 return String(c.Properties.Sdk_version)
559}
560
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800561func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700562 if c.linker != nil {
563 if library, ok := c.linker.(exportedFlagsProducer); ok {
564 return library.exportedDirs()
565 }
566 }
567 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
568}
569
570func (c *Module) HasStaticVariant() bool {
571 if c.staticVariant != nil {
572 return true
573 }
574 return false
575}
576
577func (c *Module) GetStaticVariant() LinkableInterface {
578 return c.staticVariant
579}
580
581func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
582 c.depsInLinkOrder = depsInLinkOrder
583}
584
585func (c *Module) GetDepsInLinkOrder() []android.Path {
586 return c.depsInLinkOrder
587}
588
589func (c *Module) StubsVersions() []string {
590 if c.linker != nil {
591 if library, ok := c.linker.(*libraryDecorator); ok {
592 return library.Properties.Stubs.Versions
593 }
594 }
595 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
596}
597
598func (c *Module) CcLibrary() bool {
599 if c.linker != nil {
600 if _, ok := c.linker.(*libraryDecorator); ok {
601 return true
602 }
603 }
604 return false
605}
606
607func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700608 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700609 return true
610 }
611 return false
612}
613
Ivan Lozano2b262972019-11-21 12:30:50 -0800614func (c *Module) NonCcVariants() bool {
615 return false
616}
617
Ivan Lozano183a3212019-10-18 14:18:45 -0700618func (c *Module) SetBuildStubs() {
619 if c.linker != nil {
620 if library, ok := c.linker.(*libraryDecorator); ok {
621 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700622 c.Properties.HideFromMake = true
623 c.sanitize = nil
624 c.stl = nil
625 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700626 return
627 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000628 if _, ok := c.linker.(*llndkStubDecorator); ok {
629 c.Properties.HideFromMake = true
630 return
631 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700632 }
633 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
634}
635
Ivan Lozano52767be2019-10-18 14:49:46 -0700636func (c *Module) BuildStubs() bool {
637 if c.linker != nil {
638 if library, ok := c.linker.(*libraryDecorator); ok {
639 return library.buildStubs()
640 }
641 }
642 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
643}
644
Ivan Lozano183a3212019-10-18 14:18:45 -0700645func (c *Module) SetStubsVersions(version string) {
646 if c.linker != nil {
647 if library, ok := c.linker.(*libraryDecorator); ok {
648 library.MutatedProperties.StubsVersion = version
649 return
650 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000651 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
652 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
653 return
654 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700655 }
656 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
657}
658
Jooyung Han03b51852020-02-26 22:45:42 +0900659func (c *Module) StubsVersion() string {
660 if c.linker != nil {
661 if library, ok := c.linker.(*libraryDecorator); ok {
662 return library.MutatedProperties.StubsVersion
663 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000664 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
665 return llndk.libraryDecorator.MutatedProperties.StubsVersion
666 }
Jooyung Han03b51852020-02-26 22:45:42 +0900667 }
668 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
669}
670
Ivan Lozano183a3212019-10-18 14:18:45 -0700671func (c *Module) SetStatic() {
672 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700673 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700674 library.setStatic()
675 return
676 }
677 }
678 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
679}
680
681func (c *Module) SetShared() {
682 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700683 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700684 library.setShared()
685 return
686 }
687 }
688 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
689}
690
691func (c *Module) BuildStaticVariant() bool {
692 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700693 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700694 return library.buildStatic()
695 }
696 }
697 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
698}
699
700func (c *Module) BuildSharedVariant() bool {
701 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700702 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700703 return library.buildShared()
704 }
705 }
706 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
707}
708
709func (c *Module) Module() android.Module {
710 return c
711}
712
Jiyong Parkc20eee32018-09-05 22:36:17 +0900713func (c *Module) OutputFile() android.OptionalPath {
714 return c.outputFile
715}
716
Ivan Lozano183a3212019-10-18 14:18:45 -0700717var _ LinkableInterface = (*Module)(nil)
718
Jiyong Park719b4462019-01-13 00:39:51 +0900719func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900720 if c.linker != nil {
721 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900722 }
723 return nil
724}
725
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900726func (c *Module) CoverageOutputFile() android.OptionalPath {
727 if c.linker != nil {
728 return c.linker.coverageOutputFilePath()
729 }
730 return android.OptionalPath{}
731}
732
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900733func (c *Module) RelativeInstallPath() string {
734 if c.installer != nil {
735 return c.installer.relativeInstallPath()
736 }
737 return ""
738}
739
Jooyung Han344d5432019-08-23 11:17:39 +0900740func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900741 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900742}
743
Colin Cross36242852017-06-23 15:06:31 -0700744func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700745 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800746 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700747 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800748 }
749 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700750 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800751 }
752 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700753 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800754 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700755 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700756 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700757 }
Colin Cross16b23492016-01-06 14:41:07 -0800758 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700759 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800760 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800761 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700762 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800763 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800764 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700765 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800766 }
Justin Yun8effde42017-06-23 19:24:43 +0900767 if c.vndkdep != nil {
768 c.AddProperties(c.vndkdep.props()...)
769 }
Stephen Craneba090d12017-05-09 15:44:35 -0700770 if c.lto != nil {
771 c.AddProperties(c.lto.props()...)
772 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700773 if c.pgo != nil {
774 c.AddProperties(c.pgo.props()...)
775 }
Colin Crossca860ac2016-01-04 14:34:37 -0800776 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700777 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800778 }
Colin Crossc472d572015-03-17 15:06:21 -0700779
Colin Crossa9d8bee2018-10-02 13:59:46 -0700780 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
781 switch class {
782 case android.Device:
783 return ctx.Config().DevicePrefer32BitExecutables()
784 case android.HostCross:
785 // Windows builds always prefer 32-bit
786 return true
787 default:
788 return false
789 }
790 })
Colin Cross36242852017-06-23 15:06:31 -0700791 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900792 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900793 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900794 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900795
Colin Cross36242852017-06-23 15:06:31 -0700796 return c
Colin Crossc472d572015-03-17 15:06:21 -0700797}
798
Colin Crossb916a382016-07-29 17:28:03 -0700799// Returns true for dependency roots (binaries)
800// TODO(ccross): also handle dlopenable libraries
801func (c *Module) isDependencyRoot() bool {
802 if root, ok := c.linker.(interface {
803 isDependencyRoot() bool
804 }); ok {
805 return root.isDependencyRoot()
806 }
807 return false
808}
809
Justin Yun5f7f7e82019-11-18 19:52:14 +0900810// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
811// "product" and "vendor" variant modules return true for this function.
812// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
813// "soc_specific: true" and more vendor installed modules are included here.
814// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
815// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700816func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900817 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700818}
819
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800820func (c *Module) isCoverageVariant() bool {
821 return c.coverage.Properties.IsCoverageVariant
822}
823
Peter Collingbournead84f972019-12-17 16:46:18 -0800824func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800825 return inList(c.Name(), ndkMigratedLibs)
826}
827
Inseob Kim9516ee92019-05-09 10:56:13 +0900828func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800829 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900830 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800831}
832
Inseob Kim9516ee92019-05-09 10:56:13 +0900833func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800834 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900835 name := c.BaseModuleName()
836 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800837}
838
Inseob Kim9516ee92019-05-09 10:56:13 +0900839func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800840 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900841 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800842}
843
Ivan Lozano52767be2019-10-18 14:49:46 -0700844func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800845 if vndkdep := c.vndkdep; vndkdep != nil {
846 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900847 }
848 return false
849}
850
Yi Kong7e53c572018-02-14 18:16:12 +0800851func (c *Module) isPgoCompile() bool {
852 if pgo := c.pgo; pgo != nil {
853 return pgo.Properties.PgoCompile
854 }
855 return false
856}
857
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800858func (c *Module) isNDKStubLibrary() bool {
859 if _, ok := c.compiler.(*stubDecorator); ok {
860 return true
861 }
862 return false
863}
864
Logan Chienf3511742017-10-31 18:04:35 +0800865func (c *Module) isVndkSp() bool {
866 if vndkdep := c.vndkdep; vndkdep != nil {
867 return vndkdep.isVndkSp()
868 }
869 return false
870}
871
872func (c *Module) isVndkExt() bool {
873 if vndkdep := c.vndkdep; vndkdep != nil {
874 return vndkdep.isVndkExt()
875 }
876 return false
877}
878
Ivan Lozano52767be2019-10-18 14:49:46 -0700879func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900880 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800881}
882
Logan Chienf3511742017-10-31 18:04:35 +0800883func (c *Module) getVndkExtendsModuleName() string {
884 if vndkdep := c.vndkdep; vndkdep != nil {
885 return vndkdep.getVndkExtendsModuleName()
886 }
887 return ""
888}
889
Justin Yun5f7f7e82019-11-18 19:52:14 +0900890// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900891// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700892func (c *Module) HasVendorVariant() bool {
893 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900894}
895
Justin Yun5f7f7e82019-11-18 19:52:14 +0900896const (
897 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
898 // against the VNDK.
899 VendorVariationPrefix = "vendor."
900
901 // ProductVariationPrefix is the variant prefix used for /product code that compiles
902 // against the VNDK.
903 ProductVariationPrefix = "product."
904)
905
906// Returns true if the module is "product" variant. Usually these modules are installed in /product
907func (c *Module) inProduct() bool {
908 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
909}
910
911// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
912func (c *Module) inVendor() bool {
913 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
914}
915
Yifan Hong1b3348d2020-01-21 15:53:22 -0800916func (c *Module) InRamdisk() bool {
917 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
918}
919
Ivan Lozano52767be2019-10-18 14:49:46 -0700920func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800921 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900922}
923
Yifan Hong1b3348d2020-01-21 15:53:22 -0800924func (c *Module) OnlyInRamdisk() bool {
925 return c.ModuleBase.InstallInRamdisk()
926}
927
Ivan Lozano52767be2019-10-18 14:49:46 -0700928func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900929 return c.ModuleBase.InstallInRecovery()
930}
931
Jiyong Park25fc6a92018-11-18 18:02:45 +0900932func (c *Module) IsStubs() bool {
933 if library, ok := c.linker.(*libraryDecorator); ok {
934 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900935 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
936 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900937 }
938 return false
939}
940
941func (c *Module) HasStubsVariants() bool {
942 if library, ok := c.linker.(*libraryDecorator); ok {
943 return len(library.Properties.Stubs.Versions) > 0
944 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700945 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
946 return len(library.Properties.Stubs.Versions) > 0
947 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900948 return false
949}
950
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900951func (c *Module) bootstrap() bool {
952 return Bool(c.Properties.Bootstrap)
953}
954
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700955func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700956 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
957 if c.Target().NativeBridge == android.NativeBridgeEnabled {
958 return false
959 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700960 return c.linker != nil && c.linker.nativeCoverage()
961}
962
Inseob Kim8471cda2019-11-15 09:59:12 +0900963func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900964 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
965 return true
966 }
967 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
968 return true
969 }
970 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
971 return true
972 }
973 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900974}
975
Jiyong Park73c54ee2019-10-22 20:31:18 +0900976func (c *Module) ExportedIncludeDirs() android.Paths {
977 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
978 return flagsProducer.exportedDirs()
979 }
Jiyong Park232e7852019-11-04 12:23:40 +0900980 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900981}
982
983func (c *Module) ExportedSystemIncludeDirs() android.Paths {
984 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
985 return flagsProducer.exportedSystemDirs()
986 }
Jiyong Park232e7852019-11-04 12:23:40 +0900987 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900988}
989
990func (c *Module) ExportedFlags() []string {
991 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
992 return flagsProducer.exportedFlags()
993 }
Jiyong Park232e7852019-11-04 12:23:40 +0900994 return nil
995}
996
997func (c *Module) ExportedDeps() android.Paths {
998 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
999 return flagsProducer.exportedDeps()
1000 }
1001 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001002}
1003
Inseob Kimd110f872019-12-06 13:15:38 +09001004func (c *Module) ExportedGeneratedHeaders() android.Paths {
1005 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1006 return flagsProducer.exportedGeneratedHeaders()
1007 }
1008 return nil
1009}
1010
Jiyong Parkf1194352019-02-25 11:05:47 +09001011func isBionic(name string) bool {
1012 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001013 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001014 return true
1015 }
1016 return false
1017}
1018
Martin Stjernholm279de572019-09-10 23:18:20 +01001019func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001020 if name == "libclang_rt.hwasan-aarch64-android" {
1021 return inList("hwaddress", config.SanitizeDevice())
1022 }
1023 return isBionic(name)
1024}
1025
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001026func (c *Module) XrefCcFiles() android.Paths {
1027 return c.kytheFiles
1028}
1029
Colin Crossca860ac2016-01-04 14:34:37 -08001030type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001031 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001032 moduleContextImpl
1033}
1034
Colin Cross37047f12016-12-13 17:06:13 -08001035type depsContext struct {
1036 android.BottomUpMutatorContext
1037 moduleContextImpl
1038}
1039
Colin Crossca860ac2016-01-04 14:34:37 -08001040type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001041 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001042 moduleContextImpl
1043}
1044
Justin Yun5f7f7e82019-11-18 19:52:14 +09001045func (ctx *moduleContext) ProductSpecific() bool {
1046 return ctx.ModuleContext.ProductSpecific() ||
1047 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1048}
1049
Jiyong Park2db76922017-11-08 16:03:48 +09001050func (ctx *moduleContext) SocSpecific() bool {
1051 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001052 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001053}
1054
Colin Crossca860ac2016-01-04 14:34:37 -08001055type moduleContextImpl struct {
1056 mod *Module
1057 ctx BaseModuleContext
1058}
1059
Colin Crossb98c8b02016-07-29 13:44:28 -07001060func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001061 return ctx.mod.toolchain(ctx.ctx)
1062}
1063
1064func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001065 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001066}
1067
1068func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001069 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001070}
1071
Jiyong Park1d1119f2019-07-29 21:27:18 +09001072func (ctx *moduleContextImpl) header() bool {
1073 return ctx.mod.header()
1074}
1075
Jooyung Hanccce2f22020-03-07 03:45:53 +09001076func (ctx *moduleContextImpl) canUseSdk() bool {
1077 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1078}
1079
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001080func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Hanccce2f22020-03-07 03:45:53 +09001081 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001082 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001083 }
1084 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001085}
1086
1087func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001088 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001090 vndkVer := ctx.mod.VndkVersion()
1091 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1092 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001093 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001094 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001095 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001096 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001097 }
1098 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001099}
1100
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001101func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001102 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001103}
Justin Yun8effde42017-06-23 19:24:43 +09001104
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001105func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001106 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001107}
1108
Inseob Kim9516ee92019-05-09 10:56:13 +09001109func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1110 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001111}
1112
Inseob Kim9516ee92019-05-09 10:56:13 +09001113func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1114 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001115}
1116
Inseob Kim9516ee92019-05-09 10:56:13 +09001117func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1118 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001119}
1120
Logan Chienf3511742017-10-31 18:04:35 +08001121func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001122 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001123}
1124
Yi Kong7e53c572018-02-14 18:16:12 +08001125func (ctx *moduleContextImpl) isPgoCompile() bool {
1126 return ctx.mod.isPgoCompile()
1127}
1128
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001129func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1130 return ctx.mod.isNDKStubLibrary()
1131}
1132
Justin Yun8effde42017-06-23 19:24:43 +09001133func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001134 return ctx.mod.isVndkSp()
1135}
1136
1137func (ctx *moduleContextImpl) isVndkExt() bool {
1138 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001139}
1140
Vic Yangefd249e2018-11-12 20:19:56 -08001141func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001142 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001143}
1144
Justin Yun5f7f7e82019-11-18 19:52:14 +09001145func (ctx *moduleContextImpl) inProduct() bool {
1146 return ctx.mod.inProduct()
1147}
1148
1149func (ctx *moduleContextImpl) inVendor() bool {
1150 return ctx.mod.inVendor()
1151}
1152
Yifan Hong1b3348d2020-01-21 15:53:22 -08001153func (ctx *moduleContextImpl) inRamdisk() bool {
1154 return ctx.mod.InRamdisk()
1155}
1156
Jiyong Parkf9332f12018-02-01 00:54:12 +09001157func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001158 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001159}
1160
Logan Chien2f2b8902018-07-10 15:01:19 +08001161// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001162func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001163 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1164 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001165 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001166
1167 if ctx.ctx.Fuchsia() {
1168 return false
1169 }
1170
Logan Chien2f2b8902018-07-10 15:01:19 +08001171 if sanitize := ctx.mod.sanitize; sanitize != nil {
1172 if !sanitize.isVariantOnProductionDevice() {
1173 return false
1174 }
1175 }
1176 if !ctx.ctx.Device() {
1177 // Host modules do not need ABI dumps.
1178 return false
1179 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001180 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001181 // Stubs do not need ABI dumps.
1182 return false
1183 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001184 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001185}
1186
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001187func (ctx *moduleContextImpl) selectedStl() string {
1188 if stl := ctx.mod.stl; stl != nil {
1189 return stl.Properties.SelectedStl
1190 }
1191 return ""
1192}
1193
Ivan Lozanobd721262018-11-27 14:33:03 -08001194func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1195 return ctx.mod.linker.useClangLld(actx)
1196}
1197
Colin Crossce75d2c2016-10-06 16:12:58 -07001198func (ctx *moduleContextImpl) baseModuleName() string {
1199 return ctx.mod.ModuleBase.BaseModuleName()
1200}
1201
Logan Chienf3511742017-10-31 18:04:35 +08001202func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1203 return ctx.mod.getVndkExtendsModuleName()
1204}
1205
Logan Chiene274fc92019-12-03 11:18:32 -08001206func (ctx *moduleContextImpl) isForPlatform() bool {
1207 return ctx.mod.IsForPlatform()
1208}
1209
Jiyong Park58e364a2019-01-19 19:24:06 +09001210func (ctx *moduleContextImpl) apexName() string {
1211 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001212}
1213
Jooyung Hanccce2f22020-03-07 03:45:53 +09001214func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han75568392020-03-20 04:29:24 +09001215 return ctx.mod.apexSdkVersion
Jooyung Hanccce2f22020-03-07 03:45:53 +09001216}
1217
Jiyong Parkb0788572018-12-20 22:10:17 +09001218func (ctx *moduleContextImpl) hasStubsVariants() bool {
1219 return ctx.mod.HasStubsVariants()
1220}
1221
1222func (ctx *moduleContextImpl) isStubs() bool {
1223 return ctx.mod.IsStubs()
1224}
1225
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001226func (ctx *moduleContextImpl) bootstrap() bool {
1227 return ctx.mod.bootstrap()
1228}
1229
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001230func (ctx *moduleContextImpl) nativeCoverage() bool {
1231 return ctx.mod.nativeCoverage()
1232}
1233
Colin Cross635c3b02016-05-18 15:37:25 -07001234func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001235 return &Module{
1236 hod: hod,
1237 multilib: multilib,
1238 }
1239}
1240
Colin Cross635c3b02016-05-18 15:37:25 -07001241func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001242 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001243 module.features = []feature{
1244 &tidyFeature{},
1245 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001246 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001247 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001248 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001249 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001250 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001251 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001252 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001253 return module
1254}
1255
Colin Crossce75d2c2016-10-06 16:12:58 -07001256func (c *Module) Prebuilt() *android.Prebuilt {
1257 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1258 return p.prebuilt()
1259 }
1260 return nil
1261}
1262
1263func (c *Module) Name() string {
1264 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001265 if p, ok := c.linker.(interface {
1266 Name(string) string
1267 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001268 name = p.Name(name)
1269 }
1270 return name
1271}
1272
Alex Light3d673592019-01-18 14:37:31 -08001273func (c *Module) Symlinks() []string {
1274 if p, ok := c.installer.(interface {
1275 symlinkList() []string
1276 }); ok {
1277 return p.symlinkList()
1278 }
1279 return nil
1280}
1281
Jeff Gaston294356f2017-09-27 17:05:30 -07001282// orderDeps reorders dependencies into a list such that if module A depends on B, then
1283// A will precede B in the resultant list.
1284// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001285// Note that directSharedDeps should be the analogous static library for each shared lib dep
1286func 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 -07001287 // If A depends on B, then
1288 // Every list containing A will also contain B later in the list
1289 // So, after concatenating all lists, the final instance of B will have come from the same
1290 // original list as the final instance of A
1291 // So, the final instance of B will be later in the concatenation than the final A
1292 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1293 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001294 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001295 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001296 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1297 }
1298 for _, dep := range directSharedDeps {
1299 orderedAllDeps = append(orderedAllDeps, dep)
1300 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001301 }
1302
Colin Crossb6715442017-10-24 11:13:31 -07001303 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001304
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001305 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001306 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001307 // resultant list to only what the caller has chosen to include in directStaticDeps
1308 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001309
1310 return orderedAllDeps, orderedDeclaredDeps
1311}
1312
Ivan Lozano183a3212019-10-18 14:18:45 -07001313func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001314 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001315 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001316 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1317 staticDepFiles := []android.Path{}
1318 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001319 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1320 if dep.OutputFile().Valid() {
1321 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1322 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1323 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001324 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001325 sharedDepFiles := []android.Path{}
1326 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001327 if sharedDep.HasStaticVariant() {
1328 staticAnalogue := sharedDep.GetStaticVariant()
1329 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1330 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001331 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001332 }
1333
1334 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001335 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1336 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001337
1338 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001339}
1340
Roland Levillainf89cd092019-07-29 16:22:59 +01001341func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1342 test, ok := c.linker.(testPerSrc)
1343 return ok && test.isAllTestsVariation()
1344}
1345
Justin Yun5f7f7e82019-11-18 19:52:14 +09001346func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1347 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1348 // "current", it will append the VNDK version to the name suffix.
1349 var vndkVersion string
1350 var nameSuffix string
1351 if c.inProduct() {
1352 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1353 nameSuffix = productSuffix
1354 } else {
1355 vndkVersion = ctx.DeviceConfig().VndkVersion()
1356 nameSuffix = vendorSuffix
1357 }
1358 if vndkVersion == "current" {
1359 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1360 }
1361 if c.Properties.VndkVersion != vndkVersion {
1362 // add version suffix only if the module is using different vndk version than the
1363 // version in product or vendor partition.
1364 nameSuffix += "." + c.Properties.VndkVersion
1365 }
1366 return nameSuffix
1367}
1368
Colin Cross635c3b02016-05-18 15:37:25 -07001369func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001370 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001371 //
1372 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1373 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1374 // module and return early, as this module does not produce an output file per se.
1375 if c.IsTestPerSrcAllTestsVariation() {
1376 c.outputFile = android.OptionalPath{}
1377 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001378 }
1379
Jooyung Han38002912019-05-16 04:01:54 +09001380 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001381
Inseob Kim64c43952019-08-26 16:52:35 +09001382 c.Properties.SubName = ""
1383
1384 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1385 c.Properties.SubName += nativeBridgeSuffix
1386 }
1387
Justin Yun5f7f7e82019-11-18 19:52:14 +09001388 _, llndk := c.linker.(*llndkStubDecorator)
1389 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1390 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1391 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1392 // added for product variant only when we have vendor and product variants with core
1393 // variant. The suffix is not added for vendor-only or product-only module.
1394 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1395 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001396 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1397 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1398 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001399 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1400 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001401 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001402 c.Properties.SubName += recoverySuffix
1403 }
1404
Colin Crossca860ac2016-01-04 14:34:37 -08001405 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001406 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001407 moduleContextImpl: moduleContextImpl{
1408 mod: c,
1409 },
1410 }
1411 ctx.ctx = ctx
1412
Colin Crossf18e1102017-11-16 14:33:08 -08001413 deps := c.depsToPaths(ctx)
1414 if ctx.Failed() {
1415 return
1416 }
1417
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001418 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1419 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1420 }
1421
Colin Crossca860ac2016-01-04 14:34:37 -08001422 flags := Flags{
1423 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001424 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001425 }
Colin Crossca860ac2016-01-04 14:34:37 -08001426 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001427 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001428 }
1429 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001430 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001431 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001432 if c.stl != nil {
1433 flags = c.stl.flags(ctx, flags)
1434 }
Colin Cross16b23492016-01-06 14:41:07 -08001435 if c.sanitize != nil {
1436 flags = c.sanitize.flags(ctx, flags)
1437 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001438 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001439 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001440 }
Stephen Craneba090d12017-05-09 15:44:35 -07001441 if c.lto != nil {
1442 flags = c.lto.flags(ctx, flags)
1443 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001444 if c.pgo != nil {
1445 flags = c.pgo.flags(ctx, flags)
1446 }
Colin Crossca860ac2016-01-04 14:34:37 -08001447 for _, feature := range c.features {
1448 flags = feature.flags(ctx, flags)
1449 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001450 if ctx.Failed() {
1451 return
1452 }
1453
Colin Cross4af21ed2019-11-04 09:37:55 -08001454 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1455 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1456 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001457
Colin Cross4af21ed2019-11-04 09:37:55 -08001458 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001459
1460 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001461 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001462 }
1463 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001464 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001465 }
1466
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001467 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001468 // We need access to all the flags seen by a source file.
1469 if c.sabi != nil {
1470 flags = c.sabi.flags(ctx, flags)
1471 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001472
Colin Cross4af21ed2019-11-04 09:37:55 -08001473 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001474
Colin Crossca860ac2016-01-04 14:34:37 -08001475 // Optimization to reduce size of build.ninja
1476 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001477 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1478 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1479 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1480 flags.Local.CFlags = []string{"$cflags"}
1481 flags.Local.CppFlags = []string{"$cppflags"}
1482 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001483
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001484 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001485 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001486 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001487 if ctx.Failed() {
1488 return
1489 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001490 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001491 }
1492
Colin Crossca860ac2016-01-04 14:34:37 -08001493 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001494 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001495 if ctx.Failed() {
1496 return
1497 }
Colin Cross635c3b02016-05-18 15:37:25 -07001498 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001499
1500 // If a lib is directly included in any of the APEXes, unhide the stubs
1501 // variant having the latest version gets visible to make. In addition,
1502 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1503 // force anything in the make world to link against the stubs library.
1504 // (unless it is explicitly referenced via .bootstrap suffix or the
1505 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001506 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001507 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001508 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001509 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001510 c.Properties.HideFromMake = false // unhide
1511 // Note: this is still non-installable
1512 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001513
1514 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1515 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1516 if isSnapshotAware(ctx, c) {
1517 i.collectHeadersForSnapshot(ctx)
1518 }
1519 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001520 }
Colin Cross5049f022015-03-18 13:28:46 -07001521
Inseob Kim1f086e22019-05-09 13:29:15 +09001522 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001523 c.installer.install(ctx, c.outputFile.Path())
1524 if ctx.Failed() {
1525 return
Colin Crossca860ac2016-01-04 14:34:37 -08001526 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001527 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1528 // If the module has been specifically configure to not be installed then
1529 // skip the installation as otherwise it will break when running inside make
1530 // as the output path to install will not be specified. Not all uninstallable
1531 // modules can skip installation as some are needed for resolving make side
1532 // dependencies.
1533 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001534 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001535}
1536
Colin Cross0ea8ba82019-06-06 14:33:29 -07001537func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001538 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001539 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001540 }
Colin Crossca860ac2016-01-04 14:34:37 -08001541 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001542}
1543
Colin Crossca860ac2016-01-04 14:34:37 -08001544func (c *Module) begin(ctx BaseModuleContext) {
1545 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001546 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001547 }
Colin Crossca860ac2016-01-04 14:34:37 -08001548 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001549 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001550 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001551 if c.stl != nil {
1552 c.stl.begin(ctx)
1553 }
Colin Cross16b23492016-01-06 14:41:07 -08001554 if c.sanitize != nil {
1555 c.sanitize.begin(ctx)
1556 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001557 if c.coverage != nil {
1558 c.coverage.begin(ctx)
1559 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001560 if c.sabi != nil {
1561 c.sabi.begin(ctx)
1562 }
Justin Yun8effde42017-06-23 19:24:43 +09001563 if c.vndkdep != nil {
1564 c.vndkdep.begin(ctx)
1565 }
Stephen Craneba090d12017-05-09 15:44:35 -07001566 if c.lto != nil {
1567 c.lto.begin(ctx)
1568 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001569 if c.pgo != nil {
1570 c.pgo.begin(ctx)
1571 }
Colin Crossca860ac2016-01-04 14:34:37 -08001572 for _, feature := range c.features {
1573 feature.begin(ctx)
1574 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001575 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001576 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001577 if err != nil {
1578 ctx.PropertyErrorf("sdk_version", err.Error())
1579 }
Nan Zhang0007d812017-11-07 10:57:05 -08001580 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001581 }
Colin Crossca860ac2016-01-04 14:34:37 -08001582}
1583
Colin Cross37047f12016-12-13 17:06:13 -08001584func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001585 deps := Deps{}
1586
1587 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001588 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001589 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001590 // Add the PGO dependency (the clang_rt.profile runtime library), which
1591 // sometimes depends on symbols from libgcc, before libgcc gets added
1592 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001593 if c.pgo != nil {
1594 deps = c.pgo.deps(ctx, deps)
1595 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001596 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001597 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001598 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001599 if c.stl != nil {
1600 deps = c.stl.deps(ctx, deps)
1601 }
Colin Cross16b23492016-01-06 14:41:07 -08001602 if c.sanitize != nil {
1603 deps = c.sanitize.deps(ctx, deps)
1604 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001605 if c.coverage != nil {
1606 deps = c.coverage.deps(ctx, deps)
1607 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001608 if c.sabi != nil {
1609 deps = c.sabi.deps(ctx, deps)
1610 }
Justin Yun8effde42017-06-23 19:24:43 +09001611 if c.vndkdep != nil {
1612 deps = c.vndkdep.deps(ctx, deps)
1613 }
Stephen Craneba090d12017-05-09 15:44:35 -07001614 if c.lto != nil {
1615 deps = c.lto.deps(ctx, deps)
1616 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001617 for _, feature := range c.features {
1618 deps = feature.deps(ctx, deps)
1619 }
1620
Colin Crossb6715442017-10-24 11:13:31 -07001621 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1622 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1623 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1624 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1625 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1626 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001627 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001628
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001629 for _, lib := range deps.ReexportSharedLibHeaders {
1630 if !inList(lib, deps.SharedLibs) {
1631 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1632 }
1633 }
1634
1635 for _, lib := range deps.ReexportStaticLibHeaders {
1636 if !inList(lib, deps.StaticLibs) {
1637 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1638 }
1639 }
1640
Colin Cross5950f382016-12-13 12:50:57 -08001641 for _, lib := range deps.ReexportHeaderLibHeaders {
1642 if !inList(lib, deps.HeaderLibs) {
1643 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1644 }
1645 }
1646
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001647 for _, gen := range deps.ReexportGeneratedHeaders {
1648 if !inList(gen, deps.GeneratedHeaders) {
1649 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1650 }
1651 }
1652
Colin Crossc99deeb2016-04-11 15:06:20 -07001653 return deps
1654}
1655
Dan Albert7e9d2952016-08-04 13:02:36 -07001656func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001657 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001658 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001659 moduleContextImpl: moduleContextImpl{
1660 mod: c,
1661 },
1662 }
1663 ctx.ctx = ctx
1664
Colin Crossca860ac2016-01-04 14:34:37 -08001665 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001666}
1667
Jiyong Park7ed9de32018-10-15 22:25:07 +09001668// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001669func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001670 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1671 version := name[sharp+1:]
1672 libname := name[:sharp]
1673 return libname, version
1674 }
1675 return name, ""
1676}
1677
Colin Cross1e676be2016-10-12 14:38:15 -07001678func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001679 if !c.Enabled() {
1680 return
1681 }
1682
Colin Cross37047f12016-12-13 17:06:13 -08001683 ctx := &depsContext{
1684 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001685 moduleContextImpl: moduleContextImpl{
1686 mod: c,
1687 },
1688 }
1689 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001690
Colin Crossc99deeb2016-04-11 15:06:20 -07001691 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001692
Dan Albert914449f2016-06-17 16:45:24 -07001693 variantNdkLibs := []string{}
1694 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001695 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001696 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001697
Inseob Kimeec88e12020-01-22 11:11:29 +09001698 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001699 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001700 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001701 // 1. Name of an NDK library that refers to a prebuilt module.
1702 // For each of these, it adds the name of the prebuilt module (which will be in
1703 // prebuilts/ndk) to the list of nonvariant libs.
1704 // 2. Name of an NDK library that refers to an ndk_library module.
1705 // For each of these, it adds the name of the ndk_library module to the list of
1706 // variant libs.
1707 // 3. Anything else (so anything that isn't an NDK library).
1708 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001709 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001710 // The caller can then know to add the variantLibs dependencies differently from the
1711 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001712
Inseob Kim9516ee92019-05-09 10:56:13 +09001713 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001714 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1715
1716 rewriteVendorLibs := func(lib string) string {
1717 if isLlndkLibrary(lib, ctx.Config()) {
1718 return lib + llndkLibrarySuffix
1719 }
1720
1721 // only modules with BOARD_VNDK_VERSION uses snapshot.
1722 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1723 return lib
1724 }
1725
1726 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1727 return snapshot
1728 }
1729
1730 return lib
1731 }
1732
1733 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001734 variantLibs = []string{}
1735 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001736 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001737 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001738 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001739 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1740 if !inList(name, ndkMigratedLibs) {
1741 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001742 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001743 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001744 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001745 } else if ctx.useVndk() {
1746 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001747 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001748 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001749 if actx.OtherModuleExists(vendorPublicLib) {
1750 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1751 } else {
1752 // This can happen if vendor_public_library module is defined in a
1753 // namespace that isn't visible to the current module. In that case,
1754 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001755 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001756 }
Dan Albert914449f2016-06-17 16:45:24 -07001757 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001758 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001759 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001760 }
1761 }
Dan Albert914449f2016-06-17 16:45:24 -07001762 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001763 }
1764
Inseob Kimeec88e12020-01-22 11:11:29 +09001765 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1766 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1767 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1768 if ctx.useVndk() {
1769 for idx, lib := range deps.RuntimeLibs {
1770 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1771 }
1772 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001773 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001774
Jiyong Park7e636d02019-01-28 16:16:54 +09001775 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001776 if c.linker != nil {
1777 if library, ok := c.linker.(*libraryDecorator); ok {
1778 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001779 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001780 }
1781 }
1782 }
1783
Inseob Kimeec88e12020-01-22 11:11:29 +09001784 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1785 // only modules with BOARD_VNDK_VERSION uses snapshot.
1786 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1787 return lib
1788 }
1789
1790 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1791 return snapshot
1792 }
1793
1794 return lib
1795 }
1796
1797 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001798 for _, lib := range deps.HeaderLibs {
1799 depTag := headerDepTag
1800 if inList(lib, deps.ReexportHeaderLibHeaders) {
1801 depTag = headerExportDepTag
1802 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001803
1804 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1805
Jiyong Park7e636d02019-01-28 16:16:54 +09001806 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001807 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001808 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001809 } else {
1810 actx.AddVariationDependencies(nil, depTag, lib)
1811 }
1812 }
1813
1814 if buildStubs {
1815 // Stubs lib does not have dependency to other static/shared libraries.
1816 // Don't proceed.
1817 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001818 }
Colin Cross5950f382016-12-13 12:50:57 -08001819
Inseob Kimc0907f12019-02-08 21:00:45 +09001820 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001821 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001822
Jiyong Park5d1598f2019-02-25 22:14:17 +09001823 for _, lib := range deps.WholeStaticLibs {
1824 depTag := wholeStaticDepTag
1825 if impl, ok := syspropImplLibraries[lib]; ok {
1826 lib = impl
1827 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001828
1829 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1830
Jiyong Park5d1598f2019-02-25 22:14:17 +09001831 actx.AddVariationDependencies([]blueprint.Variation{
1832 {Mutator: "link", Variation: "static"},
1833 }, depTag, lib)
1834 }
1835
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001836 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001837 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001838 if inList(lib, deps.ReexportStaticLibHeaders) {
1839 depTag = staticExportDepTag
1840 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001841
1842 if impl, ok := syspropImplLibraries[lib]; ok {
1843 lib = impl
1844 }
1845
Inseob Kimeec88e12020-01-22 11:11:29 +09001846 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1847
Dan Willemsen59339a22018-07-22 21:18:45 -07001848 actx.AddVariationDependencies([]blueprint.Variation{
1849 {Mutator: "link", Variation: "static"},
1850 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001851 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001852
Jooyung Han75568392020-03-20 04:29:24 +09001853 // staticUnwinderDep is treated as staticDep for Q apexes
1854 // so that native libraries/binaries are linked with static unwinder
1855 // because Q libc doesn't have unwinder APIs
1856 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001857 actx.AddVariationDependencies([]blueprint.Variation{
1858 {Mutator: "link", Variation: "static"},
1859 }, staticUnwinderDepTag, staticUnwinder(actx))
1860 }
1861
Inseob Kimeec88e12020-01-22 11:11:29 +09001862 for _, lib := range deps.LateStaticLibs {
1863 actx.AddVariationDependencies([]blueprint.Variation{
1864 {Mutator: "link", Variation: "static"},
1865 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1866 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001867
Ivan Lozano183a3212019-10-18 14:18:45 -07001868 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001869 var variations []blueprint.Variation
1870 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han61b66e92020-03-21 14:21:46 +00001871 versionVariantAvail := !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001872 if version != "" && versionVariantAvail {
1873 // Version is explicitly specified. i.e. libFoo#30
1874 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001875 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001876 }
1877 actx.AddVariationDependencies(variations, depTag, name)
1878
Jooyung Han03b51852020-02-26 22:45:42 +09001879 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001880 // The stubs library will be used when the depending module is built for APEX and
1881 // the dependent module is not in the same APEX.
Jooyung Han03b51852020-02-26 22:45:42 +09001882 if version == "" && versionVariantAvail {
1883 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1884 // Note that depTag.ExplicitlyVersioned is false in this case.
1885 actx.AddVariationDependencies([]blueprint.Variation{
1886 {Mutator: "link", Variation: "shared"},
1887 {Mutator: "version", Variation: ver},
1888 }, depTag, name)
1889 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001890 }
1891 }
1892
Jiyong Park7ed9de32018-10-15 22:25:07 +09001893 // shared lib names without the #version suffix
1894 var sharedLibNames []string
1895
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001896 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001897 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001898 if c.static() {
1899 depTag = SharedFromStaticDepTag
1900 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001901 if inList(lib, deps.ReexportSharedLibHeaders) {
1902 depTag = sharedExportDepTag
1903 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001904
1905 if impl, ok := syspropImplLibraries[lib]; ok {
1906 lib = impl
1907 }
1908
Jiyong Park73c54ee2019-10-22 20:31:18 +09001909 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001910 sharedLibNames = append(sharedLibNames, name)
1911
Jiyong Park25fc6a92018-11-18 18:02:45 +09001912 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001913 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001914
Jiyong Park7ed9de32018-10-15 22:25:07 +09001915 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001916 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001917 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1918 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1919 // linking against both the stubs lib and the non-stubs lib at the same time.
1920 continue
1921 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001922 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001923 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001924
Dan Willemsen59339a22018-07-22 21:18:45 -07001925 actx.AddVariationDependencies([]blueprint.Variation{
1926 {Mutator: "link", Variation: "shared"},
1927 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001928
Colin Cross68861832016-07-08 10:41:41 -07001929 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001930
1931 for _, gen := range deps.GeneratedHeaders {
1932 depTag := genHeaderDepTag
1933 if inList(gen, deps.ReexportGeneratedHeaders) {
1934 depTag = genHeaderExportDepTag
1935 }
1936 actx.AddDependency(c, depTag, gen)
1937 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001938
Colin Cross42d48b72018-08-29 14:10:52 -07001939 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001940
1941 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001942 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001943 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001944 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001945 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001946 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001947 if deps.LinkerFlagsFile != "" {
1948 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1949 }
1950 if deps.DynamicLinker != "" {
1951 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001952 }
Dan Albert914449f2016-06-17 16:45:24 -07001953
1954 version := ctx.sdkVersion()
1955 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001956 {Mutator: "ndk_api", Variation: version},
1957 {Mutator: "link", Variation: "shared"},
1958 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001959 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001960 {Mutator: "ndk_api", Variation: version},
1961 {Mutator: "link", Variation: "shared"},
1962 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001963
1964 if vndkdep := c.vndkdep; vndkdep != nil {
1965 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001966 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001967 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001968 {Mutator: "link", Variation: "shared"},
1969 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001970 }
1971 }
Colin Cross6362e272015-10-29 15:25:03 -07001972}
Colin Cross21b9a242015-03-24 14:15:58 -07001973
Colin Crosse40b4ea2018-10-02 22:25:58 -07001974func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001975 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1976 c.beginMutator(ctx)
1977 }
1978}
1979
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001980// Whether a module can link to another module, taking into
1981// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001982func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1983 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001984 // Host code is not restricted
1985 return
1986 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001987
1988 // VNDK is cc.Module supported only for now.
1989 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001990 // Though vendor code is limited by the vendor mutator,
1991 // each vendor-available module needs to check
1992 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001993 if ccTo, ok := to.(*Module); ok {
1994 if ccFrom.vndkdep != nil {
1995 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1996 }
1997 } else {
1998 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001999 }
2000 return
2001 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002002 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002003 // Platform code can link to anything
2004 return
2005 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002006 if from.InRamdisk() {
2007 // Ramdisk code is not NDK
2008 return
2009 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002010 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002011 // Recovery code is not NDK
2012 return
2013 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002014 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002015 // These are always allowed
2016 return
2017 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002018 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002019 // These are allowed, but they don't set sdk_version
2020 return
2021 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002022 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002023 // These aren't real libraries, but are the stub shared libraries that are included in
2024 // the NDK.
2025 return
2026 }
Logan Chien834b9a62019-01-14 15:39:03 +08002027
Ivan Lozano52767be2019-10-18 14:49:46 -07002028 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002029 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2030 // to link to libc++ (non-NDK and without sdk_version).
2031 return
2032 }
2033
Ivan Lozano52767be2019-10-18 14:49:46 -07002034 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002035 // NDK code linking to platform code is never okay.
2036 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002037 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002038 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002039 }
2040
2041 // At this point we know we have two NDK libraries, but we need to
2042 // check that we're not linking against anything built against a higher
2043 // API level, as it is only valid to link against older or equivalent
2044 // APIs.
2045
Inseob Kim01a28722018-04-11 09:48:45 +09002046 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002047 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002048 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002049 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002050 // Current can't be linked against by anything else.
2051 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002052 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002053 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002054 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002055 if err != nil {
2056 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002057 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002058 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002059 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002060 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002061 if err != nil {
2062 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002063 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002064 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002065 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002066
Inseob Kim01a28722018-04-11 09:48:45 +09002067 if toApi > fromApi {
2068 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002069 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002070 }
2071 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002072 }
Dan Albert202fe492017-12-15 13:56:59 -08002073
2074 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002075 fromStl := from.SelectedStl()
2076 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002077 if fromStl == "" || toStl == "" {
2078 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002079 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002080 // We can be permissive with the system "STL" since it is only the C++
2081 // ABI layer, but in the future we should make sure that everyone is
2082 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002083 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002084 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002085 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2086 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002087 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002088}
2089
Jiyong Park5fb8c102018-04-09 12:03:06 +09002090// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002091// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2092// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002093// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002094func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2095 check := func(child, parent android.Module) bool {
2096 to, ok := child.(*Module)
2097 if !ok {
2098 // follow thru cc.Defaults, etc.
2099 return true
2100 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002101
Jooyung Hana70f0672019-01-18 15:20:43 +09002102 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2103 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002104 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002105
2106 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002107 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002108 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002109 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002110
Jooyung Han0302a842019-10-30 18:43:49 +09002111 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002112 return false
2113 }
2114
2115 var stringPath []string
2116 for _, m := range ctx.GetWalkPath() {
2117 stringPath = append(stringPath, m.Name())
2118 }
2119 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2120 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2121 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2122 return false
2123 }
2124 if module, ok := ctx.Module().(*Module); ok {
2125 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002126 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002127 ctx.WalkDeps(check)
2128 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002129 }
2130 }
2131}
2132
Colin Crossc99deeb2016-04-11 15:06:20 -07002133// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002134func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002135 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002136
Ivan Lozano183a3212019-10-18 14:18:45 -07002137 directStaticDeps := []LinkableInterface{}
2138 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002139
Inseob Kim9516ee92019-05-09 10:56:13 +09002140 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2141
Inseob Kim69378442019-06-03 19:10:47 +09002142 reexportExporter := func(exporter exportedFlagsProducer) {
2143 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2144 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2145 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2146 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002147 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002148 }
2149
Colin Crossd11fcda2017-10-23 17:59:01 -07002150 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 depName := ctx.OtherModuleName(dep)
2152 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002153
Ivan Lozano52767be2019-10-18 14:49:46 -07002154 ccDep, ok := dep.(LinkableInterface)
2155 if !ok {
2156
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002157 // handling for a few module types that aren't cc Module but that are also supported
2158 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002159 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002160 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002161 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2162 genRule.GeneratedSourceFiles()...)
2163 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002164 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002165 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002166 // Support exported headers from a generated_sources dependency
2167 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002168 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002169 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002170 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002171 genRule.GeneratedSourceFiles()...)
2172 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002173 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002174 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002175 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002176 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002177 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002178 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2179 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002180 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002181 // 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 +09002182 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002183
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002184 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002185 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002186 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002187 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002188 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002189 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002190 files := genRule.GeneratedSourceFiles()
2191 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002192 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002193 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002194 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 -07002195 }
2196 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002197 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002198 }
Colin Crossca860ac2016-01-04 14:34:37 -08002199 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002200 return
2201 }
2202
Colin Crossfe17f6f2019-03-28 19:30:56 -07002203 if depTag == android.ProtoPluginDepTag {
2204 return
2205 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002206 if depTag == llndkImplDep {
2207 return
2208 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002209
Colin Crossd11fcda2017-10-23 17:59:01 -07002210 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002211 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2212 return
2213 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002214 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002215 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2216 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002217 return
2218 }
2219
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002220 // re-exporting flags
2221 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002222 // reusing objects only make sense for cc.Modules.
2223 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002224 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002226 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002227 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002228 return
2229 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002230 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002231
Jiyong Parke4bb9862019-02-01 00:31:10 +09002232 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002233 // staticVariants are a cc.Module specific concept.
2234 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002235 c.staticVariant = ccDep
2236 return
2237 }
2238 }
2239
Jooyung Han75568392020-03-20 04:29:24 +09002240 // For the dependency from platform to apex, use the latest stubs
2241 c.apexSdkVersion = android.FutureApiLevel
2242 if !c.IsForPlatform() {
2243 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2244 }
2245
2246 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2247 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2248 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2249 // (b/144430859)
2250 c.apexSdkVersion = android.FutureApiLevel
2251 }
2252
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002253 if depTag == staticUnwinderDepTag {
Jooyung Han75568392020-03-20 04:29:24 +09002254 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2255 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002256 depTag = StaticDepTag
2257 } else {
2258 return
2259 }
2260 }
2261
Ivan Lozano183a3212019-10-18 14:18:45 -07002262 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2263 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2264 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002265 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002266 if t, ok := depTag.(DependencyTag); ok {
2267 explicitlyVersioned = t.ExplicitlyVersioned
2268 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002269 depTag = t
2270 }
2271
Ivan Lozano183a3212019-10-18 14:18:45 -07002272 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002273 depIsStatic := false
2274 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002275 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002276 depIsStatic = true
2277 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002278 if ccDep.CcLibrary() && !depIsStatic {
2279 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002280 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002281 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002282 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002283
2284 var useThisDep bool
2285 if depIsStubs && explicitlyVersioned {
2286 // Always respect dependency to the versioned stubs (i.e. libX#10)
2287 useThisDep = true
2288 } else if !depHasStubs {
2289 // Use non-stub variant if that is the only choice
2290 // (i.e. depending on a lib without stubs.version property)
2291 useThisDep = true
2292 } else if c.IsForPlatform() {
2293 // If not building for APEX, use stubs only when it is from
2294 // an APEX (and not from platform)
2295 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002296 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2297 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002298 // always link to non-stub variant
2299 useThisDep = !depIsStubs
2300 }
2301 } else {
2302 // If building for APEX, use stubs only when it is not from
2303 // the same APEX
2304 useThisDep = (depInSameApex != depIsStubs)
2305 }
2306
Jooyung Han03b51852020-02-26 22:45:42 +09002307 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2308 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han75568392020-03-20 04:29:24 +09002309 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han03b51852020-02-26 22:45:42 +09002310 if err != nil {
2311 ctx.OtherModuleErrorf(dep, err.Error())
2312 return
2313 }
2314 if versionToUse != ccDep.StubsVersion() {
2315 useThisDep = false
2316 }
2317 }
2318
Jiyong Park25fc6a92018-11-18 18:02:45 +09002319 if !useThisDep {
2320 return // stop processing this dep
2321 }
2322 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002323 if c.UseVndk() {
2324 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2325 // by default, use current version of LLNDK
2326 versionToUse := ""
2327 versions := stubsVersionsFor(ctx.Config())[depName]
2328 if c.ApexName() != "" && len(versions) > 0 {
2329 // if this is for use_vendor apex && dep has stubsVersions
2330 // apply the same rule of apex sdk enforcement to choose right version
2331 var err error
Jooyung Han75568392020-03-20 04:29:24 +09002332 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han61b66e92020-03-21 14:21:46 +00002333 if err != nil {
2334 ctx.OtherModuleErrorf(dep, err.Error())
2335 return
2336 }
2337 }
2338 if versionToUse != ccDep.StubsVersion() {
2339 return
2340 }
2341 }
2342 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002343
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002344 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2345
Ivan Lozano52767be2019-10-18 14:49:46 -07002346 // Exporting flags only makes sense for cc.Modules
2347 if _, ok := ccDep.(*Module); ok {
2348 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002349 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002350 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2351 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002352 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002353
Ivan Lozano52767be2019-10-18 14:49:46 -07002354 if t.ReexportFlags {
2355 reexportExporter(i)
2356 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2357 // Re-exported shared library headers must be included as well since they can help us with type information
2358 // about template instantiations (instantiated from their headers).
2359 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2360 // scripts.
2361 c.sabi.Properties.ReexportedIncludes = append(
2362 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2363 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002364 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002365 }
Logan Chienf3511742017-10-31 18:04:35 +08002366 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002367 }
2368
Colin Cross26c34ed2016-09-30 17:10:16 -07002369 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002370 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002371
Ivan Lozano52767be2019-10-18 14:49:46 -07002372 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002373 depFile := android.OptionalPath{}
2374
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002375 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002376 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002377 ptr = &depPaths.SharedLibs
2378 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002379 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002380 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002381
Jiyong Park64a44f22019-01-18 14:37:08 +09002382 case earlySharedDepTag:
2383 ptr = &depPaths.EarlySharedLibs
2384 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002385 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002386 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002387 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002388 ptr = &depPaths.LateSharedLibs
2389 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002390 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002391 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002392 ptr = nil
2393 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002394 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002395 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002396 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002397 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002398 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002399 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002400 return
2401 }
2402
Ivan Lozano52767be2019-10-18 14:49:46 -07002403 // Because the static library objects are included, this only makes sense
2404 // in the context of proper cc.Modules.
2405 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2406 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2407 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2408 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2409 for i := range missingDeps {
2410 missingDeps[i] += postfix
2411 }
2412 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002413 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002414 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2415 } else {
2416 ctx.ModuleErrorf(
2417 "non-cc.Modules cannot be included as whole static libraries.", depName)
2418 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002419 }
Colin Cross5950f382016-12-13 12:50:57 -08002420 case headerDepTag:
2421 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002422 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002423 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002424 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002425 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002426 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002427 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002428 case dynamicLinkerDepTag:
2429 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002430 }
2431
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002432 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002433 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002434 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002435 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002436 return
2437 }
2438
2439 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002440 // in static libraries act as if they were whole static libraries. The same goes for
2441 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002442 // This should only be done for cc.Modules
2443 if c, ok := ccDep.(*Module); ok {
2444 staticLib := c.linker.(libraryInterface)
2445 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2446 staticLib.objs().coverageFiles...)
2447 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2448 staticLib.objs().sAbiDumpFiles...)
2449 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002450 }
2451
Colin Cross26c34ed2016-09-30 17:10:16 -07002452 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002453 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002454 if !ctx.Config().AllowMissingDependencies() {
2455 ctx.ModuleErrorf("module %q missing output file", depName)
2456 } else {
2457 ctx.AddMissingDependencies([]string{depName})
2458 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002459 return
2460 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002461 *ptr = append(*ptr, linkFile.Path())
2462 }
2463
Colin Crossc99deeb2016-04-11 15:06:20 -07002464 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002465 dep := depFile
2466 if !dep.Valid() {
2467 dep = linkFile
2468 }
2469 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002470 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002471
Inseob Kimeec88e12020-01-22 11:11:29 +09002472 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2473
2474 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002475 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002476 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002477 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002478 return libName
2479 }
2480
2481 makeLibName := func(depName string) string {
2482 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002483 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002484 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002485 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002486
Inseob Kimeec88e12020-01-22 11:11:29 +09002487 if c, ok := ccDep.(*Module); ok {
2488 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim752edec2020-03-14 01:30:34 +09002489 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002490 baseName := c.BaseModuleName()
Inseob Kim752edec2020-03-14 01:30:34 +09002491
2492 if c.IsVndk() {
2493 return baseName + ".vendor"
2494 }
2495
Inseob Kimeec88e12020-01-22 11:11:29 +09002496 if vendorSuffixModules[baseName] {
2497 return baseName + ".vendor"
2498 } else {
2499 return baseName
2500 }
2501 }
2502 }
2503
Yifan Hong1b3348d2020-01-21 15:53:22 -08002504 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002505 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2506 // core module instead.
2507 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002508 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002509 // The vendor module in Make will have been renamed to not conflict with the core
2510 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002511 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002512 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002513 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002514 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2515 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002516 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002517 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002518 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002519 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002520 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002521 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002522 }
Logan Chien43d34c32017-12-20 01:17:32 +08002523 }
2524
2525 // Export the shared libs to Make.
2526 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002527 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002528 if ccDep.CcLibrary() {
2529 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002530 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002531 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002532 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002533 c.Properties.ApexesProvidingSharedLibs = append(
2534 c.Properties.ApexesProvidingSharedLibs, an)
2535 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002536 }
2537 }
2538
Jiyong Park27b188b2017-07-18 13:23:39 +09002539 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002540 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002541 c.Properties.AndroidMkSharedLibs = append(
2542 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002543 // Record baseLibName for snapshots.
2544 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002545 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002546 c.Properties.AndroidMkSharedLibs = append(
2547 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002548 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002549 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002550 c.Properties.AndroidMkStaticLibs = append(
2551 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002552 case runtimeDepTag:
2553 c.Properties.AndroidMkRuntimeLibs = append(
2554 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002555 // Record baseLibName for snapshots.
2556 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002557 case wholeStaticDepTag:
2558 c.Properties.AndroidMkWholeStaticLibs = append(
2559 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002560 }
Colin Crossca860ac2016-01-04 14:34:37 -08002561 })
2562
Jeff Gaston294356f2017-09-27 17:05:30 -07002563 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002564 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002565
Colin Crossdd84e052017-05-17 13:44:16 -07002566 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002567 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002568 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2569 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002570 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002571 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002572 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2573 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002574 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002575 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002576 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002577
2578 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002579 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002580 }
Colin Crossdd84e052017-05-17 13:44:16 -07002581
Colin Crossca860ac2016-01-04 14:34:37 -08002582 return depPaths
2583}
2584
2585func (c *Module) InstallInData() bool {
2586 if c.installer == nil {
2587 return false
2588 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002589 return c.installer.inData()
2590}
2591
2592func (c *Module) InstallInSanitizerDir() bool {
2593 if c.installer == nil {
2594 return false
2595 }
2596 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002597 return true
2598 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002599 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002600}
2601
Yifan Hong1b3348d2020-01-21 15:53:22 -08002602func (c *Module) InstallInRamdisk() bool {
2603 return c.InRamdisk()
2604}
2605
Jiyong Parkf9332f12018-02-01 00:54:12 +09002606func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002607 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002608}
2609
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002610func (c *Module) HostToolPath() android.OptionalPath {
2611 if c.installer == nil {
2612 return android.OptionalPath{}
2613 }
2614 return c.installer.hostToolPath()
2615}
2616
Nan Zhangd4e641b2017-07-12 12:55:28 -07002617func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2618 return c.outputFile
2619}
2620
Colin Cross41955e82019-05-29 14:40:35 -07002621func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2622 switch tag {
2623 case "":
2624 if c.outputFile.Valid() {
2625 return android.Paths{c.outputFile.Path()}, nil
2626 }
2627 return android.Paths{}, nil
2628 default:
2629 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002630 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002631}
2632
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002633func (c *Module) static() bool {
2634 if static, ok := c.linker.(interface {
2635 static() bool
2636 }); ok {
2637 return static.static()
2638 }
2639 return false
2640}
2641
Jiyong Park379de2f2018-12-19 02:47:14 +09002642func (c *Module) staticBinary() bool {
2643 if static, ok := c.linker.(interface {
2644 staticBinary() bool
2645 }); ok {
2646 return static.staticBinary()
2647 }
2648 return false
2649}
2650
Jiyong Park1d1119f2019-07-29 21:27:18 +09002651func (c *Module) header() bool {
2652 if h, ok := c.linker.(interface {
2653 header() bool
2654 }); ok {
2655 return h.header()
2656 }
2657 return false
2658}
2659
Jooyung Han38002912019-05-16 04:01:54 +09002660func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002661 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002662 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2663 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002664 return "native:vndk"
2665 }
Jooyung Han38002912019-05-16 04:01:54 +09002666 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002667 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002668 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002669 if Bool(c.VendorProperties.Vendor_available) {
2670 return "native:vndk"
2671 }
2672 return "native:vndk_private"
2673 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002674 if c.inProduct() {
2675 return "native:product"
2676 }
Jooyung Han38002912019-05-16 04:01:54 +09002677 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002678 } else if c.InRamdisk() {
2679 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002680 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002681 return "native:recovery"
2682 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2683 return "native:ndk:none:none"
2684 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2685 //family, link := getNdkStlFamilyAndLinkType(c)
2686 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002687 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002688 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002689 } else {
2690 return "native:platform"
2691 }
2692}
2693
Jiyong Park9d452992018-10-03 00:38:19 +09002694// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002695// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002696func (c *Module) IsInstallableToApex() bool {
2697 if shared, ok := c.linker.(interface {
2698 shared() bool
2699 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002700 // Stub libs and prebuilt libs in a versioned SDK are not
2701 // installable to APEX even though they are shared libs.
2702 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002703 } else if _, ok := c.linker.(testPerSrc); ok {
2704 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002705 }
2706 return false
2707}
2708
Jiyong Parka90ca002019-10-07 15:47:24 +09002709func (c *Module) AvailableFor(what string) bool {
2710 if linker, ok := c.linker.(interface {
2711 availableFor(string) bool
2712 }); ok {
2713 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2714 } else {
2715 return c.ApexModuleBase.AvailableFor(what)
2716 }
2717}
2718
Paul Duffin0cb37b92020-03-04 14:52:46 +00002719// Return true if the module is ever installable.
2720func (c *Module) EverInstallable() bool {
2721 return c.installer != nil &&
2722 // Check to see whether the module is actually ever installable.
2723 c.installer.everInstallable()
2724}
2725
Inseob Kim1f086e22019-05-09 13:29:15 +09002726func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002727 ret := c.EverInstallable() &&
2728 // Check to see whether the module has been configured to not be installed.
2729 proptools.BoolDefault(c.Properties.Installable, true) &&
2730 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002731
2732 // The platform variant doesn't need further condition. Apex variants however might not
2733 // be installable because it will likely to be included in the APEX and won't appear
2734 // in the system partition.
2735 if c.IsForPlatform() {
2736 return ret
2737 }
2738
2739 // Special case for modules that are configured to be installed to /data, which includes
2740 // test modules. For these modules, both APEX and non-APEX variants are considered as
2741 // installable. This is because even the APEX variants won't be included in the APEX, but
2742 // will anyway be installed to /data/*.
2743 // See b/146995717
2744 if c.InstallInData() {
2745 return ret
2746 }
2747
2748 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002749}
2750
Logan Chien41eabe62019-04-10 13:33:58 +08002751func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2752 if c.linker != nil {
2753 if library, ok := c.linker.(*libraryDecorator); ok {
2754 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2755 }
2756 }
2757}
2758
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002759func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002760 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002761 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002762 if cc.HasStubsVariants() {
2763 if depTag.Shared && depTag.Library {
2764 // dynamic dep to a stubs lib crosses APEX boundary
2765 return false
2766 }
2767 if IsRuntimeDepTag(depTag) {
2768 // runtime dep to a stubs lib also crosses APEX boundary
2769 return false
2770 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002771 }
2772 if depTag.FromStatic {
2773 // shared_lib dependency from a static lib is considered as crossing
2774 // the APEX boundary because the dependency doesn't actually is
2775 // linked; the dependency is used only during the compilation phase.
2776 return false
2777 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002778 }
2779 }
2780 return true
2781}
2782
Colin Cross2ba19d92015-05-07 15:44:20 -07002783//
Colin Crosscfad1192015-11-02 16:43:11 -08002784// Defaults
2785//
Colin Crossca860ac2016-01-04 14:34:37 -08002786type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002787 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002788 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002789 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002790}
2791
Patrice Arrudac249c712019-03-19 17:00:29 -07002792// cc_defaults provides a set of properties that can be inherited by other cc
2793// modules. A module can use the properties from a cc_defaults using
2794// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2795// merged (when possible) by prepending the default module's values to the
2796// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002797func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002798 return DefaultsFactory()
2799}
2800
Colin Cross36242852017-06-23 15:06:31 -07002801func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002802 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002803
Colin Cross36242852017-06-23 15:06:31 -07002804 module.AddProperties(props...)
2805 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002806 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002807 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002808 &BaseCompilerProperties{},
2809 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002810 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002811 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002812 &StaticProperties{},
2813 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002814 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002815 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002816 &TestProperties{},
2817 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002818 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002819 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002820 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002821 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002822 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002823 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002824 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002825 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002826 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002827 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002828 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002829 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002830 )
Colin Crosscfad1192015-11-02 16:43:11 -08002831
Jooyung Hancc372c52019-09-25 15:18:44 +09002832 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002833
2834 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002835}
2836
Jiyong Park6a43f042017-10-12 23:05:00 +09002837func squashVendorSrcs(m *Module) {
2838 if lib, ok := m.compiler.(*libraryDecorator); ok {
2839 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2840 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2841
2842 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2843 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2844 }
2845}
2846
Jiyong Parkf9332f12018-02-01 00:54:12 +09002847func squashRecoverySrcs(m *Module) {
2848 if lib, ok := m.compiler.(*libraryDecorator); ok {
2849 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2850 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2851
2852 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2853 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2854 }
2855}
2856
Colin Cross7228ecd2019-11-18 16:00:16 -08002857var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002858
Colin Cross7228ecd2019-11-18 16:00:16 -08002859func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002860 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002861 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002862 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002863
2864 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002865 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002866 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002867 }
Logan Chienf3511742017-10-31 18:04:35 +08002868
2869 if vndkdep := m.vndkdep; vndkdep != nil {
2870 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09002871 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002872 if !vndkdep.isVndkExt() {
2873 mctx.PropertyErrorf("vndk",
2874 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09002875 } else if m.VendorProperties.Vendor_available != nil {
2876 mctx.PropertyErrorf("vendor_available",
2877 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002878 }
2879 } else {
2880 if vndkdep.isVndkExt() {
2881 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09002882 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002883 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002884 }
2885 if m.VendorProperties.Vendor_available == nil {
2886 mctx.PropertyErrorf("vndk",
2887 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002888 }
2889 }
2890 } else {
2891 if vndkdep.isVndkSp() {
2892 mctx.PropertyErrorf("vndk",
2893 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002894 }
2895 if vndkdep.isVndkExt() {
2896 mctx.PropertyErrorf("vndk",
2897 "must set `enabled: true` to set `extends: %q`",
2898 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002899 }
Justin Yun8effde42017-06-23 19:24:43 +09002900 }
2901 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002902
Jiyong Parkf9332f12018-02-01 00:54:12 +09002903 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002904 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002905 var recoveryVariantNeeded bool = false
2906
Inseob Kim64c43952019-08-26 16:52:35 +09002907 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002908 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002909
2910 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002911 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2912 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2913 if boardVndkVersion == "current" {
2914 boardVndkVersion = platformVndkVersion
2915 }
2916 if productVndkVersion == "current" {
2917 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002918 }
2919
Justin Yun5f7f7e82019-11-18 19:52:14 +09002920 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002921 // If the device isn't compiling against the VNDK, we always
2922 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002923 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002924 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002925 // LL-NDK stubs only exist in the vendor and product variants,
2926 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002927 vendorVariants = append(vendorVariants,
2928 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002929 boardVndkVersion,
2930 )
2931 productVariants = append(productVariants,
2932 platformVndkVersion,
2933 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002934 )
Jiyong Park2a454122017-10-19 15:59:33 +09002935 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2936 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002937 vendorVariants = append(vendorVariants,
2938 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002939 boardVndkVersion,
2940 )
2941 productVariants = append(productVariants,
2942 platformVndkVersion,
2943 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002944 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002945 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002946 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2947 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002948 if snapshot, ok := m.linker.(interface {
2949 version() string
2950 }); ok {
2951 vendorVariants = append(vendorVariants, snapshot.version())
2952 } else {
2953 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2954 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09002955 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002956 // This will be available in /system, /vendor and /product
2957 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002958 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002959 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002960 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002961 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2962 // code is PLATFORM_VNDK_VERSION.
2963 // On the other hand, vendor_available modules which are not VNDK should
2964 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002965 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002966 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002967 vendorVariants = append(vendorVariants, boardVndkVersion)
2968 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002969 }
Logan Chienf3511742017-10-31 18:04:35 +08002970 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002971 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002972 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002973 } else {
2974 // This is either in /system (or similar: /data), or is a
2975 // modules built with the NDK. Modules built with the NDK
2976 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002977 coreVariantNeeded = true
2978 }
2979
Justin Yun5f7f7e82019-11-18 19:52:14 +09002980 if boardVndkVersion != "" && productVndkVersion != "" {
2981 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2982 // The module has "product_specific: true" that does not create core variant.
2983 coreVariantNeeded = false
2984 productVariants = append(productVariants, productVndkVersion)
2985 }
2986 } else {
2987 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2988 // restriction to use system libs.
2989 // No product variants defined in this case.
2990 productVariants = []string{}
2991 }
2992
Yifan Hong1b3348d2020-01-21 15:53:22 -08002993 if Bool(m.Properties.Ramdisk_available) {
2994 ramdiskVariantNeeded = true
2995 }
2996
2997 if m.ModuleBase.InstallInRamdisk() {
2998 ramdiskVariantNeeded = true
2999 coreVariantNeeded = false
3000 }
3001
Jiyong Parkf9332f12018-02-01 00:54:12 +09003002 if Bool(m.Properties.Recovery_available) {
3003 recoveryVariantNeeded = true
3004 }
3005
3006 if m.ModuleBase.InstallInRecovery() {
3007 recoveryVariantNeeded = true
3008 coreVariantNeeded = false
3009 }
3010
Inseob Kim64c43952019-08-26 16:52:35 +09003011 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003012 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3013 }
3014
3015 for _, variant := range android.FirstUniqueStrings(productVariants) {
3016 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003017 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003018
Yifan Hong1b3348d2020-01-21 15:53:22 -08003019 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003020 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3021 m.Properties.CoreVariantNeeded = coreVariantNeeded
3022}
3023
3024func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3025 return c.Properties.CoreVariantNeeded
3026}
3027
Yifan Hong1b3348d2020-01-21 15:53:22 -08003028func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3029 return c.Properties.RamdiskVariantNeeded
3030}
3031
Colin Cross7228ecd2019-11-18 16:00:16 -08003032func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3033 return c.Properties.RecoveryVariantNeeded
3034}
3035
3036func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003037 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003038}
3039
3040func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3041 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003042 if variant == android.RamdiskVariation {
3043 m.MakeAsPlatform()
3044 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003045 m.MakeAsPlatform()
3046 squashRecoverySrcs(m)
3047 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003048 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003049 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3050 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003051
3052 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3053 // Hide other vendor variants to avoid collision.
3054 vndkVersion := ctx.DeviceConfig().VndkVersion()
3055 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3056 m.Properties.HideFromMake = true
3057 m.SkipInstall()
3058 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003059 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3060 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3061 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3062 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003063 }
3064}
3065
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003066func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003067 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003068 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3069 }
Colin Cross6510f912017-11-29 00:27:14 -08003070 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003071}
3072
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003073func kytheExtractAllFactory() android.Singleton {
3074 return &kytheExtractAllSingleton{}
3075}
3076
3077type kytheExtractAllSingleton struct {
3078}
3079
3080func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3081 var xrefTargets android.Paths
3082 ctx.VisitAllModules(func(module android.Module) {
3083 if ccModule, ok := module.(xref); ok {
3084 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3085 }
3086 })
3087 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3088 if len(xrefTargets) > 0 {
3089 ctx.Build(pctx, android.BuildParams{
3090 Rule: blueprint.Phony,
3091 Output: android.PathForPhony(ctx, "xref_cxx"),
3092 Inputs: xrefTargets,
3093 //Default: true,
3094 })
3095 }
3096}
3097
Colin Cross06a931b2015-10-28 17:23:31 -07003098var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003099var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003100var BoolPtr = proptools.BoolPtr
3101var String = proptools.String
3102var StringPtr = proptools.StringPtr