blob: 022e350e8ae245385ebc3828d1aaeaf2ee4d5aa9 [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
Jiyong Park83dc74b2020-01-14 18:38:44 +0900401func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
402 ccDepTag, ok := depTag.(DependencyTag)
403 return ok && (ccDepTag == staticExportDepTag ||
404 ccDepTag == lateStaticDepTag ||
405 ccDepTag == wholeStaticDepTag)
406}
407
Roland Levillainf89cd092019-07-29 16:22:59 +0100408func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700409 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100410 return ok && ccDepTag == runtimeDepTag
411}
412
413func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700414 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100415 return ok && ccDepTag == testPerSrcDepTag
416}
417
Colin Crossca860ac2016-01-04 14:34:37 -0800418// Module contains the properties and members used by all C/C++ module types, and implements
419// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
420// to construct the output file. Behavior can be customized with a Customizer interface
421type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700422 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700423 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900424 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900425 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700426
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700427 Properties BaseProperties
428 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700429
Colin Crossca860ac2016-01-04 14:34:37 -0800430 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700431 hod android.HostOrDeviceSupported
432 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700433
Paul Duffina0843f62019-12-13 19:50:38 +0000434 // Allowable SdkMemberTypes of this module type.
435 sdkMemberTypes []android.SdkMemberType
436
Colin Crossca860ac2016-01-04 14:34:37 -0800437 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700438 features []feature
439 compiler compiler
440 linker linker
441 installer installer
442 stl *stl
443 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800444 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800445 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900446 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700447 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700448 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800449 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800450
451 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700452
Colin Cross635c3b02016-05-18 15:37:25 -0700453 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800454
Colin Crossb98c8b02016-07-29 13:44:28 -0700455 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700456
457 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800458
459 // Flags used to compile this module
460 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700461
462 // 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 -0800463 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700464 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800465 depsInLinkOrder android.Paths
466
467 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700468 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900469
470 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800471 // Kythe (source file indexer) paths for this compilation module
472 kytheFiles android.Paths
Jiyong Park83dc74b2020-01-14 18:38:44 +0900473
474 // name of the modules that are direct or indirect static deps of this module
475 allStaticDeps []string
Colin Crossc472d572015-03-17 15:06:21 -0700476}
477
Ivan Lozano52767be2019-10-18 14:49:46 -0700478func (c *Module) Toc() android.OptionalPath {
479 if c.linker != nil {
480 if library, ok := c.linker.(libraryInterface); ok {
481 return library.toc()
482 }
483 }
484 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
485}
486
487func (c *Module) ApiLevel() string {
488 if c.linker != nil {
489 if stub, ok := c.linker.(*stubDecorator); ok {
490 return stub.properties.ApiLevel
491 }
492 }
493 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
494}
495
496func (c *Module) Static() bool {
497 if c.linker != nil {
498 if library, ok := c.linker.(libraryInterface); ok {
499 return library.static()
500 }
501 }
502 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
503}
504
505func (c *Module) Shared() bool {
506 if c.linker != nil {
507 if library, ok := c.linker.(libraryInterface); ok {
508 return library.shared()
509 }
510 }
511 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
512}
513
514func (c *Module) SelectedStl() string {
515 return c.stl.Properties.SelectedStl
516}
517
518func (c *Module) ToolchainLibrary() bool {
519 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
520 return true
521 }
522 return false
523}
524
525func (c *Module) NdkPrebuiltStl() bool {
526 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
527 return true
528 }
529 return false
530}
531
532func (c *Module) StubDecorator() bool {
533 if _, ok := c.linker.(*stubDecorator); ok {
534 return true
535 }
536 return false
537}
538
539func (c *Module) SdkVersion() string {
540 return String(c.Properties.Sdk_version)
541}
542
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800543func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700544 if c.linker != nil {
545 if library, ok := c.linker.(exportedFlagsProducer); ok {
546 return library.exportedDirs()
547 }
548 }
549 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
550}
551
552func (c *Module) HasStaticVariant() bool {
553 if c.staticVariant != nil {
554 return true
555 }
556 return false
557}
558
559func (c *Module) GetStaticVariant() LinkableInterface {
560 return c.staticVariant
561}
562
563func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
564 c.depsInLinkOrder = depsInLinkOrder
565}
566
567func (c *Module) GetDepsInLinkOrder() []android.Path {
568 return c.depsInLinkOrder
569}
570
571func (c *Module) StubsVersions() []string {
572 if c.linker != nil {
573 if library, ok := c.linker.(*libraryDecorator); ok {
574 return library.Properties.Stubs.Versions
575 }
576 }
577 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
578}
579
580func (c *Module) CcLibrary() bool {
581 if c.linker != nil {
582 if _, ok := c.linker.(*libraryDecorator); ok {
583 return true
584 }
585 }
586 return false
587}
588
589func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700590 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700591 return true
592 }
593 return false
594}
595
Ivan Lozano2b262972019-11-21 12:30:50 -0800596func (c *Module) NonCcVariants() bool {
597 return false
598}
599
Ivan Lozano183a3212019-10-18 14:18:45 -0700600func (c *Module) SetBuildStubs() {
601 if c.linker != nil {
602 if library, ok := c.linker.(*libraryDecorator); ok {
603 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700604 c.Properties.HideFromMake = true
605 c.sanitize = nil
606 c.stl = nil
607 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700608 return
609 }
610 }
611 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
612}
613
Ivan Lozano52767be2019-10-18 14:49:46 -0700614func (c *Module) BuildStubs() bool {
615 if c.linker != nil {
616 if library, ok := c.linker.(*libraryDecorator); ok {
617 return library.buildStubs()
618 }
619 }
620 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
621}
622
Ivan Lozano183a3212019-10-18 14:18:45 -0700623func (c *Module) SetStubsVersions(version string) {
624 if c.linker != nil {
625 if library, ok := c.linker.(*libraryDecorator); ok {
626 library.MutatedProperties.StubsVersion = version
627 return
628 }
629 }
630 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
631}
632
633func (c *Module) SetStatic() {
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.setStatic()
637 return
638 }
639 }
640 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
641}
642
643func (c *Module) SetShared() {
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 library.setShared()
647 return
648 }
649 }
650 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
651}
652
653func (c *Module) BuildStaticVariant() bool {
654 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700655 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700656 return library.buildStatic()
657 }
658 }
659 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
660}
661
662func (c *Module) BuildSharedVariant() bool {
663 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700664 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700665 return library.buildShared()
666 }
667 }
668 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
669}
670
671func (c *Module) Module() android.Module {
672 return c
673}
674
Jiyong Parkc20eee32018-09-05 22:36:17 +0900675func (c *Module) OutputFile() android.OptionalPath {
676 return c.outputFile
677}
678
Ivan Lozano183a3212019-10-18 14:18:45 -0700679var _ LinkableInterface = (*Module)(nil)
680
Jiyong Park719b4462019-01-13 00:39:51 +0900681func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900682 if c.linker != nil {
683 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900684 }
685 return nil
686}
687
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900688func (c *Module) CoverageOutputFile() android.OptionalPath {
689 if c.linker != nil {
690 return c.linker.coverageOutputFilePath()
691 }
692 return android.OptionalPath{}
693}
694
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900695func (c *Module) RelativeInstallPath() string {
696 if c.installer != nil {
697 return c.installer.relativeInstallPath()
698 }
699 return ""
700}
701
Jooyung Han344d5432019-08-23 11:17:39 +0900702func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900703 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900704}
705
Colin Cross36242852017-06-23 15:06:31 -0700706func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700707 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800708 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700709 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800710 }
711 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700712 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800713 }
714 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700715 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800716 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700717 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700718 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700719 }
Colin Cross16b23492016-01-06 14:41:07 -0800720 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700721 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800722 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800723 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700724 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800725 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800726 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700727 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800728 }
Justin Yun8effde42017-06-23 19:24:43 +0900729 if c.vndkdep != nil {
730 c.AddProperties(c.vndkdep.props()...)
731 }
Stephen Craneba090d12017-05-09 15:44:35 -0700732 if c.lto != nil {
733 c.AddProperties(c.lto.props()...)
734 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700735 if c.pgo != nil {
736 c.AddProperties(c.pgo.props()...)
737 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800738 if c.xom != nil {
739 c.AddProperties(c.xom.props()...)
740 }
Colin Crossca860ac2016-01-04 14:34:37 -0800741 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700742 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800743 }
Colin Crossc472d572015-03-17 15:06:21 -0700744
Colin Crossa9d8bee2018-10-02 13:59:46 -0700745 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
746 switch class {
747 case android.Device:
748 return ctx.Config().DevicePrefer32BitExecutables()
749 case android.HostCross:
750 // Windows builds always prefer 32-bit
751 return true
752 default:
753 return false
754 }
755 })
Colin Cross36242852017-06-23 15:06:31 -0700756 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900757 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900758 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900759 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900760
Colin Cross36242852017-06-23 15:06:31 -0700761 return c
Colin Crossc472d572015-03-17 15:06:21 -0700762}
763
Colin Crossb916a382016-07-29 17:28:03 -0700764// Returns true for dependency roots (binaries)
765// TODO(ccross): also handle dlopenable libraries
766func (c *Module) isDependencyRoot() bool {
767 if root, ok := c.linker.(interface {
768 isDependencyRoot() bool
769 }); ok {
770 return root.isDependencyRoot()
771 }
772 return false
773}
774
Justin Yun5f7f7e82019-11-18 19:52:14 +0900775// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
776// "product" and "vendor" variant modules return true for this function.
777// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
778// "soc_specific: true" and more vendor installed modules are included here.
779// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
780// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700781func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900782 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700783}
784
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800785func (c *Module) isCoverageVariant() bool {
786 return c.coverage.Properties.IsCoverageVariant
787}
788
Peter Collingbournead84f972019-12-17 16:46:18 -0800789func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800790 return inList(c.Name(), ndkMigratedLibs)
791}
792
Inseob Kim9516ee92019-05-09 10:56:13 +0900793func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800794 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900795 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800796}
797
Inseob Kim9516ee92019-05-09 10:56:13 +0900798func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800799 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900800 name := c.BaseModuleName()
801 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800802}
803
Inseob Kim9516ee92019-05-09 10:56:13 +0900804func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800805 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900806 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800807}
808
Ivan Lozano52767be2019-10-18 14:49:46 -0700809func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800810 if vndkdep := c.vndkdep; vndkdep != nil {
811 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900812 }
813 return false
814}
815
Yi Kong7e53c572018-02-14 18:16:12 +0800816func (c *Module) isPgoCompile() bool {
817 if pgo := c.pgo; pgo != nil {
818 return pgo.Properties.PgoCompile
819 }
820 return false
821}
822
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800823func (c *Module) isNDKStubLibrary() bool {
824 if _, ok := c.compiler.(*stubDecorator); ok {
825 return true
826 }
827 return false
828}
829
Logan Chienf3511742017-10-31 18:04:35 +0800830func (c *Module) isVndkSp() bool {
831 if vndkdep := c.vndkdep; vndkdep != nil {
832 return vndkdep.isVndkSp()
833 }
834 return false
835}
836
837func (c *Module) isVndkExt() bool {
838 if vndkdep := c.vndkdep; vndkdep != nil {
839 return vndkdep.isVndkExt()
840 }
841 return false
842}
843
Ivan Lozano52767be2019-10-18 14:49:46 -0700844func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900845 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800846}
847
Logan Chienf3511742017-10-31 18:04:35 +0800848func (c *Module) getVndkExtendsModuleName() string {
849 if vndkdep := c.vndkdep; vndkdep != nil {
850 return vndkdep.getVndkExtendsModuleName()
851 }
852 return ""
853}
854
Justin Yun5f7f7e82019-11-18 19:52:14 +0900855// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900856// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700857func (c *Module) HasVendorVariant() bool {
858 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900859}
860
Justin Yun5f7f7e82019-11-18 19:52:14 +0900861const (
862 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
863 // against the VNDK.
864 VendorVariationPrefix = "vendor."
865
866 // ProductVariationPrefix is the variant prefix used for /product code that compiles
867 // against the VNDK.
868 ProductVariationPrefix = "product."
869)
870
871// Returns true if the module is "product" variant. Usually these modules are installed in /product
872func (c *Module) inProduct() bool {
873 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
874}
875
876// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
877func (c *Module) inVendor() bool {
878 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
879}
880
Ivan Lozano52767be2019-10-18 14:49:46 -0700881func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800882 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900883}
884
Ivan Lozano52767be2019-10-18 14:49:46 -0700885func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900886 return c.ModuleBase.InstallInRecovery()
887}
888
Jiyong Park25fc6a92018-11-18 18:02:45 +0900889func (c *Module) IsStubs() bool {
890 if library, ok := c.linker.(*libraryDecorator); ok {
891 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900892 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
893 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900894 }
895 return false
896}
897
898func (c *Module) HasStubsVariants() bool {
899 if library, ok := c.linker.(*libraryDecorator); ok {
900 return len(library.Properties.Stubs.Versions) > 0
901 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700902 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
903 return len(library.Properties.Stubs.Versions) > 0
904 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900905 return false
906}
907
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900908func (c *Module) bootstrap() bool {
909 return Bool(c.Properties.Bootstrap)
910}
911
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700912func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700913 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
914 if c.Target().NativeBridge == android.NativeBridgeEnabled {
915 return false
916 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700917 return c.linker != nil && c.linker.nativeCoverage()
918}
919
Jiyong Park73c54ee2019-10-22 20:31:18 +0900920func (c *Module) ExportedIncludeDirs() android.Paths {
921 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
922 return flagsProducer.exportedDirs()
923 }
Jiyong Park232e7852019-11-04 12:23:40 +0900924 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900925}
926
927func (c *Module) ExportedSystemIncludeDirs() android.Paths {
928 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
929 return flagsProducer.exportedSystemDirs()
930 }
Jiyong Park232e7852019-11-04 12:23:40 +0900931 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900932}
933
934func (c *Module) ExportedFlags() []string {
935 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
936 return flagsProducer.exportedFlags()
937 }
Jiyong Park232e7852019-11-04 12:23:40 +0900938 return nil
939}
940
941func (c *Module) ExportedDeps() android.Paths {
942 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
943 return flagsProducer.exportedDeps()
944 }
945 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900946}
947
Inseob Kimd110f872019-12-06 13:15:38 +0900948func (c *Module) ExportedGeneratedHeaders() android.Paths {
949 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
950 return flagsProducer.exportedGeneratedHeaders()
951 }
952 return nil
953}
954
Jiyong Parkf1194352019-02-25 11:05:47 +0900955func isBionic(name string) bool {
956 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000957 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900958 return true
959 }
960 return false
961}
962
Martin Stjernholm279de572019-09-10 23:18:20 +0100963func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700964 if name == "libclang_rt.hwasan-aarch64-android" {
965 return inList("hwaddress", config.SanitizeDevice())
966 }
967 return isBionic(name)
968}
969
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800970func (c *Module) XrefCcFiles() android.Paths {
971 return c.kytheFiles
972}
973
Colin Crossca860ac2016-01-04 14:34:37 -0800974type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700975 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800976 moduleContextImpl
977}
978
Colin Cross37047f12016-12-13 17:06:13 -0800979type depsContext struct {
980 android.BottomUpMutatorContext
981 moduleContextImpl
982}
983
Colin Crossca860ac2016-01-04 14:34:37 -0800984type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700985 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800986 moduleContextImpl
987}
988
Justin Yun5f7f7e82019-11-18 19:52:14 +0900989func (ctx *moduleContext) ProductSpecific() bool {
990 return ctx.ModuleContext.ProductSpecific() ||
991 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
992}
993
Jiyong Park2db76922017-11-08 16:03:48 +0900994func (ctx *moduleContext) SocSpecific() bool {
995 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +0900996 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700997}
998
Colin Crossca860ac2016-01-04 14:34:37 -0800999type moduleContextImpl struct {
1000 mod *Module
1001 ctx BaseModuleContext
1002}
1003
Colin Crossb98c8b02016-07-29 13:44:28 -07001004func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001005 return ctx.mod.toolchain(ctx.ctx)
1006}
1007
1008func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001009 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001010}
1011
1012func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001013 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001014}
1015
Jiyong Park1d1119f2019-07-29 21:27:18 +09001016func (ctx *moduleContextImpl) header() bool {
1017 return ctx.mod.header()
1018}
1019
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001020func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -08001021 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -08001022 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001023 }
1024 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001025}
1026
1027func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001028 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001029 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001030 vndkVer := ctx.mod.VndkVersion()
1031 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1032 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001033 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001034 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001035 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001036 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001037 }
1038 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001039}
1040
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001041func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001042 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001043}
Justin Yun8effde42017-06-23 19:24:43 +09001044
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001045func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001046 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001047}
1048
Inseob Kim9516ee92019-05-09 10:56:13 +09001049func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1050 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001051}
1052
Inseob Kim9516ee92019-05-09 10:56:13 +09001053func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1054 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001055}
1056
Inseob Kim9516ee92019-05-09 10:56:13 +09001057func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1058 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001059}
1060
Logan Chienf3511742017-10-31 18:04:35 +08001061func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001062 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001063}
1064
Yi Kong7e53c572018-02-14 18:16:12 +08001065func (ctx *moduleContextImpl) isPgoCompile() bool {
1066 return ctx.mod.isPgoCompile()
1067}
1068
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001069func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1070 return ctx.mod.isNDKStubLibrary()
1071}
1072
Justin Yun8effde42017-06-23 19:24:43 +09001073func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001074 return ctx.mod.isVndkSp()
1075}
1076
1077func (ctx *moduleContextImpl) isVndkExt() bool {
1078 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001079}
1080
Vic Yangefd249e2018-11-12 20:19:56 -08001081func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001082 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001083}
1084
Justin Yun5f7f7e82019-11-18 19:52:14 +09001085func (ctx *moduleContextImpl) inProduct() bool {
1086 return ctx.mod.inProduct()
1087}
1088
1089func (ctx *moduleContextImpl) inVendor() bool {
1090 return ctx.mod.inVendor()
1091}
1092
Jiyong Parkf9332f12018-02-01 00:54:12 +09001093func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001094 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001095}
1096
Logan Chien2f2b8902018-07-10 15:01:19 +08001097// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001098func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001099 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1100 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001101 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001102
1103 if ctx.ctx.Fuchsia() {
1104 return false
1105 }
1106
Logan Chien2f2b8902018-07-10 15:01:19 +08001107 if sanitize := ctx.mod.sanitize; sanitize != nil {
1108 if !sanitize.isVariantOnProductionDevice() {
1109 return false
1110 }
1111 }
1112 if !ctx.ctx.Device() {
1113 // Host modules do not need ABI dumps.
1114 return false
1115 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001116 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001117 // Stubs do not need ABI dumps.
1118 return false
1119 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001120 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001121}
1122
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001123func (ctx *moduleContextImpl) selectedStl() string {
1124 if stl := ctx.mod.stl; stl != nil {
1125 return stl.Properties.SelectedStl
1126 }
1127 return ""
1128}
1129
Ivan Lozanobd721262018-11-27 14:33:03 -08001130func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1131 return ctx.mod.linker.useClangLld(actx)
1132}
1133
Colin Crossce75d2c2016-10-06 16:12:58 -07001134func (ctx *moduleContextImpl) baseModuleName() string {
1135 return ctx.mod.ModuleBase.BaseModuleName()
1136}
1137
Logan Chienf3511742017-10-31 18:04:35 +08001138func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1139 return ctx.mod.getVndkExtendsModuleName()
1140}
1141
Logan Chiene274fc92019-12-03 11:18:32 -08001142func (ctx *moduleContextImpl) isForPlatform() bool {
1143 return ctx.mod.IsForPlatform()
1144}
1145
Jiyong Park58e364a2019-01-19 19:24:06 +09001146func (ctx *moduleContextImpl) apexName() string {
1147 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001148}
1149
Jiyong Parkb0788572018-12-20 22:10:17 +09001150func (ctx *moduleContextImpl) hasStubsVariants() bool {
1151 return ctx.mod.HasStubsVariants()
1152}
1153
1154func (ctx *moduleContextImpl) isStubs() bool {
1155 return ctx.mod.IsStubs()
1156}
1157
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001158func (ctx *moduleContextImpl) bootstrap() bool {
1159 return ctx.mod.bootstrap()
1160}
1161
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001162func (ctx *moduleContextImpl) nativeCoverage() bool {
1163 return ctx.mod.nativeCoverage()
1164}
1165
Colin Cross635c3b02016-05-18 15:37:25 -07001166func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001167 return &Module{
1168 hod: hod,
1169 multilib: multilib,
1170 }
1171}
1172
Colin Cross635c3b02016-05-18 15:37:25 -07001173func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001174 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001175 module.features = []feature{
1176 &tidyFeature{},
1177 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001178 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001179 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001180 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001181 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001182 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001183 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001184 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001185 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001186 return module
1187}
1188
Colin Crossce75d2c2016-10-06 16:12:58 -07001189func (c *Module) Prebuilt() *android.Prebuilt {
1190 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1191 return p.prebuilt()
1192 }
1193 return nil
1194}
1195
1196func (c *Module) Name() string {
1197 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001198 if p, ok := c.linker.(interface {
1199 Name(string) string
1200 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001201 name = p.Name(name)
1202 }
1203 return name
1204}
1205
Alex Light3d673592019-01-18 14:37:31 -08001206func (c *Module) Symlinks() []string {
1207 if p, ok := c.installer.(interface {
1208 symlinkList() []string
1209 }); ok {
1210 return p.symlinkList()
1211 }
1212 return nil
1213}
1214
Jeff Gaston294356f2017-09-27 17:05:30 -07001215// orderDeps reorders dependencies into a list such that if module A depends on B, then
1216// A will precede B in the resultant list.
1217// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001218// Note that directSharedDeps should be the analogous static library for each shared lib dep
1219func 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 -07001220 // If A depends on B, then
1221 // Every list containing A will also contain B later in the list
1222 // So, after concatenating all lists, the final instance of B will have come from the same
1223 // original list as the final instance of A
1224 // So, the final instance of B will be later in the concatenation than the final A
1225 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1226 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001227 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001228 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001229 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1230 }
1231 for _, dep := range directSharedDeps {
1232 orderedAllDeps = append(orderedAllDeps, dep)
1233 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001234 }
1235
Colin Crossb6715442017-10-24 11:13:31 -07001236 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001237
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001238 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001239 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001240 // resultant list to only what the caller has chosen to include in directStaticDeps
1241 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001242
1243 return orderedAllDeps, orderedDeclaredDeps
1244}
1245
Ivan Lozano183a3212019-10-18 14:18:45 -07001246func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001247 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001248 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001249 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1250 staticDepFiles := []android.Path{}
1251 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001252 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1253 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001254 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001255 sharedDepFiles := []android.Path{}
1256 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001257 if sharedDep.HasStaticVariant() {
1258 staticAnalogue := sharedDep.GetStaticVariant()
1259 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1260 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001261 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001262 }
1263
1264 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001265 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1266 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001267
1268 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001269}
1270
Jiyong Park83dc74b2020-01-14 18:38:44 +09001271func gatherTransitiveStaticDeps(staticDeps []LinkableInterface) []string {
1272 var ret []string
1273 for _, dep := range staticDeps {
1274 ret = append(ret, dep.Module().Name())
1275 ret = append(ret, dep.AllStaticDeps()...)
1276 }
1277 return android.FirstUniqueStrings(ret)
1278}
1279
Roland Levillainf89cd092019-07-29 16:22:59 +01001280func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1281 test, ok := c.linker.(testPerSrc)
1282 return ok && test.isAllTestsVariation()
1283}
1284
Justin Yun5f7f7e82019-11-18 19:52:14 +09001285func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1286 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1287 // "current", it will append the VNDK version to the name suffix.
1288 var vndkVersion string
1289 var nameSuffix string
1290 if c.inProduct() {
1291 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1292 nameSuffix = productSuffix
1293 } else {
1294 vndkVersion = ctx.DeviceConfig().VndkVersion()
1295 nameSuffix = vendorSuffix
1296 }
1297 if vndkVersion == "current" {
1298 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1299 }
1300 if c.Properties.VndkVersion != vndkVersion {
1301 // add version suffix only if the module is using different vndk version than the
1302 // version in product or vendor partition.
1303 nameSuffix += "." + c.Properties.VndkVersion
1304 }
1305 return nameSuffix
1306}
1307
Colin Cross635c3b02016-05-18 15:37:25 -07001308func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001309 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001310 //
1311 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1312 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1313 // module and return early, as this module does not produce an output file per se.
1314 if c.IsTestPerSrcAllTestsVariation() {
1315 c.outputFile = android.OptionalPath{}
1316 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001317 }
1318
Jooyung Han38002912019-05-16 04:01:54 +09001319 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001320
Inseob Kim64c43952019-08-26 16:52:35 +09001321 c.Properties.SubName = ""
1322
1323 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1324 c.Properties.SubName += nativeBridgeSuffix
1325 }
1326
Justin Yun5f7f7e82019-11-18 19:52:14 +09001327 _, llndk := c.linker.(*llndkStubDecorator)
1328 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1329 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1330 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1331 // added for product variant only when we have vendor and product variants with core
1332 // variant. The suffix is not added for vendor-only or product-only module.
1333 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1334 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001335 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1336 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1337 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001338 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001339 c.Properties.SubName += recoverySuffix
1340 }
1341
Colin Crossca860ac2016-01-04 14:34:37 -08001342 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001343 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001344 moduleContextImpl: moduleContextImpl{
1345 mod: c,
1346 },
1347 }
1348 ctx.ctx = ctx
1349
Colin Crossf18e1102017-11-16 14:33:08 -08001350 deps := c.depsToPaths(ctx)
1351 if ctx.Failed() {
1352 return
1353 }
1354
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001355 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1356 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1357 }
1358
Colin Crossca860ac2016-01-04 14:34:37 -08001359 flags := Flags{
1360 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001361 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001362 }
Colin Crossca860ac2016-01-04 14:34:37 -08001363 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001364 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001365 }
1366 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001367 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001368 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001369 if c.stl != nil {
1370 flags = c.stl.flags(ctx, flags)
1371 }
Colin Cross16b23492016-01-06 14:41:07 -08001372 if c.sanitize != nil {
1373 flags = c.sanitize.flags(ctx, flags)
1374 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001375 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001376 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001377 }
Stephen Craneba090d12017-05-09 15:44:35 -07001378 if c.lto != nil {
1379 flags = c.lto.flags(ctx, flags)
1380 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001381 if c.pgo != nil {
1382 flags = c.pgo.flags(ctx, flags)
1383 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001384 if c.xom != nil {
1385 flags = c.xom.flags(ctx, flags)
1386 }
Colin Crossca860ac2016-01-04 14:34:37 -08001387 for _, feature := range c.features {
1388 flags = feature.flags(ctx, flags)
1389 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001390 if ctx.Failed() {
1391 return
1392 }
1393
Colin Cross4af21ed2019-11-04 09:37:55 -08001394 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1395 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1396 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001397
Colin Cross4af21ed2019-11-04 09:37:55 -08001398 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001399
1400 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001401 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001402 }
1403 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001404 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001405 }
1406
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001407 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001408 // We need access to all the flags seen by a source file.
1409 if c.sabi != nil {
1410 flags = c.sabi.flags(ctx, flags)
1411 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001412
Colin Cross4af21ed2019-11-04 09:37:55 -08001413 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001414
Colin Crossca860ac2016-01-04 14:34:37 -08001415 // Optimization to reduce size of build.ninja
1416 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001417 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1418 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1419 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1420 flags.Local.CFlags = []string{"$cflags"}
1421 flags.Local.CppFlags = []string{"$cppflags"}
1422 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001423
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001424 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001425 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001426 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001427 if ctx.Failed() {
1428 return
1429 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001430 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001431 }
1432
Colin Crossca860ac2016-01-04 14:34:37 -08001433 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001434 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001435 if ctx.Failed() {
1436 return
1437 }
Colin Cross635c3b02016-05-18 15:37:25 -07001438 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001439
1440 // If a lib is directly included in any of the APEXes, unhide the stubs
1441 // variant having the latest version gets visible to make. In addition,
1442 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1443 // force anything in the make world to link against the stubs library.
1444 // (unless it is explicitly referenced via .bootstrap suffix or the
1445 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001446 if c.HasStubsVariants() &&
1447 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001448 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001449 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001450 c.Properties.HideFromMake = false // unhide
1451 // Note: this is still non-installable
1452 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001453 }
Colin Cross5049f022015-03-18 13:28:46 -07001454
Inseob Kim1f086e22019-05-09 13:29:15 +09001455 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001456 c.installer.install(ctx, c.outputFile.Path())
1457 if ctx.Failed() {
1458 return
Colin Crossca860ac2016-01-04 14:34:37 -08001459 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001460 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001461}
1462
Colin Cross0ea8ba82019-06-06 14:33:29 -07001463func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001464 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001465 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001466 }
Colin Crossca860ac2016-01-04 14:34:37 -08001467 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001468}
1469
Colin Crossca860ac2016-01-04 14:34:37 -08001470func (c *Module) begin(ctx BaseModuleContext) {
1471 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001472 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001473 }
Colin Crossca860ac2016-01-04 14:34:37 -08001474 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001475 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001476 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001477 if c.stl != nil {
1478 c.stl.begin(ctx)
1479 }
Colin Cross16b23492016-01-06 14:41:07 -08001480 if c.sanitize != nil {
1481 c.sanitize.begin(ctx)
1482 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001483 if c.coverage != nil {
1484 c.coverage.begin(ctx)
1485 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001486 if c.sabi != nil {
1487 c.sabi.begin(ctx)
1488 }
Justin Yun8effde42017-06-23 19:24:43 +09001489 if c.vndkdep != nil {
1490 c.vndkdep.begin(ctx)
1491 }
Stephen Craneba090d12017-05-09 15:44:35 -07001492 if c.lto != nil {
1493 c.lto.begin(ctx)
1494 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001495 if c.pgo != nil {
1496 c.pgo.begin(ctx)
1497 }
Colin Crossca860ac2016-01-04 14:34:37 -08001498 for _, feature := range c.features {
1499 feature.begin(ctx)
1500 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001501 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001502 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001503 if err != nil {
1504 ctx.PropertyErrorf("sdk_version", err.Error())
1505 }
Nan Zhang0007d812017-11-07 10:57:05 -08001506 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001507 }
Colin Crossca860ac2016-01-04 14:34:37 -08001508}
1509
Colin Cross37047f12016-12-13 17:06:13 -08001510func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001511 deps := Deps{}
1512
1513 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001514 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001515 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001516 // Add the PGO dependency (the clang_rt.profile runtime library), which
1517 // sometimes depends on symbols from libgcc, before libgcc gets added
1518 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001519 if c.pgo != nil {
1520 deps = c.pgo.deps(ctx, deps)
1521 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001522 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001523 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001524 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001525 if c.stl != nil {
1526 deps = c.stl.deps(ctx, deps)
1527 }
Colin Cross16b23492016-01-06 14:41:07 -08001528 if c.sanitize != nil {
1529 deps = c.sanitize.deps(ctx, deps)
1530 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001531 if c.coverage != nil {
1532 deps = c.coverage.deps(ctx, deps)
1533 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001534 if c.sabi != nil {
1535 deps = c.sabi.deps(ctx, deps)
1536 }
Justin Yun8effde42017-06-23 19:24:43 +09001537 if c.vndkdep != nil {
1538 deps = c.vndkdep.deps(ctx, deps)
1539 }
Stephen Craneba090d12017-05-09 15:44:35 -07001540 if c.lto != nil {
1541 deps = c.lto.deps(ctx, deps)
1542 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001543 for _, feature := range c.features {
1544 deps = feature.deps(ctx, deps)
1545 }
1546
Colin Crossb6715442017-10-24 11:13:31 -07001547 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1548 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1549 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1550 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1551 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1552 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001553 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001554
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001555 for _, lib := range deps.ReexportSharedLibHeaders {
1556 if !inList(lib, deps.SharedLibs) {
1557 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1558 }
1559 }
1560
1561 for _, lib := range deps.ReexportStaticLibHeaders {
1562 if !inList(lib, deps.StaticLibs) {
1563 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1564 }
1565 }
1566
Colin Cross5950f382016-12-13 12:50:57 -08001567 for _, lib := range deps.ReexportHeaderLibHeaders {
1568 if !inList(lib, deps.HeaderLibs) {
1569 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1570 }
1571 }
1572
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001573 for _, gen := range deps.ReexportGeneratedHeaders {
1574 if !inList(gen, deps.GeneratedHeaders) {
1575 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1576 }
1577 }
1578
Colin Crossc99deeb2016-04-11 15:06:20 -07001579 return deps
1580}
1581
Dan Albert7e9d2952016-08-04 13:02:36 -07001582func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001583 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001584 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001585 moduleContextImpl: moduleContextImpl{
1586 mod: c,
1587 },
1588 }
1589 ctx.ctx = ctx
1590
Colin Crossca860ac2016-01-04 14:34:37 -08001591 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001592}
1593
Jiyong Park7ed9de32018-10-15 22:25:07 +09001594// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001595func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001596 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1597 version := name[sharp+1:]
1598 libname := name[:sharp]
1599 return libname, version
1600 }
1601 return name, ""
1602}
1603
Colin Cross1e676be2016-10-12 14:38:15 -07001604func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001605 ctx := &depsContext{
1606 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001607 moduleContextImpl: moduleContextImpl{
1608 mod: c,
1609 },
1610 }
1611 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001612
Colin Crossc99deeb2016-04-11 15:06:20 -07001613 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001614
Dan Albert914449f2016-06-17 16:45:24 -07001615 variantNdkLibs := []string{}
1616 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001617 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001618 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001619
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001620 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1621 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001622 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001623 // 1. Name of an NDK library that refers to a prebuilt module.
1624 // For each of these, it adds the name of the prebuilt module (which will be in
1625 // prebuilts/ndk) to the list of nonvariant libs.
1626 // 2. Name of an NDK library that refers to an ndk_library module.
1627 // For each of these, it adds the name of the ndk_library module to the list of
1628 // variant libs.
1629 // 3. Anything else (so anything that isn't an NDK library).
1630 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001631 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001632 // The caller can then know to add the variantLibs dependencies differently from the
1633 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001634
Inseob Kim9516ee92019-05-09 10:56:13 +09001635 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001636 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1637 variantLibs = []string{}
1638 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001639 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001640 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001641 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001642 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1643 if !inList(name, ndkMigratedLibs) {
1644 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001645 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001646 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001647 }
Jooyung Han0302a842019-10-30 18:43:49 +09001648 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001649 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001650 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001651 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001652 if actx.OtherModuleExists(vendorPublicLib) {
1653 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1654 } else {
1655 // This can happen if vendor_public_library module is defined in a
1656 // namespace that isn't visible to the current module. In that case,
1657 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001658 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001659 }
Dan Albert914449f2016-06-17 16:45:24 -07001660 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001661 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001662 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001663 }
1664 }
Dan Albert914449f2016-06-17 16:45:24 -07001665 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001666 }
1667
Dan Albert914449f2016-06-17 16:45:24 -07001668 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1669 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001670 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001671 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001672
Jiyong Park7e636d02019-01-28 16:16:54 +09001673 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001674 if c.linker != nil {
1675 if library, ok := c.linker.(*libraryDecorator); ok {
1676 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001677 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001678 }
1679 }
1680 }
1681
Colin Cross32ec36c2016-12-15 07:39:51 -08001682 for _, lib := range deps.HeaderLibs {
1683 depTag := headerDepTag
1684 if inList(lib, deps.ReexportHeaderLibHeaders) {
1685 depTag = headerExportDepTag
1686 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001687 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001688 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001689 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001690 } else {
1691 actx.AddVariationDependencies(nil, depTag, lib)
1692 }
1693 }
1694
1695 if buildStubs {
1696 // Stubs lib does not have dependency to other static/shared libraries.
1697 // Don't proceed.
1698 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001699 }
Colin Cross5950f382016-12-13 12:50:57 -08001700
Inseob Kimc0907f12019-02-08 21:00:45 +09001701 syspropImplLibraries := syspropImplLibraries(actx.Config())
1702
Jiyong Park5d1598f2019-02-25 22:14:17 +09001703 for _, lib := range deps.WholeStaticLibs {
1704 depTag := wholeStaticDepTag
1705 if impl, ok := syspropImplLibraries[lib]; ok {
1706 lib = impl
1707 }
1708 actx.AddVariationDependencies([]blueprint.Variation{
1709 {Mutator: "link", Variation: "static"},
1710 }, depTag, lib)
1711 }
1712
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001713 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001714 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001715 if inList(lib, deps.ReexportStaticLibHeaders) {
1716 depTag = staticExportDepTag
1717 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001718
1719 if impl, ok := syspropImplLibraries[lib]; ok {
1720 lib = impl
1721 }
1722
Dan Willemsen59339a22018-07-22 21:18:45 -07001723 actx.AddVariationDependencies([]blueprint.Variation{
1724 {Mutator: "link", Variation: "static"},
1725 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001726 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001727
Dan Willemsen59339a22018-07-22 21:18:45 -07001728 actx.AddVariationDependencies([]blueprint.Variation{
1729 {Mutator: "link", Variation: "static"},
1730 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001731
Ivan Lozano183a3212019-10-18 14:18:45 -07001732 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001733 var variations []blueprint.Variation
1734 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001735 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001736 if version != "" && versionVariantAvail {
1737 // Version is explicitly specified. i.e. libFoo#30
1738 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001739 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001740 }
1741 actx.AddVariationDependencies(variations, depTag, name)
1742
1743 // If the version is not specified, add dependency to the latest stubs library.
1744 // The stubs library will be used when the depending module is built for APEX and
1745 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001746 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001747 if version == "" && latestVersion != "" && versionVariantAvail {
1748 actx.AddVariationDependencies([]blueprint.Variation{
1749 {Mutator: "link", Variation: "shared"},
1750 {Mutator: "version", Variation: latestVersion},
1751 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001752 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001753 }
1754 }
1755
Jiyong Park7ed9de32018-10-15 22:25:07 +09001756 // shared lib names without the #version suffix
1757 var sharedLibNames []string
1758
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001759 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001760 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001761 if inList(lib, deps.ReexportSharedLibHeaders) {
1762 depTag = sharedExportDepTag
1763 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001764
1765 if impl, ok := syspropImplLibraries[lib]; ok {
1766 lib = impl
1767 }
1768
Jiyong Park73c54ee2019-10-22 20:31:18 +09001769 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001770 sharedLibNames = append(sharedLibNames, name)
1771
Jiyong Park25fc6a92018-11-18 18:02:45 +09001772 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001773 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001774
Jiyong Park7ed9de32018-10-15 22:25:07 +09001775 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001776 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001777 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1778 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1779 // linking against both the stubs lib and the non-stubs lib at the same time.
1780 continue
1781 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001782 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001783 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001784
Dan Willemsen59339a22018-07-22 21:18:45 -07001785 actx.AddVariationDependencies([]blueprint.Variation{
1786 {Mutator: "link", Variation: "shared"},
1787 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001788
Colin Cross68861832016-07-08 10:41:41 -07001789 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001790
1791 for _, gen := range deps.GeneratedHeaders {
1792 depTag := genHeaderDepTag
1793 if inList(gen, deps.ReexportGeneratedHeaders) {
1794 depTag = genHeaderExportDepTag
1795 }
1796 actx.AddDependency(c, depTag, gen)
1797 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001798
Colin Cross42d48b72018-08-29 14:10:52 -07001799 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001800
1801 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001802 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001803 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001804 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001805 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001806 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001807 if deps.LinkerFlagsFile != "" {
1808 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1809 }
1810 if deps.DynamicLinker != "" {
1811 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001812 }
Dan Albert914449f2016-06-17 16:45:24 -07001813
1814 version := ctx.sdkVersion()
1815 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001816 {Mutator: "ndk_api", Variation: version},
1817 {Mutator: "link", Variation: "shared"},
1818 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001819 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001820 {Mutator: "ndk_api", Variation: version},
1821 {Mutator: "link", Variation: "shared"},
1822 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001823
1824 if vndkdep := c.vndkdep; vndkdep != nil {
1825 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001826 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001827 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001828 {Mutator: "link", Variation: "shared"},
1829 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001830 }
1831 }
Colin Cross6362e272015-10-29 15:25:03 -07001832}
Colin Cross21b9a242015-03-24 14:15:58 -07001833
Colin Crosse40b4ea2018-10-02 22:25:58 -07001834func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001835 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1836 c.beginMutator(ctx)
1837 }
1838}
1839
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001840// Whether a module can link to another module, taking into
1841// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001842func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1843 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001844 // Host code is not restricted
1845 return
1846 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001847
1848 // VNDK is cc.Module supported only for now.
1849 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001850 // Though vendor code is limited by the vendor mutator,
1851 // each vendor-available module needs to check
1852 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001853 if ccTo, ok := to.(*Module); ok {
1854 if ccFrom.vndkdep != nil {
1855 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1856 }
1857 } else {
1858 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001859 }
1860 return
1861 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001862 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001863 // Platform code can link to anything
1864 return
1865 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001866 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001867 // Recovery code is not NDK
1868 return
1869 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001870 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001871 // These are always allowed
1872 return
1873 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001874 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001875 // These are allowed, but they don't set sdk_version
1876 return
1877 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001878 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001879 // These aren't real libraries, but are the stub shared libraries that are included in
1880 // the NDK.
1881 return
1882 }
Logan Chien834b9a62019-01-14 15:39:03 +08001883
Ivan Lozano52767be2019-10-18 14:49:46 -07001884 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001885 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1886 // to link to libc++ (non-NDK and without sdk_version).
1887 return
1888 }
1889
Ivan Lozano52767be2019-10-18 14:49:46 -07001890 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001891 // NDK code linking to platform code is never okay.
1892 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001893 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001894 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001895 }
1896
1897 // At this point we know we have two NDK libraries, but we need to
1898 // check that we're not linking against anything built against a higher
1899 // API level, as it is only valid to link against older or equivalent
1900 // APIs.
1901
Inseob Kim01a28722018-04-11 09:48:45 +09001902 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001903 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001904 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001905 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001906 // Current can't be linked against by anything else.
1907 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001908 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001909 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001910 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001911 if err != nil {
1912 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001913 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001914 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001915 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001916 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001917 if err != nil {
1918 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001919 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001920 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001921 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001922
Inseob Kim01a28722018-04-11 09:48:45 +09001923 if toApi > fromApi {
1924 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001925 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001926 }
1927 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001928 }
Dan Albert202fe492017-12-15 13:56:59 -08001929
1930 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001931 fromStl := from.SelectedStl()
1932 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001933 if fromStl == "" || toStl == "" {
1934 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001935 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001936 // We can be permissive with the system "STL" since it is only the C++
1937 // ABI layer, but in the future we should make sure that everyone is
1938 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001939 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001940 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001941 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1942 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001943 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001944}
1945
Jiyong Park5fb8c102018-04-09 12:03:06 +09001946// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001947// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1948// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001949// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001950func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1951 check := func(child, parent android.Module) bool {
1952 to, ok := child.(*Module)
1953 if !ok {
1954 // follow thru cc.Defaults, etc.
1955 return true
1956 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001957
Jooyung Hana70f0672019-01-18 15:20:43 +09001958 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1959 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001960 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001961
1962 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001963 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001964 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001965 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001966
Jooyung Han0302a842019-10-30 18:43:49 +09001967 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001968 return false
1969 }
1970
1971 var stringPath []string
1972 for _, m := range ctx.GetWalkPath() {
1973 stringPath = append(stringPath, m.Name())
1974 }
1975 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1976 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1977 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1978 return false
1979 }
1980 if module, ok := ctx.Module().(*Module); ok {
1981 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001982 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001983 ctx.WalkDeps(check)
1984 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001985 }
1986 }
1987}
1988
Colin Crossc99deeb2016-04-11 15:06:20 -07001989// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001990func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001991 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001992
Ivan Lozano183a3212019-10-18 14:18:45 -07001993 directStaticDeps := []LinkableInterface{}
1994 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001995
Inseob Kim9516ee92019-05-09 10:56:13 +09001996 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1997
Inseob Kim69378442019-06-03 19:10:47 +09001998 reexportExporter := func(exporter exportedFlagsProducer) {
1999 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2000 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2001 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2002 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002003 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002004 }
2005
Colin Crossd11fcda2017-10-23 17:59:01 -07002006 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002007 depName := ctx.OtherModuleName(dep)
2008 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002009
Ivan Lozano52767be2019-10-18 14:49:46 -07002010 ccDep, ok := dep.(LinkableInterface)
2011 if !ok {
2012
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002013 // handling for a few module types that aren't cc Module but that are also supported
2014 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002015 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002016 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002017 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2018 genRule.GeneratedSourceFiles()...)
2019 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002020 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002021 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002022 // Support exported headers from a generated_sources dependency
2023 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002024 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002025 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002026 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002027 genRule.GeneratedSourceFiles()...)
2028 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002029 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002030 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002031 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002032 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002033 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002034 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2035 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002036 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002037 // 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 +09002038 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002039
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002040 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002041 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002042 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002043 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002044 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002045 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002046 files := genRule.GeneratedSourceFiles()
2047 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002048 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002049 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002050 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 -07002051 }
2052 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002053 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002054 }
Colin Crossca860ac2016-01-04 14:34:37 -08002055 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002056 return
2057 }
2058
Colin Crossfe17f6f2019-03-28 19:30:56 -07002059 if depTag == android.ProtoPluginDepTag {
2060 return
2061 }
2062
Colin Crossd11fcda2017-10-23 17:59:01 -07002063 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002064 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2065 return
2066 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002067 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002068 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002069 return
2070 }
2071
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002072 // re-exporting flags
2073 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002074 // reusing objects only make sense for cc.Modules.
2075 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002076 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002077 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002078 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002079 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002080 return
2081 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002082 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002083
Jiyong Parke4bb9862019-02-01 00:31:10 +09002084 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002085 // staticVariants are a cc.Module specific concept.
2086 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002087 c.staticVariant = ccDep
2088 return
2089 }
2090 }
2091
Ivan Lozano183a3212019-10-18 14:18:45 -07002092 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2093 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2094 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002095 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002096 if t, ok := depTag.(DependencyTag); ok {
2097 explicitlyVersioned = t.ExplicitlyVersioned
2098 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002099 depTag = t
2100 }
2101
Ivan Lozano183a3212019-10-18 14:18:45 -07002102 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002103 depIsStatic := false
2104 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002105 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002106 depIsStatic = true
2107 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002108 if ccDep.CcLibrary() && !depIsStatic {
2109 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002110 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002111 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002112 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002113
2114 var useThisDep bool
2115 if depIsStubs && explicitlyVersioned {
2116 // Always respect dependency to the versioned stubs (i.e. libX#10)
2117 useThisDep = true
2118 } else if !depHasStubs {
2119 // Use non-stub variant if that is the only choice
2120 // (i.e. depending on a lib without stubs.version property)
2121 useThisDep = true
2122 } else if c.IsForPlatform() {
2123 // If not building for APEX, use stubs only when it is from
2124 // an APEX (and not from platform)
2125 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002126 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002127 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002128 // always link to non-stub variant
2129 useThisDep = !depIsStubs
2130 }
2131 } else {
2132 // If building for APEX, use stubs only when it is not from
2133 // the same APEX
2134 useThisDep = (depInSameApex != depIsStubs)
2135 }
2136
2137 if !useThisDep {
2138 return // stop processing this dep
2139 }
2140 }
2141
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002142 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2143
Ivan Lozano52767be2019-10-18 14:49:46 -07002144 // Exporting flags only makes sense for cc.Modules
2145 if _, ok := ccDep.(*Module); ok {
2146 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002147 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002148 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2149 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002150 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002151
Ivan Lozano52767be2019-10-18 14:49:46 -07002152 if t.ReexportFlags {
2153 reexportExporter(i)
2154 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2155 // Re-exported shared library headers must be included as well since they can help us with type information
2156 // about template instantiations (instantiated from their headers).
2157 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2158 // scripts.
2159 c.sabi.Properties.ReexportedIncludes = append(
2160 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2161 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002162 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002163 }
Logan Chienf3511742017-10-31 18:04:35 +08002164 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002165 }
2166
Colin Cross26c34ed2016-09-30 17:10:16 -07002167 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002168 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002169
Ivan Lozano52767be2019-10-18 14:49:46 -07002170 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002171 depFile := android.OptionalPath{}
2172
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002173 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002174 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002175 ptr = &depPaths.SharedLibs
2176 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002178 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002179
Jiyong Park64a44f22019-01-18 14:37:08 +09002180 case earlySharedDepTag:
2181 ptr = &depPaths.EarlySharedLibs
2182 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002183 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002184 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002185 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002186 ptr = &depPaths.LateSharedLibs
2187 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002188 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002189 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002190 ptr = nil
2191 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002192 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002193 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002194 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002195 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002196 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002197 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002198 return
2199 }
2200
Ivan Lozano52767be2019-10-18 14:49:46 -07002201 // Because the static library objects are included, this only makes sense
2202 // in the context of proper cc.Modules.
2203 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2204 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2205 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2206 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2207 for i := range missingDeps {
2208 missingDeps[i] += postfix
2209 }
2210 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002211 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002212 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2213 } else {
2214 ctx.ModuleErrorf(
2215 "non-cc.Modules cannot be included as whole static libraries.", depName)
2216 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002217 }
Colin Cross5950f382016-12-13 12:50:57 -08002218 case headerDepTag:
2219 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002220 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002221 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002222 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002223 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002224 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002225 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002226 case dynamicLinkerDepTag:
2227 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002228 }
2229
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002230 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002231 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002232 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002233 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002234 return
2235 }
2236
2237 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002238 // in static libraries act as if they were whole static libraries. The same goes for
2239 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002240 // This should only be done for cc.Modules
2241 if c, ok := ccDep.(*Module); ok {
2242 staticLib := c.linker.(libraryInterface)
2243 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2244 staticLib.objs().coverageFiles...)
2245 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2246 staticLib.objs().sAbiDumpFiles...)
2247 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002248 }
2249
Colin Cross26c34ed2016-09-30 17:10:16 -07002250 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002251 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002252 if !ctx.Config().AllowMissingDependencies() {
2253 ctx.ModuleErrorf("module %q missing output file", depName)
2254 } else {
2255 ctx.AddMissingDependencies([]string{depName})
2256 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002257 return
2258 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002259 *ptr = append(*ptr, linkFile.Path())
2260 }
2261
Colin Crossc99deeb2016-04-11 15:06:20 -07002262 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002263 dep := depFile
2264 if !dep.Valid() {
2265 dep = linkFile
2266 }
2267 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002268 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002269
Logan Chien43d34c32017-12-20 01:17:32 +08002270 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002271 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002272 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002273 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002274 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002275 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002276 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002277
Ivan Lozano52767be2019-10-18 14:49:46 -07002278 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002279 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2280 // core module instead.
2281 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002282 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002283 // The vendor module in Make will have been renamed to not conflict with the core
2284 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002285 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002286 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002287 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002288 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002289 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002290 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002291 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002292 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002293 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002294 }
Logan Chien43d34c32017-12-20 01:17:32 +08002295 }
2296
2297 // Export the shared libs to Make.
2298 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002299 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002300 if ccDep.CcLibrary() {
2301 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002302 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002303 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002304 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002305 c.Properties.ApexesProvidingSharedLibs = append(
2306 c.Properties.ApexesProvidingSharedLibs, an)
2307 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002308 }
2309 }
2310
Jiyong Park27b188b2017-07-18 13:23:39 +09002311 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002312 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002313 c.Properties.AndroidMkSharedLibs = append(
2314 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002315 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002316 c.Properties.AndroidMkSharedLibs = append(
2317 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002318 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002319 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002320 c.Properties.AndroidMkStaticLibs = append(
2321 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002322 case runtimeDepTag:
2323 c.Properties.AndroidMkRuntimeLibs = append(
2324 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002325 case wholeStaticDepTag:
2326 c.Properties.AndroidMkWholeStaticLibs = append(
2327 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002328 }
Colin Crossca860ac2016-01-04 14:34:37 -08002329 })
2330
Jeff Gaston294356f2017-09-27 17:05:30 -07002331 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002332 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002333
Colin Crossdd84e052017-05-17 13:44:16 -07002334 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002335 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002336 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2337 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002338 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002339 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002340 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2341 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002342 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002343 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002344 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002345
2346 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002347 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002348 }
Colin Crossdd84e052017-05-17 13:44:16 -07002349
Jiyong Park83dc74b2020-01-14 18:38:44 +09002350 c.allStaticDeps = gatherTransitiveStaticDeps(directStaticDeps)
2351
Colin Crossca860ac2016-01-04 14:34:37 -08002352 return depPaths
2353}
2354
2355func (c *Module) InstallInData() bool {
2356 if c.installer == nil {
2357 return false
2358 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002359 return c.installer.inData()
2360}
2361
2362func (c *Module) InstallInSanitizerDir() bool {
2363 if c.installer == nil {
2364 return false
2365 }
2366 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002367 return true
2368 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002369 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002370}
2371
Jiyong Parkf9332f12018-02-01 00:54:12 +09002372func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002373 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002374}
2375
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002376func (c *Module) HostToolPath() android.OptionalPath {
2377 if c.installer == nil {
2378 return android.OptionalPath{}
2379 }
2380 return c.installer.hostToolPath()
2381}
2382
Nan Zhangd4e641b2017-07-12 12:55:28 -07002383func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2384 return c.outputFile
2385}
2386
Colin Cross41955e82019-05-29 14:40:35 -07002387func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2388 switch tag {
2389 case "":
2390 if c.outputFile.Valid() {
2391 return android.Paths{c.outputFile.Path()}, nil
2392 }
2393 return android.Paths{}, nil
2394 default:
2395 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002396 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002397}
2398
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002399func (c *Module) static() bool {
2400 if static, ok := c.linker.(interface {
2401 static() bool
2402 }); ok {
2403 return static.static()
2404 }
2405 return false
2406}
2407
Jiyong Park379de2f2018-12-19 02:47:14 +09002408func (c *Module) staticBinary() bool {
2409 if static, ok := c.linker.(interface {
2410 staticBinary() bool
2411 }); ok {
2412 return static.staticBinary()
2413 }
2414 return false
2415}
2416
Jiyong Park1d1119f2019-07-29 21:27:18 +09002417func (c *Module) header() bool {
2418 if h, ok := c.linker.(interface {
2419 header() bool
2420 }); ok {
2421 return h.header()
2422 }
2423 return false
2424}
2425
Jooyung Han38002912019-05-16 04:01:54 +09002426func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002427 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002428 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2429 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002430 return "native:vndk"
2431 }
Jooyung Han38002912019-05-16 04:01:54 +09002432 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002433 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002434 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002435 if Bool(c.VendorProperties.Vendor_available) {
2436 return "native:vndk"
2437 }
2438 return "native:vndk_private"
2439 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002440 if c.inProduct() {
2441 return "native:product"
2442 }
Jooyung Han38002912019-05-16 04:01:54 +09002443 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002444 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002445 return "native:recovery"
2446 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2447 return "native:ndk:none:none"
2448 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2449 //family, link := getNdkStlFamilyAndLinkType(c)
2450 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002451 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002452 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002453 } else {
2454 return "native:platform"
2455 }
2456}
2457
Jiyong Park9d452992018-10-03 00:38:19 +09002458// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002459// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002460func (c *Module) IsInstallableToApex() bool {
2461 if shared, ok := c.linker.(interface {
2462 shared() bool
2463 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002464 // Stub libs and prebuilt libs in a versioned SDK are not
2465 // installable to APEX even though they are shared libs.
2466 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002467 } else if _, ok := c.linker.(testPerSrc); ok {
2468 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002469 }
2470 return false
2471}
2472
Jiyong Parka90ca002019-10-07 15:47:24 +09002473func (c *Module) AvailableFor(what string) bool {
2474 if linker, ok := c.linker.(interface {
2475 availableFor(string) bool
2476 }); ok {
2477 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2478 } else {
2479 return c.ApexModuleBase.AvailableFor(what)
2480 }
2481}
2482
Inseob Kim1f086e22019-05-09 13:29:15 +09002483func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002484 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2485
2486 // The platform variant doesn't need further condition. Apex variants however might not
2487 // be installable because it will likely to be included in the APEX and won't appear
2488 // in the system partition.
2489 if c.IsForPlatform() {
2490 return ret
2491 }
2492
2493 // Special case for modules that are configured to be installed to /data, which includes
2494 // test modules. For these modules, both APEX and non-APEX variants are considered as
2495 // installable. This is because even the APEX variants won't be included in the APEX, but
2496 // will anyway be installed to /data/*.
2497 // See b/146995717
2498 if c.InstallInData() {
2499 return ret
2500 }
2501
2502 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002503}
2504
Jiyong Park83dc74b2020-01-14 18:38:44 +09002505func (c *Module) AllStaticDeps() []string {
2506 return c.allStaticDeps
2507}
2508
Logan Chien41eabe62019-04-10 13:33:58 +08002509func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2510 if c.linker != nil {
2511 if library, ok := c.linker.(*libraryDecorator); ok {
2512 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2513 }
2514 }
2515}
2516
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002517func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002518 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2519 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002520 // dynamic dep to a stubs lib crosses APEX boundary
2521 return false
2522 }
2523 }
2524 return true
2525}
2526
Colin Cross2ba19d92015-05-07 15:44:20 -07002527//
Colin Crosscfad1192015-11-02 16:43:11 -08002528// Defaults
2529//
Colin Crossca860ac2016-01-04 14:34:37 -08002530type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002531 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002532 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002533 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002534}
2535
Patrice Arrudac249c712019-03-19 17:00:29 -07002536// cc_defaults provides a set of properties that can be inherited by other cc
2537// modules. A module can use the properties from a cc_defaults using
2538// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2539// merged (when possible) by prepending the default module's values to the
2540// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002541func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002542 return DefaultsFactory()
2543}
2544
Colin Cross36242852017-06-23 15:06:31 -07002545func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002546 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002547
Colin Cross36242852017-06-23 15:06:31 -07002548 module.AddProperties(props...)
2549 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002550 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002551 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002552 &BaseCompilerProperties{},
2553 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002554 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002555 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002556 &StaticProperties{},
2557 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002558 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002559 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002560 &TestProperties{},
2561 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002562 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002563 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002564 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002565 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002566 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002567 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002568 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002569 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002570 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002571 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002572 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002573 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002574 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002575 )
Colin Crosscfad1192015-11-02 16:43:11 -08002576
Jooyung Hancc372c52019-09-25 15:18:44 +09002577 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002578
2579 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002580}
2581
Jiyong Park6a43f042017-10-12 23:05:00 +09002582func squashVendorSrcs(m *Module) {
2583 if lib, ok := m.compiler.(*libraryDecorator); ok {
2584 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2585 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2586
2587 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2588 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2589 }
2590}
2591
Jiyong Parkf9332f12018-02-01 00:54:12 +09002592func squashRecoverySrcs(m *Module) {
2593 if lib, ok := m.compiler.(*libraryDecorator); ok {
2594 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2595 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2596
2597 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2598 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2599 }
2600}
2601
Colin Cross7228ecd2019-11-18 16:00:16 -08002602var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002603
Colin Cross7228ecd2019-11-18 16:00:16 -08002604func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002605 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002606 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002607 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002608
2609 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002610 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002611 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002612 }
Logan Chienf3511742017-10-31 18:04:35 +08002613
2614 if vndkdep := m.vndkdep; vndkdep != nil {
2615 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002616 if productSpecific {
2617 mctx.PropertyErrorf("product_specific",
2618 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002619 }
Logan Chienf3511742017-10-31 18:04:35 +08002620 if vendorSpecific {
2621 if !vndkdep.isVndkExt() {
2622 mctx.PropertyErrorf("vndk",
2623 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002624 }
2625 } else {
2626 if vndkdep.isVndkExt() {
2627 mctx.PropertyErrorf("vndk",
2628 "must set `vendor: true` to set `extends: %q`",
2629 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002630 }
2631 if m.VendorProperties.Vendor_available == nil {
2632 mctx.PropertyErrorf("vndk",
2633 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002634 }
2635 }
2636 } else {
2637 if vndkdep.isVndkSp() {
2638 mctx.PropertyErrorf("vndk",
2639 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002640 }
2641 if vndkdep.isVndkExt() {
2642 mctx.PropertyErrorf("vndk",
2643 "must set `enabled: true` to set `extends: %q`",
2644 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002645 }
Justin Yun8effde42017-06-23 19:24:43 +09002646 }
2647 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002648
Jiyong Parkf9332f12018-02-01 00:54:12 +09002649 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002650 var recoveryVariantNeeded bool = false
2651
Inseob Kim64c43952019-08-26 16:52:35 +09002652 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002653 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002654
2655 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002656 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2657 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2658 if boardVndkVersion == "current" {
2659 boardVndkVersion = platformVndkVersion
2660 }
2661 if productVndkVersion == "current" {
2662 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002663 }
2664
Justin Yun5f7f7e82019-11-18 19:52:14 +09002665 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002666 // If the device isn't compiling against the VNDK, we always
2667 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002668 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002669 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002670 // LL-NDK stubs only exist in the vendor and product variants,
2671 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002672 vendorVariants = append(vendorVariants,
2673 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002674 boardVndkVersion,
2675 )
2676 productVariants = append(productVariants,
2677 platformVndkVersion,
2678 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002679 )
Jiyong Park2a454122017-10-19 15:59:33 +09002680 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2681 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002682 vendorVariants = append(vendorVariants,
2683 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002684 boardVndkVersion,
2685 )
2686 productVariants = append(productVariants,
2687 platformVndkVersion,
2688 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002689 )
2690 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002691 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2692 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002693 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002694 } else if m.HasVendorVariant() && !vendorSpecific {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002695 // This will be available in /system, /vendor and /product
2696 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002697 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002698 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002699 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002700 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2701 // code is PLATFORM_VNDK_VERSION.
2702 // On the other hand, vendor_available modules which are not VNDK should
2703 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002704 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002705 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002706 vendorVariants = append(vendorVariants, boardVndkVersion)
2707 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002708 }
Logan Chienf3511742017-10-31 18:04:35 +08002709 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002710 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002711 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002712 } else {
2713 // This is either in /system (or similar: /data), or is a
2714 // modules built with the NDK. Modules built with the NDK
2715 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002716 coreVariantNeeded = true
2717 }
2718
Justin Yun5f7f7e82019-11-18 19:52:14 +09002719 if boardVndkVersion != "" && productVndkVersion != "" {
2720 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2721 // The module has "product_specific: true" that does not create core variant.
2722 coreVariantNeeded = false
2723 productVariants = append(productVariants, productVndkVersion)
2724 }
2725 } else {
2726 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2727 // restriction to use system libs.
2728 // No product variants defined in this case.
2729 productVariants = []string{}
2730 }
2731
Jiyong Parkf9332f12018-02-01 00:54:12 +09002732 if Bool(m.Properties.Recovery_available) {
2733 recoveryVariantNeeded = true
2734 }
2735
2736 if m.ModuleBase.InstallInRecovery() {
2737 recoveryVariantNeeded = true
2738 coreVariantNeeded = false
2739 }
2740
Inseob Kim64c43952019-08-26 16:52:35 +09002741 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002742 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2743 }
2744
2745 for _, variant := range android.FirstUniqueStrings(productVariants) {
2746 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002747 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002748
2749 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2750 m.Properties.CoreVariantNeeded = coreVariantNeeded
2751}
2752
2753func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2754 return c.Properties.CoreVariantNeeded
2755}
2756
2757func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2758 return c.Properties.RecoveryVariantNeeded
2759}
2760
2761func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002762 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002763}
2764
2765func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2766 m := module.(*Module)
2767 if variant == android.RecoveryVariation {
2768 m.MakeAsPlatform()
2769 squashRecoverySrcs(m)
2770 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002771 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08002772 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2773 squashVendorSrcs(m)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002774 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
2775 m.Properties.ImageVariationPrefix = ProductVariationPrefix
2776 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
2777 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002778 }
2779}
2780
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002781func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002782 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002783 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2784 }
Colin Cross6510f912017-11-29 00:27:14 -08002785 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002786}
2787
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002788func kytheExtractAllFactory() android.Singleton {
2789 return &kytheExtractAllSingleton{}
2790}
2791
2792type kytheExtractAllSingleton struct {
2793}
2794
2795func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2796 var xrefTargets android.Paths
2797 ctx.VisitAllModules(func(module android.Module) {
2798 if ccModule, ok := module.(xref); ok {
2799 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2800 }
2801 })
2802 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2803 if len(xrefTargets) > 0 {
2804 ctx.Build(pctx, android.BuildParams{
2805 Rule: blueprint.Phony,
2806 Output: android.PathForPhony(ctx, "xref_cxx"),
2807 Inputs: xrefTargets,
2808 //Default: true,
2809 })
2810 }
2811}
2812
Colin Cross06a931b2015-10-28 17:23:31 -07002813var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002814var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002815var BoolPtr = proptools.BoolPtr
2816var String = proptools.String
2817var StringPtr = proptools.StringPtr