blob: 0c32225361399527e6383a9dc5cd405466ffd98d [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
226 // Make this module available when building for recovery
227 Recovery_available *bool
228
Colin Crossae6c5202019-11-20 13:35:50 -0800229 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800230 CoreVariantNeeded bool `blueprint:"mutated"`
231 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900232 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900233
234 // Allows this module to use non-APEX version of libraries. Useful
235 // for building binaries that are started before APEXes are activated.
236 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900237
238 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
239 // see soong/cc/config/vndk.go
240 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700241}
242
243type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900244 // whether this module should be allowed to be directly depended by other
245 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900246 // In addition, this module should be allowed to be directly depended by
247 // product modules with `product_specific: true`.
248 // If set to true, three variants will be built separately, one like
249 // normal, another limited to the set of libraries and headers
250 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700251 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900252 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700253 // so it shouldn't have any unversioned runtime dependencies, or
254 // make assumptions about the system that may not be true in the
255 // future.
256 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900257 // If set to false, this module becomes inaccessible from /vendor or /product
258 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900259 //
260 // Default value is true when vndk: {enabled: true} or vendor: true.
261 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700262 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900263 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700264 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900265
266 // whether this module is capable of being loaded with other instance
267 // (possibly an older version) of the same module in the same process.
268 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
269 // can be double loaded in a vendor process if the library is also a
270 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
271 // explicitly marked as `double_loadable: true` by the owner, or the dependency
272 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
273 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800274}
275
Colin Crossca860ac2016-01-04 14:34:37 -0800276type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800277 static() bool
278 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900279 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700280 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700281 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800282 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700283 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800284 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900285 isLlndk(config android.Config) bool
286 isLlndkPublic(config android.Config) bool
287 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900288 isVndk() bool
289 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800290 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900291 inProduct() bool
292 inVendor() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900293 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800294 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700295 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700296 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800297 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800298 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800299 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800300 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800301 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900302 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900303 hasStubsVariants() bool
304 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900305 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800306 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700307 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800308}
309
310type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700311 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800312 ModuleContextIntf
313}
314
315type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700316 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800317 ModuleContextIntf
318}
319
Colin Cross37047f12016-12-13 17:06:13 -0800320type DepsContext interface {
321 android.BottomUpMutatorContext
322 ModuleContextIntf
323}
324
Colin Crossca860ac2016-01-04 14:34:37 -0800325type feature interface {
326 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800327 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800328 flags(ctx ModuleContext, flags Flags) Flags
329 props() []interface{}
330}
331
332type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700333 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800334 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800335 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700336 compilerProps() []interface{}
337
Colin Cross76fada02016-07-27 10:31:13 -0700338 appendCflags([]string)
339 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700340 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800341}
342
343type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700344 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800345 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700346 linkerFlags(ctx ModuleContext, flags Flags) Flags
347 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800348 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700349
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700350 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700351 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900352 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700353
354 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900355 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800356}
357
358type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700359 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700360 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800361 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700362 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700363 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900364 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800365}
366
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800367type xref interface {
368 XrefCcFiles() android.Paths
369}
370
Colin Crossc99deeb2016-04-11 15:06:20 -0700371var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700372 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
373 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
374 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
375 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
376 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
377 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
378 headerDepTag = DependencyTag{Name: "header", Library: true}
379 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
380 genSourceDepTag = DependencyTag{Name: "gen source"}
381 genHeaderDepTag = DependencyTag{Name: "gen header"}
382 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
383 objDepTag = DependencyTag{Name: "obj"}
384 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
385 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
386 reuseObjTag = DependencyTag{Name: "reuse objects"}
387 staticVariantTag = DependencyTag{Name: "static variant"}
388 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
389 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
390 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
391 runtimeDepTag = DependencyTag{Name: "runtime lib"}
392 coverageDepTag = DependencyTag{Name: "coverage"}
393 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700394)
395
Roland Levillainf89cd092019-07-29 16:22:59 +0100396func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700397 ccDepTag, ok := depTag.(DependencyTag)
398 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100399}
400
401func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700402 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100403 return ok && ccDepTag == runtimeDepTag
404}
405
406func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700407 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100408 return ok && ccDepTag == testPerSrcDepTag
409}
410
Colin Crossca860ac2016-01-04 14:34:37 -0800411// Module contains the properties and members used by all C/C++ module types, and implements
412// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
413// to construct the output file. Behavior can be customized with a Customizer interface
414type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700415 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700416 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900417 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900418 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700419
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700420 Properties BaseProperties
421 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700422
Colin Crossca860ac2016-01-04 14:34:37 -0800423 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700424 hod android.HostOrDeviceSupported
425 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700426
Paul Duffina0843f62019-12-13 19:50:38 +0000427 // Allowable SdkMemberTypes of this module type.
428 sdkMemberTypes []android.SdkMemberType
429
Colin Crossca860ac2016-01-04 14:34:37 -0800430 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700431 features []feature
432 compiler compiler
433 linker linker
434 installer installer
435 stl *stl
436 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800437 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800438 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900439 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700440 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700441 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800442 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800443
444 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700445
Colin Cross635c3b02016-05-18 15:37:25 -0700446 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800447
Colin Crossb98c8b02016-07-29 13:44:28 -0700448 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700449
450 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800451
452 // Flags used to compile this module
453 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700454
455 // 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 -0800456 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700457 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800458 depsInLinkOrder android.Paths
459
460 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700461 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900462
463 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800464 // Kythe (source file indexer) paths for this compilation module
465 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700466}
467
Ivan Lozano52767be2019-10-18 14:49:46 -0700468func (c *Module) Toc() android.OptionalPath {
469 if c.linker != nil {
470 if library, ok := c.linker.(libraryInterface); ok {
471 return library.toc()
472 }
473 }
474 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
475}
476
477func (c *Module) ApiLevel() string {
478 if c.linker != nil {
479 if stub, ok := c.linker.(*stubDecorator); ok {
480 return stub.properties.ApiLevel
481 }
482 }
483 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
484}
485
486func (c *Module) Static() bool {
487 if c.linker != nil {
488 if library, ok := c.linker.(libraryInterface); ok {
489 return library.static()
490 }
491 }
492 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
493}
494
495func (c *Module) Shared() bool {
496 if c.linker != nil {
497 if library, ok := c.linker.(libraryInterface); ok {
498 return library.shared()
499 }
500 }
501 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
502}
503
504func (c *Module) SelectedStl() string {
505 return c.stl.Properties.SelectedStl
506}
507
508func (c *Module) ToolchainLibrary() bool {
509 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
510 return true
511 }
512 return false
513}
514
515func (c *Module) NdkPrebuiltStl() bool {
516 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
517 return true
518 }
519 return false
520}
521
522func (c *Module) StubDecorator() bool {
523 if _, ok := c.linker.(*stubDecorator); ok {
524 return true
525 }
526 return false
527}
528
529func (c *Module) SdkVersion() string {
530 return String(c.Properties.Sdk_version)
531}
532
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800533func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700534 if c.linker != nil {
535 if library, ok := c.linker.(exportedFlagsProducer); ok {
536 return library.exportedDirs()
537 }
538 }
539 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
540}
541
542func (c *Module) HasStaticVariant() bool {
543 if c.staticVariant != nil {
544 return true
545 }
546 return false
547}
548
549func (c *Module) GetStaticVariant() LinkableInterface {
550 return c.staticVariant
551}
552
553func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
554 c.depsInLinkOrder = depsInLinkOrder
555}
556
557func (c *Module) GetDepsInLinkOrder() []android.Path {
558 return c.depsInLinkOrder
559}
560
561func (c *Module) StubsVersions() []string {
562 if c.linker != nil {
563 if library, ok := c.linker.(*libraryDecorator); ok {
564 return library.Properties.Stubs.Versions
565 }
566 }
567 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
568}
569
570func (c *Module) CcLibrary() bool {
571 if c.linker != nil {
572 if _, ok := c.linker.(*libraryDecorator); ok {
573 return true
574 }
575 }
576 return false
577}
578
579func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700580 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700581 return true
582 }
583 return false
584}
585
Ivan Lozano2b262972019-11-21 12:30:50 -0800586func (c *Module) NonCcVariants() bool {
587 return false
588}
589
Ivan Lozano183a3212019-10-18 14:18:45 -0700590func (c *Module) SetBuildStubs() {
591 if c.linker != nil {
592 if library, ok := c.linker.(*libraryDecorator); ok {
593 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700594 c.Properties.HideFromMake = true
595 c.sanitize = nil
596 c.stl = nil
597 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700598 return
599 }
600 }
601 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
602}
603
Ivan Lozano52767be2019-10-18 14:49:46 -0700604func (c *Module) BuildStubs() bool {
605 if c.linker != nil {
606 if library, ok := c.linker.(*libraryDecorator); ok {
607 return library.buildStubs()
608 }
609 }
610 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
611}
612
Ivan Lozano183a3212019-10-18 14:18:45 -0700613func (c *Module) SetStubsVersions(version string) {
614 if c.linker != nil {
615 if library, ok := c.linker.(*libraryDecorator); ok {
616 library.MutatedProperties.StubsVersion = version
617 return
618 }
619 }
620 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
621}
622
623func (c *Module) SetStatic() {
624 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700625 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700626 library.setStatic()
627 return
628 }
629 }
630 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
631}
632
633func (c *Module) SetShared() {
634 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700635 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700636 library.setShared()
637 return
638 }
639 }
640 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
641}
642
643func (c *Module) BuildStaticVariant() bool {
644 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700645 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700646 return library.buildStatic()
647 }
648 }
649 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
650}
651
652func (c *Module) BuildSharedVariant() bool {
653 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700654 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700655 return library.buildShared()
656 }
657 }
658 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
659}
660
661func (c *Module) Module() android.Module {
662 return c
663}
664
Jiyong Parkc20eee32018-09-05 22:36:17 +0900665func (c *Module) OutputFile() android.OptionalPath {
666 return c.outputFile
667}
668
Ivan Lozano183a3212019-10-18 14:18:45 -0700669var _ LinkableInterface = (*Module)(nil)
670
Jiyong Park719b4462019-01-13 00:39:51 +0900671func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900672 if c.linker != nil {
673 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900674 }
675 return nil
676}
677
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900678func (c *Module) CoverageOutputFile() android.OptionalPath {
679 if c.linker != nil {
680 return c.linker.coverageOutputFilePath()
681 }
682 return android.OptionalPath{}
683}
684
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900685func (c *Module) RelativeInstallPath() string {
686 if c.installer != nil {
687 return c.installer.relativeInstallPath()
688 }
689 return ""
690}
691
Jooyung Han344d5432019-08-23 11:17:39 +0900692func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900693 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900694}
695
Colin Cross36242852017-06-23 15:06:31 -0700696func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700697 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800698 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700699 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800700 }
701 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700702 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800703 }
704 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700705 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800706 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700707 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700708 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700709 }
Colin Cross16b23492016-01-06 14:41:07 -0800710 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700711 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800712 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800713 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700714 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800715 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800716 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700717 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800718 }
Justin Yun8effde42017-06-23 19:24:43 +0900719 if c.vndkdep != nil {
720 c.AddProperties(c.vndkdep.props()...)
721 }
Stephen Craneba090d12017-05-09 15:44:35 -0700722 if c.lto != nil {
723 c.AddProperties(c.lto.props()...)
724 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700725 if c.pgo != nil {
726 c.AddProperties(c.pgo.props()...)
727 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800728 if c.xom != nil {
729 c.AddProperties(c.xom.props()...)
730 }
Colin Crossca860ac2016-01-04 14:34:37 -0800731 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700732 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800733 }
Colin Crossc472d572015-03-17 15:06:21 -0700734
Colin Crossa9d8bee2018-10-02 13:59:46 -0700735 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
736 switch class {
737 case android.Device:
738 return ctx.Config().DevicePrefer32BitExecutables()
739 case android.HostCross:
740 // Windows builds always prefer 32-bit
741 return true
742 default:
743 return false
744 }
745 })
Colin Cross36242852017-06-23 15:06:31 -0700746 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900747 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900748 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900749 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900750
Colin Cross36242852017-06-23 15:06:31 -0700751 return c
Colin Crossc472d572015-03-17 15:06:21 -0700752}
753
Colin Crossb916a382016-07-29 17:28:03 -0700754// Returns true for dependency roots (binaries)
755// TODO(ccross): also handle dlopenable libraries
756func (c *Module) isDependencyRoot() bool {
757 if root, ok := c.linker.(interface {
758 isDependencyRoot() bool
759 }); ok {
760 return root.isDependencyRoot()
761 }
762 return false
763}
764
Justin Yun5f7f7e82019-11-18 19:52:14 +0900765// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
766// "product" and "vendor" variant modules return true for this function.
767// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
768// "soc_specific: true" and more vendor installed modules are included here.
769// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
770// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700771func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900772 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700773}
774
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800775func (c *Module) isCoverageVariant() bool {
776 return c.coverage.Properties.IsCoverageVariant
777}
778
Peter Collingbournead84f972019-12-17 16:46:18 -0800779func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800780 return inList(c.Name(), ndkMigratedLibs)
781}
782
Inseob Kim9516ee92019-05-09 10:56:13 +0900783func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800784 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900785 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800786}
787
Inseob Kim9516ee92019-05-09 10:56:13 +0900788func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800789 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900790 name := c.BaseModuleName()
791 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800792}
793
Inseob Kim9516ee92019-05-09 10:56:13 +0900794func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800795 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900796 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800797}
798
Ivan Lozano52767be2019-10-18 14:49:46 -0700799func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800800 if vndkdep := c.vndkdep; vndkdep != nil {
801 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900802 }
803 return false
804}
805
Yi Kong7e53c572018-02-14 18:16:12 +0800806func (c *Module) isPgoCompile() bool {
807 if pgo := c.pgo; pgo != nil {
808 return pgo.Properties.PgoCompile
809 }
810 return false
811}
812
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800813func (c *Module) isNDKStubLibrary() bool {
814 if _, ok := c.compiler.(*stubDecorator); ok {
815 return true
816 }
817 return false
818}
819
Logan Chienf3511742017-10-31 18:04:35 +0800820func (c *Module) isVndkSp() bool {
821 if vndkdep := c.vndkdep; vndkdep != nil {
822 return vndkdep.isVndkSp()
823 }
824 return false
825}
826
827func (c *Module) isVndkExt() bool {
828 if vndkdep := c.vndkdep; vndkdep != nil {
829 return vndkdep.isVndkExt()
830 }
831 return false
832}
833
Ivan Lozano52767be2019-10-18 14:49:46 -0700834func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900835 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800836}
837
Logan Chienf3511742017-10-31 18:04:35 +0800838func (c *Module) getVndkExtendsModuleName() string {
839 if vndkdep := c.vndkdep; vndkdep != nil {
840 return vndkdep.getVndkExtendsModuleName()
841 }
842 return ""
843}
844
Justin Yun5f7f7e82019-11-18 19:52:14 +0900845// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900846// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700847func (c *Module) HasVendorVariant() bool {
848 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900849}
850
Justin Yun5f7f7e82019-11-18 19:52:14 +0900851const (
852 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
853 // against the VNDK.
854 VendorVariationPrefix = "vendor."
855
856 // ProductVariationPrefix is the variant prefix used for /product code that compiles
857 // against the VNDK.
858 ProductVariationPrefix = "product."
859)
860
861// Returns true if the module is "product" variant. Usually these modules are installed in /product
862func (c *Module) inProduct() bool {
863 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
864}
865
866// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
867func (c *Module) inVendor() bool {
868 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
869}
870
Ivan Lozano52767be2019-10-18 14:49:46 -0700871func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800872 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900873}
874
Ivan Lozano52767be2019-10-18 14:49:46 -0700875func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900876 return c.ModuleBase.InstallInRecovery()
877}
878
Jiyong Park25fc6a92018-11-18 18:02:45 +0900879func (c *Module) IsStubs() bool {
880 if library, ok := c.linker.(*libraryDecorator); ok {
881 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900882 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
883 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900884 }
885 return false
886}
887
888func (c *Module) HasStubsVariants() bool {
889 if library, ok := c.linker.(*libraryDecorator); ok {
890 return len(library.Properties.Stubs.Versions) > 0
891 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700892 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
893 return len(library.Properties.Stubs.Versions) > 0
894 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900895 return false
896}
897
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900898func (c *Module) bootstrap() bool {
899 return Bool(c.Properties.Bootstrap)
900}
901
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700902func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700903 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
904 if c.Target().NativeBridge == android.NativeBridgeEnabled {
905 return false
906 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700907 return c.linker != nil && c.linker.nativeCoverage()
908}
909
Jiyong Park73c54ee2019-10-22 20:31:18 +0900910func (c *Module) ExportedIncludeDirs() android.Paths {
911 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
912 return flagsProducer.exportedDirs()
913 }
Jiyong Park232e7852019-11-04 12:23:40 +0900914 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900915}
916
917func (c *Module) ExportedSystemIncludeDirs() android.Paths {
918 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
919 return flagsProducer.exportedSystemDirs()
920 }
Jiyong Park232e7852019-11-04 12:23:40 +0900921 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900922}
923
924func (c *Module) ExportedFlags() []string {
925 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
926 return flagsProducer.exportedFlags()
927 }
Jiyong Park232e7852019-11-04 12:23:40 +0900928 return nil
929}
930
931func (c *Module) ExportedDeps() android.Paths {
932 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
933 return flagsProducer.exportedDeps()
934 }
935 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900936}
937
Inseob Kimd110f872019-12-06 13:15:38 +0900938func (c *Module) ExportedGeneratedHeaders() android.Paths {
939 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
940 return flagsProducer.exportedGeneratedHeaders()
941 }
942 return nil
943}
944
Jiyong Parkf1194352019-02-25 11:05:47 +0900945func isBionic(name string) bool {
946 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000947 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900948 return true
949 }
950 return false
951}
952
Martin Stjernholm279de572019-09-10 23:18:20 +0100953func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700954 if name == "libclang_rt.hwasan-aarch64-android" {
955 return inList("hwaddress", config.SanitizeDevice())
956 }
957 return isBionic(name)
958}
959
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800960func (c *Module) XrefCcFiles() android.Paths {
961 return c.kytheFiles
962}
963
Colin Crossca860ac2016-01-04 14:34:37 -0800964type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700965 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800966 moduleContextImpl
967}
968
Colin Cross37047f12016-12-13 17:06:13 -0800969type depsContext struct {
970 android.BottomUpMutatorContext
971 moduleContextImpl
972}
973
Colin Crossca860ac2016-01-04 14:34:37 -0800974type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700975 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800976 moduleContextImpl
977}
978
Justin Yun5f7f7e82019-11-18 19:52:14 +0900979func (ctx *moduleContext) ProductSpecific() bool {
980 return ctx.ModuleContext.ProductSpecific() ||
981 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
982}
983
Jiyong Park2db76922017-11-08 16:03:48 +0900984func (ctx *moduleContext) SocSpecific() bool {
985 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +0900986 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700987}
988
Colin Crossca860ac2016-01-04 14:34:37 -0800989type moduleContextImpl struct {
990 mod *Module
991 ctx BaseModuleContext
992}
993
Colin Crossb98c8b02016-07-29 13:44:28 -0700994func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800995 return ctx.mod.toolchain(ctx.ctx)
996}
997
998func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000999 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001000}
1001
1002func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001003 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001004}
1005
Jiyong Park1d1119f2019-07-29 21:27:18 +09001006func (ctx *moduleContextImpl) header() bool {
1007 return ctx.mod.header()
1008}
1009
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001010func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -08001011 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -08001012 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001013 }
1014 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001015}
1016
1017func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001018 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001019 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001020 vndkVer := ctx.mod.VndkVersion()
1021 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1022 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001023 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001024 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001025 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001026 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001027 }
1028 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001029}
1030
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001031func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001032 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001033}
Justin Yun8effde42017-06-23 19:24:43 +09001034
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001035func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001036 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001037}
1038
Inseob Kim9516ee92019-05-09 10:56:13 +09001039func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1040 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001041}
1042
Inseob Kim9516ee92019-05-09 10:56:13 +09001043func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1044 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001045}
1046
Inseob Kim9516ee92019-05-09 10:56:13 +09001047func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1048 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001049}
1050
Logan Chienf3511742017-10-31 18:04:35 +08001051func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001052 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001053}
1054
Yi Kong7e53c572018-02-14 18:16:12 +08001055func (ctx *moduleContextImpl) isPgoCompile() bool {
1056 return ctx.mod.isPgoCompile()
1057}
1058
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001059func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1060 return ctx.mod.isNDKStubLibrary()
1061}
1062
Justin Yun8effde42017-06-23 19:24:43 +09001063func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001064 return ctx.mod.isVndkSp()
1065}
1066
1067func (ctx *moduleContextImpl) isVndkExt() bool {
1068 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001069}
1070
Vic Yangefd249e2018-11-12 20:19:56 -08001071func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001072 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001073}
1074
Justin Yun5f7f7e82019-11-18 19:52:14 +09001075func (ctx *moduleContextImpl) inProduct() bool {
1076 return ctx.mod.inProduct()
1077}
1078
1079func (ctx *moduleContextImpl) inVendor() bool {
1080 return ctx.mod.inVendor()
1081}
1082
Jiyong Parkf9332f12018-02-01 00:54:12 +09001083func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001084 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001085}
1086
Logan Chien2f2b8902018-07-10 15:01:19 +08001087// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001088func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001089 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1090 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001091 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001092
1093 if ctx.ctx.Fuchsia() {
1094 return false
1095 }
1096
Logan Chien2f2b8902018-07-10 15:01:19 +08001097 if sanitize := ctx.mod.sanitize; sanitize != nil {
1098 if !sanitize.isVariantOnProductionDevice() {
1099 return false
1100 }
1101 }
1102 if !ctx.ctx.Device() {
1103 // Host modules do not need ABI dumps.
1104 return false
1105 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001106 if ctx.isStubs() {
1107 // Stubs do not need ABI dumps.
1108 return false
1109 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001110 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001111}
1112
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001113func (ctx *moduleContextImpl) selectedStl() string {
1114 if stl := ctx.mod.stl; stl != nil {
1115 return stl.Properties.SelectedStl
1116 }
1117 return ""
1118}
1119
Ivan Lozanobd721262018-11-27 14:33:03 -08001120func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1121 return ctx.mod.linker.useClangLld(actx)
1122}
1123
Colin Crossce75d2c2016-10-06 16:12:58 -07001124func (ctx *moduleContextImpl) baseModuleName() string {
1125 return ctx.mod.ModuleBase.BaseModuleName()
1126}
1127
Logan Chienf3511742017-10-31 18:04:35 +08001128func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1129 return ctx.mod.getVndkExtendsModuleName()
1130}
1131
Logan Chiene274fc92019-12-03 11:18:32 -08001132func (ctx *moduleContextImpl) isForPlatform() bool {
1133 return ctx.mod.IsForPlatform()
1134}
1135
Jiyong Park58e364a2019-01-19 19:24:06 +09001136func (ctx *moduleContextImpl) apexName() string {
1137 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001138}
1139
Jiyong Parkb0788572018-12-20 22:10:17 +09001140func (ctx *moduleContextImpl) hasStubsVariants() bool {
1141 return ctx.mod.HasStubsVariants()
1142}
1143
1144func (ctx *moduleContextImpl) isStubs() bool {
1145 return ctx.mod.IsStubs()
1146}
1147
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001148func (ctx *moduleContextImpl) bootstrap() bool {
1149 return ctx.mod.bootstrap()
1150}
1151
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001152func (ctx *moduleContextImpl) nativeCoverage() bool {
1153 return ctx.mod.nativeCoverage()
1154}
1155
Colin Cross635c3b02016-05-18 15:37:25 -07001156func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001157 return &Module{
1158 hod: hod,
1159 multilib: multilib,
1160 }
1161}
1162
Colin Cross635c3b02016-05-18 15:37:25 -07001163func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001164 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001165 module.features = []feature{
1166 &tidyFeature{},
1167 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001168 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001169 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001170 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001171 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001172 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001173 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001174 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001175 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001176 return module
1177}
1178
Colin Crossce75d2c2016-10-06 16:12:58 -07001179func (c *Module) Prebuilt() *android.Prebuilt {
1180 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1181 return p.prebuilt()
1182 }
1183 return nil
1184}
1185
1186func (c *Module) Name() string {
1187 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001188 if p, ok := c.linker.(interface {
1189 Name(string) string
1190 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001191 name = p.Name(name)
1192 }
1193 return name
1194}
1195
Alex Light3d673592019-01-18 14:37:31 -08001196func (c *Module) Symlinks() []string {
1197 if p, ok := c.installer.(interface {
1198 symlinkList() []string
1199 }); ok {
1200 return p.symlinkList()
1201 }
1202 return nil
1203}
1204
Jeff Gaston294356f2017-09-27 17:05:30 -07001205// orderDeps reorders dependencies into a list such that if module A depends on B, then
1206// A will precede B in the resultant list.
1207// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001208// Note that directSharedDeps should be the analogous static library for each shared lib dep
1209func 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 -07001210 // If A depends on B, then
1211 // Every list containing A will also contain B later in the list
1212 // So, after concatenating all lists, the final instance of B will have come from the same
1213 // original list as the final instance of A
1214 // So, the final instance of B will be later in the concatenation than the final A
1215 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1216 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001217 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001218 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001219 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1220 }
1221 for _, dep := range directSharedDeps {
1222 orderedAllDeps = append(orderedAllDeps, dep)
1223 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001224 }
1225
Colin Crossb6715442017-10-24 11:13:31 -07001226 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001227
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001228 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001229 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001230 // resultant list to only what the caller has chosen to include in directStaticDeps
1231 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001232
1233 return orderedAllDeps, orderedDeclaredDeps
1234}
1235
Ivan Lozano183a3212019-10-18 14:18:45 -07001236func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001237 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001238 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001239 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1240 staticDepFiles := []android.Path{}
1241 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001242 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1243 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001244 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001245 sharedDepFiles := []android.Path{}
1246 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001247 if sharedDep.HasStaticVariant() {
1248 staticAnalogue := sharedDep.GetStaticVariant()
1249 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1250 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001251 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001252 }
1253
1254 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001255 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1256 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001257
1258 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001259}
1260
Roland Levillainf89cd092019-07-29 16:22:59 +01001261func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1262 test, ok := c.linker.(testPerSrc)
1263 return ok && test.isAllTestsVariation()
1264}
1265
Justin Yun5f7f7e82019-11-18 19:52:14 +09001266func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1267 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1268 // "current", it will append the VNDK version to the name suffix.
1269 var vndkVersion string
1270 var nameSuffix string
1271 if c.inProduct() {
1272 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1273 nameSuffix = productSuffix
1274 } else {
1275 vndkVersion = ctx.DeviceConfig().VndkVersion()
1276 nameSuffix = vendorSuffix
1277 }
1278 if vndkVersion == "current" {
1279 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1280 }
1281 if c.Properties.VndkVersion != vndkVersion {
1282 // add version suffix only if the module is using different vndk version than the
1283 // version in product or vendor partition.
1284 nameSuffix += "." + c.Properties.VndkVersion
1285 }
1286 return nameSuffix
1287}
1288
Colin Cross635c3b02016-05-18 15:37:25 -07001289func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001290 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001291 //
1292 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1293 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1294 // module and return early, as this module does not produce an output file per se.
1295 if c.IsTestPerSrcAllTestsVariation() {
1296 c.outputFile = android.OptionalPath{}
1297 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001298 }
1299
Jooyung Han38002912019-05-16 04:01:54 +09001300 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001301
Inseob Kim64c43952019-08-26 16:52:35 +09001302 c.Properties.SubName = ""
1303
1304 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1305 c.Properties.SubName += nativeBridgeSuffix
1306 }
1307
Justin Yun5f7f7e82019-11-18 19:52:14 +09001308 _, llndk := c.linker.(*llndkStubDecorator)
1309 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1310 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1311 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1312 // added for product variant only when we have vendor and product variants with core
1313 // variant. The suffix is not added for vendor-only or product-only module.
1314 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1315 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001316 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1317 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1318 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001319 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001320 c.Properties.SubName += recoverySuffix
1321 }
1322
Colin Crossca860ac2016-01-04 14:34:37 -08001323 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001324 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001325 moduleContextImpl: moduleContextImpl{
1326 mod: c,
1327 },
1328 }
1329 ctx.ctx = ctx
1330
Colin Crossf18e1102017-11-16 14:33:08 -08001331 deps := c.depsToPaths(ctx)
1332 if ctx.Failed() {
1333 return
1334 }
1335
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001336 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1337 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1338 }
1339
Colin Crossca860ac2016-01-04 14:34:37 -08001340 flags := Flags{
1341 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001342 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001343 }
Colin Crossca860ac2016-01-04 14:34:37 -08001344 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001345 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001346 }
1347 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001348 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001349 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001350 if c.stl != nil {
1351 flags = c.stl.flags(ctx, flags)
1352 }
Colin Cross16b23492016-01-06 14:41:07 -08001353 if c.sanitize != nil {
1354 flags = c.sanitize.flags(ctx, flags)
1355 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001356 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001357 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001358 }
Stephen Craneba090d12017-05-09 15:44:35 -07001359 if c.lto != nil {
1360 flags = c.lto.flags(ctx, flags)
1361 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001362 if c.pgo != nil {
1363 flags = c.pgo.flags(ctx, flags)
1364 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001365 if c.xom != nil {
1366 flags = c.xom.flags(ctx, flags)
1367 }
Colin Crossca860ac2016-01-04 14:34:37 -08001368 for _, feature := range c.features {
1369 flags = feature.flags(ctx, flags)
1370 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001371 if ctx.Failed() {
1372 return
1373 }
1374
Colin Cross4af21ed2019-11-04 09:37:55 -08001375 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1376 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1377 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001378
Colin Cross4af21ed2019-11-04 09:37:55 -08001379 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001380
1381 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001382 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001383 }
1384 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001385 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001386 }
1387
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001388 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001389 // We need access to all the flags seen by a source file.
1390 if c.sabi != nil {
1391 flags = c.sabi.flags(ctx, flags)
1392 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001393
Colin Cross4af21ed2019-11-04 09:37:55 -08001394 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001395
Colin Crossca860ac2016-01-04 14:34:37 -08001396 // Optimization to reduce size of build.ninja
1397 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001398 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1399 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1400 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1401 flags.Local.CFlags = []string{"$cflags"}
1402 flags.Local.CppFlags = []string{"$cppflags"}
1403 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001404
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001405 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001406 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001407 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001408 if ctx.Failed() {
1409 return
1410 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001411 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001412 }
1413
Colin Crossca860ac2016-01-04 14:34:37 -08001414 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001415 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001416 if ctx.Failed() {
1417 return
1418 }
Colin Cross635c3b02016-05-18 15:37:25 -07001419 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001420
1421 // If a lib is directly included in any of the APEXes, unhide the stubs
1422 // variant having the latest version gets visible to make. In addition,
1423 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1424 // force anything in the make world to link against the stubs library.
1425 // (unless it is explicitly referenced via .bootstrap suffix or the
1426 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001427 if c.HasStubsVariants() &&
1428 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001429 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001430 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001431 c.Properties.HideFromMake = false // unhide
1432 // Note: this is still non-installable
1433 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001434 }
Colin Cross5049f022015-03-18 13:28:46 -07001435
Inseob Kim1f086e22019-05-09 13:29:15 +09001436 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001437 c.installer.install(ctx, c.outputFile.Path())
1438 if ctx.Failed() {
1439 return
Colin Crossca860ac2016-01-04 14:34:37 -08001440 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001441 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001442}
1443
Colin Cross0ea8ba82019-06-06 14:33:29 -07001444func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001445 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001446 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001447 }
Colin Crossca860ac2016-01-04 14:34:37 -08001448 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001449}
1450
Colin Crossca860ac2016-01-04 14:34:37 -08001451func (c *Module) begin(ctx BaseModuleContext) {
1452 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001453 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001454 }
Colin Crossca860ac2016-01-04 14:34:37 -08001455 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001456 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001457 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001458 if c.stl != nil {
1459 c.stl.begin(ctx)
1460 }
Colin Cross16b23492016-01-06 14:41:07 -08001461 if c.sanitize != nil {
1462 c.sanitize.begin(ctx)
1463 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001464 if c.coverage != nil {
1465 c.coverage.begin(ctx)
1466 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001467 if c.sabi != nil {
1468 c.sabi.begin(ctx)
1469 }
Justin Yun8effde42017-06-23 19:24:43 +09001470 if c.vndkdep != nil {
1471 c.vndkdep.begin(ctx)
1472 }
Stephen Craneba090d12017-05-09 15:44:35 -07001473 if c.lto != nil {
1474 c.lto.begin(ctx)
1475 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001476 if c.pgo != nil {
1477 c.pgo.begin(ctx)
1478 }
Colin Crossca860ac2016-01-04 14:34:37 -08001479 for _, feature := range c.features {
1480 feature.begin(ctx)
1481 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001482 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001483 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001484 if err != nil {
1485 ctx.PropertyErrorf("sdk_version", err.Error())
1486 }
Nan Zhang0007d812017-11-07 10:57:05 -08001487 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001488 }
Colin Crossca860ac2016-01-04 14:34:37 -08001489}
1490
Colin Cross37047f12016-12-13 17:06:13 -08001491func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001492 deps := Deps{}
1493
1494 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001495 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001496 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001497 // Add the PGO dependency (the clang_rt.profile runtime library), which
1498 // sometimes depends on symbols from libgcc, before libgcc gets added
1499 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001500 if c.pgo != nil {
1501 deps = c.pgo.deps(ctx, deps)
1502 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001503 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001504 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001505 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001506 if c.stl != nil {
1507 deps = c.stl.deps(ctx, deps)
1508 }
Colin Cross16b23492016-01-06 14:41:07 -08001509 if c.sanitize != nil {
1510 deps = c.sanitize.deps(ctx, deps)
1511 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001512 if c.coverage != nil {
1513 deps = c.coverage.deps(ctx, deps)
1514 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001515 if c.sabi != nil {
1516 deps = c.sabi.deps(ctx, deps)
1517 }
Justin Yun8effde42017-06-23 19:24:43 +09001518 if c.vndkdep != nil {
1519 deps = c.vndkdep.deps(ctx, deps)
1520 }
Stephen Craneba090d12017-05-09 15:44:35 -07001521 if c.lto != nil {
1522 deps = c.lto.deps(ctx, deps)
1523 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001524 for _, feature := range c.features {
1525 deps = feature.deps(ctx, deps)
1526 }
1527
Colin Crossb6715442017-10-24 11:13:31 -07001528 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1529 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1530 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1531 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1532 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1533 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001534 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001535
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001536 for _, lib := range deps.ReexportSharedLibHeaders {
1537 if !inList(lib, deps.SharedLibs) {
1538 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1539 }
1540 }
1541
1542 for _, lib := range deps.ReexportStaticLibHeaders {
1543 if !inList(lib, deps.StaticLibs) {
1544 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1545 }
1546 }
1547
Colin Cross5950f382016-12-13 12:50:57 -08001548 for _, lib := range deps.ReexportHeaderLibHeaders {
1549 if !inList(lib, deps.HeaderLibs) {
1550 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1551 }
1552 }
1553
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001554 for _, gen := range deps.ReexportGeneratedHeaders {
1555 if !inList(gen, deps.GeneratedHeaders) {
1556 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1557 }
1558 }
1559
Colin Crossc99deeb2016-04-11 15:06:20 -07001560 return deps
1561}
1562
Dan Albert7e9d2952016-08-04 13:02:36 -07001563func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001564 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001565 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001566 moduleContextImpl: moduleContextImpl{
1567 mod: c,
1568 },
1569 }
1570 ctx.ctx = ctx
1571
Colin Crossca860ac2016-01-04 14:34:37 -08001572 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001573}
1574
Jiyong Park7ed9de32018-10-15 22:25:07 +09001575// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001576func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001577 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1578 version := name[sharp+1:]
1579 libname := name[:sharp]
1580 return libname, version
1581 }
1582 return name, ""
1583}
1584
Colin Cross1e676be2016-10-12 14:38:15 -07001585func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001586 ctx := &depsContext{
1587 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001588 moduleContextImpl: moduleContextImpl{
1589 mod: c,
1590 },
1591 }
1592 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001593
Colin Crossc99deeb2016-04-11 15:06:20 -07001594 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001595
Dan Albert914449f2016-06-17 16:45:24 -07001596 variantNdkLibs := []string{}
1597 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001598 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001599 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001600
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001601 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1602 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001603 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001604 // 1. Name of an NDK library that refers to a prebuilt module.
1605 // For each of these, it adds the name of the prebuilt module (which will be in
1606 // prebuilts/ndk) to the list of nonvariant libs.
1607 // 2. Name of an NDK library that refers to an ndk_library module.
1608 // For each of these, it adds the name of the ndk_library module to the list of
1609 // variant libs.
1610 // 3. Anything else (so anything that isn't an NDK library).
1611 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001612 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001613 // The caller can then know to add the variantLibs dependencies differently from the
1614 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001615
Inseob Kim9516ee92019-05-09 10:56:13 +09001616 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001617 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1618 variantLibs = []string{}
1619 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001620 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001621 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001622 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001623 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1624 if !inList(name, ndkMigratedLibs) {
1625 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001626 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001627 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001628 }
Jooyung Han0302a842019-10-30 18:43:49 +09001629 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001630 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001631 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001632 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001633 if actx.OtherModuleExists(vendorPublicLib) {
1634 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1635 } else {
1636 // This can happen if vendor_public_library module is defined in a
1637 // namespace that isn't visible to the current module. In that case,
1638 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001639 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001640 }
Dan Albert914449f2016-06-17 16:45:24 -07001641 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001642 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001643 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001644 }
1645 }
Dan Albert914449f2016-06-17 16:45:24 -07001646 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001647 }
1648
Dan Albert914449f2016-06-17 16:45:24 -07001649 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1650 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001651 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001652 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001653
Jiyong Park7e636d02019-01-28 16:16:54 +09001654 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001655 if c.linker != nil {
1656 if library, ok := c.linker.(*libraryDecorator); ok {
1657 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001658 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001659 }
1660 }
1661 }
1662
Colin Cross32ec36c2016-12-15 07:39:51 -08001663 for _, lib := range deps.HeaderLibs {
1664 depTag := headerDepTag
1665 if inList(lib, deps.ReexportHeaderLibHeaders) {
1666 depTag = headerExportDepTag
1667 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001668 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001669 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001670 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001671 } else {
1672 actx.AddVariationDependencies(nil, depTag, lib)
1673 }
1674 }
1675
1676 if buildStubs {
1677 // Stubs lib does not have dependency to other static/shared libraries.
1678 // Don't proceed.
1679 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001680 }
Colin Cross5950f382016-12-13 12:50:57 -08001681
Inseob Kimc0907f12019-02-08 21:00:45 +09001682 syspropImplLibraries := syspropImplLibraries(actx.Config())
1683
Jiyong Park5d1598f2019-02-25 22:14:17 +09001684 for _, lib := range deps.WholeStaticLibs {
1685 depTag := wholeStaticDepTag
1686 if impl, ok := syspropImplLibraries[lib]; ok {
1687 lib = impl
1688 }
1689 actx.AddVariationDependencies([]blueprint.Variation{
1690 {Mutator: "link", Variation: "static"},
1691 }, depTag, lib)
1692 }
1693
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001694 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001695 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001696 if inList(lib, deps.ReexportStaticLibHeaders) {
1697 depTag = staticExportDepTag
1698 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001699
1700 if impl, ok := syspropImplLibraries[lib]; ok {
1701 lib = impl
1702 }
1703
Dan Willemsen59339a22018-07-22 21:18:45 -07001704 actx.AddVariationDependencies([]blueprint.Variation{
1705 {Mutator: "link", Variation: "static"},
1706 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001707 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001708
Dan Willemsen59339a22018-07-22 21:18:45 -07001709 actx.AddVariationDependencies([]blueprint.Variation{
1710 {Mutator: "link", Variation: "static"},
1711 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001712
Ivan Lozano183a3212019-10-18 14:18:45 -07001713 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001714 var variations []blueprint.Variation
1715 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001716 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001717 if version != "" && versionVariantAvail {
1718 // Version is explicitly specified. i.e. libFoo#30
1719 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001720 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001721 }
1722 actx.AddVariationDependencies(variations, depTag, name)
1723
1724 // If the version is not specified, add dependency to the latest stubs library.
1725 // The stubs library will be used when the depending module is built for APEX and
1726 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001727 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001728 if version == "" && latestVersion != "" && versionVariantAvail {
1729 actx.AddVariationDependencies([]blueprint.Variation{
1730 {Mutator: "link", Variation: "shared"},
1731 {Mutator: "version", Variation: latestVersion},
1732 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001733 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001734 }
1735 }
1736
Jiyong Park7ed9de32018-10-15 22:25:07 +09001737 // shared lib names without the #version suffix
1738 var sharedLibNames []string
1739
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001740 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001741 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001742 if inList(lib, deps.ReexportSharedLibHeaders) {
1743 depTag = sharedExportDepTag
1744 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001745
1746 if impl, ok := syspropImplLibraries[lib]; ok {
1747 lib = impl
1748 }
1749
Jiyong Park73c54ee2019-10-22 20:31:18 +09001750 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001751 sharedLibNames = append(sharedLibNames, name)
1752
Jiyong Park25fc6a92018-11-18 18:02:45 +09001753 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001754 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001755
Jiyong Park7ed9de32018-10-15 22:25:07 +09001756 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001757 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001758 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1759 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1760 // linking against both the stubs lib and the non-stubs lib at the same time.
1761 continue
1762 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001763 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001764 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001765
Dan Willemsen59339a22018-07-22 21:18:45 -07001766 actx.AddVariationDependencies([]blueprint.Variation{
1767 {Mutator: "link", Variation: "shared"},
1768 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001769
Colin Cross68861832016-07-08 10:41:41 -07001770 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001771
1772 for _, gen := range deps.GeneratedHeaders {
1773 depTag := genHeaderDepTag
1774 if inList(gen, deps.ReexportGeneratedHeaders) {
1775 depTag = genHeaderExportDepTag
1776 }
1777 actx.AddDependency(c, depTag, gen)
1778 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001779
Colin Cross42d48b72018-08-29 14:10:52 -07001780 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001781
1782 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001783 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001784 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001785 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001786 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001787 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001788 if deps.LinkerFlagsFile != "" {
1789 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1790 }
1791 if deps.DynamicLinker != "" {
1792 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001793 }
Dan Albert914449f2016-06-17 16:45:24 -07001794
1795 version := ctx.sdkVersion()
1796 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001797 {Mutator: "ndk_api", Variation: version},
1798 {Mutator: "link", Variation: "shared"},
1799 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001800 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001801 {Mutator: "ndk_api", Variation: version},
1802 {Mutator: "link", Variation: "shared"},
1803 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001804
1805 if vndkdep := c.vndkdep; vndkdep != nil {
1806 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001807 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001808 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001809 {Mutator: "link", Variation: "shared"},
1810 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001811 }
1812 }
Colin Cross6362e272015-10-29 15:25:03 -07001813}
Colin Cross21b9a242015-03-24 14:15:58 -07001814
Colin Crosse40b4ea2018-10-02 22:25:58 -07001815func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001816 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1817 c.beginMutator(ctx)
1818 }
1819}
1820
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001821// Whether a module can link to another module, taking into
1822// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001823func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1824 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001825 // Host code is not restricted
1826 return
1827 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001828
1829 // VNDK is cc.Module supported only for now.
1830 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001831 // Though vendor code is limited by the vendor mutator,
1832 // each vendor-available module needs to check
1833 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001834 if ccTo, ok := to.(*Module); ok {
1835 if ccFrom.vndkdep != nil {
1836 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1837 }
1838 } else {
1839 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001840 }
1841 return
1842 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001843 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001844 // Platform code can link to anything
1845 return
1846 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001847 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001848 // Recovery code is not NDK
1849 return
1850 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001851 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001852 // These are always allowed
1853 return
1854 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001855 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001856 // These are allowed, but they don't set sdk_version
1857 return
1858 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001859 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001860 // These aren't real libraries, but are the stub shared libraries that are included in
1861 // the NDK.
1862 return
1863 }
Logan Chien834b9a62019-01-14 15:39:03 +08001864
Ivan Lozano52767be2019-10-18 14:49:46 -07001865 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001866 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1867 // to link to libc++ (non-NDK and without sdk_version).
1868 return
1869 }
1870
Ivan Lozano52767be2019-10-18 14:49:46 -07001871 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001872 // NDK code linking to platform code is never okay.
1873 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001874 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001875 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001876 }
1877
1878 // At this point we know we have two NDK libraries, but we need to
1879 // check that we're not linking against anything built against a higher
1880 // API level, as it is only valid to link against older or equivalent
1881 // APIs.
1882
Inseob Kim01a28722018-04-11 09:48:45 +09001883 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001884 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001885 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001886 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001887 // Current can't be linked against by anything else.
1888 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001889 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001890 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001891 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001892 if err != nil {
1893 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001894 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001895 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001896 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001897 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001898 if err != nil {
1899 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001900 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001901 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001902 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001903
Inseob Kim01a28722018-04-11 09:48:45 +09001904 if toApi > fromApi {
1905 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001906 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001907 }
1908 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001909 }
Dan Albert202fe492017-12-15 13:56:59 -08001910
1911 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001912 fromStl := from.SelectedStl()
1913 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001914 if fromStl == "" || toStl == "" {
1915 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001916 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001917 // We can be permissive with the system "STL" since it is only the C++
1918 // ABI layer, but in the future we should make sure that everyone is
1919 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001920 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001921 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001922 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1923 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001924 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001925}
1926
Jiyong Park5fb8c102018-04-09 12:03:06 +09001927// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001928// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1929// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001930// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001931func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1932 check := func(child, parent android.Module) bool {
1933 to, ok := child.(*Module)
1934 if !ok {
1935 // follow thru cc.Defaults, etc.
1936 return true
1937 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001938
Jooyung Hana70f0672019-01-18 15:20:43 +09001939 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1940 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001941 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001942
1943 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001944 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001945 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001946 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001947
Jooyung Han0302a842019-10-30 18:43:49 +09001948 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001949 return false
1950 }
1951
1952 var stringPath []string
1953 for _, m := range ctx.GetWalkPath() {
1954 stringPath = append(stringPath, m.Name())
1955 }
1956 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1957 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1958 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1959 return false
1960 }
1961 if module, ok := ctx.Module().(*Module); ok {
1962 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001963 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001964 ctx.WalkDeps(check)
1965 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001966 }
1967 }
1968}
1969
Colin Crossc99deeb2016-04-11 15:06:20 -07001970// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001971func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001972 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001973
Ivan Lozano183a3212019-10-18 14:18:45 -07001974 directStaticDeps := []LinkableInterface{}
1975 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001976
Inseob Kim9516ee92019-05-09 10:56:13 +09001977 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1978
Inseob Kim69378442019-06-03 19:10:47 +09001979 reexportExporter := func(exporter exportedFlagsProducer) {
1980 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1981 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1982 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1983 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09001984 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09001985 }
1986
Colin Crossd11fcda2017-10-23 17:59:01 -07001987 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001988 depName := ctx.OtherModuleName(dep)
1989 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001990
Ivan Lozano52767be2019-10-18 14:49:46 -07001991 ccDep, ok := dep.(LinkableInterface)
1992 if !ok {
1993
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001994 // handling for a few module types that aren't cc Module but that are also supported
1995 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001996 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001997 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001998 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1999 genRule.GeneratedSourceFiles()...)
2000 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002001 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002002 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002003 // Support exported headers from a generated_sources dependency
2004 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002005 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002006 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002007 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002008 genRule.GeneratedSourceFiles()...)
2009 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002010 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002011 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002012 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002013 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002014 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002015 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2016 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002017 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002018 // 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 +09002019 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002020
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002021 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002022 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002023 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002024 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002025 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002026 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002027 files := genRule.GeneratedSourceFiles()
2028 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002029 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002030 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002031 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 -07002032 }
2033 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002034 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002035 }
Colin Crossca860ac2016-01-04 14:34:37 -08002036 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002037 return
2038 }
2039
Colin Crossfe17f6f2019-03-28 19:30:56 -07002040 if depTag == android.ProtoPluginDepTag {
2041 return
2042 }
2043
Colin Crossd11fcda2017-10-23 17:59:01 -07002044 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002045 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2046 return
2047 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002048 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002049 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002050 return
2051 }
2052
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002053 // re-exporting flags
2054 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002055 // reusing objects only make sense for cc.Modules.
2056 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002057 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002058 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002059 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002060 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002061 return
2062 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002063 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002064
Jiyong Parke4bb9862019-02-01 00:31:10 +09002065 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002066 // staticVariants are a cc.Module specific concept.
2067 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002068 c.staticVariant = ccDep
2069 return
2070 }
2071 }
2072
Ivan Lozano183a3212019-10-18 14:18:45 -07002073 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2074 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2075 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002076 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002077 if t, ok := depTag.(DependencyTag); ok {
2078 explicitlyVersioned = t.ExplicitlyVersioned
2079 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002080 depTag = t
2081 }
2082
Ivan Lozano183a3212019-10-18 14:18:45 -07002083 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002084 depIsStatic := false
2085 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002086 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002087 depIsStatic = true
2088 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002089 if ccDep.CcLibrary() && !depIsStatic {
2090 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002091 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002092 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002093 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002094
2095 var useThisDep bool
2096 if depIsStubs && explicitlyVersioned {
2097 // Always respect dependency to the versioned stubs (i.e. libX#10)
2098 useThisDep = true
2099 } else if !depHasStubs {
2100 // Use non-stub variant if that is the only choice
2101 // (i.e. depending on a lib without stubs.version property)
2102 useThisDep = true
2103 } else if c.IsForPlatform() {
2104 // If not building for APEX, use stubs only when it is from
2105 // an APEX (and not from platform)
2106 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002107 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002108 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002109 // always link to non-stub variant
2110 useThisDep = !depIsStubs
2111 }
2112 } else {
2113 // If building for APEX, use stubs only when it is not from
2114 // the same APEX
2115 useThisDep = (depInSameApex != depIsStubs)
2116 }
2117
2118 if !useThisDep {
2119 return // stop processing this dep
2120 }
2121 }
2122
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002123 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2124
Ivan Lozano52767be2019-10-18 14:49:46 -07002125 // Exporting flags only makes sense for cc.Modules
2126 if _, ok := ccDep.(*Module); ok {
2127 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002128 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002129 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2130 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002131 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002132
Ivan Lozano52767be2019-10-18 14:49:46 -07002133 if t.ReexportFlags {
2134 reexportExporter(i)
2135 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2136 // Re-exported shared library headers must be included as well since they can help us with type information
2137 // about template instantiations (instantiated from their headers).
2138 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2139 // scripts.
2140 c.sabi.Properties.ReexportedIncludes = append(
2141 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2142 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002143 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002144 }
Logan Chienf3511742017-10-31 18:04:35 +08002145 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002146 }
2147
Colin Cross26c34ed2016-09-30 17:10:16 -07002148 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002149 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002150
Ivan Lozano52767be2019-10-18 14:49:46 -07002151 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002152 depFile := android.OptionalPath{}
2153
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002155 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002156 ptr = &depPaths.SharedLibs
2157 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002158 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002159 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002160
Jiyong Park64a44f22019-01-18 14:37:08 +09002161 case earlySharedDepTag:
2162 ptr = &depPaths.EarlySharedLibs
2163 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002164 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002165 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002166 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002167 ptr = &depPaths.LateSharedLibs
2168 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002169 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002170 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002171 ptr = nil
2172 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002173 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002174 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002175 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002176 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002178 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002179 return
2180 }
2181
Ivan Lozano52767be2019-10-18 14:49:46 -07002182 // Because the static library objects are included, this only makes sense
2183 // in the context of proper cc.Modules.
2184 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2185 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2186 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2187 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2188 for i := range missingDeps {
2189 missingDeps[i] += postfix
2190 }
2191 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002192 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002193 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2194 } else {
2195 ctx.ModuleErrorf(
2196 "non-cc.Modules cannot be included as whole static libraries.", depName)
2197 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002198 }
Colin Cross5950f382016-12-13 12:50:57 -08002199 case headerDepTag:
2200 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002201 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002202 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002203 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002204 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002205 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002206 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002207 case dynamicLinkerDepTag:
2208 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002209 }
2210
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002211 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002212 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002213 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002214 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002215 return
2216 }
2217
2218 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002219 // in static libraries act as if they were whole static libraries. The same goes for
2220 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002221 // This should only be done for cc.Modules
2222 if c, ok := ccDep.(*Module); ok {
2223 staticLib := c.linker.(libraryInterface)
2224 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2225 staticLib.objs().coverageFiles...)
2226 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2227 staticLib.objs().sAbiDumpFiles...)
2228 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002229 }
2230
Colin Cross26c34ed2016-09-30 17:10:16 -07002231 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002232 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002233 if !ctx.Config().AllowMissingDependencies() {
2234 ctx.ModuleErrorf("module %q missing output file", depName)
2235 } else {
2236 ctx.AddMissingDependencies([]string{depName})
2237 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002238 return
2239 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002240 *ptr = append(*ptr, linkFile.Path())
2241 }
2242
Colin Crossc99deeb2016-04-11 15:06:20 -07002243 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002244 dep := depFile
2245 if !dep.Valid() {
2246 dep = linkFile
2247 }
2248 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002249 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002250
Logan Chien43d34c32017-12-20 01:17:32 +08002251 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002252 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002253 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002254 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002255 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002256 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002257 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002258
Ivan Lozano52767be2019-10-18 14:49:46 -07002259 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002260 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2261 // core module instead.
2262 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002263 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002264 // The vendor module in Make will have been renamed to not conflict with the core
2265 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002266 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002267 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002268 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002269 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002270 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002271 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002272 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002273 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002274 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002275 }
Logan Chien43d34c32017-12-20 01:17:32 +08002276 }
2277
2278 // Export the shared libs to Make.
2279 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002280 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002281 if ccDep.CcLibrary() {
2282 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002283 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002284 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002285 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002286 c.Properties.ApexesProvidingSharedLibs = append(
2287 c.Properties.ApexesProvidingSharedLibs, an)
2288 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002289 }
2290 }
2291
Jiyong Park27b188b2017-07-18 13:23:39 +09002292 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002293 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002294 c.Properties.AndroidMkSharedLibs = append(
2295 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002296 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002297 c.Properties.AndroidMkSharedLibs = append(
2298 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002299 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002300 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002301 c.Properties.AndroidMkStaticLibs = append(
2302 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002303 case runtimeDepTag:
2304 c.Properties.AndroidMkRuntimeLibs = append(
2305 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002306 case wholeStaticDepTag:
2307 c.Properties.AndroidMkWholeStaticLibs = append(
2308 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002309 }
Colin Crossca860ac2016-01-04 14:34:37 -08002310 })
2311
Jeff Gaston294356f2017-09-27 17:05:30 -07002312 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002313 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002314
Colin Crossdd84e052017-05-17 13:44:16 -07002315 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002316 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002317 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2318 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002319 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002320 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002321 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2322 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002323 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002324 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002325 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002326
2327 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002328 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002329 }
Colin Crossdd84e052017-05-17 13:44:16 -07002330
Colin Crossca860ac2016-01-04 14:34:37 -08002331 return depPaths
2332}
2333
2334func (c *Module) InstallInData() bool {
2335 if c.installer == nil {
2336 return false
2337 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002338 return c.installer.inData()
2339}
2340
2341func (c *Module) InstallInSanitizerDir() bool {
2342 if c.installer == nil {
2343 return false
2344 }
2345 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002346 return true
2347 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002348 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002349}
2350
Jiyong Parkf9332f12018-02-01 00:54:12 +09002351func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002352 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002353}
2354
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002355func (c *Module) HostToolPath() android.OptionalPath {
2356 if c.installer == nil {
2357 return android.OptionalPath{}
2358 }
2359 return c.installer.hostToolPath()
2360}
2361
Nan Zhangd4e641b2017-07-12 12:55:28 -07002362func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2363 return c.outputFile
2364}
2365
Colin Cross41955e82019-05-29 14:40:35 -07002366func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2367 switch tag {
2368 case "":
2369 if c.outputFile.Valid() {
2370 return android.Paths{c.outputFile.Path()}, nil
2371 }
2372 return android.Paths{}, nil
2373 default:
2374 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002375 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002376}
2377
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002378func (c *Module) static() bool {
2379 if static, ok := c.linker.(interface {
2380 static() bool
2381 }); ok {
2382 return static.static()
2383 }
2384 return false
2385}
2386
Jiyong Park379de2f2018-12-19 02:47:14 +09002387func (c *Module) staticBinary() bool {
2388 if static, ok := c.linker.(interface {
2389 staticBinary() bool
2390 }); ok {
2391 return static.staticBinary()
2392 }
2393 return false
2394}
2395
Jiyong Park1d1119f2019-07-29 21:27:18 +09002396func (c *Module) header() bool {
2397 if h, ok := c.linker.(interface {
2398 header() bool
2399 }); ok {
2400 return h.header()
2401 }
2402 return false
2403}
2404
Jooyung Han38002912019-05-16 04:01:54 +09002405func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002406 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002407 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2408 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002409 return "native:vndk"
2410 }
Jooyung Han38002912019-05-16 04:01:54 +09002411 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002412 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002413 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002414 if Bool(c.VendorProperties.Vendor_available) {
2415 return "native:vndk"
2416 }
2417 return "native:vndk_private"
2418 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002419 if c.inProduct() {
2420 return "native:product"
2421 }
Jooyung Han38002912019-05-16 04:01:54 +09002422 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002423 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002424 return "native:recovery"
2425 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2426 return "native:ndk:none:none"
2427 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2428 //family, link := getNdkStlFamilyAndLinkType(c)
2429 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002430 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002431 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002432 } else {
2433 return "native:platform"
2434 }
2435}
2436
Jiyong Park9d452992018-10-03 00:38:19 +09002437// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002438// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002439func (c *Module) IsInstallableToApex() bool {
2440 if shared, ok := c.linker.(interface {
2441 shared() bool
2442 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002443 // Stub libs and prebuilt libs in a versioned SDK are not
2444 // installable to APEX even though they are shared libs.
2445 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002446 } else if _, ok := c.linker.(testPerSrc); ok {
2447 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002448 }
2449 return false
2450}
2451
Jiyong Parka90ca002019-10-07 15:47:24 +09002452func (c *Module) AvailableFor(what string) bool {
2453 if linker, ok := c.linker.(interface {
2454 availableFor(string) bool
2455 }); ok {
2456 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2457 } else {
2458 return c.ApexModuleBase.AvailableFor(what)
2459 }
2460}
2461
Inseob Kim1f086e22019-05-09 13:29:15 +09002462func (c *Module) installable() bool {
2463 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2464}
2465
Logan Chien41eabe62019-04-10 13:33:58 +08002466func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2467 if c.linker != nil {
2468 if library, ok := c.linker.(*libraryDecorator); ok {
2469 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2470 }
2471 }
2472}
2473
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002474func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002475 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2476 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002477 // dynamic dep to a stubs lib crosses APEX boundary
2478 return false
2479 }
2480 }
2481 return true
2482}
2483
Colin Cross2ba19d92015-05-07 15:44:20 -07002484//
Colin Crosscfad1192015-11-02 16:43:11 -08002485// Defaults
2486//
Colin Crossca860ac2016-01-04 14:34:37 -08002487type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002488 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002489 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002490 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002491}
2492
Patrice Arrudac249c712019-03-19 17:00:29 -07002493// cc_defaults provides a set of properties that can be inherited by other cc
2494// modules. A module can use the properties from a cc_defaults using
2495// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2496// merged (when possible) by prepending the default module's values to the
2497// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002498func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002499 return DefaultsFactory()
2500}
2501
Colin Cross36242852017-06-23 15:06:31 -07002502func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002503 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002504
Colin Cross36242852017-06-23 15:06:31 -07002505 module.AddProperties(props...)
2506 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002507 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002508 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002509 &BaseCompilerProperties{},
2510 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002511 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002512 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002513 &StaticProperties{},
2514 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002515 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002516 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002517 &TestProperties{},
2518 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002519 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002520 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002521 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002522 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002523 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002524 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002525 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002526 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002527 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002528 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002529 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002530 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002531 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002532 )
Colin Crosscfad1192015-11-02 16:43:11 -08002533
Jooyung Hancc372c52019-09-25 15:18:44 +09002534 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002535
2536 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002537}
2538
Jiyong Park6a43f042017-10-12 23:05:00 +09002539func squashVendorSrcs(m *Module) {
2540 if lib, ok := m.compiler.(*libraryDecorator); ok {
2541 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2542 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2543
2544 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2545 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2546 }
2547}
2548
Jiyong Parkf9332f12018-02-01 00:54:12 +09002549func squashRecoverySrcs(m *Module) {
2550 if lib, ok := m.compiler.(*libraryDecorator); ok {
2551 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2552 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2553
2554 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2555 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2556 }
2557}
2558
Colin Cross7228ecd2019-11-18 16:00:16 -08002559var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002560
Colin Cross7228ecd2019-11-18 16:00:16 -08002561func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002562 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002563 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002564 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002565
2566 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002567 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002568 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002569 }
Logan Chienf3511742017-10-31 18:04:35 +08002570
2571 if vndkdep := m.vndkdep; vndkdep != nil {
2572 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002573 if productSpecific {
2574 mctx.PropertyErrorf("product_specific",
2575 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002576 }
Logan Chienf3511742017-10-31 18:04:35 +08002577 if vendorSpecific {
2578 if !vndkdep.isVndkExt() {
2579 mctx.PropertyErrorf("vndk",
2580 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002581 }
2582 } else {
2583 if vndkdep.isVndkExt() {
2584 mctx.PropertyErrorf("vndk",
2585 "must set `vendor: true` to set `extends: %q`",
2586 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002587 }
2588 if m.VendorProperties.Vendor_available == nil {
2589 mctx.PropertyErrorf("vndk",
2590 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002591 }
2592 }
2593 } else {
2594 if vndkdep.isVndkSp() {
2595 mctx.PropertyErrorf("vndk",
2596 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002597 }
2598 if vndkdep.isVndkExt() {
2599 mctx.PropertyErrorf("vndk",
2600 "must set `enabled: true` to set `extends: %q`",
2601 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002602 }
Justin Yun8effde42017-06-23 19:24:43 +09002603 }
2604 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002605
Jiyong Parkf9332f12018-02-01 00:54:12 +09002606 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002607 var recoveryVariantNeeded bool = false
2608
Inseob Kim64c43952019-08-26 16:52:35 +09002609 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002610 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002611
2612 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002613 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2614 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2615 if boardVndkVersion == "current" {
2616 boardVndkVersion = platformVndkVersion
2617 }
2618 if productVndkVersion == "current" {
2619 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002620 }
2621
Justin Yun5f7f7e82019-11-18 19:52:14 +09002622 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002623 // If the device isn't compiling against the VNDK, we always
2624 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002625 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002626 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002627 // LL-NDK stubs only exist in the vendor and product variants,
2628 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002629 vendorVariants = append(vendorVariants,
2630 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002631 boardVndkVersion,
2632 )
2633 productVariants = append(productVariants,
2634 platformVndkVersion,
2635 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002636 )
Jiyong Park2a454122017-10-19 15:59:33 +09002637 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2638 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002639 vendorVariants = append(vendorVariants,
2640 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002641 boardVndkVersion,
2642 )
2643 productVariants = append(productVariants,
2644 platformVndkVersion,
2645 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002646 )
2647 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002648 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2649 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002650 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002651 } else if m.HasVendorVariant() && !vendorSpecific {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002652 // This will be available in /system, /vendor and /product
2653 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002654 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002655 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002656 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002657 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2658 // code is PLATFORM_VNDK_VERSION.
2659 // On the other hand, vendor_available modules which are not VNDK should
2660 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002661 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002662 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002663 vendorVariants = append(vendorVariants, boardVndkVersion)
2664 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002665 }
Logan Chienf3511742017-10-31 18:04:35 +08002666 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002667 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002668 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002669 } else {
2670 // This is either in /system (or similar: /data), or is a
2671 // modules built with the NDK. Modules built with the NDK
2672 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002673 coreVariantNeeded = true
2674 }
2675
Justin Yun5f7f7e82019-11-18 19:52:14 +09002676 if boardVndkVersion != "" && productVndkVersion != "" {
2677 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2678 // The module has "product_specific: true" that does not create core variant.
2679 coreVariantNeeded = false
2680 productVariants = append(productVariants, productVndkVersion)
2681 }
2682 } else {
2683 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2684 // restriction to use system libs.
2685 // No product variants defined in this case.
2686 productVariants = []string{}
2687 }
2688
Jiyong Parkf9332f12018-02-01 00:54:12 +09002689 if Bool(m.Properties.Recovery_available) {
2690 recoveryVariantNeeded = true
2691 }
2692
2693 if m.ModuleBase.InstallInRecovery() {
2694 recoveryVariantNeeded = true
2695 coreVariantNeeded = false
2696 }
2697
Inseob Kim64c43952019-08-26 16:52:35 +09002698 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002699 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2700 }
2701
2702 for _, variant := range android.FirstUniqueStrings(productVariants) {
2703 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002704 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002705
2706 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2707 m.Properties.CoreVariantNeeded = coreVariantNeeded
2708}
2709
2710func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2711 return c.Properties.CoreVariantNeeded
2712}
2713
2714func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2715 return c.Properties.RecoveryVariantNeeded
2716}
2717
2718func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002719 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002720}
2721
2722func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2723 m := module.(*Module)
2724 if variant == android.RecoveryVariation {
2725 m.MakeAsPlatform()
2726 squashRecoverySrcs(m)
2727 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002728 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08002729 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2730 squashVendorSrcs(m)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002731 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
2732 m.Properties.ImageVariationPrefix = ProductVariationPrefix
2733 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
2734 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002735 }
2736}
2737
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002738func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002739 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002740 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2741 }
Colin Cross6510f912017-11-29 00:27:14 -08002742 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002743}
2744
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002745func kytheExtractAllFactory() android.Singleton {
2746 return &kytheExtractAllSingleton{}
2747}
2748
2749type kytheExtractAllSingleton struct {
2750}
2751
2752func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2753 var xrefTargets android.Paths
2754 ctx.VisitAllModules(func(module android.Module) {
2755 if ccModule, ok := module.(xref); ok {
2756 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2757 }
2758 })
2759 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2760 if len(xrefTargets) > 0 {
2761 ctx.Build(pctx, android.BuildParams{
2762 Rule: blueprint.Phony,
2763 Output: android.PathForPhony(ctx, "xref_cxx"),
2764 Inputs: xrefTargets,
2765 //Default: true,
2766 })
2767 }
2768}
2769
Colin Cross06a931b2015-10-28 17:23:31 -07002770var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002771var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002772var BoolPtr = proptools.BoolPtr
2773var String = proptools.String
2774var StringPtr = proptools.StringPtr