blob: a513a07e0db682af5d8988d2aeea993ca3f5add1 [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 Cross6b753602018-06-21 13:03:07 -070068 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
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"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700371)
372
Colin Crossca860ac2016-01-04 14:34:37 -0800373// Module contains the properties and members used by all C/C++ module types, and implements
374// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
375// to construct the output file. Behavior can be customized with a Customizer interface
376type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700377 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700378 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900379 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700380
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700381 Properties BaseProperties
382 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700383
Colin Crossca860ac2016-01-04 14:34:37 -0800384 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700385 hod android.HostOrDeviceSupported
386 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700387
Colin Crossca860ac2016-01-04 14:34:37 -0800388 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700389 features []feature
390 compiler compiler
391 linker linker
392 installer installer
393 stl *stl
394 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800395 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800396 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900397 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700398 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700399 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800400 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800401
402 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700403
Colin Cross635c3b02016-05-18 15:37:25 -0700404 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800405
Colin Crossb98c8b02016-07-29 13:44:28 -0700406 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700407
408 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800409
410 // Flags used to compile this module
411 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700412
413 // 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 -0800414 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700415 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800416 depsInLinkOrder android.Paths
417
418 // only non-nil when this is a shared library that reuses the objects of a static library
419 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900420
421 makeLinkType string
Colin Crossc472d572015-03-17 15:06:21 -0700422}
423
Jiyong Parkc20eee32018-09-05 22:36:17 +0900424func (c *Module) OutputFile() android.OptionalPath {
425 return c.outputFile
426}
427
Jiyong Park719b4462019-01-13 00:39:51 +0900428func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900429 if c.linker != nil {
430 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900431 }
432 return nil
433}
434
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900435func (c *Module) RelativeInstallPath() string {
436 if c.installer != nil {
437 return c.installer.relativeInstallPath()
438 }
439 return ""
440}
441
Colin Cross36242852017-06-23 15:06:31 -0700442func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700443 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800444 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700445 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800446 }
447 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700448 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800449 }
450 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700451 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800452 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700453 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700454 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700455 }
Colin Cross16b23492016-01-06 14:41:07 -0800456 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700457 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800458 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800459 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700460 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800461 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800462 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700463 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800464 }
Justin Yun8effde42017-06-23 19:24:43 +0900465 if c.vndkdep != nil {
466 c.AddProperties(c.vndkdep.props()...)
467 }
Stephen Craneba090d12017-05-09 15:44:35 -0700468 if c.lto != nil {
469 c.AddProperties(c.lto.props()...)
470 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700471 if c.pgo != nil {
472 c.AddProperties(c.pgo.props()...)
473 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800474 if c.xom != nil {
475 c.AddProperties(c.xom.props()...)
476 }
Colin Crossca860ac2016-01-04 14:34:37 -0800477 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700478 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800479 }
Colin Crossc472d572015-03-17 15:06:21 -0700480
Colin Crossa9d8bee2018-10-02 13:59:46 -0700481 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
482 switch class {
483 case android.Device:
484 return ctx.Config().DevicePrefer32BitExecutables()
485 case android.HostCross:
486 // Windows builds always prefer 32-bit
487 return true
488 default:
489 return false
490 }
491 })
Colin Cross36242852017-06-23 15:06:31 -0700492 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700493
Colin Cross1f44a3a2017-07-07 14:33:33 -0700494 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700495
Jiyong Park9d452992018-10-03 00:38:19 +0900496 android.InitApexModule(c)
497
Colin Cross36242852017-06-23 15:06:31 -0700498 return c
Colin Crossc472d572015-03-17 15:06:21 -0700499}
500
Colin Crossb916a382016-07-29 17:28:03 -0700501// Returns true for dependency roots (binaries)
502// TODO(ccross): also handle dlopenable libraries
503func (c *Module) isDependencyRoot() bool {
504 if root, ok := c.linker.(interface {
505 isDependencyRoot() bool
506 }); ok {
507 return root.isDependencyRoot()
508 }
509 return false
510}
511
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700512func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700513 return c.Properties.UseVndk
514}
515
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800516func (c *Module) isCoverageVariant() bool {
517 return c.coverage.Properties.IsCoverageVariant
518}
519
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800520func (c *Module) isNdk() bool {
521 return inList(c.Name(), ndkMigratedLibs)
522}
523
Inseob Kim9516ee92019-05-09 10:56:13 +0900524func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800525 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900526 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800527}
528
Inseob Kim9516ee92019-05-09 10:56:13 +0900529func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800530 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900531 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800532}
533
Inseob Kim9516ee92019-05-09 10:56:13 +0900534func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800535 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900536 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800537}
538
Justin Yun8effde42017-06-23 19:24:43 +0900539func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800540 if vndkdep := c.vndkdep; vndkdep != nil {
541 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900542 }
543 return false
544}
545
Jooyung Han76106d92019-05-20 18:49:10 +0900546func (c *Module) vndkVersion() string {
547 if vndkdep := c.vndkdep; vndkdep != nil {
548 return vndkdep.Properties.Vndk.Version
549 }
550 return ""
551}
552
Yi Kong7e53c572018-02-14 18:16:12 +0800553func (c *Module) isPgoCompile() bool {
554 if pgo := c.pgo; pgo != nil {
555 return pgo.Properties.PgoCompile
556 }
557 return false
558}
559
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800560func (c *Module) isNDKStubLibrary() bool {
561 if _, ok := c.compiler.(*stubDecorator); ok {
562 return true
563 }
564 return false
565}
566
Logan Chienf3511742017-10-31 18:04:35 +0800567func (c *Module) isVndkSp() bool {
568 if vndkdep := c.vndkdep; vndkdep != nil {
569 return vndkdep.isVndkSp()
570 }
571 return false
572}
573
574func (c *Module) isVndkExt() bool {
575 if vndkdep := c.vndkdep; vndkdep != nil {
576 return vndkdep.isVndkExt()
577 }
578 return false
579}
580
Vic Yangefd249e2018-11-12 20:19:56 -0800581func (c *Module) mustUseVendorVariant() bool {
582 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
583}
584
Logan Chienf3511742017-10-31 18:04:35 +0800585func (c *Module) getVndkExtendsModuleName() string {
586 if vndkdep := c.vndkdep; vndkdep != nil {
587 return vndkdep.getVndkExtendsModuleName()
588 }
589 return ""
590}
591
Jiyong Park82e2bf32017-08-16 14:05:54 +0900592// Returns true only when this module is configured to have core and vendor
593// variants.
594func (c *Module) hasVendorVariant() bool {
595 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
596}
597
Jiyong Parkf9332f12018-02-01 00:54:12 +0900598func (c *Module) inRecovery() bool {
599 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
600}
601
602func (c *Module) onlyInRecovery() bool {
603 return c.ModuleBase.InstallInRecovery()
604}
605
Jiyong Park25fc6a92018-11-18 18:02:45 +0900606func (c *Module) IsStubs() bool {
607 if library, ok := c.linker.(*libraryDecorator); ok {
608 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900609 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
610 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900611 }
612 return false
613}
614
615func (c *Module) HasStubsVariants() bool {
616 if library, ok := c.linker.(*libraryDecorator); ok {
617 return len(library.Properties.Stubs.Versions) > 0
618 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700619 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
620 return len(library.Properties.Stubs.Versions) > 0
621 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900622 return false
623}
624
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900625func (c *Module) bootstrap() bool {
626 return Bool(c.Properties.Bootstrap)
627}
628
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700629func (c *Module) nativeCoverage() bool {
630 return c.linker != nil && c.linker.nativeCoverage()
631}
632
Jiyong Parkf1194352019-02-25 11:05:47 +0900633func isBionic(name string) bool {
634 switch name {
635 case "libc", "libm", "libdl", "linker":
636 return true
637 }
638 return false
639}
640
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700641func installToBootstrap(name string, config android.Config) bool {
642 if name == "libclang_rt.hwasan-aarch64-android" {
643 return inList("hwaddress", config.SanitizeDevice())
644 }
645 return isBionic(name)
646}
647
Colin Crossca860ac2016-01-04 14:34:37 -0800648type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700649 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800650 moduleContextImpl
651}
652
Colin Cross37047f12016-12-13 17:06:13 -0800653type depsContext struct {
654 android.BottomUpMutatorContext
655 moduleContextImpl
656}
657
Colin Crossca860ac2016-01-04 14:34:37 -0800658type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700659 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800660 moduleContextImpl
661}
662
Jiyong Park2db76922017-11-08 16:03:48 +0900663func (ctx *moduleContext) SocSpecific() bool {
664 return ctx.ModuleContext.SocSpecific() ||
665 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700666}
667
Colin Crossca860ac2016-01-04 14:34:37 -0800668type moduleContextImpl struct {
669 mod *Module
670 ctx BaseModuleContext
671}
672
Colin Crossb98c8b02016-07-29 13:44:28 -0700673func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800674 return ctx.mod.toolchain(ctx.ctx)
675}
676
677func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000678 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800679}
680
681func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900682 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800683}
684
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700685func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800686 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800687 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700688 }
689 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800690}
691
692func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700693 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700694 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900695 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700696 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900697 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
698 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
699 return "current"
700 }
701 return platform_vndk_ver
702 }
703 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800704 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900705 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700706 }
707 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800708}
709
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700710func (ctx *moduleContextImpl) useVndk() bool {
711 return ctx.mod.useVndk()
712}
Justin Yun8effde42017-06-23 19:24:43 +0900713
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800714func (ctx *moduleContextImpl) isNdk() bool {
715 return ctx.mod.isNdk()
716}
717
Inseob Kim9516ee92019-05-09 10:56:13 +0900718func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
719 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800720}
721
Inseob Kim9516ee92019-05-09 10:56:13 +0900722func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
723 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800724}
725
Inseob Kim9516ee92019-05-09 10:56:13 +0900726func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
727 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800728}
729
Logan Chienf3511742017-10-31 18:04:35 +0800730func (ctx *moduleContextImpl) isVndk() bool {
731 return ctx.mod.isVndk()
732}
733
Yi Kong7e53c572018-02-14 18:16:12 +0800734func (ctx *moduleContextImpl) isPgoCompile() bool {
735 return ctx.mod.isPgoCompile()
736}
737
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800738func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
739 return ctx.mod.isNDKStubLibrary()
740}
741
Justin Yun8effde42017-06-23 19:24:43 +0900742func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800743 return ctx.mod.isVndkSp()
744}
745
746func (ctx *moduleContextImpl) isVndkExt() bool {
747 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900748}
749
Vic Yangefd249e2018-11-12 20:19:56 -0800750func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
751 return ctx.mod.mustUseVendorVariant()
752}
753
Jiyong Parkf9332f12018-02-01 00:54:12 +0900754func (ctx *moduleContextImpl) inRecovery() bool {
755 return ctx.mod.inRecovery()
756}
757
Logan Chien2f2b8902018-07-10 15:01:19 +0800758// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900759func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800760 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
761 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800762 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800763
764 if ctx.ctx.Fuchsia() {
765 return false
766 }
767
Logan Chien2f2b8902018-07-10 15:01:19 +0800768 if sanitize := ctx.mod.sanitize; sanitize != nil {
769 if !sanitize.isVariantOnProductionDevice() {
770 return false
771 }
772 }
773 if !ctx.ctx.Device() {
774 // Host modules do not need ABI dumps.
775 return false
776 }
Logan Chienfa478c02018-12-28 16:25:39 +0800777 if !ctx.mod.IsForPlatform() {
778 // APEX variants do not need ABI dumps.
779 return false
780 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800781 if ctx.isStubs() {
782 // Stubs do not need ABI dumps.
783 return false
784 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800785 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800786 return true
787 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900788 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800789 return true
790 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900791 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800792 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
793 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800794 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800795 }
796 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800797}
798
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700799func (ctx *moduleContextImpl) selectedStl() string {
800 if stl := ctx.mod.stl; stl != nil {
801 return stl.Properties.SelectedStl
802 }
803 return ""
804}
805
Ivan Lozanobd721262018-11-27 14:33:03 -0800806func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
807 return ctx.mod.linker.useClangLld(actx)
808}
809
Colin Crossce75d2c2016-10-06 16:12:58 -0700810func (ctx *moduleContextImpl) baseModuleName() string {
811 return ctx.mod.ModuleBase.BaseModuleName()
812}
813
Logan Chienf3511742017-10-31 18:04:35 +0800814func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
815 return ctx.mod.getVndkExtendsModuleName()
816}
817
Jiyong Park58e364a2019-01-19 19:24:06 +0900818func (ctx *moduleContextImpl) apexName() string {
819 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900820}
821
Jiyong Parkb0788572018-12-20 22:10:17 +0900822func (ctx *moduleContextImpl) hasStubsVariants() bool {
823 return ctx.mod.HasStubsVariants()
824}
825
826func (ctx *moduleContextImpl) isStubs() bool {
827 return ctx.mod.IsStubs()
828}
829
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900830func (ctx *moduleContextImpl) bootstrap() bool {
831 return ctx.mod.bootstrap()
832}
833
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700834func (ctx *moduleContextImpl) nativeCoverage() bool {
835 return ctx.mod.nativeCoverage()
836}
837
Colin Cross635c3b02016-05-18 15:37:25 -0700838func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800839 return &Module{
840 hod: hod,
841 multilib: multilib,
842 }
843}
844
Colin Cross635c3b02016-05-18 15:37:25 -0700845func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800846 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700847 module.features = []feature{
848 &tidyFeature{},
849 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700850 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800851 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800852 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800853 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900854 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700855 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700856 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800857 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800858 return module
859}
860
Colin Crossce75d2c2016-10-06 16:12:58 -0700861func (c *Module) Prebuilt() *android.Prebuilt {
862 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
863 return p.prebuilt()
864 }
865 return nil
866}
867
868func (c *Module) Name() string {
869 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700870 if p, ok := c.linker.(interface {
871 Name(string) string
872 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700873 name = p.Name(name)
874 }
875 return name
876}
877
Alex Light3d673592019-01-18 14:37:31 -0800878func (c *Module) Symlinks() []string {
879 if p, ok := c.installer.(interface {
880 symlinkList() []string
881 }); ok {
882 return p.symlinkList()
883 }
884 return nil
885}
886
Jeff Gaston294356f2017-09-27 17:05:30 -0700887// orderDeps reorders dependencies into a list such that if module A depends on B, then
888// A will precede B in the resultant list.
889// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800890// Note that directSharedDeps should be the analogous static library for each shared lib dep
891func 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 -0700892 // If A depends on B, then
893 // Every list containing A will also contain B later in the list
894 // So, after concatenating all lists, the final instance of B will have come from the same
895 // original list as the final instance of A
896 // So, the final instance of B will be later in the concatenation than the final A
897 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
898 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800899 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700900 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800901 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
902 }
903 for _, dep := range directSharedDeps {
904 orderedAllDeps = append(orderedAllDeps, dep)
905 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700906 }
907
Colin Crossb6715442017-10-24 11:13:31 -0700908 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700909
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800910 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700911 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800912 // resultant list to only what the caller has chosen to include in directStaticDeps
913 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700914
915 return orderedAllDeps, orderedDeclaredDeps
916}
917
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800918func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
919 // convert Module to Path
920 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
921 staticDepFiles := []android.Path{}
922 for _, dep := range staticDeps {
923 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
924 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700925 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800926 sharedDepFiles := []android.Path{}
927 for _, sharedDep := range sharedDeps {
928 staticAnalogue := sharedDep.staticVariant
929 if staticAnalogue != nil {
930 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
931 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
932 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700933 }
934
935 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800936 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700937
938 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700939}
940
Colin Cross635c3b02016-05-18 15:37:25 -0700941func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jooyung Han38002912019-05-16 04:01:54 +0900942 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900943
Colin Crossca860ac2016-01-04 14:34:37 -0800944 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700945 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800946 moduleContextImpl: moduleContextImpl{
947 mod: c,
948 },
949 }
950 ctx.ctx = ctx
951
Colin Crossf18e1102017-11-16 14:33:08 -0800952 deps := c.depsToPaths(ctx)
953 if ctx.Failed() {
954 return
955 }
956
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700957 if c.Properties.Clang != nil && *c.Properties.Clang == false {
958 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
959 }
960
Colin Crossca860ac2016-01-04 14:34:37 -0800961 flags := Flags{
962 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800963 }
Colin Crossca860ac2016-01-04 14:34:37 -0800964 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800965 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800966 }
967 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700968 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800969 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700970 if c.stl != nil {
971 flags = c.stl.flags(ctx, flags)
972 }
Colin Cross16b23492016-01-06 14:41:07 -0800973 if c.sanitize != nil {
974 flags = c.sanitize.flags(ctx, flags)
975 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800976 if c.coverage != nil {
977 flags = c.coverage.flags(ctx, flags)
978 }
Stephen Craneba090d12017-05-09 15:44:35 -0700979 if c.lto != nil {
980 flags = c.lto.flags(ctx, flags)
981 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700982 if c.pgo != nil {
983 flags = c.pgo.flags(ctx, flags)
984 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800985 if c.xom != nil {
986 flags = c.xom.flags(ctx, flags)
987 }
Colin Crossca860ac2016-01-04 14:34:37 -0800988 for _, feature := range c.features {
989 flags = feature.flags(ctx, flags)
990 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800991 if ctx.Failed() {
992 return
993 }
994
Colin Crossb98c8b02016-07-29 13:44:28 -0700995 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
996 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
997 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800998
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800999 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001000
1001 for _, dir := range deps.IncludeDirs {
1002 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1003 }
1004 for _, dir := range deps.SystemIncludeDirs {
1005 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1006 }
1007
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001008 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001009 // We need access to all the flags seen by a source file.
1010 if c.sabi != nil {
1011 flags = c.sabi.flags(ctx, flags)
1012 }
Colin Crossca860ac2016-01-04 14:34:37 -08001013 // Optimization to reduce size of build.ninja
1014 // Replace the long list of flags for each file with a module-local variable
1015 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1016 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1017 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1018 flags.CFlags = []string{"$cflags"}
1019 flags.CppFlags = []string{"$cppflags"}
1020 flags.AsFlags = []string{"$asflags"}
1021
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001022 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001023 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001024 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001025 if ctx.Failed() {
1026 return
1027 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001028 }
1029
Colin Crossca860ac2016-01-04 14:34:37 -08001030 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001031 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001032 if ctx.Failed() {
1033 return
1034 }
Colin Cross635c3b02016-05-18 15:37:25 -07001035 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001036
1037 // If a lib is directly included in any of the APEXes, unhide the stubs
1038 // variant having the latest version gets visible to make. In addition,
1039 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1040 // force anything in the make world to link against the stubs library.
1041 // (unless it is explicitly referenced via .bootstrap suffix or the
1042 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001043 if c.HasStubsVariants() &&
1044 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001045 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1046 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001047 c.Properties.HideFromMake = false // unhide
1048 // Note: this is still non-installable
1049 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001050 }
Colin Cross5049f022015-03-18 13:28:46 -07001051
Inseob Kim1f086e22019-05-09 13:29:15 +09001052 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001053 c.installer.install(ctx, c.outputFile.Path())
1054 if ctx.Failed() {
1055 return
Colin Crossca860ac2016-01-04 14:34:37 -08001056 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001057 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001058}
1059
Colin Cross0ea8ba82019-06-06 14:33:29 -07001060func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001061 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001062 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001063 }
Colin Crossca860ac2016-01-04 14:34:37 -08001064 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001065}
1066
Colin Crossca860ac2016-01-04 14:34:37 -08001067func (c *Module) begin(ctx BaseModuleContext) {
1068 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001069 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001070 }
Colin Crossca860ac2016-01-04 14:34:37 -08001071 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001072 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001073 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001074 if c.stl != nil {
1075 c.stl.begin(ctx)
1076 }
Colin Cross16b23492016-01-06 14:41:07 -08001077 if c.sanitize != nil {
1078 c.sanitize.begin(ctx)
1079 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001080 if c.coverage != nil {
1081 c.coverage.begin(ctx)
1082 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001083 if c.sabi != nil {
1084 c.sabi.begin(ctx)
1085 }
Justin Yun8effde42017-06-23 19:24:43 +09001086 if c.vndkdep != nil {
1087 c.vndkdep.begin(ctx)
1088 }
Stephen Craneba090d12017-05-09 15:44:35 -07001089 if c.lto != nil {
1090 c.lto.begin(ctx)
1091 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001092 if c.pgo != nil {
1093 c.pgo.begin(ctx)
1094 }
Colin Crossca860ac2016-01-04 14:34:37 -08001095 for _, feature := range c.features {
1096 feature.begin(ctx)
1097 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001098 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001099 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001100 if err != nil {
1101 ctx.PropertyErrorf("sdk_version", err.Error())
1102 }
Nan Zhang0007d812017-11-07 10:57:05 -08001103 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001104 }
Colin Crossca860ac2016-01-04 14:34:37 -08001105}
1106
Colin Cross37047f12016-12-13 17:06:13 -08001107func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001108 deps := Deps{}
1109
1110 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001111 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001112 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001113 // Add the PGO dependency (the clang_rt.profile runtime library), which
1114 // sometimes depends on symbols from libgcc, before libgcc gets added
1115 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001116 if c.pgo != nil {
1117 deps = c.pgo.deps(ctx, deps)
1118 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001119 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001120 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001121 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001122 if c.stl != nil {
1123 deps = c.stl.deps(ctx, deps)
1124 }
Colin Cross16b23492016-01-06 14:41:07 -08001125 if c.sanitize != nil {
1126 deps = c.sanitize.deps(ctx, deps)
1127 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001128 if c.coverage != nil {
1129 deps = c.coverage.deps(ctx, deps)
1130 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001131 if c.sabi != nil {
1132 deps = c.sabi.deps(ctx, deps)
1133 }
Justin Yun8effde42017-06-23 19:24:43 +09001134 if c.vndkdep != nil {
1135 deps = c.vndkdep.deps(ctx, deps)
1136 }
Stephen Craneba090d12017-05-09 15:44:35 -07001137 if c.lto != nil {
1138 deps = c.lto.deps(ctx, deps)
1139 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001140 for _, feature := range c.features {
1141 deps = feature.deps(ctx, deps)
1142 }
1143
Colin Crossb6715442017-10-24 11:13:31 -07001144 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1145 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1146 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1147 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1148 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1149 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001150 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001151
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001152 for _, lib := range deps.ReexportSharedLibHeaders {
1153 if !inList(lib, deps.SharedLibs) {
1154 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1155 }
1156 }
1157
1158 for _, lib := range deps.ReexportStaticLibHeaders {
1159 if !inList(lib, deps.StaticLibs) {
1160 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1161 }
1162 }
1163
Colin Cross5950f382016-12-13 12:50:57 -08001164 for _, lib := range deps.ReexportHeaderLibHeaders {
1165 if !inList(lib, deps.HeaderLibs) {
1166 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1167 }
1168 }
1169
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001170 for _, gen := range deps.ReexportGeneratedHeaders {
1171 if !inList(gen, deps.GeneratedHeaders) {
1172 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1173 }
1174 }
1175
Colin Crossc99deeb2016-04-11 15:06:20 -07001176 return deps
1177}
1178
Dan Albert7e9d2952016-08-04 13:02:36 -07001179func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001180 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001181 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001182 moduleContextImpl: moduleContextImpl{
1183 mod: c,
1184 },
1185 }
1186 ctx.ctx = ctx
1187
Colin Crossca860ac2016-01-04 14:34:37 -08001188 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001189}
1190
Jiyong Park7ed9de32018-10-15 22:25:07 +09001191// Split name#version into name and version
1192func stubsLibNameAndVersion(name string) (string, string) {
1193 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1194 version := name[sharp+1:]
1195 libname := name[:sharp]
1196 return libname, version
1197 }
1198 return name, ""
1199}
1200
Colin Cross1e676be2016-10-12 14:38:15 -07001201func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001202 ctx := &depsContext{
1203 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001204 moduleContextImpl: moduleContextImpl{
1205 mod: c,
1206 },
1207 }
1208 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001209
Colin Crossc99deeb2016-04-11 15:06:20 -07001210 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001211
Dan Albert914449f2016-06-17 16:45:24 -07001212 variantNdkLibs := []string{}
1213 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001214 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001215 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001216
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1218 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001219 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001220 // 1. Name of an NDK library that refers to a prebuilt module.
1221 // For each of these, it adds the name of the prebuilt module (which will be in
1222 // prebuilts/ndk) to the list of nonvariant libs.
1223 // 2. Name of an NDK library that refers to an ndk_library module.
1224 // For each of these, it adds the name of the ndk_library module to the list of
1225 // variant libs.
1226 // 3. Anything else (so anything that isn't an NDK library).
1227 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001228 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001229 // The caller can then know to add the variantLibs dependencies differently from the
1230 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001231
1232 llndkLibraries := llndkLibraries(actx.Config())
1233 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001234 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1235 variantLibs = []string{}
1236 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001237 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001238 // strip #version suffix out
1239 name, _ := stubsLibNameAndVersion(entry)
1240 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1241 if !inList(name, ndkMigratedLibs) {
1242 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001243 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001244 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001245 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001246 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001247 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001248 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001249 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001250 if actx.OtherModuleExists(vendorPublicLib) {
1251 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1252 } else {
1253 // This can happen if vendor_public_library module is defined in a
1254 // namespace that isn't visible to the current module. In that case,
1255 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001256 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001257 }
Dan Albert914449f2016-06-17 16:45:24 -07001258 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001259 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001260 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001261 }
1262 }
Dan Albert914449f2016-06-17 16:45:24 -07001263 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001264 }
1265
Dan Albert914449f2016-06-17 16:45:24 -07001266 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1267 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001268 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001269 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001270
Jiyong Park7e636d02019-01-28 16:16:54 +09001271 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001272 if c.linker != nil {
1273 if library, ok := c.linker.(*libraryDecorator); ok {
1274 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001275 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001276 }
1277 }
1278 }
1279
Colin Cross32ec36c2016-12-15 07:39:51 -08001280 for _, lib := range deps.HeaderLibs {
1281 depTag := headerDepTag
1282 if inList(lib, deps.ReexportHeaderLibHeaders) {
1283 depTag = headerExportDepTag
1284 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001285 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001286 actx.AddFarVariationDependencies([]blueprint.Variation{
1287 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001288 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001289 }, depTag, lib)
1290 } else {
1291 actx.AddVariationDependencies(nil, depTag, lib)
1292 }
1293 }
1294
1295 if buildStubs {
1296 // Stubs lib does not have dependency to other static/shared libraries.
1297 // Don't proceed.
1298 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001299 }
Colin Cross5950f382016-12-13 12:50:57 -08001300
Inseob Kimc0907f12019-02-08 21:00:45 +09001301 syspropImplLibraries := syspropImplLibraries(actx.Config())
1302
Jiyong Park5d1598f2019-02-25 22:14:17 +09001303 for _, lib := range deps.WholeStaticLibs {
1304 depTag := wholeStaticDepTag
1305 if impl, ok := syspropImplLibraries[lib]; ok {
1306 lib = impl
1307 }
1308 actx.AddVariationDependencies([]blueprint.Variation{
1309 {Mutator: "link", Variation: "static"},
1310 }, depTag, lib)
1311 }
1312
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001313 for _, lib := range deps.StaticLibs {
1314 depTag := staticDepTag
1315 if inList(lib, deps.ReexportStaticLibHeaders) {
1316 depTag = staticExportDepTag
1317 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001318
1319 if impl, ok := syspropImplLibraries[lib]; ok {
1320 lib = impl
1321 }
1322
Dan Willemsen59339a22018-07-22 21:18:45 -07001323 actx.AddVariationDependencies([]blueprint.Variation{
1324 {Mutator: "link", Variation: "static"},
1325 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001326 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001327
Dan Willemsen59339a22018-07-22 21:18:45 -07001328 actx.AddVariationDependencies([]blueprint.Variation{
1329 {Mutator: "link", Variation: "static"},
1330 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001331
Jiyong Park25fc6a92018-11-18 18:02:45 +09001332 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1333 var variations []blueprint.Variation
1334 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001335 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001336 if version != "" && versionVariantAvail {
1337 // Version is explicitly specified. i.e. libFoo#30
1338 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1339 depTag.explicitlyVersioned = true
1340 }
1341 actx.AddVariationDependencies(variations, depTag, name)
1342
1343 // If the version is not specified, add dependency to the latest stubs library.
1344 // The stubs library will be used when the depending module is built for APEX and
1345 // the dependent module is not in the same APEX.
1346 latestVersion := latestStubsVersionFor(actx.Config(), name)
1347 if version == "" && latestVersion != "" && versionVariantAvail {
1348 actx.AddVariationDependencies([]blueprint.Variation{
1349 {Mutator: "link", Variation: "shared"},
1350 {Mutator: "version", Variation: latestVersion},
1351 }, depTag, name)
1352 // Note that depTag.explicitlyVersioned is false in this case.
1353 }
1354 }
1355
Jiyong Park7ed9de32018-10-15 22:25:07 +09001356 // shared lib names without the #version suffix
1357 var sharedLibNames []string
1358
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001359 for _, lib := range deps.SharedLibs {
1360 depTag := sharedDepTag
1361 if inList(lib, deps.ReexportSharedLibHeaders) {
1362 depTag = sharedExportDepTag
1363 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001364
1365 if impl, ok := syspropImplLibraries[lib]; ok {
1366 lib = impl
1367 }
1368
1369 name, version := stubsLibNameAndVersion(lib)
1370 sharedLibNames = append(sharedLibNames, name)
1371
Jiyong Park25fc6a92018-11-18 18:02:45 +09001372 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001373 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001374
Jiyong Park7ed9de32018-10-15 22:25:07 +09001375 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001376 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001377 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1378 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1379 // linking against both the stubs lib and the non-stubs lib at the same time.
1380 continue
1381 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001382 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001383 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001384
Dan Willemsen59339a22018-07-22 21:18:45 -07001385 actx.AddVariationDependencies([]blueprint.Variation{
1386 {Mutator: "link", Variation: "shared"},
1387 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001388
Colin Cross68861832016-07-08 10:41:41 -07001389 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001390
1391 for _, gen := range deps.GeneratedHeaders {
1392 depTag := genHeaderDepTag
1393 if inList(gen, deps.ReexportGeneratedHeaders) {
1394 depTag = genHeaderExportDepTag
1395 }
1396 actx.AddDependency(c, depTag, gen)
1397 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001398
Colin Cross42d48b72018-08-29 14:10:52 -07001399 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001400
1401 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001402 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001403 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001404 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001405 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001406 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001407 if deps.LinkerFlagsFile != "" {
1408 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1409 }
1410 if deps.DynamicLinker != "" {
1411 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001412 }
Dan Albert914449f2016-06-17 16:45:24 -07001413
1414 version := ctx.sdkVersion()
1415 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001416 {Mutator: "ndk_api", Variation: version},
1417 {Mutator: "link", Variation: "shared"},
1418 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001419 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001420 {Mutator: "ndk_api", Variation: version},
1421 {Mutator: "link", Variation: "shared"},
1422 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001423
1424 if vndkdep := c.vndkdep; vndkdep != nil {
1425 if vndkdep.isVndkExt() {
1426 baseModuleMode := vendorMode
1427 if actx.DeviceConfig().VndkVersion() == "" {
1428 baseModuleMode = coreMode
1429 }
1430 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001431 {Mutator: "image", Variation: baseModuleMode},
1432 {Mutator: "link", Variation: "shared"},
1433 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001434 }
1435 }
Colin Cross6362e272015-10-29 15:25:03 -07001436}
Colin Cross21b9a242015-03-24 14:15:58 -07001437
Colin Crosse40b4ea2018-10-02 22:25:58 -07001438func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001439 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1440 c.beginMutator(ctx)
1441 }
1442}
1443
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001444// Whether a module can link to another module, taking into
1445// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001446func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001447 if from.Target().Os != android.Android {
1448 // Host code is not restricted
1449 return
1450 }
1451 if from.Properties.UseVndk {
1452 // Though vendor code is limited by the vendor mutator,
1453 // each vendor-available module needs to check
1454 // link-type for VNDK.
1455 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001456 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001457 }
1458 return
1459 }
Nan Zhang0007d812017-11-07 10:57:05 -08001460 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001461 // Platform code can link to anything
1462 return
1463 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001464 if from.inRecovery() {
1465 // Recovery code is not NDK
1466 return
1467 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001468 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1469 // These are always allowed
1470 return
1471 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001472 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1473 // These are allowed, but they don't set sdk_version
1474 return
1475 }
1476 if _, ok := to.linker.(*stubDecorator); ok {
1477 // These aren't real libraries, but are the stub shared libraries that are included in
1478 // the NDK.
1479 return
1480 }
Logan Chien834b9a62019-01-14 15:39:03 +08001481
1482 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1483 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1484 // to link to libc++ (non-NDK and without sdk_version).
1485 return
1486 }
1487
Nan Zhang0007d812017-11-07 10:57:05 -08001488 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001489 // NDK code linking to platform code is never okay.
1490 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1491 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001492 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001493 }
1494
1495 // At this point we know we have two NDK libraries, but we need to
1496 // check that we're not linking against anything built against a higher
1497 // API level, as it is only valid to link against older or equivalent
1498 // APIs.
1499
Inseob Kim01a28722018-04-11 09:48:45 +09001500 // Current can link against anything.
1501 if String(from.Properties.Sdk_version) != "current" {
1502 // Otherwise we need to check.
1503 if String(to.Properties.Sdk_version) == "current" {
1504 // Current can't be linked against by anything else.
1505 ctx.ModuleErrorf("links %q built against newer API version %q",
1506 ctx.OtherModuleName(to), "current")
1507 } else {
1508 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1509 if err != nil {
1510 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001511 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001512 String(from.Properties.Sdk_version))
1513 }
1514 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1515 if err != nil {
1516 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001517 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001518 String(to.Properties.Sdk_version))
1519 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001520
Inseob Kim01a28722018-04-11 09:48:45 +09001521 if toApi > fromApi {
1522 ctx.ModuleErrorf("links %q built against newer API version %q",
1523 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1524 }
1525 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001526 }
Dan Albert202fe492017-12-15 13:56:59 -08001527
1528 // Also check that the two STL choices are compatible.
1529 fromStl := from.stl.Properties.SelectedStl
1530 toStl := to.stl.Properties.SelectedStl
1531 if fromStl == "" || toStl == "" {
1532 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001533 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001534 // We can be permissive with the system "STL" since it is only the C++
1535 // ABI layer, but in the future we should make sure that everyone is
1536 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001537 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001538 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1539 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1540 to.stl.Properties.SelectedStl)
1541 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001542}
1543
Jiyong Park5fb8c102018-04-09 12:03:06 +09001544// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001545// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1546// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001547// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001548func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001549 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001550 check := func(child, parent android.Module) bool {
1551 to, ok := child.(*Module)
1552 if !ok {
1553 // follow thru cc.Defaults, etc.
1554 return true
1555 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001556
Jooyung Hana70f0672019-01-18 15:20:43 +09001557 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1558 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001559 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001560
1561 // if target lib has no vendor variant, keep checking dependency graph
1562 if !to.hasVendorVariant() {
1563 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001564 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001565
Inseob Kim9516ee92019-05-09 10:56:13 +09001566 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001567 return false
1568 }
1569
1570 var stringPath []string
1571 for _, m := range ctx.GetWalkPath() {
1572 stringPath = append(stringPath, m.Name())
1573 }
1574 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1575 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1576 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1577 return false
1578 }
1579 if module, ok := ctx.Module().(*Module); ok {
1580 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001581 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001582 ctx.WalkDeps(check)
1583 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001584 }
1585 }
1586}
1587
Colin Crossc99deeb2016-04-11 15:06:20 -07001588// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001589func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001590 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001591
Jeff Gaston294356f2017-09-27 17:05:30 -07001592 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001593 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001594
Inseob Kim9516ee92019-05-09 10:56:13 +09001595 llndkLibraries := llndkLibraries(ctx.Config())
1596 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1597
Inseob Kim69378442019-06-03 19:10:47 +09001598 reexportExporter := func(exporter exportedFlagsProducer) {
1599 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1600 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1601 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1602 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1603 }
1604
Colin Crossd11fcda2017-10-23 17:59:01 -07001605 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001606 depName := ctx.OtherModuleName(dep)
1607 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001608
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001609 ccDep, _ := dep.(*Module)
1610 if ccDep == nil {
1611 // handling for a few module types that aren't cc Module but that are also supported
1612 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001613 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001614 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001615 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1616 genRule.GeneratedSourceFiles()...)
1617 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001618 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001619 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001620 // Support exported headers from a generated_sources dependency
1621 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001622 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001623 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001624 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001625 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001626 dirs := genRule.GeneratedHeaderDirs().Strings()
1627 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001628 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001629 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1630 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001631 // 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 +09001632 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001633
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001634 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001635 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001636 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001637 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001638 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001639 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001640 files := genRule.GeneratedSourceFiles()
1641 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001642 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001643 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001644 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 -07001645 }
1646 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001647 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001648 }
Colin Crossca860ac2016-01-04 14:34:37 -08001649 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001650 return
1651 }
1652
Colin Crossfe17f6f2019-03-28 19:30:56 -07001653 if depTag == android.ProtoPluginDepTag {
1654 return
1655 }
1656
Colin Crossd11fcda2017-10-23 17:59:01 -07001657 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001658 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1659 return
1660 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001661 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001662 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001663 return
1664 }
1665
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001666 // re-exporting flags
1667 if depTag == reuseObjTag {
1668 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001669 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001670 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001671 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001672 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001673 return
1674 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001675 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001676
Jiyong Parke4bb9862019-02-01 00:31:10 +09001677 if depTag == staticVariantTag {
1678 if _, ok := ccDep.compiler.(libraryInterface); ok {
1679 c.staticVariant = ccDep
1680 return
1681 }
1682 }
1683
Jiyong Park25fc6a92018-11-18 18:02:45 +09001684 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1685 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1686 // won't be matched to sharedDepTag and lateSharedDepTag.
1687 explicitlyVersioned := false
1688 if t, ok := depTag.(dependencyTag); ok {
1689 explicitlyVersioned = t.explicitlyVersioned
1690 t.explicitlyVersioned = false
1691 depTag = t
1692 }
1693
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001694 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001695 depIsStatic := false
1696 switch depTag {
1697 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1698 depIsStatic = true
1699 }
1700 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001701 depIsStubs := dependentLibrary.buildStubs()
1702 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001703 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001704 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001705
1706 var useThisDep bool
1707 if depIsStubs && explicitlyVersioned {
1708 // Always respect dependency to the versioned stubs (i.e. libX#10)
1709 useThisDep = true
1710 } else if !depHasStubs {
1711 // Use non-stub variant if that is the only choice
1712 // (i.e. depending on a lib without stubs.version property)
1713 useThisDep = true
1714 } else if c.IsForPlatform() {
1715 // If not building for APEX, use stubs only when it is from
1716 // an APEX (and not from platform)
1717 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001718 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001719 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001720 // always link to non-stub variant
1721 useThisDep = !depIsStubs
1722 }
1723 } else {
1724 // If building for APEX, use stubs only when it is not from
1725 // the same APEX
1726 useThisDep = (depInSameApex != depIsStubs)
1727 }
1728
1729 if !useThisDep {
1730 return // stop processing this dep
1731 }
1732 }
1733
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001734 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001735 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1736 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1737 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1738 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001739
1740 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001741 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001742 // 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 -07001743 // Re-exported shared library headers must be included as well since they can help us with type information
1744 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001745 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1746 // scripts.
1747 c.sabi.Properties.ReexportedIncludes = append(
1748 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001749 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001750 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001751
Logan Chienf3511742017-10-31 18:04:35 +08001752 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001753 }
1754
Colin Cross26c34ed2016-09-30 17:10:16 -07001755 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001756 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001757
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001758 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001759 depFile := android.OptionalPath{}
1760
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001761 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001762 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001763 ptr = &depPaths.SharedLibs
1764 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001765 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001766 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001767 case earlySharedDepTag:
1768 ptr = &depPaths.EarlySharedLibs
1769 depPtr = &depPaths.EarlySharedLibsDeps
1770 depFile = ccDep.linker.(libraryInterface).toc()
1771 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001772 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001773 ptr = &depPaths.LateSharedLibs
1774 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001775 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001776 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001777 ptr = nil
1778 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001779 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001780 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001781 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001782 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001783 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001784 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001785 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001786 return
1787 }
1788
1789 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001790 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001791 for i := range missingDeps {
1792 missingDeps[i] += postfix
1793 }
1794 ctx.AddMissingDependencies(missingDeps)
1795 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001796 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001797 case headerDepTag:
1798 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001799 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001800 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001801 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001802 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001803 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001804 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001805 case dynamicLinkerDepTag:
1806 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001807 }
1808
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001809 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001810 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001811 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001812 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001813 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001814 return
1815 }
1816
1817 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001818 // in static libraries act as if they were whole static libraries. The same goes for
1819 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001820 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1821 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001822 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1823 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001824
Dan Willemsen581341d2017-02-09 16:16:31 -08001825 }
1826
Colin Cross26c34ed2016-09-30 17:10:16 -07001827 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001828 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001829 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001830 return
1831 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001832 *ptr = append(*ptr, linkFile.Path())
1833 }
1834
Colin Crossc99deeb2016-04-11 15:06:20 -07001835 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001836 dep := depFile
1837 if !dep.Valid() {
1838 dep = linkFile
1839 }
1840 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001841 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001842
Logan Chien43d34c32017-12-20 01:17:32 +08001843 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001844 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001845 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001846 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001847 isLLndk := inList(libName, *llndkLibraries)
1848 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001849 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001850
1851 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1852 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1853 // core module instead.
1854 return libName
1855 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001856 // The vendor module in Make will have been renamed to not conflict with the core
1857 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001858 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001859 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001860 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001861 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1862 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001863 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001864 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001866 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001867 }
Logan Chien43d34c32017-12-20 01:17:32 +08001868 }
1869
1870 // Export the shared libs to Make.
1871 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001872 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001873 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001874 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001875 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001876 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001877 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001878 c.Properties.ApexesProvidingSharedLibs = append(
1879 c.Properties.ApexesProvidingSharedLibs, an)
1880 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001881 }
1882 }
1883
Jiyong Park27b188b2017-07-18 13:23:39 +09001884 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001885 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001886 c.Properties.AndroidMkSharedLibs = append(
1887 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001888 case ndkStubDepTag, ndkLateStubDepTag:
1889 ndkStub := ccDep.linker.(*stubDecorator)
1890 c.Properties.AndroidMkSharedLibs = append(
1891 c.Properties.AndroidMkSharedLibs,
1892 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001893 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1894 c.Properties.AndroidMkStaticLibs = append(
1895 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001896 case runtimeDepTag:
1897 c.Properties.AndroidMkRuntimeLibs = append(
1898 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001899 case wholeStaticDepTag:
1900 c.Properties.AndroidMkWholeStaticLibs = append(
1901 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001902 }
Colin Crossca860ac2016-01-04 14:34:37 -08001903 })
1904
Jeff Gaston294356f2017-09-27 17:05:30 -07001905 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001906 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001907
Colin Crossdd84e052017-05-17 13:44:16 -07001908 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001909 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001910 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1911 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001912 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001913 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1914 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001915 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001916 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001917
1918 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001919 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001920 }
Colin Crossdd84e052017-05-17 13:44:16 -07001921
Colin Crossca860ac2016-01-04 14:34:37 -08001922 return depPaths
1923}
1924
1925func (c *Module) InstallInData() bool {
1926 if c.installer == nil {
1927 return false
1928 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001929 return c.installer.inData()
1930}
1931
1932func (c *Module) InstallInSanitizerDir() bool {
1933 if c.installer == nil {
1934 return false
1935 }
1936 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001937 return true
1938 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001939 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001940}
1941
Jiyong Parkf9332f12018-02-01 00:54:12 +09001942func (c *Module) InstallInRecovery() bool {
1943 return c.inRecovery()
1944}
1945
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001946func (c *Module) HostToolPath() android.OptionalPath {
1947 if c.installer == nil {
1948 return android.OptionalPath{}
1949 }
1950 return c.installer.hostToolPath()
1951}
1952
Nan Zhangd4e641b2017-07-12 12:55:28 -07001953func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1954 return c.outputFile
1955}
1956
Colin Cross41955e82019-05-29 14:40:35 -07001957func (c *Module) OutputFiles(tag string) (android.Paths, error) {
1958 switch tag {
1959 case "":
1960 if c.outputFile.Valid() {
1961 return android.Paths{c.outputFile.Path()}, nil
1962 }
1963 return android.Paths{}, nil
1964 default:
1965 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001966 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001967}
1968
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001969func (c *Module) static() bool {
1970 if static, ok := c.linker.(interface {
1971 static() bool
1972 }); ok {
1973 return static.static()
1974 }
1975 return false
1976}
1977
Jiyong Park379de2f2018-12-19 02:47:14 +09001978func (c *Module) staticBinary() bool {
1979 if static, ok := c.linker.(interface {
1980 staticBinary() bool
1981 }); ok {
1982 return static.staticBinary()
1983 }
1984 return false
1985}
1986
Jooyung Han38002912019-05-16 04:01:54 +09001987func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
1988 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07001989 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09001990 if lib, ok := c.linker.(*llndkStubDecorator); ok {
1991 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07001992 return "native:vndk"
1993 }
Jooyung Han38002912019-05-16 04:01:54 +09001994 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07001995 }
Jooyung Han38002912019-05-16 04:01:54 +09001996 if c.isVndk() && !c.isVndkExt() {
1997 if Bool(c.VendorProperties.Vendor_available) {
1998 return "native:vndk"
1999 }
2000 return "native:vndk_private"
2001 }
2002 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002003 } else if c.inRecovery() {
2004 return "native:recovery"
2005 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2006 return "native:ndk:none:none"
2007 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2008 //family, link := getNdkStlFamilyAndLinkType(c)
2009 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002010 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002011 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002012 } else {
2013 return "native:platform"
2014 }
2015}
2016
Jiyong Park9d452992018-10-03 00:38:19 +09002017// Overrides ApexModule.IsInstallabeToApex()
2018// Only shared libraries are installable to APEX.
2019func (c *Module) IsInstallableToApex() bool {
2020 if shared, ok := c.linker.(interface {
2021 shared() bool
2022 }); ok {
2023 return shared.shared()
2024 }
2025 return false
2026}
2027
Inseob Kim1f086e22019-05-09 13:29:15 +09002028func (c *Module) installable() bool {
2029 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2030}
2031
Jiyong Park3b1746a2019-01-29 11:15:04 +09002032func (c *Module) imageVariation() string {
2033 variation := "core"
2034 if c.useVndk() {
2035 variation = "vendor"
2036 } else if c.inRecovery() {
2037 variation = "recovery"
2038 }
2039 return variation
2040}
2041
bralee3f49f4d2019-03-04 06:58:15 +08002042func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002043 outputFiles, err := c.OutputFiles("")
2044 if err != nil {
2045 panic(err)
2046 }
2047 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002048}
2049
Logan Chien41eabe62019-04-10 13:33:58 +08002050func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2051 if c.linker != nil {
2052 if library, ok := c.linker.(*libraryDecorator); ok {
2053 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2054 }
2055 }
2056}
2057
Colin Cross2ba19d92015-05-07 15:44:20 -07002058//
Colin Crosscfad1192015-11-02 16:43:11 -08002059// Defaults
2060//
Colin Crossca860ac2016-01-04 14:34:37 -08002061type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002062 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002063 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002064 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002065}
2066
Patrice Arrudac249c712019-03-19 17:00:29 -07002067// cc_defaults provides a set of properties that can be inherited by other cc
2068// modules. A module can use the properties from a cc_defaults using
2069// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2070// merged (when possible) by prepending the default module's values to the
2071// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002072func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002073 return DefaultsFactory()
2074}
2075
Colin Cross36242852017-06-23 15:06:31 -07002076func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002077 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002078
Colin Cross36242852017-06-23 15:06:31 -07002079 module.AddProperties(props...)
2080 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002081 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002082 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002083 &BaseCompilerProperties{},
2084 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002085 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002086 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002087 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002088 &TestProperties{},
2089 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002090 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002091 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002092 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002093 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002094 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002095 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002096 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002097 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002098 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002099 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002100 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002101 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002102 )
Colin Crosscfad1192015-11-02 16:43:11 -08002103
Colin Cross1f44a3a2017-07-07 14:33:33 -07002104 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002105 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002106
2107 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002108}
2109
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002110const (
2111 // coreMode is the variant used for framework-private libraries, or
2112 // SDK libraries. (which framework-private libraries can use)
2113 coreMode = "core"
2114
2115 // vendorMode is the variant used for /vendor code that compiles
2116 // against the VNDK.
2117 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002118
2119 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002120)
2121
Jiyong Park6a43f042017-10-12 23:05:00 +09002122func squashVendorSrcs(m *Module) {
2123 if lib, ok := m.compiler.(*libraryDecorator); ok {
2124 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2125 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2126
2127 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2128 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2129 }
2130}
2131
Jiyong Parkf9332f12018-02-01 00:54:12 +09002132func squashRecoverySrcs(m *Module) {
2133 if lib, ok := m.compiler.(*libraryDecorator); ok {
2134 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2135 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2136
2137 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2138 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2139 }
2140}
2141
Jiyong Parkda6eb592018-12-19 17:12:36 +09002142func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002143 if mctx.Os() != android.Android {
2144 return
2145 }
2146
Jiyong Park7ed9de32018-10-15 22:25:07 +09002147 if g, ok := mctx.Module().(*genrule.Module); ok {
2148 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002149 var coreVariantNeeded bool = false
2150 var vendorVariantNeeded bool = false
2151 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002152 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002153 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002154 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002155 coreVariantNeeded = true
2156 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002157 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002158 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002159 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002160 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002161 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002162 if Bool(props.Recovery_available) {
2163 recoveryVariantNeeded = true
2164 }
2165
Jiyong Park413cc742018-06-19 01:46:06 +09002166 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002167 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002168 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002169 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002170 recoveryVariantNeeded = false
2171 }
2172 }
2173
Jiyong Park3f736c92018-05-24 13:36:56 +09002174 var variants []string
2175 if coreVariantNeeded {
2176 variants = append(variants, coreMode)
2177 }
2178 if vendorVariantNeeded {
2179 variants = append(variants, vendorMode)
2180 }
2181 if recoveryVariantNeeded {
2182 variants = append(variants, recoveryMode)
2183 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002184 mod := mctx.CreateVariations(variants...)
2185 for i, v := range variants {
2186 if v == recoveryMode {
2187 m := mod[i].(*genrule.Module)
2188 m.Extra.(*GenruleExtraProperties).InRecovery = true
2189 }
2190 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002191 }
2192 }
2193
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002194 m, ok := mctx.Module().(*Module)
2195 if !ok {
2196 return
2197 }
2198
2199 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002200 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002201 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002202
2203 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002204 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002205 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002206 return
2207 }
Logan Chienf3511742017-10-31 18:04:35 +08002208
2209 if vndkdep := m.vndkdep; vndkdep != nil {
2210 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002211 if productSpecific {
2212 mctx.PropertyErrorf("product_specific",
2213 "product_specific must not be true when `vndk: {enabled: true}`")
2214 return
2215 }
Logan Chienf3511742017-10-31 18:04:35 +08002216 if vendorSpecific {
2217 if !vndkdep.isVndkExt() {
2218 mctx.PropertyErrorf("vndk",
2219 "must set `extends: \"...\"` to vndk extension")
2220 return
2221 }
2222 } else {
2223 if vndkdep.isVndkExt() {
2224 mctx.PropertyErrorf("vndk",
2225 "must set `vendor: true` to set `extends: %q`",
2226 m.getVndkExtendsModuleName())
2227 return
2228 }
2229 if m.VendorProperties.Vendor_available == nil {
2230 mctx.PropertyErrorf("vndk",
2231 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2232 return
2233 }
2234 }
2235 } else {
2236 if vndkdep.isVndkSp() {
2237 mctx.PropertyErrorf("vndk",
2238 "must set `enabled: true` to set `support_system_process: true`")
2239 return
2240 }
2241 if vndkdep.isVndkExt() {
2242 mctx.PropertyErrorf("vndk",
2243 "must set `enabled: true` to set `extends: %q`",
2244 m.getVndkExtendsModuleName())
2245 return
2246 }
Justin Yun8effde42017-06-23 19:24:43 +09002247 }
2248 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002249
Jiyong Parkf9332f12018-02-01 00:54:12 +09002250 var coreVariantNeeded bool = false
2251 var vendorVariantNeeded bool = false
2252 var recoveryVariantNeeded bool = false
2253
Justin Yun71549282017-11-17 12:10:28 +09002254 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002255 // If the device isn't compiling against the VNDK, we always
2256 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002257 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002258 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2259 // LL-NDK stubs only exist in the vendor variant, since the
2260 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002261 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002262 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2263 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002264 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002265 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002266 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2267 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002268 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002269 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002270 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002271 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002272 coreVariantNeeded = true
2273 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002274 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002275 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002276 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002277 } else {
2278 // This is either in /system (or similar: /data), or is a
2279 // modules built with the NDK. Modules built with the NDK
2280 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002281 coreVariantNeeded = true
2282 }
2283
2284 if Bool(m.Properties.Recovery_available) {
2285 recoveryVariantNeeded = true
2286 }
2287
2288 if m.ModuleBase.InstallInRecovery() {
2289 recoveryVariantNeeded = true
2290 coreVariantNeeded = false
2291 }
2292
Jiyong Park413cc742018-06-19 01:46:06 +09002293 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002294 primaryArch := mctx.Config().DevicePrimaryArchType()
2295 moduleArch := m.Target().Arch.ArchType
2296 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002297 recoveryVariantNeeded = false
2298 }
2299 }
2300
Jiyong Parkf9332f12018-02-01 00:54:12 +09002301 var variants []string
2302 if coreVariantNeeded {
2303 variants = append(variants, coreMode)
2304 }
2305 if vendorVariantNeeded {
2306 variants = append(variants, vendorMode)
2307 }
2308 if recoveryVariantNeeded {
2309 variants = append(variants, recoveryMode)
2310 }
2311 mod := mctx.CreateVariations(variants...)
2312 for i, v := range variants {
2313 if v == vendorMode {
2314 m := mod[i].(*Module)
2315 m.Properties.UseVndk = true
2316 squashVendorSrcs(m)
2317 } else if v == recoveryMode {
2318 m := mod[i].(*Module)
2319 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002320 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002321 squashRecoverySrcs(m)
2322 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002323 }
2324}
2325
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002326func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002327 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002328 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2329 }
Colin Cross6510f912017-11-29 00:27:14 -08002330 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002331}
2332
Colin Cross06a931b2015-10-28 17:23:31 -07002333var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002334var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002335var BoolPtr = proptools.BoolPtr
2336var String = proptools.String
2337var StringPtr = proptools.StringPtr