blob: bef922a1fc86386e7b69dbc4523b2c87064aad69 [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()
Colin Cross1e676be2016-10-12 14:38:15 -070052 })
Colin Cross16b23492016-01-06 14:41:07 -080053
Paul Duffin036e7002019-12-19 19:16:28 +000054 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070055 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
56 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080057
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070058 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
59 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
60
Mitch Phillipsbfeade62019-05-01 14:42:05 -070061 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
62 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
63
Jiyong Park1d1119f2019-07-29 21:27:18 +090064 // cfi mutator shouldn't run before sanitizers that return true for
65 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000066 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
67 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
68
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080069 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
70 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
71
Colin Cross1e676be2016-10-12 14:38:15 -070072 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
73 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080074
Colin Cross0b908332019-06-19 23:00:20 -070075 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090076 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080077
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080078 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080079 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070080
81 ctx.TopDown("lto_deps", ltoDepsMutator)
82 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090083
84 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070085 })
Colin Crossb98c8b02016-07-29 13:44:28 -070086
Sasha Smundak2a4549e2018-11-05 16:49:08 -080087 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070088}
89
Colin Crossca860ac2016-01-04 14:34:37 -080090type Deps struct {
91 SharedLibs, LateSharedLibs []string
92 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080093 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080094 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070095
Colin Cross5950f382016-12-13 12:50:57 -080096 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070097
Colin Cross81413472016-04-11 14:37:39 -070098 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070099
Dan Willemsenb40aab62016-04-20 14:21:14 -0700100 GeneratedSources []string
101 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900102 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700103
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700104 ReexportGeneratedHeaders []string
105
Colin Cross97ba0732015-03-23 17:50:24 -0700106 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700107
108 // Used for host bionic
109 LinkerFlagsFile string
110 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700111}
112
Colin Crossca860ac2016-01-04 14:34:37 -0800113type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700114 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900115 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900117 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700119 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700122 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800123 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700124 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700127 GeneratedSources android.Paths
128 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900129 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700130
Inseob Kimd110f872019-12-06 13:15:38 +0900131 Flags []string
132 IncludeDirs android.Paths
133 SystemIncludeDirs android.Paths
134 ReexportedDirs android.Paths
135 ReexportedSystemDirs android.Paths
136 ReexportedFlags []string
137 ReexportedGeneratedHeaders android.Paths
138 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700139
Colin Cross26c34ed2016-09-30 17:10:16 -0700140 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700141 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700142
143 // Path to the file container flags to use with the linker
144 LinkerFlagsFile android.OptionalPath
145
146 // Path to the dynamic linker binary
147 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700148}
149
Colin Cross4af21ed2019-11-04 09:37:55 -0800150// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
151// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
152// command line so they can be overridden by the local module flags).
153type LocalOrGlobalFlags struct {
154 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700155 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800156 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 CFlags []string // Flags that apply to C and C++ source files
158 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
159 ConlyFlags []string // Flags that apply to C source files
160 CppFlags []string // Flags that apply to C++ source files
161 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700162 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800163}
164
165type Flags struct {
166 Local LocalOrGlobalFlags
167 Global LocalOrGlobalFlags
168
169 aidlFlags []string // Flags that apply to aidl source files
170 rsFlags []string // Flags that apply to renderscript source files
171 libFlags []string // Flags to add libraries early to the link order
172 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
173 TidyFlags []string // Flags that apply to clang-tidy
174 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700175
Colin Crossc3199482017-03-30 15:03:04 -0700176 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800177 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700178 SystemIncludeFlags []string
179
Colin Crossb98c8b02016-07-29 13:44:28 -0700180 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700181 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800182 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800183 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800184 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800185
186 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800187 DynamicLinker string
188
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700189 CFlagsDeps android.Paths // Files depended on by compiler flags
190 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800191
Dan Willemsen98ab3112019-08-27 21:20:40 -0700192 AssemblerWithCpp bool
193 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800194
Colin Cross19878da2019-03-28 14:45:07 -0700195 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700196 protoC bool // Whether to use C instead of C++
197 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700198
199 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700200}
201
Colin Crossca860ac2016-01-04 14:34:37 -0800202// Properties used to compile all C or C++ modules
203type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700204 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800205 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700206
207 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800208 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700209
Jiyong Parkde866cb2018-12-07 23:08:36 +0900210 AndroidMkSharedLibs []string `blueprint:"mutated"`
211 AndroidMkStaticLibs []string `blueprint:"mutated"`
212 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
213 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
214 HideFromMake bool `blueprint:"mutated"`
215 PreventInstall bool `blueprint:"mutated"`
216 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700217
Justin Yun5f7f7e82019-11-18 19:52:14 +0900218 ImageVariationPrefix string `blueprint:"mutated"`
219 VndkVersion string `blueprint:"mutated"`
220 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800221
222 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
223 // file
224 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900225
Yifan Hong1b3348d2020-01-21 15:53:22 -0800226 // Make this module available when building for ramdisk
227 Ramdisk_available *bool
228
Jiyong Parkf9332f12018-02-01 00:54:12 +0900229 // Make this module available when building for recovery
230 Recovery_available *bool
231
Colin Crossae6c5202019-11-20 13:35:50 -0800232 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800233 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800234 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800235 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900236 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900237
238 // Allows this module to use non-APEX version of libraries. Useful
239 // for building binaries that are started before APEXes are activated.
240 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900241
242 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
243 // see soong/cc/config/vndk.go
244 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900245
246 // Used by vendor snapshot to record dependencies from snapshot modules.
247 SnapshotSharedLibs []string `blueprint:"mutated"`
248 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700249}
250
251type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900252 // whether this module should be allowed to be directly depended by other
253 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900254 // In addition, this module should be allowed to be directly depended by
255 // product modules with `product_specific: true`.
256 // If set to true, three variants will be built separately, one like
257 // normal, another limited to the set of libraries and headers
258 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700259 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900260 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700261 // so it shouldn't have any unversioned runtime dependencies, or
262 // make assumptions about the system that may not be true in the
263 // future.
264 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900265 // If set to false, this module becomes inaccessible from /vendor or /product
266 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900267 //
268 // Default value is true when vndk: {enabled: true} or vendor: true.
269 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700270 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900271 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700272 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900273
274 // whether this module is capable of being loaded with other instance
275 // (possibly an older version) of the same module in the same process.
276 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
277 // can be double loaded in a vendor process if the library is also a
278 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
279 // explicitly marked as `double_loadable: true` by the owner, or the dependency
280 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
281 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800282}
283
Colin Crossca860ac2016-01-04 14:34:37 -0800284type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800285 static() bool
286 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900287 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700288 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700289 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800290 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700291 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800292 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900293 isLlndk(config android.Config) bool
294 isLlndkPublic(config android.Config) bool
295 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900296 isVndk() bool
297 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800298 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900299 inProduct() bool
300 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800301 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900302 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800303 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700304 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700305 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800306 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800307 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800308 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800309 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800310 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900311 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900312 hasStubsVariants() bool
313 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900314 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800315 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700316 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800317}
318
319type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700320 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800321 ModuleContextIntf
322}
323
324type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700325 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800326 ModuleContextIntf
327}
328
Colin Cross37047f12016-12-13 17:06:13 -0800329type DepsContext interface {
330 android.BottomUpMutatorContext
331 ModuleContextIntf
332}
333
Colin Crossca860ac2016-01-04 14:34:37 -0800334type feature interface {
335 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800336 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800337 flags(ctx ModuleContext, flags Flags) Flags
338 props() []interface{}
339}
340
341type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700342 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800343 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800344 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700345 compilerProps() []interface{}
346
Colin Cross76fada02016-07-27 10:31:13 -0700347 appendCflags([]string)
348 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700349 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800350}
351
352type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700353 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800354 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700355 linkerFlags(ctx ModuleContext, flags Flags) Flags
356 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800357 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700358
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700359 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700360 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900361 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700362
363 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900364 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800365}
366
367type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700368 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700369 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800370 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700371 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700372 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900373 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800374}
375
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800376type xref interface {
377 XrefCcFiles() android.Paths
378}
379
Colin Crossc99deeb2016-04-11 15:06:20 -0700380var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700381 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
382 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
383 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
384 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
385 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
386 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
387 headerDepTag = DependencyTag{Name: "header", Library: true}
388 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
389 genSourceDepTag = DependencyTag{Name: "gen source"}
390 genHeaderDepTag = DependencyTag{Name: "gen header"}
391 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
392 objDepTag = DependencyTag{Name: "obj"}
393 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
394 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
395 reuseObjTag = DependencyTag{Name: "reuse objects"}
396 staticVariantTag = DependencyTag{Name: "static variant"}
397 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
398 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
399 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
400 runtimeDepTag = DependencyTag{Name: "runtime lib"}
401 coverageDepTag = DependencyTag{Name: "coverage"}
402 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700403)
404
Roland Levillainf89cd092019-07-29 16:22:59 +0100405func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700406 ccDepTag, ok := depTag.(DependencyTag)
407 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100408}
409
Jiyong Park83dc74b2020-01-14 18:38:44 +0900410func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
411 ccDepTag, ok := depTag.(DependencyTag)
412 return ok && (ccDepTag == staticExportDepTag ||
413 ccDepTag == lateStaticDepTag ||
414 ccDepTag == wholeStaticDepTag)
415}
416
Roland Levillainf89cd092019-07-29 16:22:59 +0100417func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700418 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100419 return ok && ccDepTag == runtimeDepTag
420}
421
422func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700423 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100424 return ok && ccDepTag == testPerSrcDepTag
425}
426
Colin Crossca860ac2016-01-04 14:34:37 -0800427// Module contains the properties and members used by all C/C++ module types, and implements
428// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
429// to construct the output file. Behavior can be customized with a Customizer interface
430type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700431 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700432 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900433 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900434 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700435
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700436 Properties BaseProperties
437 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700438
Colin Crossca860ac2016-01-04 14:34:37 -0800439 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700440 hod android.HostOrDeviceSupported
441 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700442
Paul Duffina0843f62019-12-13 19:50:38 +0000443 // Allowable SdkMemberTypes of this module type.
444 sdkMemberTypes []android.SdkMemberType
445
Colin Crossca860ac2016-01-04 14:34:37 -0800446 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700447 features []feature
448 compiler compiler
449 linker linker
450 installer installer
451 stl *stl
452 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800453 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800454 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900455 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700456 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700457 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800458 xom *xom
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
Jiyong Park83dc74b2020-01-14 18:38:44 +0900480
481 // name of the modules that are direct or indirect static deps of this module
482 allStaticDeps []string
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 }
617 }
618 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
619}
620
Ivan Lozano52767be2019-10-18 14:49:46 -0700621func (c *Module) BuildStubs() bool {
622 if c.linker != nil {
623 if library, ok := c.linker.(*libraryDecorator); ok {
624 return library.buildStubs()
625 }
626 }
627 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
628}
629
Ivan Lozano183a3212019-10-18 14:18:45 -0700630func (c *Module) SetStubsVersions(version string) {
631 if c.linker != nil {
632 if library, ok := c.linker.(*libraryDecorator); ok {
633 library.MutatedProperties.StubsVersion = version
634 return
635 }
636 }
637 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
638}
639
640func (c *Module) SetStatic() {
641 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700642 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700643 library.setStatic()
644 return
645 }
646 }
647 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
648}
649
650func (c *Module) SetShared() {
651 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700652 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700653 library.setShared()
654 return
655 }
656 }
657 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
658}
659
660func (c *Module) BuildStaticVariant() bool {
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 return library.buildStatic()
664 }
665 }
666 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
667}
668
669func (c *Module) BuildSharedVariant() bool {
670 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700671 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700672 return library.buildShared()
673 }
674 }
675 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
676}
677
678func (c *Module) Module() android.Module {
679 return c
680}
681
Jiyong Parkc20eee32018-09-05 22:36:17 +0900682func (c *Module) OutputFile() android.OptionalPath {
683 return c.outputFile
684}
685
Ivan Lozano183a3212019-10-18 14:18:45 -0700686var _ LinkableInterface = (*Module)(nil)
687
Jiyong Park719b4462019-01-13 00:39:51 +0900688func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900689 if c.linker != nil {
690 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900691 }
692 return nil
693}
694
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900695func (c *Module) CoverageOutputFile() android.OptionalPath {
696 if c.linker != nil {
697 return c.linker.coverageOutputFilePath()
698 }
699 return android.OptionalPath{}
700}
701
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900702func (c *Module) RelativeInstallPath() string {
703 if c.installer != nil {
704 return c.installer.relativeInstallPath()
705 }
706 return ""
707}
708
Jooyung Han344d5432019-08-23 11:17:39 +0900709func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900710 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900711}
712
Colin Cross36242852017-06-23 15:06:31 -0700713func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700714 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800715 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700716 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800717 }
718 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700719 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800720 }
721 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700722 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800723 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700724 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700725 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700726 }
Colin Cross16b23492016-01-06 14:41:07 -0800727 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700728 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800729 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800730 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700731 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800732 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800733 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700734 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800735 }
Justin Yun8effde42017-06-23 19:24:43 +0900736 if c.vndkdep != nil {
737 c.AddProperties(c.vndkdep.props()...)
738 }
Stephen Craneba090d12017-05-09 15:44:35 -0700739 if c.lto != nil {
740 c.AddProperties(c.lto.props()...)
741 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700742 if c.pgo != nil {
743 c.AddProperties(c.pgo.props()...)
744 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800745 if c.xom != nil {
746 c.AddProperties(c.xom.props()...)
747 }
Colin Crossca860ac2016-01-04 14:34:37 -0800748 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700749 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800750 }
Colin Crossc472d572015-03-17 15:06:21 -0700751
Colin Crossa9d8bee2018-10-02 13:59:46 -0700752 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
753 switch class {
754 case android.Device:
755 return ctx.Config().DevicePrefer32BitExecutables()
756 case android.HostCross:
757 // Windows builds always prefer 32-bit
758 return true
759 default:
760 return false
761 }
762 })
Colin Cross36242852017-06-23 15:06:31 -0700763 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900764 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900765 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900766 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900767
Colin Cross36242852017-06-23 15:06:31 -0700768 return c
Colin Crossc472d572015-03-17 15:06:21 -0700769}
770
Colin Crossb916a382016-07-29 17:28:03 -0700771// Returns true for dependency roots (binaries)
772// TODO(ccross): also handle dlopenable libraries
773func (c *Module) isDependencyRoot() bool {
774 if root, ok := c.linker.(interface {
775 isDependencyRoot() bool
776 }); ok {
777 return root.isDependencyRoot()
778 }
779 return false
780}
781
Justin Yun5f7f7e82019-11-18 19:52:14 +0900782// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
783// "product" and "vendor" variant modules return true for this function.
784// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
785// "soc_specific: true" and more vendor installed modules are included here.
786// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
787// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700788func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900789 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700790}
791
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800792func (c *Module) isCoverageVariant() bool {
793 return c.coverage.Properties.IsCoverageVariant
794}
795
Peter Collingbournead84f972019-12-17 16:46:18 -0800796func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800797 return inList(c.Name(), ndkMigratedLibs)
798}
799
Inseob Kim9516ee92019-05-09 10:56:13 +0900800func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800801 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900802 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800803}
804
Inseob Kim9516ee92019-05-09 10:56:13 +0900805func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800806 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900807 name := c.BaseModuleName()
808 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800809}
810
Inseob Kim9516ee92019-05-09 10:56:13 +0900811func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800812 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900813 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800814}
815
Ivan Lozano52767be2019-10-18 14:49:46 -0700816func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800817 if vndkdep := c.vndkdep; vndkdep != nil {
818 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900819 }
820 return false
821}
822
Yi Kong7e53c572018-02-14 18:16:12 +0800823func (c *Module) isPgoCompile() bool {
824 if pgo := c.pgo; pgo != nil {
825 return pgo.Properties.PgoCompile
826 }
827 return false
828}
829
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800830func (c *Module) isNDKStubLibrary() bool {
831 if _, ok := c.compiler.(*stubDecorator); ok {
832 return true
833 }
834 return false
835}
836
Logan Chienf3511742017-10-31 18:04:35 +0800837func (c *Module) isVndkSp() bool {
838 if vndkdep := c.vndkdep; vndkdep != nil {
839 return vndkdep.isVndkSp()
840 }
841 return false
842}
843
844func (c *Module) isVndkExt() bool {
845 if vndkdep := c.vndkdep; vndkdep != nil {
846 return vndkdep.isVndkExt()
847 }
848 return false
849}
850
Ivan Lozano52767be2019-10-18 14:49:46 -0700851func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900852 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800853}
854
Logan Chienf3511742017-10-31 18:04:35 +0800855func (c *Module) getVndkExtendsModuleName() string {
856 if vndkdep := c.vndkdep; vndkdep != nil {
857 return vndkdep.getVndkExtendsModuleName()
858 }
859 return ""
860}
861
Justin Yun5f7f7e82019-11-18 19:52:14 +0900862// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900863// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700864func (c *Module) HasVendorVariant() bool {
865 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900866}
867
Justin Yun5f7f7e82019-11-18 19:52:14 +0900868const (
869 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
870 // against the VNDK.
871 VendorVariationPrefix = "vendor."
872
873 // ProductVariationPrefix is the variant prefix used for /product code that compiles
874 // against the VNDK.
875 ProductVariationPrefix = "product."
876)
877
878// Returns true if the module is "product" variant. Usually these modules are installed in /product
879func (c *Module) inProduct() bool {
880 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
881}
882
883// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
884func (c *Module) inVendor() bool {
885 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
886}
887
Yifan Hong1b3348d2020-01-21 15:53:22 -0800888func (c *Module) InRamdisk() bool {
889 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
890}
891
Ivan Lozano52767be2019-10-18 14:49:46 -0700892func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800893 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900894}
895
Yifan Hong1b3348d2020-01-21 15:53:22 -0800896func (c *Module) OnlyInRamdisk() bool {
897 return c.ModuleBase.InstallInRamdisk()
898}
899
Ivan Lozano52767be2019-10-18 14:49:46 -0700900func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900901 return c.ModuleBase.InstallInRecovery()
902}
903
Jiyong Park25fc6a92018-11-18 18:02:45 +0900904func (c *Module) IsStubs() bool {
905 if library, ok := c.linker.(*libraryDecorator); ok {
906 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900907 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
908 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900909 }
910 return false
911}
912
913func (c *Module) HasStubsVariants() bool {
914 if library, ok := c.linker.(*libraryDecorator); ok {
915 return len(library.Properties.Stubs.Versions) > 0
916 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700917 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
918 return len(library.Properties.Stubs.Versions) > 0
919 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900920 return false
921}
922
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900923func (c *Module) bootstrap() bool {
924 return Bool(c.Properties.Bootstrap)
925}
926
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700927func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700928 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
929 if c.Target().NativeBridge == android.NativeBridgeEnabled {
930 return false
931 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700932 return c.linker != nil && c.linker.nativeCoverage()
933}
934
Inseob Kim8471cda2019-11-15 09:59:12 +0900935func (c *Module) isSnapshotPrebuilt() bool {
936 _, ok := c.linker.(*vndkPrebuiltLibraryDecorator)
937 return ok
938}
939
Jiyong Park73c54ee2019-10-22 20:31:18 +0900940func (c *Module) ExportedIncludeDirs() android.Paths {
941 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
942 return flagsProducer.exportedDirs()
943 }
Jiyong Park232e7852019-11-04 12:23:40 +0900944 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900945}
946
947func (c *Module) ExportedSystemIncludeDirs() android.Paths {
948 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
949 return flagsProducer.exportedSystemDirs()
950 }
Jiyong Park232e7852019-11-04 12:23:40 +0900951 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900952}
953
954func (c *Module) ExportedFlags() []string {
955 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
956 return flagsProducer.exportedFlags()
957 }
Jiyong Park232e7852019-11-04 12:23:40 +0900958 return nil
959}
960
961func (c *Module) ExportedDeps() android.Paths {
962 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
963 return flagsProducer.exportedDeps()
964 }
965 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900966}
967
Inseob Kimd110f872019-12-06 13:15:38 +0900968func (c *Module) ExportedGeneratedHeaders() android.Paths {
969 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
970 return flagsProducer.exportedGeneratedHeaders()
971 }
972 return nil
973}
974
Jiyong Parkf1194352019-02-25 11:05:47 +0900975func isBionic(name string) bool {
976 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000977 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900978 return true
979 }
980 return false
981}
982
Martin Stjernholm279de572019-09-10 23:18:20 +0100983func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700984 if name == "libclang_rt.hwasan-aarch64-android" {
985 return inList("hwaddress", config.SanitizeDevice())
986 }
987 return isBionic(name)
988}
989
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800990func (c *Module) XrefCcFiles() android.Paths {
991 return c.kytheFiles
992}
993
Colin Crossca860ac2016-01-04 14:34:37 -0800994type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700995 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800996 moduleContextImpl
997}
998
Colin Cross37047f12016-12-13 17:06:13 -0800999type depsContext struct {
1000 android.BottomUpMutatorContext
1001 moduleContextImpl
1002}
1003
Colin Crossca860ac2016-01-04 14:34:37 -08001004type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001005 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001006 moduleContextImpl
1007}
1008
Justin Yun5f7f7e82019-11-18 19:52:14 +09001009func (ctx *moduleContext) ProductSpecific() bool {
1010 return ctx.ModuleContext.ProductSpecific() ||
1011 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1012}
1013
Jiyong Park2db76922017-11-08 16:03:48 +09001014func (ctx *moduleContext) SocSpecific() bool {
1015 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001016 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001017}
1018
Colin Crossca860ac2016-01-04 14:34:37 -08001019type moduleContextImpl struct {
1020 mod *Module
1021 ctx BaseModuleContext
1022}
1023
Colin Crossb98c8b02016-07-29 13:44:28 -07001024func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001025 return ctx.mod.toolchain(ctx.ctx)
1026}
1027
1028func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001029 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001030}
1031
1032func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001033 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001034}
1035
Jiyong Park1d1119f2019-07-29 21:27:18 +09001036func (ctx *moduleContextImpl) header() bool {
1037 return ctx.mod.header()
1038}
1039
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001040func (ctx *moduleContextImpl) useSdk() bool {
Yifan Hong1b3348d2020-01-21 15:53:22 -08001041 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -08001042 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001043 }
1044 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001045}
1046
1047func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001048 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001049 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001050 vndkVer := ctx.mod.VndkVersion()
1051 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1052 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001053 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001054 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001055 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001056 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001057 }
1058 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001059}
1060
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001061func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001062 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001063}
Justin Yun8effde42017-06-23 19:24:43 +09001064
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001065func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001066 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001067}
1068
Inseob Kim9516ee92019-05-09 10:56:13 +09001069func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1070 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001071}
1072
Inseob Kim9516ee92019-05-09 10:56:13 +09001073func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1074 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001075}
1076
Inseob Kim9516ee92019-05-09 10:56:13 +09001077func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1078 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001079}
1080
Logan Chienf3511742017-10-31 18:04:35 +08001081func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001082 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001083}
1084
Yi Kong7e53c572018-02-14 18:16:12 +08001085func (ctx *moduleContextImpl) isPgoCompile() bool {
1086 return ctx.mod.isPgoCompile()
1087}
1088
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001089func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1090 return ctx.mod.isNDKStubLibrary()
1091}
1092
Justin Yun8effde42017-06-23 19:24:43 +09001093func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001094 return ctx.mod.isVndkSp()
1095}
1096
1097func (ctx *moduleContextImpl) isVndkExt() bool {
1098 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001099}
1100
Vic Yangefd249e2018-11-12 20:19:56 -08001101func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001102 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001103}
1104
Justin Yun5f7f7e82019-11-18 19:52:14 +09001105func (ctx *moduleContextImpl) inProduct() bool {
1106 return ctx.mod.inProduct()
1107}
1108
1109func (ctx *moduleContextImpl) inVendor() bool {
1110 return ctx.mod.inVendor()
1111}
1112
Yifan Hong1b3348d2020-01-21 15:53:22 -08001113func (ctx *moduleContextImpl) inRamdisk() bool {
1114 return ctx.mod.InRamdisk()
1115}
1116
Jiyong Parkf9332f12018-02-01 00:54:12 +09001117func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001118 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001119}
1120
Logan Chien2f2b8902018-07-10 15:01:19 +08001121// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001122func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001123 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1124 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001125 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001126
1127 if ctx.ctx.Fuchsia() {
1128 return false
1129 }
1130
Logan Chien2f2b8902018-07-10 15:01:19 +08001131 if sanitize := ctx.mod.sanitize; sanitize != nil {
1132 if !sanitize.isVariantOnProductionDevice() {
1133 return false
1134 }
1135 }
1136 if !ctx.ctx.Device() {
1137 // Host modules do not need ABI dumps.
1138 return false
1139 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001140 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001141 // Stubs do not need ABI dumps.
1142 return false
1143 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001144 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001145}
1146
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001147func (ctx *moduleContextImpl) selectedStl() string {
1148 if stl := ctx.mod.stl; stl != nil {
1149 return stl.Properties.SelectedStl
1150 }
1151 return ""
1152}
1153
Ivan Lozanobd721262018-11-27 14:33:03 -08001154func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1155 return ctx.mod.linker.useClangLld(actx)
1156}
1157
Colin Crossce75d2c2016-10-06 16:12:58 -07001158func (ctx *moduleContextImpl) baseModuleName() string {
1159 return ctx.mod.ModuleBase.BaseModuleName()
1160}
1161
Logan Chienf3511742017-10-31 18:04:35 +08001162func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1163 return ctx.mod.getVndkExtendsModuleName()
1164}
1165
Logan Chiene274fc92019-12-03 11:18:32 -08001166func (ctx *moduleContextImpl) isForPlatform() bool {
1167 return ctx.mod.IsForPlatform()
1168}
1169
Jiyong Park58e364a2019-01-19 19:24:06 +09001170func (ctx *moduleContextImpl) apexName() string {
1171 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001172}
1173
Jiyong Parkb0788572018-12-20 22:10:17 +09001174func (ctx *moduleContextImpl) hasStubsVariants() bool {
1175 return ctx.mod.HasStubsVariants()
1176}
1177
1178func (ctx *moduleContextImpl) isStubs() bool {
1179 return ctx.mod.IsStubs()
1180}
1181
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001182func (ctx *moduleContextImpl) bootstrap() bool {
1183 return ctx.mod.bootstrap()
1184}
1185
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001186func (ctx *moduleContextImpl) nativeCoverage() bool {
1187 return ctx.mod.nativeCoverage()
1188}
1189
Colin Cross635c3b02016-05-18 15:37:25 -07001190func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001191 return &Module{
1192 hod: hod,
1193 multilib: multilib,
1194 }
1195}
1196
Colin Cross635c3b02016-05-18 15:37:25 -07001197func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001198 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001199 module.features = []feature{
1200 &tidyFeature{},
1201 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001202 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001203 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001204 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001205 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001206 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001207 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001208 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001209 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001210 return module
1211}
1212
Colin Crossce75d2c2016-10-06 16:12:58 -07001213func (c *Module) Prebuilt() *android.Prebuilt {
1214 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1215 return p.prebuilt()
1216 }
1217 return nil
1218}
1219
1220func (c *Module) Name() string {
1221 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001222 if p, ok := c.linker.(interface {
1223 Name(string) string
1224 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001225 name = p.Name(name)
1226 }
1227 return name
1228}
1229
Alex Light3d673592019-01-18 14:37:31 -08001230func (c *Module) Symlinks() []string {
1231 if p, ok := c.installer.(interface {
1232 symlinkList() []string
1233 }); ok {
1234 return p.symlinkList()
1235 }
1236 return nil
1237}
1238
Jeff Gaston294356f2017-09-27 17:05:30 -07001239// orderDeps reorders dependencies into a list such that if module A depends on B, then
1240// A will precede B in the resultant list.
1241// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001242// Note that directSharedDeps should be the analogous static library for each shared lib dep
1243func 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 -07001244 // If A depends on B, then
1245 // Every list containing A will also contain B later in the list
1246 // So, after concatenating all lists, the final instance of B will have come from the same
1247 // original list as the final instance of A
1248 // So, the final instance of B will be later in the concatenation than the final A
1249 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1250 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001251 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001252 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001253 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1254 }
1255 for _, dep := range directSharedDeps {
1256 orderedAllDeps = append(orderedAllDeps, dep)
1257 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001258 }
1259
Colin Crossb6715442017-10-24 11:13:31 -07001260 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001261
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001262 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001263 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001264 // resultant list to only what the caller has chosen to include in directStaticDeps
1265 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001266
1267 return orderedAllDeps, orderedDeclaredDeps
1268}
1269
Ivan Lozano183a3212019-10-18 14:18:45 -07001270func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001271 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001272 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001273 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1274 staticDepFiles := []android.Path{}
1275 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001276 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1277 if dep.OutputFile().Valid() {
1278 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1279 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1280 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001281 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001282 sharedDepFiles := []android.Path{}
1283 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001284 if sharedDep.HasStaticVariant() {
1285 staticAnalogue := sharedDep.GetStaticVariant()
1286 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1287 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001288 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001289 }
1290
1291 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001292 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1293 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001294
1295 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001296}
1297
Jiyong Park83dc74b2020-01-14 18:38:44 +09001298func gatherTransitiveStaticDeps(staticDeps []LinkableInterface) []string {
1299 var ret []string
1300 for _, dep := range staticDeps {
1301 ret = append(ret, dep.Module().Name())
1302 ret = append(ret, dep.AllStaticDeps()...)
1303 }
1304 return android.FirstUniqueStrings(ret)
1305}
1306
Roland Levillainf89cd092019-07-29 16:22:59 +01001307func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1308 test, ok := c.linker.(testPerSrc)
1309 return ok && test.isAllTestsVariation()
1310}
1311
Justin Yun5f7f7e82019-11-18 19:52:14 +09001312func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1313 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1314 // "current", it will append the VNDK version to the name suffix.
1315 var vndkVersion string
1316 var nameSuffix string
1317 if c.inProduct() {
1318 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1319 nameSuffix = productSuffix
1320 } else {
1321 vndkVersion = ctx.DeviceConfig().VndkVersion()
1322 nameSuffix = vendorSuffix
1323 }
1324 if vndkVersion == "current" {
1325 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1326 }
1327 if c.Properties.VndkVersion != vndkVersion {
1328 // add version suffix only if the module is using different vndk version than the
1329 // version in product or vendor partition.
1330 nameSuffix += "." + c.Properties.VndkVersion
1331 }
1332 return nameSuffix
1333}
1334
Colin Cross635c3b02016-05-18 15:37:25 -07001335func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001336 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001337 //
1338 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1339 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1340 // module and return early, as this module does not produce an output file per se.
1341 if c.IsTestPerSrcAllTestsVariation() {
1342 c.outputFile = android.OptionalPath{}
1343 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001344 }
1345
Jooyung Han38002912019-05-16 04:01:54 +09001346 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001347
Inseob Kim64c43952019-08-26 16:52:35 +09001348 c.Properties.SubName = ""
1349
1350 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1351 c.Properties.SubName += nativeBridgeSuffix
1352 }
1353
Justin Yun5f7f7e82019-11-18 19:52:14 +09001354 _, llndk := c.linker.(*llndkStubDecorator)
1355 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1356 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1357 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1358 // added for product variant only when we have vendor and product variants with core
1359 // variant. The suffix is not added for vendor-only or product-only module.
1360 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1361 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001362 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1363 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1364 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001365 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1366 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001367 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001368 c.Properties.SubName += recoverySuffix
1369 }
1370
Colin Crossca860ac2016-01-04 14:34:37 -08001371 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001372 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001373 moduleContextImpl: moduleContextImpl{
1374 mod: c,
1375 },
1376 }
1377 ctx.ctx = ctx
1378
Colin Crossf18e1102017-11-16 14:33:08 -08001379 deps := c.depsToPaths(ctx)
1380 if ctx.Failed() {
1381 return
1382 }
1383
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001384 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1385 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1386 }
1387
Colin Crossca860ac2016-01-04 14:34:37 -08001388 flags := Flags{
1389 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001390 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001391 }
Colin Crossca860ac2016-01-04 14:34:37 -08001392 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001393 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001394 }
1395 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001396 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001397 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001398 if c.stl != nil {
1399 flags = c.stl.flags(ctx, flags)
1400 }
Colin Cross16b23492016-01-06 14:41:07 -08001401 if c.sanitize != nil {
1402 flags = c.sanitize.flags(ctx, flags)
1403 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001404 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001405 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001406 }
Stephen Craneba090d12017-05-09 15:44:35 -07001407 if c.lto != nil {
1408 flags = c.lto.flags(ctx, flags)
1409 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001410 if c.pgo != nil {
1411 flags = c.pgo.flags(ctx, flags)
1412 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001413 if c.xom != nil {
1414 flags = c.xom.flags(ctx, flags)
1415 }
Colin Crossca860ac2016-01-04 14:34:37 -08001416 for _, feature := range c.features {
1417 flags = feature.flags(ctx, flags)
1418 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001419 if ctx.Failed() {
1420 return
1421 }
1422
Colin Cross4af21ed2019-11-04 09:37:55 -08001423 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1424 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1425 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001426
Colin Cross4af21ed2019-11-04 09:37:55 -08001427 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001428
1429 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001430 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001431 }
1432 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001433 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001434 }
1435
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001436 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001437 // We need access to all the flags seen by a source file.
1438 if c.sabi != nil {
1439 flags = c.sabi.flags(ctx, flags)
1440 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001441
Colin Cross4af21ed2019-11-04 09:37:55 -08001442 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001443
Colin Crossca860ac2016-01-04 14:34:37 -08001444 // Optimization to reduce size of build.ninja
1445 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001446 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1447 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1448 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1449 flags.Local.CFlags = []string{"$cflags"}
1450 flags.Local.CppFlags = []string{"$cppflags"}
1451 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001452
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001453 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001454 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001455 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001456 if ctx.Failed() {
1457 return
1458 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001459 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001460 }
1461
Colin Crossca860ac2016-01-04 14:34:37 -08001462 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001463 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001464 if ctx.Failed() {
1465 return
1466 }
Colin Cross635c3b02016-05-18 15:37:25 -07001467 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001468
1469 // If a lib is directly included in any of the APEXes, unhide the stubs
1470 // variant having the latest version gets visible to make. In addition,
1471 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1472 // force anything in the make world to link against the stubs library.
1473 // (unless it is explicitly referenced via .bootstrap suffix or the
1474 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001475 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001476 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001477 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001478 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001479 c.Properties.HideFromMake = false // unhide
1480 // Note: this is still non-installable
1481 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001482 }
Colin Cross5049f022015-03-18 13:28:46 -07001483
Inseob Kim1f086e22019-05-09 13:29:15 +09001484 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001485 c.installer.install(ctx, c.outputFile.Path())
1486 if ctx.Failed() {
1487 return
Colin Crossca860ac2016-01-04 14:34:37 -08001488 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001489 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001490}
1491
Colin Cross0ea8ba82019-06-06 14:33:29 -07001492func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001493 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001494 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001495 }
Colin Crossca860ac2016-01-04 14:34:37 -08001496 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001497}
1498
Colin Crossca860ac2016-01-04 14:34:37 -08001499func (c *Module) begin(ctx BaseModuleContext) {
1500 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001501 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001502 }
Colin Crossca860ac2016-01-04 14:34:37 -08001503 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001504 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001505 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001506 if c.stl != nil {
1507 c.stl.begin(ctx)
1508 }
Colin Cross16b23492016-01-06 14:41:07 -08001509 if c.sanitize != nil {
1510 c.sanitize.begin(ctx)
1511 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001512 if c.coverage != nil {
1513 c.coverage.begin(ctx)
1514 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001515 if c.sabi != nil {
1516 c.sabi.begin(ctx)
1517 }
Justin Yun8effde42017-06-23 19:24:43 +09001518 if c.vndkdep != nil {
1519 c.vndkdep.begin(ctx)
1520 }
Stephen Craneba090d12017-05-09 15:44:35 -07001521 if c.lto != nil {
1522 c.lto.begin(ctx)
1523 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001524 if c.pgo != nil {
1525 c.pgo.begin(ctx)
1526 }
Colin Crossca860ac2016-01-04 14:34:37 -08001527 for _, feature := range c.features {
1528 feature.begin(ctx)
1529 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001530 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001531 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001532 if err != nil {
1533 ctx.PropertyErrorf("sdk_version", err.Error())
1534 }
Nan Zhang0007d812017-11-07 10:57:05 -08001535 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001536 }
Colin Crossca860ac2016-01-04 14:34:37 -08001537}
1538
Colin Cross37047f12016-12-13 17:06:13 -08001539func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001540 deps := Deps{}
1541
1542 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001543 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001544 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001545 // Add the PGO dependency (the clang_rt.profile runtime library), which
1546 // sometimes depends on symbols from libgcc, before libgcc gets added
1547 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001548 if c.pgo != nil {
1549 deps = c.pgo.deps(ctx, deps)
1550 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001551 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001552 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001553 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001554 if c.stl != nil {
1555 deps = c.stl.deps(ctx, deps)
1556 }
Colin Cross16b23492016-01-06 14:41:07 -08001557 if c.sanitize != nil {
1558 deps = c.sanitize.deps(ctx, deps)
1559 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001560 if c.coverage != nil {
1561 deps = c.coverage.deps(ctx, deps)
1562 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001563 if c.sabi != nil {
1564 deps = c.sabi.deps(ctx, deps)
1565 }
Justin Yun8effde42017-06-23 19:24:43 +09001566 if c.vndkdep != nil {
1567 deps = c.vndkdep.deps(ctx, deps)
1568 }
Stephen Craneba090d12017-05-09 15:44:35 -07001569 if c.lto != nil {
1570 deps = c.lto.deps(ctx, deps)
1571 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001572 for _, feature := range c.features {
1573 deps = feature.deps(ctx, deps)
1574 }
1575
Colin Crossb6715442017-10-24 11:13:31 -07001576 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1577 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1578 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1579 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1580 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1581 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001582 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001583
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001584 for _, lib := range deps.ReexportSharedLibHeaders {
1585 if !inList(lib, deps.SharedLibs) {
1586 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1587 }
1588 }
1589
1590 for _, lib := range deps.ReexportStaticLibHeaders {
1591 if !inList(lib, deps.StaticLibs) {
1592 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1593 }
1594 }
1595
Colin Cross5950f382016-12-13 12:50:57 -08001596 for _, lib := range deps.ReexportHeaderLibHeaders {
1597 if !inList(lib, deps.HeaderLibs) {
1598 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1599 }
1600 }
1601
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001602 for _, gen := range deps.ReexportGeneratedHeaders {
1603 if !inList(gen, deps.GeneratedHeaders) {
1604 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1605 }
1606 }
1607
Colin Crossc99deeb2016-04-11 15:06:20 -07001608 return deps
1609}
1610
Dan Albert7e9d2952016-08-04 13:02:36 -07001611func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001612 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001613 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001614 moduleContextImpl: moduleContextImpl{
1615 mod: c,
1616 },
1617 }
1618 ctx.ctx = ctx
1619
Colin Crossca860ac2016-01-04 14:34:37 -08001620 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001621}
1622
Jiyong Park7ed9de32018-10-15 22:25:07 +09001623// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001624func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001625 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1626 version := name[sharp+1:]
1627 libname := name[:sharp]
1628 return libname, version
1629 }
1630 return name, ""
1631}
1632
Colin Cross1e676be2016-10-12 14:38:15 -07001633func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001634 ctx := &depsContext{
1635 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001636 moduleContextImpl: moduleContextImpl{
1637 mod: c,
1638 },
1639 }
1640 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001641
Colin Crossc99deeb2016-04-11 15:06:20 -07001642 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001643
Dan Albert914449f2016-06-17 16:45:24 -07001644 variantNdkLibs := []string{}
1645 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001646 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001647 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001648
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001649 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1650 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001651 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001652 // 1. Name of an NDK library that refers to a prebuilt module.
1653 // For each of these, it adds the name of the prebuilt module (which will be in
1654 // prebuilts/ndk) to the list of nonvariant libs.
1655 // 2. Name of an NDK library that refers to an ndk_library module.
1656 // For each of these, it adds the name of the ndk_library module to the list of
1657 // variant libs.
1658 // 3. Anything else (so anything that isn't an NDK library).
1659 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001660 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001661 // The caller can then know to add the variantLibs dependencies differently from the
1662 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001663
Inseob Kim9516ee92019-05-09 10:56:13 +09001664 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001665 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1666 variantLibs = []string{}
1667 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001668 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001669 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001670 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001671 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1672 if !inList(name, ndkMigratedLibs) {
1673 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001674 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001675 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001676 }
Jooyung Han0302a842019-10-30 18:43:49 +09001677 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001678 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001679 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001680 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001681 if actx.OtherModuleExists(vendorPublicLib) {
1682 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1683 } else {
1684 // This can happen if vendor_public_library module is defined in a
1685 // namespace that isn't visible to the current module. In that case,
1686 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001687 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001688 }
Dan Albert914449f2016-06-17 16:45:24 -07001689 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001690 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001691 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001692 }
1693 }
Dan Albert914449f2016-06-17 16:45:24 -07001694 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001695 }
1696
Dan Albert914449f2016-06-17 16:45:24 -07001697 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1698 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001699 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001700 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001701
Jiyong Park7e636d02019-01-28 16:16:54 +09001702 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001703 if c.linker != nil {
1704 if library, ok := c.linker.(*libraryDecorator); ok {
1705 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001706 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001707 }
1708 }
1709 }
1710
Colin Cross32ec36c2016-12-15 07:39:51 -08001711 for _, lib := range deps.HeaderLibs {
1712 depTag := headerDepTag
1713 if inList(lib, deps.ReexportHeaderLibHeaders) {
1714 depTag = headerExportDepTag
1715 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001716 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001717 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001718 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001719 } else {
1720 actx.AddVariationDependencies(nil, depTag, lib)
1721 }
1722 }
1723
1724 if buildStubs {
1725 // Stubs lib does not have dependency to other static/shared libraries.
1726 // Don't proceed.
1727 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001728 }
Colin Cross5950f382016-12-13 12:50:57 -08001729
Inseob Kimc0907f12019-02-08 21:00:45 +09001730 syspropImplLibraries := syspropImplLibraries(actx.Config())
1731
Jiyong Park5d1598f2019-02-25 22:14:17 +09001732 for _, lib := range deps.WholeStaticLibs {
1733 depTag := wholeStaticDepTag
1734 if impl, ok := syspropImplLibraries[lib]; ok {
1735 lib = impl
1736 }
1737 actx.AddVariationDependencies([]blueprint.Variation{
1738 {Mutator: "link", Variation: "static"},
1739 }, depTag, lib)
1740 }
1741
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001742 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001743 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001744 if inList(lib, deps.ReexportStaticLibHeaders) {
1745 depTag = staticExportDepTag
1746 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001747
1748 if impl, ok := syspropImplLibraries[lib]; ok {
1749 lib = impl
1750 }
1751
Dan Willemsen59339a22018-07-22 21:18:45 -07001752 actx.AddVariationDependencies([]blueprint.Variation{
1753 {Mutator: "link", Variation: "static"},
1754 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001755 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001756
Dan Willemsen59339a22018-07-22 21:18:45 -07001757 actx.AddVariationDependencies([]blueprint.Variation{
1758 {Mutator: "link", Variation: "static"},
1759 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001760
Ivan Lozano183a3212019-10-18 14:18:45 -07001761 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001762 var variations []blueprint.Variation
1763 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Yifan Hong1b3348d2020-01-21 15:53:22 -08001764 versionVariantAvail := !ctx.useVndk() && !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001765 if version != "" && versionVariantAvail {
1766 // Version is explicitly specified. i.e. libFoo#30
1767 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001768 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001769 }
1770 actx.AddVariationDependencies(variations, depTag, name)
1771
1772 // If the version is not specified, add dependency to the latest stubs library.
1773 // The stubs library will be used when the depending module is built for APEX and
1774 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001775 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001776 if version == "" && latestVersion != "" && versionVariantAvail {
1777 actx.AddVariationDependencies([]blueprint.Variation{
1778 {Mutator: "link", Variation: "shared"},
1779 {Mutator: "version", Variation: latestVersion},
1780 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001781 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001782 }
1783 }
1784
Jiyong Park7ed9de32018-10-15 22:25:07 +09001785 // shared lib names without the #version suffix
1786 var sharedLibNames []string
1787
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001788 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001789 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001790 if inList(lib, deps.ReexportSharedLibHeaders) {
1791 depTag = sharedExportDepTag
1792 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001793
1794 if impl, ok := syspropImplLibraries[lib]; ok {
1795 lib = impl
1796 }
1797
Jiyong Park73c54ee2019-10-22 20:31:18 +09001798 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001799 sharedLibNames = append(sharedLibNames, name)
1800
Jiyong Park25fc6a92018-11-18 18:02:45 +09001801 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001802 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001803
Jiyong Park7ed9de32018-10-15 22:25:07 +09001804 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001805 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001806 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1807 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1808 // linking against both the stubs lib and the non-stubs lib at the same time.
1809 continue
1810 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001811 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001812 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001813
Dan Willemsen59339a22018-07-22 21:18:45 -07001814 actx.AddVariationDependencies([]blueprint.Variation{
1815 {Mutator: "link", Variation: "shared"},
1816 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001817
Colin Cross68861832016-07-08 10:41:41 -07001818 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001819
1820 for _, gen := range deps.GeneratedHeaders {
1821 depTag := genHeaderDepTag
1822 if inList(gen, deps.ReexportGeneratedHeaders) {
1823 depTag = genHeaderExportDepTag
1824 }
1825 actx.AddDependency(c, depTag, gen)
1826 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001827
Colin Cross42d48b72018-08-29 14:10:52 -07001828 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001829
1830 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001831 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001832 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001833 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001834 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001835 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001836 if deps.LinkerFlagsFile != "" {
1837 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1838 }
1839 if deps.DynamicLinker != "" {
1840 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001841 }
Dan Albert914449f2016-06-17 16:45:24 -07001842
1843 version := ctx.sdkVersion()
1844 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001845 {Mutator: "ndk_api", Variation: version},
1846 {Mutator: "link", Variation: "shared"},
1847 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001848 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001849 {Mutator: "ndk_api", Variation: version},
1850 {Mutator: "link", Variation: "shared"},
1851 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001852
1853 if vndkdep := c.vndkdep; vndkdep != nil {
1854 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001855 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001856 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001857 {Mutator: "link", Variation: "shared"},
1858 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001859 }
1860 }
Colin Cross6362e272015-10-29 15:25:03 -07001861}
Colin Cross21b9a242015-03-24 14:15:58 -07001862
Colin Crosse40b4ea2018-10-02 22:25:58 -07001863func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001864 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1865 c.beginMutator(ctx)
1866 }
1867}
1868
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001869// Whether a module can link to another module, taking into
1870// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001871func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1872 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001873 // Host code is not restricted
1874 return
1875 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001876
1877 // VNDK is cc.Module supported only for now.
1878 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001879 // Though vendor code is limited by the vendor mutator,
1880 // each vendor-available module needs to check
1881 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001882 if ccTo, ok := to.(*Module); ok {
1883 if ccFrom.vndkdep != nil {
1884 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1885 }
1886 } else {
1887 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001888 }
1889 return
1890 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001891 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001892 // Platform code can link to anything
1893 return
1894 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001895 if from.InRamdisk() {
1896 // Ramdisk code is not NDK
1897 return
1898 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001899 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001900 // Recovery code is not NDK
1901 return
1902 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001903 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001904 // These are always allowed
1905 return
1906 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001907 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001908 // These are allowed, but they don't set sdk_version
1909 return
1910 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001911 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001912 // These aren't real libraries, but are the stub shared libraries that are included in
1913 // the NDK.
1914 return
1915 }
Logan Chien834b9a62019-01-14 15:39:03 +08001916
Ivan Lozano52767be2019-10-18 14:49:46 -07001917 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001918 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1919 // to link to libc++ (non-NDK and without sdk_version).
1920 return
1921 }
1922
Ivan Lozano52767be2019-10-18 14:49:46 -07001923 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001924 // NDK code linking to platform code is never okay.
1925 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001926 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001927 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001928 }
1929
1930 // At this point we know we have two NDK libraries, but we need to
1931 // check that we're not linking against anything built against a higher
1932 // API level, as it is only valid to link against older or equivalent
1933 // APIs.
1934
Inseob Kim01a28722018-04-11 09:48:45 +09001935 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001936 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001937 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001938 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001939 // Current can't be linked against by anything else.
1940 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001941 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001942 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001943 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001944 if err != nil {
1945 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001946 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001947 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001948 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001949 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001950 if err != nil {
1951 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001952 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001953 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001954 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001955
Inseob Kim01a28722018-04-11 09:48:45 +09001956 if toApi > fromApi {
1957 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001958 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001959 }
1960 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001961 }
Dan Albert202fe492017-12-15 13:56:59 -08001962
1963 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001964 fromStl := from.SelectedStl()
1965 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001966 if fromStl == "" || toStl == "" {
1967 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001968 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001969 // We can be permissive with the system "STL" since it is only the C++
1970 // ABI layer, but in the future we should make sure that everyone is
1971 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001972 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001973 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001974 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1975 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001976 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001977}
1978
Jiyong Park5fb8c102018-04-09 12:03:06 +09001979// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001980// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1981// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001982// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001983func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1984 check := func(child, parent android.Module) bool {
1985 to, ok := child.(*Module)
1986 if !ok {
1987 // follow thru cc.Defaults, etc.
1988 return true
1989 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001990
Jooyung Hana70f0672019-01-18 15:20:43 +09001991 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1992 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001993 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001994
1995 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001996 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001997 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001998 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001999
Jooyung Han0302a842019-10-30 18:43:49 +09002000 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002001 return false
2002 }
2003
2004 var stringPath []string
2005 for _, m := range ctx.GetWalkPath() {
2006 stringPath = append(stringPath, m.Name())
2007 }
2008 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2009 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2010 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2011 return false
2012 }
2013 if module, ok := ctx.Module().(*Module); ok {
2014 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002015 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002016 ctx.WalkDeps(check)
2017 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002018 }
2019 }
2020}
2021
Colin Crossc99deeb2016-04-11 15:06:20 -07002022// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002023func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002024 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002025
Ivan Lozano183a3212019-10-18 14:18:45 -07002026 directStaticDeps := []LinkableInterface{}
2027 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002028
Inseob Kim9516ee92019-05-09 10:56:13 +09002029 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2030
Inseob Kim69378442019-06-03 19:10:47 +09002031 reexportExporter := func(exporter exportedFlagsProducer) {
2032 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2033 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2034 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2035 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002036 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002037 }
2038
Colin Crossd11fcda2017-10-23 17:59:01 -07002039 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002040 depName := ctx.OtherModuleName(dep)
2041 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002042
Ivan Lozano52767be2019-10-18 14:49:46 -07002043 ccDep, ok := dep.(LinkableInterface)
2044 if !ok {
2045
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002046 // handling for a few module types that aren't cc Module but that are also supported
2047 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002048 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002049 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002050 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2051 genRule.GeneratedSourceFiles()...)
2052 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002053 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002054 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002055 // Support exported headers from a generated_sources dependency
2056 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002057 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002058 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002059 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002060 genRule.GeneratedSourceFiles()...)
2061 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002062 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002063 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002064 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002065 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002066 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002067 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2068 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002069 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002070 // 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 +09002071 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002072
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002073 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002074 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002075 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002076 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002077 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002078 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002079 files := genRule.GeneratedSourceFiles()
2080 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002081 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002082 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002083 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 -07002084 }
2085 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002086 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002087 }
Colin Crossca860ac2016-01-04 14:34:37 -08002088 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002089 return
2090 }
2091
Colin Crossfe17f6f2019-03-28 19:30:56 -07002092 if depTag == android.ProtoPluginDepTag {
2093 return
2094 }
2095
Colin Crossd11fcda2017-10-23 17:59:01 -07002096 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002097 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2098 return
2099 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002100 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002101 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002102 return
2103 }
2104
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002105 // re-exporting flags
2106 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002107 // reusing objects only make sense for cc.Modules.
2108 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002109 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002110 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002111 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002112 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002113 return
2114 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002115 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002116
Jiyong Parke4bb9862019-02-01 00:31:10 +09002117 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002118 // staticVariants are a cc.Module specific concept.
2119 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002120 c.staticVariant = ccDep
2121 return
2122 }
2123 }
2124
Ivan Lozano183a3212019-10-18 14:18:45 -07002125 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2126 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2127 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002128 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002129 if t, ok := depTag.(DependencyTag); ok {
2130 explicitlyVersioned = t.ExplicitlyVersioned
2131 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002132 depTag = t
2133 }
2134
Ivan Lozano183a3212019-10-18 14:18:45 -07002135 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002136 depIsStatic := false
2137 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002138 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002139 depIsStatic = true
2140 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002141 if ccDep.CcLibrary() && !depIsStatic {
2142 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002143 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002144 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002145 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002146
2147 var useThisDep bool
2148 if depIsStubs && explicitlyVersioned {
2149 // Always respect dependency to the versioned stubs (i.e. libX#10)
2150 useThisDep = true
2151 } else if !depHasStubs {
2152 // Use non-stub variant if that is the only choice
2153 // (i.e. depending on a lib without stubs.version property)
2154 useThisDep = true
2155 } else if c.IsForPlatform() {
2156 // If not building for APEX, use stubs only when it is from
2157 // an APEX (and not from platform)
2158 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002159 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2160 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002161 // always link to non-stub variant
2162 useThisDep = !depIsStubs
2163 }
2164 } else {
2165 // If building for APEX, use stubs only when it is not from
2166 // the same APEX
2167 useThisDep = (depInSameApex != depIsStubs)
2168 }
2169
2170 if !useThisDep {
2171 return // stop processing this dep
2172 }
2173 }
2174
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002175 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2176
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 // Exporting flags only makes sense for cc.Modules
2178 if _, ok := ccDep.(*Module); ok {
2179 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002180 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002181 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2182 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002183 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002184
Ivan Lozano52767be2019-10-18 14:49:46 -07002185 if t.ReexportFlags {
2186 reexportExporter(i)
2187 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2188 // Re-exported shared library headers must be included as well since they can help us with type information
2189 // about template instantiations (instantiated from their headers).
2190 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2191 // scripts.
2192 c.sabi.Properties.ReexportedIncludes = append(
2193 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2194 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002195 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002196 }
Logan Chienf3511742017-10-31 18:04:35 +08002197 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002198 }
2199
Colin Cross26c34ed2016-09-30 17:10:16 -07002200 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002201 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002202
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002204 depFile := android.OptionalPath{}
2205
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002206 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002207 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002208 ptr = &depPaths.SharedLibs
2209 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002210 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002211 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002212
Jiyong Park64a44f22019-01-18 14:37:08 +09002213 case earlySharedDepTag:
2214 ptr = &depPaths.EarlySharedLibs
2215 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002216 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002217 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002218 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002219 ptr = &depPaths.LateSharedLibs
2220 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002221 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002222 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002223 ptr = nil
2224 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002225 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002226 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002227 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002228 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002229 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002230 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002231 return
2232 }
2233
Ivan Lozano52767be2019-10-18 14:49:46 -07002234 // Because the static library objects are included, this only makes sense
2235 // in the context of proper cc.Modules.
2236 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2237 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2238 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2239 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2240 for i := range missingDeps {
2241 missingDeps[i] += postfix
2242 }
2243 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002244 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002245 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2246 } else {
2247 ctx.ModuleErrorf(
2248 "non-cc.Modules cannot be included as whole static libraries.", depName)
2249 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002250 }
Colin Cross5950f382016-12-13 12:50:57 -08002251 case headerDepTag:
2252 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002253 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002254 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002255 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002256 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002257 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002258 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002259 case dynamicLinkerDepTag:
2260 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002261 }
2262
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002263 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002264 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002265 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002266 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002267 return
2268 }
2269
2270 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002271 // in static libraries act as if they were whole static libraries. The same goes for
2272 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002273 // This should only be done for cc.Modules
2274 if c, ok := ccDep.(*Module); ok {
2275 staticLib := c.linker.(libraryInterface)
2276 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2277 staticLib.objs().coverageFiles...)
2278 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2279 staticLib.objs().sAbiDumpFiles...)
2280 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002281 }
2282
Colin Cross26c34ed2016-09-30 17:10:16 -07002283 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002284 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002285 if !ctx.Config().AllowMissingDependencies() {
2286 ctx.ModuleErrorf("module %q missing output file", depName)
2287 } else {
2288 ctx.AddMissingDependencies([]string{depName})
2289 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002290 return
2291 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002292 *ptr = append(*ptr, linkFile.Path())
2293 }
2294
Colin Crossc99deeb2016-04-11 15:06:20 -07002295 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002296 dep := depFile
2297 if !dep.Valid() {
2298 dep = linkFile
2299 }
2300 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002301 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002302
Logan Chien43d34c32017-12-20 01:17:32 +08002303 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002304 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002305 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002306 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002307 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002308 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002309 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002310
Yifan Hong1b3348d2020-01-21 15:53:22 -08002311 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002312 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2313 // core module instead.
2314 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002315 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002316 // The vendor module in Make will have been renamed to not conflict with the core
2317 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002318 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002319 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002320 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002321 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2322 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002323 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002324 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002325 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002326 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002327 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002328 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002329 }
Logan Chien43d34c32017-12-20 01:17:32 +08002330 }
2331
2332 // Export the shared libs to Make.
2333 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002334 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002335 if ccDep.CcLibrary() {
2336 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002337 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002338 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002339 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002340 c.Properties.ApexesProvidingSharedLibs = append(
2341 c.Properties.ApexesProvidingSharedLibs, an)
2342 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002343 }
2344 }
2345
Jiyong Park27b188b2017-07-18 13:23:39 +09002346 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002347 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002348 c.Properties.AndroidMkSharedLibs = append(
2349 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kim8471cda2019-11-15 09:59:12 +09002350 // Record depName as-is for snapshots.
2351 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, depName)
Logan Chienc7f797e2019-01-14 15:35:08 +08002352 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002353 c.Properties.AndroidMkSharedLibs = append(
2354 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002355 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002356 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002357 c.Properties.AndroidMkStaticLibs = append(
2358 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002359 case runtimeDepTag:
2360 c.Properties.AndroidMkRuntimeLibs = append(
2361 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kim8471cda2019-11-15 09:59:12 +09002362 // Record depName as-is for snapshots.
2363 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, depName)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002364 case wholeStaticDepTag:
2365 c.Properties.AndroidMkWholeStaticLibs = append(
2366 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002367 }
Colin Crossca860ac2016-01-04 14:34:37 -08002368 })
2369
Jeff Gaston294356f2017-09-27 17:05:30 -07002370 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002371 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002372
Colin Crossdd84e052017-05-17 13:44:16 -07002373 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002374 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002375 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2376 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002377 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002378 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002379 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2380 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002381 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002382 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002383 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002384
2385 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002386 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002387 }
Colin Crossdd84e052017-05-17 13:44:16 -07002388
Jiyong Park83dc74b2020-01-14 18:38:44 +09002389 c.allStaticDeps = gatherTransitiveStaticDeps(directStaticDeps)
2390
Colin Crossca860ac2016-01-04 14:34:37 -08002391 return depPaths
2392}
2393
2394func (c *Module) InstallInData() bool {
2395 if c.installer == nil {
2396 return false
2397 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002398 return c.installer.inData()
2399}
2400
2401func (c *Module) InstallInSanitizerDir() bool {
2402 if c.installer == nil {
2403 return false
2404 }
2405 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002406 return true
2407 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002408 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002409}
2410
Yifan Hong1b3348d2020-01-21 15:53:22 -08002411func (c *Module) InstallInRamdisk() bool {
2412 return c.InRamdisk()
2413}
2414
Jiyong Parkf9332f12018-02-01 00:54:12 +09002415func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002416 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002417}
2418
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002419func (c *Module) HostToolPath() android.OptionalPath {
2420 if c.installer == nil {
2421 return android.OptionalPath{}
2422 }
2423 return c.installer.hostToolPath()
2424}
2425
Nan Zhangd4e641b2017-07-12 12:55:28 -07002426func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2427 return c.outputFile
2428}
2429
Colin Cross41955e82019-05-29 14:40:35 -07002430func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2431 switch tag {
2432 case "":
2433 if c.outputFile.Valid() {
2434 return android.Paths{c.outputFile.Path()}, nil
2435 }
2436 return android.Paths{}, nil
2437 default:
2438 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002439 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002440}
2441
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002442func (c *Module) static() bool {
2443 if static, ok := c.linker.(interface {
2444 static() bool
2445 }); ok {
2446 return static.static()
2447 }
2448 return false
2449}
2450
Jiyong Park379de2f2018-12-19 02:47:14 +09002451func (c *Module) staticBinary() bool {
2452 if static, ok := c.linker.(interface {
2453 staticBinary() bool
2454 }); ok {
2455 return static.staticBinary()
2456 }
2457 return false
2458}
2459
Jiyong Park1d1119f2019-07-29 21:27:18 +09002460func (c *Module) header() bool {
2461 if h, ok := c.linker.(interface {
2462 header() bool
2463 }); ok {
2464 return h.header()
2465 }
2466 return false
2467}
2468
Jooyung Han38002912019-05-16 04:01:54 +09002469func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002470 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002471 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2472 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002473 return "native:vndk"
2474 }
Jooyung Han38002912019-05-16 04:01:54 +09002475 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002476 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002477 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002478 if Bool(c.VendorProperties.Vendor_available) {
2479 return "native:vndk"
2480 }
2481 return "native:vndk_private"
2482 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002483 if c.inProduct() {
2484 return "native:product"
2485 }
Jooyung Han38002912019-05-16 04:01:54 +09002486 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002487 } else if c.InRamdisk() {
2488 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002489 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002490 return "native:recovery"
2491 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2492 return "native:ndk:none:none"
2493 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2494 //family, link := getNdkStlFamilyAndLinkType(c)
2495 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002496 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002497 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002498 } else {
2499 return "native:platform"
2500 }
2501}
2502
Jiyong Park9d452992018-10-03 00:38:19 +09002503// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002504// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002505func (c *Module) IsInstallableToApex() bool {
2506 if shared, ok := c.linker.(interface {
2507 shared() bool
2508 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002509 // Stub libs and prebuilt libs in a versioned SDK are not
2510 // installable to APEX even though they are shared libs.
2511 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002512 } else if _, ok := c.linker.(testPerSrc); ok {
2513 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002514 }
2515 return false
2516}
2517
Jiyong Parka90ca002019-10-07 15:47:24 +09002518func (c *Module) AvailableFor(what string) bool {
2519 if linker, ok := c.linker.(interface {
2520 availableFor(string) bool
2521 }); ok {
2522 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2523 } else {
2524 return c.ApexModuleBase.AvailableFor(what)
2525 }
2526}
2527
Inseob Kim1f086e22019-05-09 13:29:15 +09002528func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002529 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2530
2531 // The platform variant doesn't need further condition. Apex variants however might not
2532 // be installable because it will likely to be included in the APEX and won't appear
2533 // in the system partition.
2534 if c.IsForPlatform() {
2535 return ret
2536 }
2537
2538 // Special case for modules that are configured to be installed to /data, which includes
2539 // test modules. For these modules, both APEX and non-APEX variants are considered as
2540 // installable. This is because even the APEX variants won't be included in the APEX, but
2541 // will anyway be installed to /data/*.
2542 // See b/146995717
2543 if c.InstallInData() {
2544 return ret
2545 }
2546
2547 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002548}
2549
Jiyong Park83dc74b2020-01-14 18:38:44 +09002550func (c *Module) AllStaticDeps() []string {
2551 return c.allStaticDeps
2552}
2553
Logan Chien41eabe62019-04-10 13:33:58 +08002554func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2555 if c.linker != nil {
2556 if library, ok := c.linker.(*libraryDecorator); ok {
2557 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2558 }
2559 }
2560}
2561
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002562func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002563 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2564 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002565 // dynamic dep to a stubs lib crosses APEX boundary
2566 return false
2567 }
2568 }
2569 return true
2570}
2571
Colin Cross2ba19d92015-05-07 15:44:20 -07002572//
Colin Crosscfad1192015-11-02 16:43:11 -08002573// Defaults
2574//
Colin Crossca860ac2016-01-04 14:34:37 -08002575type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002576 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002577 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002578 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002579}
2580
Patrice Arrudac249c712019-03-19 17:00:29 -07002581// cc_defaults provides a set of properties that can be inherited by other cc
2582// modules. A module can use the properties from a cc_defaults using
2583// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2584// merged (when possible) by prepending the default module's values to the
2585// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002586func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002587 return DefaultsFactory()
2588}
2589
Colin Cross36242852017-06-23 15:06:31 -07002590func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002591 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002592
Colin Cross36242852017-06-23 15:06:31 -07002593 module.AddProperties(props...)
2594 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002595 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002596 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002597 &BaseCompilerProperties{},
2598 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002599 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002600 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002601 &StaticProperties{},
2602 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002603 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002604 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002605 &TestProperties{},
2606 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002607 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002608 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002609 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002610 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002611 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002612 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002613 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002614 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002615 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002616 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002617 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002618 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002619 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002620 )
Colin Crosscfad1192015-11-02 16:43:11 -08002621
Jooyung Hancc372c52019-09-25 15:18:44 +09002622 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002623
2624 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002625}
2626
Jiyong Park6a43f042017-10-12 23:05:00 +09002627func squashVendorSrcs(m *Module) {
2628 if lib, ok := m.compiler.(*libraryDecorator); ok {
2629 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2630 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2631
2632 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2633 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2634 }
2635}
2636
Jiyong Parkf9332f12018-02-01 00:54:12 +09002637func squashRecoverySrcs(m *Module) {
2638 if lib, ok := m.compiler.(*libraryDecorator); ok {
2639 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2640 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2641
2642 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2643 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2644 }
2645}
2646
Colin Cross7228ecd2019-11-18 16:00:16 -08002647var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002648
Colin Cross7228ecd2019-11-18 16:00:16 -08002649func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002650 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002651 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002652 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002653
2654 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002655 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002656 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002657 }
Logan Chienf3511742017-10-31 18:04:35 +08002658
2659 if vndkdep := m.vndkdep; vndkdep != nil {
2660 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002661 if productSpecific {
2662 mctx.PropertyErrorf("product_specific",
2663 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002664 }
Logan Chienf3511742017-10-31 18:04:35 +08002665 if vendorSpecific {
2666 if !vndkdep.isVndkExt() {
2667 mctx.PropertyErrorf("vndk",
2668 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002669 }
2670 } else {
2671 if vndkdep.isVndkExt() {
2672 mctx.PropertyErrorf("vndk",
2673 "must set `vendor: true` to set `extends: %q`",
2674 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002675 }
2676 if m.VendorProperties.Vendor_available == nil {
2677 mctx.PropertyErrorf("vndk",
2678 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002679 }
2680 }
2681 } else {
2682 if vndkdep.isVndkSp() {
2683 mctx.PropertyErrorf("vndk",
2684 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002685 }
2686 if vndkdep.isVndkExt() {
2687 mctx.PropertyErrorf("vndk",
2688 "must set `enabled: true` to set `extends: %q`",
2689 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002690 }
Justin Yun8effde42017-06-23 19:24:43 +09002691 }
2692 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002693
Jiyong Parkf9332f12018-02-01 00:54:12 +09002694 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002695 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002696 var recoveryVariantNeeded bool = false
2697
Inseob Kim64c43952019-08-26 16:52:35 +09002698 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002699 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002700
2701 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002702 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2703 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2704 if boardVndkVersion == "current" {
2705 boardVndkVersion = platformVndkVersion
2706 }
2707 if productVndkVersion == "current" {
2708 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002709 }
2710
Justin Yun5f7f7e82019-11-18 19:52:14 +09002711 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002712 // If the device isn't compiling against the VNDK, we always
2713 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002714 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002715 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002716 // LL-NDK stubs only exist in the vendor and product variants,
2717 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002718 vendorVariants = append(vendorVariants,
2719 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002720 boardVndkVersion,
2721 )
2722 productVariants = append(productVariants,
2723 platformVndkVersion,
2724 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002725 )
Jiyong Park2a454122017-10-19 15:59:33 +09002726 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2727 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002728 vendorVariants = append(vendorVariants,
2729 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002730 boardVndkVersion,
2731 )
2732 productVariants = append(productVariants,
2733 platformVndkVersion,
2734 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002735 )
2736 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002737 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2738 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002739 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002740 } else if m.HasVendorVariant() && !vendorSpecific {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002741 // This will be available in /system, /vendor and /product
2742 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002743 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002744 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002745 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002746 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2747 // code is PLATFORM_VNDK_VERSION.
2748 // On the other hand, vendor_available modules which are not VNDK should
2749 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002750 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002751 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002752 vendorVariants = append(vendorVariants, boardVndkVersion)
2753 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002754 }
Logan Chienf3511742017-10-31 18:04:35 +08002755 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002756 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002757 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002758 } else {
2759 // This is either in /system (or similar: /data), or is a
2760 // modules built with the NDK. Modules built with the NDK
2761 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002762 coreVariantNeeded = true
2763 }
2764
Justin Yun5f7f7e82019-11-18 19:52:14 +09002765 if boardVndkVersion != "" && productVndkVersion != "" {
2766 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2767 // The module has "product_specific: true" that does not create core variant.
2768 coreVariantNeeded = false
2769 productVariants = append(productVariants, productVndkVersion)
2770 }
2771 } else {
2772 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2773 // restriction to use system libs.
2774 // No product variants defined in this case.
2775 productVariants = []string{}
2776 }
2777
Yifan Hong1b3348d2020-01-21 15:53:22 -08002778 if Bool(m.Properties.Ramdisk_available) {
2779 ramdiskVariantNeeded = true
2780 }
2781
2782 if m.ModuleBase.InstallInRamdisk() {
2783 ramdiskVariantNeeded = true
2784 coreVariantNeeded = false
2785 }
2786
Jiyong Parkf9332f12018-02-01 00:54:12 +09002787 if Bool(m.Properties.Recovery_available) {
2788 recoveryVariantNeeded = true
2789 }
2790
2791 if m.ModuleBase.InstallInRecovery() {
2792 recoveryVariantNeeded = true
2793 coreVariantNeeded = false
2794 }
2795
Inseob Kim64c43952019-08-26 16:52:35 +09002796 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002797 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2798 }
2799
2800 for _, variant := range android.FirstUniqueStrings(productVariants) {
2801 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002802 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002803
Yifan Hong1b3348d2020-01-21 15:53:22 -08002804 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002805 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2806 m.Properties.CoreVariantNeeded = coreVariantNeeded
2807}
2808
2809func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2810 return c.Properties.CoreVariantNeeded
2811}
2812
Yifan Hong1b3348d2020-01-21 15:53:22 -08002813func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
2814 return c.Properties.RamdiskVariantNeeded
2815}
2816
Colin Cross7228ecd2019-11-18 16:00:16 -08002817func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2818 return c.Properties.RecoveryVariantNeeded
2819}
2820
2821func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002822 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002823}
2824
2825func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2826 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002827 if variant == android.RamdiskVariation {
2828 m.MakeAsPlatform()
2829 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08002830 m.MakeAsPlatform()
2831 squashRecoverySrcs(m)
2832 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002833 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08002834 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2835 squashVendorSrcs(m)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002836 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
2837 m.Properties.ImageVariationPrefix = ProductVariationPrefix
2838 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
2839 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002840 }
2841}
2842
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002843func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002844 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002845 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2846 }
Colin Cross6510f912017-11-29 00:27:14 -08002847 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002848}
2849
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002850func kytheExtractAllFactory() android.Singleton {
2851 return &kytheExtractAllSingleton{}
2852}
2853
2854type kytheExtractAllSingleton struct {
2855}
2856
2857func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2858 var xrefTargets android.Paths
2859 ctx.VisitAllModules(func(module android.Module) {
2860 if ccModule, ok := module.(xref); ok {
2861 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2862 }
2863 })
2864 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2865 if len(xrefTargets) > 0 {
2866 ctx.Build(pctx, android.BuildParams{
2867 Rule: blueprint.Phony,
2868 Output: android.PathForPhony(ctx, "xref_cxx"),
2869 Inputs: xrefTargets,
2870 //Default: true,
2871 })
2872 }
2873}
2874
Colin Cross06a931b2015-10-28 17:23:31 -07002875var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002876var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002877var BoolPtr = proptools.BoolPtr
2878var String = proptools.String
2879var StringPtr = proptools.StringPtr