blob: 70da92deb9eec2f625b684bcbdcc731572a29f02 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090041 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
43 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000059 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
60 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
61
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080062 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
63 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
64
Colin Cross1e676be2016-10-12 14:38:15 -070065 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
66 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080067
Colin Cross0b908332019-06-19 23:00:20 -070068 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090069 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080070
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080071 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080072 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070073
74 ctx.TopDown("lto_deps", ltoDepsMutator)
75 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090076
77 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070078 })
Colin Crossb98c8b02016-07-29 13:44:28 -070079
80 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070081}
82
Colin Crossca860ac2016-01-04 14:34:37 -080083type Deps struct {
84 SharedLibs, LateSharedLibs []string
85 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080086 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080087 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070088
Colin Cross5950f382016-12-13 12:50:57 -080089 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070090
Colin Cross81413472016-04-11 14:37:39 -070091 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070092
Dan Willemsenb40aab62016-04-20 14:21:14 -070093 GeneratedSources []string
94 GeneratedHeaders []string
95
Dan Willemsenb3454ab2016-09-28 17:34:58 -070096 ReexportGeneratedHeaders []string
97
Colin Cross97ba0732015-03-23 17:50:24 -070098 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070099
100 // Used for host bionic
101 LinkerFlagsFile string
102 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700103}
104
Colin Crossca860ac2016-01-04 14:34:37 -0800105type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900107 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700108 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900109 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700111 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700112
Colin Cross26c34ed2016-09-30 17:10:16 -0700113 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700114 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800115 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700116 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700117
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700119 GeneratedSources android.Paths
120 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700121
Inseob Kim69378442019-06-03 19:10:47 +0900122 Flags []string
123 IncludeDirs []string
124 SystemIncludeDirs []string
125 ReexportedDirs []string
126 ReexportedSystemDirs []string
127 ReexportedFlags []string
128 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700132
133 // Path to the file container flags to use with the linker
134 LinkerFlagsFile android.OptionalPath
135
136 // Path to the dynamic linker binary
137 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700138}
139
Colin Crossca860ac2016-01-04 14:34:37 -0800140type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700141 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
142 ArFlags []string // Flags that apply to ar
143 AsFlags []string // Flags that apply to assembly source files
144 CFlags []string // Flags that apply to C and C++ source files
145 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
146 ConlyFlags []string // Flags that apply to C source files
147 CppFlags []string // Flags that apply to C++ source files
148 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700149 aidlFlags []string // Flags that apply to aidl source files
150 rsFlags []string // Flags that apply to renderscript source files
151 LdFlags []string // Flags that apply to linker command lines
152 libFlags []string // Flags to add libraries early to the link order
153 TidyFlags []string // Flags that apply to clang-tidy
154 SAbiFlags []string // Flags that apply to header-abi-dumper
155 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700156
Colin Crossc3199482017-03-30 15:03:04 -0700157 // Global include flags that apply to C, C++, and assembly source files
158 // These must be after any module include flags, which will be in GlobalFlags.
159 SystemIncludeFlags []string
160
Colin Crossb98c8b02016-07-29 13:44:28 -0700161 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700162 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800163 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800164 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800165
166 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800167 DynamicLinker string
168
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700169 CFlagsDeps android.Paths // Files depended on by compiler flags
170 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800171
172 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800173
Colin Cross19878da2019-03-28 14:45:07 -0700174 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700175 protoC bool // Whether to use C instead of C++
176 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700177
178 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700179}
180
Colin Cross81413472016-04-11 14:37:39 -0700181type ObjectLinkerProperties struct {
182 // names of other cc_object modules to link into this module using partial linking
183 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700184
185 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800186 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700187}
188
Colin Crossca860ac2016-01-04 14:34:37 -0800189// Properties used to compile all C or C++ modules
190type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700191 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800192 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700193
194 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800195 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700196
Jiyong Parkde866cb2018-12-07 23:08:36 +0900197 AndroidMkSharedLibs []string `blueprint:"mutated"`
198 AndroidMkStaticLibs []string `blueprint:"mutated"`
199 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
200 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
201 HideFromMake bool `blueprint:"mutated"`
202 PreventInstall bool `blueprint:"mutated"`
203 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700204
205 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800206
207 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
208 // file
209 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900210
211 // Make this module available when building for recovery
212 Recovery_available *bool
213
214 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900215
216 // Allows this module to use non-APEX version of libraries. Useful
217 // for building binaries that are started before APEXes are activated.
218 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700219}
220
221type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900222 // whether this module should be allowed to be directly depended by other
223 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
224 // If set to true, two variants will be built separately, one like
225 // normal, and the other limited to the set of libraries and headers
226 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700227 //
228 // The vendor variant may be used with a different (newer) /system,
229 // so it shouldn't have any unversioned runtime dependencies, or
230 // make assumptions about the system that may not be true in the
231 // future.
232 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900233 // If set to false, this module becomes inaccessible from /vendor modules.
234 //
235 // Default value is true when vndk: {enabled: true} or vendor: true.
236 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700237 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
238 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900239
240 // whether this module is capable of being loaded with other instance
241 // (possibly an older version) of the same module in the same process.
242 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
243 // can be double loaded in a vendor process if the library is also a
244 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
245 // explicitly marked as `double_loadable: true` by the owner, or the dependency
246 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
247 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800248}
249
Colin Crossca860ac2016-01-04 14:34:37 -0800250type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800251 static() bool
252 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700253 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700254 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800255 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700256 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800257 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900258 isLlndk(config android.Config) bool
259 isLlndkPublic(config android.Config) bool
260 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900261 isVndk() bool
262 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800263 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900264 inRecovery() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900265 shouldCreateVndkSourceAbiDump(config android.Config) bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700266 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700267 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800268 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800269 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800270 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800271 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900272 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900273 hasStubsVariants() bool
274 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900275 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800276 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700277 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800278}
279
280type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700281 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800282 ModuleContextIntf
283}
284
285type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700286 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800287 ModuleContextIntf
288}
289
Colin Cross37047f12016-12-13 17:06:13 -0800290type DepsContext interface {
291 android.BottomUpMutatorContext
292 ModuleContextIntf
293}
294
Colin Crossca860ac2016-01-04 14:34:37 -0800295type feature interface {
296 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800297 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800298 flags(ctx ModuleContext, flags Flags) Flags
299 props() []interface{}
300}
301
302type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700303 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800304 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800305 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700306 compilerProps() []interface{}
307
Colin Cross76fada02016-07-27 10:31:13 -0700308 appendCflags([]string)
309 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700310 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800311}
312
313type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700314 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800315 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700316 linkerFlags(ctx ModuleContext, flags Flags) Flags
317 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800318 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700319
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700320 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700321 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900322 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700323
324 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800325}
326
327type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700328 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700329 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800330 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700331 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700332 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900333 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800334}
335
Colin Crossc99deeb2016-04-11 15:06:20 -0700336type dependencyTag struct {
337 blueprint.BaseDependencyTag
338 name string
339 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700340
341 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900342
343 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700344}
345
346var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700347 sharedDepTag = dependencyTag{name: "shared", library: true}
348 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900349 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700350 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
351 staticDepTag = dependencyTag{name: "static", library: true}
352 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
353 lateStaticDepTag = dependencyTag{name: "late static", library: true}
354 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800355 headerDepTag = dependencyTag{name: "header", library: true}
356 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700357 genSourceDepTag = dependencyTag{name: "gen source"}
358 genHeaderDepTag = dependencyTag{name: "gen header"}
359 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
360 objDepTag = dependencyTag{name: "obj"}
361 crtBeginDepTag = dependencyTag{name: "crtbegin"}
362 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700363 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
364 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700365 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900366 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700367 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
368 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800369 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800370 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700371 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100372 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700373)
374
Colin Crossca860ac2016-01-04 14:34:37 -0800375// Module contains the properties and members used by all C/C++ module types, and implements
376// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
377// to construct the output file. Behavior can be customized with a Customizer interface
378type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700379 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700380 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900381 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700382
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700383 Properties BaseProperties
384 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700385
Colin Crossca860ac2016-01-04 14:34:37 -0800386 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700387 hod android.HostOrDeviceSupported
388 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700389
Colin Crossca860ac2016-01-04 14:34:37 -0800390 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700391 features []feature
392 compiler compiler
393 linker linker
394 installer installer
395 stl *stl
396 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800397 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800398 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900399 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700400 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700401 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800402 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800403
404 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700405
Colin Cross635c3b02016-05-18 15:37:25 -0700406 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800407
Roland Levillainf2fad972019-06-28 15:41:19 +0100408 // Test output files, in the case of a test module using `test_per_src`.
409 testPerSrcOutputFiles []android.Path
410
Colin Crossb98c8b02016-07-29 13:44:28 -0700411 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700412
413 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800414
415 // Flags used to compile this module
416 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700417
418 // 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 -0800419 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700420 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800421 depsInLinkOrder android.Paths
422
423 // only non-nil when this is a shared library that reuses the objects of a static library
424 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900425
426 makeLinkType string
Colin Crossc472d572015-03-17 15:06:21 -0700427}
428
Jiyong Parkc20eee32018-09-05 22:36:17 +0900429func (c *Module) OutputFile() android.OptionalPath {
430 return c.outputFile
431}
432
Roland Levillainf2fad972019-06-28 15:41:19 +0100433func (c *Module) TestPerSrcOutputFiles() []android.Path {
434 return c.testPerSrcOutputFiles
435}
436
Jiyong Park719b4462019-01-13 00:39:51 +0900437func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900438 if c.linker != nil {
439 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900440 }
441 return nil
442}
443
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900444func (c *Module) RelativeInstallPath() string {
445 if c.installer != nil {
446 return c.installer.relativeInstallPath()
447 }
448 return ""
449}
450
Colin Cross36242852017-06-23 15:06:31 -0700451func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700452 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800453 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700454 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800455 }
456 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700457 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800458 }
459 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700460 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800461 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700462 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700463 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700464 }
Colin Cross16b23492016-01-06 14:41:07 -0800465 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700466 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800467 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800468 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700469 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800470 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800471 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700472 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800473 }
Justin Yun8effde42017-06-23 19:24:43 +0900474 if c.vndkdep != nil {
475 c.AddProperties(c.vndkdep.props()...)
476 }
Stephen Craneba090d12017-05-09 15:44:35 -0700477 if c.lto != nil {
478 c.AddProperties(c.lto.props()...)
479 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700480 if c.pgo != nil {
481 c.AddProperties(c.pgo.props()...)
482 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800483 if c.xom != nil {
484 c.AddProperties(c.xom.props()...)
485 }
Colin Crossca860ac2016-01-04 14:34:37 -0800486 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700487 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800488 }
Colin Crossc472d572015-03-17 15:06:21 -0700489
Colin Crossa9d8bee2018-10-02 13:59:46 -0700490 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
491 switch class {
492 case android.Device:
493 return ctx.Config().DevicePrefer32BitExecutables()
494 case android.HostCross:
495 // Windows builds always prefer 32-bit
496 return true
497 default:
498 return false
499 }
500 })
Colin Cross36242852017-06-23 15:06:31 -0700501 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700502
Colin Cross1f44a3a2017-07-07 14:33:33 -0700503 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700504
Jiyong Park9d452992018-10-03 00:38:19 +0900505 android.InitApexModule(c)
506
Colin Cross36242852017-06-23 15:06:31 -0700507 return c
Colin Crossc472d572015-03-17 15:06:21 -0700508}
509
Colin Crossb916a382016-07-29 17:28:03 -0700510// Returns true for dependency roots (binaries)
511// TODO(ccross): also handle dlopenable libraries
512func (c *Module) isDependencyRoot() bool {
513 if root, ok := c.linker.(interface {
514 isDependencyRoot() bool
515 }); ok {
516 return root.isDependencyRoot()
517 }
518 return false
519}
520
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700521func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700522 return c.Properties.UseVndk
523}
524
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800525func (c *Module) isCoverageVariant() bool {
526 return c.coverage.Properties.IsCoverageVariant
527}
528
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800529func (c *Module) isNdk() bool {
530 return inList(c.Name(), ndkMigratedLibs)
531}
532
Inseob Kim9516ee92019-05-09 10:56:13 +0900533func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800534 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900535 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800536}
537
Inseob Kim9516ee92019-05-09 10:56:13 +0900538func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800539 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900540 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800541}
542
Inseob Kim9516ee92019-05-09 10:56:13 +0900543func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800544 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900545 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800546}
547
Justin Yun8effde42017-06-23 19:24:43 +0900548func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800549 if vndkdep := c.vndkdep; vndkdep != nil {
550 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900551 }
552 return false
553}
554
Jooyung Han76106d92019-05-20 18:49:10 +0900555func (c *Module) vndkVersion() string {
556 if vndkdep := c.vndkdep; vndkdep != nil {
557 return vndkdep.Properties.Vndk.Version
558 }
559 return ""
560}
561
Yi Kong7e53c572018-02-14 18:16:12 +0800562func (c *Module) isPgoCompile() bool {
563 if pgo := c.pgo; pgo != nil {
564 return pgo.Properties.PgoCompile
565 }
566 return false
567}
568
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800569func (c *Module) isNDKStubLibrary() bool {
570 if _, ok := c.compiler.(*stubDecorator); ok {
571 return true
572 }
573 return false
574}
575
Logan Chienf3511742017-10-31 18:04:35 +0800576func (c *Module) isVndkSp() bool {
577 if vndkdep := c.vndkdep; vndkdep != nil {
578 return vndkdep.isVndkSp()
579 }
580 return false
581}
582
583func (c *Module) isVndkExt() bool {
584 if vndkdep := c.vndkdep; vndkdep != nil {
585 return vndkdep.isVndkExt()
586 }
587 return false
588}
589
Vic Yangefd249e2018-11-12 20:19:56 -0800590func (c *Module) mustUseVendorVariant() bool {
591 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
592}
593
Logan Chienf3511742017-10-31 18:04:35 +0800594func (c *Module) getVndkExtendsModuleName() string {
595 if vndkdep := c.vndkdep; vndkdep != nil {
596 return vndkdep.getVndkExtendsModuleName()
597 }
598 return ""
599}
600
Jiyong Park82e2bf32017-08-16 14:05:54 +0900601// Returns true only when this module is configured to have core and vendor
602// variants.
603func (c *Module) hasVendorVariant() bool {
604 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
605}
606
Jiyong Parkf9332f12018-02-01 00:54:12 +0900607func (c *Module) inRecovery() bool {
608 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
609}
610
611func (c *Module) onlyInRecovery() bool {
612 return c.ModuleBase.InstallInRecovery()
613}
614
Jiyong Park25fc6a92018-11-18 18:02:45 +0900615func (c *Module) IsStubs() bool {
616 if library, ok := c.linker.(*libraryDecorator); ok {
617 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900618 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
619 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900620 }
621 return false
622}
623
624func (c *Module) HasStubsVariants() bool {
625 if library, ok := c.linker.(*libraryDecorator); ok {
626 return len(library.Properties.Stubs.Versions) > 0
627 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700628 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
629 return len(library.Properties.Stubs.Versions) > 0
630 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900631 return false
632}
633
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900634func (c *Module) bootstrap() bool {
635 return Bool(c.Properties.Bootstrap)
636}
637
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700638func (c *Module) nativeCoverage() bool {
639 return c.linker != nil && c.linker.nativeCoverage()
640}
641
Jiyong Parkf1194352019-02-25 11:05:47 +0900642func isBionic(name string) bool {
643 switch name {
644 case "libc", "libm", "libdl", "linker":
645 return true
646 }
647 return false
648}
649
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700650func installToBootstrap(name string, config android.Config) bool {
651 if name == "libclang_rt.hwasan-aarch64-android" {
652 return inList("hwaddress", config.SanitizeDevice())
653 }
654 return isBionic(name)
655}
656
Colin Crossca860ac2016-01-04 14:34:37 -0800657type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700658 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800659 moduleContextImpl
660}
661
Colin Cross37047f12016-12-13 17:06:13 -0800662type depsContext struct {
663 android.BottomUpMutatorContext
664 moduleContextImpl
665}
666
Colin Crossca860ac2016-01-04 14:34:37 -0800667type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700668 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800669 moduleContextImpl
670}
671
Jiyong Park2db76922017-11-08 16:03:48 +0900672func (ctx *moduleContext) SocSpecific() bool {
673 return ctx.ModuleContext.SocSpecific() ||
674 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700675}
676
Colin Crossca860ac2016-01-04 14:34:37 -0800677type moduleContextImpl struct {
678 mod *Module
679 ctx BaseModuleContext
680}
681
Colin Crossb98c8b02016-07-29 13:44:28 -0700682func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800683 return ctx.mod.toolchain(ctx.ctx)
684}
685
686func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000687 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800688}
689
690func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900691 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800692}
693
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700694func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800695 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800696 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700697 }
698 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800699}
700
701func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700702 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700703 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900704 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700705 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900706 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
707 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
708 return "current"
709 }
710 return platform_vndk_ver
711 }
712 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800713 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900714 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700715 }
716 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800717}
718
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700719func (ctx *moduleContextImpl) useVndk() bool {
720 return ctx.mod.useVndk()
721}
Justin Yun8effde42017-06-23 19:24:43 +0900722
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800723func (ctx *moduleContextImpl) isNdk() bool {
724 return ctx.mod.isNdk()
725}
726
Inseob Kim9516ee92019-05-09 10:56:13 +0900727func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
728 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800729}
730
Inseob Kim9516ee92019-05-09 10:56:13 +0900731func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
732 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800733}
734
Inseob Kim9516ee92019-05-09 10:56:13 +0900735func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
736 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800737}
738
Logan Chienf3511742017-10-31 18:04:35 +0800739func (ctx *moduleContextImpl) isVndk() bool {
740 return ctx.mod.isVndk()
741}
742
Yi Kong7e53c572018-02-14 18:16:12 +0800743func (ctx *moduleContextImpl) isPgoCompile() bool {
744 return ctx.mod.isPgoCompile()
745}
746
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800747func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
748 return ctx.mod.isNDKStubLibrary()
749}
750
Justin Yun8effde42017-06-23 19:24:43 +0900751func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800752 return ctx.mod.isVndkSp()
753}
754
755func (ctx *moduleContextImpl) isVndkExt() bool {
756 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900757}
758
Vic Yangefd249e2018-11-12 20:19:56 -0800759func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
760 return ctx.mod.mustUseVendorVariant()
761}
762
Jiyong Parkf9332f12018-02-01 00:54:12 +0900763func (ctx *moduleContextImpl) inRecovery() bool {
764 return ctx.mod.inRecovery()
765}
766
Logan Chien2f2b8902018-07-10 15:01:19 +0800767// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900768func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800769 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
770 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800771 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800772
773 if ctx.ctx.Fuchsia() {
774 return false
775 }
776
Logan Chien2f2b8902018-07-10 15:01:19 +0800777 if sanitize := ctx.mod.sanitize; sanitize != nil {
778 if !sanitize.isVariantOnProductionDevice() {
779 return false
780 }
781 }
782 if !ctx.ctx.Device() {
783 // Host modules do not need ABI dumps.
784 return false
785 }
Logan Chienfa478c02018-12-28 16:25:39 +0800786 if !ctx.mod.IsForPlatform() {
787 // APEX variants do not need ABI dumps.
788 return false
789 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800790 if ctx.isStubs() {
791 // Stubs do not need ABI dumps.
792 return false
793 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800794 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800795 return true
796 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900797 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800798 return true
799 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900800 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800801 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
802 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800803 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800804 }
805 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800806}
807
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700808func (ctx *moduleContextImpl) selectedStl() string {
809 if stl := ctx.mod.stl; stl != nil {
810 return stl.Properties.SelectedStl
811 }
812 return ""
813}
814
Ivan Lozanobd721262018-11-27 14:33:03 -0800815func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
816 return ctx.mod.linker.useClangLld(actx)
817}
818
Colin Crossce75d2c2016-10-06 16:12:58 -0700819func (ctx *moduleContextImpl) baseModuleName() string {
820 return ctx.mod.ModuleBase.BaseModuleName()
821}
822
Logan Chienf3511742017-10-31 18:04:35 +0800823func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
824 return ctx.mod.getVndkExtendsModuleName()
825}
826
Jiyong Park58e364a2019-01-19 19:24:06 +0900827func (ctx *moduleContextImpl) apexName() string {
828 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900829}
830
Jiyong Parkb0788572018-12-20 22:10:17 +0900831func (ctx *moduleContextImpl) hasStubsVariants() bool {
832 return ctx.mod.HasStubsVariants()
833}
834
835func (ctx *moduleContextImpl) isStubs() bool {
836 return ctx.mod.IsStubs()
837}
838
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900839func (ctx *moduleContextImpl) bootstrap() bool {
840 return ctx.mod.bootstrap()
841}
842
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700843func (ctx *moduleContextImpl) nativeCoverage() bool {
844 return ctx.mod.nativeCoverage()
845}
846
Colin Cross635c3b02016-05-18 15:37:25 -0700847func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800848 return &Module{
849 hod: hod,
850 multilib: multilib,
851 }
852}
853
Colin Cross635c3b02016-05-18 15:37:25 -0700854func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800855 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700856 module.features = []feature{
857 &tidyFeature{},
858 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700859 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800860 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800861 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800862 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900863 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700864 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700865 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800866 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800867 return module
868}
869
Colin Crossce75d2c2016-10-06 16:12:58 -0700870func (c *Module) Prebuilt() *android.Prebuilt {
871 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
872 return p.prebuilt()
873 }
874 return nil
875}
876
877func (c *Module) Name() string {
878 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700879 if p, ok := c.linker.(interface {
880 Name(string) string
881 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700882 name = p.Name(name)
883 }
884 return name
885}
886
Alex Light3d673592019-01-18 14:37:31 -0800887func (c *Module) Symlinks() []string {
888 if p, ok := c.installer.(interface {
889 symlinkList() []string
890 }); ok {
891 return p.symlinkList()
892 }
893 return nil
894}
895
Jeff Gaston294356f2017-09-27 17:05:30 -0700896// orderDeps reorders dependencies into a list such that if module A depends on B, then
897// A will precede B in the resultant list.
898// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800899// Note that directSharedDeps should be the analogous static library for each shared lib dep
900func 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 -0700901 // If A depends on B, then
902 // Every list containing A will also contain B later in the list
903 // So, after concatenating all lists, the final instance of B will have come from the same
904 // original list as the final instance of A
905 // So, the final instance of B will be later in the concatenation than the final A
906 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
907 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800908 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700909 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800910 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
911 }
912 for _, dep := range directSharedDeps {
913 orderedAllDeps = append(orderedAllDeps, dep)
914 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700915 }
916
Colin Crossb6715442017-10-24 11:13:31 -0700917 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700918
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800919 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700920 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800921 // resultant list to only what the caller has chosen to include in directStaticDeps
922 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700923
924 return orderedAllDeps, orderedDeclaredDeps
925}
926
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800927func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
928 // convert Module to Path
929 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
930 staticDepFiles := []android.Path{}
931 for _, dep := range staticDeps {
932 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
933 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700934 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800935 sharedDepFiles := []android.Path{}
936 for _, sharedDep := range sharedDeps {
937 staticAnalogue := sharedDep.staticVariant
938 if staticAnalogue != nil {
939 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
940 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
941 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700942 }
943
944 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800945 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700946
947 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700948}
949
Colin Cross635c3b02016-05-18 15:37:25 -0700950func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100951 // Handle the case of a test module split by `test_per_src` mutator.
952 if test, ok := c.linker.(testPerSrc); ok {
953 // The `test_per_src` mutator adds an extra variant named "", depending on all the
954 // other `test_per_src` variants of the test module. Collect the output files of
955 // these dependencies and record them in the `testPerSrcOutputFiles` for later use
956 // (see e.g. `apexBundle.GenerateAndroidBuildActions`).
957 if test.isAllTestsVariation() {
958 var testPerSrcOutputFiles []android.Path
959 for _, dep := range actx.GetDirectDepsWithTag(testPerSrcDepTag) {
960 if ccDep, ok := dep.(*Module); ok {
961 depOutputFile := ccDep.OutputFile().Path()
962 testPerSrcOutputFiles =
963 append(testPerSrcOutputFiles, depOutputFile)
964 }
965 }
966 c.testPerSrcOutputFiles = testPerSrcOutputFiles
967 // Set outputFile to an empty path, as this module does not produce an
968 // output file per se.
969 c.outputFile = android.OptionalPath{}
970 return
971 }
972 }
973
Jooyung Han38002912019-05-16 04:01:54 +0900974 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900975
Colin Crossca860ac2016-01-04 14:34:37 -0800976 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700977 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800978 moduleContextImpl: moduleContextImpl{
979 mod: c,
980 },
981 }
982 ctx.ctx = ctx
983
Colin Crossf18e1102017-11-16 14:33:08 -0800984 deps := c.depsToPaths(ctx)
985 if ctx.Failed() {
986 return
987 }
988
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700989 if c.Properties.Clang != nil && *c.Properties.Clang == false {
990 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
991 }
992
Colin Crossca860ac2016-01-04 14:34:37 -0800993 flags := Flags{
994 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800995 }
Colin Crossca860ac2016-01-04 14:34:37 -0800996 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800997 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800998 }
999 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001000 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001001 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001002 if c.stl != nil {
1003 flags = c.stl.flags(ctx, flags)
1004 }
Colin Cross16b23492016-01-06 14:41:07 -08001005 if c.sanitize != nil {
1006 flags = c.sanitize.flags(ctx, flags)
1007 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001008 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001009 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001010 }
Stephen Craneba090d12017-05-09 15:44:35 -07001011 if c.lto != nil {
1012 flags = c.lto.flags(ctx, flags)
1013 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001014 if c.pgo != nil {
1015 flags = c.pgo.flags(ctx, flags)
1016 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001017 if c.xom != nil {
1018 flags = c.xom.flags(ctx, flags)
1019 }
Colin Crossca860ac2016-01-04 14:34:37 -08001020 for _, feature := range c.features {
1021 flags = feature.flags(ctx, flags)
1022 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001023 if ctx.Failed() {
1024 return
1025 }
1026
Colin Crossb98c8b02016-07-29 13:44:28 -07001027 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1028 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1029 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001030
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001031 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001032
1033 for _, dir := range deps.IncludeDirs {
1034 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1035 }
1036 for _, dir := range deps.SystemIncludeDirs {
1037 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1038 }
1039
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001040 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001041 // We need access to all the flags seen by a source file.
1042 if c.sabi != nil {
1043 flags = c.sabi.flags(ctx, flags)
1044 }
Colin Crossca860ac2016-01-04 14:34:37 -08001045 // Optimization to reduce size of build.ninja
1046 // Replace the long list of flags for each file with a module-local variable
1047 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1048 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1049 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1050 flags.CFlags = []string{"$cflags"}
1051 flags.CppFlags = []string{"$cppflags"}
1052 flags.AsFlags = []string{"$asflags"}
1053
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001054 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001055 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001056 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001057 if ctx.Failed() {
1058 return
1059 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001060 }
1061
Colin Crossca860ac2016-01-04 14:34:37 -08001062 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001063 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001064 if ctx.Failed() {
1065 return
1066 }
Colin Cross635c3b02016-05-18 15:37:25 -07001067 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001068
1069 // If a lib is directly included in any of the APEXes, unhide the stubs
1070 // variant having the latest version gets visible to make. In addition,
1071 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1072 // force anything in the make world to link against the stubs library.
1073 // (unless it is explicitly referenced via .bootstrap suffix or the
1074 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001075 if c.HasStubsVariants() &&
1076 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001077 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1078 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001079 c.Properties.HideFromMake = false // unhide
1080 // Note: this is still non-installable
1081 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001082 }
Colin Cross5049f022015-03-18 13:28:46 -07001083
Inseob Kim1f086e22019-05-09 13:29:15 +09001084 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001085 c.installer.install(ctx, c.outputFile.Path())
1086 if ctx.Failed() {
1087 return
Colin Crossca860ac2016-01-04 14:34:37 -08001088 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001089 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001090}
1091
Colin Cross0ea8ba82019-06-06 14:33:29 -07001092func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001093 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001094 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001095 }
Colin Crossca860ac2016-01-04 14:34:37 -08001096 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001097}
1098
Colin Crossca860ac2016-01-04 14:34:37 -08001099func (c *Module) begin(ctx BaseModuleContext) {
1100 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001101 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001102 }
Colin Crossca860ac2016-01-04 14:34:37 -08001103 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001104 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001105 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001106 if c.stl != nil {
1107 c.stl.begin(ctx)
1108 }
Colin Cross16b23492016-01-06 14:41:07 -08001109 if c.sanitize != nil {
1110 c.sanitize.begin(ctx)
1111 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001112 if c.coverage != nil {
1113 c.coverage.begin(ctx)
1114 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001115 if c.sabi != nil {
1116 c.sabi.begin(ctx)
1117 }
Justin Yun8effde42017-06-23 19:24:43 +09001118 if c.vndkdep != nil {
1119 c.vndkdep.begin(ctx)
1120 }
Stephen Craneba090d12017-05-09 15:44:35 -07001121 if c.lto != nil {
1122 c.lto.begin(ctx)
1123 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001124 if c.pgo != nil {
1125 c.pgo.begin(ctx)
1126 }
Colin Crossca860ac2016-01-04 14:34:37 -08001127 for _, feature := range c.features {
1128 feature.begin(ctx)
1129 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001130 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001131 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001132 if err != nil {
1133 ctx.PropertyErrorf("sdk_version", err.Error())
1134 }
Nan Zhang0007d812017-11-07 10:57:05 -08001135 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001136 }
Colin Crossca860ac2016-01-04 14:34:37 -08001137}
1138
Colin Cross37047f12016-12-13 17:06:13 -08001139func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001140 deps := Deps{}
1141
1142 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001143 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001144 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001145 // Add the PGO dependency (the clang_rt.profile runtime library), which
1146 // sometimes depends on symbols from libgcc, before libgcc gets added
1147 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001148 if c.pgo != nil {
1149 deps = c.pgo.deps(ctx, deps)
1150 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001151 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001152 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001153 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001154 if c.stl != nil {
1155 deps = c.stl.deps(ctx, deps)
1156 }
Colin Cross16b23492016-01-06 14:41:07 -08001157 if c.sanitize != nil {
1158 deps = c.sanitize.deps(ctx, deps)
1159 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001160 if c.coverage != nil {
1161 deps = c.coverage.deps(ctx, deps)
1162 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001163 if c.sabi != nil {
1164 deps = c.sabi.deps(ctx, deps)
1165 }
Justin Yun8effde42017-06-23 19:24:43 +09001166 if c.vndkdep != nil {
1167 deps = c.vndkdep.deps(ctx, deps)
1168 }
Stephen Craneba090d12017-05-09 15:44:35 -07001169 if c.lto != nil {
1170 deps = c.lto.deps(ctx, deps)
1171 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001172 for _, feature := range c.features {
1173 deps = feature.deps(ctx, deps)
1174 }
1175
Colin Crossb6715442017-10-24 11:13:31 -07001176 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1177 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1178 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1179 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1180 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1181 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001182 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001183
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001184 for _, lib := range deps.ReexportSharedLibHeaders {
1185 if !inList(lib, deps.SharedLibs) {
1186 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1187 }
1188 }
1189
1190 for _, lib := range deps.ReexportStaticLibHeaders {
1191 if !inList(lib, deps.StaticLibs) {
1192 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1193 }
1194 }
1195
Colin Cross5950f382016-12-13 12:50:57 -08001196 for _, lib := range deps.ReexportHeaderLibHeaders {
1197 if !inList(lib, deps.HeaderLibs) {
1198 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1199 }
1200 }
1201
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001202 for _, gen := range deps.ReexportGeneratedHeaders {
1203 if !inList(gen, deps.GeneratedHeaders) {
1204 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1205 }
1206 }
1207
Colin Crossc99deeb2016-04-11 15:06:20 -07001208 return deps
1209}
1210
Dan Albert7e9d2952016-08-04 13:02:36 -07001211func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001212 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001213 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001214 moduleContextImpl: moduleContextImpl{
1215 mod: c,
1216 },
1217 }
1218 ctx.ctx = ctx
1219
Colin Crossca860ac2016-01-04 14:34:37 -08001220 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001221}
1222
Jiyong Park7ed9de32018-10-15 22:25:07 +09001223// Split name#version into name and version
1224func stubsLibNameAndVersion(name string) (string, string) {
1225 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1226 version := name[sharp+1:]
1227 libname := name[:sharp]
1228 return libname, version
1229 }
1230 return name, ""
1231}
1232
Colin Cross1e676be2016-10-12 14:38:15 -07001233func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001234 ctx := &depsContext{
1235 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001236 moduleContextImpl: moduleContextImpl{
1237 mod: c,
1238 },
1239 }
1240 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001241
Colin Crossc99deeb2016-04-11 15:06:20 -07001242 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001243
Dan Albert914449f2016-06-17 16:45:24 -07001244 variantNdkLibs := []string{}
1245 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001246 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001247 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001248
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001249 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1250 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001251 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001252 // 1. Name of an NDK library that refers to a prebuilt module.
1253 // For each of these, it adds the name of the prebuilt module (which will be in
1254 // prebuilts/ndk) to the list of nonvariant libs.
1255 // 2. Name of an NDK library that refers to an ndk_library module.
1256 // For each of these, it adds the name of the ndk_library module to the list of
1257 // variant libs.
1258 // 3. Anything else (so anything that isn't an NDK library).
1259 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001260 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001261 // The caller can then know to add the variantLibs dependencies differently from the
1262 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001263
1264 llndkLibraries := llndkLibraries(actx.Config())
1265 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001266 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1267 variantLibs = []string{}
1268 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001269 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001270 // strip #version suffix out
1271 name, _ := stubsLibNameAndVersion(entry)
1272 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1273 if !inList(name, ndkMigratedLibs) {
1274 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001275 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001276 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001277 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001278 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001279 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001280 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001281 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001282 if actx.OtherModuleExists(vendorPublicLib) {
1283 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1284 } else {
1285 // This can happen if vendor_public_library module is defined in a
1286 // namespace that isn't visible to the current module. In that case,
1287 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001288 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001289 }
Dan Albert914449f2016-06-17 16:45:24 -07001290 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001291 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001292 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001293 }
1294 }
Dan Albert914449f2016-06-17 16:45:24 -07001295 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001296 }
1297
Dan Albert914449f2016-06-17 16:45:24 -07001298 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1299 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001300 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001301 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001302
Jiyong Park7e636d02019-01-28 16:16:54 +09001303 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001304 if c.linker != nil {
1305 if library, ok := c.linker.(*libraryDecorator); ok {
1306 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001307 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001308 }
1309 }
1310 }
1311
Colin Cross32ec36c2016-12-15 07:39:51 -08001312 for _, lib := range deps.HeaderLibs {
1313 depTag := headerDepTag
1314 if inList(lib, deps.ReexportHeaderLibHeaders) {
1315 depTag = headerExportDepTag
1316 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001317 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001318 actx.AddFarVariationDependencies([]blueprint.Variation{
1319 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001320 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001321 }, depTag, lib)
1322 } else {
1323 actx.AddVariationDependencies(nil, depTag, lib)
1324 }
1325 }
1326
1327 if buildStubs {
1328 // Stubs lib does not have dependency to other static/shared libraries.
1329 // Don't proceed.
1330 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001331 }
Colin Cross5950f382016-12-13 12:50:57 -08001332
Inseob Kimc0907f12019-02-08 21:00:45 +09001333 syspropImplLibraries := syspropImplLibraries(actx.Config())
1334
Jiyong Park5d1598f2019-02-25 22:14:17 +09001335 for _, lib := range deps.WholeStaticLibs {
1336 depTag := wholeStaticDepTag
1337 if impl, ok := syspropImplLibraries[lib]; ok {
1338 lib = impl
1339 }
1340 actx.AddVariationDependencies([]blueprint.Variation{
1341 {Mutator: "link", Variation: "static"},
1342 }, depTag, lib)
1343 }
1344
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001345 for _, lib := range deps.StaticLibs {
1346 depTag := staticDepTag
1347 if inList(lib, deps.ReexportStaticLibHeaders) {
1348 depTag = staticExportDepTag
1349 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001350
1351 if impl, ok := syspropImplLibraries[lib]; ok {
1352 lib = impl
1353 }
1354
Dan Willemsen59339a22018-07-22 21:18:45 -07001355 actx.AddVariationDependencies([]blueprint.Variation{
1356 {Mutator: "link", Variation: "static"},
1357 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001358 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001359
Dan Willemsen59339a22018-07-22 21:18:45 -07001360 actx.AddVariationDependencies([]blueprint.Variation{
1361 {Mutator: "link", Variation: "static"},
1362 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001363
Jiyong Park25fc6a92018-11-18 18:02:45 +09001364 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1365 var variations []blueprint.Variation
1366 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001367 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001368 if version != "" && versionVariantAvail {
1369 // Version is explicitly specified. i.e. libFoo#30
1370 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1371 depTag.explicitlyVersioned = true
1372 }
1373 actx.AddVariationDependencies(variations, depTag, name)
1374
1375 // If the version is not specified, add dependency to the latest stubs library.
1376 // The stubs library will be used when the depending module is built for APEX and
1377 // the dependent module is not in the same APEX.
1378 latestVersion := latestStubsVersionFor(actx.Config(), name)
1379 if version == "" && latestVersion != "" && versionVariantAvail {
1380 actx.AddVariationDependencies([]blueprint.Variation{
1381 {Mutator: "link", Variation: "shared"},
1382 {Mutator: "version", Variation: latestVersion},
1383 }, depTag, name)
1384 // Note that depTag.explicitlyVersioned is false in this case.
1385 }
1386 }
1387
Jiyong Park7ed9de32018-10-15 22:25:07 +09001388 // shared lib names without the #version suffix
1389 var sharedLibNames []string
1390
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001391 for _, lib := range deps.SharedLibs {
1392 depTag := sharedDepTag
1393 if inList(lib, deps.ReexportSharedLibHeaders) {
1394 depTag = sharedExportDepTag
1395 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001396
1397 if impl, ok := syspropImplLibraries[lib]; ok {
1398 lib = impl
1399 }
1400
1401 name, version := stubsLibNameAndVersion(lib)
1402 sharedLibNames = append(sharedLibNames, name)
1403
Jiyong Park25fc6a92018-11-18 18:02:45 +09001404 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001405 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001406
Jiyong Park7ed9de32018-10-15 22:25:07 +09001407 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001408 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001409 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1410 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1411 // linking against both the stubs lib and the non-stubs lib at the same time.
1412 continue
1413 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001414 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001415 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001416
Dan Willemsen59339a22018-07-22 21:18:45 -07001417 actx.AddVariationDependencies([]blueprint.Variation{
1418 {Mutator: "link", Variation: "shared"},
1419 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001420
Colin Cross68861832016-07-08 10:41:41 -07001421 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001422
1423 for _, gen := range deps.GeneratedHeaders {
1424 depTag := genHeaderDepTag
1425 if inList(gen, deps.ReexportGeneratedHeaders) {
1426 depTag = genHeaderExportDepTag
1427 }
1428 actx.AddDependency(c, depTag, gen)
1429 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001430
Colin Cross42d48b72018-08-29 14:10:52 -07001431 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001432
1433 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001434 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001435 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001436 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001437 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001438 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001439 if deps.LinkerFlagsFile != "" {
1440 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1441 }
1442 if deps.DynamicLinker != "" {
1443 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001444 }
Dan Albert914449f2016-06-17 16:45:24 -07001445
1446 version := ctx.sdkVersion()
1447 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001448 {Mutator: "ndk_api", Variation: version},
1449 {Mutator: "link", Variation: "shared"},
1450 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001451 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001452 {Mutator: "ndk_api", Variation: version},
1453 {Mutator: "link", Variation: "shared"},
1454 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001455
1456 if vndkdep := c.vndkdep; vndkdep != nil {
1457 if vndkdep.isVndkExt() {
1458 baseModuleMode := vendorMode
1459 if actx.DeviceConfig().VndkVersion() == "" {
1460 baseModuleMode = coreMode
1461 }
1462 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001463 {Mutator: "image", Variation: baseModuleMode},
1464 {Mutator: "link", Variation: "shared"},
1465 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001466 }
1467 }
Colin Cross6362e272015-10-29 15:25:03 -07001468}
Colin Cross21b9a242015-03-24 14:15:58 -07001469
Colin Crosse40b4ea2018-10-02 22:25:58 -07001470func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001471 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1472 c.beginMutator(ctx)
1473 }
1474}
1475
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001476// Whether a module can link to another module, taking into
1477// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001478func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001479 if from.Target().Os != android.Android {
1480 // Host code is not restricted
1481 return
1482 }
1483 if from.Properties.UseVndk {
1484 // Though vendor code is limited by the vendor mutator,
1485 // each vendor-available module needs to check
1486 // link-type for VNDK.
1487 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001488 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001489 }
1490 return
1491 }
Nan Zhang0007d812017-11-07 10:57:05 -08001492 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001493 // Platform code can link to anything
1494 return
1495 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001496 if from.inRecovery() {
1497 // Recovery code is not NDK
1498 return
1499 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001500 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1501 // These are always allowed
1502 return
1503 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001504 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1505 // These are allowed, but they don't set sdk_version
1506 return
1507 }
1508 if _, ok := to.linker.(*stubDecorator); ok {
1509 // These aren't real libraries, but are the stub shared libraries that are included in
1510 // the NDK.
1511 return
1512 }
Logan Chien834b9a62019-01-14 15:39:03 +08001513
1514 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1515 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1516 // to link to libc++ (non-NDK and without sdk_version).
1517 return
1518 }
1519
Nan Zhang0007d812017-11-07 10:57:05 -08001520 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001521 // NDK code linking to platform code is never okay.
1522 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1523 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001524 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001525 }
1526
1527 // At this point we know we have two NDK libraries, but we need to
1528 // check that we're not linking against anything built against a higher
1529 // API level, as it is only valid to link against older or equivalent
1530 // APIs.
1531
Inseob Kim01a28722018-04-11 09:48:45 +09001532 // Current can link against anything.
1533 if String(from.Properties.Sdk_version) != "current" {
1534 // Otherwise we need to check.
1535 if String(to.Properties.Sdk_version) == "current" {
1536 // Current can't be linked against by anything else.
1537 ctx.ModuleErrorf("links %q built against newer API version %q",
1538 ctx.OtherModuleName(to), "current")
1539 } else {
1540 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1541 if err != nil {
1542 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001543 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001544 String(from.Properties.Sdk_version))
1545 }
1546 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1547 if err != nil {
1548 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001549 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001550 String(to.Properties.Sdk_version))
1551 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001552
Inseob Kim01a28722018-04-11 09:48:45 +09001553 if toApi > fromApi {
1554 ctx.ModuleErrorf("links %q built against newer API version %q",
1555 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1556 }
1557 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001558 }
Dan Albert202fe492017-12-15 13:56:59 -08001559
1560 // Also check that the two STL choices are compatible.
1561 fromStl := from.stl.Properties.SelectedStl
1562 toStl := to.stl.Properties.SelectedStl
1563 if fromStl == "" || toStl == "" {
1564 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001565 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001566 // We can be permissive with the system "STL" since it is only the C++
1567 // ABI layer, but in the future we should make sure that everyone is
1568 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001569 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001570 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1571 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1572 to.stl.Properties.SelectedStl)
1573 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001574}
1575
Jiyong Park5fb8c102018-04-09 12:03:06 +09001576// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001577// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1578// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001579// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001580func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001581 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001582 check := func(child, parent android.Module) bool {
1583 to, ok := child.(*Module)
1584 if !ok {
1585 // follow thru cc.Defaults, etc.
1586 return true
1587 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001588
Jooyung Hana70f0672019-01-18 15:20:43 +09001589 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1590 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001591 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001592
1593 // if target lib has no vendor variant, keep checking dependency graph
1594 if !to.hasVendorVariant() {
1595 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001596 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001597
Inseob Kim9516ee92019-05-09 10:56:13 +09001598 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001599 return false
1600 }
1601
1602 var stringPath []string
1603 for _, m := range ctx.GetWalkPath() {
1604 stringPath = append(stringPath, m.Name())
1605 }
1606 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1607 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1608 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1609 return false
1610 }
1611 if module, ok := ctx.Module().(*Module); ok {
1612 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001613 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001614 ctx.WalkDeps(check)
1615 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001616 }
1617 }
1618}
1619
Colin Crossc99deeb2016-04-11 15:06:20 -07001620// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001621func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001622 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001623
Jeff Gaston294356f2017-09-27 17:05:30 -07001624 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001625 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001626
Inseob Kim9516ee92019-05-09 10:56:13 +09001627 llndkLibraries := llndkLibraries(ctx.Config())
1628 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1629
Inseob Kim69378442019-06-03 19:10:47 +09001630 reexportExporter := func(exporter exportedFlagsProducer) {
1631 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1632 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1633 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1634 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1635 }
1636
Colin Crossd11fcda2017-10-23 17:59:01 -07001637 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001638 depName := ctx.OtherModuleName(dep)
1639 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001640
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001641 ccDep, _ := dep.(*Module)
1642 if ccDep == nil {
1643 // handling for a few module types that aren't cc Module but that are also supported
1644 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001645 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001646 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001647 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1648 genRule.GeneratedSourceFiles()...)
1649 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001650 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001651 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001652 // Support exported headers from a generated_sources dependency
1653 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001654 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001655 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001656 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001657 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001658 dirs := genRule.GeneratedHeaderDirs().Strings()
1659 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001660 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001661 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1662 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001663 // 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 +09001664 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001665
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001666 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001667 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001668 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001669 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001670 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001671 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001672 files := genRule.GeneratedSourceFiles()
1673 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001674 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001675 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001676 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 -07001677 }
1678 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001679 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001680 }
Colin Crossca860ac2016-01-04 14:34:37 -08001681 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001682 return
1683 }
1684
Colin Crossfe17f6f2019-03-28 19:30:56 -07001685 if depTag == android.ProtoPluginDepTag {
1686 return
1687 }
1688
Colin Crossd11fcda2017-10-23 17:59:01 -07001689 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001690 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1691 return
1692 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001693 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001694 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001695 return
1696 }
1697
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001698 // re-exporting flags
1699 if depTag == reuseObjTag {
1700 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001701 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001702 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001703 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001704 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001705 return
1706 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001707 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001708
Jiyong Parke4bb9862019-02-01 00:31:10 +09001709 if depTag == staticVariantTag {
1710 if _, ok := ccDep.compiler.(libraryInterface); ok {
1711 c.staticVariant = ccDep
1712 return
1713 }
1714 }
1715
Jiyong Park25fc6a92018-11-18 18:02:45 +09001716 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1717 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1718 // won't be matched to sharedDepTag and lateSharedDepTag.
1719 explicitlyVersioned := false
1720 if t, ok := depTag.(dependencyTag); ok {
1721 explicitlyVersioned = t.explicitlyVersioned
1722 t.explicitlyVersioned = false
1723 depTag = t
1724 }
1725
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001726 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001727 depIsStatic := false
1728 switch depTag {
1729 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1730 depIsStatic = true
1731 }
1732 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001733 depIsStubs := dependentLibrary.buildStubs()
1734 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001735 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001736 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001737
1738 var useThisDep bool
1739 if depIsStubs && explicitlyVersioned {
1740 // Always respect dependency to the versioned stubs (i.e. libX#10)
1741 useThisDep = true
1742 } else if !depHasStubs {
1743 // Use non-stub variant if that is the only choice
1744 // (i.e. depending on a lib without stubs.version property)
1745 useThisDep = true
1746 } else if c.IsForPlatform() {
1747 // If not building for APEX, use stubs only when it is from
1748 // an APEX (and not from platform)
1749 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001750 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001751 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001752 // always link to non-stub variant
1753 useThisDep = !depIsStubs
1754 }
1755 } else {
1756 // If building for APEX, use stubs only when it is not from
1757 // the same APEX
1758 useThisDep = (depInSameApex != depIsStubs)
1759 }
1760
1761 if !useThisDep {
1762 return // stop processing this dep
1763 }
1764 }
1765
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001766 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001767 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1768 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1769 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1770 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001771
1772 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001773 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001774 // 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 -07001775 // Re-exported shared library headers must be included as well since they can help us with type information
1776 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001777 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1778 // scripts.
1779 c.sabi.Properties.ReexportedIncludes = append(
1780 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001781 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001782 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001783
Logan Chienf3511742017-10-31 18:04:35 +08001784 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001785 }
1786
Colin Cross26c34ed2016-09-30 17:10:16 -07001787 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001788 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001789
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001790 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001791 depFile := android.OptionalPath{}
1792
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001793 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001794 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001795 ptr = &depPaths.SharedLibs
1796 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001797 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001798 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001799 case earlySharedDepTag:
1800 ptr = &depPaths.EarlySharedLibs
1801 depPtr = &depPaths.EarlySharedLibsDeps
1802 depFile = ccDep.linker.(libraryInterface).toc()
1803 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001804 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001805 ptr = &depPaths.LateSharedLibs
1806 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001807 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001808 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001809 ptr = nil
1810 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001811 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001812 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001813 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001814 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001815 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001816 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001817 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001818 return
1819 }
1820
1821 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001822 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001823 for i := range missingDeps {
1824 missingDeps[i] += postfix
1825 }
1826 ctx.AddMissingDependencies(missingDeps)
1827 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001828 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001829 case headerDepTag:
1830 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001831 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001832 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001833 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001834 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001835 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001836 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001837 case dynamicLinkerDepTag:
1838 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001839 }
1840
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001841 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001842 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001843 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001844 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001845 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001846 return
1847 }
1848
1849 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001850 // in static libraries act as if they were whole static libraries. The same goes for
1851 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001852 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1853 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001854 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1855 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001856
Dan Willemsen581341d2017-02-09 16:16:31 -08001857 }
1858
Colin Cross26c34ed2016-09-30 17:10:16 -07001859 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001860 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001861 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001862 return
1863 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001864 *ptr = append(*ptr, linkFile.Path())
1865 }
1866
Colin Crossc99deeb2016-04-11 15:06:20 -07001867 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001868 dep := depFile
1869 if !dep.Valid() {
1870 dep = linkFile
1871 }
1872 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001873 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001874
Logan Chien43d34c32017-12-20 01:17:32 +08001875 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001876 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001877 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001878 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001879 isLLndk := inList(libName, *llndkLibraries)
1880 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001881 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001882
1883 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1884 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1885 // core module instead.
1886 return libName
1887 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001888 // The vendor module in Make will have been renamed to not conflict with the core
1889 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001890 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001891 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001892 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001893 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1894 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001895 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001896 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001897 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001898 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001899 }
Logan Chien43d34c32017-12-20 01:17:32 +08001900 }
1901
1902 // Export the shared libs to Make.
1903 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001904 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001905 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001906 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001907 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001908 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001909 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001910 c.Properties.ApexesProvidingSharedLibs = append(
1911 c.Properties.ApexesProvidingSharedLibs, an)
1912 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001913 }
1914 }
1915
Jiyong Park27b188b2017-07-18 13:23:39 +09001916 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001917 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001918 c.Properties.AndroidMkSharedLibs = append(
1919 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001920 case ndkStubDepTag, ndkLateStubDepTag:
1921 ndkStub := ccDep.linker.(*stubDecorator)
1922 c.Properties.AndroidMkSharedLibs = append(
1923 c.Properties.AndroidMkSharedLibs,
1924 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001925 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1926 c.Properties.AndroidMkStaticLibs = append(
1927 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001928 case runtimeDepTag:
1929 c.Properties.AndroidMkRuntimeLibs = append(
1930 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001931 case wholeStaticDepTag:
1932 c.Properties.AndroidMkWholeStaticLibs = append(
1933 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001934 }
Colin Crossca860ac2016-01-04 14:34:37 -08001935 })
1936
Jeff Gaston294356f2017-09-27 17:05:30 -07001937 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001938 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001939
Colin Crossdd84e052017-05-17 13:44:16 -07001940 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001941 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001942 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1943 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001944 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001945 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1946 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001947 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001948 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001949
1950 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001951 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001952 }
Colin Crossdd84e052017-05-17 13:44:16 -07001953
Colin Crossca860ac2016-01-04 14:34:37 -08001954 return depPaths
1955}
1956
1957func (c *Module) InstallInData() bool {
1958 if c.installer == nil {
1959 return false
1960 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001961 return c.installer.inData()
1962}
1963
1964func (c *Module) InstallInSanitizerDir() bool {
1965 if c.installer == nil {
1966 return false
1967 }
1968 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001969 return true
1970 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001971 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001972}
1973
Jiyong Parkf9332f12018-02-01 00:54:12 +09001974func (c *Module) InstallInRecovery() bool {
1975 return c.inRecovery()
1976}
1977
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001978func (c *Module) HostToolPath() android.OptionalPath {
1979 if c.installer == nil {
1980 return android.OptionalPath{}
1981 }
1982 return c.installer.hostToolPath()
1983}
1984
Nan Zhangd4e641b2017-07-12 12:55:28 -07001985func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1986 return c.outputFile
1987}
1988
Colin Cross41955e82019-05-29 14:40:35 -07001989func (c *Module) OutputFiles(tag string) (android.Paths, error) {
1990 switch tag {
1991 case "":
1992 if c.outputFile.Valid() {
1993 return android.Paths{c.outputFile.Path()}, nil
1994 }
1995 return android.Paths{}, nil
1996 default:
1997 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001998 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001999}
2000
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002001func (c *Module) static() bool {
2002 if static, ok := c.linker.(interface {
2003 static() bool
2004 }); ok {
2005 return static.static()
2006 }
2007 return false
2008}
2009
Jiyong Park379de2f2018-12-19 02:47:14 +09002010func (c *Module) staticBinary() bool {
2011 if static, ok := c.linker.(interface {
2012 staticBinary() bool
2013 }); ok {
2014 return static.staticBinary()
2015 }
2016 return false
2017}
2018
Jooyung Han38002912019-05-16 04:01:54 +09002019func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2020 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002021 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002022 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2023 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002024 return "native:vndk"
2025 }
Jooyung Han38002912019-05-16 04:01:54 +09002026 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002027 }
Jooyung Han38002912019-05-16 04:01:54 +09002028 if c.isVndk() && !c.isVndkExt() {
2029 if Bool(c.VendorProperties.Vendor_available) {
2030 return "native:vndk"
2031 }
2032 return "native:vndk_private"
2033 }
2034 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002035 } else if c.inRecovery() {
2036 return "native:recovery"
2037 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2038 return "native:ndk:none:none"
2039 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2040 //family, link := getNdkStlFamilyAndLinkType(c)
2041 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002042 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002043 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002044 } else {
2045 return "native:platform"
2046 }
2047}
2048
Jiyong Park9d452992018-10-03 00:38:19 +09002049// Overrides ApexModule.IsInstallabeToApex()
2050// Only shared libraries are installable to APEX.
2051func (c *Module) IsInstallableToApex() bool {
2052 if shared, ok := c.linker.(interface {
2053 shared() bool
2054 }); ok {
2055 return shared.shared()
2056 }
2057 return false
2058}
2059
Inseob Kim1f086e22019-05-09 13:29:15 +09002060func (c *Module) installable() bool {
2061 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2062}
2063
Jiyong Park3b1746a2019-01-29 11:15:04 +09002064func (c *Module) imageVariation() string {
2065 variation := "core"
2066 if c.useVndk() {
2067 variation = "vendor"
2068 } else if c.inRecovery() {
2069 variation = "recovery"
2070 }
2071 return variation
2072}
2073
bralee3f49f4d2019-03-04 06:58:15 +08002074func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002075 outputFiles, err := c.OutputFiles("")
2076 if err != nil {
2077 panic(err)
2078 }
2079 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002080}
2081
Logan Chien41eabe62019-04-10 13:33:58 +08002082func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2083 if c.linker != nil {
2084 if library, ok := c.linker.(*libraryDecorator); ok {
2085 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2086 }
2087 }
2088}
2089
Colin Cross2ba19d92015-05-07 15:44:20 -07002090//
Colin Crosscfad1192015-11-02 16:43:11 -08002091// Defaults
2092//
Colin Crossca860ac2016-01-04 14:34:37 -08002093type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002094 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002095 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002096 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002097}
2098
Patrice Arrudac249c712019-03-19 17:00:29 -07002099// cc_defaults provides a set of properties that can be inherited by other cc
2100// modules. A module can use the properties from a cc_defaults using
2101// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2102// merged (when possible) by prepending the default module's values to the
2103// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002104func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002105 return DefaultsFactory()
2106}
2107
Colin Cross36242852017-06-23 15:06:31 -07002108func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002109 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002110
Colin Cross36242852017-06-23 15:06:31 -07002111 module.AddProperties(props...)
2112 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002113 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002114 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002115 &BaseCompilerProperties{},
2116 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002117 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002118 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002119 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002120 &TestProperties{},
2121 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002122 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002123 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002124 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002125 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002126 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002127 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002128 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002129 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002130 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002131 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002132 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002133 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002134 )
Colin Crosscfad1192015-11-02 16:43:11 -08002135
Colin Cross1f44a3a2017-07-07 14:33:33 -07002136 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002137 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002138
2139 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002140}
2141
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002142const (
2143 // coreMode is the variant used for framework-private libraries, or
2144 // SDK libraries. (which framework-private libraries can use)
2145 coreMode = "core"
2146
2147 // vendorMode is the variant used for /vendor code that compiles
2148 // against the VNDK.
2149 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002150
2151 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002152)
2153
Jiyong Park6a43f042017-10-12 23:05:00 +09002154func squashVendorSrcs(m *Module) {
2155 if lib, ok := m.compiler.(*libraryDecorator); ok {
2156 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2157 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2158
2159 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2160 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2161 }
2162}
2163
Jiyong Parkf9332f12018-02-01 00:54:12 +09002164func squashRecoverySrcs(m *Module) {
2165 if lib, ok := m.compiler.(*libraryDecorator); ok {
2166 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2167 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2168
2169 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2170 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2171 }
2172}
2173
Jiyong Parkda6eb592018-12-19 17:12:36 +09002174func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002175 if mctx.Os() != android.Android {
2176 return
2177 }
2178
Jiyong Park7ed9de32018-10-15 22:25:07 +09002179 if g, ok := mctx.Module().(*genrule.Module); ok {
2180 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002181 var coreVariantNeeded bool = false
2182 var vendorVariantNeeded bool = false
2183 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002184 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002185 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002186 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002187 coreVariantNeeded = true
2188 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002189 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002190 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002191 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002192 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002193 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002194 if Bool(props.Recovery_available) {
2195 recoveryVariantNeeded = true
2196 }
2197
Jiyong Park413cc742018-06-19 01:46:06 +09002198 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002199 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002200 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002201 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002202 recoveryVariantNeeded = false
2203 }
2204 }
2205
Jiyong Park3f736c92018-05-24 13:36:56 +09002206 var variants []string
2207 if coreVariantNeeded {
2208 variants = append(variants, coreMode)
2209 }
2210 if vendorVariantNeeded {
2211 variants = append(variants, vendorMode)
2212 }
2213 if recoveryVariantNeeded {
2214 variants = append(variants, recoveryMode)
2215 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002216 mod := mctx.CreateVariations(variants...)
2217 for i, v := range variants {
2218 if v == recoveryMode {
2219 m := mod[i].(*genrule.Module)
2220 m.Extra.(*GenruleExtraProperties).InRecovery = true
2221 }
2222 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002223 }
2224 }
2225
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002226 m, ok := mctx.Module().(*Module)
2227 if !ok {
2228 return
2229 }
2230
2231 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002232 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002233 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002234
2235 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002236 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002237 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002238 return
2239 }
Logan Chienf3511742017-10-31 18:04:35 +08002240
2241 if vndkdep := m.vndkdep; vndkdep != nil {
2242 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002243 if productSpecific {
2244 mctx.PropertyErrorf("product_specific",
2245 "product_specific must not be true when `vndk: {enabled: true}`")
2246 return
2247 }
Logan Chienf3511742017-10-31 18:04:35 +08002248 if vendorSpecific {
2249 if !vndkdep.isVndkExt() {
2250 mctx.PropertyErrorf("vndk",
2251 "must set `extends: \"...\"` to vndk extension")
2252 return
2253 }
2254 } else {
2255 if vndkdep.isVndkExt() {
2256 mctx.PropertyErrorf("vndk",
2257 "must set `vendor: true` to set `extends: %q`",
2258 m.getVndkExtendsModuleName())
2259 return
2260 }
2261 if m.VendorProperties.Vendor_available == nil {
2262 mctx.PropertyErrorf("vndk",
2263 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2264 return
2265 }
2266 }
2267 } else {
2268 if vndkdep.isVndkSp() {
2269 mctx.PropertyErrorf("vndk",
2270 "must set `enabled: true` to set `support_system_process: true`")
2271 return
2272 }
2273 if vndkdep.isVndkExt() {
2274 mctx.PropertyErrorf("vndk",
2275 "must set `enabled: true` to set `extends: %q`",
2276 m.getVndkExtendsModuleName())
2277 return
2278 }
Justin Yun8effde42017-06-23 19:24:43 +09002279 }
2280 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002281
Jiyong Parkf9332f12018-02-01 00:54:12 +09002282 var coreVariantNeeded bool = false
2283 var vendorVariantNeeded bool = false
2284 var recoveryVariantNeeded bool = false
2285
Justin Yun71549282017-11-17 12:10:28 +09002286 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002287 // If the device isn't compiling against the VNDK, we always
2288 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002289 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002290 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2291 // LL-NDK stubs only exist in the vendor variant, since the
2292 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002293 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002294 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2295 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002296 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002297 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002298 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2299 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002300 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002301 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002302 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002303 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002304 coreVariantNeeded = true
2305 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002306 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002307 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002308 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002309 } else {
2310 // This is either in /system (or similar: /data), or is a
2311 // modules built with the NDK. Modules built with the NDK
2312 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002313 coreVariantNeeded = true
2314 }
2315
2316 if Bool(m.Properties.Recovery_available) {
2317 recoveryVariantNeeded = true
2318 }
2319
2320 if m.ModuleBase.InstallInRecovery() {
2321 recoveryVariantNeeded = true
2322 coreVariantNeeded = false
2323 }
2324
Jiyong Park413cc742018-06-19 01:46:06 +09002325 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002326 primaryArch := mctx.Config().DevicePrimaryArchType()
2327 moduleArch := m.Target().Arch.ArchType
2328 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002329 recoveryVariantNeeded = false
2330 }
2331 }
2332
Jiyong Parkf9332f12018-02-01 00:54:12 +09002333 var variants []string
2334 if coreVariantNeeded {
2335 variants = append(variants, coreMode)
2336 }
2337 if vendorVariantNeeded {
2338 variants = append(variants, vendorMode)
2339 }
2340 if recoveryVariantNeeded {
2341 variants = append(variants, recoveryMode)
2342 }
2343 mod := mctx.CreateVariations(variants...)
2344 for i, v := range variants {
2345 if v == vendorMode {
2346 m := mod[i].(*Module)
2347 m.Properties.UseVndk = true
2348 squashVendorSrcs(m)
2349 } else if v == recoveryMode {
2350 m := mod[i].(*Module)
2351 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002352 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002353 squashRecoverySrcs(m)
2354 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002355 }
2356}
2357
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002358func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002359 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002360 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2361 }
Colin Cross6510f912017-11-29 00:27:14 -08002362 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002363}
2364
Colin Cross06a931b2015-10-28 17:23:31 -07002365var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002366var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002367var BoolPtr = proptools.BoolPtr
2368var String = proptools.String
2369var StringPtr = proptools.StringPtr