blob: 54f21aa30584234e8ff8c102e8f820e662c45890 [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) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090041 ctx.BottomUp("vndk", VndkMutator).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
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000059 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
60 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
61
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080062 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
63 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
64
Colin Cross1e676be2016-10-12 14:38:15 -070065 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
66 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080067
Colin Cross0b908332019-06-19 23:00:20 -070068 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090069 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080070
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080071 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080072 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070073
74 ctx.TopDown("lto_deps", ltoDepsMutator)
75 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090076
77 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070078 })
Colin Crossb98c8b02016-07-29 13:44:28 -070079
Sasha Smundak2a4549e2018-11-05 16:49:08 -080080 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Crossb98c8b02016-07-29 13:44:28 -070081 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070082}
83
Colin Crossca860ac2016-01-04 14:34:37 -080084type Deps struct {
85 SharedLibs, LateSharedLibs []string
86 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080087 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080088 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070089
Colin Cross5950f382016-12-13 12:50:57 -080090 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070091
Colin Cross81413472016-04-11 14:37:39 -070092 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070093
Dan Willemsenb40aab62016-04-20 14:21:14 -070094 GeneratedSources []string
95 GeneratedHeaders []string
96
Dan Willemsenb3454ab2016-09-28 17:34:58 -070097 ReexportGeneratedHeaders []string
98
Colin Cross97ba0732015-03-23 17:50:24 -070099 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700100
101 // Used for host bionic
102 LinkerFlagsFile string
103 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700104}
105
Colin Crossca860ac2016-01-04 14:34:37 -0800106type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700107 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900108 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900110 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700111 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700112 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700113
Colin Cross26c34ed2016-09-30 17:10:16 -0700114 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700115 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800116 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700117 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700118
Colin Cross26c34ed2016-09-30 17:10:16 -0700119 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700120 GeneratedSources android.Paths
121 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700122
Inseob Kim69378442019-06-03 19:10:47 +0900123 Flags []string
124 IncludeDirs []string
125 SystemIncludeDirs []string
126 ReexportedDirs []string
127 ReexportedSystemDirs []string
128 ReexportedFlags []string
129 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700130
Colin Cross26c34ed2016-09-30 17:10:16 -0700131 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700132 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700133
134 // Path to the file container flags to use with the linker
135 LinkerFlagsFile android.OptionalPath
136
137 // Path to the dynamic linker binary
138 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700139}
140
Colin Crossca860ac2016-01-04 14:34:37 -0800141type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700142 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
143 ArFlags []string // Flags that apply to ar
144 AsFlags []string // Flags that apply to assembly source files
145 CFlags []string // Flags that apply to C and C++ source files
146 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
147 ConlyFlags []string // Flags that apply to C source files
148 CppFlags []string // Flags that apply to C++ source files
149 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700150 aidlFlags []string // Flags that apply to aidl source files
151 rsFlags []string // Flags that apply to renderscript source files
152 LdFlags []string // Flags that apply to linker command lines
153 libFlags []string // Flags to add libraries early to the link order
154 TidyFlags []string // Flags that apply to clang-tidy
155 SAbiFlags []string // Flags that apply to header-abi-dumper
156 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700157
Colin Crossc3199482017-03-30 15:03:04 -0700158 // Global include flags that apply to C, C++, and assembly source files
159 // These must be after any module include flags, which will be in GlobalFlags.
160 SystemIncludeFlags []string
161
Colin Crossb98c8b02016-07-29 13:44:28 -0700162 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700163 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800164 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800165 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800166 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800167
168 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800169 DynamicLinker string
170
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700171 CFlagsDeps android.Paths // Files depended on by compiler flags
172 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800173
174 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800175
Colin Cross19878da2019-03-28 14:45:07 -0700176 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700177 protoC bool // Whether to use C instead of C++
178 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700179
180 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700181}
182
Colin Cross81413472016-04-11 14:37:39 -0700183type ObjectLinkerProperties struct {
Paul Duffina37832a2019-07-18 12:31:26 +0100184 // list of modules that should only provide headers for this module.
185 Header_libs []string `android:"arch_variant,variant_prepend"`
186
Colin Cross81413472016-04-11 14:37:39 -0700187 // names of other cc_object modules to link into this module using partial linking
188 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700189
190 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800191 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700192}
193
Colin Crossca860ac2016-01-04 14:34:37 -0800194// Properties used to compile all C or C++ modules
195type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700196 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800197 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700198
199 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800200 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700201
Jiyong Parkde866cb2018-12-07 23:08:36 +0900202 AndroidMkSharedLibs []string `blueprint:"mutated"`
203 AndroidMkStaticLibs []string `blueprint:"mutated"`
204 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
205 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
206 HideFromMake bool `blueprint:"mutated"`
207 PreventInstall bool `blueprint:"mutated"`
208 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700209
210 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800211
212 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
213 // file
214 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900215
216 // Make this module available when building for recovery
217 Recovery_available *bool
218
219 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900220
221 // Allows this module to use non-APEX version of libraries. Useful
222 // for building binaries that are started before APEXes are activated.
223 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700224}
225
226type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900227 // whether this module should be allowed to be directly depended by other
228 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
229 // If set to true, two variants will be built separately, one like
230 // normal, and the other limited to the set of libraries and headers
231 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700232 //
233 // The vendor variant may be used with a different (newer) /system,
234 // so it shouldn't have any unversioned runtime dependencies, or
235 // make assumptions about the system that may not be true in the
236 // future.
237 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900238 // If set to false, this module becomes inaccessible from /vendor modules.
239 //
240 // Default value is true when vndk: {enabled: true} or vendor: true.
241 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700242 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
243 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900244
245 // whether this module is capable of being loaded with other instance
246 // (possibly an older version) of the same module in the same process.
247 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
248 // can be double loaded in a vendor process if the library is also a
249 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
250 // explicitly marked as `double_loadable: true` by the owner, or the dependency
251 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
252 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800253}
254
Colin Crossca860ac2016-01-04 14:34:37 -0800255type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800256 static() bool
257 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700258 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700259 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800260 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700261 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800262 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900263 isLlndk(config android.Config) bool
264 isLlndkPublic(config android.Config) bool
265 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900266 isVndk() bool
267 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800268 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900269 inRecovery() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900270 shouldCreateVndkSourceAbiDump(config android.Config) bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700271 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700272 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800273 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800274 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800275 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800276 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900277 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900278 hasStubsVariants() bool
279 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900280 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800281 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700282 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800283}
284
285type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700286 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800287 ModuleContextIntf
288}
289
290type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700291 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800292 ModuleContextIntf
293}
294
Colin Cross37047f12016-12-13 17:06:13 -0800295type DepsContext interface {
296 android.BottomUpMutatorContext
297 ModuleContextIntf
298}
299
Colin Crossca860ac2016-01-04 14:34:37 -0800300type feature interface {
301 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800302 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800303 flags(ctx ModuleContext, flags Flags) Flags
304 props() []interface{}
305}
306
307type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700308 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800309 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800310 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700311 compilerProps() []interface{}
312
Colin Cross76fada02016-07-27 10:31:13 -0700313 appendCflags([]string)
314 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700315 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800316}
317
318type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700319 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800320 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700321 linkerFlags(ctx ModuleContext, flags Flags) Flags
322 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800323 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700324
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700325 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700326 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900327 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700328
329 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800330}
331
332type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700333 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700334 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800335 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700336 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700337 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900338 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800339}
340
Colin Crossc99deeb2016-04-11 15:06:20 -0700341type dependencyTag struct {
342 blueprint.BaseDependencyTag
343 name string
344 library bool
Roland Levillainf89cd092019-07-29 16:22:59 +0100345 shared bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700346
347 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900348
349 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700350}
351
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800352type xref interface {
353 XrefCcFiles() android.Paths
354}
355
Colin Crossc99deeb2016-04-11 15:06:20 -0700356var (
Roland Levillainf89cd092019-07-29 16:22:59 +0100357 sharedDepTag = dependencyTag{name: "shared", library: true, shared: true}
358 sharedExportDepTag = dependencyTag{name: "shared", library: true, shared: true, reexportFlags: true}
359 earlySharedDepTag = dependencyTag{name: "early_shared", library: true, shared: true}
360 lateSharedDepTag = dependencyTag{name: "late shared", library: true, shared: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700361 staticDepTag = dependencyTag{name: "static", library: true}
362 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
363 lateStaticDepTag = dependencyTag{name: "late static", library: true}
364 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800365 headerDepTag = dependencyTag{name: "header", library: true}
366 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700367 genSourceDepTag = dependencyTag{name: "gen source"}
368 genHeaderDepTag = dependencyTag{name: "gen header"}
369 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
370 objDepTag = dependencyTag{name: "obj"}
371 crtBeginDepTag = dependencyTag{name: "crtbegin"}
372 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700373 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
374 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700375 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900376 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700377 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
378 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800379 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800380 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700381 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100382 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700383)
384
Roland Levillainf89cd092019-07-29 16:22:59 +0100385func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
386 ccDepTag, ok := depTag.(dependencyTag)
387 return ok && ccDepTag.shared
388}
389
390func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
391 ccDepTag, ok := depTag.(dependencyTag)
392 return ok && ccDepTag == runtimeDepTag
393}
394
395func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
396 ccDepTag, ok := depTag.(dependencyTag)
397 return ok && ccDepTag == testPerSrcDepTag
398}
399
Colin Crossca860ac2016-01-04 14:34:37 -0800400// Module contains the properties and members used by all C/C++ module types, and implements
401// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
402// to construct the output file. Behavior can be customized with a Customizer interface
403type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700404 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700405 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900406 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700407
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700408 Properties BaseProperties
409 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700410
Colin Crossca860ac2016-01-04 14:34:37 -0800411 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700412 hod android.HostOrDeviceSupported
413 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700414
Colin Crossca860ac2016-01-04 14:34:37 -0800415 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700416 features []feature
417 compiler compiler
418 linker linker
419 installer installer
420 stl *stl
421 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800422 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800423 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900424 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700425 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700426 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800427 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800428
429 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700430
Colin Cross635c3b02016-05-18 15:37:25 -0700431 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800432
Colin Crossb98c8b02016-07-29 13:44:28 -0700433 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700434
435 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800436
437 // Flags used to compile this module
438 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700439
440 // 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 -0800441 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700442 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800443 depsInLinkOrder android.Paths
444
445 // only non-nil when this is a shared library that reuses the objects of a static library
446 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900447
448 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800449 // Kythe (source file indexer) paths for this compilation module
450 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700451}
452
Jiyong Parkc20eee32018-09-05 22:36:17 +0900453func (c *Module) OutputFile() android.OptionalPath {
454 return c.outputFile
455}
456
Jiyong Park719b4462019-01-13 00:39:51 +0900457func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900458 if c.linker != nil {
459 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900460 }
461 return nil
462}
463
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900464func (c *Module) RelativeInstallPath() string {
465 if c.installer != nil {
466 return c.installer.relativeInstallPath()
467 }
468 return ""
469}
470
Colin Cross36242852017-06-23 15:06:31 -0700471func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700472 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800473 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700474 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800475 }
476 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700477 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800478 }
479 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700480 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800481 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700482 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700483 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700484 }
Colin Cross16b23492016-01-06 14:41:07 -0800485 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700486 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800487 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800488 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700489 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800490 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800491 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700492 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800493 }
Justin Yun8effde42017-06-23 19:24:43 +0900494 if c.vndkdep != nil {
495 c.AddProperties(c.vndkdep.props()...)
496 }
Stephen Craneba090d12017-05-09 15:44:35 -0700497 if c.lto != nil {
498 c.AddProperties(c.lto.props()...)
499 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700500 if c.pgo != nil {
501 c.AddProperties(c.pgo.props()...)
502 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800503 if c.xom != nil {
504 c.AddProperties(c.xom.props()...)
505 }
Colin Crossca860ac2016-01-04 14:34:37 -0800506 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700507 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800508 }
Colin Crossc472d572015-03-17 15:06:21 -0700509
Colin Crossa9d8bee2018-10-02 13:59:46 -0700510 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
511 switch class {
512 case android.Device:
513 return ctx.Config().DevicePrefer32BitExecutables()
514 case android.HostCross:
515 // Windows builds always prefer 32-bit
516 return true
517 default:
518 return false
519 }
520 })
Colin Cross36242852017-06-23 15:06:31 -0700521 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700522
Colin Cross1f44a3a2017-07-07 14:33:33 -0700523 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700524
Jiyong Park9d452992018-10-03 00:38:19 +0900525 android.InitApexModule(c)
526
Colin Cross36242852017-06-23 15:06:31 -0700527 return c
Colin Crossc472d572015-03-17 15:06:21 -0700528}
529
Colin Crossb916a382016-07-29 17:28:03 -0700530// Returns true for dependency roots (binaries)
531// TODO(ccross): also handle dlopenable libraries
532func (c *Module) isDependencyRoot() bool {
533 if root, ok := c.linker.(interface {
534 isDependencyRoot() bool
535 }); ok {
536 return root.isDependencyRoot()
537 }
538 return false
539}
540
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700541func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700542 return c.Properties.UseVndk
543}
544
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800545func (c *Module) isCoverageVariant() bool {
546 return c.coverage.Properties.IsCoverageVariant
547}
548
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800549func (c *Module) isNdk() bool {
550 return inList(c.Name(), ndkMigratedLibs)
551}
552
Inseob Kim9516ee92019-05-09 10:56:13 +0900553func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800554 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900555 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800556}
557
Inseob Kim9516ee92019-05-09 10:56:13 +0900558func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800559 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900560 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800561}
562
Inseob Kim9516ee92019-05-09 10:56:13 +0900563func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800564 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900565 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800566}
567
Justin Yun8effde42017-06-23 19:24:43 +0900568func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800569 if vndkdep := c.vndkdep; vndkdep != nil {
570 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900571 }
572 return false
573}
574
Jooyung Han76106d92019-05-20 18:49:10 +0900575func (c *Module) vndkVersion() string {
576 if vndkdep := c.vndkdep; vndkdep != nil {
577 return vndkdep.Properties.Vndk.Version
578 }
579 return ""
580}
581
Yi Kong7e53c572018-02-14 18:16:12 +0800582func (c *Module) isPgoCompile() bool {
583 if pgo := c.pgo; pgo != nil {
584 return pgo.Properties.PgoCompile
585 }
586 return false
587}
588
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800589func (c *Module) isNDKStubLibrary() bool {
590 if _, ok := c.compiler.(*stubDecorator); ok {
591 return true
592 }
593 return false
594}
595
Logan Chienf3511742017-10-31 18:04:35 +0800596func (c *Module) isVndkSp() bool {
597 if vndkdep := c.vndkdep; vndkdep != nil {
598 return vndkdep.isVndkSp()
599 }
600 return false
601}
602
603func (c *Module) isVndkExt() bool {
604 if vndkdep := c.vndkdep; vndkdep != nil {
605 return vndkdep.isVndkExt()
606 }
607 return false
608}
609
Vic Yangefd249e2018-11-12 20:19:56 -0800610func (c *Module) mustUseVendorVariant() bool {
611 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
612}
613
Logan Chienf3511742017-10-31 18:04:35 +0800614func (c *Module) getVndkExtendsModuleName() string {
615 if vndkdep := c.vndkdep; vndkdep != nil {
616 return vndkdep.getVndkExtendsModuleName()
617 }
618 return ""
619}
620
Jiyong Park82e2bf32017-08-16 14:05:54 +0900621// Returns true only when this module is configured to have core and vendor
622// variants.
623func (c *Module) hasVendorVariant() bool {
624 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
625}
626
Jiyong Parkf9332f12018-02-01 00:54:12 +0900627func (c *Module) inRecovery() bool {
628 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
629}
630
631func (c *Module) onlyInRecovery() bool {
632 return c.ModuleBase.InstallInRecovery()
633}
634
Jiyong Park25fc6a92018-11-18 18:02:45 +0900635func (c *Module) IsStubs() bool {
636 if library, ok := c.linker.(*libraryDecorator); ok {
637 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900638 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
639 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900640 }
641 return false
642}
643
644func (c *Module) HasStubsVariants() bool {
645 if library, ok := c.linker.(*libraryDecorator); ok {
646 return len(library.Properties.Stubs.Versions) > 0
647 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700648 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
649 return len(library.Properties.Stubs.Versions) > 0
650 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900651 return false
652}
653
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900654func (c *Module) bootstrap() bool {
655 return Bool(c.Properties.Bootstrap)
656}
657
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700658func (c *Module) nativeCoverage() bool {
659 return c.linker != nil && c.linker.nativeCoverage()
660}
661
Jiyong Parkf1194352019-02-25 11:05:47 +0900662func isBionic(name string) bool {
663 switch name {
664 case "libc", "libm", "libdl", "linker":
665 return true
666 }
667 return false
668}
669
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700670func installToBootstrap(name string, config android.Config) bool {
671 if name == "libclang_rt.hwasan-aarch64-android" {
672 return inList("hwaddress", config.SanitizeDevice())
673 }
674 return isBionic(name)
675}
676
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800677func (c *Module) XrefCcFiles() android.Paths {
678 return c.kytheFiles
679}
680
Colin Crossca860ac2016-01-04 14:34:37 -0800681type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700682 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800683 moduleContextImpl
684}
685
Colin Cross37047f12016-12-13 17:06:13 -0800686type depsContext struct {
687 android.BottomUpMutatorContext
688 moduleContextImpl
689}
690
Colin Crossca860ac2016-01-04 14:34:37 -0800691type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700692 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800693 moduleContextImpl
694}
695
Jiyong Park2db76922017-11-08 16:03:48 +0900696func (ctx *moduleContext) SocSpecific() bool {
697 return ctx.ModuleContext.SocSpecific() ||
698 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700699}
700
Colin Crossca860ac2016-01-04 14:34:37 -0800701type moduleContextImpl struct {
702 mod *Module
703 ctx BaseModuleContext
704}
705
Colin Crossb98c8b02016-07-29 13:44:28 -0700706func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800707 return ctx.mod.toolchain(ctx.ctx)
708}
709
710func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000711 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800712}
713
714func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900715 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800716}
717
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700718func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800719 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800720 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700721 }
722 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800723}
724
725func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700726 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700727 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900728 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700729 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900730 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
731 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
732 return "current"
733 }
734 return platform_vndk_ver
735 }
736 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800737 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900738 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700739 }
740 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800741}
742
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700743func (ctx *moduleContextImpl) useVndk() bool {
744 return ctx.mod.useVndk()
745}
Justin Yun8effde42017-06-23 19:24:43 +0900746
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800747func (ctx *moduleContextImpl) isNdk() bool {
748 return ctx.mod.isNdk()
749}
750
Inseob Kim9516ee92019-05-09 10:56:13 +0900751func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
752 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800753}
754
Inseob Kim9516ee92019-05-09 10:56:13 +0900755func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
756 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800757}
758
Inseob Kim9516ee92019-05-09 10:56:13 +0900759func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
760 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800761}
762
Logan Chienf3511742017-10-31 18:04:35 +0800763func (ctx *moduleContextImpl) isVndk() bool {
764 return ctx.mod.isVndk()
765}
766
Yi Kong7e53c572018-02-14 18:16:12 +0800767func (ctx *moduleContextImpl) isPgoCompile() bool {
768 return ctx.mod.isPgoCompile()
769}
770
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800771func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
772 return ctx.mod.isNDKStubLibrary()
773}
774
Justin Yun8effde42017-06-23 19:24:43 +0900775func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800776 return ctx.mod.isVndkSp()
777}
778
779func (ctx *moduleContextImpl) isVndkExt() bool {
780 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900781}
782
Vic Yangefd249e2018-11-12 20:19:56 -0800783func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
784 return ctx.mod.mustUseVendorVariant()
785}
786
Jiyong Parkf9332f12018-02-01 00:54:12 +0900787func (ctx *moduleContextImpl) inRecovery() bool {
788 return ctx.mod.inRecovery()
789}
790
Logan Chien2f2b8902018-07-10 15:01:19 +0800791// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900792func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800793 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
794 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800795 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800796
797 if ctx.ctx.Fuchsia() {
798 return false
799 }
800
Logan Chien2f2b8902018-07-10 15:01:19 +0800801 if sanitize := ctx.mod.sanitize; sanitize != nil {
802 if !sanitize.isVariantOnProductionDevice() {
803 return false
804 }
805 }
806 if !ctx.ctx.Device() {
807 // Host modules do not need ABI dumps.
808 return false
809 }
Logan Chienfa478c02018-12-28 16:25:39 +0800810 if !ctx.mod.IsForPlatform() {
811 // APEX variants do not need ABI dumps.
812 return false
813 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800814 if ctx.isStubs() {
815 // Stubs do not need ABI dumps.
816 return false
817 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800818 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800819 return true
820 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900821 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800822 return true
823 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900824 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800825 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
826 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800827 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800828 }
829 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800830}
831
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700832func (ctx *moduleContextImpl) selectedStl() string {
833 if stl := ctx.mod.stl; stl != nil {
834 return stl.Properties.SelectedStl
835 }
836 return ""
837}
838
Ivan Lozanobd721262018-11-27 14:33:03 -0800839func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
840 return ctx.mod.linker.useClangLld(actx)
841}
842
Colin Crossce75d2c2016-10-06 16:12:58 -0700843func (ctx *moduleContextImpl) baseModuleName() string {
844 return ctx.mod.ModuleBase.BaseModuleName()
845}
846
Logan Chienf3511742017-10-31 18:04:35 +0800847func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
848 return ctx.mod.getVndkExtendsModuleName()
849}
850
Jiyong Park58e364a2019-01-19 19:24:06 +0900851func (ctx *moduleContextImpl) apexName() string {
852 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900853}
854
Jiyong Parkb0788572018-12-20 22:10:17 +0900855func (ctx *moduleContextImpl) hasStubsVariants() bool {
856 return ctx.mod.HasStubsVariants()
857}
858
859func (ctx *moduleContextImpl) isStubs() bool {
860 return ctx.mod.IsStubs()
861}
862
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900863func (ctx *moduleContextImpl) bootstrap() bool {
864 return ctx.mod.bootstrap()
865}
866
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700867func (ctx *moduleContextImpl) nativeCoverage() bool {
868 return ctx.mod.nativeCoverage()
869}
870
Colin Cross635c3b02016-05-18 15:37:25 -0700871func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800872 return &Module{
873 hod: hod,
874 multilib: multilib,
875 }
876}
877
Colin Cross635c3b02016-05-18 15:37:25 -0700878func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800879 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700880 module.features = []feature{
881 &tidyFeature{},
882 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700883 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800884 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800885 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800886 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900887 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700888 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700889 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800890 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800891 return module
892}
893
Colin Crossce75d2c2016-10-06 16:12:58 -0700894func (c *Module) Prebuilt() *android.Prebuilt {
895 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
896 return p.prebuilt()
897 }
898 return nil
899}
900
901func (c *Module) Name() string {
902 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700903 if p, ok := c.linker.(interface {
904 Name(string) string
905 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700906 name = p.Name(name)
907 }
908 return name
909}
910
Alex Light3d673592019-01-18 14:37:31 -0800911func (c *Module) Symlinks() []string {
912 if p, ok := c.installer.(interface {
913 symlinkList() []string
914 }); ok {
915 return p.symlinkList()
916 }
917 return nil
918}
919
Jeff Gaston294356f2017-09-27 17:05:30 -0700920// orderDeps reorders dependencies into a list such that if module A depends on B, then
921// A will precede B in the resultant list.
922// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800923// Note that directSharedDeps should be the analogous static library for each shared lib dep
924func 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 -0700925 // If A depends on B, then
926 // Every list containing A will also contain B later in the list
927 // So, after concatenating all lists, the final instance of B will have come from the same
928 // original list as the final instance of A
929 // So, the final instance of B will be later in the concatenation than the final A
930 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
931 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800932 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700933 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800934 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
935 }
936 for _, dep := range directSharedDeps {
937 orderedAllDeps = append(orderedAllDeps, dep)
938 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700939 }
940
Colin Crossb6715442017-10-24 11:13:31 -0700941 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700942
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800943 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700944 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800945 // resultant list to only what the caller has chosen to include in directStaticDeps
946 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700947
948 return orderedAllDeps, orderedDeclaredDeps
949}
950
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800951func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
952 // convert Module to Path
953 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
954 staticDepFiles := []android.Path{}
955 for _, dep := range staticDeps {
956 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
957 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700958 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800959 sharedDepFiles := []android.Path{}
960 for _, sharedDep := range sharedDeps {
961 staticAnalogue := sharedDep.staticVariant
962 if staticAnalogue != nil {
963 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
964 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
965 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700966 }
967
968 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800969 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700970
971 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700972}
973
Roland Levillainf89cd092019-07-29 16:22:59 +0100974func (c *Module) IsTestPerSrcAllTestsVariation() bool {
975 test, ok := c.linker.(testPerSrc)
976 return ok && test.isAllTestsVariation()
977}
978
Colin Cross635c3b02016-05-18 15:37:25 -0700979func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100980 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +0100981 //
982 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
983 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
984 // module and return early, as this module does not produce an output file per se.
985 if c.IsTestPerSrcAllTestsVariation() {
986 c.outputFile = android.OptionalPath{}
987 return
Roland Levillainf2fad972019-06-28 15:41:19 +0100988 }
989
Jooyung Han38002912019-05-16 04:01:54 +0900990 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900991
Colin Crossca860ac2016-01-04 14:34:37 -0800992 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700993 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800994 moduleContextImpl: moduleContextImpl{
995 mod: c,
996 },
997 }
998 ctx.ctx = ctx
999
Colin Crossf18e1102017-11-16 14:33:08 -08001000 deps := c.depsToPaths(ctx)
1001 if ctx.Failed() {
1002 return
1003 }
1004
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001005 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1006 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1007 }
1008
Colin Crossca860ac2016-01-04 14:34:37 -08001009 flags := Flags{
1010 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001011 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001012 }
Colin Crossca860ac2016-01-04 14:34:37 -08001013 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001014 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001015 }
1016 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001017 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001018 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001019 if c.stl != nil {
1020 flags = c.stl.flags(ctx, flags)
1021 }
Colin Cross16b23492016-01-06 14:41:07 -08001022 if c.sanitize != nil {
1023 flags = c.sanitize.flags(ctx, flags)
1024 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001025 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001026 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001027 }
Stephen Craneba090d12017-05-09 15:44:35 -07001028 if c.lto != nil {
1029 flags = c.lto.flags(ctx, flags)
1030 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001031 if c.pgo != nil {
1032 flags = c.pgo.flags(ctx, flags)
1033 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001034 if c.xom != nil {
1035 flags = c.xom.flags(ctx, flags)
1036 }
Colin Crossca860ac2016-01-04 14:34:37 -08001037 for _, feature := range c.features {
1038 flags = feature.flags(ctx, flags)
1039 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001040 if ctx.Failed() {
1041 return
1042 }
1043
Colin Crossb98c8b02016-07-29 13:44:28 -07001044 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1045 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1046 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001047
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001048 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001049
1050 for _, dir := range deps.IncludeDirs {
1051 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1052 }
1053 for _, dir := range deps.SystemIncludeDirs {
1054 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1055 }
1056
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001057 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001058 // We need access to all the flags seen by a source file.
1059 if c.sabi != nil {
1060 flags = c.sabi.flags(ctx, flags)
1061 }
Colin Crossca860ac2016-01-04 14:34:37 -08001062 // Optimization to reduce size of build.ninja
1063 // Replace the long list of flags for each file with a module-local variable
1064 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1065 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1066 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1067 flags.CFlags = []string{"$cflags"}
1068 flags.CppFlags = []string{"$cppflags"}
1069 flags.AsFlags = []string{"$asflags"}
1070
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001071 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001072 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001073 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001074 if ctx.Failed() {
1075 return
1076 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001077 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001078 }
1079
Colin Crossca860ac2016-01-04 14:34:37 -08001080 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001081 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001082 if ctx.Failed() {
1083 return
1084 }
Colin Cross635c3b02016-05-18 15:37:25 -07001085 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001086
1087 // If a lib is directly included in any of the APEXes, unhide the stubs
1088 // variant having the latest version gets visible to make. In addition,
1089 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1090 // force anything in the make world to link against the stubs library.
1091 // (unless it is explicitly referenced via .bootstrap suffix or the
1092 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001093 if c.HasStubsVariants() &&
1094 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001095 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1096 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001097 c.Properties.HideFromMake = false // unhide
1098 // Note: this is still non-installable
1099 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001100 }
Colin Cross5049f022015-03-18 13:28:46 -07001101
Inseob Kim1f086e22019-05-09 13:29:15 +09001102 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001103 c.installer.install(ctx, c.outputFile.Path())
1104 if ctx.Failed() {
1105 return
Colin Crossca860ac2016-01-04 14:34:37 -08001106 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001107 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001108}
1109
Colin Cross0ea8ba82019-06-06 14:33:29 -07001110func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001111 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001112 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001113 }
Colin Crossca860ac2016-01-04 14:34:37 -08001114 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001115}
1116
Colin Crossca860ac2016-01-04 14:34:37 -08001117func (c *Module) begin(ctx BaseModuleContext) {
1118 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001119 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001120 }
Colin Crossca860ac2016-01-04 14:34:37 -08001121 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001122 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001123 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001124 if c.stl != nil {
1125 c.stl.begin(ctx)
1126 }
Colin Cross16b23492016-01-06 14:41:07 -08001127 if c.sanitize != nil {
1128 c.sanitize.begin(ctx)
1129 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001130 if c.coverage != nil {
1131 c.coverage.begin(ctx)
1132 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001133 if c.sabi != nil {
1134 c.sabi.begin(ctx)
1135 }
Justin Yun8effde42017-06-23 19:24:43 +09001136 if c.vndkdep != nil {
1137 c.vndkdep.begin(ctx)
1138 }
Stephen Craneba090d12017-05-09 15:44:35 -07001139 if c.lto != nil {
1140 c.lto.begin(ctx)
1141 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001142 if c.pgo != nil {
1143 c.pgo.begin(ctx)
1144 }
Colin Crossca860ac2016-01-04 14:34:37 -08001145 for _, feature := range c.features {
1146 feature.begin(ctx)
1147 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001148 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001149 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001150 if err != nil {
1151 ctx.PropertyErrorf("sdk_version", err.Error())
1152 }
Nan Zhang0007d812017-11-07 10:57:05 -08001153 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001154 }
Colin Crossca860ac2016-01-04 14:34:37 -08001155}
1156
Colin Cross37047f12016-12-13 17:06:13 -08001157func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001158 deps := Deps{}
1159
1160 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001161 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001162 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001163 // Add the PGO dependency (the clang_rt.profile runtime library), which
1164 // sometimes depends on symbols from libgcc, before libgcc gets added
1165 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001166 if c.pgo != nil {
1167 deps = c.pgo.deps(ctx, deps)
1168 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001169 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001170 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001171 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001172 if c.stl != nil {
1173 deps = c.stl.deps(ctx, deps)
1174 }
Colin Cross16b23492016-01-06 14:41:07 -08001175 if c.sanitize != nil {
1176 deps = c.sanitize.deps(ctx, deps)
1177 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001178 if c.coverage != nil {
1179 deps = c.coverage.deps(ctx, deps)
1180 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001181 if c.sabi != nil {
1182 deps = c.sabi.deps(ctx, deps)
1183 }
Justin Yun8effde42017-06-23 19:24:43 +09001184 if c.vndkdep != nil {
1185 deps = c.vndkdep.deps(ctx, deps)
1186 }
Stephen Craneba090d12017-05-09 15:44:35 -07001187 if c.lto != nil {
1188 deps = c.lto.deps(ctx, deps)
1189 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001190 for _, feature := range c.features {
1191 deps = feature.deps(ctx, deps)
1192 }
1193
Colin Crossb6715442017-10-24 11:13:31 -07001194 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1195 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1196 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1197 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1198 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1199 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001200 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001201
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001202 for _, lib := range deps.ReexportSharedLibHeaders {
1203 if !inList(lib, deps.SharedLibs) {
1204 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1205 }
1206 }
1207
1208 for _, lib := range deps.ReexportStaticLibHeaders {
1209 if !inList(lib, deps.StaticLibs) {
1210 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1211 }
1212 }
1213
Colin Cross5950f382016-12-13 12:50:57 -08001214 for _, lib := range deps.ReexportHeaderLibHeaders {
1215 if !inList(lib, deps.HeaderLibs) {
1216 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1217 }
1218 }
1219
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001220 for _, gen := range deps.ReexportGeneratedHeaders {
1221 if !inList(gen, deps.GeneratedHeaders) {
1222 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1223 }
1224 }
1225
Colin Crossc99deeb2016-04-11 15:06:20 -07001226 return deps
1227}
1228
Dan Albert7e9d2952016-08-04 13:02:36 -07001229func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001230 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001231 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001232 moduleContextImpl: moduleContextImpl{
1233 mod: c,
1234 },
1235 }
1236 ctx.ctx = ctx
1237
Colin Crossca860ac2016-01-04 14:34:37 -08001238 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001239}
1240
Jiyong Park7ed9de32018-10-15 22:25:07 +09001241// Split name#version into name and version
1242func stubsLibNameAndVersion(name string) (string, string) {
1243 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1244 version := name[sharp+1:]
1245 libname := name[:sharp]
1246 return libname, version
1247 }
1248 return name, ""
1249}
1250
Colin Cross1e676be2016-10-12 14:38:15 -07001251func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001252 ctx := &depsContext{
1253 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001254 moduleContextImpl: moduleContextImpl{
1255 mod: c,
1256 },
1257 }
1258 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001259
Colin Crossc99deeb2016-04-11 15:06:20 -07001260 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001261
Dan Albert914449f2016-06-17 16:45:24 -07001262 variantNdkLibs := []string{}
1263 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001264 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001265 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001266
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001267 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1268 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001269 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001270 // 1. Name of an NDK library that refers to a prebuilt module.
1271 // For each of these, it adds the name of the prebuilt module (which will be in
1272 // prebuilts/ndk) to the list of nonvariant libs.
1273 // 2. Name of an NDK library that refers to an ndk_library module.
1274 // For each of these, it adds the name of the ndk_library module to the list of
1275 // variant libs.
1276 // 3. Anything else (so anything that isn't an NDK library).
1277 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001278 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001279 // The caller can then know to add the variantLibs dependencies differently from the
1280 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001281
1282 llndkLibraries := llndkLibraries(actx.Config())
1283 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001284 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1285 variantLibs = []string{}
1286 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001287 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001288 // strip #version suffix out
1289 name, _ := stubsLibNameAndVersion(entry)
1290 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1291 if !inList(name, ndkMigratedLibs) {
1292 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001293 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001294 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001295 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001296 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001297 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001298 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001299 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001300 if actx.OtherModuleExists(vendorPublicLib) {
1301 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1302 } else {
1303 // This can happen if vendor_public_library module is defined in a
1304 // namespace that isn't visible to the current module. In that case,
1305 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001306 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001307 }
Dan Albert914449f2016-06-17 16:45:24 -07001308 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001309 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001310 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001311 }
1312 }
Dan Albert914449f2016-06-17 16:45:24 -07001313 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001314 }
1315
Dan Albert914449f2016-06-17 16:45:24 -07001316 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1317 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001318 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001319 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001320
Jiyong Park7e636d02019-01-28 16:16:54 +09001321 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001322 if c.linker != nil {
1323 if library, ok := c.linker.(*libraryDecorator); ok {
1324 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001325 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001326 }
1327 }
1328 }
1329
Colin Cross32ec36c2016-12-15 07:39:51 -08001330 for _, lib := range deps.HeaderLibs {
1331 depTag := headerDepTag
1332 if inList(lib, deps.ReexportHeaderLibHeaders) {
1333 depTag = headerExportDepTag
1334 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001335 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001336 actx.AddFarVariationDependencies([]blueprint.Variation{
1337 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001338 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001339 }, depTag, lib)
1340 } else {
1341 actx.AddVariationDependencies(nil, depTag, lib)
1342 }
1343 }
1344
1345 if buildStubs {
1346 // Stubs lib does not have dependency to other static/shared libraries.
1347 // Don't proceed.
1348 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001349 }
Colin Cross5950f382016-12-13 12:50:57 -08001350
Inseob Kimc0907f12019-02-08 21:00:45 +09001351 syspropImplLibraries := syspropImplLibraries(actx.Config())
1352
Jiyong Park5d1598f2019-02-25 22:14:17 +09001353 for _, lib := range deps.WholeStaticLibs {
1354 depTag := wholeStaticDepTag
1355 if impl, ok := syspropImplLibraries[lib]; ok {
1356 lib = impl
1357 }
1358 actx.AddVariationDependencies([]blueprint.Variation{
1359 {Mutator: "link", Variation: "static"},
1360 }, depTag, lib)
1361 }
1362
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001363 for _, lib := range deps.StaticLibs {
1364 depTag := staticDepTag
1365 if inList(lib, deps.ReexportStaticLibHeaders) {
1366 depTag = staticExportDepTag
1367 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001368
1369 if impl, ok := syspropImplLibraries[lib]; ok {
1370 lib = impl
1371 }
1372
Dan Willemsen59339a22018-07-22 21:18:45 -07001373 actx.AddVariationDependencies([]blueprint.Variation{
1374 {Mutator: "link", Variation: "static"},
1375 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001376 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001377
Dan Willemsen59339a22018-07-22 21:18:45 -07001378 actx.AddVariationDependencies([]blueprint.Variation{
1379 {Mutator: "link", Variation: "static"},
1380 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001381
Jiyong Park25fc6a92018-11-18 18:02:45 +09001382 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1383 var variations []blueprint.Variation
1384 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001385 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001386 if version != "" && versionVariantAvail {
1387 // Version is explicitly specified. i.e. libFoo#30
1388 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1389 depTag.explicitlyVersioned = true
1390 }
1391 actx.AddVariationDependencies(variations, depTag, name)
1392
1393 // If the version is not specified, add dependency to the latest stubs library.
1394 // The stubs library will be used when the depending module is built for APEX and
1395 // the dependent module is not in the same APEX.
1396 latestVersion := latestStubsVersionFor(actx.Config(), name)
1397 if version == "" && latestVersion != "" && versionVariantAvail {
1398 actx.AddVariationDependencies([]blueprint.Variation{
1399 {Mutator: "link", Variation: "shared"},
1400 {Mutator: "version", Variation: latestVersion},
1401 }, depTag, name)
1402 // Note that depTag.explicitlyVersioned is false in this case.
1403 }
1404 }
1405
Jiyong Park7ed9de32018-10-15 22:25:07 +09001406 // shared lib names without the #version suffix
1407 var sharedLibNames []string
1408
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001409 for _, lib := range deps.SharedLibs {
1410 depTag := sharedDepTag
1411 if inList(lib, deps.ReexportSharedLibHeaders) {
1412 depTag = sharedExportDepTag
1413 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001414
1415 if impl, ok := syspropImplLibraries[lib]; ok {
1416 lib = impl
1417 }
1418
1419 name, version := stubsLibNameAndVersion(lib)
1420 sharedLibNames = append(sharedLibNames, name)
1421
Jiyong Park25fc6a92018-11-18 18:02:45 +09001422 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001423 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001424
Jiyong Park7ed9de32018-10-15 22:25:07 +09001425 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001426 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001427 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1428 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1429 // linking against both the stubs lib and the non-stubs lib at the same time.
1430 continue
1431 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001432 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001433 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001434
Dan Willemsen59339a22018-07-22 21:18:45 -07001435 actx.AddVariationDependencies([]blueprint.Variation{
1436 {Mutator: "link", Variation: "shared"},
1437 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001438
Colin Cross68861832016-07-08 10:41:41 -07001439 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001440
1441 for _, gen := range deps.GeneratedHeaders {
1442 depTag := genHeaderDepTag
1443 if inList(gen, deps.ReexportGeneratedHeaders) {
1444 depTag = genHeaderExportDepTag
1445 }
1446 actx.AddDependency(c, depTag, gen)
1447 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001448
Colin Cross42d48b72018-08-29 14:10:52 -07001449 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001450
1451 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001452 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001453 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001454 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001455 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001456 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001457 if deps.LinkerFlagsFile != "" {
1458 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1459 }
1460 if deps.DynamicLinker != "" {
1461 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001462 }
Dan Albert914449f2016-06-17 16:45:24 -07001463
1464 version := ctx.sdkVersion()
1465 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001466 {Mutator: "ndk_api", Variation: version},
1467 {Mutator: "link", Variation: "shared"},
1468 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001469 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001470 {Mutator: "ndk_api", Variation: version},
1471 {Mutator: "link", Variation: "shared"},
1472 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001473
1474 if vndkdep := c.vndkdep; vndkdep != nil {
1475 if vndkdep.isVndkExt() {
1476 baseModuleMode := vendorMode
1477 if actx.DeviceConfig().VndkVersion() == "" {
1478 baseModuleMode = coreMode
1479 }
1480 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001481 {Mutator: "image", Variation: baseModuleMode},
1482 {Mutator: "link", Variation: "shared"},
1483 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001484 }
1485 }
Colin Cross6362e272015-10-29 15:25:03 -07001486}
Colin Cross21b9a242015-03-24 14:15:58 -07001487
Colin Crosse40b4ea2018-10-02 22:25:58 -07001488func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001489 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1490 c.beginMutator(ctx)
1491 }
1492}
1493
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001494// Whether a module can link to another module, taking into
1495// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001496func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001497 if from.Target().Os != android.Android {
1498 // Host code is not restricted
1499 return
1500 }
1501 if from.Properties.UseVndk {
1502 // Though vendor code is limited by the vendor mutator,
1503 // each vendor-available module needs to check
1504 // link-type for VNDK.
1505 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001506 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001507 }
1508 return
1509 }
Nan Zhang0007d812017-11-07 10:57:05 -08001510 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001511 // Platform code can link to anything
1512 return
1513 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001514 if from.inRecovery() {
1515 // Recovery code is not NDK
1516 return
1517 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001518 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1519 // These are always allowed
1520 return
1521 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001522 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1523 // These are allowed, but they don't set sdk_version
1524 return
1525 }
1526 if _, ok := to.linker.(*stubDecorator); ok {
1527 // These aren't real libraries, but are the stub shared libraries that are included in
1528 // the NDK.
1529 return
1530 }
Logan Chien834b9a62019-01-14 15:39:03 +08001531
1532 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1533 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1534 // to link to libc++ (non-NDK and without sdk_version).
1535 return
1536 }
1537
Nan Zhang0007d812017-11-07 10:57:05 -08001538 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001539 // NDK code linking to platform code is never okay.
1540 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1541 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001542 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001543 }
1544
1545 // At this point we know we have two NDK libraries, but we need to
1546 // check that we're not linking against anything built against a higher
1547 // API level, as it is only valid to link against older or equivalent
1548 // APIs.
1549
Inseob Kim01a28722018-04-11 09:48:45 +09001550 // Current can link against anything.
1551 if String(from.Properties.Sdk_version) != "current" {
1552 // Otherwise we need to check.
1553 if String(to.Properties.Sdk_version) == "current" {
1554 // Current can't be linked against by anything else.
1555 ctx.ModuleErrorf("links %q built against newer API version %q",
1556 ctx.OtherModuleName(to), "current")
1557 } else {
1558 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1559 if err != nil {
1560 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001561 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001562 String(from.Properties.Sdk_version))
1563 }
1564 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1565 if err != nil {
1566 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001567 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001568 String(to.Properties.Sdk_version))
1569 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001570
Inseob Kim01a28722018-04-11 09:48:45 +09001571 if toApi > fromApi {
1572 ctx.ModuleErrorf("links %q built against newer API version %q",
1573 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1574 }
1575 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001576 }
Dan Albert202fe492017-12-15 13:56:59 -08001577
1578 // Also check that the two STL choices are compatible.
1579 fromStl := from.stl.Properties.SelectedStl
1580 toStl := to.stl.Properties.SelectedStl
1581 if fromStl == "" || toStl == "" {
1582 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001583 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001584 // We can be permissive with the system "STL" since it is only the C++
1585 // ABI layer, but in the future we should make sure that everyone is
1586 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001587 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001588 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1589 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1590 to.stl.Properties.SelectedStl)
1591 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001592}
1593
Jiyong Park5fb8c102018-04-09 12:03:06 +09001594// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001595// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1596// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001597// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001598func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001599 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001600 check := func(child, parent android.Module) bool {
1601 to, ok := child.(*Module)
1602 if !ok {
1603 // follow thru cc.Defaults, etc.
1604 return true
1605 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001606
Jooyung Hana70f0672019-01-18 15:20:43 +09001607 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1608 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001609 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001610
1611 // if target lib has no vendor variant, keep checking dependency graph
1612 if !to.hasVendorVariant() {
1613 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001614 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001615
Inseob Kim9516ee92019-05-09 10:56:13 +09001616 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001617 return false
1618 }
1619
1620 var stringPath []string
1621 for _, m := range ctx.GetWalkPath() {
1622 stringPath = append(stringPath, m.Name())
1623 }
1624 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1625 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1626 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1627 return false
1628 }
1629 if module, ok := ctx.Module().(*Module); ok {
1630 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001631 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001632 ctx.WalkDeps(check)
1633 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001634 }
1635 }
1636}
1637
Colin Crossc99deeb2016-04-11 15:06:20 -07001638// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001639func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001640 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001641
Jeff Gaston294356f2017-09-27 17:05:30 -07001642 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001643 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001644
Inseob Kim9516ee92019-05-09 10:56:13 +09001645 llndkLibraries := llndkLibraries(ctx.Config())
1646 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1647
Inseob Kim69378442019-06-03 19:10:47 +09001648 reexportExporter := func(exporter exportedFlagsProducer) {
1649 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1650 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1651 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1652 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1653 }
1654
Colin Crossd11fcda2017-10-23 17:59:01 -07001655 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001656 depName := ctx.OtherModuleName(dep)
1657 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001658
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001659 ccDep, _ := dep.(*Module)
1660 if ccDep == nil {
1661 // handling for a few module types that aren't cc Module but that are also supported
1662 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001663 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001664 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001665 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1666 genRule.GeneratedSourceFiles()...)
1667 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001668 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001669 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001670 // Support exported headers from a generated_sources dependency
1671 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001672 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001673 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001674 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001675 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001676 dirs := genRule.GeneratedHeaderDirs().Strings()
1677 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001678 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001679 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1680 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001681 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Inseob Kim69378442019-06-03 19:10:47 +09001682 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001683
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001684 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001685 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001686 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001687 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001688 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001689 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001690 files := genRule.GeneratedSourceFiles()
1691 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001692 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001693 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001694 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 -07001695 }
1696 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001697 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001698 }
Colin Crossca860ac2016-01-04 14:34:37 -08001699 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001700 return
1701 }
1702
Colin Crossfe17f6f2019-03-28 19:30:56 -07001703 if depTag == android.ProtoPluginDepTag {
1704 return
1705 }
1706
Colin Crossd11fcda2017-10-23 17:59:01 -07001707 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001708 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1709 return
1710 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001711 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001712 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001713 return
1714 }
1715
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001716 // re-exporting flags
1717 if depTag == reuseObjTag {
1718 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001719 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001720 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001721 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001722 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001723 return
1724 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001725 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001726
Jiyong Parke4bb9862019-02-01 00:31:10 +09001727 if depTag == staticVariantTag {
1728 if _, ok := ccDep.compiler.(libraryInterface); ok {
1729 c.staticVariant = ccDep
1730 return
1731 }
1732 }
1733
Jiyong Park25fc6a92018-11-18 18:02:45 +09001734 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1735 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1736 // won't be matched to sharedDepTag and lateSharedDepTag.
1737 explicitlyVersioned := false
1738 if t, ok := depTag.(dependencyTag); ok {
1739 explicitlyVersioned = t.explicitlyVersioned
1740 t.explicitlyVersioned = false
1741 depTag = t
1742 }
1743
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001744 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001745 depIsStatic := false
1746 switch depTag {
1747 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1748 depIsStatic = true
1749 }
1750 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001751 depIsStubs := dependentLibrary.buildStubs()
1752 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001753 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001754 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001755
1756 var useThisDep bool
1757 if depIsStubs && explicitlyVersioned {
1758 // Always respect dependency to the versioned stubs (i.e. libX#10)
1759 useThisDep = true
1760 } else if !depHasStubs {
1761 // Use non-stub variant if that is the only choice
1762 // (i.e. depending on a lib without stubs.version property)
1763 useThisDep = true
1764 } else if c.IsForPlatform() {
1765 // If not building for APEX, use stubs only when it is from
1766 // an APEX (and not from platform)
1767 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001768 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001769 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001770 // always link to non-stub variant
1771 useThisDep = !depIsStubs
1772 }
1773 } else {
1774 // If building for APEX, use stubs only when it is not from
1775 // the same APEX
1776 useThisDep = (depInSameApex != depIsStubs)
1777 }
1778
1779 if !useThisDep {
1780 return // stop processing this dep
1781 }
1782 }
1783
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001784 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001785 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1786 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1787 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1788 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001789
1790 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001791 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001792 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jayant Chowdharyaf6eb712017-08-23 16:08:29 -07001793 // Re-exported shared library headers must be included as well since they can help us with type information
1794 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001795 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1796 // scripts.
1797 c.sabi.Properties.ReexportedIncludes = append(
1798 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001799 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001800 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001801
Logan Chienf3511742017-10-31 18:04:35 +08001802 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001803 }
1804
Colin Cross26c34ed2016-09-30 17:10:16 -07001805 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001806 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001807
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001808 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001809 depFile := android.OptionalPath{}
1810
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001811 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001812 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001813 ptr = &depPaths.SharedLibs
1814 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001815 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001816 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001817 case earlySharedDepTag:
1818 ptr = &depPaths.EarlySharedLibs
1819 depPtr = &depPaths.EarlySharedLibsDeps
1820 depFile = ccDep.linker.(libraryInterface).toc()
1821 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001822 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001823 ptr = &depPaths.LateSharedLibs
1824 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001825 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001826 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001827 ptr = nil
1828 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001829 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001830 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001831 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001832 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001833 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001834 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001835 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001836 return
1837 }
1838
1839 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001840 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001841 for i := range missingDeps {
1842 missingDeps[i] += postfix
1843 }
1844 ctx.AddMissingDependencies(missingDeps)
1845 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001846 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001847 case headerDepTag:
1848 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001849 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001850 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001851 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001852 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001853 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001854 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001855 case dynamicLinkerDepTag:
1856 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001857 }
1858
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001859 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001860 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001861 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001862 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001863 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001864 return
1865 }
1866
1867 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001868 // in static libraries act as if they were whole static libraries. The same goes for
1869 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001870 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1871 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001872 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1873 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001874
Dan Willemsen581341d2017-02-09 16:16:31 -08001875 }
1876
Colin Cross26c34ed2016-09-30 17:10:16 -07001877 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001878 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001879 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001880 return
1881 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001882 *ptr = append(*ptr, linkFile.Path())
1883 }
1884
Colin Crossc99deeb2016-04-11 15:06:20 -07001885 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001886 dep := depFile
1887 if !dep.Valid() {
1888 dep = linkFile
1889 }
1890 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001891 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001892
Logan Chien43d34c32017-12-20 01:17:32 +08001893 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001894 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001895 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001896 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001897 isLLndk := inList(libName, *llndkLibraries)
1898 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001899 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001900
yidong.zhangd06ecc82019-08-02 15:49:24 +08001901 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() && !c.inRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08001902 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1903 // core module instead.
1904 return libName
1905 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001906 // The vendor module in Make will have been renamed to not conflict with the core
1907 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001908 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001909 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001910 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001911 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1912 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001913 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001914 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001915 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001916 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001917 }
Logan Chien43d34c32017-12-20 01:17:32 +08001918 }
1919
1920 // Export the shared libs to Make.
1921 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001922 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001923 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001924 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001925 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001926 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001927 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001928 c.Properties.ApexesProvidingSharedLibs = append(
1929 c.Properties.ApexesProvidingSharedLibs, an)
1930 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001931 }
1932 }
1933
Jiyong Park27b188b2017-07-18 13:23:39 +09001934 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001935 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001936 c.Properties.AndroidMkSharedLibs = append(
1937 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001938 case ndkStubDepTag, ndkLateStubDepTag:
1939 ndkStub := ccDep.linker.(*stubDecorator)
1940 c.Properties.AndroidMkSharedLibs = append(
1941 c.Properties.AndroidMkSharedLibs,
1942 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001943 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1944 c.Properties.AndroidMkStaticLibs = append(
1945 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001946 case runtimeDepTag:
1947 c.Properties.AndroidMkRuntimeLibs = append(
1948 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001949 case wholeStaticDepTag:
1950 c.Properties.AndroidMkWholeStaticLibs = append(
1951 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001952 }
Colin Crossca860ac2016-01-04 14:34:37 -08001953 })
1954
Jeff Gaston294356f2017-09-27 17:05:30 -07001955 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001956 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001957
Colin Crossdd84e052017-05-17 13:44:16 -07001958 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001959 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001960 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1961 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001962 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001963 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1964 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001965 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001966 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001967
1968 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001969 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001970 }
Colin Crossdd84e052017-05-17 13:44:16 -07001971
Colin Crossca860ac2016-01-04 14:34:37 -08001972 return depPaths
1973}
1974
1975func (c *Module) InstallInData() bool {
1976 if c.installer == nil {
1977 return false
1978 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001979 return c.installer.inData()
1980}
1981
1982func (c *Module) InstallInSanitizerDir() bool {
1983 if c.installer == nil {
1984 return false
1985 }
1986 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001987 return true
1988 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001989 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001990}
1991
Jiyong Parkf9332f12018-02-01 00:54:12 +09001992func (c *Module) InstallInRecovery() bool {
1993 return c.inRecovery()
1994}
1995
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001996func (c *Module) HostToolPath() android.OptionalPath {
1997 if c.installer == nil {
1998 return android.OptionalPath{}
1999 }
2000 return c.installer.hostToolPath()
2001}
2002
Nan Zhangd4e641b2017-07-12 12:55:28 -07002003func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2004 return c.outputFile
2005}
2006
Colin Cross41955e82019-05-29 14:40:35 -07002007func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2008 switch tag {
2009 case "":
2010 if c.outputFile.Valid() {
2011 return android.Paths{c.outputFile.Path()}, nil
2012 }
2013 return android.Paths{}, nil
2014 default:
2015 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002016 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002017}
2018
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002019func (c *Module) static() bool {
2020 if static, ok := c.linker.(interface {
2021 static() bool
2022 }); ok {
2023 return static.static()
2024 }
2025 return false
2026}
2027
Jiyong Park379de2f2018-12-19 02:47:14 +09002028func (c *Module) staticBinary() bool {
2029 if static, ok := c.linker.(interface {
2030 staticBinary() bool
2031 }); ok {
2032 return static.staticBinary()
2033 }
2034 return false
2035}
2036
Jooyung Han38002912019-05-16 04:01:54 +09002037func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2038 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002039 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002040 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2041 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002042 return "native:vndk"
2043 }
Jooyung Han38002912019-05-16 04:01:54 +09002044 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002045 }
Jooyung Han38002912019-05-16 04:01:54 +09002046 if c.isVndk() && !c.isVndkExt() {
2047 if Bool(c.VendorProperties.Vendor_available) {
2048 return "native:vndk"
2049 }
2050 return "native:vndk_private"
2051 }
2052 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002053 } else if c.inRecovery() {
2054 return "native:recovery"
2055 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2056 return "native:ndk:none:none"
2057 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2058 //family, link := getNdkStlFamilyAndLinkType(c)
2059 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002060 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002061 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002062 } else {
2063 return "native:platform"
2064 }
2065}
2066
Jiyong Park9d452992018-10-03 00:38:19 +09002067// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002068// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002069func (c *Module) IsInstallableToApex() bool {
2070 if shared, ok := c.linker.(interface {
2071 shared() bool
2072 }); ok {
2073 return shared.shared()
Roland Levillainf89cd092019-07-29 16:22:59 +01002074 } else if _, ok := c.linker.(testPerSrc); ok {
2075 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002076 }
2077 return false
2078}
2079
Inseob Kim1f086e22019-05-09 13:29:15 +09002080func (c *Module) installable() bool {
2081 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2082}
2083
Jiyong Park3b1746a2019-01-29 11:15:04 +09002084func (c *Module) imageVariation() string {
2085 variation := "core"
2086 if c.useVndk() {
2087 variation = "vendor"
2088 } else if c.inRecovery() {
2089 variation = "recovery"
2090 }
2091 return variation
2092}
2093
bralee3f49f4d2019-03-04 06:58:15 +08002094func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002095 outputFiles, err := c.OutputFiles("")
2096 if err != nil {
2097 panic(err)
2098 }
2099 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002100}
2101
Logan Chien41eabe62019-04-10 13:33:58 +08002102func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2103 if c.linker != nil {
2104 if library, ok := c.linker.(*libraryDecorator); ok {
2105 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2106 }
2107 }
2108}
2109
Colin Cross2ba19d92015-05-07 15:44:20 -07002110//
Colin Crosscfad1192015-11-02 16:43:11 -08002111// Defaults
2112//
Colin Crossca860ac2016-01-04 14:34:37 -08002113type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002114 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002115 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002116 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002117}
2118
Patrice Arrudac249c712019-03-19 17:00:29 -07002119// cc_defaults provides a set of properties that can be inherited by other cc
2120// modules. A module can use the properties from a cc_defaults using
2121// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2122// merged (when possible) by prepending the default module's values to the
2123// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002124func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002125 return DefaultsFactory()
2126}
2127
Colin Cross36242852017-06-23 15:06:31 -07002128func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002129 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002130
Colin Cross36242852017-06-23 15:06:31 -07002131 module.AddProperties(props...)
2132 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002133 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002134 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002135 &BaseCompilerProperties{},
2136 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002137 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002138 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002139 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002140 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002141 &TestProperties{},
2142 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002143 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002144 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002145 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002146 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002147 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002148 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002149 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002150 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002151 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002152 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002153 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002154 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002155 )
Colin Crosscfad1192015-11-02 16:43:11 -08002156
Colin Cross1f44a3a2017-07-07 14:33:33 -07002157 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002158 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002159
2160 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002161}
2162
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002163const (
2164 // coreMode is the variant used for framework-private libraries, or
2165 // SDK libraries. (which framework-private libraries can use)
2166 coreMode = "core"
2167
2168 // vendorMode is the variant used for /vendor code that compiles
2169 // against the VNDK.
2170 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002171
2172 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002173)
2174
Jiyong Park6a43f042017-10-12 23:05:00 +09002175func squashVendorSrcs(m *Module) {
2176 if lib, ok := m.compiler.(*libraryDecorator); ok {
2177 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2178 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2179
2180 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2181 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2182 }
2183}
2184
Jiyong Parkf9332f12018-02-01 00:54:12 +09002185func squashRecoverySrcs(m *Module) {
2186 if lib, ok := m.compiler.(*libraryDecorator); ok {
2187 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2188 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2189
2190 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2191 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2192 }
2193}
2194
Jiyong Parkda6eb592018-12-19 17:12:36 +09002195func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002196 if mctx.Os() != android.Android {
2197 return
2198 }
2199
Jiyong Park7ed9de32018-10-15 22:25:07 +09002200 if g, ok := mctx.Module().(*genrule.Module); ok {
2201 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002202 var coreVariantNeeded bool = false
2203 var vendorVariantNeeded bool = false
2204 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002205 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002206 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002207 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002208 coreVariantNeeded = true
2209 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002210 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002211 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002212 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002213 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002214 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002215 if Bool(props.Recovery_available) {
2216 recoveryVariantNeeded = true
2217 }
2218
Jiyong Park413cc742018-06-19 01:46:06 +09002219 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002220 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002221 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002222 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002223 recoveryVariantNeeded = false
2224 }
2225 }
2226
Jiyong Park3f736c92018-05-24 13:36:56 +09002227 var variants []string
2228 if coreVariantNeeded {
2229 variants = append(variants, coreMode)
2230 }
2231 if vendorVariantNeeded {
2232 variants = append(variants, vendorMode)
2233 }
2234 if recoveryVariantNeeded {
2235 variants = append(variants, recoveryMode)
2236 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002237 mod := mctx.CreateVariations(variants...)
2238 for i, v := range variants {
2239 if v == recoveryMode {
2240 m := mod[i].(*genrule.Module)
2241 m.Extra.(*GenruleExtraProperties).InRecovery = true
2242 }
2243 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002244 }
2245 }
2246
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002247 m, ok := mctx.Module().(*Module)
2248 if !ok {
2249 return
2250 }
2251
2252 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002253 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002254 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002255
2256 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002257 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002258 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002259 return
2260 }
Logan Chienf3511742017-10-31 18:04:35 +08002261
2262 if vndkdep := m.vndkdep; vndkdep != nil {
2263 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002264 if productSpecific {
2265 mctx.PropertyErrorf("product_specific",
2266 "product_specific must not be true when `vndk: {enabled: true}`")
2267 return
2268 }
Logan Chienf3511742017-10-31 18:04:35 +08002269 if vendorSpecific {
2270 if !vndkdep.isVndkExt() {
2271 mctx.PropertyErrorf("vndk",
2272 "must set `extends: \"...\"` to vndk extension")
2273 return
2274 }
2275 } else {
2276 if vndkdep.isVndkExt() {
2277 mctx.PropertyErrorf("vndk",
2278 "must set `vendor: true` to set `extends: %q`",
2279 m.getVndkExtendsModuleName())
2280 return
2281 }
2282 if m.VendorProperties.Vendor_available == nil {
2283 mctx.PropertyErrorf("vndk",
2284 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2285 return
2286 }
2287 }
2288 } else {
2289 if vndkdep.isVndkSp() {
2290 mctx.PropertyErrorf("vndk",
2291 "must set `enabled: true` to set `support_system_process: true`")
2292 return
2293 }
2294 if vndkdep.isVndkExt() {
2295 mctx.PropertyErrorf("vndk",
2296 "must set `enabled: true` to set `extends: %q`",
2297 m.getVndkExtendsModuleName())
2298 return
2299 }
Justin Yun8effde42017-06-23 19:24:43 +09002300 }
2301 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002302
Jiyong Parkf9332f12018-02-01 00:54:12 +09002303 var coreVariantNeeded bool = false
2304 var vendorVariantNeeded bool = false
2305 var recoveryVariantNeeded bool = false
2306
Justin Yun71549282017-11-17 12:10:28 +09002307 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002308 // If the device isn't compiling against the VNDK, we always
2309 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002310 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002311 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2312 // LL-NDK stubs only exist in the vendor variant, since the
2313 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002314 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002315 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2316 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002317 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002318 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002319 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2320 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002321 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002322 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002323 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002324 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002325 coreVariantNeeded = true
2326 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002327 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002328 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002329 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002330 } else {
2331 // This is either in /system (or similar: /data), or is a
2332 // modules built with the NDK. Modules built with the NDK
2333 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002334 coreVariantNeeded = true
2335 }
2336
2337 if Bool(m.Properties.Recovery_available) {
2338 recoveryVariantNeeded = true
2339 }
2340
2341 if m.ModuleBase.InstallInRecovery() {
2342 recoveryVariantNeeded = true
2343 coreVariantNeeded = false
2344 }
2345
Jiyong Park413cc742018-06-19 01:46:06 +09002346 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002347 primaryArch := mctx.Config().DevicePrimaryArchType()
2348 moduleArch := m.Target().Arch.ArchType
2349 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002350 recoveryVariantNeeded = false
2351 }
2352 }
2353
Jiyong Parkf9332f12018-02-01 00:54:12 +09002354 var variants []string
2355 if coreVariantNeeded {
2356 variants = append(variants, coreMode)
2357 }
2358 if vendorVariantNeeded {
2359 variants = append(variants, vendorMode)
2360 }
2361 if recoveryVariantNeeded {
2362 variants = append(variants, recoveryMode)
2363 }
2364 mod := mctx.CreateVariations(variants...)
2365 for i, v := range variants {
2366 if v == vendorMode {
2367 m := mod[i].(*Module)
2368 m.Properties.UseVndk = true
2369 squashVendorSrcs(m)
2370 } else if v == recoveryMode {
2371 m := mod[i].(*Module)
2372 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002373 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002374 squashRecoverySrcs(m)
2375 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002376 }
2377}
2378
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002379func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002380 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002381 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2382 }
Colin Cross6510f912017-11-29 00:27:14 -08002383 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002384}
2385
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002386func kytheExtractAllFactory() android.Singleton {
2387 return &kytheExtractAllSingleton{}
2388}
2389
2390type kytheExtractAllSingleton struct {
2391}
2392
2393func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2394 var xrefTargets android.Paths
2395 ctx.VisitAllModules(func(module android.Module) {
2396 if ccModule, ok := module.(xref); ok {
2397 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2398 }
2399 })
2400 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2401 if len(xrefTargets) > 0 {
2402 ctx.Build(pctx, android.BuildParams{
2403 Rule: blueprint.Phony,
2404 Output: android.PathForPhony(ctx, "xref_cxx"),
2405 Inputs: xrefTargets,
2406 //Default: true,
2407 })
2408 }
2409}
2410
Colin Cross06a931b2015-10-28 17:23:31 -07002411var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002412var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002413var BoolPtr = proptools.BoolPtr
2414var String = proptools.String
2415var StringPtr = proptools.StringPtr