blob: e4a42a0e14ca4ec5cd1ad63b0c7e347feb72208f [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090045 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070046 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090047 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090049 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070050 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090051 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090052 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
53 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070054 })
Colin Cross16b23492016-01-06 14:41:07 -080055
Paul Duffin036e7002019-12-19 19:16:28 +000056 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070057 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
58 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080059
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070060 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
61 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
62
Mitch Phillipsbfeade62019-05-01 14:42:05 -070063 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
64 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
65
Jiyong Park1d1119f2019-07-29 21:27:18 +090066 // cfi mutator shouldn't run before sanitizers that return true for
67 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000068 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
69 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
70
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080071 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
72 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
73
Colin Cross1e676be2016-10-12 14:38:15 -070074 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
75 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080076
Colin Cross0b908332019-06-19 23:00:20 -070077 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090078 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080079
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080080 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080081 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070082
83 ctx.TopDown("lto_deps", ltoDepsMutator)
84 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090085
86 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070087 })
Colin Crossb98c8b02016-07-29 13:44:28 -070088
Sasha Smundak2a4549e2018-11-05 16:49:08 -080089 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070090}
91
Colin Crossca860ac2016-01-04 14:34:37 -080092type Deps struct {
93 SharedLibs, LateSharedLibs []string
94 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080095 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080096 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070097
Peter Collingbournedc4f9862020-02-12 17:13:25 -080098 StaticUnwinderIfLegacy bool
99
Colin Cross5950f382016-12-13 12:50:57 -0800100 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700101
Colin Cross81413472016-04-11 14:37:39 -0700102 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Dan Willemsenb40aab62016-04-20 14:21:14 -0700104 GeneratedSources []string
105 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900106 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700107
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700108 ReexportGeneratedHeaders []string
109
Colin Cross97ba0732015-03-23 17:50:24 -0700110 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700111
112 // Used for host bionic
113 LinkerFlagsFile string
114 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700115}
116
Colin Crossca860ac2016-01-04 14:34:37 -0800117type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900119 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900121 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700123 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700126 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800127 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700128 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 GeneratedSources android.Paths
132 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900133 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700134
Inseob Kimd110f872019-12-06 13:15:38 +0900135 Flags []string
136 IncludeDirs android.Paths
137 SystemIncludeDirs android.Paths
138 ReexportedDirs android.Paths
139 ReexportedSystemDirs android.Paths
140 ReexportedFlags []string
141 ReexportedGeneratedHeaders android.Paths
142 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700146
147 // Path to the file container flags to use with the linker
148 LinkerFlagsFile android.OptionalPath
149
150 // Path to the dynamic linker binary
151 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152}
153
Colin Cross4af21ed2019-11-04 09:37:55 -0800154// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
155// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
156// command line so they can be overridden by the local module flags).
157type LocalOrGlobalFlags struct {
158 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700159 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800160 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700161 CFlags []string // Flags that apply to C and C++ source files
162 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
163 ConlyFlags []string // Flags that apply to C source files
164 CppFlags []string // Flags that apply to C++ source files
165 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700166 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800167}
168
169type Flags struct {
170 Local LocalOrGlobalFlags
171 Global LocalOrGlobalFlags
172
173 aidlFlags []string // Flags that apply to aidl source files
174 rsFlags []string // Flags that apply to renderscript source files
175 libFlags []string // Flags to add libraries early to the link order
176 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
177 TidyFlags []string // Flags that apply to clang-tidy
178 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700179
Colin Crossc3199482017-03-30 15:03:04 -0700180 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800181 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700182 SystemIncludeFlags []string
183
Colin Crossb98c8b02016-07-29 13:44:28 -0700184 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700185 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800186 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800187 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800188 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800189
190 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800191 DynamicLinker string
192
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700193 CFlagsDeps android.Paths // Files depended on by compiler flags
194 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800195
Dan Willemsen98ab3112019-08-27 21:20:40 -0700196 AssemblerWithCpp bool
197 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800198
Colin Cross19878da2019-03-28 14:45:07 -0700199 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700200 protoC bool // Whether to use C instead of C++
201 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700202
203 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700204}
205
Colin Crossca860ac2016-01-04 14:34:37 -0800206// Properties used to compile all C or C++ modules
207type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700208 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800209 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700210
211 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800212 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700213
Jiyong Parkde866cb2018-12-07 23:08:36 +0900214 AndroidMkSharedLibs []string `blueprint:"mutated"`
215 AndroidMkStaticLibs []string `blueprint:"mutated"`
216 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
217 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
218 HideFromMake bool `blueprint:"mutated"`
219 PreventInstall bool `blueprint:"mutated"`
220 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700221
Justin Yun5f7f7e82019-11-18 19:52:14 +0900222 ImageVariationPrefix string `blueprint:"mutated"`
223 VndkVersion string `blueprint:"mutated"`
224 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800225
226 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
227 // file
228 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900229
Yifan Hong1b3348d2020-01-21 15:53:22 -0800230 // Make this module available when building for ramdisk
231 Ramdisk_available *bool
232
Jiyong Parkf9332f12018-02-01 00:54:12 +0900233 // Make this module available when building for recovery
234 Recovery_available *bool
235
Colin Crossae6c5202019-11-20 13:35:50 -0800236 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800237 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800238 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800239 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900240 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900241
242 // Allows this module to use non-APEX version of libraries. Useful
243 // for building binaries that are started before APEXes are activated.
244 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900245
246 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
247 // see soong/cc/config/vndk.go
248 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900249
250 // Used by vendor snapshot to record dependencies from snapshot modules.
251 SnapshotSharedLibs []string `blueprint:"mutated"`
252 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700253}
254
255type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900256 // whether this module should be allowed to be directly depended by other
257 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900258 // In addition, this module should be allowed to be directly depended by
259 // product modules with `product_specific: true`.
260 // If set to true, three variants will be built separately, one like
261 // normal, another limited to the set of libraries and headers
262 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700263 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900264 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700265 // so it shouldn't have any unversioned runtime dependencies, or
266 // make assumptions about the system that may not be true in the
267 // future.
268 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900269 // If set to false, this module becomes inaccessible from /vendor or /product
270 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900271 //
272 // Default value is true when vndk: {enabled: true} or vendor: true.
273 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700274 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900275 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700276 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900277
278 // whether this module is capable of being loaded with other instance
279 // (possibly an older version) of the same module in the same process.
280 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
281 // can be double loaded in a vendor process if the library is also a
282 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
283 // explicitly marked as `double_loadable: true` by the owner, or the dependency
284 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
285 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800286}
287
Colin Crossca860ac2016-01-04 14:34:37 -0800288type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800289 static() bool
290 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900291 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700292 toolchain() config.Toolchain
Jooyung Han61c41542020-03-07 03:45:53 +0900293 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700294 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800295 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700296 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800297 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900298 isLlndk(config android.Config) bool
299 isLlndkPublic(config android.Config) bool
300 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900301 isVndk() bool
302 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800303 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900304 inProduct() bool
305 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800306 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900307 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800308 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700309 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700310 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800311 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800312 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800313 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800314 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800315 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900316 apexName() string
Jooyung Han61c41542020-03-07 03:45:53 +0900317 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900318 hasStubsVariants() bool
319 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900320 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800321 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700322 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
325type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700326 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800327 ModuleContextIntf
328}
329
330type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700331 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800332 ModuleContextIntf
333}
334
Colin Cross37047f12016-12-13 17:06:13 -0800335type DepsContext interface {
336 android.BottomUpMutatorContext
337 ModuleContextIntf
338}
339
Colin Crossca860ac2016-01-04 14:34:37 -0800340type feature interface {
341 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800342 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800343 flags(ctx ModuleContext, flags Flags) Flags
344 props() []interface{}
345}
346
347type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700348 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800349 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800350 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700351 compilerProps() []interface{}
352
Colin Cross76fada02016-07-27 10:31:13 -0700353 appendCflags([]string)
354 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700355 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800356}
357
358type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700359 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800360 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700361 linkerFlags(ctx ModuleContext, flags Flags) Flags
362 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800363 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700364
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700365 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700366 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900367 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700368
369 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900370 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800371}
372
373type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700374 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700375 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800376 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700377 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700378 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900379 relativeInstallPath() string
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +0100380 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800381}
382
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800383type xref interface {
384 XrefCcFiles() android.Paths
385}
386
Colin Crossc99deeb2016-04-11 15:06:20 -0700387var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700388 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
389 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
390 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
391 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
392 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800393 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700394 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
395 headerDepTag = DependencyTag{Name: "header", Library: true}
396 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
397 genSourceDepTag = DependencyTag{Name: "gen source"}
398 genHeaderDepTag = DependencyTag{Name: "gen header"}
399 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
400 objDepTag = DependencyTag{Name: "obj"}
401 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
402 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
403 reuseObjTag = DependencyTag{Name: "reuse objects"}
404 staticVariantTag = DependencyTag{Name: "static variant"}
405 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
406 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
407 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
408 runtimeDepTag = DependencyTag{Name: "runtime lib"}
409 coverageDepTag = DependencyTag{Name: "coverage"}
410 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700411)
412
Roland Levillainf89cd092019-07-29 16:22:59 +0100413func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700414 ccDepTag, ok := depTag.(DependencyTag)
415 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100416}
417
418func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700419 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100420 return ok && ccDepTag == runtimeDepTag
421}
422
423func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700424 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100425 return ok && ccDepTag == testPerSrcDepTag
426}
427
Colin Crossca860ac2016-01-04 14:34:37 -0800428// Module contains the properties and members used by all C/C++ module types, and implements
429// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
430// to construct the output file. Behavior can be customized with a Customizer interface
431type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700432 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700433 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900434 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900435 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700436
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700437 Properties BaseProperties
438 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700439
Colin Crossca860ac2016-01-04 14:34:37 -0800440 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700441 hod android.HostOrDeviceSupported
442 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700443
Paul Duffina0843f62019-12-13 19:50:38 +0000444 // Allowable SdkMemberTypes of this module type.
445 sdkMemberTypes []android.SdkMemberType
446
Colin Crossca860ac2016-01-04 14:34:37 -0800447 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700448 features []feature
449 compiler compiler
450 linker linker
451 installer installer
452 stl *stl
453 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800454 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800455 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900456 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700457 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700458 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800459
Colin Cross635c3b02016-05-18 15:37:25 -0700460 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800461
Colin Crossb98c8b02016-07-29 13:44:28 -0700462 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700463
464 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800465
466 // Flags used to compile this module
467 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700468
469 // 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 -0800470 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700471 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800472 depsInLinkOrder android.Paths
473
474 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700475 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900476
477 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800478 // Kythe (source file indexer) paths for this compilation module
479 kytheFiles android.Paths
Jooyung Han74066602020-03-20 04:29:24 +0900480
481 // For apex variants, this is set as apex.min_sdk_version
482 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700483}
484
Ivan Lozano52767be2019-10-18 14:49:46 -0700485func (c *Module) Toc() android.OptionalPath {
486 if c.linker != nil {
487 if library, ok := c.linker.(libraryInterface); ok {
488 return library.toc()
489 }
490 }
491 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
492}
493
494func (c *Module) ApiLevel() string {
495 if c.linker != nil {
496 if stub, ok := c.linker.(*stubDecorator); ok {
497 return stub.properties.ApiLevel
498 }
499 }
500 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
501}
502
503func (c *Module) Static() bool {
504 if c.linker != nil {
505 if library, ok := c.linker.(libraryInterface); ok {
506 return library.static()
507 }
508 }
509 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
510}
511
512func (c *Module) Shared() bool {
513 if c.linker != nil {
514 if library, ok := c.linker.(libraryInterface); ok {
515 return library.shared()
516 }
517 }
518 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
519}
520
521func (c *Module) SelectedStl() string {
522 return c.stl.Properties.SelectedStl
523}
524
525func (c *Module) ToolchainLibrary() bool {
526 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
527 return true
528 }
529 return false
530}
531
532func (c *Module) NdkPrebuiltStl() bool {
533 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
534 return true
535 }
536 return false
537}
538
539func (c *Module) StubDecorator() bool {
540 if _, ok := c.linker.(*stubDecorator); ok {
541 return true
542 }
543 return false
544}
545
546func (c *Module) SdkVersion() string {
547 return String(c.Properties.Sdk_version)
548}
549
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800550func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700551 if c.linker != nil {
552 if library, ok := c.linker.(exportedFlagsProducer); ok {
553 return library.exportedDirs()
554 }
555 }
556 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
557}
558
559func (c *Module) HasStaticVariant() bool {
560 if c.staticVariant != nil {
561 return true
562 }
563 return false
564}
565
566func (c *Module) GetStaticVariant() LinkableInterface {
567 return c.staticVariant
568}
569
570func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
571 c.depsInLinkOrder = depsInLinkOrder
572}
573
574func (c *Module) GetDepsInLinkOrder() []android.Path {
575 return c.depsInLinkOrder
576}
577
578func (c *Module) StubsVersions() []string {
579 if c.linker != nil {
580 if library, ok := c.linker.(*libraryDecorator); ok {
581 return library.Properties.Stubs.Versions
582 }
583 }
584 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
585}
586
587func (c *Module) CcLibrary() bool {
588 if c.linker != nil {
589 if _, ok := c.linker.(*libraryDecorator); ok {
590 return true
591 }
592 }
593 return false
594}
595
596func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700597 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700598 return true
599 }
600 return false
601}
602
Ivan Lozano2b262972019-11-21 12:30:50 -0800603func (c *Module) NonCcVariants() bool {
604 return false
605}
606
Ivan Lozano183a3212019-10-18 14:18:45 -0700607func (c *Module) SetBuildStubs() {
608 if c.linker != nil {
609 if library, ok := c.linker.(*libraryDecorator); ok {
610 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700611 c.Properties.HideFromMake = true
612 c.sanitize = nil
613 c.stl = nil
614 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700615 return
616 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900617 if _, ok := c.linker.(*llndkStubDecorator); ok {
618 c.Properties.HideFromMake = true
619 return
620 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700621 }
622 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
623}
624
Ivan Lozano52767be2019-10-18 14:49:46 -0700625func (c *Module) BuildStubs() bool {
626 if c.linker != nil {
627 if library, ok := c.linker.(*libraryDecorator); ok {
628 return library.buildStubs()
629 }
630 }
631 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
632}
633
Ivan Lozano183a3212019-10-18 14:18:45 -0700634func (c *Module) SetStubsVersions(version string) {
635 if c.linker != nil {
636 if library, ok := c.linker.(*libraryDecorator); ok {
637 library.MutatedProperties.StubsVersion = version
638 return
639 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900640 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
641 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
642 return
643 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700644 }
645 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
646}
647
Jooyung Han0c4e0162020-02-26 22:45:42 +0900648func (c *Module) StubsVersion() string {
649 if c.linker != nil {
650 if library, ok := c.linker.(*libraryDecorator); ok {
651 return library.MutatedProperties.StubsVersion
652 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900653 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
654 return llndk.libraryDecorator.MutatedProperties.StubsVersion
655 }
Jooyung Han0c4e0162020-02-26 22:45:42 +0900656 }
657 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
658}
659
Ivan Lozano183a3212019-10-18 14:18:45 -0700660func (c *Module) SetStatic() {
661 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700662 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700663 library.setStatic()
664 return
665 }
666 }
667 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
668}
669
670func (c *Module) SetShared() {
671 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700672 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700673 library.setShared()
674 return
675 }
676 }
677 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
678}
679
680func (c *Module) BuildStaticVariant() bool {
681 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700682 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700683 return library.buildStatic()
684 }
685 }
686 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
687}
688
689func (c *Module) BuildSharedVariant() bool {
690 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700691 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700692 return library.buildShared()
693 }
694 }
695 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
696}
697
698func (c *Module) Module() android.Module {
699 return c
700}
701
Jiyong Parkc20eee32018-09-05 22:36:17 +0900702func (c *Module) OutputFile() android.OptionalPath {
703 return c.outputFile
704}
705
Ivan Lozano183a3212019-10-18 14:18:45 -0700706var _ LinkableInterface = (*Module)(nil)
707
Jiyong Park719b4462019-01-13 00:39:51 +0900708func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900709 if c.linker != nil {
710 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900711 }
712 return nil
713}
714
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900715func (c *Module) CoverageOutputFile() android.OptionalPath {
716 if c.linker != nil {
717 return c.linker.coverageOutputFilePath()
718 }
719 return android.OptionalPath{}
720}
721
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900722func (c *Module) RelativeInstallPath() string {
723 if c.installer != nil {
724 return c.installer.relativeInstallPath()
725 }
726 return ""
727}
728
Jooyung Han344d5432019-08-23 11:17:39 +0900729func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900730 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900731}
732
Colin Cross36242852017-06-23 15:06:31 -0700733func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700734 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800735 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700736 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800737 }
738 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700739 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800740 }
741 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700742 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800743 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700744 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700745 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700746 }
Colin Cross16b23492016-01-06 14:41:07 -0800747 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700748 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800749 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800750 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700751 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800752 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800753 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700754 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800755 }
Justin Yun8effde42017-06-23 19:24:43 +0900756 if c.vndkdep != nil {
757 c.AddProperties(c.vndkdep.props()...)
758 }
Stephen Craneba090d12017-05-09 15:44:35 -0700759 if c.lto != nil {
760 c.AddProperties(c.lto.props()...)
761 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700762 if c.pgo != nil {
763 c.AddProperties(c.pgo.props()...)
764 }
Colin Crossca860ac2016-01-04 14:34:37 -0800765 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700766 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800767 }
Colin Crossc472d572015-03-17 15:06:21 -0700768
Colin Crossa9d8bee2018-10-02 13:59:46 -0700769 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
770 switch class {
771 case android.Device:
772 return ctx.Config().DevicePrefer32BitExecutables()
773 case android.HostCross:
774 // Windows builds always prefer 32-bit
775 return true
776 default:
777 return false
778 }
779 })
Colin Cross36242852017-06-23 15:06:31 -0700780 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900781 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900782 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900783 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900784
Colin Cross36242852017-06-23 15:06:31 -0700785 return c
Colin Crossc472d572015-03-17 15:06:21 -0700786}
787
Colin Crossb916a382016-07-29 17:28:03 -0700788// Returns true for dependency roots (binaries)
789// TODO(ccross): also handle dlopenable libraries
790func (c *Module) isDependencyRoot() bool {
791 if root, ok := c.linker.(interface {
792 isDependencyRoot() bool
793 }); ok {
794 return root.isDependencyRoot()
795 }
796 return false
797}
798
Justin Yun5f7f7e82019-11-18 19:52:14 +0900799// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
800// "product" and "vendor" variant modules return true for this function.
801// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
802// "soc_specific: true" and more vendor installed modules are included here.
803// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
804// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700805func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900806 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700807}
808
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800809func (c *Module) isCoverageVariant() bool {
810 return c.coverage.Properties.IsCoverageVariant
811}
812
Peter Collingbournead84f972019-12-17 16:46:18 -0800813func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800814 return inList(c.Name(), ndkMigratedLibs)
815}
816
Inseob Kim9516ee92019-05-09 10:56:13 +0900817func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800818 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900819 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800820}
821
Inseob Kim9516ee92019-05-09 10:56:13 +0900822func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800823 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900824 name := c.BaseModuleName()
825 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800826}
827
Inseob Kim9516ee92019-05-09 10:56:13 +0900828func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800829 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900830 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800831}
832
Ivan Lozano52767be2019-10-18 14:49:46 -0700833func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800834 if vndkdep := c.vndkdep; vndkdep != nil {
835 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900836 }
837 return false
838}
839
Yi Kong7e53c572018-02-14 18:16:12 +0800840func (c *Module) isPgoCompile() bool {
841 if pgo := c.pgo; pgo != nil {
842 return pgo.Properties.PgoCompile
843 }
844 return false
845}
846
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800847func (c *Module) isNDKStubLibrary() bool {
848 if _, ok := c.compiler.(*stubDecorator); ok {
849 return true
850 }
851 return false
852}
853
Logan Chienf3511742017-10-31 18:04:35 +0800854func (c *Module) isVndkSp() bool {
855 if vndkdep := c.vndkdep; vndkdep != nil {
856 return vndkdep.isVndkSp()
857 }
858 return false
859}
860
861func (c *Module) isVndkExt() bool {
862 if vndkdep := c.vndkdep; vndkdep != nil {
863 return vndkdep.isVndkExt()
864 }
865 return false
866}
867
Ivan Lozano52767be2019-10-18 14:49:46 -0700868func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900869 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800870}
871
Logan Chienf3511742017-10-31 18:04:35 +0800872func (c *Module) getVndkExtendsModuleName() string {
873 if vndkdep := c.vndkdep; vndkdep != nil {
874 return vndkdep.getVndkExtendsModuleName()
875 }
876 return ""
877}
878
Justin Yun5f7f7e82019-11-18 19:52:14 +0900879// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900880// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700881func (c *Module) HasVendorVariant() bool {
882 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900883}
884
Justin Yun5f7f7e82019-11-18 19:52:14 +0900885const (
886 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
887 // against the VNDK.
888 VendorVariationPrefix = "vendor."
889
890 // ProductVariationPrefix is the variant prefix used for /product code that compiles
891 // against the VNDK.
892 ProductVariationPrefix = "product."
893)
894
895// Returns true if the module is "product" variant. Usually these modules are installed in /product
896func (c *Module) inProduct() bool {
897 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
898}
899
900// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
901func (c *Module) inVendor() bool {
902 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
903}
904
Yifan Hong1b3348d2020-01-21 15:53:22 -0800905func (c *Module) InRamdisk() bool {
906 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
907}
908
Ivan Lozano52767be2019-10-18 14:49:46 -0700909func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800910 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900911}
912
Yifan Hong1b3348d2020-01-21 15:53:22 -0800913func (c *Module) OnlyInRamdisk() bool {
914 return c.ModuleBase.InstallInRamdisk()
915}
916
Ivan Lozano52767be2019-10-18 14:49:46 -0700917func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900918 return c.ModuleBase.InstallInRecovery()
919}
920
Jiyong Park25fc6a92018-11-18 18:02:45 +0900921func (c *Module) IsStubs() bool {
922 if library, ok := c.linker.(*libraryDecorator); ok {
923 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900924 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
925 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900926 }
927 return false
928}
929
930func (c *Module) HasStubsVariants() bool {
931 if library, ok := c.linker.(*libraryDecorator); ok {
932 return len(library.Properties.Stubs.Versions) > 0
933 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700934 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
935 return len(library.Properties.Stubs.Versions) > 0
936 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900937 return false
938}
939
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900940func (c *Module) bootstrap() bool {
941 return Bool(c.Properties.Bootstrap)
942}
943
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700944func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700945 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
946 if c.Target().NativeBridge == android.NativeBridgeEnabled {
947 return false
948 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700949 return c.linker != nil && c.linker.nativeCoverage()
950}
951
Inseob Kim8471cda2019-11-15 09:59:12 +0900952func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900953 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
954 return true
955 }
956 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
957 return true
958 }
959 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
960 return true
961 }
962 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900963}
964
Jiyong Park73c54ee2019-10-22 20:31:18 +0900965func (c *Module) ExportedIncludeDirs() android.Paths {
966 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
967 return flagsProducer.exportedDirs()
968 }
Jiyong Park232e7852019-11-04 12:23:40 +0900969 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900970}
971
972func (c *Module) ExportedSystemIncludeDirs() android.Paths {
973 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
974 return flagsProducer.exportedSystemDirs()
975 }
Jiyong Park232e7852019-11-04 12:23:40 +0900976 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900977}
978
979func (c *Module) ExportedFlags() []string {
980 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
981 return flagsProducer.exportedFlags()
982 }
Jiyong Park232e7852019-11-04 12:23:40 +0900983 return nil
984}
985
986func (c *Module) ExportedDeps() android.Paths {
987 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
988 return flagsProducer.exportedDeps()
989 }
990 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900991}
992
Inseob Kimd110f872019-12-06 13:15:38 +0900993func (c *Module) ExportedGeneratedHeaders() android.Paths {
994 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
995 return flagsProducer.exportedGeneratedHeaders()
996 }
997 return nil
998}
999
Jiyong Parkf1194352019-02-25 11:05:47 +09001000func isBionic(name string) bool {
1001 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001002 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001003 return true
1004 }
1005 return false
1006}
1007
Martin Stjernholm279de572019-09-10 23:18:20 +01001008func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001009 if name == "libclang_rt.hwasan-aarch64-android" {
1010 return inList("hwaddress", config.SanitizeDevice())
1011 }
1012 return isBionic(name)
1013}
1014
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001015func (c *Module) XrefCcFiles() android.Paths {
1016 return c.kytheFiles
1017}
1018
Colin Crossca860ac2016-01-04 14:34:37 -08001019type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001020 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001021 moduleContextImpl
1022}
1023
Colin Cross37047f12016-12-13 17:06:13 -08001024type depsContext struct {
1025 android.BottomUpMutatorContext
1026 moduleContextImpl
1027}
1028
Colin Crossca860ac2016-01-04 14:34:37 -08001029type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001030 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001031 moduleContextImpl
1032}
1033
Justin Yun5f7f7e82019-11-18 19:52:14 +09001034func (ctx *moduleContext) ProductSpecific() bool {
1035 return ctx.ModuleContext.ProductSpecific() ||
1036 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1037}
1038
Jiyong Park2db76922017-11-08 16:03:48 +09001039func (ctx *moduleContext) SocSpecific() bool {
1040 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001041 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001042}
1043
Colin Crossca860ac2016-01-04 14:34:37 -08001044type moduleContextImpl struct {
1045 mod *Module
1046 ctx BaseModuleContext
1047}
1048
Colin Crossb98c8b02016-07-29 13:44:28 -07001049func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001050 return ctx.mod.toolchain(ctx.ctx)
1051}
1052
1053func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001054 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001055}
1056
1057func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001058 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001059}
1060
Jiyong Park1d1119f2019-07-29 21:27:18 +09001061func (ctx *moduleContextImpl) header() bool {
1062 return ctx.mod.header()
1063}
1064
Jooyung Han61c41542020-03-07 03:45:53 +09001065func (ctx *moduleContextImpl) canUseSdk() bool {
1066 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1067}
1068
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001069func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Han61c41542020-03-07 03:45:53 +09001070 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001071 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001072 }
1073 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001074}
1075
1076func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001077 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001078 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001079 vndkVer := ctx.mod.VndkVersion()
Jooyung Han424175d2020-04-08 09:22:26 +09001080 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001081 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001082 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001083 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001084 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001085 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001086 }
1087 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001088}
1089
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001090func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001091 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001092}
Justin Yun8effde42017-06-23 19:24:43 +09001093
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001094func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001095 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001096}
1097
Inseob Kim9516ee92019-05-09 10:56:13 +09001098func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1099 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001100}
1101
Inseob Kim9516ee92019-05-09 10:56:13 +09001102func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1103 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001104}
1105
Inseob Kim9516ee92019-05-09 10:56:13 +09001106func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1107 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001108}
1109
Logan Chienf3511742017-10-31 18:04:35 +08001110func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001111 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001112}
1113
Yi Kong7e53c572018-02-14 18:16:12 +08001114func (ctx *moduleContextImpl) isPgoCompile() bool {
1115 return ctx.mod.isPgoCompile()
1116}
1117
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001118func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1119 return ctx.mod.isNDKStubLibrary()
1120}
1121
Justin Yun8effde42017-06-23 19:24:43 +09001122func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001123 return ctx.mod.isVndkSp()
1124}
1125
1126func (ctx *moduleContextImpl) isVndkExt() bool {
1127 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001128}
1129
Vic Yangefd249e2018-11-12 20:19:56 -08001130func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001131 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001132}
1133
Justin Yun5f7f7e82019-11-18 19:52:14 +09001134func (ctx *moduleContextImpl) inProduct() bool {
1135 return ctx.mod.inProduct()
1136}
1137
1138func (ctx *moduleContextImpl) inVendor() bool {
1139 return ctx.mod.inVendor()
1140}
1141
Yifan Hong1b3348d2020-01-21 15:53:22 -08001142func (ctx *moduleContextImpl) inRamdisk() bool {
1143 return ctx.mod.InRamdisk()
1144}
1145
Jiyong Parkf9332f12018-02-01 00:54:12 +09001146func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001147 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001148}
1149
Logan Chien2f2b8902018-07-10 15:01:19 +08001150// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001151func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001152 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1153 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001154 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001155
1156 if ctx.ctx.Fuchsia() {
1157 return false
1158 }
1159
Logan Chien2f2b8902018-07-10 15:01:19 +08001160 if sanitize := ctx.mod.sanitize; sanitize != nil {
1161 if !sanitize.isVariantOnProductionDevice() {
1162 return false
1163 }
1164 }
1165 if !ctx.ctx.Device() {
1166 // Host modules do not need ABI dumps.
1167 return false
1168 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001169 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001170 // Stubs do not need ABI dumps.
1171 return false
1172 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001173 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001174}
1175
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001176func (ctx *moduleContextImpl) selectedStl() string {
1177 if stl := ctx.mod.stl; stl != nil {
1178 return stl.Properties.SelectedStl
1179 }
1180 return ""
1181}
1182
Ivan Lozanobd721262018-11-27 14:33:03 -08001183func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1184 return ctx.mod.linker.useClangLld(actx)
1185}
1186
Colin Crossce75d2c2016-10-06 16:12:58 -07001187func (ctx *moduleContextImpl) baseModuleName() string {
1188 return ctx.mod.ModuleBase.BaseModuleName()
1189}
1190
Logan Chienf3511742017-10-31 18:04:35 +08001191func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1192 return ctx.mod.getVndkExtendsModuleName()
1193}
1194
Logan Chiene274fc92019-12-03 11:18:32 -08001195func (ctx *moduleContextImpl) isForPlatform() bool {
1196 return ctx.mod.IsForPlatform()
1197}
1198
Jiyong Park58e364a2019-01-19 19:24:06 +09001199func (ctx *moduleContextImpl) apexName() string {
1200 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001201}
1202
Jooyung Han61c41542020-03-07 03:45:53 +09001203func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han74066602020-03-20 04:29:24 +09001204 return ctx.mod.apexSdkVersion
Jooyung Han61c41542020-03-07 03:45:53 +09001205}
1206
Jiyong Parkb0788572018-12-20 22:10:17 +09001207func (ctx *moduleContextImpl) hasStubsVariants() bool {
1208 return ctx.mod.HasStubsVariants()
1209}
1210
1211func (ctx *moduleContextImpl) isStubs() bool {
1212 return ctx.mod.IsStubs()
1213}
1214
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001215func (ctx *moduleContextImpl) bootstrap() bool {
1216 return ctx.mod.bootstrap()
1217}
1218
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001219func (ctx *moduleContextImpl) nativeCoverage() bool {
1220 return ctx.mod.nativeCoverage()
1221}
1222
Colin Cross635c3b02016-05-18 15:37:25 -07001223func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001224 return &Module{
1225 hod: hod,
1226 multilib: multilib,
1227 }
1228}
1229
Colin Cross635c3b02016-05-18 15:37:25 -07001230func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001231 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001232 module.features = []feature{
1233 &tidyFeature{},
1234 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001235 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001236 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001237 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001238 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001239 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001240 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001241 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001242 return module
1243}
1244
Colin Crossce75d2c2016-10-06 16:12:58 -07001245func (c *Module) Prebuilt() *android.Prebuilt {
1246 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1247 return p.prebuilt()
1248 }
1249 return nil
1250}
1251
1252func (c *Module) Name() string {
1253 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001254 if p, ok := c.linker.(interface {
1255 Name(string) string
1256 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001257 name = p.Name(name)
1258 }
1259 return name
1260}
1261
Alex Light3d673592019-01-18 14:37:31 -08001262func (c *Module) Symlinks() []string {
1263 if p, ok := c.installer.(interface {
1264 symlinkList() []string
1265 }); ok {
1266 return p.symlinkList()
1267 }
1268 return nil
1269}
1270
Jeff Gaston294356f2017-09-27 17:05:30 -07001271// orderDeps reorders dependencies into a list such that if module A depends on B, then
1272// A will precede B in the resultant list.
1273// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001274// Note that directSharedDeps should be the analogous static library for each shared lib dep
1275func 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 -07001276 // If A depends on B, then
1277 // Every list containing A will also contain B later in the list
1278 // So, after concatenating all lists, the final instance of B will have come from the same
1279 // original list as the final instance of A
1280 // So, the final instance of B will be later in the concatenation than the final A
1281 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1282 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001283 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001284 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001285 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1286 }
1287 for _, dep := range directSharedDeps {
1288 orderedAllDeps = append(orderedAllDeps, dep)
1289 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001290 }
1291
Colin Crossb6715442017-10-24 11:13:31 -07001292 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001293
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001294 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001295 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001296 // resultant list to only what the caller has chosen to include in directStaticDeps
1297 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001298
1299 return orderedAllDeps, orderedDeclaredDeps
1300}
1301
Ivan Lozano183a3212019-10-18 14:18:45 -07001302func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001303 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001304 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001305 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1306 staticDepFiles := []android.Path{}
1307 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001308 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1309 if dep.OutputFile().Valid() {
1310 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1311 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1312 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001313 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001314 sharedDepFiles := []android.Path{}
1315 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001316 if sharedDep.HasStaticVariant() {
1317 staticAnalogue := sharedDep.GetStaticVariant()
1318 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1319 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001320 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001321 }
1322
1323 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001324 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1325 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001326
1327 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001328}
1329
Roland Levillainf89cd092019-07-29 16:22:59 +01001330func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1331 test, ok := c.linker.(testPerSrc)
1332 return ok && test.isAllTestsVariation()
1333}
1334
Justin Yun5f7f7e82019-11-18 19:52:14 +09001335func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1336 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1337 // "current", it will append the VNDK version to the name suffix.
1338 var vndkVersion string
1339 var nameSuffix string
1340 if c.inProduct() {
1341 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1342 nameSuffix = productSuffix
1343 } else {
1344 vndkVersion = ctx.DeviceConfig().VndkVersion()
1345 nameSuffix = vendorSuffix
1346 }
1347 if vndkVersion == "current" {
1348 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1349 }
1350 if c.Properties.VndkVersion != vndkVersion {
1351 // add version suffix only if the module is using different vndk version than the
1352 // version in product or vendor partition.
1353 nameSuffix += "." + c.Properties.VndkVersion
1354 }
1355 return nameSuffix
1356}
1357
Colin Cross635c3b02016-05-18 15:37:25 -07001358func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001359 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001360 //
1361 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1362 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1363 // module and return early, as this module does not produce an output file per se.
1364 if c.IsTestPerSrcAllTestsVariation() {
1365 c.outputFile = android.OptionalPath{}
1366 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001367 }
1368
Jooyung Han38002912019-05-16 04:01:54 +09001369 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001370
Inseob Kim64c43952019-08-26 16:52:35 +09001371 c.Properties.SubName = ""
1372
1373 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1374 c.Properties.SubName += nativeBridgeSuffix
1375 }
1376
Justin Yun5f7f7e82019-11-18 19:52:14 +09001377 _, llndk := c.linker.(*llndkStubDecorator)
1378 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1379 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1380 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1381 // added for product variant only when we have vendor and product variants with core
1382 // variant. The suffix is not added for vendor-only or product-only module.
1383 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1384 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001385 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1386 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1387 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001388 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1389 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001390 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001391 c.Properties.SubName += recoverySuffix
1392 }
1393
Colin Crossca860ac2016-01-04 14:34:37 -08001394 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001395 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001396 moduleContextImpl: moduleContextImpl{
1397 mod: c,
1398 },
1399 }
1400 ctx.ctx = ctx
1401
Colin Crossf18e1102017-11-16 14:33:08 -08001402 deps := c.depsToPaths(ctx)
1403 if ctx.Failed() {
1404 return
1405 }
1406
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001407 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1408 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1409 }
1410
Colin Crossca860ac2016-01-04 14:34:37 -08001411 flags := Flags{
1412 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001413 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001414 }
Colin Crossca860ac2016-01-04 14:34:37 -08001415 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001416 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001417 }
1418 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001419 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001420 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001421 if c.stl != nil {
1422 flags = c.stl.flags(ctx, flags)
1423 }
Colin Cross16b23492016-01-06 14:41:07 -08001424 if c.sanitize != nil {
1425 flags = c.sanitize.flags(ctx, flags)
1426 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001427 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001428 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001429 }
Stephen Craneba090d12017-05-09 15:44:35 -07001430 if c.lto != nil {
1431 flags = c.lto.flags(ctx, flags)
1432 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001433 if c.pgo != nil {
1434 flags = c.pgo.flags(ctx, flags)
1435 }
Colin Crossca860ac2016-01-04 14:34:37 -08001436 for _, feature := range c.features {
1437 flags = feature.flags(ctx, flags)
1438 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001439 if ctx.Failed() {
1440 return
1441 }
1442
Colin Cross4af21ed2019-11-04 09:37:55 -08001443 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1444 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1445 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001446
Colin Cross4af21ed2019-11-04 09:37:55 -08001447 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001448
1449 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001450 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001451 }
1452 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001453 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001454 }
1455
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001456 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001457 // We need access to all the flags seen by a source file.
1458 if c.sabi != nil {
1459 flags = c.sabi.flags(ctx, flags)
1460 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001461
Colin Cross4af21ed2019-11-04 09:37:55 -08001462 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001463
Colin Crossca860ac2016-01-04 14:34:37 -08001464 // Optimization to reduce size of build.ninja
1465 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001466 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1467 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1468 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1469 flags.Local.CFlags = []string{"$cflags"}
1470 flags.Local.CppFlags = []string{"$cppflags"}
1471 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001472
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001473 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001474 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001475 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001476 if ctx.Failed() {
1477 return
1478 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001479 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001480 }
1481
Colin Crossca860ac2016-01-04 14:34:37 -08001482 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001483 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001484 if ctx.Failed() {
1485 return
1486 }
Colin Cross635c3b02016-05-18 15:37:25 -07001487 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001488
1489 // If a lib is directly included in any of the APEXes, unhide the stubs
1490 // variant having the latest version gets visible to make. In addition,
1491 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1492 // force anything in the make world to link against the stubs library.
1493 // (unless it is explicitly referenced via .bootstrap suffix or the
1494 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001495 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001496 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001497 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001498 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001499 c.Properties.HideFromMake = false // unhide
1500 // Note: this is still non-installable
1501 }
Inseob Kimac775b22020-03-03 22:06:32 +09001502
1503 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1504 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1505 if isSnapshotAware(ctx, c) {
1506 i.collectHeadersForSnapshot(ctx)
1507 }
1508 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001509 }
Colin Cross5049f022015-03-18 13:28:46 -07001510
Inseob Kim1f086e22019-05-09 13:29:15 +09001511 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001512 c.installer.install(ctx, c.outputFile.Path())
1513 if ctx.Failed() {
1514 return
Colin Crossca860ac2016-01-04 14:34:37 -08001515 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001516 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001517}
1518
Colin Cross0ea8ba82019-06-06 14:33:29 -07001519func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001520 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001521 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001522 }
Colin Crossca860ac2016-01-04 14:34:37 -08001523 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001524}
1525
Colin Crossca860ac2016-01-04 14:34:37 -08001526func (c *Module) begin(ctx BaseModuleContext) {
1527 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001528 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001529 }
Colin Crossca860ac2016-01-04 14:34:37 -08001530 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001531 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001532 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001533 if c.stl != nil {
1534 c.stl.begin(ctx)
1535 }
Colin Cross16b23492016-01-06 14:41:07 -08001536 if c.sanitize != nil {
1537 c.sanitize.begin(ctx)
1538 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001539 if c.coverage != nil {
1540 c.coverage.begin(ctx)
1541 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001542 if c.sabi != nil {
1543 c.sabi.begin(ctx)
1544 }
Justin Yun8effde42017-06-23 19:24:43 +09001545 if c.vndkdep != nil {
1546 c.vndkdep.begin(ctx)
1547 }
Stephen Craneba090d12017-05-09 15:44:35 -07001548 if c.lto != nil {
1549 c.lto.begin(ctx)
1550 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001551 if c.pgo != nil {
1552 c.pgo.begin(ctx)
1553 }
Colin Crossca860ac2016-01-04 14:34:37 -08001554 for _, feature := range c.features {
1555 feature.begin(ctx)
1556 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001557 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001558 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001559 if err != nil {
1560 ctx.PropertyErrorf("sdk_version", err.Error())
1561 }
Nan Zhang0007d812017-11-07 10:57:05 -08001562 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001563 }
Colin Crossca860ac2016-01-04 14:34:37 -08001564}
1565
Colin Cross37047f12016-12-13 17:06:13 -08001566func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001567 deps := Deps{}
1568
1569 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001570 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001571 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001572 // Add the PGO dependency (the clang_rt.profile runtime library), which
1573 // sometimes depends on symbols from libgcc, before libgcc gets added
1574 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001575 if c.pgo != nil {
1576 deps = c.pgo.deps(ctx, deps)
1577 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001578 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001579 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001580 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001581 if c.stl != nil {
1582 deps = c.stl.deps(ctx, deps)
1583 }
Colin Cross16b23492016-01-06 14:41:07 -08001584 if c.sanitize != nil {
1585 deps = c.sanitize.deps(ctx, deps)
1586 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001587 if c.coverage != nil {
1588 deps = c.coverage.deps(ctx, deps)
1589 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001590 if c.sabi != nil {
1591 deps = c.sabi.deps(ctx, deps)
1592 }
Justin Yun8effde42017-06-23 19:24:43 +09001593 if c.vndkdep != nil {
1594 deps = c.vndkdep.deps(ctx, deps)
1595 }
Stephen Craneba090d12017-05-09 15:44:35 -07001596 if c.lto != nil {
1597 deps = c.lto.deps(ctx, deps)
1598 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001599 for _, feature := range c.features {
1600 deps = feature.deps(ctx, deps)
1601 }
1602
Colin Crossb6715442017-10-24 11:13:31 -07001603 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1604 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1605 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1606 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1607 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1608 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001609 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001610
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001611 for _, lib := range deps.ReexportSharedLibHeaders {
1612 if !inList(lib, deps.SharedLibs) {
1613 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1614 }
1615 }
1616
1617 for _, lib := range deps.ReexportStaticLibHeaders {
1618 if !inList(lib, deps.StaticLibs) {
1619 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1620 }
1621 }
1622
Colin Cross5950f382016-12-13 12:50:57 -08001623 for _, lib := range deps.ReexportHeaderLibHeaders {
1624 if !inList(lib, deps.HeaderLibs) {
1625 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1626 }
1627 }
1628
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001629 for _, gen := range deps.ReexportGeneratedHeaders {
1630 if !inList(gen, deps.GeneratedHeaders) {
1631 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1632 }
1633 }
1634
Colin Crossc99deeb2016-04-11 15:06:20 -07001635 return deps
1636}
1637
Dan Albert7e9d2952016-08-04 13:02:36 -07001638func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001639 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001640 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001641 moduleContextImpl: moduleContextImpl{
1642 mod: c,
1643 },
1644 }
1645 ctx.ctx = ctx
1646
Colin Crossca860ac2016-01-04 14:34:37 -08001647 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001648}
1649
Jiyong Park7ed9de32018-10-15 22:25:07 +09001650// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001651func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001652 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1653 version := name[sharp+1:]
1654 libname := name[:sharp]
1655 return libname, version
1656 }
1657 return name, ""
1658}
1659
Colin Cross1e676be2016-10-12 14:38:15 -07001660func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001661 if !c.Enabled() {
1662 return
1663 }
1664
Colin Cross37047f12016-12-13 17:06:13 -08001665 ctx := &depsContext{
1666 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001667 moduleContextImpl: moduleContextImpl{
1668 mod: c,
1669 },
1670 }
1671 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001672
Colin Crossc99deeb2016-04-11 15:06:20 -07001673 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001674
Dan Albert914449f2016-06-17 16:45:24 -07001675 variantNdkLibs := []string{}
1676 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001677 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001678 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001679
Inseob Kimeec88e12020-01-22 11:11:29 +09001680 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001681 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001682 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001683 // 1. Name of an NDK library that refers to a prebuilt module.
1684 // For each of these, it adds the name of the prebuilt module (which will be in
1685 // prebuilts/ndk) to the list of nonvariant libs.
1686 // 2. Name of an NDK library that refers to an ndk_library module.
1687 // For each of these, it adds the name of the ndk_library module to the list of
1688 // variant libs.
1689 // 3. Anything else (so anything that isn't an NDK library).
1690 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001691 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001692 // The caller can then know to add the variantLibs dependencies differently from the
1693 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001694
Inseob Kim9516ee92019-05-09 10:56:13 +09001695 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001696 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1697
1698 rewriteVendorLibs := func(lib string) string {
1699 if isLlndkLibrary(lib, ctx.Config()) {
1700 return lib + llndkLibrarySuffix
1701 }
1702
1703 // only modules with BOARD_VNDK_VERSION uses snapshot.
1704 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1705 return lib
1706 }
1707
1708 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1709 return snapshot
1710 }
1711
1712 return lib
1713 }
1714
1715 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001716 variantLibs = []string{}
1717 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001718 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001719 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001720 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001721 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1722 if !inList(name, ndkMigratedLibs) {
1723 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001724 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001725 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001726 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001727 } else if ctx.useVndk() {
1728 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001729 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001730 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001731 if actx.OtherModuleExists(vendorPublicLib) {
1732 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1733 } else {
1734 // This can happen if vendor_public_library module is defined in a
1735 // namespace that isn't visible to the current module. In that case,
1736 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001737 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001738 }
Dan Albert914449f2016-06-17 16:45:24 -07001739 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001740 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001741 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001742 }
1743 }
Dan Albert914449f2016-06-17 16:45:24 -07001744 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001745 }
1746
Inseob Kimeec88e12020-01-22 11:11:29 +09001747 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1748 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1749 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1750 if ctx.useVndk() {
1751 for idx, lib := range deps.RuntimeLibs {
1752 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1753 }
1754 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001755 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001756
Jiyong Park7e636d02019-01-28 16:16:54 +09001757 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001758 if c.linker != nil {
1759 if library, ok := c.linker.(*libraryDecorator); ok {
1760 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001761 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001762 }
1763 }
1764 }
1765
Inseob Kimeec88e12020-01-22 11:11:29 +09001766 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1767 // only modules with BOARD_VNDK_VERSION uses snapshot.
1768 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1769 return lib
1770 }
1771
1772 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1773 return snapshot
1774 }
1775
1776 return lib
1777 }
1778
1779 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001780 for _, lib := range deps.HeaderLibs {
1781 depTag := headerDepTag
1782 if inList(lib, deps.ReexportHeaderLibHeaders) {
1783 depTag = headerExportDepTag
1784 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001785
1786 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1787
Jiyong Park7e636d02019-01-28 16:16:54 +09001788 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001789 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001790 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001791 } else {
1792 actx.AddVariationDependencies(nil, depTag, lib)
1793 }
1794 }
1795
1796 if buildStubs {
1797 // Stubs lib does not have dependency to other static/shared libraries.
1798 // Don't proceed.
1799 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001800 }
Colin Cross5950f382016-12-13 12:50:57 -08001801
Inseob Kimc0907f12019-02-08 21:00:45 +09001802 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001803 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001804
Jiyong Park5d1598f2019-02-25 22:14:17 +09001805 for _, lib := range deps.WholeStaticLibs {
1806 depTag := wholeStaticDepTag
1807 if impl, ok := syspropImplLibraries[lib]; ok {
1808 lib = impl
1809 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001810
1811 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1812
Jiyong Park5d1598f2019-02-25 22:14:17 +09001813 actx.AddVariationDependencies([]blueprint.Variation{
1814 {Mutator: "link", Variation: "static"},
1815 }, depTag, lib)
1816 }
1817
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001818 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001819 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001820 if inList(lib, deps.ReexportStaticLibHeaders) {
1821 depTag = staticExportDepTag
1822 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001823
1824 if impl, ok := syspropImplLibraries[lib]; ok {
1825 lib = impl
1826 }
1827
Inseob Kimeec88e12020-01-22 11:11:29 +09001828 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1829
Dan Willemsen59339a22018-07-22 21:18:45 -07001830 actx.AddVariationDependencies([]blueprint.Variation{
1831 {Mutator: "link", Variation: "static"},
1832 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001833 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001834
Jooyung Han74066602020-03-20 04:29:24 +09001835 // staticUnwinderDep is treated as staticDep for Q apexes
1836 // so that native libraries/binaries are linked with static unwinder
1837 // because Q libc doesn't have unwinder APIs
1838 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001839 actx.AddVariationDependencies([]blueprint.Variation{
1840 {Mutator: "link", Variation: "static"},
1841 }, staticUnwinderDepTag, staticUnwinder(actx))
1842 }
1843
Inseob Kimeec88e12020-01-22 11:11:29 +09001844 for _, lib := range deps.LateStaticLibs {
1845 actx.AddVariationDependencies([]blueprint.Variation{
1846 {Mutator: "link", Variation: "static"},
1847 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1848 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001849
Ivan Lozano183a3212019-10-18 14:18:45 -07001850 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001851 var variations []blueprint.Variation
1852 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han67a96cd2020-03-13 15:23:36 +09001853 versionVariantAvail := !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001854 if version != "" && versionVariantAvail {
1855 // Version is explicitly specified. i.e. libFoo#30
1856 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001857 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001858 }
1859 actx.AddVariationDependencies(variations, depTag, name)
1860
Jooyung Han0c4e0162020-02-26 22:45:42 +09001861 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001862 // The stubs library will be used when the depending module is built for APEX and
1863 // the dependent module is not in the same APEX.
Jooyung Han0c4e0162020-02-26 22:45:42 +09001864 if version == "" && versionVariantAvail {
1865 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1866 // Note that depTag.ExplicitlyVersioned is false in this case.
1867 actx.AddVariationDependencies([]blueprint.Variation{
1868 {Mutator: "link", Variation: "shared"},
1869 {Mutator: "version", Variation: ver},
1870 }, depTag, name)
1871 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001872 }
1873 }
1874
Jiyong Park7ed9de32018-10-15 22:25:07 +09001875 // shared lib names without the #version suffix
1876 var sharedLibNames []string
1877
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001878 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001879 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001880 if c.static() {
1881 depTag = SharedFromStaticDepTag
1882 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001883 if inList(lib, deps.ReexportSharedLibHeaders) {
1884 depTag = sharedExportDepTag
1885 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001886
1887 if impl, ok := syspropImplLibraries[lib]; ok {
1888 lib = impl
1889 }
1890
Jiyong Park73c54ee2019-10-22 20:31:18 +09001891 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001892 sharedLibNames = append(sharedLibNames, name)
1893
Jiyong Park25fc6a92018-11-18 18:02:45 +09001894 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001895 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001896
Jiyong Park7ed9de32018-10-15 22:25:07 +09001897 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001898 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001899 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1900 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1901 // linking against both the stubs lib and the non-stubs lib at the same time.
1902 continue
1903 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001904 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001905 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001906
Dan Willemsen59339a22018-07-22 21:18:45 -07001907 actx.AddVariationDependencies([]blueprint.Variation{
1908 {Mutator: "link", Variation: "shared"},
1909 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001910
Colin Cross68861832016-07-08 10:41:41 -07001911 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001912
1913 for _, gen := range deps.GeneratedHeaders {
1914 depTag := genHeaderDepTag
1915 if inList(gen, deps.ReexportGeneratedHeaders) {
1916 depTag = genHeaderExportDepTag
1917 }
1918 actx.AddDependency(c, depTag, gen)
1919 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001920
Colin Cross42d48b72018-08-29 14:10:52 -07001921 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001922
1923 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001924 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001925 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001926 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001927 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001928 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001929 if deps.LinkerFlagsFile != "" {
1930 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1931 }
1932 if deps.DynamicLinker != "" {
1933 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001934 }
Dan Albert914449f2016-06-17 16:45:24 -07001935
1936 version := ctx.sdkVersion()
1937 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001938 {Mutator: "ndk_api", Variation: version},
1939 {Mutator: "link", Variation: "shared"},
1940 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001941 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001942 {Mutator: "ndk_api", Variation: version},
1943 {Mutator: "link", Variation: "shared"},
1944 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001945
1946 if vndkdep := c.vndkdep; vndkdep != nil {
1947 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001948 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001949 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001950 {Mutator: "link", Variation: "shared"},
1951 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001952 }
1953 }
Colin Cross6362e272015-10-29 15:25:03 -07001954}
Colin Cross21b9a242015-03-24 14:15:58 -07001955
Colin Crosse40b4ea2018-10-02 22:25:58 -07001956func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001957 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1958 c.beginMutator(ctx)
1959 }
1960}
1961
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001962// Whether a module can link to another module, taking into
1963// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001964func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1965 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001966 // Host code is not restricted
1967 return
1968 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001969
1970 // VNDK is cc.Module supported only for now.
1971 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001972 // Though vendor code is limited by the vendor mutator,
1973 // each vendor-available module needs to check
1974 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001975 if ccTo, ok := to.(*Module); ok {
1976 if ccFrom.vndkdep != nil {
1977 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1978 }
1979 } else {
1980 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001981 }
1982 return
1983 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001984 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001985 // Platform code can link to anything
1986 return
1987 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001988 if from.InRamdisk() {
1989 // Ramdisk code is not NDK
1990 return
1991 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001992 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001993 // Recovery code is not NDK
1994 return
1995 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001996 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001997 // These are always allowed
1998 return
1999 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002000 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002001 // These are allowed, but they don't set sdk_version
2002 return
2003 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002004 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002005 // These aren't real libraries, but are the stub shared libraries that are included in
2006 // the NDK.
2007 return
2008 }
Logan Chien834b9a62019-01-14 15:39:03 +08002009
Ivan Lozano52767be2019-10-18 14:49:46 -07002010 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002011 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2012 // to link to libc++ (non-NDK and without sdk_version).
2013 return
2014 }
2015
Ivan Lozano52767be2019-10-18 14:49:46 -07002016 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002017 // NDK code linking to platform code is never okay.
2018 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002019 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002020 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002021 }
2022
2023 // At this point we know we have two NDK libraries, but we need to
2024 // check that we're not linking against anything built against a higher
2025 // API level, as it is only valid to link against older or equivalent
2026 // APIs.
2027
Inseob Kim01a28722018-04-11 09:48:45 +09002028 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002029 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002030 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002031 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002032 // Current can't be linked against by anything else.
2033 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002034 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002035 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002036 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002037 if err != nil {
2038 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002039 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002040 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002041 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002042 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002043 if err != nil {
2044 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002045 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002046 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002047 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002048
Inseob Kim01a28722018-04-11 09:48:45 +09002049 if toApi > fromApi {
2050 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002051 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002052 }
2053 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002054 }
Dan Albert202fe492017-12-15 13:56:59 -08002055
2056 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002057 fromStl := from.SelectedStl()
2058 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002059 if fromStl == "" || toStl == "" {
2060 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002061 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002062 // We can be permissive with the system "STL" since it is only the C++
2063 // ABI layer, but in the future we should make sure that everyone is
2064 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002065 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002066 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002067 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2068 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002069 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002070}
2071
Jiyong Park5fb8c102018-04-09 12:03:06 +09002072// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002073// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2074// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002075// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002076func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2077 check := func(child, parent android.Module) bool {
2078 to, ok := child.(*Module)
2079 if !ok {
2080 // follow thru cc.Defaults, etc.
2081 return true
2082 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002083
Jooyung Hana70f0672019-01-18 15:20:43 +09002084 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2085 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002086 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002087
2088 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002089 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002090 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002091 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002092
Jooyung Han0302a842019-10-30 18:43:49 +09002093 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002094 return false
2095 }
2096
2097 var stringPath []string
2098 for _, m := range ctx.GetWalkPath() {
2099 stringPath = append(stringPath, m.Name())
2100 }
2101 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2102 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2103 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2104 return false
2105 }
2106 if module, ok := ctx.Module().(*Module); ok {
2107 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002108 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002109 ctx.WalkDeps(check)
2110 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002111 }
2112 }
2113}
2114
Colin Crossc99deeb2016-04-11 15:06:20 -07002115// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002116func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002117 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002118
Ivan Lozano183a3212019-10-18 14:18:45 -07002119 directStaticDeps := []LinkableInterface{}
2120 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002121
Inseob Kim9516ee92019-05-09 10:56:13 +09002122 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2123
Inseob Kim69378442019-06-03 19:10:47 +09002124 reexportExporter := func(exporter exportedFlagsProducer) {
2125 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2126 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2127 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2128 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002129 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002130 }
2131
Colin Crossd11fcda2017-10-23 17:59:01 -07002132 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002133 depName := ctx.OtherModuleName(dep)
2134 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002135
Ivan Lozano52767be2019-10-18 14:49:46 -07002136 ccDep, ok := dep.(LinkableInterface)
2137 if !ok {
2138
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002139 // handling for a few module types that aren't cc Module but that are also supported
2140 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002141 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002142 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002143 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2144 genRule.GeneratedSourceFiles()...)
2145 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002146 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002147 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002148 // Support exported headers from a generated_sources dependency
2149 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002150 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002152 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002153 genRule.GeneratedSourceFiles()...)
2154 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002155 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002156 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002157 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002158 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002159 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002160 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2161 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002162 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002163 // 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 +09002164 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002165
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002166 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002167 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002168 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002169 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002170 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002171 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002172 files := genRule.GeneratedSourceFiles()
2173 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002174 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002175 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002176 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 -07002177 }
2178 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002179 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002180 }
Colin Crossca860ac2016-01-04 14:34:37 -08002181 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002182 return
2183 }
2184
Colin Crossfe17f6f2019-03-28 19:30:56 -07002185 if depTag == android.ProtoPluginDepTag {
2186 return
2187 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002188 if depTag == llndkImplDep {
2189 return
2190 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002191
Colin Crossd11fcda2017-10-23 17:59:01 -07002192 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002193 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2194 return
2195 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002196 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002197 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2198 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002199 return
2200 }
2201
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002202 // re-exporting flags
2203 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002204 // reusing objects only make sense for cc.Modules.
2205 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002206 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002207 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002208 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002209 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002210 return
2211 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002212 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002213
Jiyong Parke4bb9862019-02-01 00:31:10 +09002214 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002215 // staticVariants are a cc.Module specific concept.
2216 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002217 c.staticVariant = ccDep
2218 return
2219 }
2220 }
2221
Jooyung Han74066602020-03-20 04:29:24 +09002222 // For the dependency from platform to apex, use the latest stubs
2223 c.apexSdkVersion = android.FutureApiLevel
2224 if !c.IsForPlatform() {
2225 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2226 }
2227
2228 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2229 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2230 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2231 // (b/144430859)
2232 c.apexSdkVersion = android.FutureApiLevel
2233 }
2234
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002235 if depTag == staticUnwinderDepTag {
Jooyung Han74066602020-03-20 04:29:24 +09002236 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2237 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002238 depTag = StaticDepTag
2239 } else {
2240 return
2241 }
2242 }
2243
Ivan Lozano183a3212019-10-18 14:18:45 -07002244 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2245 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2246 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002247 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002248 if t, ok := depTag.(DependencyTag); ok {
2249 explicitlyVersioned = t.ExplicitlyVersioned
2250 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002251 depTag = t
2252 }
2253
Ivan Lozano183a3212019-10-18 14:18:45 -07002254 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002255 depIsStatic := false
2256 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002257 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002258 depIsStatic = true
2259 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002260 if ccDep.CcLibrary() && !depIsStatic {
2261 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002262 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002263 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002264 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002265
2266 var useThisDep bool
2267 if depIsStubs && explicitlyVersioned {
2268 // Always respect dependency to the versioned stubs (i.e. libX#10)
2269 useThisDep = true
2270 } else if !depHasStubs {
2271 // Use non-stub variant if that is the only choice
2272 // (i.e. depending on a lib without stubs.version property)
2273 useThisDep = true
2274 } else if c.IsForPlatform() {
2275 // If not building for APEX, use stubs only when it is from
2276 // an APEX (and not from platform)
2277 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002278 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2279 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002280 // always link to non-stub variant
2281 useThisDep = !depIsStubs
2282 }
2283 } else {
2284 // If building for APEX, use stubs only when it is not from
2285 // the same APEX
2286 useThisDep = (depInSameApex != depIsStubs)
2287 }
2288
Jooyung Han0c4e0162020-02-26 22:45:42 +09002289 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2290 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han74066602020-03-20 04:29:24 +09002291 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han0c4e0162020-02-26 22:45:42 +09002292 if err != nil {
2293 ctx.OtherModuleErrorf(dep, err.Error())
2294 return
2295 }
2296 if versionToUse != ccDep.StubsVersion() {
2297 useThisDep = false
2298 }
2299 }
2300
Jiyong Park25fc6a92018-11-18 18:02:45 +09002301 if !useThisDep {
2302 return // stop processing this dep
2303 }
2304 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002305 if c.UseVndk() {
2306 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2307 // by default, use current version of LLNDK
2308 versionToUse := ""
2309 versions := stubsVersionsFor(ctx.Config())[depName]
2310 if c.ApexName() != "" && len(versions) > 0 {
2311 // if this is for use_vendor apex && dep has stubsVersions
2312 // apply the same rule of apex sdk enforcement to choose right version
2313 var err error
Jooyung Han74066602020-03-20 04:29:24 +09002314 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han67a96cd2020-03-13 15:23:36 +09002315 if err != nil {
2316 ctx.OtherModuleErrorf(dep, err.Error())
2317 return
2318 }
2319 }
2320 if versionToUse != ccDep.StubsVersion() {
2321 return
2322 }
2323 }
2324 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002325
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002326 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2327
Ivan Lozano52767be2019-10-18 14:49:46 -07002328 // Exporting flags only makes sense for cc.Modules
2329 if _, ok := ccDep.(*Module); ok {
2330 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002331 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002332 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2333 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002334 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002335
Ivan Lozano52767be2019-10-18 14:49:46 -07002336 if t.ReexportFlags {
2337 reexportExporter(i)
2338 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2339 // Re-exported shared library headers must be included as well since they can help us with type information
2340 // about template instantiations (instantiated from their headers).
2341 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2342 // scripts.
2343 c.sabi.Properties.ReexportedIncludes = append(
2344 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2345 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002346 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002347 }
Logan Chienf3511742017-10-31 18:04:35 +08002348 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002349 }
2350
Colin Cross26c34ed2016-09-30 17:10:16 -07002351 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002352 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002353
Ivan Lozano52767be2019-10-18 14:49:46 -07002354 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002355 depFile := android.OptionalPath{}
2356
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002357 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002358 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002359 ptr = &depPaths.SharedLibs
2360 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002361 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002362 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002363
Jiyong Park64a44f22019-01-18 14:37:08 +09002364 case earlySharedDepTag:
2365 ptr = &depPaths.EarlySharedLibs
2366 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002367 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002368 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002369 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002370 ptr = &depPaths.LateSharedLibs
2371 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002372 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002373 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002374 ptr = nil
2375 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002376 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002377 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002378 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002379 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002380 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002381 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002382 return
2383 }
2384
Ivan Lozano52767be2019-10-18 14:49:46 -07002385 // Because the static library objects are included, this only makes sense
2386 // in the context of proper cc.Modules.
2387 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2388 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2389 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2390 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2391 for i := range missingDeps {
2392 missingDeps[i] += postfix
2393 }
2394 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002395 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002396 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2397 } else {
2398 ctx.ModuleErrorf(
2399 "non-cc.Modules cannot be included as whole static libraries.", depName)
2400 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002401 }
Colin Cross5950f382016-12-13 12:50:57 -08002402 case headerDepTag:
2403 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002404 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002405 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002406 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002407 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002408 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002409 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002410 case dynamicLinkerDepTag:
2411 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002412 }
2413
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002414 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002415 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002416 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002417 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002418 return
2419 }
2420
2421 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002422 // in static libraries act as if they were whole static libraries. The same goes for
2423 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002424 // This should only be done for cc.Modules
2425 if c, ok := ccDep.(*Module); ok {
2426 staticLib := c.linker.(libraryInterface)
2427 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2428 staticLib.objs().coverageFiles...)
2429 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2430 staticLib.objs().sAbiDumpFiles...)
2431 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002432 }
2433
Colin Cross26c34ed2016-09-30 17:10:16 -07002434 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002435 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002436 if !ctx.Config().AllowMissingDependencies() {
2437 ctx.ModuleErrorf("module %q missing output file", depName)
2438 } else {
2439 ctx.AddMissingDependencies([]string{depName})
2440 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002441 return
2442 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002443 *ptr = append(*ptr, linkFile.Path())
2444 }
2445
Colin Crossc99deeb2016-04-11 15:06:20 -07002446 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002447 dep := depFile
2448 if !dep.Valid() {
2449 dep = linkFile
2450 }
2451 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002452 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002453
Inseob Kimeec88e12020-01-22 11:11:29 +09002454 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2455
2456 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002457 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002458 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002459 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002460 return libName
2461 }
2462
2463 makeLibName := func(depName string) string {
2464 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002465 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002466 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002467 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002468
Inseob Kimeec88e12020-01-22 11:11:29 +09002469 if c, ok := ccDep.(*Module); ok {
2470 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002471 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002472 baseName := c.BaseModuleName()
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002473
2474 if c.IsVndk() {
2475 return baseName + ".vendor"
2476 }
2477
Inseob Kimeec88e12020-01-22 11:11:29 +09002478 if vendorSuffixModules[baseName] {
2479 return baseName + ".vendor"
2480 } else {
2481 return baseName
2482 }
2483 }
2484 }
2485
Yifan Hong1b3348d2020-01-21 15:53:22 -08002486 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002487 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2488 // core module instead.
2489 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002490 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002491 // The vendor module in Make will have been renamed to not conflict with the core
2492 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002493 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002494 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002495 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002496 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2497 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002498 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002499 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002500 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002501 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002502 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002503 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002504 }
Logan Chien43d34c32017-12-20 01:17:32 +08002505 }
2506
2507 // Export the shared libs to Make.
2508 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002509 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002510 if ccDep.CcLibrary() {
2511 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002512 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002513 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002514 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002515 c.Properties.ApexesProvidingSharedLibs = append(
2516 c.Properties.ApexesProvidingSharedLibs, an)
2517 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002518 }
2519 }
2520
Jiyong Park27b188b2017-07-18 13:23:39 +09002521 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002522 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002523 c.Properties.AndroidMkSharedLibs = append(
2524 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002525 // Record baseLibName for snapshots.
2526 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002527 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002528 c.Properties.AndroidMkSharedLibs = append(
2529 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002530 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002531 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002532 c.Properties.AndroidMkStaticLibs = append(
2533 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002534 case runtimeDepTag:
2535 c.Properties.AndroidMkRuntimeLibs = append(
2536 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002537 // Record baseLibName for snapshots.
2538 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002539 case wholeStaticDepTag:
2540 c.Properties.AndroidMkWholeStaticLibs = append(
2541 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002542 }
Colin Crossca860ac2016-01-04 14:34:37 -08002543 })
2544
Jeff Gaston294356f2017-09-27 17:05:30 -07002545 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002546 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002547
Colin Crossdd84e052017-05-17 13:44:16 -07002548 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002549 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002550 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2551 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002552 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002553 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002554 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2555 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002556 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002557 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002558 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002559
2560 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002561 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002562 }
Colin Crossdd84e052017-05-17 13:44:16 -07002563
Colin Crossca860ac2016-01-04 14:34:37 -08002564 return depPaths
2565}
2566
2567func (c *Module) InstallInData() bool {
2568 if c.installer == nil {
2569 return false
2570 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002571 return c.installer.inData()
2572}
2573
2574func (c *Module) InstallInSanitizerDir() bool {
2575 if c.installer == nil {
2576 return false
2577 }
2578 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002579 return true
2580 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002581 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002582}
2583
Yifan Hong1b3348d2020-01-21 15:53:22 -08002584func (c *Module) InstallInRamdisk() bool {
2585 return c.InRamdisk()
2586}
2587
Jiyong Parkf9332f12018-02-01 00:54:12 +09002588func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002589 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002590}
2591
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +01002592func (c *Module) SkipInstall() {
2593 if c.installer == nil {
2594 c.ModuleBase.SkipInstall()
2595 return
2596 }
2597 c.installer.skipInstall(c)
2598}
2599
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002600func (c *Module) HostToolPath() android.OptionalPath {
2601 if c.installer == nil {
2602 return android.OptionalPath{}
2603 }
2604 return c.installer.hostToolPath()
2605}
2606
Nan Zhangd4e641b2017-07-12 12:55:28 -07002607func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2608 return c.outputFile
2609}
2610
Colin Cross41955e82019-05-29 14:40:35 -07002611func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2612 switch tag {
2613 case "":
2614 if c.outputFile.Valid() {
2615 return android.Paths{c.outputFile.Path()}, nil
2616 }
2617 return android.Paths{}, nil
2618 default:
2619 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002620 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002621}
2622
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002623func (c *Module) static() bool {
2624 if static, ok := c.linker.(interface {
2625 static() bool
2626 }); ok {
2627 return static.static()
2628 }
2629 return false
2630}
2631
Jiyong Park379de2f2018-12-19 02:47:14 +09002632func (c *Module) staticBinary() bool {
2633 if static, ok := c.linker.(interface {
2634 staticBinary() bool
2635 }); ok {
2636 return static.staticBinary()
2637 }
2638 return false
2639}
2640
Jiyong Park1d1119f2019-07-29 21:27:18 +09002641func (c *Module) header() bool {
2642 if h, ok := c.linker.(interface {
2643 header() bool
2644 }); ok {
2645 return h.header()
2646 }
2647 return false
2648}
2649
Jooyung Han38002912019-05-16 04:01:54 +09002650func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002651 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002652 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2653 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002654 return "native:vndk"
2655 }
Jooyung Han38002912019-05-16 04:01:54 +09002656 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002657 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002658 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002659 if Bool(c.VendorProperties.Vendor_available) {
2660 return "native:vndk"
2661 }
2662 return "native:vndk_private"
2663 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002664 if c.inProduct() {
2665 return "native:product"
2666 }
Jooyung Han38002912019-05-16 04:01:54 +09002667 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002668 } else if c.InRamdisk() {
2669 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002670 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002671 return "native:recovery"
2672 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2673 return "native:ndk:none:none"
2674 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2675 //family, link := getNdkStlFamilyAndLinkType(c)
2676 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002677 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002678 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002679 } else {
2680 return "native:platform"
2681 }
2682}
2683
Jiyong Park9d452992018-10-03 00:38:19 +09002684// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002685// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002686func (c *Module) IsInstallableToApex() bool {
2687 if shared, ok := c.linker.(interface {
2688 shared() bool
2689 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002690 // Stub libs and prebuilt libs in a versioned SDK are not
2691 // installable to APEX even though they are shared libs.
2692 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002693 } else if _, ok := c.linker.(testPerSrc); ok {
2694 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002695 }
2696 return false
2697}
2698
Jiyong Parka90ca002019-10-07 15:47:24 +09002699func (c *Module) AvailableFor(what string) bool {
2700 if linker, ok := c.linker.(interface {
2701 availableFor(string) bool
2702 }); ok {
2703 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2704 } else {
2705 return c.ApexModuleBase.AvailableFor(what)
2706 }
2707}
2708
Inseob Kim1f086e22019-05-09 13:29:15 +09002709func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002710 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2711
2712 // The platform variant doesn't need further condition. Apex variants however might not
2713 // be installable because it will likely to be included in the APEX and won't appear
2714 // in the system partition.
2715 if c.IsForPlatform() {
2716 return ret
2717 }
2718
2719 // Special case for modules that are configured to be installed to /data, which includes
2720 // test modules. For these modules, both APEX and non-APEX variants are considered as
2721 // installable. This is because even the APEX variants won't be included in the APEX, but
2722 // will anyway be installed to /data/*.
2723 // See b/146995717
2724 if c.InstallInData() {
2725 return ret
2726 }
2727
2728 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002729}
2730
Logan Chien41eabe62019-04-10 13:33:58 +08002731func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2732 if c.linker != nil {
2733 if library, ok := c.linker.(*libraryDecorator); ok {
2734 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2735 }
2736 }
2737}
2738
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002739func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002740 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002741 if cc, ok := dep.(*Module); ok {
Jiyong Park9f14b9b2020-03-01 17:29:06 +09002742 if cc.HasStubsVariants() {
2743 if depTag.Shared && depTag.Library {
2744 // dynamic dep to a stubs lib crosses APEX boundary
2745 return false
2746 }
2747 if IsRuntimeDepTag(depTag) {
2748 // runtime dep to a stubs lib also crosses APEX boundary
2749 return false
2750 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002751 }
2752 if depTag.FromStatic {
2753 // shared_lib dependency from a static lib is considered as crossing
2754 // the APEX boundary because the dependency doesn't actually is
2755 // linked; the dependency is used only during the compilation phase.
2756 return false
2757 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002758 }
2759 }
2760 return true
2761}
2762
Colin Cross2ba19d92015-05-07 15:44:20 -07002763//
Colin Crosscfad1192015-11-02 16:43:11 -08002764// Defaults
2765//
Colin Crossca860ac2016-01-04 14:34:37 -08002766type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002767 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002768 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002769 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002770}
2771
Patrice Arrudac249c712019-03-19 17:00:29 -07002772// cc_defaults provides a set of properties that can be inherited by other cc
2773// modules. A module can use the properties from a cc_defaults using
2774// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2775// merged (when possible) by prepending the default module's values to the
2776// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002777func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002778 return DefaultsFactory()
2779}
2780
Colin Cross36242852017-06-23 15:06:31 -07002781func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002782 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002783
Colin Cross36242852017-06-23 15:06:31 -07002784 module.AddProperties(props...)
2785 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002786 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002787 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002788 &BaseCompilerProperties{},
2789 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002790 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002791 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002792 &StaticProperties{},
2793 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002794 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002795 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002796 &TestProperties{},
2797 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002798 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002799 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002800 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002801 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002802 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002803 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002804 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002805 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002806 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002807 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002808 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002809 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002810 )
Colin Crosscfad1192015-11-02 16:43:11 -08002811
Jooyung Hancc372c52019-09-25 15:18:44 +09002812 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002813
2814 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002815}
2816
Jiyong Park6a43f042017-10-12 23:05:00 +09002817func squashVendorSrcs(m *Module) {
2818 if lib, ok := m.compiler.(*libraryDecorator); ok {
2819 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2820 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2821
2822 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2823 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2824 }
2825}
2826
Jiyong Parkf9332f12018-02-01 00:54:12 +09002827func squashRecoverySrcs(m *Module) {
2828 if lib, ok := m.compiler.(*libraryDecorator); ok {
2829 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2830 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2831
2832 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2833 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2834 }
2835}
2836
Colin Cross7228ecd2019-11-18 16:00:16 -08002837var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002838
Colin Cross7228ecd2019-11-18 16:00:16 -08002839func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002840 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002841 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002842 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002843
2844 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002845 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002846 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002847 }
Logan Chienf3511742017-10-31 18:04:35 +08002848
2849 if vndkdep := m.vndkdep; vndkdep != nil {
2850 if vndkdep.isVndk() {
Justin Yun98df0d12020-02-28 15:07:59 +09002851 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002852 if !vndkdep.isVndkExt() {
2853 mctx.PropertyErrorf("vndk",
2854 "must set `extends: \"...\"` to vndk extension")
Justin Yun98df0d12020-02-28 15:07:59 +09002855 } else if m.VendorProperties.Vendor_available != nil {
2856 mctx.PropertyErrorf("vendor_available",
2857 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002858 }
2859 } else {
2860 if vndkdep.isVndkExt() {
2861 mctx.PropertyErrorf("vndk",
Justin Yun98df0d12020-02-28 15:07:59 +09002862 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002863 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002864 }
2865 if m.VendorProperties.Vendor_available == nil {
2866 mctx.PropertyErrorf("vndk",
2867 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002868 }
2869 }
2870 } else {
2871 if vndkdep.isVndkSp() {
2872 mctx.PropertyErrorf("vndk",
2873 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002874 }
2875 if vndkdep.isVndkExt() {
2876 mctx.PropertyErrorf("vndk",
2877 "must set `enabled: true` to set `extends: %q`",
2878 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002879 }
Justin Yun8effde42017-06-23 19:24:43 +09002880 }
2881 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002882
Jiyong Parkf9332f12018-02-01 00:54:12 +09002883 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002884 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002885 var recoveryVariantNeeded bool = false
2886
Inseob Kim64c43952019-08-26 16:52:35 +09002887 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002888 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002889
2890 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002891 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2892 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2893 if boardVndkVersion == "current" {
2894 boardVndkVersion = platformVndkVersion
2895 }
2896 if productVndkVersion == "current" {
2897 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002898 }
2899
Justin Yun5f7f7e82019-11-18 19:52:14 +09002900 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002901 // If the device isn't compiling against the VNDK, we always
2902 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002903 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002904 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002905 // LL-NDK stubs only exist in the vendor and product variants,
2906 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002907 vendorVariants = append(vendorVariants,
2908 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002909 boardVndkVersion,
2910 )
2911 productVariants = append(productVariants,
2912 platformVndkVersion,
2913 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002914 )
Jiyong Park2a454122017-10-19 15:59:33 +09002915 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2916 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002917 vendorVariants = append(vendorVariants,
2918 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002919 boardVndkVersion,
2920 )
2921 productVariants = append(productVariants,
2922 platformVndkVersion,
2923 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002924 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002925 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002926 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2927 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002928 if snapshot, ok := m.linker.(interface {
2929 version() string
2930 }); ok {
2931 vendorVariants = append(vendorVariants, snapshot.version())
2932 } else {
2933 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2934 }
Justin Yun98df0d12020-02-28 15:07:59 +09002935 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002936 // This will be available in /system, /vendor and /product
2937 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002938 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002939 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002940 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002941 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2942 // code is PLATFORM_VNDK_VERSION.
2943 // On the other hand, vendor_available modules which are not VNDK should
2944 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002945 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002946 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002947 vendorVariants = append(vendorVariants, boardVndkVersion)
2948 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002949 }
Logan Chienf3511742017-10-31 18:04:35 +08002950 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002951 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002952 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002953 } else {
2954 // This is either in /system (or similar: /data), or is a
2955 // modules built with the NDK. Modules built with the NDK
2956 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002957 coreVariantNeeded = true
2958 }
2959
Justin Yun5f7f7e82019-11-18 19:52:14 +09002960 if boardVndkVersion != "" && productVndkVersion != "" {
2961 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2962 // The module has "product_specific: true" that does not create core variant.
2963 coreVariantNeeded = false
2964 productVariants = append(productVariants, productVndkVersion)
2965 }
2966 } else {
2967 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2968 // restriction to use system libs.
2969 // No product variants defined in this case.
2970 productVariants = []string{}
2971 }
2972
Yifan Hong1b3348d2020-01-21 15:53:22 -08002973 if Bool(m.Properties.Ramdisk_available) {
2974 ramdiskVariantNeeded = true
2975 }
2976
2977 if m.ModuleBase.InstallInRamdisk() {
2978 ramdiskVariantNeeded = true
2979 coreVariantNeeded = false
2980 }
2981
Jiyong Parkf9332f12018-02-01 00:54:12 +09002982 if Bool(m.Properties.Recovery_available) {
2983 recoveryVariantNeeded = true
2984 }
2985
2986 if m.ModuleBase.InstallInRecovery() {
2987 recoveryVariantNeeded = true
2988 coreVariantNeeded = false
2989 }
2990
Inseob Kim64c43952019-08-26 16:52:35 +09002991 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002992 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2993 }
2994
2995 for _, variant := range android.FirstUniqueStrings(productVariants) {
2996 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002997 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002998
Yifan Hong1b3348d2020-01-21 15:53:22 -08002999 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003000 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3001 m.Properties.CoreVariantNeeded = coreVariantNeeded
3002}
3003
3004func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3005 return c.Properties.CoreVariantNeeded
3006}
3007
Yifan Hong1b3348d2020-01-21 15:53:22 -08003008func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3009 return c.Properties.RamdiskVariantNeeded
3010}
3011
Colin Cross7228ecd2019-11-18 16:00:16 -08003012func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3013 return c.Properties.RecoveryVariantNeeded
3014}
3015
3016func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003017 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003018}
3019
3020func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3021 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003022 if variant == android.RamdiskVariation {
3023 m.MakeAsPlatform()
3024 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003025 m.MakeAsPlatform()
3026 squashRecoverySrcs(m)
3027 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003028 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003029 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3030 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003031
3032 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3033 // Hide other vendor variants to avoid collision.
3034 vndkVersion := ctx.DeviceConfig().VndkVersion()
3035 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3036 m.Properties.HideFromMake = true
3037 m.SkipInstall()
3038 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003039 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3040 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3041 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3042 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003043 }
3044}
3045
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003046func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003047 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003048 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3049 }
Colin Cross6510f912017-11-29 00:27:14 -08003050 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003051}
3052
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003053func kytheExtractAllFactory() android.Singleton {
3054 return &kytheExtractAllSingleton{}
3055}
3056
3057type kytheExtractAllSingleton struct {
3058}
3059
3060func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3061 var xrefTargets android.Paths
3062 ctx.VisitAllModules(func(module android.Module) {
3063 if ccModule, ok := module.(xref); ok {
3064 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3065 }
3066 })
3067 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3068 if len(xrefTargets) > 0 {
3069 ctx.Build(pctx, android.BuildParams{
3070 Rule: blueprint.Phony,
3071 Output: android.PathForPhony(ctx, "xref_cxx"),
3072 Inputs: xrefTargets,
3073 //Default: true,
3074 })
3075 }
3076}
3077
Colin Cross06a931b2015-10-28 17:23:31 -07003078var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003079var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003080var BoolPtr = proptools.BoolPtr
3081var String = proptools.String
3082var StringPtr = proptools.StringPtr