blob: 840fe24d6c6a894b4a1924dadb71a9cb93316b8f [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
Jooyung Hancc372c52019-09-25 15:18:44 +0900723 android.InitDefaultableModule(c)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900724
725 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900726 android.InitSdkAwareModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900727
Colin Cross36242852017-06-23 15:06:31 -0700728 return c
Colin Crossc472d572015-03-17 15:06:21 -0700729}
730
Colin Crossb916a382016-07-29 17:28:03 -0700731// Returns true for dependency roots (binaries)
732// TODO(ccross): also handle dlopenable libraries
733func (c *Module) isDependencyRoot() bool {
734 if root, ok := c.linker.(interface {
735 isDependencyRoot() bool
736 }); ok {
737 return root.isDependencyRoot()
738 }
739 return false
740}
741
Ivan Lozano52767be2019-10-18 14:49:46 -0700742func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900743 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700744}
745
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800746func (c *Module) isCoverageVariant() bool {
747 return c.coverage.Properties.IsCoverageVariant
748}
749
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800750func (c *Module) isNdk() bool {
751 return inList(c.Name(), ndkMigratedLibs)
752}
753
Inseob Kim9516ee92019-05-09 10:56:13 +0900754func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800755 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900756 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800757}
758
Inseob Kim9516ee92019-05-09 10:56:13 +0900759func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800760 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900761 name := c.BaseModuleName()
762 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800763}
764
Inseob Kim9516ee92019-05-09 10:56:13 +0900765func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800766 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900767 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800768}
769
Ivan Lozano52767be2019-10-18 14:49:46 -0700770func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800771 if vndkdep := c.vndkdep; vndkdep != nil {
772 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900773 }
774 return false
775}
776
Jooyung Han76106d92019-05-20 18:49:10 +0900777func (c *Module) vndkVersion() string {
Inseob Kim64c43952019-08-26 16:52:35 +0900778 return c.Properties.VndkVersion
Jooyung Han76106d92019-05-20 18:49:10 +0900779}
780
Yi Kong7e53c572018-02-14 18:16:12 +0800781func (c *Module) isPgoCompile() bool {
782 if pgo := c.pgo; pgo != nil {
783 return pgo.Properties.PgoCompile
784 }
785 return false
786}
787
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800788func (c *Module) isNDKStubLibrary() bool {
789 if _, ok := c.compiler.(*stubDecorator); ok {
790 return true
791 }
792 return false
793}
794
Logan Chienf3511742017-10-31 18:04:35 +0800795func (c *Module) isVndkSp() bool {
796 if vndkdep := c.vndkdep; vndkdep != nil {
797 return vndkdep.isVndkSp()
798 }
799 return false
800}
801
802func (c *Module) isVndkExt() bool {
803 if vndkdep := c.vndkdep; vndkdep != nil {
804 return vndkdep.isVndkExt()
805 }
806 return false
807}
808
Ivan Lozano52767be2019-10-18 14:49:46 -0700809func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900810 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800811}
812
Logan Chienf3511742017-10-31 18:04:35 +0800813func (c *Module) getVndkExtendsModuleName() string {
814 if vndkdep := c.vndkdep; vndkdep != nil {
815 return vndkdep.getVndkExtendsModuleName()
816 }
817 return ""
818}
819
Jiyong Park82e2bf32017-08-16 14:05:54 +0900820// Returns true only when this module is configured to have core and vendor
821// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700822func (c *Module) HasVendorVariant() bool {
823 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900824}
825
Ivan Lozano52767be2019-10-18 14:49:46 -0700826func (c *Module) InRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900827 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
828}
829
Ivan Lozano52767be2019-10-18 14:49:46 -0700830func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900831 return c.ModuleBase.InstallInRecovery()
832}
833
Jiyong Park25fc6a92018-11-18 18:02:45 +0900834func (c *Module) IsStubs() bool {
835 if library, ok := c.linker.(*libraryDecorator); ok {
836 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900837 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
838 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900839 }
840 return false
841}
842
843func (c *Module) HasStubsVariants() bool {
844 if library, ok := c.linker.(*libraryDecorator); ok {
845 return len(library.Properties.Stubs.Versions) > 0
846 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700847 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
848 return len(library.Properties.Stubs.Versions) > 0
849 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900850 return false
851}
852
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900853func (c *Module) bootstrap() bool {
854 return Bool(c.Properties.Bootstrap)
855}
856
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700857func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700858 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
859 if c.Target().NativeBridge == android.NativeBridgeEnabled {
860 return false
861 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700862 return c.linker != nil && c.linker.nativeCoverage()
863}
864
Jiyong Park73c54ee2019-10-22 20:31:18 +0900865func (c *Module) ExportedIncludeDirs() android.Paths {
866 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
867 return flagsProducer.exportedDirs()
868 }
Jiyong Park232e7852019-11-04 12:23:40 +0900869 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900870}
871
872func (c *Module) ExportedSystemIncludeDirs() android.Paths {
873 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
874 return flagsProducer.exportedSystemDirs()
875 }
Jiyong Park232e7852019-11-04 12:23:40 +0900876 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900877}
878
879func (c *Module) ExportedFlags() []string {
880 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
881 return flagsProducer.exportedFlags()
882 }
Jiyong Park232e7852019-11-04 12:23:40 +0900883 return nil
884}
885
886func (c *Module) ExportedDeps() android.Paths {
887 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
888 return flagsProducer.exportedDeps()
889 }
890 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900891}
892
Jiyong Parkf1194352019-02-25 11:05:47 +0900893func isBionic(name string) bool {
894 switch name {
Yuexi Ma31f36fb2019-11-07 18:37:18 +0000895 case "libc", "libm", "libdl", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900896 return true
897 }
898 return false
899}
900
Martin Stjernholm279de572019-09-10 23:18:20 +0100901func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700902 if name == "libclang_rt.hwasan-aarch64-android" {
903 return inList("hwaddress", config.SanitizeDevice())
904 }
905 return isBionic(name)
906}
907
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800908func (c *Module) XrefCcFiles() android.Paths {
909 return c.kytheFiles
910}
911
Colin Crossca860ac2016-01-04 14:34:37 -0800912type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700913 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800914 moduleContextImpl
915}
916
Colin Cross37047f12016-12-13 17:06:13 -0800917type depsContext struct {
918 android.BottomUpMutatorContext
919 moduleContextImpl
920}
921
Colin Crossca860ac2016-01-04 14:34:37 -0800922type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700923 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800924 moduleContextImpl
925}
926
Jiyong Park2db76922017-11-08 16:03:48 +0900927func (ctx *moduleContext) SocSpecific() bool {
928 return ctx.ModuleContext.SocSpecific() ||
Ivan Lozano52767be2019-10-18 14:49:46 -0700929 (ctx.mod.HasVendorVariant() && ctx.mod.UseVndk() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700930}
931
Colin Crossca860ac2016-01-04 14:34:37 -0800932type moduleContextImpl struct {
933 mod *Module
934 ctx BaseModuleContext
935}
936
Colin Crossb98c8b02016-07-29 13:44:28 -0700937func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800938 return ctx.mod.toolchain(ctx.ctx)
939}
940
941func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000942 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800943}
944
945func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900946 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800947}
948
Jiyong Park1d1119f2019-07-29 21:27:18 +0900949func (ctx *moduleContextImpl) header() bool {
950 return ctx.mod.header()
951}
952
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700953func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800954 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800955 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700956 }
957 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800958}
959
960func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700961 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700962 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900963 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700964 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900965 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
966 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
967 return "current"
968 }
969 return platform_vndk_ver
970 }
971 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800972 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900973 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700974 }
975 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800976}
977
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700978func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700979 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700980}
Justin Yun8effde42017-06-23 19:24:43 +0900981
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800982func (ctx *moduleContextImpl) isNdk() bool {
983 return ctx.mod.isNdk()
984}
985
Inseob Kim9516ee92019-05-09 10:56:13 +0900986func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
987 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800988}
989
Inseob Kim9516ee92019-05-09 10:56:13 +0900990func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
991 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800992}
993
Inseob Kim9516ee92019-05-09 10:56:13 +0900994func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
995 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800996}
997
Logan Chienf3511742017-10-31 18:04:35 +0800998func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700999 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001000}
1001
Yi Kong7e53c572018-02-14 18:16:12 +08001002func (ctx *moduleContextImpl) isPgoCompile() bool {
1003 return ctx.mod.isPgoCompile()
1004}
1005
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001006func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1007 return ctx.mod.isNDKStubLibrary()
1008}
1009
Justin Yun8effde42017-06-23 19:24:43 +09001010func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001011 return ctx.mod.isVndkSp()
1012}
1013
1014func (ctx *moduleContextImpl) isVndkExt() bool {
1015 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001016}
1017
Vic Yangefd249e2018-11-12 20:19:56 -08001018func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001019 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001020}
1021
Jiyong Parkf9332f12018-02-01 00:54:12 +09001022func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001023 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001024}
1025
Logan Chien2f2b8902018-07-10 15:01:19 +08001026// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001027func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001028 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1029 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001030 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001031
1032 if ctx.ctx.Fuchsia() {
1033 return false
1034 }
1035
Logan Chien2f2b8902018-07-10 15:01:19 +08001036 if sanitize := ctx.mod.sanitize; sanitize != nil {
1037 if !sanitize.isVariantOnProductionDevice() {
1038 return false
1039 }
1040 }
1041 if !ctx.ctx.Device() {
1042 // Host modules do not need ABI dumps.
1043 return false
1044 }
Logan Chienfa478c02018-12-28 16:25:39 +08001045 if !ctx.mod.IsForPlatform() {
1046 // APEX variants do not need ABI dumps.
1047 return false
1048 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001049 if ctx.isStubs() {
1050 // Stubs do not need ABI dumps.
1051 return false
1052 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001053 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001054}
1055
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001056func (ctx *moduleContextImpl) selectedStl() string {
1057 if stl := ctx.mod.stl; stl != nil {
1058 return stl.Properties.SelectedStl
1059 }
1060 return ""
1061}
1062
Ivan Lozanobd721262018-11-27 14:33:03 -08001063func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1064 return ctx.mod.linker.useClangLld(actx)
1065}
1066
Colin Crossce75d2c2016-10-06 16:12:58 -07001067func (ctx *moduleContextImpl) baseModuleName() string {
1068 return ctx.mod.ModuleBase.BaseModuleName()
1069}
1070
Logan Chienf3511742017-10-31 18:04:35 +08001071func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1072 return ctx.mod.getVndkExtendsModuleName()
1073}
1074
Jiyong Park58e364a2019-01-19 19:24:06 +09001075func (ctx *moduleContextImpl) apexName() string {
1076 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001077}
1078
Jiyong Parkb0788572018-12-20 22:10:17 +09001079func (ctx *moduleContextImpl) hasStubsVariants() bool {
1080 return ctx.mod.HasStubsVariants()
1081}
1082
1083func (ctx *moduleContextImpl) isStubs() bool {
1084 return ctx.mod.IsStubs()
1085}
1086
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001087func (ctx *moduleContextImpl) bootstrap() bool {
1088 return ctx.mod.bootstrap()
1089}
1090
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001091func (ctx *moduleContextImpl) nativeCoverage() bool {
1092 return ctx.mod.nativeCoverage()
1093}
1094
Colin Cross635c3b02016-05-18 15:37:25 -07001095func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001096 return &Module{
1097 hod: hod,
1098 multilib: multilib,
1099 }
1100}
1101
Colin Cross635c3b02016-05-18 15:37:25 -07001102func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001103 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001104 module.features = []feature{
1105 &tidyFeature{},
1106 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001107 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001108 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001109 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001110 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001111 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001112 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001113 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001114 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001115 return module
1116}
1117
Colin Crossce75d2c2016-10-06 16:12:58 -07001118func (c *Module) Prebuilt() *android.Prebuilt {
1119 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1120 return p.prebuilt()
1121 }
1122 return nil
1123}
1124
1125func (c *Module) Name() string {
1126 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001127 if p, ok := c.linker.(interface {
1128 Name(string) string
1129 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001130 name = p.Name(name)
1131 }
1132 return name
1133}
1134
Alex Light3d673592019-01-18 14:37:31 -08001135func (c *Module) Symlinks() []string {
1136 if p, ok := c.installer.(interface {
1137 symlinkList() []string
1138 }); ok {
1139 return p.symlinkList()
1140 }
1141 return nil
1142}
1143
Jeff Gaston294356f2017-09-27 17:05:30 -07001144// orderDeps reorders dependencies into a list such that if module A depends on B, then
1145// A will precede B in the resultant list.
1146// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001147// Note that directSharedDeps should be the analogous static library for each shared lib dep
1148func 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 -07001149 // If A depends on B, then
1150 // Every list containing A will also contain B later in the list
1151 // So, after concatenating all lists, the final instance of B will have come from the same
1152 // original list as the final instance of A
1153 // So, the final instance of B will be later in the concatenation than the final A
1154 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1155 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001156 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001157 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001158 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1159 }
1160 for _, dep := range directSharedDeps {
1161 orderedAllDeps = append(orderedAllDeps, dep)
1162 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001163 }
1164
Colin Crossb6715442017-10-24 11:13:31 -07001165 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001166
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001167 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001168 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001169 // resultant list to only what the caller has chosen to include in directStaticDeps
1170 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001171
1172 return orderedAllDeps, orderedDeclaredDeps
1173}
1174
Ivan Lozano183a3212019-10-18 14:18:45 -07001175func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001176 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001177 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001178 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1179 staticDepFiles := []android.Path{}
1180 for _, dep := range staticDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001181 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1182 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
Jeff Gaston294356f2017-09-27 17:05:30 -07001183 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001184 sharedDepFiles := []android.Path{}
1185 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001186 if sharedDep.HasStaticVariant() {
1187 staticAnalogue := sharedDep.GetStaticVariant()
1188 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1189 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001190 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001191 }
1192
1193 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001194 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1195 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001196
1197 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001198}
1199
Roland Levillainf89cd092019-07-29 16:22:59 +01001200func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1201 test, ok := c.linker.(testPerSrc)
1202 return ok && test.isAllTestsVariation()
1203}
1204
Colin Cross635c3b02016-05-18 15:37:25 -07001205func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001206 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001207 //
1208 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1209 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1210 // module and return early, as this module does not produce an output file per se.
1211 if c.IsTestPerSrcAllTestsVariation() {
1212 c.outputFile = android.OptionalPath{}
1213 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001214 }
1215
Jooyung Han38002912019-05-16 04:01:54 +09001216 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001217
Inseob Kim64c43952019-08-26 16:52:35 +09001218 c.Properties.SubName = ""
1219
1220 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1221 c.Properties.SubName += nativeBridgeSuffix
1222 }
1223
1224 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
1225 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1226 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1227 c.Properties.SubName += vendorSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001228 } else if _, ok := c.linker.(*llndkStubDecorator); ok || (c.UseVndk() && c.HasVendorVariant()) {
Inseob Kim64c43952019-08-26 16:52:35 +09001229 // .vendor.{version} suffix is added only when we will have two variants: core and vendor.
1230 // The suffix is not added for vendor-only module.
1231 c.Properties.SubName += vendorSuffix
1232 vendorVersion := actx.DeviceConfig().VndkVersion()
1233 if vendorVersion == "current" {
1234 vendorVersion = actx.DeviceConfig().PlatformVndkVersion()
1235 }
1236 if c.Properties.VndkVersion != vendorVersion {
1237 c.Properties.SubName += "." + c.Properties.VndkVersion
1238 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001239 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001240 c.Properties.SubName += recoverySuffix
1241 }
1242
Colin Crossca860ac2016-01-04 14:34:37 -08001243 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001244 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001245 moduleContextImpl: moduleContextImpl{
1246 mod: c,
1247 },
1248 }
1249 ctx.ctx = ctx
1250
Colin Crossf18e1102017-11-16 14:33:08 -08001251 deps := c.depsToPaths(ctx)
1252 if ctx.Failed() {
1253 return
1254 }
1255
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001256 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1257 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1258 }
1259
Colin Crossca860ac2016-01-04 14:34:37 -08001260 flags := Flags{
1261 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001262 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001263 }
Colin Crossca860ac2016-01-04 14:34:37 -08001264 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001265 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001266 }
1267 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001268 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001269 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001270 if c.stl != nil {
1271 flags = c.stl.flags(ctx, flags)
1272 }
Colin Cross16b23492016-01-06 14:41:07 -08001273 if c.sanitize != nil {
1274 flags = c.sanitize.flags(ctx, flags)
1275 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001276 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001277 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001278 }
Stephen Craneba090d12017-05-09 15:44:35 -07001279 if c.lto != nil {
1280 flags = c.lto.flags(ctx, flags)
1281 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001282 if c.pgo != nil {
1283 flags = c.pgo.flags(ctx, flags)
1284 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001285 if c.xom != nil {
1286 flags = c.xom.flags(ctx, flags)
1287 }
Colin Crossca860ac2016-01-04 14:34:37 -08001288 for _, feature := range c.features {
1289 flags = feature.flags(ctx, flags)
1290 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001291 if ctx.Failed() {
1292 return
1293 }
1294
Colin Cross4af21ed2019-11-04 09:37:55 -08001295 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1296 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1297 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001298
Colin Cross4af21ed2019-11-04 09:37:55 -08001299 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001300
1301 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001302 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001303 }
1304 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001305 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001306 }
1307
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001308 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001309 // We need access to all the flags seen by a source file.
1310 if c.sabi != nil {
1311 flags = c.sabi.flags(ctx, flags)
1312 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001313
Colin Cross4af21ed2019-11-04 09:37:55 -08001314 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001315
Colin Crossca860ac2016-01-04 14:34:37 -08001316 // Optimization to reduce size of build.ninja
1317 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001318 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1319 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1320 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1321 flags.Local.CFlags = []string{"$cflags"}
1322 flags.Local.CppFlags = []string{"$cppflags"}
1323 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001324
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001325 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001326 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001327 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001328 if ctx.Failed() {
1329 return
1330 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001331 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001332 }
1333
Colin Crossca860ac2016-01-04 14:34:37 -08001334 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001335 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001336 if ctx.Failed() {
1337 return
1338 }
Colin Cross635c3b02016-05-18 15:37:25 -07001339 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001340
1341 // If a lib is directly included in any of the APEXes, unhide the stubs
1342 // variant having the latest version gets visible to make. In addition,
1343 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1344 // force anything in the make world to link against the stubs library.
1345 // (unless it is explicitly referenced via .bootstrap suffix or the
1346 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001347 if c.HasStubsVariants() &&
1348 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001349 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001350 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001351 c.Properties.HideFromMake = false // unhide
1352 // Note: this is still non-installable
1353 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001354 }
Colin Cross5049f022015-03-18 13:28:46 -07001355
Inseob Kim1f086e22019-05-09 13:29:15 +09001356 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001357 c.installer.install(ctx, c.outputFile.Path())
1358 if ctx.Failed() {
1359 return
Colin Crossca860ac2016-01-04 14:34:37 -08001360 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001361 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001362}
1363
Colin Cross0ea8ba82019-06-06 14:33:29 -07001364func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001365 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001366 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001367 }
Colin Crossca860ac2016-01-04 14:34:37 -08001368 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001369}
1370
Colin Crossca860ac2016-01-04 14:34:37 -08001371func (c *Module) begin(ctx BaseModuleContext) {
1372 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001373 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001374 }
Colin Crossca860ac2016-01-04 14:34:37 -08001375 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001376 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001377 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001378 if c.stl != nil {
1379 c.stl.begin(ctx)
1380 }
Colin Cross16b23492016-01-06 14:41:07 -08001381 if c.sanitize != nil {
1382 c.sanitize.begin(ctx)
1383 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001384 if c.coverage != nil {
1385 c.coverage.begin(ctx)
1386 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001387 if c.sabi != nil {
1388 c.sabi.begin(ctx)
1389 }
Justin Yun8effde42017-06-23 19:24:43 +09001390 if c.vndkdep != nil {
1391 c.vndkdep.begin(ctx)
1392 }
Stephen Craneba090d12017-05-09 15:44:35 -07001393 if c.lto != nil {
1394 c.lto.begin(ctx)
1395 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001396 if c.pgo != nil {
1397 c.pgo.begin(ctx)
1398 }
Colin Crossca860ac2016-01-04 14:34:37 -08001399 for _, feature := range c.features {
1400 feature.begin(ctx)
1401 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001402 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001403 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001404 if err != nil {
1405 ctx.PropertyErrorf("sdk_version", err.Error())
1406 }
Nan Zhang0007d812017-11-07 10:57:05 -08001407 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001408 }
Colin Crossca860ac2016-01-04 14:34:37 -08001409}
1410
Colin Cross37047f12016-12-13 17:06:13 -08001411func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001412 deps := Deps{}
1413
1414 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001415 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001416 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001417 // Add the PGO dependency (the clang_rt.profile runtime library), which
1418 // sometimes depends on symbols from libgcc, before libgcc gets added
1419 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001420 if c.pgo != nil {
1421 deps = c.pgo.deps(ctx, deps)
1422 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001423 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001424 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001425 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001426 if c.stl != nil {
1427 deps = c.stl.deps(ctx, deps)
1428 }
Colin Cross16b23492016-01-06 14:41:07 -08001429 if c.sanitize != nil {
1430 deps = c.sanitize.deps(ctx, deps)
1431 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001432 if c.coverage != nil {
1433 deps = c.coverage.deps(ctx, deps)
1434 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001435 if c.sabi != nil {
1436 deps = c.sabi.deps(ctx, deps)
1437 }
Justin Yun8effde42017-06-23 19:24:43 +09001438 if c.vndkdep != nil {
1439 deps = c.vndkdep.deps(ctx, deps)
1440 }
Stephen Craneba090d12017-05-09 15:44:35 -07001441 if c.lto != nil {
1442 deps = c.lto.deps(ctx, deps)
1443 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001444 for _, feature := range c.features {
1445 deps = feature.deps(ctx, deps)
1446 }
1447
Colin Crossb6715442017-10-24 11:13:31 -07001448 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1449 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1450 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1451 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1452 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1453 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001454 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001455
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001456 for _, lib := range deps.ReexportSharedLibHeaders {
1457 if !inList(lib, deps.SharedLibs) {
1458 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1459 }
1460 }
1461
1462 for _, lib := range deps.ReexportStaticLibHeaders {
1463 if !inList(lib, deps.StaticLibs) {
1464 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1465 }
1466 }
1467
Colin Cross5950f382016-12-13 12:50:57 -08001468 for _, lib := range deps.ReexportHeaderLibHeaders {
1469 if !inList(lib, deps.HeaderLibs) {
1470 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1471 }
1472 }
1473
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001474 for _, gen := range deps.ReexportGeneratedHeaders {
1475 if !inList(gen, deps.GeneratedHeaders) {
1476 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1477 }
1478 }
1479
Colin Crossc99deeb2016-04-11 15:06:20 -07001480 return deps
1481}
1482
Dan Albert7e9d2952016-08-04 13:02:36 -07001483func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001484 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001485 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001486 moduleContextImpl: moduleContextImpl{
1487 mod: c,
1488 },
1489 }
1490 ctx.ctx = ctx
1491
Colin Crossca860ac2016-01-04 14:34:37 -08001492 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001493}
1494
Jiyong Park7ed9de32018-10-15 22:25:07 +09001495// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001496func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001497 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1498 version := name[sharp+1:]
1499 libname := name[:sharp]
1500 return libname, version
1501 }
1502 return name, ""
1503}
1504
Colin Cross1e676be2016-10-12 14:38:15 -07001505func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001506 ctx := &depsContext{
1507 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001508 moduleContextImpl: moduleContextImpl{
1509 mod: c,
1510 },
1511 }
1512 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001513
Colin Crossc99deeb2016-04-11 15:06:20 -07001514 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001515
Dan Albert914449f2016-06-17 16:45:24 -07001516 variantNdkLibs := []string{}
1517 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001518 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001519 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001520
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001521 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1522 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001523 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001524 // 1. Name of an NDK library that refers to a prebuilt module.
1525 // For each of these, it adds the name of the prebuilt module (which will be in
1526 // prebuilts/ndk) to the list of nonvariant libs.
1527 // 2. Name of an NDK library that refers to an ndk_library module.
1528 // For each of these, it adds the name of the ndk_library module to the list of
1529 // variant libs.
1530 // 3. Anything else (so anything that isn't an NDK library).
1531 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001532 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001533 // The caller can then know to add the variantLibs dependencies differently from the
1534 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001535
Inseob Kim9516ee92019-05-09 10:56:13 +09001536 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001537 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1538 variantLibs = []string{}
1539 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001540 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001541 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001542 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001543 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1544 if !inList(name, ndkMigratedLibs) {
1545 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001546 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001547 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001548 }
Jooyung Han0302a842019-10-30 18:43:49 +09001549 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001550 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001551 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001552 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001553 if actx.OtherModuleExists(vendorPublicLib) {
1554 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1555 } else {
1556 // This can happen if vendor_public_library module is defined in a
1557 // namespace that isn't visible to the current module. In that case,
1558 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001559 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001560 }
Dan Albert914449f2016-06-17 16:45:24 -07001561 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001562 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001563 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001564 }
1565 }
Dan Albert914449f2016-06-17 16:45:24 -07001566 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001567 }
1568
Dan Albert914449f2016-06-17 16:45:24 -07001569 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1570 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001571 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001572 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001573
Jiyong Park7e636d02019-01-28 16:16:54 +09001574 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001575 if c.linker != nil {
1576 if library, ok := c.linker.(*libraryDecorator); ok {
1577 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001578 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001579 }
1580 }
1581 }
1582
Colin Cross32ec36c2016-12-15 07:39:51 -08001583 for _, lib := range deps.HeaderLibs {
1584 depTag := headerDepTag
1585 if inList(lib, deps.ReexportHeaderLibHeaders) {
1586 depTag = headerExportDepTag
1587 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001588 if buildStubs {
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001589 actx.AddFarVariationDependencies(append(ctx.Target().Variations(),
1590 blueprint.Variation{Mutator: "image", Variation: c.imageVariation()}),
1591 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001592 } else {
1593 actx.AddVariationDependencies(nil, depTag, lib)
1594 }
1595 }
1596
1597 if buildStubs {
1598 // Stubs lib does not have dependency to other static/shared libraries.
1599 // Don't proceed.
1600 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001601 }
Colin Cross5950f382016-12-13 12:50:57 -08001602
Inseob Kimc0907f12019-02-08 21:00:45 +09001603 syspropImplLibraries := syspropImplLibraries(actx.Config())
1604
Jiyong Park5d1598f2019-02-25 22:14:17 +09001605 for _, lib := range deps.WholeStaticLibs {
1606 depTag := wholeStaticDepTag
1607 if impl, ok := syspropImplLibraries[lib]; ok {
1608 lib = impl
1609 }
1610 actx.AddVariationDependencies([]blueprint.Variation{
1611 {Mutator: "link", Variation: "static"},
1612 }, depTag, lib)
1613 }
1614
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001615 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001616 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001617 if inList(lib, deps.ReexportStaticLibHeaders) {
1618 depTag = staticExportDepTag
1619 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001620
1621 if impl, ok := syspropImplLibraries[lib]; ok {
1622 lib = impl
1623 }
1624
Dan Willemsen59339a22018-07-22 21:18:45 -07001625 actx.AddVariationDependencies([]blueprint.Variation{
1626 {Mutator: "link", Variation: "static"},
1627 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001628 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001629
Dan Willemsen59339a22018-07-22 21:18:45 -07001630 actx.AddVariationDependencies([]blueprint.Variation{
1631 {Mutator: "link", Variation: "static"},
1632 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001633
Ivan Lozano183a3212019-10-18 14:18:45 -07001634 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001635 var variations []blueprint.Variation
1636 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Ivan Lozano52767be2019-10-18 14:49:46 -07001637 versionVariantAvail := !ctx.useVndk() && !c.InRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001638 if version != "" && versionVariantAvail {
1639 // Version is explicitly specified. i.e. libFoo#30
1640 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001641 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001642 }
1643 actx.AddVariationDependencies(variations, depTag, name)
1644
1645 // If the version is not specified, add dependency to the latest stubs library.
1646 // The stubs library will be used when the depending module is built for APEX and
1647 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001648 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001649 if version == "" && latestVersion != "" && versionVariantAvail {
1650 actx.AddVariationDependencies([]blueprint.Variation{
1651 {Mutator: "link", Variation: "shared"},
1652 {Mutator: "version", Variation: latestVersion},
1653 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001654 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001655 }
1656 }
1657
Jiyong Park7ed9de32018-10-15 22:25:07 +09001658 // shared lib names without the #version suffix
1659 var sharedLibNames []string
1660
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001661 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001662 depTag := SharedDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001663 if inList(lib, deps.ReexportSharedLibHeaders) {
1664 depTag = sharedExportDepTag
1665 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001666
1667 if impl, ok := syspropImplLibraries[lib]; ok {
1668 lib = impl
1669 }
1670
Jiyong Park73c54ee2019-10-22 20:31:18 +09001671 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001672 sharedLibNames = append(sharedLibNames, name)
1673
Jiyong Park25fc6a92018-11-18 18:02:45 +09001674 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001675 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001676
Jiyong Park7ed9de32018-10-15 22:25:07 +09001677 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001678 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001679 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1680 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1681 // linking against both the stubs lib and the non-stubs lib at the same time.
1682 continue
1683 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001684 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001685 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001686
Dan Willemsen59339a22018-07-22 21:18:45 -07001687 actx.AddVariationDependencies([]blueprint.Variation{
1688 {Mutator: "link", Variation: "shared"},
1689 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001690
Colin Cross68861832016-07-08 10:41:41 -07001691 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001692
1693 for _, gen := range deps.GeneratedHeaders {
1694 depTag := genHeaderDepTag
1695 if inList(gen, deps.ReexportGeneratedHeaders) {
1696 depTag = genHeaderExportDepTag
1697 }
1698 actx.AddDependency(c, depTag, gen)
1699 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001700
Colin Cross42d48b72018-08-29 14:10:52 -07001701 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001702
1703 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001704 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001705 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001706 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001707 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001708 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001709 if deps.LinkerFlagsFile != "" {
1710 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1711 }
1712 if deps.DynamicLinker != "" {
1713 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001714 }
Dan Albert914449f2016-06-17 16:45:24 -07001715
1716 version := ctx.sdkVersion()
1717 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001718 {Mutator: "ndk_api", Variation: version},
1719 {Mutator: "link", Variation: "shared"},
1720 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001721 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001722 {Mutator: "ndk_api", Variation: version},
1723 {Mutator: "link", Variation: "shared"},
1724 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001725
1726 if vndkdep := c.vndkdep; vndkdep != nil {
1727 if vndkdep.isVndkExt() {
Inseob Kim64c43952019-08-26 16:52:35 +09001728 var baseModuleMode string
Logan Chienf3511742017-10-31 18:04:35 +08001729 if actx.DeviceConfig().VndkVersion() == "" {
1730 baseModuleMode = coreMode
Inseob Kim64c43952019-08-26 16:52:35 +09001731 } else {
1732 baseModuleMode = c.imageVariation()
Logan Chienf3511742017-10-31 18:04:35 +08001733 }
1734 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001735 {Mutator: "image", Variation: baseModuleMode},
1736 {Mutator: "link", Variation: "shared"},
1737 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001738 }
1739 }
Colin Cross6362e272015-10-29 15:25:03 -07001740}
Colin Cross21b9a242015-03-24 14:15:58 -07001741
Colin Crosse40b4ea2018-10-02 22:25:58 -07001742func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001743 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1744 c.beginMutator(ctx)
1745 }
1746}
1747
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001748// Whether a module can link to another module, taking into
1749// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001750func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1751 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001752 // Host code is not restricted
1753 return
1754 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001755
1756 // VNDK is cc.Module supported only for now.
1757 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001758 // Though vendor code is limited by the vendor mutator,
1759 // each vendor-available module needs to check
1760 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001761 if ccTo, ok := to.(*Module); ok {
1762 if ccFrom.vndkdep != nil {
1763 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1764 }
1765 } else {
1766 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001767 }
1768 return
1769 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001770 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001771 // Platform code can link to anything
1772 return
1773 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001774 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001775 // Recovery code is not NDK
1776 return
1777 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001778 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001779 // These are always allowed
1780 return
1781 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001782 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001783 // These are allowed, but they don't set sdk_version
1784 return
1785 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001786 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001787 // These aren't real libraries, but are the stub shared libraries that are included in
1788 // the NDK.
1789 return
1790 }
Logan Chien834b9a62019-01-14 15:39:03 +08001791
Ivan Lozano52767be2019-10-18 14:49:46 -07001792 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001793 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1794 // to link to libc++ (non-NDK and without sdk_version).
1795 return
1796 }
1797
Ivan Lozano52767be2019-10-18 14:49:46 -07001798 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001799 // NDK code linking to platform code is never okay.
1800 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001801 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001802 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001803 }
1804
1805 // At this point we know we have two NDK libraries, but we need to
1806 // check that we're not linking against anything built against a higher
1807 // API level, as it is only valid to link against older or equivalent
1808 // APIs.
1809
Inseob Kim01a28722018-04-11 09:48:45 +09001810 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001811 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001812 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001813 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001814 // Current can't be linked against by anything else.
1815 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001816 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001817 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001818 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001819 if err != nil {
1820 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001821 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001822 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001823 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001824 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001825 if err != nil {
1826 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001827 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001828 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001829 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001830
Inseob Kim01a28722018-04-11 09:48:45 +09001831 if toApi > fromApi {
1832 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001833 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001834 }
1835 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001836 }
Dan Albert202fe492017-12-15 13:56:59 -08001837
1838 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001839 fromStl := from.SelectedStl()
1840 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001841 if fromStl == "" || toStl == "" {
1842 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001843 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001844 // We can be permissive with the system "STL" since it is only the C++
1845 // ABI layer, but in the future we should make sure that everyone is
1846 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001847 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001848 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001849 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1850 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001851 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001852}
1853
Jiyong Park5fb8c102018-04-09 12:03:06 +09001854// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001855// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1856// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001857// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001858func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1859 check := func(child, parent android.Module) bool {
1860 to, ok := child.(*Module)
1861 if !ok {
1862 // follow thru cc.Defaults, etc.
1863 return true
1864 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001865
Jooyung Hana70f0672019-01-18 15:20:43 +09001866 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1867 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001868 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001869
1870 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001871 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001872 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001873 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001874
Jooyung Han0302a842019-10-30 18:43:49 +09001875 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001876 return false
1877 }
1878
1879 var stringPath []string
1880 for _, m := range ctx.GetWalkPath() {
1881 stringPath = append(stringPath, m.Name())
1882 }
1883 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1884 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1885 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1886 return false
1887 }
1888 if module, ok := ctx.Module().(*Module); ok {
1889 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09001890 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001891 ctx.WalkDeps(check)
1892 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001893 }
1894 }
1895}
1896
Colin Crossc99deeb2016-04-11 15:06:20 -07001897// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001898func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001899 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001900
Ivan Lozano183a3212019-10-18 14:18:45 -07001901 directStaticDeps := []LinkableInterface{}
1902 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001903
Inseob Kim9516ee92019-05-09 10:56:13 +09001904 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1905
Inseob Kim69378442019-06-03 19:10:47 +09001906 reexportExporter := func(exporter exportedFlagsProducer) {
1907 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1908 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1909 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1910 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1911 }
1912
Colin Crossd11fcda2017-10-23 17:59:01 -07001913 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001914 depName := ctx.OtherModuleName(dep)
1915 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001916
Ivan Lozano52767be2019-10-18 14:49:46 -07001917 ccDep, ok := dep.(LinkableInterface)
1918 if !ok {
1919
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001920 // handling for a few module types that aren't cc Module but that are also supported
1921 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001922 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001923 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001924 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1925 genRule.GeneratedSourceFiles()...)
1926 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001927 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001928 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001929 // Support exported headers from a generated_sources dependency
1930 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001931 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001932 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001933 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001934 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09001935 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09001936 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001937 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001938 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1939 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001940 // 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 +09001941 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001942
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001943 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001944 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001945 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001946 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001947 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001948 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001949 files := genRule.GeneratedSourceFiles()
1950 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001951 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001952 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001953 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 -07001954 }
1955 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001956 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001957 }
Colin Crossca860ac2016-01-04 14:34:37 -08001958 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001959 return
1960 }
1961
Colin Crossfe17f6f2019-03-28 19:30:56 -07001962 if depTag == android.ProtoPluginDepTag {
1963 return
1964 }
1965
Colin Crossd11fcda2017-10-23 17:59:01 -07001966 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001967 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1968 return
1969 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001970 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001971 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001972 return
1973 }
1974
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001975 // re-exporting flags
1976 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001977 // reusing objects only make sense for cc.Modules.
1978 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001979 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07001980 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001981 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001982 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001983 return
1984 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001985 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001986
Jiyong Parke4bb9862019-02-01 00:31:10 +09001987 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07001988 // staticVariants are a cc.Module specific concept.
1989 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09001990 c.staticVariant = ccDep
1991 return
1992 }
1993 }
1994
Ivan Lozano183a3212019-10-18 14:18:45 -07001995 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
1996 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
1997 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001998 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07001999 if t, ok := depTag.(DependencyTag); ok {
2000 explicitlyVersioned = t.ExplicitlyVersioned
2001 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002002 depTag = t
2003 }
2004
Ivan Lozano183a3212019-10-18 14:18:45 -07002005 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002006 depIsStatic := false
2007 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002008 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002009 depIsStatic = true
2010 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002011 if ccDep.CcLibrary() && !depIsStatic {
2012 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002013 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002014 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002015 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002016
2017 var useThisDep bool
2018 if depIsStubs && explicitlyVersioned {
2019 // Always respect dependency to the versioned stubs (i.e. libX#10)
2020 useThisDep = true
2021 } else if !depHasStubs {
2022 // Use non-stub variant if that is the only choice
2023 // (i.e. depending on a lib without stubs.version property)
2024 useThisDep = true
2025 } else if c.IsForPlatform() {
2026 // If not building for APEX, use stubs only when it is from
2027 // an APEX (and not from platform)
2028 useThisDep = (depInPlatform != depIsStubs)
Ivan Lozano52767be2019-10-18 14:49:46 -07002029 if c.InRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09002030 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002031 // always link to non-stub variant
2032 useThisDep = !depIsStubs
2033 }
2034 } else {
2035 // If building for APEX, use stubs only when it is not from
2036 // the same APEX
2037 useThisDep = (depInSameApex != depIsStubs)
2038 }
2039
2040 if !useThisDep {
2041 return // stop processing this dep
2042 }
2043 }
2044
Ivan Lozano52767be2019-10-18 14:49:46 -07002045 // Exporting flags only makes sense for cc.Modules
2046 if _, ok := ccDep.(*Module); ok {
2047 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
2048 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
2049 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
2050 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
2051 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002052
Ivan Lozano52767be2019-10-18 14:49:46 -07002053 if t.ReexportFlags {
2054 reexportExporter(i)
2055 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2056 // Re-exported shared library headers must be included as well since they can help us with type information
2057 // about template instantiations (instantiated from their headers).
2058 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2059 // scripts.
2060 c.sabi.Properties.ReexportedIncludes = append(
2061 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2062 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002063 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002064 }
Logan Chienf3511742017-10-31 18:04:35 +08002065 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002066 }
2067
Colin Cross26c34ed2016-09-30 17:10:16 -07002068 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002069 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002070
Ivan Lozano52767be2019-10-18 14:49:46 -07002071 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002072 depFile := android.OptionalPath{}
2073
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002074 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002075 case ndkStubDepTag, SharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002076 ptr = &depPaths.SharedLibs
2077 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002078 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002079 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002080
Jiyong Park64a44f22019-01-18 14:37:08 +09002081 case earlySharedDepTag:
2082 ptr = &depPaths.EarlySharedLibs
2083 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002084 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002085 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002086 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002087 ptr = &depPaths.LateSharedLibs
2088 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002089 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002090 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002091 ptr = nil
2092 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002093 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002094 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002095 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002096 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002097 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002098 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002099 return
2100 }
2101
Ivan Lozano52767be2019-10-18 14:49:46 -07002102 // Because the static library objects are included, this only makes sense
2103 // in the context of proper cc.Modules.
2104 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2105 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2106 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2107 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2108 for i := range missingDeps {
2109 missingDeps[i] += postfix
2110 }
2111 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002112 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002113 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2114 } else {
2115 ctx.ModuleErrorf(
2116 "non-cc.Modules cannot be included as whole static libraries.", depName)
2117 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002118 }
Colin Cross5950f382016-12-13 12:50:57 -08002119 case headerDepTag:
2120 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002121 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002122 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002123 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002124 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002125 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002126 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002127 case dynamicLinkerDepTag:
2128 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002129 }
2130
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002131 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002132 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002133 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002134 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002135 return
2136 }
2137
2138 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002139 // in static libraries act as if they were whole static libraries. The same goes for
2140 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002141 // This should only be done for cc.Modules
2142 if c, ok := ccDep.(*Module); ok {
2143 staticLib := c.linker.(libraryInterface)
2144 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2145 staticLib.objs().coverageFiles...)
2146 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2147 staticLib.objs().sAbiDumpFiles...)
2148 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002149 }
2150
Colin Cross26c34ed2016-09-30 17:10:16 -07002151 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002152 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002153 if !ctx.Config().AllowMissingDependencies() {
2154 ctx.ModuleErrorf("module %q missing output file", depName)
2155 } else {
2156 ctx.AddMissingDependencies([]string{depName})
2157 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002158 return
2159 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002160 *ptr = append(*ptr, linkFile.Path())
2161 }
2162
Colin Crossc99deeb2016-04-11 15:06:20 -07002163 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002164 dep := depFile
2165 if !dep.Valid() {
2166 dep = linkFile
2167 }
2168 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002169 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002170
Logan Chien43d34c32017-12-20 01:17:32 +08002171 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002172 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002173 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002174 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002175 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002176 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002177 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002178
Ivan Lozano52767be2019-10-18 14:49:46 -07002179 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002180 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2181 // core module instead.
2182 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002183 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002184 // The vendor module in Make will have been renamed to not conflict with the core
2185 // module, so update the dependency name here accordingly.
Inseob Kim64c43952019-08-26 16:52:35 +09002186 ret := libName + vendorSuffix
2187 vendorVersion := ctx.DeviceConfig().VndkVersion()
2188 if vendorVersion == "current" {
2189 vendorVersion = ctx.DeviceConfig().PlatformVndkVersion()
2190 }
2191 if c.Properties.VndkVersion != vendorVersion {
2192 ret += "." + c.Properties.VndkVersion
2193 }
2194 return ret
Jiyong Park374510b2018-03-19 18:23:01 +09002195 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002196 return libName + vendorPublicLibrarySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002197 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002198 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002199 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002200 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002201 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002202 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002203 }
Logan Chien43d34c32017-12-20 01:17:32 +08002204 }
2205
2206 // Export the shared libs to Make.
2207 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002208 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002209 if ccDep.CcLibrary() {
2210 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002211 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002212 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002213 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002214 c.Properties.ApexesProvidingSharedLibs = append(
2215 c.Properties.ApexesProvidingSharedLibs, an)
2216 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002217 }
2218 }
2219
Jiyong Park27b188b2017-07-18 13:23:39 +09002220 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002221 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002222 c.Properties.AndroidMkSharedLibs = append(
2223 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002224 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002225 c.Properties.AndroidMkSharedLibs = append(
2226 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002227 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002228 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002229 c.Properties.AndroidMkStaticLibs = append(
2230 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002231 case runtimeDepTag:
2232 c.Properties.AndroidMkRuntimeLibs = append(
2233 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002234 case wholeStaticDepTag:
2235 c.Properties.AndroidMkWholeStaticLibs = append(
2236 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002237 }
Colin Crossca860ac2016-01-04 14:34:37 -08002238 })
2239
Jeff Gaston294356f2017-09-27 17:05:30 -07002240 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002241 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002242
Colin Crossdd84e052017-05-17 13:44:16 -07002243 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002244 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002245 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2246 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002247 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Jiyong Park74955042019-10-22 20:19:51 +09002248 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2249 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002250 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002251 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002252
2253 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002254 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002255 }
Colin Crossdd84e052017-05-17 13:44:16 -07002256
Colin Crossca860ac2016-01-04 14:34:37 -08002257 return depPaths
2258}
2259
2260func (c *Module) InstallInData() bool {
2261 if c.installer == nil {
2262 return false
2263 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002264 return c.installer.inData()
2265}
2266
2267func (c *Module) InstallInSanitizerDir() bool {
2268 if c.installer == nil {
2269 return false
2270 }
2271 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002272 return true
2273 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002274 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002275}
2276
Jiyong Parkf9332f12018-02-01 00:54:12 +09002277func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002278 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002279}
2280
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002281func (c *Module) HostToolPath() android.OptionalPath {
2282 if c.installer == nil {
2283 return android.OptionalPath{}
2284 }
2285 return c.installer.hostToolPath()
2286}
2287
Nan Zhangd4e641b2017-07-12 12:55:28 -07002288func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2289 return c.outputFile
2290}
2291
Colin Cross41955e82019-05-29 14:40:35 -07002292func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2293 switch tag {
2294 case "":
2295 if c.outputFile.Valid() {
2296 return android.Paths{c.outputFile.Path()}, nil
2297 }
2298 return android.Paths{}, nil
2299 default:
2300 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002301 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002302}
2303
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002304func (c *Module) static() bool {
2305 if static, ok := c.linker.(interface {
2306 static() bool
2307 }); ok {
2308 return static.static()
2309 }
2310 return false
2311}
2312
Jiyong Park379de2f2018-12-19 02:47:14 +09002313func (c *Module) staticBinary() bool {
2314 if static, ok := c.linker.(interface {
2315 staticBinary() bool
2316 }); ok {
2317 return static.staticBinary()
2318 }
2319 return false
2320}
2321
Jiyong Park1d1119f2019-07-29 21:27:18 +09002322func (c *Module) header() bool {
2323 if h, ok := c.linker.(interface {
2324 header() bool
2325 }); ok {
2326 return h.header()
2327 }
2328 return false
2329}
2330
Jooyung Han38002912019-05-16 04:01:54 +09002331func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002332 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002333 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2334 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002335 return "native:vndk"
2336 }
Jooyung Han38002912019-05-16 04:01:54 +09002337 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002338 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002339 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002340 if Bool(c.VendorProperties.Vendor_available) {
2341 return "native:vndk"
2342 }
2343 return "native:vndk_private"
2344 }
2345 return "native:vendor"
Ivan Lozano52767be2019-10-18 14:49:46 -07002346 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002347 return "native:recovery"
2348 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2349 return "native:ndk:none:none"
2350 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2351 //family, link := getNdkStlFamilyAndLinkType(c)
2352 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002353 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002354 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002355 } else {
2356 return "native:platform"
2357 }
2358}
2359
Jiyong Park9d452992018-10-03 00:38:19 +09002360// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002361// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002362func (c *Module) IsInstallableToApex() bool {
2363 if shared, ok := c.linker.(interface {
2364 shared() bool
2365 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002366 // Stub libs and prebuilt libs in a versioned SDK are not
2367 // installable to APEX even though they are shared libs.
2368 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002369 } else if _, ok := c.linker.(testPerSrc); ok {
2370 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002371 }
2372 return false
2373}
2374
Jiyong Parka90ca002019-10-07 15:47:24 +09002375func (c *Module) AvailableFor(what string) bool {
2376 if linker, ok := c.linker.(interface {
2377 availableFor(string) bool
2378 }); ok {
2379 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2380 } else {
2381 return c.ApexModuleBase.AvailableFor(what)
2382 }
2383}
2384
Inseob Kim1f086e22019-05-09 13:29:15 +09002385func (c *Module) installable() bool {
2386 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2387}
2388
Jiyong Park3b1746a2019-01-29 11:15:04 +09002389func (c *Module) imageVariation() string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002390 if c.UseVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002391 return vendorMode + "." + c.Properties.VndkVersion
Ivan Lozano52767be2019-10-18 14:49:46 -07002392 } else if c.InRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09002393 return recoveryMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002394 }
Inseob Kim64c43952019-08-26 16:52:35 +09002395 return coreMode
Jiyong Park3b1746a2019-01-29 11:15:04 +09002396}
2397
bralee3f49f4d2019-03-04 06:58:15 +08002398func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002399 outputFiles, err := c.OutputFiles("")
2400 if err != nil {
2401 panic(err)
2402 }
2403 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002404}
2405
Logan Chien41eabe62019-04-10 13:33:58 +08002406func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2407 if c.linker != nil {
2408 if library, ok := c.linker.(*libraryDecorator); ok {
2409 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2410 }
2411 }
2412}
2413
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002414func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002415 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
2416 if cc, ok := dep.(*Module); ok && cc.IsStubs() && depTag.Shared {
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002417 // dynamic dep to a stubs lib crosses APEX boundary
2418 return false
2419 }
2420 }
2421 return true
2422}
2423
Colin Cross2ba19d92015-05-07 15:44:20 -07002424//
Colin Crosscfad1192015-11-02 16:43:11 -08002425// Defaults
2426//
Colin Crossca860ac2016-01-04 14:34:37 -08002427type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002428 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002429 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002430 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002431}
2432
Patrice Arrudac249c712019-03-19 17:00:29 -07002433// cc_defaults provides a set of properties that can be inherited by other cc
2434// modules. A module can use the properties from a cc_defaults using
2435// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2436// merged (when possible) by prepending the default module's values to the
2437// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002438func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002439 return DefaultsFactory()
2440}
2441
Colin Cross36242852017-06-23 15:06:31 -07002442func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002443 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002444
Colin Cross36242852017-06-23 15:06:31 -07002445 module.AddProperties(props...)
2446 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002447 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002448 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002449 &BaseCompilerProperties{},
2450 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002451 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002452 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002453 &StaticProperties{},
2454 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002455 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002456 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002457 &TestProperties{},
2458 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002459 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002460 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002461 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002462 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002463 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002464 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002465 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002466 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002467 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002468 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002469 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002470 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002471 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002472 )
Colin Crosscfad1192015-11-02 16:43:11 -08002473
Jooyung Hancc372c52019-09-25 15:18:44 +09002474 android.InitDefaultsModule(module)
Jiyong Park7916bfc2019-09-30 19:13:12 +09002475 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002476
2477 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002478}
2479
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002480const (
2481 // coreMode is the variant used for framework-private libraries, or
2482 // SDK libraries. (which framework-private libraries can use)
2483 coreMode = "core"
2484
Inseob Kim64c43952019-08-26 16:52:35 +09002485 // vendorMode is the variant prefix used for /vendor code that compiles
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002486 // against the VNDK.
2487 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002488
2489 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002490)
2491
Jiyong Park6a43f042017-10-12 23:05:00 +09002492func squashVendorSrcs(m *Module) {
2493 if lib, ok := m.compiler.(*libraryDecorator); ok {
2494 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2495 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2496
2497 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2498 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2499 }
2500}
2501
Jiyong Parkf9332f12018-02-01 00:54:12 +09002502func squashRecoverySrcs(m *Module) {
2503 if lib, ok := m.compiler.(*libraryDecorator); ok {
2504 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2505 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2506
2507 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2508 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2509 }
2510}
2511
Jiyong Parkda6eb592018-12-19 17:12:36 +09002512func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002513 if mctx.Os() != android.Android {
2514 return
2515 }
2516
Jiyong Park7ed9de32018-10-15 22:25:07 +09002517 if g, ok := mctx.Module().(*genrule.Module); ok {
2518 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002519 var coreVariantNeeded bool = false
2520 var vendorVariantNeeded bool = false
2521 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002522 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002523 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002524 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002525 coreVariantNeeded = true
2526 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002527 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002528 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002529 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002530 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002531 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002532 if Bool(props.Recovery_available) {
2533 recoveryVariantNeeded = true
2534 }
2535
Jiyong Park413cc742018-06-19 01:46:06 +09002536 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002537 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002538 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002539 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002540 recoveryVariantNeeded = false
2541 }
2542 }
2543
Jiyong Park3f736c92018-05-24 13:36:56 +09002544 var variants []string
2545 if coreVariantNeeded {
2546 variants = append(variants, coreMode)
2547 }
2548 if vendorVariantNeeded {
Inseob Kim64c43952019-08-26 16:52:35 +09002549 variants = append(variants, vendorMode+"."+mctx.DeviceConfig().PlatformVndkVersion())
2550 if vndkVersion := mctx.DeviceConfig().VndkVersion(); vndkVersion != "current" {
2551 variants = append(variants, vendorMode+"."+vndkVersion)
2552 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002553 }
2554 if recoveryVariantNeeded {
2555 variants = append(variants, recoveryMode)
2556 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002557 mod := mctx.CreateVariations(variants...)
2558 for i, v := range variants {
2559 if v == recoveryMode {
2560 m := mod[i].(*genrule.Module)
2561 m.Extra.(*GenruleExtraProperties).InRecovery = true
2562 }
2563 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002564 }
2565 }
2566
Ivan Lozano52767be2019-10-18 14:49:46 -07002567 //TODO When LinkableInterface supports VNDK, this should be mctx.Module().(LinkableInterface)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002568 m, ok := mctx.Module().(*Module)
2569 if !ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002570 if linkable, ok := mctx.Module().(LinkableInterface); ok {
2571 variations := []string{coreMode}
2572 if linkable.InRecovery() {
2573 variations = append(variations, recoveryMode)
2574 }
2575 mctx.CreateVariations(variations...)
2576 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002577 return
2578 }
2579
2580 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002581 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002582 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002583
2584 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002585 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002586 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002587 return
2588 }
Logan Chienf3511742017-10-31 18:04:35 +08002589
2590 if vndkdep := m.vndkdep; vndkdep != nil {
2591 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002592 if productSpecific {
2593 mctx.PropertyErrorf("product_specific",
2594 "product_specific must not be true when `vndk: {enabled: true}`")
2595 return
2596 }
Logan Chienf3511742017-10-31 18:04:35 +08002597 if vendorSpecific {
2598 if !vndkdep.isVndkExt() {
2599 mctx.PropertyErrorf("vndk",
2600 "must set `extends: \"...\"` to vndk extension")
2601 return
2602 }
2603 } else {
2604 if vndkdep.isVndkExt() {
2605 mctx.PropertyErrorf("vndk",
2606 "must set `vendor: true` to set `extends: %q`",
2607 m.getVndkExtendsModuleName())
2608 return
2609 }
2610 if m.VendorProperties.Vendor_available == nil {
2611 mctx.PropertyErrorf("vndk",
2612 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2613 return
2614 }
2615 }
2616 } else {
2617 if vndkdep.isVndkSp() {
2618 mctx.PropertyErrorf("vndk",
2619 "must set `enabled: true` to set `support_system_process: true`")
2620 return
2621 }
2622 if vndkdep.isVndkExt() {
2623 mctx.PropertyErrorf("vndk",
2624 "must set `enabled: true` to set `extends: %q`",
2625 m.getVndkExtendsModuleName())
2626 return
2627 }
Justin Yun8effde42017-06-23 19:24:43 +09002628 }
2629 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002630
Jiyong Parkf9332f12018-02-01 00:54:12 +09002631 var coreVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002632 var recoveryVariantNeeded bool = false
2633
Inseob Kim64c43952019-08-26 16:52:35 +09002634 var vendorVariants []string
2635
2636 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
2637 deviceVndkVersion := mctx.DeviceConfig().VndkVersion()
2638 if deviceVndkVersion == "current" {
2639 deviceVndkVersion = platformVndkVersion
2640 }
2641
Justin Yun71549282017-11-17 12:10:28 +09002642 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002643 // If the device isn't compiling against the VNDK, we always
2644 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002645 coreVariantNeeded = true
Justin Yun1282f422019-09-09 14:42:44 +09002646 } else if m.Target().NativeBridge == android.NativeBridgeEnabled {
2647 // Skip creating vendor variants for natvie bridge modules
2648 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002649 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2650 // LL-NDK stubs only exist in the vendor variant, since the
2651 // real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002652 vendorVariants = append(vendorVariants,
2653 platformVndkVersion,
2654 deviceVndkVersion,
2655 )
Jiyong Park2a454122017-10-19 15:59:33 +09002656 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2657 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002658 vendorVariants = append(vendorVariants,
2659 platformVndkVersion,
2660 deviceVndkVersion,
2661 )
2662 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002663 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2664 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002665 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002666 } else if m.HasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002667 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002668 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002669 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002670 vendorVariants = append(vendorVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002671 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2672 // code is PLATFORM_VNDK_VERSION.
2673 // On the other hand, vendor_available modules which are not VNDK should
2674 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
2675 if !m.IsVndk() {
Inseob Kim64c43952019-08-26 16:52:35 +09002676 vendorVariants = append(vendorVariants, deviceVndkVersion)
2677 }
Logan Chienf3511742017-10-31 18:04:35 +08002678 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002679 // This will be available in /vendor (or /odm) only
Inseob Kim64c43952019-08-26 16:52:35 +09002680 vendorVariants = append(vendorVariants, deviceVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002681 } else {
2682 // This is either in /system (or similar: /data), or is a
2683 // modules built with the NDK. Modules built with the NDK
2684 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002685 coreVariantNeeded = true
2686 }
2687
2688 if Bool(m.Properties.Recovery_available) {
2689 recoveryVariantNeeded = true
2690 }
2691
2692 if m.ModuleBase.InstallInRecovery() {
2693 recoveryVariantNeeded = true
2694 coreVariantNeeded = false
2695 }
2696
Jiyong Park413cc742018-06-19 01:46:06 +09002697 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002698 primaryArch := mctx.Config().DevicePrimaryArchType()
2699 moduleArch := m.Target().Arch.ArchType
2700 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002701 recoveryVariantNeeded = false
2702 }
2703 }
2704
Jiyong Parkf9332f12018-02-01 00:54:12 +09002705 var variants []string
2706 if coreVariantNeeded {
2707 variants = append(variants, coreMode)
2708 }
Inseob Kim64c43952019-08-26 16:52:35 +09002709 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
2710 variants = append(variants, vendorMode+"."+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002711 }
2712 if recoveryVariantNeeded {
2713 variants = append(variants, recoveryMode)
2714 }
2715 mod := mctx.CreateVariations(variants...)
2716 for i, v := range variants {
Inseob Kim64c43952019-08-26 16:52:35 +09002717 if strings.HasPrefix(v, vendorMode+".") {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002718 m := mod[i].(*Module)
Inseob Kim64c43952019-08-26 16:52:35 +09002719 m.Properties.VndkVersion = strings.TrimPrefix(v, vendorMode+".")
Jiyong Parkf9332f12018-02-01 00:54:12 +09002720 squashVendorSrcs(m)
2721 } else if v == recoveryMode {
2722 m := mod[i].(*Module)
2723 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002724 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002725 squashRecoverySrcs(m)
2726 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002727 }
2728}
2729
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002730func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002731 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002732 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2733 }
Colin Cross6510f912017-11-29 00:27:14 -08002734 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002735}
2736
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002737func kytheExtractAllFactory() android.Singleton {
2738 return &kytheExtractAllSingleton{}
2739}
2740
2741type kytheExtractAllSingleton struct {
2742}
2743
2744func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2745 var xrefTargets android.Paths
2746 ctx.VisitAllModules(func(module android.Module) {
2747 if ccModule, ok := module.(xref); ok {
2748 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2749 }
2750 })
2751 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2752 if len(xrefTargets) > 0 {
2753 ctx.Build(pctx, android.BuildParams{
2754 Rule: blueprint.Phony,
2755 Output: android.PathForPhony(ctx, "xref_cxx"),
2756 Inputs: xrefTargets,
2757 //Default: true,
2758 })
2759 }
2760}
2761
Colin Cross06a931b2015-10-28 17:23:31 -07002762var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002763var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002764var BoolPtr = proptools.BoolPtr
2765var String = proptools.String
2766var StringPtr = proptools.StringPtr