blob: a0ab2558a093a825c333ca38d3bbb3e390c48ed0 [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()
43 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
80 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070081}
82
Colin Crossca860ac2016-01-04 14:34:37 -080083type Deps struct {
84 SharedLibs, LateSharedLibs []string
85 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080086 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080087 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070088
Colin Cross5950f382016-12-13 12:50:57 -080089 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070090
Colin Cross81413472016-04-11 14:37:39 -070091 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070092
Dan Willemsenb40aab62016-04-20 14:21:14 -070093 GeneratedSources []string
94 GeneratedHeaders []string
95
Dan Willemsenb3454ab2016-09-28 17:34:58 -070096 ReexportGeneratedHeaders []string
97
Colin Cross97ba0732015-03-23 17:50:24 -070098 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070099
100 // Used for host bionic
101 LinkerFlagsFile string
102 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700103}
104
Colin Crossca860ac2016-01-04 14:34:37 -0800105type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900107 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700108 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900109 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700111 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700114 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800115 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700116 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700117
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700119 GeneratedSources android.Paths
120 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700121
Inseob Kim69378442019-06-03 19:10:47 +0900122 Flags []string
123 IncludeDirs []string
124 SystemIncludeDirs []string
125 ReexportedDirs []string
126 ReexportedSystemDirs []string
127 ReexportedFlags []string
128 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700132
133 // Path to the file container flags to use with the linker
134 LinkerFlagsFile android.OptionalPath
135
136 // Path to the dynamic linker binary
137 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700138}
139
Colin Crossca860ac2016-01-04 14:34:37 -0800140type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700141 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
142 ArFlags []string // Flags that apply to ar
143 AsFlags []string // Flags that apply to assembly source files
144 CFlags []string // Flags that apply to C and C++ source files
145 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
146 ConlyFlags []string // Flags that apply to C source files
147 CppFlags []string // Flags that apply to C++ source files
148 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700149 aidlFlags []string // Flags that apply to aidl source files
150 rsFlags []string // Flags that apply to renderscript source files
151 LdFlags []string // Flags that apply to linker command lines
152 libFlags []string // Flags to add libraries early to the link order
153 TidyFlags []string // Flags that apply to clang-tidy
154 SAbiFlags []string // Flags that apply to header-abi-dumper
155 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700156
Colin Crossc3199482017-03-30 15:03:04 -0700157 // Global include flags that apply to C, C++, and assembly source files
158 // These must be after any module include flags, which will be in GlobalFlags.
159 SystemIncludeFlags []string
160
Colin Crossb98c8b02016-07-29 13:44:28 -0700161 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700162 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800163 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800164 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800165
166 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800167 DynamicLinker string
168
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700169 CFlagsDeps android.Paths // Files depended on by compiler flags
170 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800171
172 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800173
Colin Cross19878da2019-03-28 14:45:07 -0700174 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700175 protoC bool // Whether to use C instead of C++
176 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700177
178 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700179}
180
Colin Cross81413472016-04-11 14:37:39 -0700181type ObjectLinkerProperties struct {
182 // names of other cc_object modules to link into this module using partial linking
183 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700184
185 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800186 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700187}
188
Colin Crossca860ac2016-01-04 14:34:37 -0800189// Properties used to compile all C or C++ modules
190type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700191 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800192 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700193
194 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800195 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700196
Jiyong Parkde866cb2018-12-07 23:08:36 +0900197 AndroidMkSharedLibs []string `blueprint:"mutated"`
198 AndroidMkStaticLibs []string `blueprint:"mutated"`
199 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
200 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
201 HideFromMake bool `blueprint:"mutated"`
202 PreventInstall bool `blueprint:"mutated"`
203 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700204
205 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800206
207 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
208 // file
209 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900210
211 // Make this module available when building for recovery
212 Recovery_available *bool
213
214 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900215
216 // Allows this module to use non-APEX version of libraries. Useful
217 // for building binaries that are started before APEXes are activated.
218 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700219}
220
221type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900222 // whether this module should be allowed to be directly depended by other
223 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
224 // If set to true, two variants will be built separately, one like
225 // normal, and the other limited to the set of libraries and headers
226 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700227 //
228 // The vendor variant may be used with a different (newer) /system,
229 // so it shouldn't have any unversioned runtime dependencies, or
230 // make assumptions about the system that may not be true in the
231 // future.
232 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900233 // If set to false, this module becomes inaccessible from /vendor modules.
234 //
235 // Default value is true when vndk: {enabled: true} or vendor: true.
236 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700237 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
238 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900239
240 // whether this module is capable of being loaded with other instance
241 // (possibly an older version) of the same module in the same process.
242 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
243 // can be double loaded in a vendor process if the library is also a
244 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
245 // explicitly marked as `double_loadable: true` by the owner, or the dependency
246 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
247 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800248}
249
Colin Crossca860ac2016-01-04 14:34:37 -0800250type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800251 static() bool
252 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700253 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700254 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800255 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700256 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800257 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900258 isLlndk(config android.Config) bool
259 isLlndkPublic(config android.Config) bool
260 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900261 isVndk() bool
262 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800263 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900264 inRecovery() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900265 shouldCreateVndkSourceAbiDump(config android.Config) bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700266 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700267 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800268 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800269 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800270 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800271 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900272 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900273 hasStubsVariants() bool
274 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900275 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800276 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700277 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800278}
279
280type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700281 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800282 ModuleContextIntf
283}
284
285type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700286 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800287 ModuleContextIntf
288}
289
Colin Cross37047f12016-12-13 17:06:13 -0800290type DepsContext interface {
291 android.BottomUpMutatorContext
292 ModuleContextIntf
293}
294
Colin Crossca860ac2016-01-04 14:34:37 -0800295type feature interface {
296 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800297 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800298 flags(ctx ModuleContext, flags Flags) Flags
299 props() []interface{}
300}
301
302type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700303 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800304 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800305 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700306 compilerProps() []interface{}
307
Colin Cross76fada02016-07-27 10:31:13 -0700308 appendCflags([]string)
309 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700310 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800311}
312
313type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700314 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800315 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700316 linkerFlags(ctx ModuleContext, flags Flags) Flags
317 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800318 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700319
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700320 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700321 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900322 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700323
324 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800325}
326
327type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700328 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700329 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800330 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700331 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700332 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900333 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800334}
335
Colin Crossc99deeb2016-04-11 15:06:20 -0700336type dependencyTag struct {
337 blueprint.BaseDependencyTag
338 name string
339 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700340
341 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900342
343 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700344}
345
346var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700347 sharedDepTag = dependencyTag{name: "shared", library: true}
348 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900349 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700350 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
351 staticDepTag = dependencyTag{name: "static", library: true}
352 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
353 lateStaticDepTag = dependencyTag{name: "late static", library: true}
354 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800355 headerDepTag = dependencyTag{name: "header", library: true}
356 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700357 genSourceDepTag = dependencyTag{name: "gen source"}
358 genHeaderDepTag = dependencyTag{name: "gen header"}
359 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
360 objDepTag = dependencyTag{name: "obj"}
361 crtBeginDepTag = dependencyTag{name: "crtbegin"}
362 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700363 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
364 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700365 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900366 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700367 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
368 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800369 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800370 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700371 coverageDepTag = dependencyTag{name: "coverage"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700372)
373
Colin Crossca860ac2016-01-04 14:34:37 -0800374// Module contains the properties and members used by all C/C++ module types, and implements
375// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
376// to construct the output file. Behavior can be customized with a Customizer interface
377type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700378 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700379 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900380 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700381
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700382 Properties BaseProperties
383 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700384
Colin Crossca860ac2016-01-04 14:34:37 -0800385 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700386 hod android.HostOrDeviceSupported
387 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700388
Colin Crossca860ac2016-01-04 14:34:37 -0800389 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700390 features []feature
391 compiler compiler
392 linker linker
393 installer installer
394 stl *stl
395 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800396 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800397 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900398 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700399 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700400 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800401 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800402
403 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700404
Colin Cross635c3b02016-05-18 15:37:25 -0700405 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800406
Colin Crossb98c8b02016-07-29 13:44:28 -0700407 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700408
409 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800410
411 // Flags used to compile this module
412 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700413
414 // 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 -0800415 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700416 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800417 depsInLinkOrder android.Paths
418
419 // only non-nil when this is a shared library that reuses the objects of a static library
420 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900421
422 makeLinkType string
Colin Crossc472d572015-03-17 15:06:21 -0700423}
424
Jiyong Parkc20eee32018-09-05 22:36:17 +0900425func (c *Module) OutputFile() android.OptionalPath {
426 return c.outputFile
427}
428
Jiyong Park719b4462019-01-13 00:39:51 +0900429func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900430 if c.linker != nil {
431 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900432 }
433 return nil
434}
435
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900436func (c *Module) RelativeInstallPath() string {
437 if c.installer != nil {
438 return c.installer.relativeInstallPath()
439 }
440 return ""
441}
442
Colin Cross36242852017-06-23 15:06:31 -0700443func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700444 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800445 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700446 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800447 }
448 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700449 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800450 }
451 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700452 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800453 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700454 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700455 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700456 }
Colin Cross16b23492016-01-06 14:41:07 -0800457 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700458 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800459 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800460 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700461 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800462 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800463 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700464 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800465 }
Justin Yun8effde42017-06-23 19:24:43 +0900466 if c.vndkdep != nil {
467 c.AddProperties(c.vndkdep.props()...)
468 }
Stephen Craneba090d12017-05-09 15:44:35 -0700469 if c.lto != nil {
470 c.AddProperties(c.lto.props()...)
471 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700472 if c.pgo != nil {
473 c.AddProperties(c.pgo.props()...)
474 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800475 if c.xom != nil {
476 c.AddProperties(c.xom.props()...)
477 }
Colin Crossca860ac2016-01-04 14:34:37 -0800478 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700479 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800480 }
Colin Crossc472d572015-03-17 15:06:21 -0700481
Colin Crossa9d8bee2018-10-02 13:59:46 -0700482 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
483 switch class {
484 case android.Device:
485 return ctx.Config().DevicePrefer32BitExecutables()
486 case android.HostCross:
487 // Windows builds always prefer 32-bit
488 return true
489 default:
490 return false
491 }
492 })
Colin Cross36242852017-06-23 15:06:31 -0700493 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700494
Colin Cross1f44a3a2017-07-07 14:33:33 -0700495 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700496
Jiyong Park9d452992018-10-03 00:38:19 +0900497 android.InitApexModule(c)
498
Colin Cross36242852017-06-23 15:06:31 -0700499 return c
Colin Crossc472d572015-03-17 15:06:21 -0700500}
501
Colin Crossb916a382016-07-29 17:28:03 -0700502// Returns true for dependency roots (binaries)
503// TODO(ccross): also handle dlopenable libraries
504func (c *Module) isDependencyRoot() bool {
505 if root, ok := c.linker.(interface {
506 isDependencyRoot() bool
507 }); ok {
508 return root.isDependencyRoot()
509 }
510 return false
511}
512
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700513func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700514 return c.Properties.UseVndk
515}
516
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800517func (c *Module) isCoverageVariant() bool {
518 return c.coverage.Properties.IsCoverageVariant
519}
520
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800521func (c *Module) isNdk() bool {
522 return inList(c.Name(), ndkMigratedLibs)
523}
524
Inseob Kim9516ee92019-05-09 10:56:13 +0900525func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800526 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900527 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800528}
529
Inseob Kim9516ee92019-05-09 10:56:13 +0900530func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800531 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900532 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800533}
534
Inseob Kim9516ee92019-05-09 10:56:13 +0900535func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800536 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900537 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800538}
539
Justin Yun8effde42017-06-23 19:24:43 +0900540func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800541 if vndkdep := c.vndkdep; vndkdep != nil {
542 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900543 }
544 return false
545}
546
Jooyung Han76106d92019-05-20 18:49:10 +0900547func (c *Module) vndkVersion() string {
548 if vndkdep := c.vndkdep; vndkdep != nil {
549 return vndkdep.Properties.Vndk.Version
550 }
551 return ""
552}
553
Yi Kong7e53c572018-02-14 18:16:12 +0800554func (c *Module) isPgoCompile() bool {
555 if pgo := c.pgo; pgo != nil {
556 return pgo.Properties.PgoCompile
557 }
558 return false
559}
560
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800561func (c *Module) isNDKStubLibrary() bool {
562 if _, ok := c.compiler.(*stubDecorator); ok {
563 return true
564 }
565 return false
566}
567
Logan Chienf3511742017-10-31 18:04:35 +0800568func (c *Module) isVndkSp() bool {
569 if vndkdep := c.vndkdep; vndkdep != nil {
570 return vndkdep.isVndkSp()
571 }
572 return false
573}
574
575func (c *Module) isVndkExt() bool {
576 if vndkdep := c.vndkdep; vndkdep != nil {
577 return vndkdep.isVndkExt()
578 }
579 return false
580}
581
Vic Yangefd249e2018-11-12 20:19:56 -0800582func (c *Module) mustUseVendorVariant() bool {
583 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
584}
585
Logan Chienf3511742017-10-31 18:04:35 +0800586func (c *Module) getVndkExtendsModuleName() string {
587 if vndkdep := c.vndkdep; vndkdep != nil {
588 return vndkdep.getVndkExtendsModuleName()
589 }
590 return ""
591}
592
Jiyong Park82e2bf32017-08-16 14:05:54 +0900593// Returns true only when this module is configured to have core and vendor
594// variants.
595func (c *Module) hasVendorVariant() bool {
596 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
597}
598
Jiyong Parkf9332f12018-02-01 00:54:12 +0900599func (c *Module) inRecovery() bool {
600 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
601}
602
603func (c *Module) onlyInRecovery() bool {
604 return c.ModuleBase.InstallInRecovery()
605}
606
Jiyong Park25fc6a92018-11-18 18:02:45 +0900607func (c *Module) IsStubs() bool {
608 if library, ok := c.linker.(*libraryDecorator); ok {
609 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900610 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
611 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900612 }
613 return false
614}
615
616func (c *Module) HasStubsVariants() bool {
617 if library, ok := c.linker.(*libraryDecorator); ok {
618 return len(library.Properties.Stubs.Versions) > 0
619 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700620 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
621 return len(library.Properties.Stubs.Versions) > 0
622 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900623 return false
624}
625
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900626func (c *Module) bootstrap() bool {
627 return Bool(c.Properties.Bootstrap)
628}
629
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700630func (c *Module) nativeCoverage() bool {
631 return c.linker != nil && c.linker.nativeCoverage()
632}
633
Jiyong Parkf1194352019-02-25 11:05:47 +0900634func isBionic(name string) bool {
635 switch name {
636 case "libc", "libm", "libdl", "linker":
637 return true
638 }
639 return false
640}
641
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700642func installToBootstrap(name string, config android.Config) bool {
643 if name == "libclang_rt.hwasan-aarch64-android" {
644 return inList("hwaddress", config.SanitizeDevice())
645 }
646 return isBionic(name)
647}
648
Colin Crossca860ac2016-01-04 14:34:37 -0800649type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700650 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800651 moduleContextImpl
652}
653
Colin Cross37047f12016-12-13 17:06:13 -0800654type depsContext struct {
655 android.BottomUpMutatorContext
656 moduleContextImpl
657}
658
Colin Crossca860ac2016-01-04 14:34:37 -0800659type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700660 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800661 moduleContextImpl
662}
663
Jiyong Park2db76922017-11-08 16:03:48 +0900664func (ctx *moduleContext) SocSpecific() bool {
665 return ctx.ModuleContext.SocSpecific() ||
666 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700667}
668
Colin Crossca860ac2016-01-04 14:34:37 -0800669type moduleContextImpl struct {
670 mod *Module
671 ctx BaseModuleContext
672}
673
Colin Crossb98c8b02016-07-29 13:44:28 -0700674func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800675 return ctx.mod.toolchain(ctx.ctx)
676}
677
678func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000679 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800680}
681
682func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900683 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800684}
685
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700686func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800687 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800688 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700689 }
690 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800691}
692
693func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700694 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700695 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900696 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700697 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900698 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
699 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
700 return "current"
701 }
702 return platform_vndk_ver
703 }
704 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800705 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900706 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700707 }
708 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800709}
710
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700711func (ctx *moduleContextImpl) useVndk() bool {
712 return ctx.mod.useVndk()
713}
Justin Yun8effde42017-06-23 19:24:43 +0900714
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800715func (ctx *moduleContextImpl) isNdk() bool {
716 return ctx.mod.isNdk()
717}
718
Inseob Kim9516ee92019-05-09 10:56:13 +0900719func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
720 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800721}
722
Inseob Kim9516ee92019-05-09 10:56:13 +0900723func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
724 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800725}
726
Inseob Kim9516ee92019-05-09 10:56:13 +0900727func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
728 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800729}
730
Logan Chienf3511742017-10-31 18:04:35 +0800731func (ctx *moduleContextImpl) isVndk() bool {
732 return ctx.mod.isVndk()
733}
734
Yi Kong7e53c572018-02-14 18:16:12 +0800735func (ctx *moduleContextImpl) isPgoCompile() bool {
736 return ctx.mod.isPgoCompile()
737}
738
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800739func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
740 return ctx.mod.isNDKStubLibrary()
741}
742
Justin Yun8effde42017-06-23 19:24:43 +0900743func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800744 return ctx.mod.isVndkSp()
745}
746
747func (ctx *moduleContextImpl) isVndkExt() bool {
748 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900749}
750
Vic Yangefd249e2018-11-12 20:19:56 -0800751func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
752 return ctx.mod.mustUseVendorVariant()
753}
754
Jiyong Parkf9332f12018-02-01 00:54:12 +0900755func (ctx *moduleContextImpl) inRecovery() bool {
756 return ctx.mod.inRecovery()
757}
758
Logan Chien2f2b8902018-07-10 15:01:19 +0800759// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900760func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800761 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
762 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800763 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800764
765 if ctx.ctx.Fuchsia() {
766 return false
767 }
768
Logan Chien2f2b8902018-07-10 15:01:19 +0800769 if sanitize := ctx.mod.sanitize; sanitize != nil {
770 if !sanitize.isVariantOnProductionDevice() {
771 return false
772 }
773 }
774 if !ctx.ctx.Device() {
775 // Host modules do not need ABI dumps.
776 return false
777 }
Logan Chienfa478c02018-12-28 16:25:39 +0800778 if !ctx.mod.IsForPlatform() {
779 // APEX variants do not need ABI dumps.
780 return false
781 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800782 if ctx.isStubs() {
783 // Stubs do not need ABI dumps.
784 return false
785 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800786 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800787 return true
788 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900789 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800790 return true
791 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900792 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800793 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
794 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800795 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800796 }
797 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800798}
799
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700800func (ctx *moduleContextImpl) selectedStl() string {
801 if stl := ctx.mod.stl; stl != nil {
802 return stl.Properties.SelectedStl
803 }
804 return ""
805}
806
Ivan Lozanobd721262018-11-27 14:33:03 -0800807func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
808 return ctx.mod.linker.useClangLld(actx)
809}
810
Colin Crossce75d2c2016-10-06 16:12:58 -0700811func (ctx *moduleContextImpl) baseModuleName() string {
812 return ctx.mod.ModuleBase.BaseModuleName()
813}
814
Logan Chienf3511742017-10-31 18:04:35 +0800815func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
816 return ctx.mod.getVndkExtendsModuleName()
817}
818
Jiyong Park58e364a2019-01-19 19:24:06 +0900819func (ctx *moduleContextImpl) apexName() string {
820 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900821}
822
Jiyong Parkb0788572018-12-20 22:10:17 +0900823func (ctx *moduleContextImpl) hasStubsVariants() bool {
824 return ctx.mod.HasStubsVariants()
825}
826
827func (ctx *moduleContextImpl) isStubs() bool {
828 return ctx.mod.IsStubs()
829}
830
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900831func (ctx *moduleContextImpl) bootstrap() bool {
832 return ctx.mod.bootstrap()
833}
834
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700835func (ctx *moduleContextImpl) nativeCoverage() bool {
836 return ctx.mod.nativeCoverage()
837}
838
Colin Cross635c3b02016-05-18 15:37:25 -0700839func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800840 return &Module{
841 hod: hod,
842 multilib: multilib,
843 }
844}
845
Colin Cross635c3b02016-05-18 15:37:25 -0700846func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800847 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700848 module.features = []feature{
849 &tidyFeature{},
850 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700851 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800852 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800853 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800854 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900855 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700856 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700857 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800858 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800859 return module
860}
861
Colin Crossce75d2c2016-10-06 16:12:58 -0700862func (c *Module) Prebuilt() *android.Prebuilt {
863 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
864 return p.prebuilt()
865 }
866 return nil
867}
868
869func (c *Module) Name() string {
870 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700871 if p, ok := c.linker.(interface {
872 Name(string) string
873 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700874 name = p.Name(name)
875 }
876 return name
877}
878
Alex Light3d673592019-01-18 14:37:31 -0800879func (c *Module) Symlinks() []string {
880 if p, ok := c.installer.(interface {
881 symlinkList() []string
882 }); ok {
883 return p.symlinkList()
884 }
885 return nil
886}
887
Jeff Gaston294356f2017-09-27 17:05:30 -0700888// orderDeps reorders dependencies into a list such that if module A depends on B, then
889// A will precede B in the resultant list.
890// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800891// Note that directSharedDeps should be the analogous static library for each shared lib dep
892func 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 -0700893 // If A depends on B, then
894 // Every list containing A will also contain B later in the list
895 // So, after concatenating all lists, the final instance of B will have come from the same
896 // original list as the final instance of A
897 // So, the final instance of B will be later in the concatenation than the final A
898 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
899 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800900 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700901 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800902 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
903 }
904 for _, dep := range directSharedDeps {
905 orderedAllDeps = append(orderedAllDeps, dep)
906 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700907 }
908
Colin Crossb6715442017-10-24 11:13:31 -0700909 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700910
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800911 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700912 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800913 // resultant list to only what the caller has chosen to include in directStaticDeps
914 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700915
916 return orderedAllDeps, orderedDeclaredDeps
917}
918
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800919func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
920 // convert Module to Path
921 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
922 staticDepFiles := []android.Path{}
923 for _, dep := range staticDeps {
924 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
925 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700926 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800927 sharedDepFiles := []android.Path{}
928 for _, sharedDep := range sharedDeps {
929 staticAnalogue := sharedDep.staticVariant
930 if staticAnalogue != nil {
931 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
932 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
933 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700934 }
935
936 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800937 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700938
939 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700940}
941
Colin Cross635c3b02016-05-18 15:37:25 -0700942func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jooyung Han38002912019-05-16 04:01:54 +0900943 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900944
Colin Crossca860ac2016-01-04 14:34:37 -0800945 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700946 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800947 moduleContextImpl: moduleContextImpl{
948 mod: c,
949 },
950 }
951 ctx.ctx = ctx
952
Colin Crossf18e1102017-11-16 14:33:08 -0800953 deps := c.depsToPaths(ctx)
954 if ctx.Failed() {
955 return
956 }
957
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700958 if c.Properties.Clang != nil && *c.Properties.Clang == false {
959 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
960 }
961
Colin Crossca860ac2016-01-04 14:34:37 -0800962 flags := Flags{
963 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800964 }
Colin Crossca860ac2016-01-04 14:34:37 -0800965 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800966 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800967 }
968 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700969 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800970 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700971 if c.stl != nil {
972 flags = c.stl.flags(ctx, flags)
973 }
Colin Cross16b23492016-01-06 14:41:07 -0800974 if c.sanitize != nil {
975 flags = c.sanitize.flags(ctx, flags)
976 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800977 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700978 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -0800979 }
Stephen Craneba090d12017-05-09 15:44:35 -0700980 if c.lto != nil {
981 flags = c.lto.flags(ctx, flags)
982 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700983 if c.pgo != nil {
984 flags = c.pgo.flags(ctx, flags)
985 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800986 if c.xom != nil {
987 flags = c.xom.flags(ctx, flags)
988 }
Colin Crossca860ac2016-01-04 14:34:37 -0800989 for _, feature := range c.features {
990 flags = feature.flags(ctx, flags)
991 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800992 if ctx.Failed() {
993 return
994 }
995
Colin Crossb98c8b02016-07-29 13:44:28 -0700996 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
997 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
998 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800999
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001000 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001001
1002 for _, dir := range deps.IncludeDirs {
1003 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1004 }
1005 for _, dir := range deps.SystemIncludeDirs {
1006 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1007 }
1008
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001009 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001010 // We need access to all the flags seen by a source file.
1011 if c.sabi != nil {
1012 flags = c.sabi.flags(ctx, flags)
1013 }
Colin Crossca860ac2016-01-04 14:34:37 -08001014 // Optimization to reduce size of build.ninja
1015 // Replace the long list of flags for each file with a module-local variable
1016 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1017 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1018 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1019 flags.CFlags = []string{"$cflags"}
1020 flags.CppFlags = []string{"$cppflags"}
1021 flags.AsFlags = []string{"$asflags"}
1022
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001023 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001024 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001025 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001026 if ctx.Failed() {
1027 return
1028 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001029 }
1030
Colin Crossca860ac2016-01-04 14:34:37 -08001031 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001032 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001033 if ctx.Failed() {
1034 return
1035 }
Colin Cross635c3b02016-05-18 15:37:25 -07001036 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001037
1038 // If a lib is directly included in any of the APEXes, unhide the stubs
1039 // variant having the latest version gets visible to make. In addition,
1040 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1041 // force anything in the make world to link against the stubs library.
1042 // (unless it is explicitly referenced via .bootstrap suffix or the
1043 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001044 if c.HasStubsVariants() &&
1045 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001046 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1047 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001048 c.Properties.HideFromMake = false // unhide
1049 // Note: this is still non-installable
1050 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001051 }
Colin Cross5049f022015-03-18 13:28:46 -07001052
Inseob Kim1f086e22019-05-09 13:29:15 +09001053 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001054 c.installer.install(ctx, c.outputFile.Path())
1055 if ctx.Failed() {
1056 return
Colin Crossca860ac2016-01-04 14:34:37 -08001057 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001058 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001059}
1060
Colin Cross0ea8ba82019-06-06 14:33:29 -07001061func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001062 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001063 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001064 }
Colin Crossca860ac2016-01-04 14:34:37 -08001065 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001066}
1067
Colin Crossca860ac2016-01-04 14:34:37 -08001068func (c *Module) begin(ctx BaseModuleContext) {
1069 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001070 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001071 }
Colin Crossca860ac2016-01-04 14:34:37 -08001072 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001073 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001074 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001075 if c.stl != nil {
1076 c.stl.begin(ctx)
1077 }
Colin Cross16b23492016-01-06 14:41:07 -08001078 if c.sanitize != nil {
1079 c.sanitize.begin(ctx)
1080 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001081 if c.coverage != nil {
1082 c.coverage.begin(ctx)
1083 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001084 if c.sabi != nil {
1085 c.sabi.begin(ctx)
1086 }
Justin Yun8effde42017-06-23 19:24:43 +09001087 if c.vndkdep != nil {
1088 c.vndkdep.begin(ctx)
1089 }
Stephen Craneba090d12017-05-09 15:44:35 -07001090 if c.lto != nil {
1091 c.lto.begin(ctx)
1092 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001093 if c.pgo != nil {
1094 c.pgo.begin(ctx)
1095 }
Colin Crossca860ac2016-01-04 14:34:37 -08001096 for _, feature := range c.features {
1097 feature.begin(ctx)
1098 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001099 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001100 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001101 if err != nil {
1102 ctx.PropertyErrorf("sdk_version", err.Error())
1103 }
Nan Zhang0007d812017-11-07 10:57:05 -08001104 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001105 }
Colin Crossca860ac2016-01-04 14:34:37 -08001106}
1107
Colin Cross37047f12016-12-13 17:06:13 -08001108func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001109 deps := Deps{}
1110
1111 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001112 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001113 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001114 // Add the PGO dependency (the clang_rt.profile runtime library), which
1115 // sometimes depends on symbols from libgcc, before libgcc gets added
1116 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001117 if c.pgo != nil {
1118 deps = c.pgo.deps(ctx, deps)
1119 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001120 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001121 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001122 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001123 if c.stl != nil {
1124 deps = c.stl.deps(ctx, deps)
1125 }
Colin Cross16b23492016-01-06 14:41:07 -08001126 if c.sanitize != nil {
1127 deps = c.sanitize.deps(ctx, deps)
1128 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001129 if c.coverage != nil {
1130 deps = c.coverage.deps(ctx, deps)
1131 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001132 if c.sabi != nil {
1133 deps = c.sabi.deps(ctx, deps)
1134 }
Justin Yun8effde42017-06-23 19:24:43 +09001135 if c.vndkdep != nil {
1136 deps = c.vndkdep.deps(ctx, deps)
1137 }
Stephen Craneba090d12017-05-09 15:44:35 -07001138 if c.lto != nil {
1139 deps = c.lto.deps(ctx, deps)
1140 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001141 for _, feature := range c.features {
1142 deps = feature.deps(ctx, deps)
1143 }
1144
Colin Crossb6715442017-10-24 11:13:31 -07001145 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1146 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1147 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1148 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1149 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1150 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001151 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001152
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001153 for _, lib := range deps.ReexportSharedLibHeaders {
1154 if !inList(lib, deps.SharedLibs) {
1155 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1156 }
1157 }
1158
1159 for _, lib := range deps.ReexportStaticLibHeaders {
1160 if !inList(lib, deps.StaticLibs) {
1161 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1162 }
1163 }
1164
Colin Cross5950f382016-12-13 12:50:57 -08001165 for _, lib := range deps.ReexportHeaderLibHeaders {
1166 if !inList(lib, deps.HeaderLibs) {
1167 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1168 }
1169 }
1170
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001171 for _, gen := range deps.ReexportGeneratedHeaders {
1172 if !inList(gen, deps.GeneratedHeaders) {
1173 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1174 }
1175 }
1176
Colin Crossc99deeb2016-04-11 15:06:20 -07001177 return deps
1178}
1179
Dan Albert7e9d2952016-08-04 13:02:36 -07001180func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001181 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001182 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001183 moduleContextImpl: moduleContextImpl{
1184 mod: c,
1185 },
1186 }
1187 ctx.ctx = ctx
1188
Colin Crossca860ac2016-01-04 14:34:37 -08001189 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001190}
1191
Jiyong Park7ed9de32018-10-15 22:25:07 +09001192// Split name#version into name and version
1193func stubsLibNameAndVersion(name string) (string, string) {
1194 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1195 version := name[sharp+1:]
1196 libname := name[:sharp]
1197 return libname, version
1198 }
1199 return name, ""
1200}
1201
Colin Cross1e676be2016-10-12 14:38:15 -07001202func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001203 ctx := &depsContext{
1204 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001205 moduleContextImpl: moduleContextImpl{
1206 mod: c,
1207 },
1208 }
1209 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001210
Colin Crossc99deeb2016-04-11 15:06:20 -07001211 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001212
Dan Albert914449f2016-06-17 16:45:24 -07001213 variantNdkLibs := []string{}
1214 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001215 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001216 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001217
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001218 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1219 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001220 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001221 // 1. Name of an NDK library that refers to a prebuilt module.
1222 // For each of these, it adds the name of the prebuilt module (which will be in
1223 // prebuilts/ndk) to the list of nonvariant libs.
1224 // 2. Name of an NDK library that refers to an ndk_library module.
1225 // For each of these, it adds the name of the ndk_library module to the list of
1226 // variant libs.
1227 // 3. Anything else (so anything that isn't an NDK library).
1228 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001229 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001230 // The caller can then know to add the variantLibs dependencies differently from the
1231 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001232
1233 llndkLibraries := llndkLibraries(actx.Config())
1234 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001235 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1236 variantLibs = []string{}
1237 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001238 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001239 // strip #version suffix out
1240 name, _ := stubsLibNameAndVersion(entry)
1241 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1242 if !inList(name, ndkMigratedLibs) {
1243 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001244 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001245 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001246 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001247 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001248 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001249 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001250 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001251 if actx.OtherModuleExists(vendorPublicLib) {
1252 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1253 } else {
1254 // This can happen if vendor_public_library module is defined in a
1255 // namespace that isn't visible to the current module. In that case,
1256 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001257 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001258 }
Dan Albert914449f2016-06-17 16:45:24 -07001259 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001260 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001261 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001262 }
1263 }
Dan Albert914449f2016-06-17 16:45:24 -07001264 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001265 }
1266
Dan Albert914449f2016-06-17 16:45:24 -07001267 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1268 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001269 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001270 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001271
Jiyong Park7e636d02019-01-28 16:16:54 +09001272 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001273 if c.linker != nil {
1274 if library, ok := c.linker.(*libraryDecorator); ok {
1275 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001276 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001277 }
1278 }
1279 }
1280
Colin Cross32ec36c2016-12-15 07:39:51 -08001281 for _, lib := range deps.HeaderLibs {
1282 depTag := headerDepTag
1283 if inList(lib, deps.ReexportHeaderLibHeaders) {
1284 depTag = headerExportDepTag
1285 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001286 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001287 actx.AddFarVariationDependencies([]blueprint.Variation{
1288 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001289 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001290 }, depTag, lib)
1291 } else {
1292 actx.AddVariationDependencies(nil, depTag, lib)
1293 }
1294 }
1295
1296 if buildStubs {
1297 // Stubs lib does not have dependency to other static/shared libraries.
1298 // Don't proceed.
1299 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001300 }
Colin Cross5950f382016-12-13 12:50:57 -08001301
Inseob Kimc0907f12019-02-08 21:00:45 +09001302 syspropImplLibraries := syspropImplLibraries(actx.Config())
1303
Jiyong Park5d1598f2019-02-25 22:14:17 +09001304 for _, lib := range deps.WholeStaticLibs {
1305 depTag := wholeStaticDepTag
1306 if impl, ok := syspropImplLibraries[lib]; ok {
1307 lib = impl
1308 }
1309 actx.AddVariationDependencies([]blueprint.Variation{
1310 {Mutator: "link", Variation: "static"},
1311 }, depTag, lib)
1312 }
1313
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001314 for _, lib := range deps.StaticLibs {
1315 depTag := staticDepTag
1316 if inList(lib, deps.ReexportStaticLibHeaders) {
1317 depTag = staticExportDepTag
1318 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001319
1320 if impl, ok := syspropImplLibraries[lib]; ok {
1321 lib = impl
1322 }
1323
Dan Willemsen59339a22018-07-22 21:18:45 -07001324 actx.AddVariationDependencies([]blueprint.Variation{
1325 {Mutator: "link", Variation: "static"},
1326 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001327 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001328
Dan Willemsen59339a22018-07-22 21:18:45 -07001329 actx.AddVariationDependencies([]blueprint.Variation{
1330 {Mutator: "link", Variation: "static"},
1331 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001332
Jiyong Park25fc6a92018-11-18 18:02:45 +09001333 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1334 var variations []blueprint.Variation
1335 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001336 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001337 if version != "" && versionVariantAvail {
1338 // Version is explicitly specified. i.e. libFoo#30
1339 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1340 depTag.explicitlyVersioned = true
1341 }
1342 actx.AddVariationDependencies(variations, depTag, name)
1343
1344 // If the version is not specified, add dependency to the latest stubs library.
1345 // The stubs library will be used when the depending module is built for APEX and
1346 // the dependent module is not in the same APEX.
1347 latestVersion := latestStubsVersionFor(actx.Config(), name)
1348 if version == "" && latestVersion != "" && versionVariantAvail {
1349 actx.AddVariationDependencies([]blueprint.Variation{
1350 {Mutator: "link", Variation: "shared"},
1351 {Mutator: "version", Variation: latestVersion},
1352 }, depTag, name)
1353 // Note that depTag.explicitlyVersioned is false in this case.
1354 }
1355 }
1356
Jiyong Park7ed9de32018-10-15 22:25:07 +09001357 // shared lib names without the #version suffix
1358 var sharedLibNames []string
1359
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001360 for _, lib := range deps.SharedLibs {
1361 depTag := sharedDepTag
1362 if inList(lib, deps.ReexportSharedLibHeaders) {
1363 depTag = sharedExportDepTag
1364 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001365
1366 if impl, ok := syspropImplLibraries[lib]; ok {
1367 lib = impl
1368 }
1369
1370 name, version := stubsLibNameAndVersion(lib)
1371 sharedLibNames = append(sharedLibNames, name)
1372
Jiyong Park25fc6a92018-11-18 18:02:45 +09001373 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001374 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001375
Jiyong Park7ed9de32018-10-15 22:25:07 +09001376 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001377 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001378 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1379 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1380 // linking against both the stubs lib and the non-stubs lib at the same time.
1381 continue
1382 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001383 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001384 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001385
Dan Willemsen59339a22018-07-22 21:18:45 -07001386 actx.AddVariationDependencies([]blueprint.Variation{
1387 {Mutator: "link", Variation: "shared"},
1388 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001389
Colin Cross68861832016-07-08 10:41:41 -07001390 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001391
1392 for _, gen := range deps.GeneratedHeaders {
1393 depTag := genHeaderDepTag
1394 if inList(gen, deps.ReexportGeneratedHeaders) {
1395 depTag = genHeaderExportDepTag
1396 }
1397 actx.AddDependency(c, depTag, gen)
1398 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001399
Colin Cross42d48b72018-08-29 14:10:52 -07001400 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001401
1402 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001403 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001404 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001405 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001406 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001407 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001408 if deps.LinkerFlagsFile != "" {
1409 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1410 }
1411 if deps.DynamicLinker != "" {
1412 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001413 }
Dan Albert914449f2016-06-17 16:45:24 -07001414
1415 version := ctx.sdkVersion()
1416 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001417 {Mutator: "ndk_api", Variation: version},
1418 {Mutator: "link", Variation: "shared"},
1419 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001420 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001421 {Mutator: "ndk_api", Variation: version},
1422 {Mutator: "link", Variation: "shared"},
1423 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001424
1425 if vndkdep := c.vndkdep; vndkdep != nil {
1426 if vndkdep.isVndkExt() {
1427 baseModuleMode := vendorMode
1428 if actx.DeviceConfig().VndkVersion() == "" {
1429 baseModuleMode = coreMode
1430 }
1431 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001432 {Mutator: "image", Variation: baseModuleMode},
1433 {Mutator: "link", Variation: "shared"},
1434 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001435 }
1436 }
Colin Cross6362e272015-10-29 15:25:03 -07001437}
Colin Cross21b9a242015-03-24 14:15:58 -07001438
Colin Crosse40b4ea2018-10-02 22:25:58 -07001439func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001440 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1441 c.beginMutator(ctx)
1442 }
1443}
1444
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001445// Whether a module can link to another module, taking into
1446// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001447func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001448 if from.Target().Os != android.Android {
1449 // Host code is not restricted
1450 return
1451 }
1452 if from.Properties.UseVndk {
1453 // Though vendor code is limited by the vendor mutator,
1454 // each vendor-available module needs to check
1455 // link-type for VNDK.
1456 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001457 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001458 }
1459 return
1460 }
Nan Zhang0007d812017-11-07 10:57:05 -08001461 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001462 // Platform code can link to anything
1463 return
1464 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001465 if from.inRecovery() {
1466 // Recovery code is not NDK
1467 return
1468 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001469 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1470 // These are always allowed
1471 return
1472 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001473 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1474 // These are allowed, but they don't set sdk_version
1475 return
1476 }
1477 if _, ok := to.linker.(*stubDecorator); ok {
1478 // These aren't real libraries, but are the stub shared libraries that are included in
1479 // the NDK.
1480 return
1481 }
Logan Chien834b9a62019-01-14 15:39:03 +08001482
1483 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1484 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1485 // to link to libc++ (non-NDK and without sdk_version).
1486 return
1487 }
1488
Nan Zhang0007d812017-11-07 10:57:05 -08001489 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001490 // NDK code linking to platform code is never okay.
1491 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1492 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001493 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001494 }
1495
1496 // At this point we know we have two NDK libraries, but we need to
1497 // check that we're not linking against anything built against a higher
1498 // API level, as it is only valid to link against older or equivalent
1499 // APIs.
1500
Inseob Kim01a28722018-04-11 09:48:45 +09001501 // Current can link against anything.
1502 if String(from.Properties.Sdk_version) != "current" {
1503 // Otherwise we need to check.
1504 if String(to.Properties.Sdk_version) == "current" {
1505 // Current can't be linked against by anything else.
1506 ctx.ModuleErrorf("links %q built against newer API version %q",
1507 ctx.OtherModuleName(to), "current")
1508 } else {
1509 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1510 if err != nil {
1511 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001512 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001513 String(from.Properties.Sdk_version))
1514 }
1515 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1516 if err != nil {
1517 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001518 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001519 String(to.Properties.Sdk_version))
1520 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001521
Inseob Kim01a28722018-04-11 09:48:45 +09001522 if toApi > fromApi {
1523 ctx.ModuleErrorf("links %q built against newer API version %q",
1524 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1525 }
1526 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001527 }
Dan Albert202fe492017-12-15 13:56:59 -08001528
1529 // Also check that the two STL choices are compatible.
1530 fromStl := from.stl.Properties.SelectedStl
1531 toStl := to.stl.Properties.SelectedStl
1532 if fromStl == "" || toStl == "" {
1533 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001534 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001535 // We can be permissive with the system "STL" since it is only the C++
1536 // ABI layer, but in the future we should make sure that everyone is
1537 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001538 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001539 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1540 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1541 to.stl.Properties.SelectedStl)
1542 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001543}
1544
Jiyong Park5fb8c102018-04-09 12:03:06 +09001545// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001546// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1547// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001548// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001549func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001550 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001551 check := func(child, parent android.Module) bool {
1552 to, ok := child.(*Module)
1553 if !ok {
1554 // follow thru cc.Defaults, etc.
1555 return true
1556 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001557
Jooyung Hana70f0672019-01-18 15:20:43 +09001558 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1559 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001560 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001561
1562 // if target lib has no vendor variant, keep checking dependency graph
1563 if !to.hasVendorVariant() {
1564 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001565 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001566
Inseob Kim9516ee92019-05-09 10:56:13 +09001567 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001568 return false
1569 }
1570
1571 var stringPath []string
1572 for _, m := range ctx.GetWalkPath() {
1573 stringPath = append(stringPath, m.Name())
1574 }
1575 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1576 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1577 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1578 return false
1579 }
1580 if module, ok := ctx.Module().(*Module); ok {
1581 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001582 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001583 ctx.WalkDeps(check)
1584 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001585 }
1586 }
1587}
1588
Colin Crossc99deeb2016-04-11 15:06:20 -07001589// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001590func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001591 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001592
Jeff Gaston294356f2017-09-27 17:05:30 -07001593 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001594 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001595
Inseob Kim9516ee92019-05-09 10:56:13 +09001596 llndkLibraries := llndkLibraries(ctx.Config())
1597 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1598
Inseob Kim69378442019-06-03 19:10:47 +09001599 reexportExporter := func(exporter exportedFlagsProducer) {
1600 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1601 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1602 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1603 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1604 }
1605
Colin Crossd11fcda2017-10-23 17:59:01 -07001606 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001607 depName := ctx.OtherModuleName(dep)
1608 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001609
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001610 ccDep, _ := dep.(*Module)
1611 if ccDep == nil {
1612 // handling for a few module types that aren't cc Module but that are also supported
1613 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001614 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001615 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001616 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1617 genRule.GeneratedSourceFiles()...)
1618 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001619 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001620 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001621 // Support exported headers from a generated_sources dependency
1622 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001623 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001624 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001625 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001626 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001627 dirs := genRule.GeneratedHeaderDirs().Strings()
1628 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001629 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001630 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1631 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001632 // 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 +09001633 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001634
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001635 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001636 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001637 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001638 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001639 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001640 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001641 files := genRule.GeneratedSourceFiles()
1642 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001643 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001644 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001645 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 -07001646 }
1647 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001648 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001649 }
Colin Crossca860ac2016-01-04 14:34:37 -08001650 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001651 return
1652 }
1653
Colin Crossfe17f6f2019-03-28 19:30:56 -07001654 if depTag == android.ProtoPluginDepTag {
1655 return
1656 }
1657
Colin Crossd11fcda2017-10-23 17:59:01 -07001658 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001659 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1660 return
1661 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001662 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001663 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001664 return
1665 }
1666
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001667 // re-exporting flags
1668 if depTag == reuseObjTag {
1669 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001670 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001671 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001672 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001673 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001674 return
1675 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001676 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001677
Jiyong Parke4bb9862019-02-01 00:31:10 +09001678 if depTag == staticVariantTag {
1679 if _, ok := ccDep.compiler.(libraryInterface); ok {
1680 c.staticVariant = ccDep
1681 return
1682 }
1683 }
1684
Jiyong Park25fc6a92018-11-18 18:02:45 +09001685 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1686 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1687 // won't be matched to sharedDepTag and lateSharedDepTag.
1688 explicitlyVersioned := false
1689 if t, ok := depTag.(dependencyTag); ok {
1690 explicitlyVersioned = t.explicitlyVersioned
1691 t.explicitlyVersioned = false
1692 depTag = t
1693 }
1694
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001695 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001696 depIsStatic := false
1697 switch depTag {
1698 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1699 depIsStatic = true
1700 }
1701 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001702 depIsStubs := dependentLibrary.buildStubs()
1703 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001704 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001705 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001706
1707 var useThisDep bool
1708 if depIsStubs && explicitlyVersioned {
1709 // Always respect dependency to the versioned stubs (i.e. libX#10)
1710 useThisDep = true
1711 } else if !depHasStubs {
1712 // Use non-stub variant if that is the only choice
1713 // (i.e. depending on a lib without stubs.version property)
1714 useThisDep = true
1715 } else if c.IsForPlatform() {
1716 // If not building for APEX, use stubs only when it is from
1717 // an APEX (and not from platform)
1718 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001719 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001720 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001721 // always link to non-stub variant
1722 useThisDep = !depIsStubs
1723 }
1724 } else {
1725 // If building for APEX, use stubs only when it is not from
1726 // the same APEX
1727 useThisDep = (depInSameApex != depIsStubs)
1728 }
1729
1730 if !useThisDep {
1731 return // stop processing this dep
1732 }
1733 }
1734
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001735 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001736 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1737 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1738 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1739 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001740
1741 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001742 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001743 // 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 -07001744 // Re-exported shared library headers must be included as well since they can help us with type information
1745 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001746 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1747 // scripts.
1748 c.sabi.Properties.ReexportedIncludes = append(
1749 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001750 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001751 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001752
Logan Chienf3511742017-10-31 18:04:35 +08001753 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001754 }
1755
Colin Cross26c34ed2016-09-30 17:10:16 -07001756 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001757 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001758
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001759 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001760 depFile := android.OptionalPath{}
1761
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001762 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001763 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001764 ptr = &depPaths.SharedLibs
1765 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001766 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001767 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001768 case earlySharedDepTag:
1769 ptr = &depPaths.EarlySharedLibs
1770 depPtr = &depPaths.EarlySharedLibsDeps
1771 depFile = ccDep.linker.(libraryInterface).toc()
1772 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001773 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001774 ptr = &depPaths.LateSharedLibs
1775 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001776 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001777 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001778 ptr = nil
1779 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001780 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001781 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001782 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001783 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001784 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001785 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001786 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001787 return
1788 }
1789
1790 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001791 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001792 for i := range missingDeps {
1793 missingDeps[i] += postfix
1794 }
1795 ctx.AddMissingDependencies(missingDeps)
1796 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001797 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001798 case headerDepTag:
1799 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001800 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001801 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001802 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001803 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001804 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001805 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001806 case dynamicLinkerDepTag:
1807 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001808 }
1809
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001810 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001811 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001812 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001813 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001814 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001815 return
1816 }
1817
1818 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001819 // in static libraries act as if they were whole static libraries. The same goes for
1820 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001821 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1822 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001823 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1824 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001825
Dan Willemsen581341d2017-02-09 16:16:31 -08001826 }
1827
Colin Cross26c34ed2016-09-30 17:10:16 -07001828 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001829 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001830 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001831 return
1832 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001833 *ptr = append(*ptr, linkFile.Path())
1834 }
1835
Colin Crossc99deeb2016-04-11 15:06:20 -07001836 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001837 dep := depFile
1838 if !dep.Valid() {
1839 dep = linkFile
1840 }
1841 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001842 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001843
Logan Chien43d34c32017-12-20 01:17:32 +08001844 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001845 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001846 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001847 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001848 isLLndk := inList(libName, *llndkLibraries)
1849 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001850 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001851
1852 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1853 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1854 // core module instead.
1855 return libName
1856 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001857 // The vendor module in Make will have been renamed to not conflict with the core
1858 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001859 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001860 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001861 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001862 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1863 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001864 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001865 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001866 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001867 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001868 }
Logan Chien43d34c32017-12-20 01:17:32 +08001869 }
1870
1871 // Export the shared libs to Make.
1872 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001873 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001874 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001875 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001876 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001877 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001878 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001879 c.Properties.ApexesProvidingSharedLibs = append(
1880 c.Properties.ApexesProvidingSharedLibs, an)
1881 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001882 }
1883 }
1884
Jiyong Park27b188b2017-07-18 13:23:39 +09001885 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001886 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001887 c.Properties.AndroidMkSharedLibs = append(
1888 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001889 case ndkStubDepTag, ndkLateStubDepTag:
1890 ndkStub := ccDep.linker.(*stubDecorator)
1891 c.Properties.AndroidMkSharedLibs = append(
1892 c.Properties.AndroidMkSharedLibs,
1893 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001894 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1895 c.Properties.AndroidMkStaticLibs = append(
1896 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001897 case runtimeDepTag:
1898 c.Properties.AndroidMkRuntimeLibs = append(
1899 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001900 case wholeStaticDepTag:
1901 c.Properties.AndroidMkWholeStaticLibs = append(
1902 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001903 }
Colin Crossca860ac2016-01-04 14:34:37 -08001904 })
1905
Jeff Gaston294356f2017-09-27 17:05:30 -07001906 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001907 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001908
Colin Crossdd84e052017-05-17 13:44:16 -07001909 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001910 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001911 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1912 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001913 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001914 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1915 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001916 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001917 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001918
1919 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001920 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001921 }
Colin Crossdd84e052017-05-17 13:44:16 -07001922
Colin Crossca860ac2016-01-04 14:34:37 -08001923 return depPaths
1924}
1925
1926func (c *Module) InstallInData() bool {
1927 if c.installer == nil {
1928 return false
1929 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001930 return c.installer.inData()
1931}
1932
1933func (c *Module) InstallInSanitizerDir() bool {
1934 if c.installer == nil {
1935 return false
1936 }
1937 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001938 return true
1939 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001940 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001941}
1942
Jiyong Parkf9332f12018-02-01 00:54:12 +09001943func (c *Module) InstallInRecovery() bool {
1944 return c.inRecovery()
1945}
1946
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001947func (c *Module) HostToolPath() android.OptionalPath {
1948 if c.installer == nil {
1949 return android.OptionalPath{}
1950 }
1951 return c.installer.hostToolPath()
1952}
1953
Nan Zhangd4e641b2017-07-12 12:55:28 -07001954func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1955 return c.outputFile
1956}
1957
Colin Cross41955e82019-05-29 14:40:35 -07001958func (c *Module) OutputFiles(tag string) (android.Paths, error) {
1959 switch tag {
1960 case "":
1961 if c.outputFile.Valid() {
1962 return android.Paths{c.outputFile.Path()}, nil
1963 }
1964 return android.Paths{}, nil
1965 default:
1966 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001967 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001968}
1969
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001970func (c *Module) static() bool {
1971 if static, ok := c.linker.(interface {
1972 static() bool
1973 }); ok {
1974 return static.static()
1975 }
1976 return false
1977}
1978
Jiyong Park379de2f2018-12-19 02:47:14 +09001979func (c *Module) staticBinary() bool {
1980 if static, ok := c.linker.(interface {
1981 staticBinary() bool
1982 }); ok {
1983 return static.staticBinary()
1984 }
1985 return false
1986}
1987
Jooyung Han38002912019-05-16 04:01:54 +09001988func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
1989 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07001990 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09001991 if lib, ok := c.linker.(*llndkStubDecorator); ok {
1992 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07001993 return "native:vndk"
1994 }
Jooyung Han38002912019-05-16 04:01:54 +09001995 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07001996 }
Jooyung Han38002912019-05-16 04:01:54 +09001997 if c.isVndk() && !c.isVndkExt() {
1998 if Bool(c.VendorProperties.Vendor_available) {
1999 return "native:vndk"
2000 }
2001 return "native:vndk_private"
2002 }
2003 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002004 } else if c.inRecovery() {
2005 return "native:recovery"
2006 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2007 return "native:ndk:none:none"
2008 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2009 //family, link := getNdkStlFamilyAndLinkType(c)
2010 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002011 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002012 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002013 } else {
2014 return "native:platform"
2015 }
2016}
2017
Jiyong Park9d452992018-10-03 00:38:19 +09002018// Overrides ApexModule.IsInstallabeToApex()
2019// Only shared libraries are installable to APEX.
2020func (c *Module) IsInstallableToApex() bool {
2021 if shared, ok := c.linker.(interface {
2022 shared() bool
2023 }); ok {
2024 return shared.shared()
2025 }
2026 return false
2027}
2028
Inseob Kim1f086e22019-05-09 13:29:15 +09002029func (c *Module) installable() bool {
2030 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2031}
2032
Jiyong Park3b1746a2019-01-29 11:15:04 +09002033func (c *Module) imageVariation() string {
2034 variation := "core"
2035 if c.useVndk() {
2036 variation = "vendor"
2037 } else if c.inRecovery() {
2038 variation = "recovery"
2039 }
2040 return variation
2041}
2042
bralee3f49f4d2019-03-04 06:58:15 +08002043func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002044 outputFiles, err := c.OutputFiles("")
2045 if err != nil {
2046 panic(err)
2047 }
2048 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002049}
2050
Logan Chien41eabe62019-04-10 13:33:58 +08002051func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2052 if c.linker != nil {
2053 if library, ok := c.linker.(*libraryDecorator); ok {
2054 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2055 }
2056 }
2057}
2058
Colin Cross2ba19d92015-05-07 15:44:20 -07002059//
Colin Crosscfad1192015-11-02 16:43:11 -08002060// Defaults
2061//
Colin Crossca860ac2016-01-04 14:34:37 -08002062type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002063 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002064 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002065 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002066}
2067
Patrice Arrudac249c712019-03-19 17:00:29 -07002068// cc_defaults provides a set of properties that can be inherited by other cc
2069// modules. A module can use the properties from a cc_defaults using
2070// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2071// merged (when possible) by prepending the default module's values to the
2072// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002073func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002074 return DefaultsFactory()
2075}
2076
Colin Cross36242852017-06-23 15:06:31 -07002077func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002078 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002079
Colin Cross36242852017-06-23 15:06:31 -07002080 module.AddProperties(props...)
2081 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002082 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002083 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002084 &BaseCompilerProperties{},
2085 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002086 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002087 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002088 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002089 &TestProperties{},
2090 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002091 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002092 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002093 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002094 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002095 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002096 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002097 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002098 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002099 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002100 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002101 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002102 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002103 )
Colin Crosscfad1192015-11-02 16:43:11 -08002104
Colin Cross1f44a3a2017-07-07 14:33:33 -07002105 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002106 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002107
2108 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002109}
2110
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002111const (
2112 // coreMode is the variant used for framework-private libraries, or
2113 // SDK libraries. (which framework-private libraries can use)
2114 coreMode = "core"
2115
2116 // vendorMode is the variant used for /vendor code that compiles
2117 // against the VNDK.
2118 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002119
2120 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002121)
2122
Jiyong Park6a43f042017-10-12 23:05:00 +09002123func squashVendorSrcs(m *Module) {
2124 if lib, ok := m.compiler.(*libraryDecorator); ok {
2125 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2126 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2127
2128 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2129 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2130 }
2131}
2132
Jiyong Parkf9332f12018-02-01 00:54:12 +09002133func squashRecoverySrcs(m *Module) {
2134 if lib, ok := m.compiler.(*libraryDecorator); ok {
2135 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2136 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2137
2138 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2139 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2140 }
2141}
2142
Jiyong Parkda6eb592018-12-19 17:12:36 +09002143func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002144 if mctx.Os() != android.Android {
2145 return
2146 }
2147
Jiyong Park7ed9de32018-10-15 22:25:07 +09002148 if g, ok := mctx.Module().(*genrule.Module); ok {
2149 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002150 var coreVariantNeeded bool = false
2151 var vendorVariantNeeded bool = false
2152 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002153 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002154 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002155 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002156 coreVariantNeeded = true
2157 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002158 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002159 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002160 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002161 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002162 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002163 if Bool(props.Recovery_available) {
2164 recoveryVariantNeeded = true
2165 }
2166
Jiyong Park413cc742018-06-19 01:46:06 +09002167 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002168 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002169 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002170 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002171 recoveryVariantNeeded = false
2172 }
2173 }
2174
Jiyong Park3f736c92018-05-24 13:36:56 +09002175 var variants []string
2176 if coreVariantNeeded {
2177 variants = append(variants, coreMode)
2178 }
2179 if vendorVariantNeeded {
2180 variants = append(variants, vendorMode)
2181 }
2182 if recoveryVariantNeeded {
2183 variants = append(variants, recoveryMode)
2184 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002185 mod := mctx.CreateVariations(variants...)
2186 for i, v := range variants {
2187 if v == recoveryMode {
2188 m := mod[i].(*genrule.Module)
2189 m.Extra.(*GenruleExtraProperties).InRecovery = true
2190 }
2191 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002192 }
2193 }
2194
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002195 m, ok := mctx.Module().(*Module)
2196 if !ok {
2197 return
2198 }
2199
2200 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002201 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002202 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002203
2204 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002205 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002206 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002207 return
2208 }
Logan Chienf3511742017-10-31 18:04:35 +08002209
2210 if vndkdep := m.vndkdep; vndkdep != nil {
2211 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002212 if productSpecific {
2213 mctx.PropertyErrorf("product_specific",
2214 "product_specific must not be true when `vndk: {enabled: true}`")
2215 return
2216 }
Logan Chienf3511742017-10-31 18:04:35 +08002217 if vendorSpecific {
2218 if !vndkdep.isVndkExt() {
2219 mctx.PropertyErrorf("vndk",
2220 "must set `extends: \"...\"` to vndk extension")
2221 return
2222 }
2223 } else {
2224 if vndkdep.isVndkExt() {
2225 mctx.PropertyErrorf("vndk",
2226 "must set `vendor: true` to set `extends: %q`",
2227 m.getVndkExtendsModuleName())
2228 return
2229 }
2230 if m.VendorProperties.Vendor_available == nil {
2231 mctx.PropertyErrorf("vndk",
2232 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2233 return
2234 }
2235 }
2236 } else {
2237 if vndkdep.isVndkSp() {
2238 mctx.PropertyErrorf("vndk",
2239 "must set `enabled: true` to set `support_system_process: true`")
2240 return
2241 }
2242 if vndkdep.isVndkExt() {
2243 mctx.PropertyErrorf("vndk",
2244 "must set `enabled: true` to set `extends: %q`",
2245 m.getVndkExtendsModuleName())
2246 return
2247 }
Justin Yun8effde42017-06-23 19:24:43 +09002248 }
2249 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002250
Jiyong Parkf9332f12018-02-01 00:54:12 +09002251 var coreVariantNeeded bool = false
2252 var vendorVariantNeeded bool = false
2253 var recoveryVariantNeeded bool = false
2254
Justin Yun71549282017-11-17 12:10:28 +09002255 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002256 // If the device isn't compiling against the VNDK, we always
2257 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002258 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002259 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2260 // LL-NDK stubs only exist in the vendor variant, since the
2261 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002262 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002263 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2264 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002265 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002266 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002267 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2268 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002269 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002270 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002271 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002272 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002273 coreVariantNeeded = true
2274 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002275 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002276 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002277 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002278 } else {
2279 // This is either in /system (or similar: /data), or is a
2280 // modules built with the NDK. Modules built with the NDK
2281 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002282 coreVariantNeeded = true
2283 }
2284
2285 if Bool(m.Properties.Recovery_available) {
2286 recoveryVariantNeeded = true
2287 }
2288
2289 if m.ModuleBase.InstallInRecovery() {
2290 recoveryVariantNeeded = true
2291 coreVariantNeeded = false
2292 }
2293
Jiyong Park413cc742018-06-19 01:46:06 +09002294 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002295 primaryArch := mctx.Config().DevicePrimaryArchType()
2296 moduleArch := m.Target().Arch.ArchType
2297 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002298 recoveryVariantNeeded = false
2299 }
2300 }
2301
Jiyong Parkf9332f12018-02-01 00:54:12 +09002302 var variants []string
2303 if coreVariantNeeded {
2304 variants = append(variants, coreMode)
2305 }
2306 if vendorVariantNeeded {
2307 variants = append(variants, vendorMode)
2308 }
2309 if recoveryVariantNeeded {
2310 variants = append(variants, recoveryMode)
2311 }
2312 mod := mctx.CreateVariations(variants...)
2313 for i, v := range variants {
2314 if v == vendorMode {
2315 m := mod[i].(*Module)
2316 m.Properties.UseVndk = true
2317 squashVendorSrcs(m)
2318 } else if v == recoveryMode {
2319 m := mod[i].(*Module)
2320 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002321 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002322 squashRecoverySrcs(m)
2323 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002324 }
2325}
2326
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002327func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002328 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002329 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2330 }
Colin Cross6510f912017-11-29 00:27:14 -08002331 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002332}
2333
Colin Cross06a931b2015-10-28 17:23:31 -07002334var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002335var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002336var BoolPtr = proptools.BoolPtr
2337var String = proptools.String
2338var StringPtr = proptools.StringPtr