blob: 40e0fcaa0af96110e25d636418d326cf9d20aec7 [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() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090040 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070041 ctx.BottomUp("link", LinkageMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010043 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Jiyong Park1d1119f2019-07-29 21:27:18 +090059 // cfi mutator shouldn't run before sanitizers that return true for
60 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000061 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
62 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
63
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080064 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
65 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
66
Colin Cross1e676be2016-10-12 14:38:15 -070067 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
68 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080069
Colin Cross0b908332019-06-19 23:00:20 -070070 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090071 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080072
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080073 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080074 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070075
76 ctx.TopDown("lto_deps", ltoDepsMutator)
77 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090078
79 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070080 })
Colin Crossb98c8b02016-07-29 13:44:28 -070081
Sasha Smundak2a4549e2018-11-05 16:49:08 -080082 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070083 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070084}
85
Colin Crossca860ac2016-01-04 14:34:37 -080086type Deps struct {
87 SharedLibs, LateSharedLibs []string
88 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080089 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080090 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070091
Colin Cross5950f382016-12-13 12:50:57 -080092 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070093
Colin Cross81413472016-04-11 14:37:39 -070094 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Dan Willemsenb40aab62016-04-20 14:21:14 -070096 GeneratedSources []string
97 GeneratedHeaders []string
98
Dan Willemsenb3454ab2016-09-28 17:34:58 -070099 ReexportGeneratedHeaders []string
100
Colin Cross97ba0732015-03-23 17:50:24 -0700101 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700102
103 // Used for host bionic
104 LinkerFlagsFile string
105 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900110 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700111 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900112 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700114 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700117 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800118 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700119 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700122 GeneratedSources android.Paths
123 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700124
Inseob Kim69378442019-06-03 19:10:47 +0900125 Flags []string
Jiyong Park74955042019-10-22 20:19:51 +0900126 IncludeDirs android.Paths
127 SystemIncludeDirs android.Paths
128 ReexportedDirs android.Paths
129 ReexportedSystemDirs android.Paths
Inseob Kim69378442019-06-03 19:10:47 +0900130 ReexportedFlags []string
131 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700132
Colin Cross26c34ed2016-09-30 17:10:16 -0700133 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700134 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700135
136 // Path to the file container flags to use with the linker
137 LinkerFlagsFile android.OptionalPath
138
139 // Path to the dynamic linker binary
140 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700141}
142
Colin Cross4af21ed2019-11-04 09:37:55 -0800143// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
144// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
145// command line so they can be overridden by the local module flags).
146type LocalOrGlobalFlags struct {
147 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700148 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800149 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700150 CFlags []string // Flags that apply to C and C++ source files
151 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
152 ConlyFlags []string // Flags that apply to C source files
153 CppFlags []string // Flags that apply to C++ source files
154 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700155 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800156}
157
158type Flags struct {
159 Local LocalOrGlobalFlags
160 Global LocalOrGlobalFlags
161
162 aidlFlags []string // Flags that apply to aidl source files
163 rsFlags []string // Flags that apply to renderscript source files
164 libFlags []string // Flags to add libraries early to the link order
165 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
166 TidyFlags []string // Flags that apply to clang-tidy
167 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700168
Colin Crossc3199482017-03-30 15:03:04 -0700169 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800170 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700171 SystemIncludeFlags []string
172
Colin Crossb98c8b02016-07-29 13:44:28 -0700173 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700174 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800175 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800176 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800177 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800178
179 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800180 DynamicLinker string
181
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700182 CFlagsDeps android.Paths // Files depended on by compiler flags
183 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800184
Dan Willemsen98ab3112019-08-27 21:20:40 -0700185 AssemblerWithCpp bool
186 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800187
Colin Cross19878da2019-03-28 14:45:07 -0700188 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700189 protoC bool // Whether to use C instead of C++
190 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700191
192 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700193}
194
Colin Crossca860ac2016-01-04 14:34:37 -0800195// Properties used to compile all C or C++ modules
196type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700197 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800198 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700199
200 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800201 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700202
Jiyong Parkde866cb2018-12-07 23:08:36 +0900203 AndroidMkSharedLibs []string `blueprint:"mutated"`
204 AndroidMkStaticLibs []string `blueprint:"mutated"`
205 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
206 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
207 HideFromMake bool `blueprint:"mutated"`
208 PreventInstall bool `blueprint:"mutated"`
209 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700210
Inseob Kim64c43952019-08-26 16:52:35 +0900211 VndkVersion string `blueprint:"mutated"`
212 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800213
214 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
215 // file
216 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900217
218 // Make this module available when building for recovery
219 Recovery_available *bool
220
221 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900222
223 // Allows this module to use non-APEX version of libraries. Useful
224 // for building binaries that are started before APEXes are activated.
225 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900226
227 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
228 // see soong/cc/config/vndk.go
229 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700230}
231
232type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900233 // whether this module should be allowed to be directly depended by other
234 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
235 // If set to true, two variants will be built separately, one like
236 // normal, and the other limited to the set of libraries and headers
237 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700238 //
239 // The vendor variant may be used with a different (newer) /system,
240 // so it shouldn't have any unversioned runtime dependencies, or
241 // make assumptions about the system that may not be true in the
242 // future.
243 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900244 // If set to false, this module becomes inaccessible from /vendor modules.
245 //
246 // Default value is true when vndk: {enabled: true} or vendor: true.
247 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700248 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
249 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900250
251 // whether this module is capable of being loaded with other instance
252 // (possibly an older version) of the same module in the same process.
253 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
254 // can be double loaded in a vendor process if the library is also a
255 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
256 // explicitly marked as `double_loadable: true` by the owner, or the dependency
257 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
258 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800259}
260
Colin Crossca860ac2016-01-04 14:34:37 -0800261type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800262 static() bool
263 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900264 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700265 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700266 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800267 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700268 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800269 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900270 isLlndk(config android.Config) bool
271 isLlndkPublic(config android.Config) bool
272 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900273 isVndk() bool
274 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800275 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900276 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800277 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700278 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700279 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800280 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800281 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800282 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800283 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900284 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900285 hasStubsVariants() bool
286 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900287 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800288 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700289 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800290}
291
292type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700293 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800294 ModuleContextIntf
295}
296
297type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700298 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800299 ModuleContextIntf
300}
301
Colin Cross37047f12016-12-13 17:06:13 -0800302type DepsContext interface {
303 android.BottomUpMutatorContext
304 ModuleContextIntf
305}
306
Colin Crossca860ac2016-01-04 14:34:37 -0800307type feature interface {
308 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800309 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800310 flags(ctx ModuleContext, flags Flags) Flags
311 props() []interface{}
312}
313
314type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700315 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800316 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800317 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700318 compilerProps() []interface{}
319
Colin Cross76fada02016-07-27 10:31:13 -0700320 appendCflags([]string)
321 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700322 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800323}
324
325type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700326 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800327 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700328 linkerFlags(ctx ModuleContext, flags Flags) Flags
329 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800330 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700331
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700332 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700333 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900334 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700335
336 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900337 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800338}
339
340type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700341 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700342 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800343 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700344 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700345 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900346 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800347}
348
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800349type xref interface {
350 XrefCcFiles() android.Paths
351}
352
Colin Crossc99deeb2016-04-11 15:06:20 -0700353var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700354 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
355 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
356 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
357 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
358 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
359 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
360 headerDepTag = DependencyTag{Name: "header", Library: true}
361 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
362 genSourceDepTag = DependencyTag{Name: "gen source"}
363 genHeaderDepTag = DependencyTag{Name: "gen header"}
364 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
365 objDepTag = DependencyTag{Name: "obj"}
366 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
367 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
368 reuseObjTag = DependencyTag{Name: "reuse objects"}
369 staticVariantTag = DependencyTag{Name: "static variant"}
370 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
371 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
372 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
373 runtimeDepTag = DependencyTag{Name: "runtime lib"}
374 coverageDepTag = DependencyTag{Name: "coverage"}
375 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700376)
377
Roland Levillainf89cd092019-07-29 16:22:59 +0100378func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700379 ccDepTag, ok := depTag.(DependencyTag)
380 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100381}
382
383func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700384 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100385 return ok && ccDepTag == runtimeDepTag
386}
387
388func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700389 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100390 return ok && ccDepTag == testPerSrcDepTag
391}
392
Colin Crossca860ac2016-01-04 14:34:37 -0800393// Module contains the properties and members used by all C/C++ module types, and implements
394// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
395// to construct the output file. Behavior can be customized with a Customizer interface
396type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700397 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700398 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900399 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900400 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700401
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700402 Properties BaseProperties
403 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700404
Colin Crossca860ac2016-01-04 14:34:37 -0800405 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700406 hod android.HostOrDeviceSupported
407 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700408
Colin Crossca860ac2016-01-04 14:34:37 -0800409 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700410 features []feature
411 compiler compiler
412 linker linker
413 installer installer
414 stl *stl
415 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800416 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800417 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900418 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700419 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700420 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800421 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800422
423 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700424
Colin Cross635c3b02016-05-18 15:37:25 -0700425 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800426
Colin Crossb98c8b02016-07-29 13:44:28 -0700427 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700428
429 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800430
431 // Flags used to compile this module
432 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700433
434 // 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 -0800435 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700436 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800437 depsInLinkOrder android.Paths
438
439 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700440 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900441
442 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800443 // Kythe (source file indexer) paths for this compilation module
444 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700445}
446
Ivan Lozano52767be2019-10-18 14:49:46 -0700447func (c *Module) Toc() android.OptionalPath {
448 if c.linker != nil {
449 if library, ok := c.linker.(libraryInterface); ok {
450 return library.toc()
451 }
452 }
453 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
454}
455
456func (c *Module) ApiLevel() string {
457 if c.linker != nil {
458 if stub, ok := c.linker.(*stubDecorator); ok {
459 return stub.properties.ApiLevel
460 }
461 }
462 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
463}
464
465func (c *Module) Static() bool {
466 if c.linker != nil {
467 if library, ok := c.linker.(libraryInterface); ok {
468 return library.static()
469 }
470 }
471 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
472}
473
474func (c *Module) Shared() bool {
475 if c.linker != nil {
476 if library, ok := c.linker.(libraryInterface); ok {
477 return library.shared()
478 }
479 }
480 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
481}
482
483func (c *Module) SelectedStl() string {
484 return c.stl.Properties.SelectedStl
485}
486
487func (c *Module) ToolchainLibrary() bool {
488 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
489 return true
490 }
491 return false
492}
493
494func (c *Module) NdkPrebuiltStl() bool {
495 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
496 return true
497 }
498 return false
499}
500
501func (c *Module) StubDecorator() bool {
502 if _, ok := c.linker.(*stubDecorator); ok {
503 return true
504 }
505 return false
506}
507
508func (c *Module) SdkVersion() string {
509 return String(c.Properties.Sdk_version)
510}
511
512func (c *Module) IncludeDirs(ctx android.BaseModuleContext) android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700513 if c.linker != nil {
514 if library, ok := c.linker.(exportedFlagsProducer); ok {
515 return library.exportedDirs()
516 }
517 }
518 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
519}
520
521func (c *Module) HasStaticVariant() bool {
522 if c.staticVariant != nil {
523 return true
524 }
525 return false
526}
527
528func (c *Module) GetStaticVariant() LinkableInterface {
529 return c.staticVariant
530}
531
532func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
533 c.depsInLinkOrder = depsInLinkOrder
534}
535
536func (c *Module) GetDepsInLinkOrder() []android.Path {
537 return c.depsInLinkOrder
538}
539
540func (c *Module) StubsVersions() []string {
541 if c.linker != nil {
542 if library, ok := c.linker.(*libraryDecorator); ok {
543 return library.Properties.Stubs.Versions
544 }
545 }
546 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
547}
548
549func (c *Module) CcLibrary() bool {
550 if c.linker != nil {
551 if _, ok := c.linker.(*libraryDecorator); ok {
552 return true
553 }
554 }
555 return false
556}
557
558func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700559 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700560 return true
561 }
562 return false
563}
564
565func (c *Module) SetBuildStubs() {
566 if c.linker != nil {
567 if library, ok := c.linker.(*libraryDecorator); ok {
568 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700569 c.Properties.HideFromMake = true
570 c.sanitize = nil
571 c.stl = nil
572 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700573 return
574 }
575 }
576 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
577}
578
Ivan Lozano52767be2019-10-18 14:49:46 -0700579func (c *Module) BuildStubs() bool {
580 if c.linker != nil {
581 if library, ok := c.linker.(*libraryDecorator); ok {
582 return library.buildStubs()
583 }
584 }
585 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
586}
587
Ivan Lozano183a3212019-10-18 14:18:45 -0700588func (c *Module) SetStubsVersions(version string) {
589 if c.linker != nil {
590 if library, ok := c.linker.(*libraryDecorator); ok {
591 library.MutatedProperties.StubsVersion = version
592 return
593 }
594 }
595 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
596}
597
598func (c *Module) SetStatic() {
599 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700600 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700601 library.setStatic()
602 return
603 }
604 }
605 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
606}
607
608func (c *Module) SetShared() {
609 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700610 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700611 library.setShared()
612 return
613 }
614 }
615 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
616}
617
618func (c *Module) BuildStaticVariant() bool {
619 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700620 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700621 return library.buildStatic()
622 }
623 }
624 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
625}
626
627func (c *Module) BuildSharedVariant() bool {
628 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700629 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700630 return library.buildShared()
631 }
632 }
633 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
634}
635
636func (c *Module) Module() android.Module {
637 return c
638}
639
Jiyong Parkc20eee32018-09-05 22:36:17 +0900640func (c *Module) OutputFile() android.OptionalPath {
641 return c.outputFile
642}
643
Ivan Lozano183a3212019-10-18 14:18:45 -0700644var _ LinkableInterface = (*Module)(nil)
645
Jiyong Park719b4462019-01-13 00:39:51 +0900646func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900647 if c.linker != nil {
648 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900649 }
650 return nil
651}
652
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900653func (c *Module) CoverageOutputFile() android.OptionalPath {
654 if c.linker != nil {
655 return c.linker.coverageOutputFilePath()
656 }
657 return android.OptionalPath{}
658}
659
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900660func (c *Module) RelativeInstallPath() string {
661 if c.installer != nil {
662 return c.installer.relativeInstallPath()
663 }
664 return ""
665}
666
Jooyung Han344d5432019-08-23 11:17:39 +0900667func (c *Module) VndkVersion() string {
668 return c.vndkVersion()
669}
670
Colin Cross36242852017-06-23 15:06:31 -0700671func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700672 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800673 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700674 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800675 }
676 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700677 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800678 }
679 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700680 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800681 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700682 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700683 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700684 }
Colin Cross16b23492016-01-06 14:41:07 -0800685 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700686 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800687 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800688 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700689 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800690 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800691 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700692 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800693 }
Justin Yun8effde42017-06-23 19:24:43 +0900694 if c.vndkdep != nil {
695 c.AddProperties(c.vndkdep.props()...)
696 }
Stephen Craneba090d12017-05-09 15:44:35 -0700697 if c.lto != nil {
698 c.AddProperties(c.lto.props()...)
699 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700700 if c.pgo != nil {
701 c.AddProperties(c.pgo.props()...)
702 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800703 if c.xom != nil {
704 c.AddProperties(c.xom.props()...)
705 }
Colin Crossca860ac2016-01-04 14:34:37 -0800706 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700707 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800708 }
Colin Crossc472d572015-03-17 15:06:21 -0700709
Colin Crossa9d8bee2018-10-02 13:59:46 -0700710 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
711 switch class {
712 case android.Device:
713 return ctx.Config().DevicePrefer32BitExecutables()
714 case android.HostCross:
715 // Windows builds always prefer 32-bit
716 return true
717 default:
718 return false
719 }
720 })
Colin Cross36242852017-06-23 15:06:31 -0700721 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900722 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900723 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900724 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900725
Colin Cross36242852017-06-23 15:06:31 -0700726 return c
Colin Crossc472d572015-03-17 15:06:21 -0700727}
728
Colin Crossb916a382016-07-29 17:28:03 -0700729// Returns true for dependency roots (binaries)
730// TODO(ccross): also handle dlopenable libraries
731func (c *Module) isDependencyRoot() bool {
732 if root, ok := c.linker.(interface {
733 isDependencyRoot() bool
734 }); ok {
735 return root.isDependencyRoot()
736 }
737 return false
738}
739
Ivan Lozano52767be2019-10-18 14:49:46 -0700740func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900741 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700742}
743
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800744func (c *Module) isCoverageVariant() bool {
745 return c.coverage.Properties.IsCoverageVariant
746}
747
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800748func (c *Module) isNdk() bool {
749 return inList(c.Name(), ndkMigratedLibs)
750}
751
Inseob Kim9516ee92019-05-09 10:56:13 +0900752func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800753 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900754 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800755}
756
Inseob Kim9516ee92019-05-09 10:56:13 +0900757func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800758 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900759 name := c.BaseModuleName()
760 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800761}
762
Inseob Kim9516ee92019-05-09 10:56:13 +0900763func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800764 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900765 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800766}
767
Ivan Lozano52767be2019-10-18 14:49:46 -0700768func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800769 if vndkdep := c.vndkdep; vndkdep != nil {
770 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900771 }
772 return false
773}
774
Jooyung Han76106d92019-05-20 18:49:10 +0900775func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900776 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900777}
778
Yi Kong7e53c572018-02-14 18:16:12 +0800779func (c *Module) isPgoCompile() bool {
780 if pgo := c.pgo; pgo != nil {
781 return pgo.Properties.PgoCompile
782 }
783 return false
784}
785
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800786func (c *Module) isNDKStubLibrary() bool {
787 if _, ok := c.compiler.(*stubDecorator); ok {
788 return true
789 }
790 return false
791}
792
Logan Chienf3511742017-10-31 18:04:35 +0800793func (c *Module) isVndkSp() bool {
794 if vndkdep := c.vndkdep; vndkdep != nil {
795 return vndkdep.isVndkSp()
796 }
797 return false
798}
799
800func (c *Module) isVndkExt() bool {
801 if vndkdep := c.vndkdep; vndkdep != nil {
802 return vndkdep.isVndkExt()
803 }
804 return false
805}
806
Ivan Lozano52767be2019-10-18 14:49:46 -0700807func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900808 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800809}
810
Logan Chienf3511742017-10-31 18:04:35 +0800811func (c *Module) getVndkExtendsModuleName() string {
812 if vndkdep := c.vndkdep; vndkdep != nil {
813 return vndkdep.getVndkExtendsModuleName()
814 }
815 return ""
816}
817
Jiyong Park82e2bf32017-08-16 14:05:54 +0900818// Returns true only when this module is configured to have core and vendor
819// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700820func (c *Module) HasVendorVariant() bool {
821 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900822}
823
Ivan Lozano52767be2019-10-18 14:49:46 -0700824func (c *Module) InRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900825 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
826}
827
Ivan Lozano52767be2019-10-18 14:49:46 -0700828func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900829 return c.ModuleBase.InstallInRecovery()
830}
831
Jiyong Park25fc6a92018-11-18 18:02:45 +0900832func (c *Module) IsStubs() bool {
833 if library, ok := c.linker.(*libraryDecorator); ok {
834 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900835 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
836 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900837 }
838 return false
839}
840
841func (c *Module) HasStubsVariants() bool {
842 if library, ok := c.linker.(*libraryDecorator); ok {
843 return len(library.Properties.Stubs.Versions) > 0
844 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700845 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
846 return len(library.Properties.Stubs.Versions) > 0
847 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900848 return false
849}
850
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900851func (c *Module) bootstrap() bool {
852 return Bool(c.Properties.Bootstrap)
853}
854
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700855func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700856 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
857 if c.Target().NativeBridge == android.NativeBridgeEnabled {
858 return false
859 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700860 return c.linker != nil && c.linker.nativeCoverage()
861}
862
Jiyong Park73c54ee2019-10-22 20:31:18 +0900863func (c *Module) ExportedIncludeDirs() android.Paths {
864 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
865 return flagsProducer.exportedDirs()
866 }
Jiyong Park232e7852019-11-04 12:23:40 +0900867 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900868}
869
870func (c *Module) ExportedSystemIncludeDirs() android.Paths {
871 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
872 return flagsProducer.exportedSystemDirs()
873 }
Jiyong Park232e7852019-11-04 12:23:40 +0900874 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900875}
876
877func (c *Module) ExportedFlags() []string {
878 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
879 return flagsProducer.exportedFlags()
880 }
Jiyong Park232e7852019-11-04 12:23:40 +0900881 return nil
882}
883
884func (c *Module) ExportedDeps() android.Paths {
885 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
886 return flagsProducer.exportedDeps()
887 }
888 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900889}
890
Jiyong Parkf1194352019-02-25 11:05:47 +0900891func isBionic(name string) bool {
892 switch name {
Yuexi Ma31f36fb2019-11-07 18:37:18 +0000893 case "libc", "libm", "libdl", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900894 return true
895 }
896 return false
897}
898
Martin Stjernholm279de572019-09-10 23:18:20 +0100899func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700900 if name == "libclang_rt.hwasan-aarch64-android" {
901 return inList("hwaddress", config.SanitizeDevice())
902 }
903 return isBionic(name)
904}
905
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800906func (c *Module) XrefCcFiles() android.Paths {
907 return c.kytheFiles
908}
909
Colin Crossca860ac2016-01-04 14:34:37 -0800910type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700911 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800912 moduleContextImpl
913}
914
Colin Cross37047f12016-12-13 17:06:13 -0800915type depsContext struct {
916 android.BottomUpMutatorContext
917 moduleContextImpl
918}
919
Colin Crossca860ac2016-01-04 14:34:37 -0800920type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700921 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800922 moduleContextImpl
923}
924
Jiyong Park2db76922017-11-08 16:03:48 +0900925func (ctx *moduleContext) SocSpecific() bool {
926 return ctx.ModuleContext.SocSpecific() ||
Ivan Lozano52767be2019-10-18 14:49:46 -0700927 (ctx.mod.HasVendorVariant() && ctx.mod.UseVndk() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700928}
929
Colin Crossca860ac2016-01-04 14:34:37 -0800930type moduleContextImpl struct {
931 mod *Module
932 ctx BaseModuleContext
933}
934
Colin Crossb98c8b02016-07-29 13:44:28 -0700935func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800936 return ctx.mod.toolchain(ctx.ctx)
937}
938
939func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000940 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800941}
942
943func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900944 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800945}
946
Jiyong Park1d1119f2019-07-29 21:27:18 +0900947func (ctx *moduleContextImpl) header() bool {
948 return ctx.mod.header()
949}
950
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700951func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800952 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800953 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700954 }
955 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800956}
957
958func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700959 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700960 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900961 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700962 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900963 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
964 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
965 return "current"
966 }
967 return platform_vndk_ver
968 }
969 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800970 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900971 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700972 }
973 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800974}
975
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700976func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700977 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700978}
Justin Yun8effde42017-06-23 19:24:43 +0900979
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800980func (ctx *moduleContextImpl) isNdk() bool {
981 return ctx.mod.isNdk()
982}
983
Inseob Kim9516ee92019-05-09 10:56:13 +0900984func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
985 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800986}
987
Inseob Kim9516ee92019-05-09 10:56:13 +0900988func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
989 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800990}
991
Inseob Kim9516ee92019-05-09 10:56:13 +0900992func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
993 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800994}
995
Logan Chienf3511742017-10-31 18:04:35 +0800996func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700997 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +0800998}
999
Yi Kong7e53c572018-02-14 18:16:12 +08001000func (ctx *moduleContextImpl) isPgoCompile() bool {
1001 return ctx.mod.isPgoCompile()
1002}
1003
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001004func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1005 return ctx.mod.isNDKStubLibrary()
1006}
1007
Justin Yun8effde42017-06-23 19:24:43 +09001008func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001009 return ctx.mod.isVndkSp()
1010}
1011
1012func (ctx *moduleContextImpl) isVndkExt() bool {
1013 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001014}
1015
Vic Yangefd249e2018-11-12 20:19:56 -08001016func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001017 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001018}
1019
Jiyong Parkf9332f12018-02-01 00:54:12 +09001020func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001021 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001022}
1023
Logan Chien2f2b8902018-07-10 15:01:19 +08001024// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001025func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001026 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1027 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001028 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001029
1030 if ctx.ctx.Fuchsia() {
1031 return false
1032 }
1033
Logan Chien2f2b8902018-07-10 15:01:19 +08001034 if sanitize := ctx.mod.sanitize; sanitize != nil {
1035 if !sanitize.isVariantOnProductionDevice() {
1036 return false
1037 }
1038 }
1039 if !ctx.ctx.Device() {
1040 // Host modules do not need ABI dumps.
1041 return false
1042 }
Logan Chienfa478c02018-12-28 16:25:39 +08001043 if !ctx.mod.IsForPlatform() {
1044 // APEX variants do not need ABI dumps.
1045 return false
1046 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001047 if ctx.isStubs() {
1048 // Stubs do not need ABI dumps.
1049 return false
1050 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001051 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001052}
1053
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001054func (ctx *moduleContextImpl) selectedStl() string {
1055 if stl := ctx.mod.stl; stl != nil {
1056 return stl.Properties.SelectedStl
1057 }
1058 return ""
1059}
1060
Ivan Lozanobd721262018-11-27 14:33:03 -08001061func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1062 return ctx.mod.linker.useClangLld(actx)
1063}
1064
Colin Crossce75d2c2016-10-06 16:12:58 -07001065func (ctx *moduleContextImpl) baseModuleName() string {
1066 return ctx.mod.ModuleBase.BaseModuleName()
1067}
1068
Logan Chienf3511742017-10-31 18:04:35 +08001069func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1070 return ctx.mod.getVndkExtendsModuleName()
1071}
1072
Jiyong Park58e364a2019-01-19 19:24:06 +09001073func (ctx *moduleContextImpl) apexName() string {
1074 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001075}
1076
Jiyong Parkb0788572018-12-20 22:10:17 +09001077func (ctx *moduleContextImpl) hasStubsVariants() bool {
1078 return ctx.mod.HasStubsVariants()
1079}
1080
1081func (ctx *moduleContextImpl) isStubs() bool {
1082 return ctx.mod.IsStubs()
1083}
1084
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001085func (ctx *moduleContextImpl) bootstrap() bool {
1086 return ctx.mod.bootstrap()
1087}
1088
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001089func (ctx *moduleContextImpl) nativeCoverage() bool {
1090 return ctx.mod.nativeCoverage()
1091}
1092
Colin Cross635c3b02016-05-18 15:37:25 -07001093func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001094 return &Module{
1095 hod: hod,
1096 multilib: multilib,
1097 }
1098}
1099
Colin Cross635c3b02016-05-18 15:37:25 -07001100func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001101 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001102 module.features = []feature{
1103 &tidyFeature{},
1104 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001105 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001106 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001107 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001108 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001109 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001110 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001111 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001112 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001113 return module
1114}
1115
Colin Crossce75d2c2016-10-06 16:12:58 -07001116func (c *Module) Prebuilt() *android.Prebuilt {
1117 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1118 return p.prebuilt()
1119 }
1120 return nil
1121}
1122
1123func (c *Module) Name() string {
1124 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001125 if p, ok := c.linker.(interface {
1126 Name(string) string
1127 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001128 name = p.Name(name)
1129 }
1130 return name
1131}
1132
Alex Light3d673592019-01-18 14:37:31 -08001133func (c *Module) Symlinks() []string {
1134 if p, ok := c.installer.(interface {
1135 symlinkList() []string
1136 }); ok {
1137 return p.symlinkList()
1138 }
1139 return nil
1140}
1141
Jeff Gaston294356f2017-09-27 17:05:30 -07001142// orderDeps reorders dependencies into a list such that if module A depends on B, then
1143// A will precede B in the resultant list.
1144// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001145// Note that directSharedDeps should be the analogous static library for each shared lib dep
1146func 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 -07001147 // If A depends on B, then
1148 // Every list containing A will also contain B later in the list
1149 // So, after concatenating all lists, the final instance of B will have come from the same
1150 // original list as the final instance of A
1151 // So, the final instance of B will be later in the concatenation than the final A
1152 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1153 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001154 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001155 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001156 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1157 }
1158 for _, dep := range directSharedDeps {
1159 orderedAllDeps = append(orderedAllDeps, dep)
1160 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001161 }
1162
Colin Crossb6715442017-10-24 11:13:31 -07001163 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001164
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001165 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001166 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001167 // resultant list to only what the caller has chosen to include in directStaticDeps
1168 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001169
1170 return orderedAllDeps, orderedDeclaredDeps
1171}
1172
Ivan Lozano183a3212019-10-18 14:18:45 -07001173func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001174 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001175 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001176 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1177 staticDepFiles := []android.Path{}
1178 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001179 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1180 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001181 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001182 sharedDepFiles := []android.Path{}
1183 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001184 if sharedDep.HasStaticVariant() {
1185 staticAnalogue := sharedDep.GetStaticVariant()
1186 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1187 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001188 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001189 }
1190
1191 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001192 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1193 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001194
1195 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001196}
1197
Roland Levillainf89cd092019-07-29 16:22:59 +01001198func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1199 test, ok := c.linker.(testPerSrc)
1200 return ok && test.isAllTestsVariation()
1201}
1202
Colin Cross635c3b02016-05-18 15:37:25 -07001203func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001204 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001205 //
1206 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1207 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1208 // module and return early, as this module does not produce an output file per se.
1209 if c.IsTestPerSrcAllTestsVariation() {
1210 c.outputFile = android.OptionalPath{}
1211 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001212 }
1213
Jooyung Han38002912019-05-16 04:01:54 +09001214 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001215
Inseob Kim64c43952019-08-26 16:52:35 +09001216 c.Properties.SubName = ""
1217
1218 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1219 c.Properties.SubName += nativeBridgeSuffix
1220 }
1221
1222 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1223 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1224 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1225 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001226 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.UseVndk() && c.HasVendorVariant()) {
Inseob Kim64c43952019-08-26 16:52:35 +09001227 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1228 // The suffix is not added for vendor-only module.
1229 c.Properties.SubName += vendorSuffix
1230 vendorVersion := actx.DeviceConfig().VndkVersion()
1231 if vendorVersion == "current" {
1232 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1233 }
1234 if c.Properties.VndkVersion != vendorVersion {
1235 c.Properties.SubName += "." + c.Properties.VndkVersion
1236 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001237 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001238 c.Properties.SubName += recoverySuffix
1239 }
1240
Colin Crossca860ac2016-01-04 14:34:37 -08001241 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001242 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001243 moduleContextImpl: moduleContextImpl{
1244 mod: c,
1245 },
1246 }
1247 ctx.ctx = ctx
1248
Colin Crossf18e1102017-11-16 14:33:08 -08001249 deps := c.depsToPaths(ctx)
1250 if ctx.Failed() {
1251 return
1252 }
1253
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001254 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1255 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1256 }
1257
Colin Crossca860ac2016-01-04 14:34:37 -08001258 flags := Flags{
1259 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001260 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001261 }
Colin Crossca860ac2016-01-04 14:34:37 -08001262 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001263 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001264 }
1265 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001266 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001267 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001268 if c.stl != nil {
1269 flags = c.stl.flags(ctx, flags)
1270 }
Colin Cross16b23492016-01-06 14:41:07 -08001271 if c.sanitize != nil {
1272 flags = c.sanitize.flags(ctx, flags)
1273 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001274 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001275 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001276 }
Stephen Craneba090d12017-05-09 15:44:35 -07001277 if c.lto != nil {
1278 flags = c.lto.flags(ctx, flags)
1279 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001280 if c.pgo != nil {
1281 flags = c.pgo.flags(ctx, flags)
1282 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001283 if c.xom != nil {
1284 flags = c.xom.flags(ctx, flags)
1285 }
Colin Crossca860ac2016-01-04 14:34:37 -08001286 for _, feature := range c.features {
1287 flags = feature.flags(ctx, flags)
1288 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001289 if ctx.Failed() {
1290 return
1291 }
1292
Colin Cross4af21ed2019-11-04 09:37:55 -08001293 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1294 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1295 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001296
Colin Cross4af21ed2019-11-04 09:37:55 -08001297 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001298
1299 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001300 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001301 }
1302 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001303 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001304 }
1305
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001306 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001307 // We need access to all the flags seen by a source file.
1308 if c.sabi != nil {
1309 flags = c.sabi.flags(ctx, flags)
1310 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001311
Colin Cross4af21ed2019-11-04 09:37:55 -08001312 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001313
Colin Crossca860ac2016-01-04 14:34:37 -08001314 // Optimization to reduce size of build.ninja
1315 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001316 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1317 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1318 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1319 flags.Local.CFlags = []string{"$cflags"}
1320 flags.Local.CppFlags = []string{"$cppflags"}
1321 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001322
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001323 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001324 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001325 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001326 if ctx.Failed() {
1327 return
1328 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001329 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001330 }
1331
Colin Crossca860ac2016-01-04 14:34:37 -08001332 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001333 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001334 if ctx.Failed() {
1335 return
1336 }
Colin Cross635c3b02016-05-18 15:37:25 -07001337 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001338
1339 // If a lib is directly included in any of the APEXes, unhide the stubs
1340 // variant having the latest version gets visible to make. In addition,
1341 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1342 // force anything in the make world to link against the stubs library.
1343 // (unless it is explicitly referenced via .bootstrap suffix or the
1344 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001345 if c.HasStubsVariants() &&
1346 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001347 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001348 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001349 c.Properties.HideFromMake = false // unhide
1350 // Note: this is still non-installable
1351 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001352 }
Colin Cross5049f022015-03-18 13:28:46 -07001353
Inseob Kim1f086e22019-05-09 13:29:15 +09001354 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001355 c.installer.install(ctx, c.outputFile.Path())
1356 if ctx.Failed() {
1357 return
Colin Crossca860ac2016-01-04 14:34:37 -08001358 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001359 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001360}
1361
Colin Cross0ea8ba82019-06-06 14:33:29 -07001362func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001363 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001364 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001365 }
Colin Crossca860ac2016-01-04 14:34:37 -08001366 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001367}
1368
Colin Crossca860ac2016-01-04 14:34:37 -08001369func (c *Module) begin(ctx BaseModuleContext) {
1370 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001371 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001372 }
Colin Crossca860ac2016-01-04 14:34:37 -08001373 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001374 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001375 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001376 if c.stl != nil {
1377 c.stl.begin(ctx)
1378 }
Colin Cross16b23492016-01-06 14:41:07 -08001379 if c.sanitize != nil {
1380 c.sanitize.begin(ctx)
1381 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001382 if c.coverage != nil {
1383 c.coverage.begin(ctx)
1384 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001385 if c.sabi != nil {
1386 c.sabi.begin(ctx)
1387 }
Justin Yun8effde42017-06-23 19:24:43 +09001388 if c.vndkdep != nil {
1389 c.vndkdep.begin(ctx)
1390 }
Stephen Craneba090d12017-05-09 15:44:35 -07001391 if c.lto != nil {
1392 c.lto.begin(ctx)
1393 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001394 if c.pgo != nil {
1395 c.pgo.begin(ctx)
1396 }
Colin Crossca860ac2016-01-04 14:34:37 -08001397 for _, feature := range c.features {
1398 feature.begin(ctx)
1399 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001400 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001401 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001402 if err != nil {
1403 ctx.PropertyErrorf("sdk_version", err.Error())
1404 }
Nan Zhang0007d812017-11-07 10:57:05 -08001405 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001406 }
Colin Crossca860ac2016-01-04 14:34:37 -08001407}
1408
Colin Cross37047f12016-12-13 17:06:13 -08001409func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001410 deps := Deps{}
1411
1412 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001413 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001414 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001415 // Add the PGO dependency (the clang_rt.profile runtime library), which
1416 // sometimes depends on symbols from libgcc, before libgcc gets added
1417 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001418 if c.pgo != nil {
1419 deps = c.pgo.deps(ctx, deps)
1420 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001421 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001422 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001423 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001424 if c.stl != nil {
1425 deps = c.stl.deps(ctx, deps)
1426 }
Colin Cross16b23492016-01-06 14:41:07 -08001427 if c.sanitize != nil {
1428 deps = c.sanitize.deps(ctx, deps)
1429 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001430 if c.coverage != nil {
1431 deps = c.coverage.deps(ctx, deps)
1432 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001433 if c.sabi != nil {
1434 deps = c.sabi.deps(ctx, deps)
1435 }
Justin Yun8effde42017-06-23 19:24:43 +09001436 if c.vndkdep != nil {
1437 deps = c.vndkdep.deps(ctx, deps)
1438 }
Stephen Craneba090d12017-05-09 15:44:35 -07001439 if c.lto != nil {
1440 deps = c.lto.deps(ctx, deps)
1441 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001442 for _, feature := range c.features {
1443 deps = feature.deps(ctx, deps)
1444 }
1445
Colin Crossb6715442017-10-24 11:13:31 -07001446 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1447 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1448 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1449 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1450 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1451 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001452 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001453
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001454 for _, lib := range deps.ReexportSharedLibHeaders {
1455 if !inList(lib, deps.SharedLibs) {
1456 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1457 }
1458 }
1459
1460 for _, lib := range deps.ReexportStaticLibHeaders {
1461 if !inList(lib, deps.StaticLibs) {
1462 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1463 }
1464 }
1465
Colin Cross5950f382016-12-13 12:50:57 -08001466 for _, lib := range deps.ReexportHeaderLibHeaders {
1467 if !inList(lib, deps.HeaderLibs) {
1468 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1469 }
1470 }
1471
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001472 for _, gen := range deps.ReexportGeneratedHeaders {
1473 if !inList(gen, deps.GeneratedHeaders) {
1474 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1475 }
1476 }
1477
Colin Crossc99deeb2016-04-11 15:06:20 -07001478 return deps
1479}
1480
Dan Albert7e9d2952016-08-04 13:02:36 -07001481func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001482 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001483 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001484 moduleContextImpl: moduleContextImpl{
1485 mod: c,
1486 },
1487 }
1488 ctx.ctx = ctx
1489
Colin Crossca860ac2016-01-04 14:34:37 -08001490 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001491}
1492
Jiyong Park7ed9de32018-10-15 22:25:07 +09001493// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001494func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001495 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1496 version := name[sharp+1:]
1497 libname := name[:sharp]
1498 return libname, version
1499 }
1500 return name, ""
1501}
1502
Colin Cross1e676be2016-10-12 14:38:15 -07001503func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001504 ctx := &depsContext{
1505 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001506 moduleContextImpl: moduleContextImpl{
1507 mod: c,
1508 },
1509 }
1510 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001511
Colin Crossc99deeb2016-04-11 15:06:20 -07001512 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001513
Dan Albert914449f2016-06-17 16:45:24 -07001514 variantNdkLibs := []string{}
1515 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001516 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001517 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001518
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001519 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1520 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001521 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001522 // 1. Name of an NDK library that refers to a prebuilt module.
1523 // For each of these, it adds the name of the prebuilt module (which will be in
1524 // prebuilts/ndk) to the list of nonvariant libs.
1525 // 2. Name of an NDK library that refers to an ndk_library module.
1526 // For each of these, it adds the name of the ndk_library module to the list of
1527 // variant libs.
1528 // 3. Anything else (so anything that isn't an NDK library).
1529 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001530 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001531 // The caller can then know to add the variantLibs dependencies differently from the
1532 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001533
Inseob Kim9516ee92019-05-09 10:56:13 +09001534 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001535 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1536 variantLibs = []string{}
1537 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001538 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001539 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001540 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001541 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1542 if !inList(name, ndkMigratedLibs) {
1543 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001544 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001545 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001546 }
Jooyung Han0302a842019-10-30 18:43:49 +09001547 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001548 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001549 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001550 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001551 if actx.OtherModuleExists(vendorPublicLib) {
1552 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1553 } else {
1554 // This can happen if vendor_public_library module is defined in a
1555 // namespace that isn't visible to the current module. In that case,
1556 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001557 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001558 }
Dan Albert914449f2016-06-17 16:45:24 -07001559 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001560 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001561 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001562 }
1563 }
Dan Albert914449f2016-06-17 16:45:24 -07001564 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001565 }
1566
Dan Albert914449f2016-06-17 16:45:24 -07001567 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1568 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001569 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001570 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001571
Jiyong Park7e636d02019-01-28 16:16:54 +09001572 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001573 if c.linker != nil {
1574 if library, ok := c.linker.(*libraryDecorator); ok {
1575 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001576 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001577 }
1578 }
1579 }
1580
Colin Cross32ec36c2016-12-15 07:39:51 -08001581 for _, lib := range deps.HeaderLibs {
1582 depTag := headerDepTag
1583 if inList(lib, deps.ReexportHeaderLibHeaders) {
1584 depTag = headerExportDepTag
1585 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001586 if buildStubs {
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001587 actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
1588 blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}),
1589 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001590 } else {
1591 actx.AddVariationDependencies(nil, depTag, lib)
1592 }
1593 }
1594
1595 if buildStubs {
1596 // Stubs lib does not have dependency to other static/shared libraries.
1597 // Don't proceed.
1598 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001599 }
Colin Cross5950f382016-12-13 12:50:57 -08001600
Inseob Kimc0907f12019-02-08 21:00:45 +09001601 syspropImplLibraries := syspropImplLibraries(actx.Config())
1602
Jiyong Park5d1598f2019-02-25 22:14:17 +09001603 for _, lib := range deps.WholeStaticLibs {
1604 depTag := wholeStaticDepTag
1605 if impl, ok := syspropImplLibraries[lib]; ok {
1606 lib = impl
1607 }
1608 actx.AddVariationDependencies([]blueprint.Variation{
1609 {Mutator: "link", Variation: "static"},
1610 }, depTag, lib)
1611 }
1612
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001613 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001614 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001615 if inList(lib, deps.ReexportStaticLibHeaders) {
1616 depTag = staticExportDepTag
1617 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001618
1619 if impl, ok := syspropImplLibraries[lib]; ok {
1620 lib = impl
1621 }
1622
Dan Willemsen59339a22018-07-22 21:18:45 -07001623 actx.AddVariationDependencies([]blueprint.Variation{
1624 {Mutator: "link", Variation: "static"},
1625 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001626 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001627
Dan Willemsen59339a22018-07-22 21:18:45 -07001628 actx.AddVariationDependencies([]blueprint.Variation{
1629 {Mutator: "link", Variation: "static"},
1630 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001631
Ivan Lozano183a3212019-10-18 14:18:45 -07001632 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001633 var variations []blueprint.Variation
1634 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001635 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001636 if version != "" && versionVariantAvail {
1637 // Version is explicitly specified. i.e. libFoo#30
1638 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001639 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001640 }
1641 actx.AddVariationDependencies(variations, depTag, name)
1642
1643 // If the version is not specified, add dependency to the latest stubs library.
1644 // The stubs library will be used when the depending module is built for APEX and
1645 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001646 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001647 if version == "" && latestVersion != "" && versionVariantAvail {
1648 actx.AddVariationDependencies([]blueprint.Variation{
1649 {Mutator: "link", Variation: "shared"},
1650 {Mutator: "version", Variation: latestVersion},
1651 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001652 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001653 }
1654 }
1655
Jiyong Park7ed9de32018-10-15 22:25:07 +09001656 // shared lib names without the #version suffix
1657 var sharedLibNames []string
1658
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001659 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001660 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001661 if inList(lib, deps.ReexportSharedLibHeaders) {
1662 depTag = sharedExportDepTag
1663 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001664
1665 if impl, ok := syspropImplLibraries[lib]; ok {
1666 lib = impl
1667 }
1668
Jiyong Park73c54ee2019-10-22 20:31:18 +09001669 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001670 sharedLibNames = append(sharedLibNames, name)
1671
Jiyong Park25fc6a92018-11-18 18:02:45 +09001672 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001673 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001674
Jiyong Park7ed9de32018-10-15 22:25:07 +09001675 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001676 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001677 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1678 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1679 // linking against both the stubs lib and the non-stubs lib at the same time.
1680 continue
1681 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001682 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001683 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001684
Dan Willemsen59339a22018-07-22 21:18:45 -07001685 actx.AddVariationDependencies([]blueprint.Variation{
1686 {Mutator: "link", Variation: "shared"},
1687 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001688
Colin Cross68861832016-07-08 10:41:41 -07001689 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001690
1691 for _, gen := range deps.GeneratedHeaders {
1692 depTag := genHeaderDepTag
1693 if inList(gen, deps.ReexportGeneratedHeaders) {
1694 depTag = genHeaderExportDepTag
1695 }
1696 actx.AddDependency(c, depTag, gen)
1697 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001698
Colin Cross42d48b72018-08-29 14:10:52 -07001699 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001700
1701 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001702 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001703 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001704 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001705 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001706 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001707 if deps.LinkerFlagsFile != "" {
1708 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1709 }
1710 if deps.DynamicLinker != "" {
1711 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001712 }
Dan Albert914449f2016-06-17 16:45:24 -07001713
1714 version := ctx.sdkVersion()
1715 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001716 {Mutator: "ndk_api", Variation: version},
1717 {Mutator: "link", Variation: "shared"},
1718 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001719 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001720 {Mutator: "ndk_api", Variation: version},
1721 {Mutator: "link", Variation: "shared"},
1722 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001723
1724 if vndkdep := c.vndkdep; vndkdep != nil {
1725 if vndkdep.isVndkExt() {
Inseob Kim64c43952019-08-26 16:52:35 +09001726 var baseModuleMode string
Logan Chienf3511742017-10-31 18:04:35 +08001727 if actx.DeviceConfig().VndkVersion() == "" {
1728 baseModuleMode = coreMode
Inseob Kim64c43952019-08-26 16:52:35 +09001729 } else {
1730 baseModuleMode = c.imageVariation()
Logan Chienf3511742017-10-31 18:04:35 +08001731 }
1732 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001733 {Mutator: "image", Variation: baseModuleMode},
1734 {Mutator: "link", Variation: "shared"},
1735 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001736 }
1737 }
Colin Cross6362e272015-10-29 15:25:03 -07001738}
Colin Cross21b9a242015-03-24 14:15:58 -07001739
Colin Crosse40b4ea2018-10-02 22:25:58 -07001740func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001741 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1742 c.beginMutator(ctx)
1743 }
1744}
1745
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001746// Whether a module can link to another module, taking into
1747// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001748func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1749 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001750 // Host code is not restricted
1751 return
1752 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001753
1754 // VNDK is cc.Module supported only for now.
1755 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001756 // Though vendor code is limited by the vendor mutator,
1757 // each vendor-available module needs to check
1758 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001759 if ccTo, ok := to.(*Module); ok {
1760 if ccFrom.vndkdep != nil {
1761 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1762 }
1763 } else {
1764 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001765 }
1766 return
1767 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001768 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001769 // Platform code can link to anything
1770 return
1771 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001772 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001773 // Recovery code is not NDK
1774 return
1775 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001776 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001777 // These are always allowed
1778 return
1779 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001780 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001781 // These are allowed, but they don't set sdk_version
1782 return
1783 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001784 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001785 // These aren't real libraries, but are the stub shared libraries that are included in
1786 // the NDK.
1787 return
1788 }
Logan Chien834b9a62019-01-14 15:39:03 +08001789
Ivan Lozano52767be2019-10-18 14:49:46 -07001790 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001791 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1792 // to link to libc++ (non-NDK and without sdk_version).
1793 return
1794 }
1795
Ivan Lozano52767be2019-10-18 14:49:46 -07001796 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001797 // NDK code linking to platform code is never okay.
1798 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001799 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001800 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001801 }
1802
1803 // At this point we know we have two NDK libraries, but we need to
1804 // check that we're not linking against anything built against a higher
1805 // API level, as it is only valid to link against older or equivalent
1806 // APIs.
1807
Inseob Kim01a28722018-04-11 09:48:45 +09001808 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001809 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001810 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001811 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001812 // Current can't be linked against by anything else.
1813 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001814 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001815 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001816 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001817 if err != nil {
1818 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001819 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001820 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001821 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001822 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001823 if err != nil {
1824 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001825 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001826 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001827 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001828
Inseob Kim01a28722018-04-11 09:48:45 +09001829 if toApi > fromApi {
1830 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001831 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001832 }
1833 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001834 }
Dan Albert202fe492017-12-15 13:56:59 -08001835
1836 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001837 fromStl := from.SelectedStl()
1838 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001839 if fromStl == "" || toStl == "" {
1840 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001841 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001842 // We can be permissive with the system "STL" since it is only the C++
1843 // ABI layer, but in the future we should make sure that everyone is
1844 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001845 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001846 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001847 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1848 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001849 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001850}
1851
Jiyong Park5fb8c102018-04-09 12:03:06 +09001852// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001853// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1854// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001855// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001856func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1857 check := func(child, parent android.Module) bool {
1858 to, ok := child.(*Module)
1859 if !ok {
1860 // follow thru cc.Defaults, etc.
1861 return true
1862 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001863
Jooyung Hana70f0672019-01-18 15:20:43 +09001864 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1865 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001866 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001867
1868 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001869 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001870 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001871 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001872
Jooyung Han0302a842019-10-30 18:43:49 +09001873 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001874 return false
1875 }
1876
1877 var stringPath []string
1878 for _, m := range ctx.GetWalkPath() {
1879 stringPath = append(stringPath, m.Name())
1880 }
1881 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1882 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1883 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1884 return false
1885 }
1886 if module, ok := ctx.Module().(*Module); ok {
1887 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001888 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001889 ctx.WalkDeps(check)
1890 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001891 }
1892 }
1893}
1894
Colin Crossc99deeb2016-04-11 15:06:20 -07001895// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001896func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001897 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001898
Ivan Lozano183a3212019-10-18 14:18:45 -07001899 directStaticDeps := []LinkableInterface{}
1900 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001901
Inseob Kim9516ee92019-05-09 10:56:13 +09001902 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1903
Inseob Kim69378442019-06-03 19:10:47 +09001904 reexportExporter := func(exporter exportedFlagsProducer) {
1905 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1906 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1907 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1908 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1909 }
1910
Colin Crossd11fcda2017-10-23 17:59:01 -07001911 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001912 depName := ctx.OtherModuleName(dep)
1913 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001914
Ivan Lozano52767be2019-10-18 14:49:46 -07001915 ccDep, ok := dep.(LinkableInterface)
1916 if !ok {
1917
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001918 // handling for a few module types that aren't cc Module but that are also supported
1919 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001920 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001921 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001922 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1923 genRule.GeneratedSourceFiles()...)
1924 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001925 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001926 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001927 // Support exported headers from a generated_sources dependency
1928 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001929 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001930 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001931 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001932 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09001933 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09001934 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001935 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001936 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1937 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001938 // 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 +09001939 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001940
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001941 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001942 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001943 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001944 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001945 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001946 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001947 files := genRule.GeneratedSourceFiles()
1948 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001949 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001950 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001951 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 -07001952 }
1953 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001954 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001955 }
Colin Crossca860ac2016-01-04 14:34:37 -08001956 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001957 return
1958 }
1959
Colin Crossfe17f6f2019-03-28 19:30:56 -07001960 if depTag == android.ProtoPluginDepTag {
1961 return
1962 }
1963
Colin Crossd11fcda2017-10-23 17:59:01 -07001964 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001965 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1966 return
1967 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001968 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001969 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001970 return
1971 }
1972
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001973 // re-exporting flags
1974 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001975 // reusing objects only make sense for cc.Modules.
1976 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001977 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07001978 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001979 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001980 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001981 return
1982 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001983 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001984
Jiyong Parke4bb9862019-02-01 00:31:10 +09001985 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001986 // staticVariants are a cc.Module specific concept.
1987 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09001988 c.staticVariant = ccDep
1989 return
1990 }
1991 }
1992
Ivan Lozano183a3212019-10-18 14:18:45 -07001993 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
1994 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
1995 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001996 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07001997 if t, ok := depTag.(DependencyTag); ok {
1998 explicitlyVersioned = t.ExplicitlyVersioned
1999 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002000 depTag = t
2001 }
2002
Ivan Lozano183a3212019-10-18 14:18:45 -07002003 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002004 depIsStatic := false
2005 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002006 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002007 depIsStatic = true
2008 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002009 if ccDep.CcLibrary() && !depIsStatic {
2010 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002011 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002012 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002013 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002014
2015 var useThisDep bool
2016 if depIsStubs && explicitlyVersioned {
2017 // Always respect dependency to the versioned stubs (i.e. libX#10)
2018 useThisDep = true
2019 } else if !depHasStubs {
2020 // Use non-stub variant if that is the only choice
2021 // (i.e. depending on a lib without stubs.version property)
2022 useThisDep = true
2023 } else if c.IsForPlatform() {
2024 // If not building for APEX, use stubs only when it is from
2025 // an APEX (and not from platform)
2026 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002027 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002028 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002029 // always link to non-stub variant
2030 useThisDep = !depIsStubs
2031 }
2032 } else {
2033 // If building for APEX, use stubs only when it is not from
2034 // the same APEX
2035 useThisDep = (depInSameApex != depIsStubs)
2036 }
2037
2038 if !useThisDep {
2039 return // stop processing this dep
2040 }
2041 }
2042
Ivan Lozano52767be2019-10-18 14:49:46 -07002043 // Exporting flags only makes sense for cc.Modules
2044 if _, ok := ccDep.(*Module); ok {
2045 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
2046 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
2047 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
2048 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
2049 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002050
Ivan Lozano52767be2019-10-18 14:49:46 -07002051 if t.ReexportFlags {
2052 reexportExporter(i)
2053 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2054 // Re-exported shared library headers must be included as well since they can help us with type information
2055 // about template instantiations (instantiated from their headers).
2056 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2057 // scripts.
2058 c.sabi.Properties.ReexportedIncludes = append(
2059 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2060 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002061 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002062 }
Logan Chienf3511742017-10-31 18:04:35 +08002063 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002064 }
2065
Colin Cross26c34ed2016-09-30 17:10:16 -07002066 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002067 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002068
Ivan Lozano52767be2019-10-18 14:49:46 -07002069 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002070 depFile := android.OptionalPath{}
2071
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002072 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002073 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002074 ptr = &depPaths.SharedLibs
2075 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002076 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002077 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002078
Jiyong Park64a44f22019-01-18 14:37:08 +09002079 case earlySharedDepTag:
2080 ptr = &depPaths.EarlySharedLibs
2081 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002082 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002083 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002084 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002085 ptr = &depPaths.LateSharedLibs
2086 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002087 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002088 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002089 ptr = nil
2090 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002091 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002092 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002093 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002094 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002095 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002096 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002097 return
2098 }
2099
Ivan Lozano52767be2019-10-18 14:49:46 -07002100 // Because the static library objects are included, this only makes sense
2101 // in the context of proper cc.Modules.
2102 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2103 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2104 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2105 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2106 for i := range missingDeps {
2107 missingDeps[i] += postfix
2108 }
2109 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002110 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002111 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2112 } else {
2113 ctx.ModuleErrorf(
2114 "non-cc.Modules cannot be included as whole static libraries.", depName)
2115 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002116 }
Colin Cross5950f382016-12-13 12:50:57 -08002117 case headerDepTag:
2118 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002119 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002120 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002121 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002122 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002123 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002124 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002125 case dynamicLinkerDepTag:
2126 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002127 }
2128
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002129 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002130 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002131 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002132 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002133 return
2134 }
2135
2136 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002137 // in static libraries act as if they were whole static libraries. The same goes for
2138 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002139 // This should only be done for cc.Modules
2140 if c, ok := ccDep.(*Module); ok {
2141 staticLib := c.linker.(libraryInterface)
2142 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2143 staticLib.objs().coverageFiles...)
2144 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2145 staticLib.objs().sAbiDumpFiles...)
2146 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002147 }
2148
Colin Cross26c34ed2016-09-30 17:10:16 -07002149 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002150 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002151 if !ctx.Config().AllowMissingDependencies() {
2152 ctx.ModuleErrorf("module %q missing output file", depName)
2153 } else {
2154 ctx.AddMissingDependencies([]string{depName})
2155 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002156 return
2157 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002158 *ptr = append(*ptr, linkFile.Path())
2159 }
2160
Colin Crossc99deeb2016-04-11 15:06:20 -07002161 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002162 dep := depFile
2163 if !dep.Valid() {
2164 dep = linkFile
2165 }
2166 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002167 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002168
Logan Chien43d34c32017-12-20 01:17:32 +08002169 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002171 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002172 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002173 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002174 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002175 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002176
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002178 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2179 // core module instead.
2180 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002181 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002182 // The vendor module in Make will have been renamed to not conflict with the core
2183 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09002184 ret := libName + vendorSuffix
2185 vendorVersion := ctx.DeviceConfig().VndkVersion()
2186 if vendorVersion == "current" {
2187 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
2188 }
2189 if c.Properties.VndkVersion != vendorVersion {
2190 ret += "." + c.Properties.VndkVersion
2191 }
2192 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09002193 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002194 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002195 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002196 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002198 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002199 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002200 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002201 }
Logan Chien43d34c32017-12-20 01:17:32 +08002202 }
2203
2204 // Export the shared libs to Make.
2205 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002206 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002207 if ccDep.CcLibrary() {
2208 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002209 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002210 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002211 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002212 c.Properties.ApexesProvidingSharedLibs = append(
2213 c.Properties.ApexesProvidingSharedLibs, an)
2214 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002215 }
2216 }
2217
Jiyong Park27b188b2017-07-18 13:23:39 +09002218 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002219 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002220 c.Properties.AndroidMkSharedLibs = append(
2221 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002222 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002223 c.Properties.AndroidMkSharedLibs = append(
2224 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002226 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002227 c.Properties.AndroidMkStaticLibs = append(
2228 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002229 case runtimeDepTag:
2230 c.Properties.AndroidMkRuntimeLibs = append(
2231 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002232 case wholeStaticDepTag:
2233 c.Properties.AndroidMkWholeStaticLibs = append(
2234 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002235 }
Colin Crossca860ac2016-01-04 14:34:37 -08002236 })
2237
Jeff Gaston294356f2017-09-27 17:05:30 -07002238 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002239 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002240
Colin Crossdd84e052017-05-17 13:44:16 -07002241 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002242 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002243 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2244 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002245 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Jiyong Park74955042019-10-22 20:19:51 +09002246 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2247 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002248 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002249 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002250
2251 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002252 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002253 }
Colin Crossdd84e052017-05-17 13:44:16 -07002254
Colin Crossca860ac2016-01-04 14:34:37 -08002255 return depPaths
2256}
2257
2258func (c *Module) InstallInData() bool {
2259 if c.installer == nil {
2260 return false
2261 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002262 return c.installer.inData()
2263}
2264
2265func (c *Module) InstallInSanitizerDir() bool {
2266 if c.installer == nil {
2267 return false
2268 }
2269 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002270 return true
2271 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002272 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002273}
2274
Jiyong Parkf9332f12018-02-01 00:54:12 +09002275func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002276 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002277}
2278
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002279func (c *Module) HostToolPath() android.OptionalPath {
2280 if c.installer == nil {
2281 return android.OptionalPath{}
2282 }
2283 return c.installer.hostToolPath()
2284}
2285
Nan Zhangd4e641b2017-07-12 12:55:28 -07002286func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2287 return c.outputFile
2288}
2289
Colin Cross41955e82019-05-29 14:40:35 -07002290func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2291 switch tag {
2292 case "":
2293 if c.outputFile.Valid() {
2294 return android.Paths{c.outputFile.Path()}, nil
2295 }
2296 return android.Paths{}, nil
2297 default:
2298 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002299 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002300}
2301
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002302func (c *Module) static() bool {
2303 if static, ok := c.linker.(interface {
2304 static() bool
2305 }); ok {
2306 return static.static()
2307 }
2308 return false
2309}
2310
Jiyong Park379de2f2018-12-19 02:47:14 +09002311func (c *Module) staticBinary() bool {
2312 if static, ok := c.linker.(interface {
2313 staticBinary() bool
2314 }); ok {
2315 return static.staticBinary()
2316 }
2317 return false
2318}
2319
Jiyong Park1d1119f2019-07-29 21:27:18 +09002320func (c *Module) header() bool {
2321 if h, ok := c.linker.(interface {
2322 header() bool
2323 }); ok {
2324 return h.header()
2325 }
2326 return false
2327}
2328
Jooyung Han38002912019-05-16 04:01:54 +09002329func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002330 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002331 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2332 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002333 return "native:vndk"
2334 }
Jooyung Han38002912019-05-16 04:01:54 +09002335 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002336 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002337 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002338 if Bool(c.VendorProperties.Vendor_available) {
2339 return "native:vndk"
2340 }
2341 return "native:vndk_private"
2342 }
2343 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002344 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002345 return "native:recovery"
2346 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2347 return "native:ndk:none:none"
2348 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2349 //family, link := getNdkStlFamilyAndLinkType(c)
2350 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002351 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002352 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002353 } else {
2354 return "native:platform"
2355 }
2356}
2357
Jiyong Park9d452992018-10-03 00:38:19 +09002358// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002359// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002360func (c *Module) IsInstallableToApex() bool {
2361 if shared, ok := c.linker.(interface {
2362 shared() bool
2363 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002364 // Stub libs and prebuilt libs in a versioned SDK are not
2365 // installable to APEX even though they are shared libs.
2366 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002367 } else if _, ok := c.linker.(testPerSrc); ok {
2368 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002369 }
2370 return false
2371}
2372
Jiyong Parka90ca002019-10-07 15:47:24 +09002373func (c *Module) AvailableFor(what string) bool {
2374 if linker, ok := c.linker.(interface {
2375 availableFor(string) bool
2376 }); ok {
2377 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2378 } else {
2379 return c.ApexModuleBase.AvailableFor(what)
2380 }
2381}
2382
Inseob Kim1f086e22019-05-09 13:29:15 +09002383func (c *Module) installable() bool {
2384 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2385}
2386
Jiyong Park3b1746a2019-01-29 11:15:04 +09002387func (c *Module) imageVariation() string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002388 if c.UseVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002389 return vendorMode + "." + c.Properties.VndkVersion
Ivan Lozano52767be2019-10-18 14:49:46 -07002390 } else if c.InRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09002391 return recoveryMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002392 }
Inseob Kim64c43952019-08-26 16:52:35 +09002393 return coreMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002394}
2395
bralee3f49f4d2019-03-04 06:58:15 +08002396func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002397 outputFiles, err := c.OutputFiles("")
2398 if err != nil {
2399 panic(err)
2400 }
2401 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002402}
2403
Logan Chien41eabe62019-04-10 13:33:58 +08002404func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2405 if c.linker != nil {
2406 if library, ok := c.linker.(*libraryDecorator); ok {
2407 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2408 }
2409 }
2410}
2411
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002412func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002413 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2414 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002415 // dynamic dep to a stubs lib crosses APEX boundary
2416 return false
2417 }
2418 }
2419 return true
2420}
2421
Colin Cross2ba19d92015-05-07 15:44:20 -07002422//
Colin Crosscfad1192015-11-02 16:43:11 -08002423// Defaults
2424//
Colin Crossca860ac2016-01-04 14:34:37 -08002425type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002426 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002427 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002428 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002429}
2430
Patrice Arrudac249c712019-03-19 17:00:29 -07002431// cc_defaults provides a set of properties that can be inherited by other cc
2432// modules. A module can use the properties from a cc_defaults using
2433// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2434// merged (when possible) by prepending the default module's values to the
2435// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002436func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002437 return DefaultsFactory()
2438}
2439
Colin Cross36242852017-06-23 15:06:31 -07002440func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002441 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002442
Colin Cross36242852017-06-23 15:06:31 -07002443 module.AddProperties(props...)
2444 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002445 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002446 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002447 &BaseCompilerProperties{},
2448 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002449 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002450 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002451 &StaticProperties{},
2452 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002453 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002454 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002455 &TestProperties{},
2456 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002457 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002458 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002459 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002460 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002461 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002462 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002463 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002464 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002465 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002466 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002467 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002468 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002469 &android.ProtoProperties{},
Jooyung Han18020ea2019-11-13 10:50:48 +09002470 &android.ApexProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002471 )
Colin Crosscfad1192015-11-02 16:43:11 -08002472
Jooyung Hancc372c52019-09-25 15:18:44 +09002473 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002474
2475 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002476}
2477
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002478const (
2479 // coreMode is the variant used for framework-private libraries, or
2480 // SDK libraries. (which framework-private libraries can use)
2481 coreMode = "core"
2482
Inseob Kim64c43952019-08-26 16:52:35 +09002483 // vendorMode is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002484 // against the VNDK.
2485 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002486
2487 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002488)
2489
Jiyong Park6a43f042017-10-12 23:05:00 +09002490func squashVendorSrcs(m *Module) {
2491 if lib, ok := m.compiler.(*libraryDecorator); ok {
2492 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2493 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2494
2495 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2496 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2497 }
2498}
2499
Jiyong Parkf9332f12018-02-01 00:54:12 +09002500func squashRecoverySrcs(m *Module) {
2501 if lib, ok := m.compiler.(*libraryDecorator); ok {
2502 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2503 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2504
2505 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2506 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2507 }
2508}
2509
Jiyong Parkda6eb592018-12-19 17:12:36 +09002510func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002511 if mctx.Os() != android.Android {
2512 return
2513 }
2514
Jiyong Park7ed9de32018-10-15 22:25:07 +09002515 if g, ok := mctx.Module().(*genrule.Module); ok {
2516 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002517 var coreVariantNeeded bool = false
2518 var vendorVariantNeeded bool = false
2519 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002520 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002521 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002522 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002523 coreVariantNeeded = true
2524 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002525 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002526 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002527 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002528 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002529 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002530 if Bool(props.Recovery_available) {
2531 recoveryVariantNeeded = true
2532 }
2533
Jiyong Park413cc742018-06-19 01:46:06 +09002534 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002535 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002536 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002537 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002538 recoveryVariantNeeded = false
2539 }
2540 }
2541
Jiyong Park3f736c92018-05-24 13:36:56 +09002542 var variants []string
2543 if coreVariantNeeded {
2544 variants = append(variants, coreMode)
2545 }
2546 if vendorVariantNeeded {
Inseob Kim64c43952019-08-26 16:52:35 +09002547 variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion())
2548 if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" {
2549 variants = append(variants, vendorMode+"."+vndkVersion)
2550 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002551 }
2552 if recoveryVariantNeeded {
2553 variants = append(variants, recoveryMode)
2554 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002555 mod := mctx.CreateVariations(variants...)
2556 for i, v := range variants {
2557 if v == recoveryMode {
2558 m := mod[i].(*genrule.Module)
2559 m.Extra.(*GenruleExtraProperties).InRecovery = true
2560 }
2561 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002562 }
2563 }
2564
Ivan Lozano52767be2019-10-18 14:49:46 -07002565 //TODO When LinkableInterface supports VNDK, this should be mctx.Module().(LinkableInterface)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002566 m, ok := mctx.Module().(*Module)
2567 if !ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002568 if linkable, ok := mctx.Module().(LinkableInterface); ok {
2569 variations := []string{coreMode}
2570 if linkable.InRecovery() {
2571 variations = append(variations, recoveryMode)
2572 }
2573 mctx.CreateVariations(variations...)
2574 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002575 return
2576 }
2577
2578 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002579 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002580 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002581
2582 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002583 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002584 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002585 return
2586 }
Logan Chienf3511742017-10-31 18:04:35 +08002587
2588 if vndkdep := m.vndkdep; vndkdep != nil {
2589 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002590 if productSpecific {
2591 mctx.PropertyErrorf("product_specific",
2592 "product_specific must not be true when `vndk: {enabled: true}`")
2593 return
2594 }
Logan Chienf3511742017-10-31 18:04:35 +08002595 if vendorSpecific {
2596 if !vndkdep.isVndkExt() {
2597 mctx.PropertyErrorf("vndk",
2598 "must set `extends: \"...\"` to vndk extension")
2599 return
2600 }
2601 } else {
2602 if vndkdep.isVndkExt() {
2603 mctx.PropertyErrorf("vndk",
2604 "must set `vendor: true` to set `extends: %q`",
2605 m.getVndkExtendsModuleName())
2606 return
2607 }
2608 if m.VendorProperties.Vendor_available == nil {
2609 mctx.PropertyErrorf("vndk",
2610 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2611 return
2612 }
2613 }
2614 } else {
2615 if vndkdep.isVndkSp() {
2616 mctx.PropertyErrorf("vndk",
2617 "must set `enabled: true` to set `support_system_process: true`")
2618 return
2619 }
2620 if vndkdep.isVndkExt() {
2621 mctx.PropertyErrorf("vndk",
2622 "must set `enabled: true` to set `extends: %q`",
2623 m.getVndkExtendsModuleName())
2624 return
2625 }
Justin Yun8effde42017-06-23 19:24:43 +09002626 }
2627 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002628
Jiyong Parkf9332f12018-02-01 00:54:12 +09002629 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002630 var recoveryVariantNeeded bool = false
2631
Inseob Kim64c43952019-08-26 16:52:35 +09002632 var vendorVariants []string
2633
2634 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2635 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2636 if deviceVndkVersion == "current" {
2637 deviceVndkVersion = platformVndkVersion
2638 }
2639
Justin Yun71549282017-11-17 12:10:28 +09002640 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002641 // If the device isn't compiling against the VNDK, we always
2642 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002643 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002644 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2645 // Skip creating vendor variants for natvie bridge modules
2646 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002647 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2648 // LL-NDK stubs only exist in the vendor variant, since the
2649 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002650 vendorVariants = append(vendorVariants,
2651 platformVndkVersion,
2652 deviceVndkVersion,
2653 )
Jiyong Park2a454122017-10-19 15:59:33 +09002654 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2655 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002656 vendorVariants = append(vendorVariants,
2657 platformVndkVersion,
2658 deviceVndkVersion,
2659 )
2660 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002661 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2662 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002663 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002664 } else if m.HasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002665 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002666 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002667 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002668 vendorVariants = append(vendorVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002669 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2670 // code is PLATFORM_VNDK_VERSION.
2671 // On the other hand, vendor_available modules which are not VNDK should
2672 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
2673 if !m.IsVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002674 vendorVariants = append(vendorVariants, deviceVndkVersion)
2675 }
Logan Chienf3511742017-10-31 18:04:35 +08002676 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002677 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002678 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002679 } else {
2680 // This is either in /system (or similar: /data), or is a
2681 // modules built with the NDK. Modules built with the NDK
2682 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002683 coreVariantNeeded = true
2684 }
2685
2686 if Bool(m.Properties.Recovery_available) {
2687 recoveryVariantNeeded = true
2688 }
2689
2690 if m.ModuleBase.InstallInRecovery() {
2691 recoveryVariantNeeded = true
2692 coreVariantNeeded = false
2693 }
2694
Jiyong Park413cc742018-06-19 01:46:06 +09002695 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002696 primaryArch := mctx.Config().DevicePrimaryArchType()
2697 moduleArch := m.Target().Arch.ArchType
2698 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002699 recoveryVariantNeeded = false
2700 }
2701 }
2702
Jiyong Parkf9332f12018-02-01 00:54:12 +09002703 var variants []string
2704 if coreVariantNeeded {
2705 variants = append(variants, coreMode)
2706 }
Inseob Kim64c43952019-08-26 16:52:35 +09002707 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
2708 variants = append(variants, vendorMode+"."+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002709 }
2710 if recoveryVariantNeeded {
2711 variants = append(variants, recoveryMode)
2712 }
2713 mod := mctx.CreateVariations(variants...)
2714 for i, v := range variants {
Inseob Kim64c43952019-08-26 16:52:35 +09002715 if strings.HasPrefix(v, vendorMode+".") {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002716 m := mod[i].(*Module)
Inseob Kim64c43952019-08-26 16:52:35 +09002717 m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".")
Jiyong Parkf9332f12018-02-01 00:54:12 +09002718 squashVendorSrcs(m)
2719 } else if v == recoveryMode {
2720 m := mod[i].(*Module)
2721 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002722 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002723 squashRecoverySrcs(m)
2724 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002725 }
2726}
2727
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002728func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002729 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002730 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2731 }
Colin Cross6510f912017-11-29 00:27:14 -08002732 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002733}
2734
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002735func kytheExtractAllFactory() android.Singleton {
2736 return &kytheExtractAllSingleton{}
2737}
2738
2739type kytheExtractAllSingleton struct {
2740}
2741
2742func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2743 var xrefTargets android.Paths
2744 ctx.VisitAllModules(func(module android.Module) {
2745 if ccModule, ok := module.(xref); ok {
2746 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2747 }
2748 })
2749 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2750 if len(xrefTargets) > 0 {
2751 ctx.Build(pctx, android.BuildParams{
2752 Rule: blueprint.Phony,
2753 Output: android.PathForPhony(ctx, "xref_cxx"),
2754 Inputs: xrefTargets,
2755 //Default: true,
2756 })
2757 }
2758}
2759
Colin Cross06a931b2015-10-28 17:23:31 -07002760var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002761var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002762var BoolPtr = proptools.BoolPtr
2763var String = proptools.String
2764var StringPtr = proptools.StringPtr