blob: 14e71226e1be32439543a2350e51ddc0251944e1 [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
Inseob Kim64c43952019-08-26 16:52:35 +0900218 VndkVersion string `blueprint:"mutated"`
219 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800220
221 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
222 // file
223 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900224
225 // Make this module available when building for recovery
226 Recovery_available *bool
227
Colin Crossae6c5202019-11-20 13:35:50 -0800228 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800229 CoreVariantNeeded bool `blueprint:"mutated"`
230 RecoveryVariantNeeded bool `blueprint:"mutated"`
231 VendorVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900232
233 // Allows this module to use non-APEX version of libraries. Useful
234 // for building binaries that are started before APEXes are activated.
235 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900236
237 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
238 // see soong/cc/config/vndk.go
239 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700240}
241
242type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900243 // whether this module should be allowed to be directly depended by other
244 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
245 // If set to true, two variants will be built separately, one like
246 // normal, and the other limited to the set of libraries and headers
247 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700248 //
249 // The vendor variant may be used with a different (newer) /system,
250 // so it shouldn't have any unversioned runtime dependencies, or
251 // make assumptions about the system that may not be true in the
252 // future.
253 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900254 // If set to false, this module becomes inaccessible from /vendor modules.
255 //
256 // Default value is true when vndk: {enabled: true} or vendor: true.
257 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700258 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
259 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900260
261 // whether this module is capable of being loaded with other instance
262 // (possibly an older version) of the same module in the same process.
263 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
264 // can be double loaded in a vendor process if the library is also a
265 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
266 // explicitly marked as `double_loadable: true` by the owner, or the dependency
267 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
268 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800269}
270
Colin Crossca860ac2016-01-04 14:34:37 -0800271type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800272 static() bool
273 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900274 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700275 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700276 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800277 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700278 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800279 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900280 isLlndk(config android.Config) bool
281 isLlndkPublic(config android.Config) bool
282 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900283 isVndk() bool
284 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800285 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900286 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800287 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700288 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700289 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800290 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800291 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800292 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800293 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800294 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900295 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900296 hasStubsVariants() bool
297 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900298 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800299 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700300 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800301}
302
303type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700304 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800305 ModuleContextIntf
306}
307
308type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700309 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800310 ModuleContextIntf
311}
312
Colin Cross37047f12016-12-13 17:06:13 -0800313type DepsContext interface {
314 android.BottomUpMutatorContext
315 ModuleContextIntf
316}
317
Colin Crossca860ac2016-01-04 14:34:37 -0800318type feature interface {
319 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800320 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800321 flags(ctx ModuleContext, flags Flags) Flags
322 props() []interface{}
323}
324
325type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700326 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800327 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800328 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700329 compilerProps() []interface{}
330
Colin Cross76fada02016-07-27 10:31:13 -0700331 appendCflags([]string)
332 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700333 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800334}
335
336type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700337 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800338 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700339 linkerFlags(ctx ModuleContext, flags Flags) Flags
340 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800341 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700342
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700343 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700344 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900345 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700346
347 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900348 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800349}
350
351type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700352 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700353 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800354 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700355 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700356 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900357 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800358}
359
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800360type xref interface {
361 XrefCcFiles() android.Paths
362}
363
Colin Crossc99deeb2016-04-11 15:06:20 -0700364var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700365 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
366 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
367 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
368 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
369 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
370 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
371 headerDepTag = DependencyTag{Name: "header", Library: true}
372 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
373 genSourceDepTag = DependencyTag{Name: "gen source"}
374 genHeaderDepTag = DependencyTag{Name: "gen header"}
375 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
376 objDepTag = DependencyTag{Name: "obj"}
377 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
378 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
379 reuseObjTag = DependencyTag{Name: "reuse objects"}
380 staticVariantTag = DependencyTag{Name: "static variant"}
381 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
382 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
383 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
384 runtimeDepTag = DependencyTag{Name: "runtime lib"}
385 coverageDepTag = DependencyTag{Name: "coverage"}
386 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700387)
388
Roland Levillainf89cd092019-07-29 16:22:59 +0100389func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700390 ccDepTag, ok := depTag.(DependencyTag)
391 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100392}
393
394func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700395 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100396 return ok && ccDepTag == runtimeDepTag
397}
398
399func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700400 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100401 return ok && ccDepTag == testPerSrcDepTag
402}
403
Colin Crossca860ac2016-01-04 14:34:37 -0800404// Module contains the properties and members used by all C/C++ module types, and implements
405// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
406// to construct the output file. Behavior can be customized with a Customizer interface
407type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700408 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700409 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900410 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900411 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700412
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700413 Properties BaseProperties
414 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700415
Colin Crossca860ac2016-01-04 14:34:37 -0800416 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700417 hod android.HostOrDeviceSupported
418 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700419
Colin Crossca860ac2016-01-04 14:34:37 -0800420 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700421 features []feature
422 compiler compiler
423 linker linker
424 installer installer
425 stl *stl
426 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800427 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800428 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900429 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700430 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700431 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800432 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800433
434 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700435
Colin Cross635c3b02016-05-18 15:37:25 -0700436 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800437
Colin Crossb98c8b02016-07-29 13:44:28 -0700438 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700439
440 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800441
442 // Flags used to compile this module
443 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700444
445 // 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 -0800446 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700447 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800448 depsInLinkOrder android.Paths
449
450 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700451 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900452
453 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800454 // Kythe (source file indexer) paths for this compilation module
455 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700456}
457
Ivan Lozano52767be2019-10-18 14:49:46 -0700458func (c *Module) Toc() android.OptionalPath {
459 if c.linker != nil {
460 if library, ok := c.linker.(libraryInterface); ok {
461 return library.toc()
462 }
463 }
464 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
465}
466
467func (c *Module) ApiLevel() string {
468 if c.linker != nil {
469 if stub, ok := c.linker.(*stubDecorator); ok {
470 return stub.properties.ApiLevel
471 }
472 }
473 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
474}
475
476func (c *Module) Static() bool {
477 if c.linker != nil {
478 if library, ok := c.linker.(libraryInterface); ok {
479 return library.static()
480 }
481 }
482 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
483}
484
485func (c *Module) Shared() bool {
486 if c.linker != nil {
487 if library, ok := c.linker.(libraryInterface); ok {
488 return library.shared()
489 }
490 }
491 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
492}
493
494func (c *Module) SelectedStl() string {
495 return c.stl.Properties.SelectedStl
496}
497
498func (c *Module) ToolchainLibrary() bool {
499 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
500 return true
501 }
502 return false
503}
504
505func (c *Module) NdkPrebuiltStl() bool {
506 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
507 return true
508 }
509 return false
510}
511
512func (c *Module) StubDecorator() bool {
513 if _, ok := c.linker.(*stubDecorator); ok {
514 return true
515 }
516 return false
517}
518
519func (c *Module) SdkVersion() string {
520 return String(c.Properties.Sdk_version)
521}
522
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800523func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700524 if c.linker != nil {
525 if library, ok := c.linker.(exportedFlagsProducer); ok {
526 return library.exportedDirs()
527 }
528 }
529 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
530}
531
532func (c *Module) HasStaticVariant() bool {
533 if c.staticVariant != nil {
534 return true
535 }
536 return false
537}
538
539func (c *Module) GetStaticVariant() LinkableInterface {
540 return c.staticVariant
541}
542
543func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
544 c.depsInLinkOrder = depsInLinkOrder
545}
546
547func (c *Module) GetDepsInLinkOrder() []android.Path {
548 return c.depsInLinkOrder
549}
550
551func (c *Module) StubsVersions() []string {
552 if c.linker != nil {
553 if library, ok := c.linker.(*libraryDecorator); ok {
554 return library.Properties.Stubs.Versions
555 }
556 }
557 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
558}
559
560func (c *Module) CcLibrary() bool {
561 if c.linker != nil {
562 if _, ok := c.linker.(*libraryDecorator); ok {
563 return true
564 }
565 }
566 return false
567}
568
569func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700570 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700571 return true
572 }
573 return false
574}
575
Ivan Lozano2b262972019-11-21 12:30:50 -0800576func (c *Module) NonCcVariants() bool {
577 return false
578}
579
Ivan Lozano183a3212019-10-18 14:18:45 -0700580func (c *Module) SetBuildStubs() {
581 if c.linker != nil {
582 if library, ok := c.linker.(*libraryDecorator); ok {
583 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700584 c.Properties.HideFromMake = true
585 c.sanitize = nil
586 c.stl = nil
587 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700588 return
589 }
590 }
591 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
592}
593
Ivan Lozano52767be2019-10-18 14:49:46 -0700594func (c *Module) BuildStubs() bool {
595 if c.linker != nil {
596 if library, ok := c.linker.(*libraryDecorator); ok {
597 return library.buildStubs()
598 }
599 }
600 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
601}
602
Ivan Lozano183a3212019-10-18 14:18:45 -0700603func (c *Module) SetStubsVersions(version string) {
604 if c.linker != nil {
605 if library, ok := c.linker.(*libraryDecorator); ok {
606 library.MutatedProperties.StubsVersion = version
607 return
608 }
609 }
610 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
611}
612
613func (c *Module) SetStatic() {
614 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700615 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700616 library.setStatic()
617 return
618 }
619 }
620 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
621}
622
623func (c *Module) SetShared() {
624 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700625 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700626 library.setShared()
627 return
628 }
629 }
630 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
631}
632
633func (c *Module) BuildStaticVariant() bool {
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 return library.buildStatic()
637 }
638 }
639 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
640}
641
642func (c *Module) BuildSharedVariant() bool {
643 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700644 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700645 return library.buildShared()
646 }
647 }
648 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
649}
650
651func (c *Module) Module() android.Module {
652 return c
653}
654
Jiyong Parkc20eee32018-09-05 22:36:17 +0900655func (c *Module) OutputFile() android.OptionalPath {
656 return c.outputFile
657}
658
Ivan Lozano183a3212019-10-18 14:18:45 -0700659var _ LinkableInterface = (*Module)(nil)
660
Jiyong Park719b4462019-01-13 00:39:51 +0900661func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900662 if c.linker != nil {
663 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900664 }
665 return nil
666}
667
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900668func (c *Module) CoverageOutputFile() android.OptionalPath {
669 if c.linker != nil {
670 return c.linker.coverageOutputFilePath()
671 }
672 return android.OptionalPath{}
673}
674
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900675func (c *Module) RelativeInstallPath() string {
676 if c.installer != nil {
677 return c.installer.relativeInstallPath()
678 }
679 return ""
680}
681
Jooyung Han344d5432019-08-23 11:17:39 +0900682func (c *Module) VndkVersion() string {
683 return c.vndkVersion()
684}
685
Colin Cross36242852017-06-23 15:06:31 -0700686func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700687 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800688 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700689 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800690 }
691 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700692 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800693 }
694 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700695 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800696 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700697 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700698 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700699 }
Colin Cross16b23492016-01-06 14:41:07 -0800700 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700701 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800702 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800703 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700704 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800705 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800706 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700707 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800708 }
Justin Yun8effde42017-06-23 19:24:43 +0900709 if c.vndkdep != nil {
710 c.AddProperties(c.vndkdep.props()...)
711 }
Stephen Craneba090d12017-05-09 15:44:35 -0700712 if c.lto != nil {
713 c.AddProperties(c.lto.props()...)
714 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700715 if c.pgo != nil {
716 c.AddProperties(c.pgo.props()...)
717 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800718 if c.xom != nil {
719 c.AddProperties(c.xom.props()...)
720 }
Colin Crossca860ac2016-01-04 14:34:37 -0800721 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700722 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800723 }
Colin Crossc472d572015-03-17 15:06:21 -0700724
Colin Crossa9d8bee2018-10-02 13:59:46 -0700725 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
726 switch class {
727 case android.Device:
728 return ctx.Config().DevicePrefer32BitExecutables()
729 case android.HostCross:
730 // Windows builds always prefer 32-bit
731 return true
732 default:
733 return false
734 }
735 })
Colin Cross36242852017-06-23 15:06:31 -0700736 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900737 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900738 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900739 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900740
Colin Cross36242852017-06-23 15:06:31 -0700741 return c
Colin Crossc472d572015-03-17 15:06:21 -0700742}
743
Colin Crossb916a382016-07-29 17:28:03 -0700744// Returns true for dependency roots (binaries)
745// TODO(ccross): also handle dlopenable libraries
746func (c *Module) isDependencyRoot() bool {
747 if root, ok := c.linker.(interface {
748 isDependencyRoot() bool
749 }); ok {
750 return root.isDependencyRoot()
751 }
752 return false
753}
754
Ivan Lozano52767be2019-10-18 14:49:46 -0700755func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900756 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700757}
758
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800759func (c *Module) isCoverageVariant() bool {
760 return c.coverage.Properties.IsCoverageVariant
761}
762
Peter Collingbournead84f972019-12-17 16:46:18 -0800763func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800764 return inList(c.Name(), ndkMigratedLibs)
765}
766
Inseob Kim9516ee92019-05-09 10:56:13 +0900767func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800768 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900769 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800770}
771
Inseob Kim9516ee92019-05-09 10:56:13 +0900772func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800773 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900774 name := c.BaseModuleName()
775 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800776}
777
Inseob Kim9516ee92019-05-09 10:56:13 +0900778func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800779 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900780 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800781}
782
Ivan Lozano52767be2019-10-18 14:49:46 -0700783func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800784 if vndkdep := c.vndkdep; vndkdep != nil {
785 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900786 }
787 return false
788}
789
Jooyung Han76106d92019-05-20 18:49:10 +0900790func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900791 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900792}
793
Yi Kong7e53c572018-02-14 18:16:12 +0800794func (c *Module) isPgoCompile() bool {
795 if pgo := c.pgo; pgo != nil {
796 return pgo.Properties.PgoCompile
797 }
798 return false
799}
800
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800801func (c *Module) isNDKStubLibrary() bool {
802 if _, ok := c.compiler.(*stubDecorator); ok {
803 return true
804 }
805 return false
806}
807
Logan Chienf3511742017-10-31 18:04:35 +0800808func (c *Module) isVndkSp() bool {
809 if vndkdep := c.vndkdep; vndkdep != nil {
810 return vndkdep.isVndkSp()
811 }
812 return false
813}
814
815func (c *Module) isVndkExt() bool {
816 if vndkdep := c.vndkdep; vndkdep != nil {
817 return vndkdep.isVndkExt()
818 }
819 return false
820}
821
Ivan Lozano52767be2019-10-18 14:49:46 -0700822func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900823 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800824}
825
Logan Chienf3511742017-10-31 18:04:35 +0800826func (c *Module) getVndkExtendsModuleName() string {
827 if vndkdep := c.vndkdep; vndkdep != nil {
828 return vndkdep.getVndkExtendsModuleName()
829 }
830 return ""
831}
832
Jiyong Park82e2bf32017-08-16 14:05:54 +0900833// Returns true only when this module is configured to have core and vendor
834// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700835func (c *Module) HasVendorVariant() bool {
836 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900837}
838
Ivan Lozano52767be2019-10-18 14:49:46 -0700839func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800840 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900841}
842
Ivan Lozano52767be2019-10-18 14:49:46 -0700843func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900844 return c.ModuleBase.InstallInRecovery()
845}
846
Jiyong Park25fc6a92018-11-18 18:02:45 +0900847func (c *Module) IsStubs() bool {
848 if library, ok := c.linker.(*libraryDecorator); ok {
849 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900850 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
851 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900852 }
853 return false
854}
855
856func (c *Module) HasStubsVariants() bool {
857 if library, ok := c.linker.(*libraryDecorator); ok {
858 return len(library.Properties.Stubs.Versions) > 0
859 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700860 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
861 return len(library.Properties.Stubs.Versions) > 0
862 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900863 return false
864}
865
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900866func (c *Module) bootstrap() bool {
867 return Bool(c.Properties.Bootstrap)
868}
869
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700870func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700871 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
872 if c.Target().NativeBridge == android.NativeBridgeEnabled {
873 return false
874 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700875 return c.linker != nil && c.linker.nativeCoverage()
876}
877
Jiyong Park73c54ee2019-10-22 20:31:18 +0900878func (c *Module) ExportedIncludeDirs() android.Paths {
879 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
880 return flagsProducer.exportedDirs()
881 }
Jiyong Park232e7852019-11-04 12:23:40 +0900882 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900883}
884
885func (c *Module) ExportedSystemIncludeDirs() android.Paths {
886 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
887 return flagsProducer.exportedSystemDirs()
888 }
Jiyong Park232e7852019-11-04 12:23:40 +0900889 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900890}
891
892func (c *Module) ExportedFlags() []string {
893 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
894 return flagsProducer.exportedFlags()
895 }
Jiyong Park232e7852019-11-04 12:23:40 +0900896 return nil
897}
898
899func (c *Module) ExportedDeps() android.Paths {
900 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
901 return flagsProducer.exportedDeps()
902 }
903 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900904}
905
Inseob Kimd110f872019-12-06 13:15:38 +0900906func (c *Module) ExportedGeneratedHeaders() android.Paths {
907 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
908 return flagsProducer.exportedGeneratedHeaders()
909 }
910 return nil
911}
912
Jiyong Parkf1194352019-02-25 11:05:47 +0900913func isBionic(name string) bool {
914 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000915 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900916 return true
917 }
918 return false
919}
920
Martin Stjernholm279de572019-09-10 23:18:20 +0100921func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700922 if name == "libclang_rt.hwasan-aarch64-android" {
923 return inList("hwaddress", config.SanitizeDevice())
924 }
925 return isBionic(name)
926}
927
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800928func (c *Module) XrefCcFiles() android.Paths {
929 return c.kytheFiles
930}
931
Colin Crossca860ac2016-01-04 14:34:37 -0800932type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700933 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800934 moduleContextImpl
935}
936
Colin Cross37047f12016-12-13 17:06:13 -0800937type depsContext struct {
938 android.BottomUpMutatorContext
939 moduleContextImpl
940}
941
Colin Crossca860ac2016-01-04 14:34:37 -0800942type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700943 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800944 moduleContextImpl
945}
946
Jiyong Park2db76922017-11-08 16:03:48 +0900947func (ctx *moduleContext) SocSpecific() bool {
948 return ctx.ModuleContext.SocSpecific() ||
Ivan Lozano52767be2019-10-18 14:49:46 -0700949 (ctx.mod.HasVendorVariant() && ctx.mod.UseVndk() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700950}
951
Colin Crossca860ac2016-01-04 14:34:37 -0800952type moduleContextImpl struct {
953 mod *Module
954 ctx BaseModuleContext
955}
956
Colin Crossb98c8b02016-07-29 13:44:28 -0700957func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800958 return ctx.mod.toolchain(ctx.ctx)
959}
960
961func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000962 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800963}
964
965func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900966 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800967}
968
Jiyong Park1d1119f2019-07-29 21:27:18 +0900969func (ctx *moduleContextImpl) header() bool {
970 return ctx.mod.header()
971}
972
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700973func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800974 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800975 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700976 }
977 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800978}
979
980func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700981 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700982 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900983 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700984 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900985 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
986 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
987 return "current"
988 }
989 return platform_vndk_ver
990 }
991 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800992 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900993 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700994 }
995 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800996}
997
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700998func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700999 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001000}
Justin Yun8effde42017-06-23 19:24:43 +09001001
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001002func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001003 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001004}
1005
Inseob Kim9516ee92019-05-09 10:56:13 +09001006func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1007 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001008}
1009
Inseob Kim9516ee92019-05-09 10:56:13 +09001010func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1011 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001012}
1013
Inseob Kim9516ee92019-05-09 10:56:13 +09001014func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1015 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001016}
1017
Logan Chienf3511742017-10-31 18:04:35 +08001018func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001019 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001020}
1021
Yi Kong7e53c572018-02-14 18:16:12 +08001022func (ctx *moduleContextImpl) isPgoCompile() bool {
1023 return ctx.mod.isPgoCompile()
1024}
1025
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001026func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1027 return ctx.mod.isNDKStubLibrary()
1028}
1029
Justin Yun8effde42017-06-23 19:24:43 +09001030func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001031 return ctx.mod.isVndkSp()
1032}
1033
1034func (ctx *moduleContextImpl) isVndkExt() bool {
1035 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001036}
1037
Vic Yangefd249e2018-11-12 20:19:56 -08001038func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001039 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001040}
1041
Jiyong Parkf9332f12018-02-01 00:54:12 +09001042func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001043 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001044}
1045
Logan Chien2f2b8902018-07-10 15:01:19 +08001046// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001047func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001048 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1049 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001050 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001051
1052 if ctx.ctx.Fuchsia() {
1053 return false
1054 }
1055
Logan Chien2f2b8902018-07-10 15:01:19 +08001056 if sanitize := ctx.mod.sanitize; sanitize != nil {
1057 if !sanitize.isVariantOnProductionDevice() {
1058 return false
1059 }
1060 }
1061 if !ctx.ctx.Device() {
1062 // Host modules do not need ABI dumps.
1063 return false
1064 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001065 if ctx.isStubs() {
1066 // Stubs do not need ABI dumps.
1067 return false
1068 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001069 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001070}
1071
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001072func (ctx *moduleContextImpl) selectedStl() string {
1073 if stl := ctx.mod.stl; stl != nil {
1074 return stl.Properties.SelectedStl
1075 }
1076 return ""
1077}
1078
Ivan Lozanobd721262018-11-27 14:33:03 -08001079func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1080 return ctx.mod.linker.useClangLld(actx)
1081}
1082
Colin Crossce75d2c2016-10-06 16:12:58 -07001083func (ctx *moduleContextImpl) baseModuleName() string {
1084 return ctx.mod.ModuleBase.BaseModuleName()
1085}
1086
Logan Chienf3511742017-10-31 18:04:35 +08001087func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1088 return ctx.mod.getVndkExtendsModuleName()
1089}
1090
Logan Chiene274fc92019-12-03 11:18:32 -08001091func (ctx *moduleContextImpl) isForPlatform() bool {
1092 return ctx.mod.IsForPlatform()
1093}
1094
Jiyong Park58e364a2019-01-19 19:24:06 +09001095func (ctx *moduleContextImpl) apexName() string {
1096 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001097}
1098
Jiyong Parkb0788572018-12-20 22:10:17 +09001099func (ctx *moduleContextImpl) hasStubsVariants() bool {
1100 return ctx.mod.HasStubsVariants()
1101}
1102
1103func (ctx *moduleContextImpl) isStubs() bool {
1104 return ctx.mod.IsStubs()
1105}
1106
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001107func (ctx *moduleContextImpl) bootstrap() bool {
1108 return ctx.mod.bootstrap()
1109}
1110
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001111func (ctx *moduleContextImpl) nativeCoverage() bool {
1112 return ctx.mod.nativeCoverage()
1113}
1114
Colin Cross635c3b02016-05-18 15:37:25 -07001115func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001116 return &Module{
1117 hod: hod,
1118 multilib: multilib,
1119 }
1120}
1121
Colin Cross635c3b02016-05-18 15:37:25 -07001122func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001123 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001124 module.features = []feature{
1125 &tidyFeature{},
1126 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001127 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001128 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001129 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001130 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001131 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001132 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001133 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001134 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001135 return module
1136}
1137
Colin Crossce75d2c2016-10-06 16:12:58 -07001138func (c *Module) Prebuilt() *android.Prebuilt {
1139 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1140 return p.prebuilt()
1141 }
1142 return nil
1143}
1144
1145func (c *Module) Name() string {
1146 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001147 if p, ok := c.linker.(interface {
1148 Name(string) string
1149 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001150 name = p.Name(name)
1151 }
1152 return name
1153}
1154
Alex Light3d673592019-01-18 14:37:31 -08001155func (c *Module) Symlinks() []string {
1156 if p, ok := c.installer.(interface {
1157 symlinkList() []string
1158 }); ok {
1159 return p.symlinkList()
1160 }
1161 return nil
1162}
1163
Jeff Gaston294356f2017-09-27 17:05:30 -07001164// orderDeps reorders dependencies into a list such that if module A depends on B, then
1165// A will precede B in the resultant list.
1166// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001167// Note that directSharedDeps should be the analogous static library for each shared lib dep
1168func 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 -07001169 // If A depends on B, then
1170 // Every list containing A will also contain B later in the list
1171 // So, after concatenating all lists, the final instance of B will have come from the same
1172 // original list as the final instance of A
1173 // So, the final instance of B will be later in the concatenation than the final A
1174 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1175 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001176 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001177 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001178 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1179 }
1180 for _, dep := range directSharedDeps {
1181 orderedAllDeps = append(orderedAllDeps, dep)
1182 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001183 }
1184
Colin Crossb6715442017-10-24 11:13:31 -07001185 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001186
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001187 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001188 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001189 // resultant list to only what the caller has chosen to include in directStaticDeps
1190 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001191
1192 return orderedAllDeps, orderedDeclaredDeps
1193}
1194
Ivan Lozano183a3212019-10-18 14:18:45 -07001195func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001196 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001197 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001198 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1199 staticDepFiles := []android.Path{}
1200 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001201 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1202 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001203 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001204 sharedDepFiles := []android.Path{}
1205 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001206 if sharedDep.HasStaticVariant() {
1207 staticAnalogue := sharedDep.GetStaticVariant()
1208 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1209 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001210 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001211 }
1212
1213 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001214 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1215 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001216
1217 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001218}
1219
Roland Levillainf89cd092019-07-29 16:22:59 +01001220func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1221 test, ok := c.linker.(testPerSrc)
1222 return ok && test.isAllTestsVariation()
1223}
1224
Colin Cross635c3b02016-05-18 15:37:25 -07001225func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001226 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001227 //
1228 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1229 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1230 // module and return early, as this module does not produce an output file per se.
1231 if c.IsTestPerSrcAllTestsVariation() {
1232 c.outputFile = android.OptionalPath{}
1233 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001234 }
1235
Jooyung Han38002912019-05-16 04:01:54 +09001236 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001237
Inseob Kim64c43952019-08-26 16:52:35 +09001238 c.Properties.SubName = ""
1239
1240 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1241 c.Properties.SubName += nativeBridgeSuffix
1242 }
1243
1244 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1245 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1246 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1247 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001248 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.UseVndk() && c.HasVendorVariant()) {
Inseob Kim64c43952019-08-26 16:52:35 +09001249 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1250 // The suffix is not added for vendor-only module.
1251 c.Properties.SubName += vendorSuffix
1252 vendorVersion := actx.DeviceConfig().VndkVersion()
1253 if vendorVersion == "current" {
1254 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1255 }
1256 if c.Properties.VndkVersion != vendorVersion {
1257 c.Properties.SubName += "." + c.Properties.VndkVersion
1258 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001259 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001260 c.Properties.SubName += recoverySuffix
1261 }
1262
Colin Crossca860ac2016-01-04 14:34:37 -08001263 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001264 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001265 moduleContextImpl: moduleContextImpl{
1266 mod: c,
1267 },
1268 }
1269 ctx.ctx = ctx
1270
Colin Crossf18e1102017-11-16 14:33:08 -08001271 deps := c.depsToPaths(ctx)
1272 if ctx.Failed() {
1273 return
1274 }
1275
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001276 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1277 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1278 }
1279
Colin Crossca860ac2016-01-04 14:34:37 -08001280 flags := Flags{
1281 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001282 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001283 }
Colin Crossca860ac2016-01-04 14:34:37 -08001284 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001285 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001286 }
1287 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001288 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001289 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001290 if c.stl != nil {
1291 flags = c.stl.flags(ctx, flags)
1292 }
Colin Cross16b23492016-01-06 14:41:07 -08001293 if c.sanitize != nil {
1294 flags = c.sanitize.flags(ctx, flags)
1295 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001296 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001297 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001298 }
Stephen Craneba090d12017-05-09 15:44:35 -07001299 if c.lto != nil {
1300 flags = c.lto.flags(ctx, flags)
1301 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001302 if c.pgo != nil {
1303 flags = c.pgo.flags(ctx, flags)
1304 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001305 if c.xom != nil {
1306 flags = c.xom.flags(ctx, flags)
1307 }
Colin Crossca860ac2016-01-04 14:34:37 -08001308 for _, feature := range c.features {
1309 flags = feature.flags(ctx, flags)
1310 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001311 if ctx.Failed() {
1312 return
1313 }
1314
Colin Cross4af21ed2019-11-04 09:37:55 -08001315 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1316 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1317 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001318
Colin Cross4af21ed2019-11-04 09:37:55 -08001319 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001320
1321 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001322 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001323 }
1324 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001325 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001326 }
1327
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001328 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001329 // We need access to all the flags seen by a source file.
1330 if c.sabi != nil {
1331 flags = c.sabi.flags(ctx, flags)
1332 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001333
Colin Cross4af21ed2019-11-04 09:37:55 -08001334 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001335
Colin Crossca860ac2016-01-04 14:34:37 -08001336 // Optimization to reduce size of build.ninja
1337 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001338 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1339 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1340 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1341 flags.Local.CFlags = []string{"$cflags"}
1342 flags.Local.CppFlags = []string{"$cppflags"}
1343 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001344
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001345 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001346 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001347 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001348 if ctx.Failed() {
1349 return
1350 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001351 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001352 }
1353
Colin Crossca860ac2016-01-04 14:34:37 -08001354 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001355 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001356 if ctx.Failed() {
1357 return
1358 }
Colin Cross635c3b02016-05-18 15:37:25 -07001359 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001360
1361 // If a lib is directly included in any of the APEXes, unhide the stubs
1362 // variant having the latest version gets visible to make. In addition,
1363 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1364 // force anything in the make world to link against the stubs library.
1365 // (unless it is explicitly referenced via .bootstrap suffix or the
1366 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001367 if c.HasStubsVariants() &&
1368 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001369 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001370 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001371 c.Properties.HideFromMake = false // unhide
1372 // Note: this is still non-installable
1373 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001374 }
Colin Cross5049f022015-03-18 13:28:46 -07001375
Inseob Kim1f086e22019-05-09 13:29:15 +09001376 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001377 c.installer.install(ctx, c.outputFile.Path())
1378 if ctx.Failed() {
1379 return
Colin Crossca860ac2016-01-04 14:34:37 -08001380 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001381 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001382}
1383
Colin Cross0ea8ba82019-06-06 14:33:29 -07001384func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001385 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001386 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001387 }
Colin Crossca860ac2016-01-04 14:34:37 -08001388 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001389}
1390
Colin Crossca860ac2016-01-04 14:34:37 -08001391func (c *Module) begin(ctx BaseModuleContext) {
1392 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001393 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001394 }
Colin Crossca860ac2016-01-04 14:34:37 -08001395 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001396 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001397 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001398 if c.stl != nil {
1399 c.stl.begin(ctx)
1400 }
Colin Cross16b23492016-01-06 14:41:07 -08001401 if c.sanitize != nil {
1402 c.sanitize.begin(ctx)
1403 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001404 if c.coverage != nil {
1405 c.coverage.begin(ctx)
1406 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001407 if c.sabi != nil {
1408 c.sabi.begin(ctx)
1409 }
Justin Yun8effde42017-06-23 19:24:43 +09001410 if c.vndkdep != nil {
1411 c.vndkdep.begin(ctx)
1412 }
Stephen Craneba090d12017-05-09 15:44:35 -07001413 if c.lto != nil {
1414 c.lto.begin(ctx)
1415 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001416 if c.pgo != nil {
1417 c.pgo.begin(ctx)
1418 }
Colin Crossca860ac2016-01-04 14:34:37 -08001419 for _, feature := range c.features {
1420 feature.begin(ctx)
1421 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001422 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001423 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001424 if err != nil {
1425 ctx.PropertyErrorf("sdk_version", err.Error())
1426 }
Nan Zhang0007d812017-11-07 10:57:05 -08001427 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001428 }
Colin Crossca860ac2016-01-04 14:34:37 -08001429}
1430
Colin Cross37047f12016-12-13 17:06:13 -08001431func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001432 deps := Deps{}
1433
1434 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001435 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001436 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001437 // Add the PGO dependency (the clang_rt.profile runtime library), which
1438 // sometimes depends on symbols from libgcc, before libgcc gets added
1439 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001440 if c.pgo != nil {
1441 deps = c.pgo.deps(ctx, deps)
1442 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001443 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001444 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001445 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001446 if c.stl != nil {
1447 deps = c.stl.deps(ctx, deps)
1448 }
Colin Cross16b23492016-01-06 14:41:07 -08001449 if c.sanitize != nil {
1450 deps = c.sanitize.deps(ctx, deps)
1451 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001452 if c.coverage != nil {
1453 deps = c.coverage.deps(ctx, deps)
1454 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001455 if c.sabi != nil {
1456 deps = c.sabi.deps(ctx, deps)
1457 }
Justin Yun8effde42017-06-23 19:24:43 +09001458 if c.vndkdep != nil {
1459 deps = c.vndkdep.deps(ctx, deps)
1460 }
Stephen Craneba090d12017-05-09 15:44:35 -07001461 if c.lto != nil {
1462 deps = c.lto.deps(ctx, deps)
1463 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001464 for _, feature := range c.features {
1465 deps = feature.deps(ctx, deps)
1466 }
1467
Colin Crossb6715442017-10-24 11:13:31 -07001468 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1469 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1470 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1471 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1472 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1473 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001474 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001475
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001476 for _, lib := range deps.ReexportSharedLibHeaders {
1477 if !inList(lib, deps.SharedLibs) {
1478 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1479 }
1480 }
1481
1482 for _, lib := range deps.ReexportStaticLibHeaders {
1483 if !inList(lib, deps.StaticLibs) {
1484 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1485 }
1486 }
1487
Colin Cross5950f382016-12-13 12:50:57 -08001488 for _, lib := range deps.ReexportHeaderLibHeaders {
1489 if !inList(lib, deps.HeaderLibs) {
1490 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1491 }
1492 }
1493
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001494 for _, gen := range deps.ReexportGeneratedHeaders {
1495 if !inList(gen, deps.GeneratedHeaders) {
1496 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1497 }
1498 }
1499
Colin Crossc99deeb2016-04-11 15:06:20 -07001500 return deps
1501}
1502
Dan Albert7e9d2952016-08-04 13:02:36 -07001503func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001504 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001505 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001506 moduleContextImpl: moduleContextImpl{
1507 mod: c,
1508 },
1509 }
1510 ctx.ctx = ctx
1511
Colin Crossca860ac2016-01-04 14:34:37 -08001512 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001513}
1514
Jiyong Park7ed9de32018-10-15 22:25:07 +09001515// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001516func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001517 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1518 version := name[sharp+1:]
1519 libname := name[:sharp]
1520 return libname, version
1521 }
1522 return name, ""
1523}
1524
Colin Cross1e676be2016-10-12 14:38:15 -07001525func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001526 ctx := &depsContext{
1527 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001528 moduleContextImpl: moduleContextImpl{
1529 mod: c,
1530 },
1531 }
1532 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001533
Colin Crossc99deeb2016-04-11 15:06:20 -07001534 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001535
Dan Albert914449f2016-06-17 16:45:24 -07001536 variantNdkLibs := []string{}
1537 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001538 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001539 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001540
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001541 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1542 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001543 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001544 // 1. Name of an NDK library that refers to a prebuilt module.
1545 // For each of these, it adds the name of the prebuilt module (which will be in
1546 // prebuilts/ndk) to the list of nonvariant libs.
1547 // 2. Name of an NDK library that refers to an ndk_library module.
1548 // For each of these, it adds the name of the ndk_library module to the list of
1549 // variant libs.
1550 // 3. Anything else (so anything that isn't an NDK library).
1551 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001552 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001553 // The caller can then know to add the variantLibs dependencies differently from the
1554 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001555
Inseob Kim9516ee92019-05-09 10:56:13 +09001556 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001557 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1558 variantLibs = []string{}
1559 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001560 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001561 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001562 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001563 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1564 if !inList(name, ndkMigratedLibs) {
1565 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001566 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001567 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001568 }
Jooyung Han0302a842019-10-30 18:43:49 +09001569 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001570 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001571 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001572 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001573 if actx.OtherModuleExists(vendorPublicLib) {
1574 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1575 } else {
1576 // This can happen if vendor_public_library module is defined in a
1577 // namespace that isn't visible to the current module. In that case,
1578 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001579 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001580 }
Dan Albert914449f2016-06-17 16:45:24 -07001581 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001582 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001583 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001584 }
1585 }
Dan Albert914449f2016-06-17 16:45:24 -07001586 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001587 }
1588
Dan Albert914449f2016-06-17 16:45:24 -07001589 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1590 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001591 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001592 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001593
Jiyong Park7e636d02019-01-28 16:16:54 +09001594 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001595 if c.linker != nil {
1596 if library, ok := c.linker.(*libraryDecorator); ok {
1597 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001598 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001599 }
1600 }
1601 }
1602
Colin Cross32ec36c2016-12-15 07:39:51 -08001603 for _, lib := range deps.HeaderLibs {
1604 depTag := headerDepTag
1605 if inList(lib, deps.ReexportHeaderLibHeaders) {
1606 depTag = headerExportDepTag
1607 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001608 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001609 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001610 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001611 } else {
1612 actx.AddVariationDependencies(nil, depTag, lib)
1613 }
1614 }
1615
1616 if buildStubs {
1617 // Stubs lib does not have dependency to other static/shared libraries.
1618 // Don't proceed.
1619 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001620 }
Colin Cross5950f382016-12-13 12:50:57 -08001621
Inseob Kimc0907f12019-02-08 21:00:45 +09001622 syspropImplLibraries := syspropImplLibraries(actx.Config())
1623
Jiyong Park5d1598f2019-02-25 22:14:17 +09001624 for _, lib := range deps.WholeStaticLibs {
1625 depTag := wholeStaticDepTag
1626 if impl, ok := syspropImplLibraries[lib]; ok {
1627 lib = impl
1628 }
1629 actx.AddVariationDependencies([]blueprint.Variation{
1630 {Mutator: "link", Variation: "static"},
1631 }, depTag, lib)
1632 }
1633
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001634 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001635 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001636 if inList(lib, deps.ReexportStaticLibHeaders) {
1637 depTag = staticExportDepTag
1638 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001639
1640 if impl, ok := syspropImplLibraries[lib]; ok {
1641 lib = impl
1642 }
1643
Dan Willemsen59339a22018-07-22 21:18:45 -07001644 actx.AddVariationDependencies([]blueprint.Variation{
1645 {Mutator: "link", Variation: "static"},
1646 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001647 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001648
Dan Willemsen59339a22018-07-22 21:18:45 -07001649 actx.AddVariationDependencies([]blueprint.Variation{
1650 {Mutator: "link", Variation: "static"},
1651 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001652
Ivan Lozano183a3212019-10-18 14:18:45 -07001653 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001654 var variations []blueprint.Variation
1655 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001656 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001657 if version != "" && versionVariantAvail {
1658 // Version is explicitly specified. i.e. libFoo#30
1659 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001660 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001661 }
1662 actx.AddVariationDependencies(variations, depTag, name)
1663
1664 // If the version is not specified, add dependency to the latest stubs library.
1665 // The stubs library will be used when the depending module is built for APEX and
1666 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001667 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001668 if version == "" && latestVersion != "" && versionVariantAvail {
1669 actx.AddVariationDependencies([]blueprint.Variation{
1670 {Mutator: "link", Variation: "shared"},
1671 {Mutator: "version", Variation: latestVersion},
1672 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001673 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001674 }
1675 }
1676
Jiyong Park7ed9de32018-10-15 22:25:07 +09001677 // shared lib names without the #version suffix
1678 var sharedLibNames []string
1679
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001680 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001681 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001682 if inList(lib, deps.ReexportSharedLibHeaders) {
1683 depTag = sharedExportDepTag
1684 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001685
1686 if impl, ok := syspropImplLibraries[lib]; ok {
1687 lib = impl
1688 }
1689
Jiyong Park73c54ee2019-10-22 20:31:18 +09001690 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001691 sharedLibNames = append(sharedLibNames, name)
1692
Jiyong Park25fc6a92018-11-18 18:02:45 +09001693 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001694 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001695
Jiyong Park7ed9de32018-10-15 22:25:07 +09001696 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001697 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001698 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1699 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1700 // linking against both the stubs lib and the non-stubs lib at the same time.
1701 continue
1702 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001703 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001704 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001705
Dan Willemsen59339a22018-07-22 21:18:45 -07001706 actx.AddVariationDependencies([]blueprint.Variation{
1707 {Mutator: "link", Variation: "shared"},
1708 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001709
Colin Cross68861832016-07-08 10:41:41 -07001710 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001711
1712 for _, gen := range deps.GeneratedHeaders {
1713 depTag := genHeaderDepTag
1714 if inList(gen, deps.ReexportGeneratedHeaders) {
1715 depTag = genHeaderExportDepTag
1716 }
1717 actx.AddDependency(c, depTag, gen)
1718 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001719
Colin Cross42d48b72018-08-29 14:10:52 -07001720 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001721
1722 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001723 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001724 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001725 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001726 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001727 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001728 if deps.LinkerFlagsFile != "" {
1729 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1730 }
1731 if deps.DynamicLinker != "" {
1732 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001733 }
Dan Albert914449f2016-06-17 16:45:24 -07001734
1735 version := ctx.sdkVersion()
1736 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001737 {Mutator: "ndk_api", Variation: version},
1738 {Mutator: "link", Variation: "shared"},
1739 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001740 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001741 {Mutator: "ndk_api", Variation: version},
1742 {Mutator: "link", Variation: "shared"},
1743 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001744
1745 if vndkdep := c.vndkdep; vndkdep != nil {
1746 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001747 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001748 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001749 {Mutator: "link", Variation: "shared"},
1750 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001751 }
1752 }
Colin Cross6362e272015-10-29 15:25:03 -07001753}
Colin Cross21b9a242015-03-24 14:15:58 -07001754
Colin Crosse40b4ea2018-10-02 22:25:58 -07001755func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001756 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1757 c.beginMutator(ctx)
1758 }
1759}
1760
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001761// Whether a module can link to another module, taking into
1762// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001763func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1764 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001765 // Host code is not restricted
1766 return
1767 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001768
1769 // VNDK is cc.Module supported only for now.
1770 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001771 // Though vendor code is limited by the vendor mutator,
1772 // each vendor-available module needs to check
1773 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001774 if ccTo, ok := to.(*Module); ok {
1775 if ccFrom.vndkdep != nil {
1776 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1777 }
1778 } else {
1779 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001780 }
1781 return
1782 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001783 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001784 // Platform code can link to anything
1785 return
1786 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001787 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001788 // Recovery code is not NDK
1789 return
1790 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001791 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001792 // These are always allowed
1793 return
1794 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001795 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001796 // These are allowed, but they don't set sdk_version
1797 return
1798 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001799 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001800 // These aren't real libraries, but are the stub shared libraries that are included in
1801 // the NDK.
1802 return
1803 }
Logan Chien834b9a62019-01-14 15:39:03 +08001804
Ivan Lozano52767be2019-10-18 14:49:46 -07001805 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001806 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1807 // to link to libc++ (non-NDK and without sdk_version).
1808 return
1809 }
1810
Ivan Lozano52767be2019-10-18 14:49:46 -07001811 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001812 // NDK code linking to platform code is never okay.
1813 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001814 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001815 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001816 }
1817
1818 // At this point we know we have two NDK libraries, but we need to
1819 // check that we're not linking against anything built against a higher
1820 // API level, as it is only valid to link against older or equivalent
1821 // APIs.
1822
Inseob Kim01a28722018-04-11 09:48:45 +09001823 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001824 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001825 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001826 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001827 // Current can't be linked against by anything else.
1828 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001829 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001830 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001831 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001832 if err != nil {
1833 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001834 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001835 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001836 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001837 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001838 if err != nil {
1839 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001840 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001841 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001842 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001843
Inseob Kim01a28722018-04-11 09:48:45 +09001844 if toApi > fromApi {
1845 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001846 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001847 }
1848 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001849 }
Dan Albert202fe492017-12-15 13:56:59 -08001850
1851 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001852 fromStl := from.SelectedStl()
1853 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001854 if fromStl == "" || toStl == "" {
1855 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001856 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001857 // We can be permissive with the system "STL" since it is only the C++
1858 // ABI layer, but in the future we should make sure that everyone is
1859 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001860 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001861 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001862 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1863 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001864 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865}
1866
Jiyong Park5fb8c102018-04-09 12:03:06 +09001867// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001868// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1869// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001870// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001871func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1872 check := func(child, parent android.Module) bool {
1873 to, ok := child.(*Module)
1874 if !ok {
1875 // follow thru cc.Defaults, etc.
1876 return true
1877 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001878
Jooyung Hana70f0672019-01-18 15:20:43 +09001879 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1880 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001881 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001882
1883 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001884 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001885 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001886 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001887
Jooyung Han0302a842019-10-30 18:43:49 +09001888 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001889 return false
1890 }
1891
1892 var stringPath []string
1893 for _, m := range ctx.GetWalkPath() {
1894 stringPath = append(stringPath, m.Name())
1895 }
1896 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1897 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1898 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1899 return false
1900 }
1901 if module, ok := ctx.Module().(*Module); ok {
1902 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001903 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001904 ctx.WalkDeps(check)
1905 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001906 }
1907 }
1908}
1909
Colin Crossc99deeb2016-04-11 15:06:20 -07001910// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001911func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001912 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001913
Ivan Lozano183a3212019-10-18 14:18:45 -07001914 directStaticDeps := []LinkableInterface{}
1915 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001916
Inseob Kim9516ee92019-05-09 10:56:13 +09001917 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1918
Inseob Kim69378442019-06-03 19:10:47 +09001919 reexportExporter := func(exporter exportedFlagsProducer) {
1920 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1921 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1922 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1923 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09001924 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09001925 }
1926
Colin Crossd11fcda2017-10-23 17:59:01 -07001927 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001928 depName := ctx.OtherModuleName(dep)
1929 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001930
Ivan Lozano52767be2019-10-18 14:49:46 -07001931 ccDep, ok := dep.(LinkableInterface)
1932 if !ok {
1933
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001934 // handling for a few module types that aren't cc Module but that are also supported
1935 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001936 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001937 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001938 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1939 genRule.GeneratedSourceFiles()...)
1940 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001941 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001942 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001943 // Support exported headers from a generated_sources dependency
1944 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001945 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001946 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001947 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09001948 genRule.GeneratedSourceFiles()...)
1949 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001950 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09001951 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09001952 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001953 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001954 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09001955 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
1956 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09001957 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001958 // 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 +09001959 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001960
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001961 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001962 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001963 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001964 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001965 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001966 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001967 files := genRule.GeneratedSourceFiles()
1968 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001969 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001970 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001971 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 -07001972 }
1973 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001974 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001975 }
Colin Crossca860ac2016-01-04 14:34:37 -08001976 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001977 return
1978 }
1979
Colin Crossfe17f6f2019-03-28 19:30:56 -07001980 if depTag == android.ProtoPluginDepTag {
1981 return
1982 }
1983
Colin Crossd11fcda2017-10-23 17:59:01 -07001984 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001985 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1986 return
1987 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001988 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001989 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001990 return
1991 }
1992
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001993 // re-exporting flags
1994 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001995 // reusing objects only make sense for cc.Modules.
1996 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001997 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07001998 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001999 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002000 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002001 return
2002 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002003 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002004
Jiyong Parke4bb9862019-02-01 00:31:10 +09002005 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002006 // staticVariants are a cc.Module specific concept.
2007 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002008 c.staticVariant = ccDep
2009 return
2010 }
2011 }
2012
Ivan Lozano183a3212019-10-18 14:18:45 -07002013 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2014 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2015 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002016 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002017 if t, ok := depTag.(DependencyTag); ok {
2018 explicitlyVersioned = t.ExplicitlyVersioned
2019 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002020 depTag = t
2021 }
2022
Ivan Lozano183a3212019-10-18 14:18:45 -07002023 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002024 depIsStatic := false
2025 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002026 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002027 depIsStatic = true
2028 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002029 if ccDep.CcLibrary() && !depIsStatic {
2030 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002031 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002032 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002033 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002034
2035 var useThisDep bool
2036 if depIsStubs && explicitlyVersioned {
2037 // Always respect dependency to the versioned stubs (i.e. libX#10)
2038 useThisDep = true
2039 } else if !depHasStubs {
2040 // Use non-stub variant if that is the only choice
2041 // (i.e. depending on a lib without stubs.version property)
2042 useThisDep = true
2043 } else if c.IsForPlatform() {
2044 // If not building for APEX, use stubs only when it is from
2045 // an APEX (and not from platform)
2046 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002047 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002048 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002049 // always link to non-stub variant
2050 useThisDep = !depIsStubs
2051 }
2052 } else {
2053 // If building for APEX, use stubs only when it is not from
2054 // the same APEX
2055 useThisDep = (depInSameApex != depIsStubs)
2056 }
2057
2058 if !useThisDep {
2059 return // stop processing this dep
2060 }
2061 }
2062
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002063 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2064
Ivan Lozano52767be2019-10-18 14:49:46 -07002065 // Exporting flags only makes sense for cc.Modules
2066 if _, ok := ccDep.(*Module); ok {
2067 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002068 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002069 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2070 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002071 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002072
Ivan Lozano52767be2019-10-18 14:49:46 -07002073 if t.ReexportFlags {
2074 reexportExporter(i)
2075 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2076 // Re-exported shared library headers must be included as well since they can help us with type information
2077 // about template instantiations (instantiated from their headers).
2078 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2079 // scripts.
2080 c.sabi.Properties.ReexportedIncludes = append(
2081 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2082 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002083 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002084 }
Logan Chienf3511742017-10-31 18:04:35 +08002085 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002086 }
2087
Colin Cross26c34ed2016-09-30 17:10:16 -07002088 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002089 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002090
Ivan Lozano52767be2019-10-18 14:49:46 -07002091 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002092 depFile := android.OptionalPath{}
2093
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002094 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002095 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002096 ptr = &depPaths.SharedLibs
2097 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002098 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002099 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002100
Jiyong Park64a44f22019-01-18 14:37:08 +09002101 case earlySharedDepTag:
2102 ptr = &depPaths.EarlySharedLibs
2103 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002104 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002105 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002106 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002107 ptr = &depPaths.LateSharedLibs
2108 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002109 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002110 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002111 ptr = nil
2112 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002113 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002114 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002115 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002116 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002117 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002118 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002119 return
2120 }
2121
Ivan Lozano52767be2019-10-18 14:49:46 -07002122 // Because the static library objects are included, this only makes sense
2123 // in the context of proper cc.Modules.
2124 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2125 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2126 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2127 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2128 for i := range missingDeps {
2129 missingDeps[i] += postfix
2130 }
2131 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002132 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002133 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2134 } else {
2135 ctx.ModuleErrorf(
2136 "non-cc.Modules cannot be included as whole static libraries.", depName)
2137 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002138 }
Colin Cross5950f382016-12-13 12:50:57 -08002139 case headerDepTag:
2140 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002141 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002142 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002143 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002144 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002145 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002146 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002147 case dynamicLinkerDepTag:
2148 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002149 }
2150
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002152 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002153 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002155 return
2156 }
2157
2158 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002159 // in static libraries act as if they were whole static libraries. The same goes for
2160 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002161 // This should only be done for cc.Modules
2162 if c, ok := ccDep.(*Module); ok {
2163 staticLib := c.linker.(libraryInterface)
2164 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2165 staticLib.objs().coverageFiles...)
2166 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2167 staticLib.objs().sAbiDumpFiles...)
2168 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002169 }
2170
Colin Cross26c34ed2016-09-30 17:10:16 -07002171 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002172 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002173 if !ctx.Config().AllowMissingDependencies() {
2174 ctx.ModuleErrorf("module %q missing output file", depName)
2175 } else {
2176 ctx.AddMissingDependencies([]string{depName})
2177 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002178 return
2179 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002180 *ptr = append(*ptr, linkFile.Path())
2181 }
2182
Colin Crossc99deeb2016-04-11 15:06:20 -07002183 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002184 dep := depFile
2185 if !dep.Valid() {
2186 dep = linkFile
2187 }
2188 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002189 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002190
Logan Chien43d34c32017-12-20 01:17:32 +08002191 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002192 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002193 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002194 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002195 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002196 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002198
Ivan Lozano52767be2019-10-18 14:49:46 -07002199 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002200 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2201 // core module instead.
2202 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002203 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002204 // The vendor module in Make will have been renamed to not conflict with the core
2205 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09002206 ret := libName + vendorSuffix
2207 vendorVersion := ctx.DeviceConfig().VndkVersion()
2208 if vendorVersion == "current" {
2209 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
2210 }
2211 if c.Properties.VndkVersion != vendorVersion {
2212 ret += "." + c.Properties.VndkVersion
2213 }
2214 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09002215 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002216 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002217 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002218 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002219 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002220 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002221 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002222 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002223 }
Logan Chien43d34c32017-12-20 01:17:32 +08002224 }
2225
2226 // Export the shared libs to Make.
2227 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002228 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002229 if ccDep.CcLibrary() {
2230 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002231 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002232 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002233 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002234 c.Properties.ApexesProvidingSharedLibs = append(
2235 c.Properties.ApexesProvidingSharedLibs, an)
2236 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002237 }
2238 }
2239
Jiyong Park27b188b2017-07-18 13:23:39 +09002240 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002241 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002242 c.Properties.AndroidMkSharedLibs = append(
2243 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002244 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002245 c.Properties.AndroidMkSharedLibs = append(
2246 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002247 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002248 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002249 c.Properties.AndroidMkStaticLibs = append(
2250 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002251 case runtimeDepTag:
2252 c.Properties.AndroidMkRuntimeLibs = append(
2253 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002254 case wholeStaticDepTag:
2255 c.Properties.AndroidMkWholeStaticLibs = append(
2256 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002257 }
Colin Crossca860ac2016-01-04 14:34:37 -08002258 })
2259
Jeff Gaston294356f2017-09-27 17:05:30 -07002260 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002261 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002262
Colin Crossdd84e052017-05-17 13:44:16 -07002263 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002264 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002265 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2266 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002267 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002268 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002269 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2270 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002271 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002272 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002273 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002274
2275 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002276 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002277 }
Colin Crossdd84e052017-05-17 13:44:16 -07002278
Colin Crossca860ac2016-01-04 14:34:37 -08002279 return depPaths
2280}
2281
2282func (c *Module) InstallInData() bool {
2283 if c.installer == nil {
2284 return false
2285 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002286 return c.installer.inData()
2287}
2288
2289func (c *Module) InstallInSanitizerDir() bool {
2290 if c.installer == nil {
2291 return false
2292 }
2293 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002294 return true
2295 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002296 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002297}
2298
Jiyong Parkf9332f12018-02-01 00:54:12 +09002299func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002300 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002301}
2302
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002303func (c *Module) HostToolPath() android.OptionalPath {
2304 if c.installer == nil {
2305 return android.OptionalPath{}
2306 }
2307 return c.installer.hostToolPath()
2308}
2309
Nan Zhangd4e641b2017-07-12 12:55:28 -07002310func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2311 return c.outputFile
2312}
2313
Colin Cross41955e82019-05-29 14:40:35 -07002314func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2315 switch tag {
2316 case "":
2317 if c.outputFile.Valid() {
2318 return android.Paths{c.outputFile.Path()}, nil
2319 }
2320 return android.Paths{}, nil
2321 default:
2322 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002323 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002324}
2325
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002326func (c *Module) static() bool {
2327 if static, ok := c.linker.(interface {
2328 static() bool
2329 }); ok {
2330 return static.static()
2331 }
2332 return false
2333}
2334
Jiyong Park379de2f2018-12-19 02:47:14 +09002335func (c *Module) staticBinary() bool {
2336 if static, ok := c.linker.(interface {
2337 staticBinary() bool
2338 }); ok {
2339 return static.staticBinary()
2340 }
2341 return false
2342}
2343
Jiyong Park1d1119f2019-07-29 21:27:18 +09002344func (c *Module) header() bool {
2345 if h, ok := c.linker.(interface {
2346 header() bool
2347 }); ok {
2348 return h.header()
2349 }
2350 return false
2351}
2352
Jooyung Han38002912019-05-16 04:01:54 +09002353func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002354 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002355 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2356 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002357 return "native:vndk"
2358 }
Jooyung Han38002912019-05-16 04:01:54 +09002359 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002360 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002361 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002362 if Bool(c.VendorProperties.Vendor_available) {
2363 return "native:vndk"
2364 }
2365 return "native:vndk_private"
2366 }
2367 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002368 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002369 return "native:recovery"
2370 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2371 return "native:ndk:none:none"
2372 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2373 //family, link := getNdkStlFamilyAndLinkType(c)
2374 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002375 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002376 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002377 } else {
2378 return "native:platform"
2379 }
2380}
2381
Jiyong Park9d452992018-10-03 00:38:19 +09002382// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002383// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002384func (c *Module) IsInstallableToApex() bool {
2385 if shared, ok := c.linker.(interface {
2386 shared() bool
2387 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002388 // Stub libs and prebuilt libs in a versioned SDK are not
2389 // installable to APEX even though they are shared libs.
2390 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002391 } else if _, ok := c.linker.(testPerSrc); ok {
2392 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002393 }
2394 return false
2395}
2396
Jiyong Parka90ca002019-10-07 15:47:24 +09002397func (c *Module) AvailableFor(what string) bool {
2398 if linker, ok := c.linker.(interface {
2399 availableFor(string) bool
2400 }); ok {
2401 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2402 } else {
2403 return c.ApexModuleBase.AvailableFor(what)
2404 }
2405}
2406
Inseob Kim1f086e22019-05-09 13:29:15 +09002407func (c *Module) installable() bool {
2408 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2409}
2410
bralee3f49f4d2019-03-04 06:58:15 +08002411func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002412 outputFiles, err := c.OutputFiles("")
2413 if err != nil {
2414 panic(err)
2415 }
2416 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002417}
2418
Logan Chien41eabe62019-04-10 13:33:58 +08002419func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2420 if c.linker != nil {
2421 if library, ok := c.linker.(*libraryDecorator); ok {
2422 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2423 }
2424 }
2425}
2426
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002427func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002428 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2429 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002430 // dynamic dep to a stubs lib crosses APEX boundary
2431 return false
2432 }
2433 }
2434 return true
2435}
2436
Colin Cross2ba19d92015-05-07 15:44:20 -07002437//
Colin Crosscfad1192015-11-02 16:43:11 -08002438// Defaults
2439//
Colin Crossca860ac2016-01-04 14:34:37 -08002440type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002441 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002442 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002443 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002444}
2445
Patrice Arrudac249c712019-03-19 17:00:29 -07002446// cc_defaults provides a set of properties that can be inherited by other cc
2447// modules. A module can use the properties from a cc_defaults using
2448// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2449// merged (when possible) by prepending the default module's values to the
2450// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002451func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002452 return DefaultsFactory()
2453}
2454
Colin Cross36242852017-06-23 15:06:31 -07002455func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002456 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002457
Colin Cross36242852017-06-23 15:06:31 -07002458 module.AddProperties(props...)
2459 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002460 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002461 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002462 &BaseCompilerProperties{},
2463 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002464 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002465 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002466 &StaticProperties{},
2467 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002468 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002469 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002470 &TestProperties{},
2471 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002472 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002473 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002474 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002475 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002476 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002477 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002478 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002479 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002480 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002481 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002482 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002483 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002484 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002485 )
Colin Crosscfad1192015-11-02 16:43:11 -08002486
Jooyung Hancc372c52019-09-25 15:18:44 +09002487 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002488
2489 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002490}
2491
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002492const (
Colin Cross7228ecd2019-11-18 16:00:16 -08002493 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002494 // against the VNDK.
Colin Cross7228ecd2019-11-18 16:00:16 -08002495 VendorVariationPrefix = "vendor."
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002496)
2497
Jiyong Park6a43f042017-10-12 23:05:00 +09002498func squashVendorSrcs(m *Module) {
2499 if lib, ok := m.compiler.(*libraryDecorator); ok {
2500 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2501 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2502
2503 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2504 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2505 }
2506}
2507
Jiyong Parkf9332f12018-02-01 00:54:12 +09002508func squashRecoverySrcs(m *Module) {
2509 if lib, ok := m.compiler.(*libraryDecorator); ok {
2510 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2511 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2512
2513 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2514 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2515 }
2516}
2517
Colin Cross7228ecd2019-11-18 16:00:16 -08002518var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002519
Colin Cross7228ecd2019-11-18 16:00:16 -08002520func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002521 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002522 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002523 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002524
2525 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002526 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002527 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002528 }
Logan Chienf3511742017-10-31 18:04:35 +08002529
2530 if vndkdep := m.vndkdep; vndkdep != nil {
2531 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002532 if productSpecific {
2533 mctx.PropertyErrorf("product_specific",
2534 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002535 }
Logan Chienf3511742017-10-31 18:04:35 +08002536 if vendorSpecific {
2537 if !vndkdep.isVndkExt() {
2538 mctx.PropertyErrorf("vndk",
2539 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002540 }
2541 } else {
2542 if vndkdep.isVndkExt() {
2543 mctx.PropertyErrorf("vndk",
2544 "must set `vendor: true` to set `extends: %q`",
2545 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002546 }
2547 if m.VendorProperties.Vendor_available == nil {
2548 mctx.PropertyErrorf("vndk",
2549 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002550 }
2551 }
2552 } else {
2553 if vndkdep.isVndkSp() {
2554 mctx.PropertyErrorf("vndk",
2555 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002556 }
2557 if vndkdep.isVndkExt() {
2558 mctx.PropertyErrorf("vndk",
2559 "must set `enabled: true` to set `extends: %q`",
2560 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002561 }
Justin Yun8effde42017-06-23 19:24:43 +09002562 }
2563 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002564
Jiyong Parkf9332f12018-02-01 00:54:12 +09002565 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002566 var recoveryVariantNeeded bool = false
2567
Inseob Kim64c43952019-08-26 16:52:35 +09002568 var vendorVariants []string
2569
2570 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2571 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2572 if deviceVndkVersion == "current" {
2573 deviceVndkVersion = platformVndkVersion
2574 }
2575
Justin Yun71549282017-11-17 12:10:28 +09002576 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002577 // If the device isn't compiling against the VNDK, we always
2578 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002579 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002580 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2581 // LL-NDK stubs only exist in the vendor variant, since the
2582 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002583 vendorVariants = append(vendorVariants,
2584 platformVndkVersion,
2585 deviceVndkVersion,
2586 )
Jiyong Park2a454122017-10-19 15:59:33 +09002587 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2588 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002589 vendorVariants = append(vendorVariants,
2590 platformVndkVersion,
2591 deviceVndkVersion,
2592 )
2593 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002594 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2595 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002596 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002597 } else if m.HasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002598 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002599 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002600 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002601 vendorVariants = append(vendorVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002602 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2603 // code is PLATFORM_VNDK_VERSION.
2604 // On the other hand, vendor_available modules which are not VNDK should
2605 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
2606 if !m.IsVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002607 vendorVariants = append(vendorVariants, deviceVndkVersion)
2608 }
Logan Chienf3511742017-10-31 18:04:35 +08002609 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002610 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002611 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002612 } else {
2613 // This is either in /system (or similar: /data), or is a
2614 // modules built with the NDK. Modules built with the NDK
2615 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002616 coreVariantNeeded = true
2617 }
2618
2619 if Bool(m.Properties.Recovery_available) {
2620 recoveryVariantNeeded = true
2621 }
2622
2623 if m.ModuleBase.InstallInRecovery() {
2624 recoveryVariantNeeded = true
2625 coreVariantNeeded = false
2626 }
2627
Inseob Kim64c43952019-08-26 16:52:35 +09002628 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Colin Cross7228ecd2019-11-18 16:00:16 -08002629 m.Properties.VendorVariants = append(m.Properties.VendorVariants, VendorVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002630 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002631
2632 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2633 m.Properties.CoreVariantNeeded = coreVariantNeeded
2634}
2635
2636func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2637 return c.Properties.CoreVariantNeeded
2638}
2639
2640func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2641 return c.Properties.RecoveryVariantNeeded
2642}
2643
2644func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
2645 return c.Properties.VendorVariants
2646}
2647
2648func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2649 m := module.(*Module)
2650 if variant == android.RecoveryVariation {
2651 m.MakeAsPlatform()
2652 squashRecoverySrcs(m)
2653 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
2654 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2655 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002656 }
2657}
2658
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002659func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002660 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002661 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2662 }
Colin Cross6510f912017-11-29 00:27:14 -08002663 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002664}
2665
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002666func kytheExtractAllFactory() android.Singleton {
2667 return &kytheExtractAllSingleton{}
2668}
2669
2670type kytheExtractAllSingleton struct {
2671}
2672
2673func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2674 var xrefTargets android.Paths
2675 ctx.VisitAllModules(func(module android.Module) {
2676 if ccModule, ok := module.(xref); ok {
2677 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2678 }
2679 })
2680 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2681 if len(xrefTargets) > 0 {
2682 ctx.Build(pctx, android.BuildParams{
2683 Rule: blueprint.Phony,
2684 Output: android.PathForPhony(ctx, "xref_cxx"),
2685 Inputs: xrefTargets,
2686 //Default: true,
2687 })
2688 }
2689}
2690
Colin Cross06a931b2015-10-28 17:23:31 -07002691var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002692var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002693var BoolPtr = proptools.BoolPtr
2694var String = proptools.String
2695var StringPtr = proptools.StringPtr