blob: 2cee807178f6008fc6a358214fa1c26f7113cec5 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070036 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Colin Cross1e676be2016-10-12 14:38:15 -070038 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070040 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090041 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070042 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010043 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090044 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070045 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090046 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070047 })
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
50 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
51 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080052
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070053 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
54 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
55
Mitch Phillipsbfeade62019-05-01 14:42:05 -070056 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
57 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
58
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000059 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
60 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
61
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080062 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
63 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
64
Colin Cross1e676be2016-10-12 14:38:15 -070065 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
66 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080067
Colin Cross0b908332019-06-19 23:00:20 -070068 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090069 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080070
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080071 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080072 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070073
74 ctx.TopDown("lto_deps", ltoDepsMutator)
75 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090076
77 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070078 })
Colin Crossb98c8b02016-07-29 13:44:28 -070079
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 {
Paul Duffina37832a2019-07-18 12:31:26 +0100182 // list of modules that should only provide headers for this module.
183 Header_libs []string `android:"arch_variant,variant_prepend"`
184
Colin Cross81413472016-04-11 14:37:39 -0700185 // names of other cc_object modules to link into this module using partial linking
186 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700187
188 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800189 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700190}
191
Colin Crossca860ac2016-01-04 14:34:37 -0800192// Properties used to compile all C or C++ modules
193type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700194 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800195 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700196
197 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800198 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700199
Jiyong Parkde866cb2018-12-07 23:08:36 +0900200 AndroidMkSharedLibs []string `blueprint:"mutated"`
201 AndroidMkStaticLibs []string `blueprint:"mutated"`
202 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
203 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
204 HideFromMake bool `blueprint:"mutated"`
205 PreventInstall bool `blueprint:"mutated"`
206 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700207
208 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800209
210 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
211 // file
212 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900213
214 // Make this module available when building for recovery
215 Recovery_available *bool
216
217 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900218
219 // Allows this module to use non-APEX version of libraries. Useful
220 // for building binaries that are started before APEXes are activated.
221 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700222}
223
224type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900225 // whether this module should be allowed to be directly depended by other
226 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
227 // If set to true, two variants will be built separately, one like
228 // normal, and the other limited to the set of libraries and headers
229 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700230 //
231 // The vendor variant may be used with a different (newer) /system,
232 // so it shouldn't have any unversioned runtime dependencies, or
233 // make assumptions about the system that may not be true in the
234 // future.
235 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900236 // If set to false, this module becomes inaccessible from /vendor modules.
237 //
238 // Default value is true when vndk: {enabled: true} or vendor: true.
239 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700240 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
241 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900242
243 // whether this module is capable of being loaded with other instance
244 // (possibly an older version) of the same module in the same process.
245 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
246 // can be double loaded in a vendor process if the library is also a
247 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
248 // explicitly marked as `double_loadable: true` by the owner, or the dependency
249 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
250 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800251}
252
Colin Crossca860ac2016-01-04 14:34:37 -0800253type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800254 static() bool
255 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700256 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700257 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800258 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700259 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800260 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900261 isLlndk(config android.Config) bool
262 isLlndkPublic(config android.Config) bool
263 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900264 isVndk() bool
265 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800266 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900267 inRecovery() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900268 shouldCreateVndkSourceAbiDump(config android.Config) bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700269 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700270 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800271 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800272 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800273 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800274 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900275 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900276 hasStubsVariants() bool
277 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900278 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800279 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700280 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800281}
282
283type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700284 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800285 ModuleContextIntf
286}
287
288type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700289 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800290 ModuleContextIntf
291}
292
Colin Cross37047f12016-12-13 17:06:13 -0800293type DepsContext interface {
294 android.BottomUpMutatorContext
295 ModuleContextIntf
296}
297
Colin Crossca860ac2016-01-04 14:34:37 -0800298type feature interface {
299 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800300 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800301 flags(ctx ModuleContext, flags Flags) Flags
302 props() []interface{}
303}
304
305type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700306 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800307 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800308 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700309 compilerProps() []interface{}
310
Colin Cross76fada02016-07-27 10:31:13 -0700311 appendCflags([]string)
312 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700313 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800314}
315
316type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700317 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800318 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700319 linkerFlags(ctx ModuleContext, flags Flags) Flags
320 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800321 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700322
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700323 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700324 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900325 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700326
327 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800328}
329
330type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700331 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700332 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800333 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700334 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700335 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900336 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800337}
338
Colin Crossc99deeb2016-04-11 15:06:20 -0700339type dependencyTag struct {
340 blueprint.BaseDependencyTag
341 name string
342 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700343
344 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900345
346 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700347}
348
349var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700350 sharedDepTag = dependencyTag{name: "shared", library: true}
351 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900352 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700353 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
354 staticDepTag = dependencyTag{name: "static", library: true}
355 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
356 lateStaticDepTag = dependencyTag{name: "late static", library: true}
357 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800358 headerDepTag = dependencyTag{name: "header", library: true}
359 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700360 genSourceDepTag = dependencyTag{name: "gen source"}
361 genHeaderDepTag = dependencyTag{name: "gen header"}
362 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
363 objDepTag = dependencyTag{name: "obj"}
364 crtBeginDepTag = dependencyTag{name: "crtbegin"}
365 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700366 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
367 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700368 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900369 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700370 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
371 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800372 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800373 runtimeDepTag = dependencyTag{name: "runtime lib"}
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -0700374 coverageDepTag = dependencyTag{name: "coverage"}
Roland Levillainf2fad972019-06-28 15:41:19 +0100375 testPerSrcDepTag = dependencyTag{name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700376)
377
Colin Crossca860ac2016-01-04 14:34:37 -0800378// Module contains the properties and members used by all C/C++ module types, and implements
379// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
380// to construct the output file. Behavior can be customized with a Customizer interface
381type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700382 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700383 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900384 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700385
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700386 Properties BaseProperties
387 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700388
Colin Crossca860ac2016-01-04 14:34:37 -0800389 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700390 hod android.HostOrDeviceSupported
391 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700392
Colin Crossca860ac2016-01-04 14:34:37 -0800393 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700394 features []feature
395 compiler compiler
396 linker linker
397 installer installer
398 stl *stl
399 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800400 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800401 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900402 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700403 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700404 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800405 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800406
407 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700408
Colin Cross635c3b02016-05-18 15:37:25 -0700409 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800410
Roland Levillainf2fad972019-06-28 15:41:19 +0100411 // Test output files, in the case of a test module using `test_per_src`.
412 testPerSrcOutputFiles []android.Path
413
Colin Crossb98c8b02016-07-29 13:44:28 -0700414 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700415
416 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800417
418 // Flags used to compile this module
419 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700420
421 // 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 -0800422 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700423 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800424 depsInLinkOrder android.Paths
425
426 // only non-nil when this is a shared library that reuses the objects of a static library
427 staticVariant *Module
Inseob Kim9516ee92019-05-09 10:56:13 +0900428
429 makeLinkType string
Colin Crossc472d572015-03-17 15:06:21 -0700430}
431
Jiyong Parkc20eee32018-09-05 22:36:17 +0900432func (c *Module) OutputFile() android.OptionalPath {
433 return c.outputFile
434}
435
Roland Levillainf2fad972019-06-28 15:41:19 +0100436func (c *Module) TestPerSrcOutputFiles() []android.Path {
437 return c.testPerSrcOutputFiles
438}
439
Jiyong Park719b4462019-01-13 00:39:51 +0900440func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900441 if c.linker != nil {
442 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900443 }
444 return nil
445}
446
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900447func (c *Module) RelativeInstallPath() string {
448 if c.installer != nil {
449 return c.installer.relativeInstallPath()
450 }
451 return ""
452}
453
Colin Cross36242852017-06-23 15:06:31 -0700454func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700455 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800456 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700457 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800458 }
459 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700460 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800461 }
462 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700463 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800464 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700465 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700466 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700467 }
Colin Cross16b23492016-01-06 14:41:07 -0800468 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700469 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800470 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800471 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700472 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800473 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800474 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700475 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800476 }
Justin Yun8effde42017-06-23 19:24:43 +0900477 if c.vndkdep != nil {
478 c.AddProperties(c.vndkdep.props()...)
479 }
Stephen Craneba090d12017-05-09 15:44:35 -0700480 if c.lto != nil {
481 c.AddProperties(c.lto.props()...)
482 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700483 if c.pgo != nil {
484 c.AddProperties(c.pgo.props()...)
485 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800486 if c.xom != nil {
487 c.AddProperties(c.xom.props()...)
488 }
Colin Crossca860ac2016-01-04 14:34:37 -0800489 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700490 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800491 }
Colin Crossc472d572015-03-17 15:06:21 -0700492
Colin Crossa9d8bee2018-10-02 13:59:46 -0700493 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
494 switch class {
495 case android.Device:
496 return ctx.Config().DevicePrefer32BitExecutables()
497 case android.HostCross:
498 // Windows builds always prefer 32-bit
499 return true
500 default:
501 return false
502 }
503 })
Colin Cross36242852017-06-23 15:06:31 -0700504 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700505
Colin Cross1f44a3a2017-07-07 14:33:33 -0700506 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700507
Jiyong Park9d452992018-10-03 00:38:19 +0900508 android.InitApexModule(c)
509
Colin Cross36242852017-06-23 15:06:31 -0700510 return c
Colin Crossc472d572015-03-17 15:06:21 -0700511}
512
Colin Crossb916a382016-07-29 17:28:03 -0700513// Returns true for dependency roots (binaries)
514// TODO(ccross): also handle dlopenable libraries
515func (c *Module) isDependencyRoot() bool {
516 if root, ok := c.linker.(interface {
517 isDependencyRoot() bool
518 }); ok {
519 return root.isDependencyRoot()
520 }
521 return false
522}
523
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700524func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700525 return c.Properties.UseVndk
526}
527
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800528func (c *Module) isCoverageVariant() bool {
529 return c.coverage.Properties.IsCoverageVariant
530}
531
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800532func (c *Module) isNdk() bool {
533 return inList(c.Name(), ndkMigratedLibs)
534}
535
Inseob Kim9516ee92019-05-09 10:56:13 +0900536func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800537 // Returns true for both LLNDK (public) and LLNDK-private libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900538 return inList(c.Name(), *llndkLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800539}
540
Inseob Kim9516ee92019-05-09 10:56:13 +0900541func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800542 // Returns true only for LLNDK (public) libs.
Inseob Kim9516ee92019-05-09 10:56:13 +0900543 return c.isLlndk(config) && !c.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800544}
545
Inseob Kim9516ee92019-05-09 10:56:13 +0900546func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800547 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Inseob Kim9516ee92019-05-09 10:56:13 +0900548 return inList(c.Name(), *vndkPrivateLibraries(config))
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800549}
550
Justin Yun8effde42017-06-23 19:24:43 +0900551func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800552 if vndkdep := c.vndkdep; vndkdep != nil {
553 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900554 }
555 return false
556}
557
Jooyung Han76106d92019-05-20 18:49:10 +0900558func (c *Module) vndkVersion() string {
559 if vndkdep := c.vndkdep; vndkdep != nil {
560 return vndkdep.Properties.Vndk.Version
561 }
562 return ""
563}
564
Yi Kong7e53c572018-02-14 18:16:12 +0800565func (c *Module) isPgoCompile() bool {
566 if pgo := c.pgo; pgo != nil {
567 return pgo.Properties.PgoCompile
568 }
569 return false
570}
571
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800572func (c *Module) isNDKStubLibrary() bool {
573 if _, ok := c.compiler.(*stubDecorator); ok {
574 return true
575 }
576 return false
577}
578
Logan Chienf3511742017-10-31 18:04:35 +0800579func (c *Module) isVndkSp() bool {
580 if vndkdep := c.vndkdep; vndkdep != nil {
581 return vndkdep.isVndkSp()
582 }
583 return false
584}
585
586func (c *Module) isVndkExt() bool {
587 if vndkdep := c.vndkdep; vndkdep != nil {
588 return vndkdep.isVndkExt()
589 }
590 return false
591}
592
Vic Yangefd249e2018-11-12 20:19:56 -0800593func (c *Module) mustUseVendorVariant() bool {
594 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
595}
596
Logan Chienf3511742017-10-31 18:04:35 +0800597func (c *Module) getVndkExtendsModuleName() string {
598 if vndkdep := c.vndkdep; vndkdep != nil {
599 return vndkdep.getVndkExtendsModuleName()
600 }
601 return ""
602}
603
Jiyong Park82e2bf32017-08-16 14:05:54 +0900604// Returns true only when this module is configured to have core and vendor
605// variants.
606func (c *Module) hasVendorVariant() bool {
607 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
608}
609
Jiyong Parkf9332f12018-02-01 00:54:12 +0900610func (c *Module) inRecovery() bool {
611 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
612}
613
614func (c *Module) onlyInRecovery() bool {
615 return c.ModuleBase.InstallInRecovery()
616}
617
Jiyong Park25fc6a92018-11-18 18:02:45 +0900618func (c *Module) IsStubs() bool {
619 if library, ok := c.linker.(*libraryDecorator); ok {
620 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900621 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
622 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900623 }
624 return false
625}
626
627func (c *Module) HasStubsVariants() bool {
628 if library, ok := c.linker.(*libraryDecorator); ok {
629 return len(library.Properties.Stubs.Versions) > 0
630 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700631 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
632 return len(library.Properties.Stubs.Versions) > 0
633 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900634 return false
635}
636
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900637func (c *Module) bootstrap() bool {
638 return Bool(c.Properties.Bootstrap)
639}
640
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700641func (c *Module) nativeCoverage() bool {
642 return c.linker != nil && c.linker.nativeCoverage()
643}
644
Jiyong Parkf1194352019-02-25 11:05:47 +0900645func isBionic(name string) bool {
646 switch name {
647 case "libc", "libm", "libdl", "linker":
648 return true
649 }
650 return false
651}
652
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700653func installToBootstrap(name string, config android.Config) bool {
654 if name == "libclang_rt.hwasan-aarch64-android" {
655 return inList("hwaddress", config.SanitizeDevice())
656 }
657 return isBionic(name)
658}
659
Colin Crossca860ac2016-01-04 14:34:37 -0800660type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700661 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800662 moduleContextImpl
663}
664
Colin Cross37047f12016-12-13 17:06:13 -0800665type depsContext struct {
666 android.BottomUpMutatorContext
667 moduleContextImpl
668}
669
Colin Crossca860ac2016-01-04 14:34:37 -0800670type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700671 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800672 moduleContextImpl
673}
674
Jiyong Park2db76922017-11-08 16:03:48 +0900675func (ctx *moduleContext) SocSpecific() bool {
676 return ctx.ModuleContext.SocSpecific() ||
677 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700678}
679
Colin Crossca860ac2016-01-04 14:34:37 -0800680type moduleContextImpl struct {
681 mod *Module
682 ctx BaseModuleContext
683}
684
Colin Crossb98c8b02016-07-29 13:44:28 -0700685func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800686 return ctx.mod.toolchain(ctx.ctx)
687}
688
689func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000690 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800691}
692
693func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900694 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800695}
696
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700697func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800698 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800699 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700700 }
701 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800702}
703
704func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700705 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700706 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900707 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700708 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900709 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
710 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
711 return "current"
712 }
713 return platform_vndk_ver
714 }
715 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800716 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900717 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700718 }
719 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800720}
721
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700722func (ctx *moduleContextImpl) useVndk() bool {
723 return ctx.mod.useVndk()
724}
Justin Yun8effde42017-06-23 19:24:43 +0900725
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800726func (ctx *moduleContextImpl) isNdk() bool {
727 return ctx.mod.isNdk()
728}
729
Inseob Kim9516ee92019-05-09 10:56:13 +0900730func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
731 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800732}
733
Inseob Kim9516ee92019-05-09 10:56:13 +0900734func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
735 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800736}
737
Inseob Kim9516ee92019-05-09 10:56:13 +0900738func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
739 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800740}
741
Logan Chienf3511742017-10-31 18:04:35 +0800742func (ctx *moduleContextImpl) isVndk() bool {
743 return ctx.mod.isVndk()
744}
745
Yi Kong7e53c572018-02-14 18:16:12 +0800746func (ctx *moduleContextImpl) isPgoCompile() bool {
747 return ctx.mod.isPgoCompile()
748}
749
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800750func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
751 return ctx.mod.isNDKStubLibrary()
752}
753
Justin Yun8effde42017-06-23 19:24:43 +0900754func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800755 return ctx.mod.isVndkSp()
756}
757
758func (ctx *moduleContextImpl) isVndkExt() bool {
759 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900760}
761
Vic Yangefd249e2018-11-12 20:19:56 -0800762func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
763 return ctx.mod.mustUseVendorVariant()
764}
765
Jiyong Parkf9332f12018-02-01 00:54:12 +0900766func (ctx *moduleContextImpl) inRecovery() bool {
767 return ctx.mod.inRecovery()
768}
769
Logan Chien2f2b8902018-07-10 15:01:19 +0800770// Check whether ABI dumps should be created for this module.
Inseob Kim9516ee92019-05-09 10:56:13 +0900771func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
Logan Chien2f2b8902018-07-10 15:01:19 +0800772 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
773 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800774 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800775
776 if ctx.ctx.Fuchsia() {
777 return false
778 }
779
Logan Chien2f2b8902018-07-10 15:01:19 +0800780 if sanitize := ctx.mod.sanitize; sanitize != nil {
781 if !sanitize.isVariantOnProductionDevice() {
782 return false
783 }
784 }
785 if !ctx.ctx.Device() {
786 // Host modules do not need ABI dumps.
787 return false
788 }
Logan Chienfa478c02018-12-28 16:25:39 +0800789 if !ctx.mod.IsForPlatform() {
790 // APEX variants do not need ABI dumps.
791 return false
792 }
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +0800793 if ctx.isStubs() {
794 // Stubs do not need ABI dumps.
795 return false
796 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800797 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800798 return true
799 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900800 if ctx.isLlndkPublic(config) {
Logan Chienf4b79c62018-08-02 02:27:02 +0800801 return true
802 }
Inseob Kim9516ee92019-05-09 10:56:13 +0900803 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
Logan Chien2f2b8902018-07-10 15:01:19 +0800804 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
805 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800806 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800807 }
808 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800809}
810
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700811func (ctx *moduleContextImpl) selectedStl() string {
812 if stl := ctx.mod.stl; stl != nil {
813 return stl.Properties.SelectedStl
814 }
815 return ""
816}
817
Ivan Lozanobd721262018-11-27 14:33:03 -0800818func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
819 return ctx.mod.linker.useClangLld(actx)
820}
821
Colin Crossce75d2c2016-10-06 16:12:58 -0700822func (ctx *moduleContextImpl) baseModuleName() string {
823 return ctx.mod.ModuleBase.BaseModuleName()
824}
825
Logan Chienf3511742017-10-31 18:04:35 +0800826func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
827 return ctx.mod.getVndkExtendsModuleName()
828}
829
Jiyong Park58e364a2019-01-19 19:24:06 +0900830func (ctx *moduleContextImpl) apexName() string {
831 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900832}
833
Jiyong Parkb0788572018-12-20 22:10:17 +0900834func (ctx *moduleContextImpl) hasStubsVariants() bool {
835 return ctx.mod.HasStubsVariants()
836}
837
838func (ctx *moduleContextImpl) isStubs() bool {
839 return ctx.mod.IsStubs()
840}
841
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900842func (ctx *moduleContextImpl) bootstrap() bool {
843 return ctx.mod.bootstrap()
844}
845
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700846func (ctx *moduleContextImpl) nativeCoverage() bool {
847 return ctx.mod.nativeCoverage()
848}
849
Colin Cross635c3b02016-05-18 15:37:25 -0700850func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800851 return &Module{
852 hod: hod,
853 multilib: multilib,
854 }
855}
856
Colin Cross635c3b02016-05-18 15:37:25 -0700857func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800858 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700859 module.features = []feature{
860 &tidyFeature{},
861 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700862 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800863 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800864 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800865 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900866 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700867 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700868 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800869 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800870 return module
871}
872
Colin Crossce75d2c2016-10-06 16:12:58 -0700873func (c *Module) Prebuilt() *android.Prebuilt {
874 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
875 return p.prebuilt()
876 }
877 return nil
878}
879
880func (c *Module) Name() string {
881 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700882 if p, ok := c.linker.(interface {
883 Name(string) string
884 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700885 name = p.Name(name)
886 }
887 return name
888}
889
Alex Light3d673592019-01-18 14:37:31 -0800890func (c *Module) Symlinks() []string {
891 if p, ok := c.installer.(interface {
892 symlinkList() []string
893 }); ok {
894 return p.symlinkList()
895 }
896 return nil
897}
898
Jeff Gaston294356f2017-09-27 17:05:30 -0700899// orderDeps reorders dependencies into a list such that if module A depends on B, then
900// A will precede B in the resultant list.
901// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800902// Note that directSharedDeps should be the analogous static library for each shared lib dep
903func 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 -0700904 // If A depends on B, then
905 // Every list containing A will also contain B later in the list
906 // So, after concatenating all lists, the final instance of B will have come from the same
907 // original list as the final instance of A
908 // So, the final instance of B will be later in the concatenation than the final A
909 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
910 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800911 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700912 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800913 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
914 }
915 for _, dep := range directSharedDeps {
916 orderedAllDeps = append(orderedAllDeps, dep)
917 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700918 }
919
Colin Crossb6715442017-10-24 11:13:31 -0700920 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700921
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800922 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700923 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800924 // resultant list to only what the caller has chosen to include in directStaticDeps
925 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700926
927 return orderedAllDeps, orderedDeclaredDeps
928}
929
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800930func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
931 // convert Module to Path
932 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
933 staticDepFiles := []android.Path{}
934 for _, dep := range staticDeps {
935 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
936 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700937 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800938 sharedDepFiles := []android.Path{}
939 for _, sharedDep := range sharedDeps {
940 staticAnalogue := sharedDep.staticVariant
941 if staticAnalogue != nil {
942 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
943 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
944 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700945 }
946
947 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800948 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700949
950 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700951}
952
Colin Cross635c3b02016-05-18 15:37:25 -0700953func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +0100954 // Handle the case of a test module split by `test_per_src` mutator.
955 if test, ok := c.linker.(testPerSrc); ok {
956 // The `test_per_src` mutator adds an extra variant named "", depending on all the
957 // other `test_per_src` variants of the test module. Collect the output files of
958 // these dependencies and record them in the `testPerSrcOutputFiles` for later use
959 // (see e.g. `apexBundle.GenerateAndroidBuildActions`).
960 if test.isAllTestsVariation() {
961 var testPerSrcOutputFiles []android.Path
962 for _, dep := range actx.GetDirectDepsWithTag(testPerSrcDepTag) {
963 if ccDep, ok := dep.(*Module); ok {
964 depOutputFile := ccDep.OutputFile().Path()
965 testPerSrcOutputFiles =
966 append(testPerSrcOutputFiles, depOutputFile)
967 }
968 }
969 c.testPerSrcOutputFiles = testPerSrcOutputFiles
970 // Set outputFile to an empty path, as this module does not produce an
971 // output file per se.
972 c.outputFile = android.OptionalPath{}
973 return
974 }
975 }
976
Jooyung Han38002912019-05-16 04:01:54 +0900977 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +0900978
Colin Crossca860ac2016-01-04 14:34:37 -0800979 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700980 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800981 moduleContextImpl: moduleContextImpl{
982 mod: c,
983 },
984 }
985 ctx.ctx = ctx
986
Colin Crossf18e1102017-11-16 14:33:08 -0800987 deps := c.depsToPaths(ctx)
988 if ctx.Failed() {
989 return
990 }
991
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700992 if c.Properties.Clang != nil && *c.Properties.Clang == false {
993 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
994 }
995
Colin Crossca860ac2016-01-04 14:34:37 -0800996 flags := Flags{
997 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800998 }
Colin Crossca860ac2016-01-04 14:34:37 -0800999 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001000 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001001 }
1002 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001003 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001004 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001005 if c.stl != nil {
1006 flags = c.stl.flags(ctx, flags)
1007 }
Colin Cross16b23492016-01-06 14:41:07 -08001008 if c.sanitize != nil {
1009 flags = c.sanitize.flags(ctx, flags)
1010 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001011 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001012 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001013 }
Stephen Craneba090d12017-05-09 15:44:35 -07001014 if c.lto != nil {
1015 flags = c.lto.flags(ctx, flags)
1016 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001017 if c.pgo != nil {
1018 flags = c.pgo.flags(ctx, flags)
1019 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001020 if c.xom != nil {
1021 flags = c.xom.flags(ctx, flags)
1022 }
Colin Crossca860ac2016-01-04 14:34:37 -08001023 for _, feature := range c.features {
1024 flags = feature.flags(ctx, flags)
1025 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001026 if ctx.Failed() {
1027 return
1028 }
1029
Colin Crossb98c8b02016-07-29 13:44:28 -07001030 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
1031 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
1032 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001033
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001034 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001035
1036 for _, dir := range deps.IncludeDirs {
1037 flags.GlobalFlags = append(flags.GlobalFlags, "-I"+dir)
1038 }
1039 for _, dir := range deps.SystemIncludeDirs {
1040 flags.GlobalFlags = append(flags.GlobalFlags, "-isystem "+dir)
1041 }
1042
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001043 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001044 // We need access to all the flags seen by a source file.
1045 if c.sabi != nil {
1046 flags = c.sabi.flags(ctx, flags)
1047 }
Colin Crossca860ac2016-01-04 14:34:37 -08001048 // Optimization to reduce size of build.ninja
1049 // Replace the long list of flags for each file with a module-local variable
1050 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
1051 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
1052 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
1053 flags.CFlags = []string{"$cflags"}
1054 flags.CppFlags = []string{"$cppflags"}
1055 flags.AsFlags = []string{"$asflags"}
1056
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001057 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001058 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001059 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001060 if ctx.Failed() {
1061 return
1062 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001063 }
1064
Colin Crossca860ac2016-01-04 14:34:37 -08001065 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001066 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001067 if ctx.Failed() {
1068 return
1069 }
Colin Cross635c3b02016-05-18 15:37:25 -07001070 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001071
1072 // If a lib is directly included in any of the APEXes, unhide the stubs
1073 // variant having the latest version gets visible to make. In addition,
1074 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1075 // force anything in the make world to link against the stubs library.
1076 // (unless it is explicitly referenced via .bootstrap suffix or the
1077 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001078 if c.HasStubsVariants() &&
1079 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001080 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1081 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001082 c.Properties.HideFromMake = false // unhide
1083 // Note: this is still non-installable
1084 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001085 }
Colin Cross5049f022015-03-18 13:28:46 -07001086
Inseob Kim1f086e22019-05-09 13:29:15 +09001087 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001088 c.installer.install(ctx, c.outputFile.Path())
1089 if ctx.Failed() {
1090 return
Colin Crossca860ac2016-01-04 14:34:37 -08001091 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001092 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001093}
1094
Colin Cross0ea8ba82019-06-06 14:33:29 -07001095func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001096 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001097 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001098 }
Colin Crossca860ac2016-01-04 14:34:37 -08001099 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001100}
1101
Colin Crossca860ac2016-01-04 14:34:37 -08001102func (c *Module) begin(ctx BaseModuleContext) {
1103 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001104 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001105 }
Colin Crossca860ac2016-01-04 14:34:37 -08001106 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001107 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001108 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001109 if c.stl != nil {
1110 c.stl.begin(ctx)
1111 }
Colin Cross16b23492016-01-06 14:41:07 -08001112 if c.sanitize != nil {
1113 c.sanitize.begin(ctx)
1114 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001115 if c.coverage != nil {
1116 c.coverage.begin(ctx)
1117 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001118 if c.sabi != nil {
1119 c.sabi.begin(ctx)
1120 }
Justin Yun8effde42017-06-23 19:24:43 +09001121 if c.vndkdep != nil {
1122 c.vndkdep.begin(ctx)
1123 }
Stephen Craneba090d12017-05-09 15:44:35 -07001124 if c.lto != nil {
1125 c.lto.begin(ctx)
1126 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001127 if c.pgo != nil {
1128 c.pgo.begin(ctx)
1129 }
Colin Crossca860ac2016-01-04 14:34:37 -08001130 for _, feature := range c.features {
1131 feature.begin(ctx)
1132 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001133 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001134 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001135 if err != nil {
1136 ctx.PropertyErrorf("sdk_version", err.Error())
1137 }
Nan Zhang0007d812017-11-07 10:57:05 -08001138 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001139 }
Colin Crossca860ac2016-01-04 14:34:37 -08001140}
1141
Colin Cross37047f12016-12-13 17:06:13 -08001142func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001143 deps := Deps{}
1144
1145 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001146 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001147 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001148 // Add the PGO dependency (the clang_rt.profile runtime library), which
1149 // sometimes depends on symbols from libgcc, before libgcc gets added
1150 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001151 if c.pgo != nil {
1152 deps = c.pgo.deps(ctx, deps)
1153 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001154 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001155 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001156 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001157 if c.stl != nil {
1158 deps = c.stl.deps(ctx, deps)
1159 }
Colin Cross16b23492016-01-06 14:41:07 -08001160 if c.sanitize != nil {
1161 deps = c.sanitize.deps(ctx, deps)
1162 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001163 if c.coverage != nil {
1164 deps = c.coverage.deps(ctx, deps)
1165 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001166 if c.sabi != nil {
1167 deps = c.sabi.deps(ctx, deps)
1168 }
Justin Yun8effde42017-06-23 19:24:43 +09001169 if c.vndkdep != nil {
1170 deps = c.vndkdep.deps(ctx, deps)
1171 }
Stephen Craneba090d12017-05-09 15:44:35 -07001172 if c.lto != nil {
1173 deps = c.lto.deps(ctx, deps)
1174 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001175 for _, feature := range c.features {
1176 deps = feature.deps(ctx, deps)
1177 }
1178
Colin Crossb6715442017-10-24 11:13:31 -07001179 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1180 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1181 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1182 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1183 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1184 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001185 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001186
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001187 for _, lib := range deps.ReexportSharedLibHeaders {
1188 if !inList(lib, deps.SharedLibs) {
1189 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1190 }
1191 }
1192
1193 for _, lib := range deps.ReexportStaticLibHeaders {
1194 if !inList(lib, deps.StaticLibs) {
1195 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1196 }
1197 }
1198
Colin Cross5950f382016-12-13 12:50:57 -08001199 for _, lib := range deps.ReexportHeaderLibHeaders {
1200 if !inList(lib, deps.HeaderLibs) {
1201 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1202 }
1203 }
1204
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001205 for _, gen := range deps.ReexportGeneratedHeaders {
1206 if !inList(gen, deps.GeneratedHeaders) {
1207 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1208 }
1209 }
1210
Colin Crossc99deeb2016-04-11 15:06:20 -07001211 return deps
1212}
1213
Dan Albert7e9d2952016-08-04 13:02:36 -07001214func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001215 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001216 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001217 moduleContextImpl: moduleContextImpl{
1218 mod: c,
1219 },
1220 }
1221 ctx.ctx = ctx
1222
Colin Crossca860ac2016-01-04 14:34:37 -08001223 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001224}
1225
Jiyong Park7ed9de32018-10-15 22:25:07 +09001226// Split name#version into name and version
1227func stubsLibNameAndVersion(name string) (string, string) {
1228 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1229 version := name[sharp+1:]
1230 libname := name[:sharp]
1231 return libname, version
1232 }
1233 return name, ""
1234}
1235
Colin Cross1e676be2016-10-12 14:38:15 -07001236func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001237 ctx := &depsContext{
1238 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001239 moduleContextImpl: moduleContextImpl{
1240 mod: c,
1241 },
1242 }
1243 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001244
Colin Crossc99deeb2016-04-11 15:06:20 -07001245 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001246
Dan Albert914449f2016-06-17 16:45:24 -07001247 variantNdkLibs := []string{}
1248 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001249 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001250 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001251
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001252 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1253 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001254 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001255 // 1. Name of an NDK library that refers to a prebuilt module.
1256 // For each of these, it adds the name of the prebuilt module (which will be in
1257 // prebuilts/ndk) to the list of nonvariant libs.
1258 // 2. Name of an NDK library that refers to an ndk_library module.
1259 // For each of these, it adds the name of the ndk_library module to the list of
1260 // variant libs.
1261 // 3. Anything else (so anything that isn't an NDK library).
1262 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001263 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001264 // The caller can then know to add the variantLibs dependencies differently from the
1265 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001266
1267 llndkLibraries := llndkLibraries(actx.Config())
1268 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001269 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1270 variantLibs = []string{}
1271 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001272 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001273 // strip #version suffix out
1274 name, _ := stubsLibNameAndVersion(entry)
1275 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1276 if !inList(name, ndkMigratedLibs) {
1277 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001278 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001279 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001280 }
Inseob Kim9516ee92019-05-09 10:56:13 +09001281 } else if ctx.useVndk() && inList(name, *llndkLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001282 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001283 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001284 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001285 if actx.OtherModuleExists(vendorPublicLib) {
1286 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1287 } else {
1288 // This can happen if vendor_public_library module is defined in a
1289 // namespace that isn't visible to the current module. In that case,
1290 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001291 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001292 }
Dan Albert914449f2016-06-17 16:45:24 -07001293 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001294 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001295 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001296 }
1297 }
Dan Albert914449f2016-06-17 16:45:24 -07001298 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001299 }
1300
Dan Albert914449f2016-06-17 16:45:24 -07001301 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1302 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001303 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001304 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001305
Jiyong Park7e636d02019-01-28 16:16:54 +09001306 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001307 if c.linker != nil {
1308 if library, ok := c.linker.(*libraryDecorator); ok {
1309 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001310 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001311 }
1312 }
1313 }
1314
Colin Cross32ec36c2016-12-15 07:39:51 -08001315 for _, lib := range deps.HeaderLibs {
1316 depTag := headerDepTag
1317 if inList(lib, deps.ReexportHeaderLibHeaders) {
1318 depTag = headerExportDepTag
1319 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001320 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001321 actx.AddFarVariationDependencies([]blueprint.Variation{
1322 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001323 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001324 }, depTag, lib)
1325 } else {
1326 actx.AddVariationDependencies(nil, depTag, lib)
1327 }
1328 }
1329
1330 if buildStubs {
1331 // Stubs lib does not have dependency to other static/shared libraries.
1332 // Don't proceed.
1333 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001334 }
Colin Cross5950f382016-12-13 12:50:57 -08001335
Inseob Kimc0907f12019-02-08 21:00:45 +09001336 syspropImplLibraries := syspropImplLibraries(actx.Config())
1337
Jiyong Park5d1598f2019-02-25 22:14:17 +09001338 for _, lib := range deps.WholeStaticLibs {
1339 depTag := wholeStaticDepTag
1340 if impl, ok := syspropImplLibraries[lib]; ok {
1341 lib = impl
1342 }
1343 actx.AddVariationDependencies([]blueprint.Variation{
1344 {Mutator: "link", Variation: "static"},
1345 }, depTag, lib)
1346 }
1347
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001348 for _, lib := range deps.StaticLibs {
1349 depTag := staticDepTag
1350 if inList(lib, deps.ReexportStaticLibHeaders) {
1351 depTag = staticExportDepTag
1352 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001353
1354 if impl, ok := syspropImplLibraries[lib]; ok {
1355 lib = impl
1356 }
1357
Dan Willemsen59339a22018-07-22 21:18:45 -07001358 actx.AddVariationDependencies([]blueprint.Variation{
1359 {Mutator: "link", Variation: "static"},
1360 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001361 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001362
Dan Willemsen59339a22018-07-22 21:18:45 -07001363 actx.AddVariationDependencies([]blueprint.Variation{
1364 {Mutator: "link", Variation: "static"},
1365 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001366
Jiyong Park25fc6a92018-11-18 18:02:45 +09001367 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1368 var variations []blueprint.Variation
1369 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001370 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001371 if version != "" && versionVariantAvail {
1372 // Version is explicitly specified. i.e. libFoo#30
1373 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1374 depTag.explicitlyVersioned = true
1375 }
1376 actx.AddVariationDependencies(variations, depTag, name)
1377
1378 // If the version is not specified, add dependency to the latest stubs library.
1379 // The stubs library will be used when the depending module is built for APEX and
1380 // the dependent module is not in the same APEX.
1381 latestVersion := latestStubsVersionFor(actx.Config(), name)
1382 if version == "" && latestVersion != "" && versionVariantAvail {
1383 actx.AddVariationDependencies([]blueprint.Variation{
1384 {Mutator: "link", Variation: "shared"},
1385 {Mutator: "version", Variation: latestVersion},
1386 }, depTag, name)
1387 // Note that depTag.explicitlyVersioned is false in this case.
1388 }
1389 }
1390
Jiyong Park7ed9de32018-10-15 22:25:07 +09001391 // shared lib names without the #version suffix
1392 var sharedLibNames []string
1393
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001394 for _, lib := range deps.SharedLibs {
1395 depTag := sharedDepTag
1396 if inList(lib, deps.ReexportSharedLibHeaders) {
1397 depTag = sharedExportDepTag
1398 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001399
1400 if impl, ok := syspropImplLibraries[lib]; ok {
1401 lib = impl
1402 }
1403
1404 name, version := stubsLibNameAndVersion(lib)
1405 sharedLibNames = append(sharedLibNames, name)
1406
Jiyong Park25fc6a92018-11-18 18:02:45 +09001407 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001408 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001409
Jiyong Park7ed9de32018-10-15 22:25:07 +09001410 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001411 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001412 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1413 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1414 // linking against both the stubs lib and the non-stubs lib at the same time.
1415 continue
1416 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001417 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001418 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001419
Dan Willemsen59339a22018-07-22 21:18:45 -07001420 actx.AddVariationDependencies([]blueprint.Variation{
1421 {Mutator: "link", Variation: "shared"},
1422 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001423
Colin Cross68861832016-07-08 10:41:41 -07001424 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001425
1426 for _, gen := range deps.GeneratedHeaders {
1427 depTag := genHeaderDepTag
1428 if inList(gen, deps.ReexportGeneratedHeaders) {
1429 depTag = genHeaderExportDepTag
1430 }
1431 actx.AddDependency(c, depTag, gen)
1432 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001433
Colin Cross42d48b72018-08-29 14:10:52 -07001434 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001435
1436 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001437 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001438 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001439 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001440 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001441 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001442 if deps.LinkerFlagsFile != "" {
1443 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1444 }
1445 if deps.DynamicLinker != "" {
1446 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001447 }
Dan Albert914449f2016-06-17 16:45:24 -07001448
1449 version := ctx.sdkVersion()
1450 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001451 {Mutator: "ndk_api", Variation: version},
1452 {Mutator: "link", Variation: "shared"},
1453 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001454 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001455 {Mutator: "ndk_api", Variation: version},
1456 {Mutator: "link", Variation: "shared"},
1457 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001458
1459 if vndkdep := c.vndkdep; vndkdep != nil {
1460 if vndkdep.isVndkExt() {
1461 baseModuleMode := vendorMode
1462 if actx.DeviceConfig().VndkVersion() == "" {
1463 baseModuleMode = coreMode
1464 }
1465 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001466 {Mutator: "image", Variation: baseModuleMode},
1467 {Mutator: "link", Variation: "shared"},
1468 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001469 }
1470 }
Colin Cross6362e272015-10-29 15:25:03 -07001471}
Colin Cross21b9a242015-03-24 14:15:58 -07001472
Colin Crosse40b4ea2018-10-02 22:25:58 -07001473func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001474 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1475 c.beginMutator(ctx)
1476 }
1477}
1478
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001479// Whether a module can link to another module, taking into
1480// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001481func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001482 if from.Target().Os != android.Android {
1483 // Host code is not restricted
1484 return
1485 }
1486 if from.Properties.UseVndk {
1487 // Though vendor code is limited by the vendor mutator,
1488 // each vendor-available module needs to check
1489 // link-type for VNDK.
1490 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001491 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001492 }
1493 return
1494 }
Nan Zhang0007d812017-11-07 10:57:05 -08001495 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001496 // Platform code can link to anything
1497 return
1498 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001499 if from.inRecovery() {
1500 // Recovery code is not NDK
1501 return
1502 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001503 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1504 // These are always allowed
1505 return
1506 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001507 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1508 // These are allowed, but they don't set sdk_version
1509 return
1510 }
1511 if _, ok := to.linker.(*stubDecorator); ok {
1512 // These aren't real libraries, but are the stub shared libraries that are included in
1513 // the NDK.
1514 return
1515 }
Logan Chien834b9a62019-01-14 15:39:03 +08001516
1517 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1518 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1519 // to link to libc++ (non-NDK and without sdk_version).
1520 return
1521 }
1522
Nan Zhang0007d812017-11-07 10:57:05 -08001523 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001524 // NDK code linking to platform code is never okay.
1525 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1526 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001527 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001528 }
1529
1530 // At this point we know we have two NDK libraries, but we need to
1531 // check that we're not linking against anything built against a higher
1532 // API level, as it is only valid to link against older or equivalent
1533 // APIs.
1534
Inseob Kim01a28722018-04-11 09:48:45 +09001535 // Current can link against anything.
1536 if String(from.Properties.Sdk_version) != "current" {
1537 // Otherwise we need to check.
1538 if String(to.Properties.Sdk_version) == "current" {
1539 // Current can't be linked against by anything else.
1540 ctx.ModuleErrorf("links %q built against newer API version %q",
1541 ctx.OtherModuleName(to), "current")
1542 } else {
1543 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1544 if err != nil {
1545 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001546 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001547 String(from.Properties.Sdk_version))
1548 }
1549 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1550 if err != nil {
1551 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001552 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001553 String(to.Properties.Sdk_version))
1554 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001555
Inseob Kim01a28722018-04-11 09:48:45 +09001556 if toApi > fromApi {
1557 ctx.ModuleErrorf("links %q built against newer API version %q",
1558 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1559 }
1560 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001561 }
Dan Albert202fe492017-12-15 13:56:59 -08001562
1563 // Also check that the two STL choices are compatible.
1564 fromStl := from.stl.Properties.SelectedStl
1565 toStl := to.stl.Properties.SelectedStl
1566 if fromStl == "" || toStl == "" {
1567 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001568 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001569 // We can be permissive with the system "STL" since it is only the C++
1570 // ABI layer, but in the future we should make sure that everyone is
1571 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001572 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001573 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1574 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1575 to.stl.Properties.SelectedStl)
1576 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001577}
1578
Jiyong Park5fb8c102018-04-09 12:03:06 +09001579// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001580// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1581// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001582// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001583func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
Inseob Kim9516ee92019-05-09 10:56:13 +09001584 llndkLibraries := llndkLibraries(ctx.Config())
Jooyung Hana70f0672019-01-18 15:20:43 +09001585 check := func(child, parent android.Module) bool {
1586 to, ok := child.(*Module)
1587 if !ok {
1588 // follow thru cc.Defaults, etc.
1589 return true
1590 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001591
Jooyung Hana70f0672019-01-18 15:20:43 +09001592 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1593 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001594 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001595
1596 // if target lib has no vendor variant, keep checking dependency graph
1597 if !to.hasVendorVariant() {
1598 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001599 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001600
Inseob Kim9516ee92019-05-09 10:56:13 +09001601 if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001602 return false
1603 }
1604
1605 var stringPath []string
1606 for _, m := range ctx.GetWalkPath() {
1607 stringPath = append(stringPath, m.Name())
1608 }
1609 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1610 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1611 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1612 return false
1613 }
1614 if module, ok := ctx.Module().(*Module); ok {
1615 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Inseob Kim9516ee92019-05-09 10:56:13 +09001616 if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001617 ctx.WalkDeps(check)
1618 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001619 }
1620 }
1621}
1622
Colin Crossc99deeb2016-04-11 15:06:20 -07001623// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001624func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001625 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001626
Jeff Gaston294356f2017-09-27 17:05:30 -07001627 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001628 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001629
Inseob Kim9516ee92019-05-09 10:56:13 +09001630 llndkLibraries := llndkLibraries(ctx.Config())
1631 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
1632
Inseob Kim69378442019-06-03 19:10:47 +09001633 reexportExporter := func(exporter exportedFlagsProducer) {
1634 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
1635 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
1636 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
1637 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
1638 }
1639
Colin Crossd11fcda2017-10-23 17:59:01 -07001640 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001641 depName := ctx.OtherModuleName(dep)
1642 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001643
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001644 ccDep, _ := dep.(*Module)
1645 if ccDep == nil {
1646 // handling for a few module types that aren't cc Module but that are also supported
1647 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001648 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001649 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001650 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1651 genRule.GeneratedSourceFiles()...)
1652 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001653 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001654 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001655 // Support exported headers from a generated_sources dependency
1656 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001657 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001658 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001659 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001660 genRule.GeneratedDeps()...)
Inseob Kim69378442019-06-03 19:10:47 +09001661 dirs := genRule.GeneratedHeaderDirs().Strings()
1662 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001663 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09001664 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
1665 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001666 // 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 +09001667 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001668
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001669 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001670 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001671 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001672 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001673 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001674 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001675 files := genRule.GeneratedSourceFiles()
1676 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001677 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001678 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001679 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 -07001680 }
1681 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001682 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001683 }
Colin Crossca860ac2016-01-04 14:34:37 -08001684 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001685 return
1686 }
1687
Colin Crossfe17f6f2019-03-28 19:30:56 -07001688 if depTag == android.ProtoPluginDepTag {
1689 return
1690 }
1691
Colin Crossd11fcda2017-10-23 17:59:01 -07001692 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001693 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1694 return
1695 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001696 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001697 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001698 return
1699 }
1700
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001701 // re-exporting flags
1702 if depTag == reuseObjTag {
1703 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001704 c.staticVariant = ccDep
Inseob Kim69378442019-06-03 19:10:47 +09001705 objs, exporter := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001706 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09001707 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08001708 return
1709 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001710 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001711
Jiyong Parke4bb9862019-02-01 00:31:10 +09001712 if depTag == staticVariantTag {
1713 if _, ok := ccDep.compiler.(libraryInterface); ok {
1714 c.staticVariant = ccDep
1715 return
1716 }
1717 }
1718
Jiyong Park25fc6a92018-11-18 18:02:45 +09001719 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1720 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1721 // won't be matched to sharedDepTag and lateSharedDepTag.
1722 explicitlyVersioned := false
1723 if t, ok := depTag.(dependencyTag); ok {
1724 explicitlyVersioned = t.explicitlyVersioned
1725 t.explicitlyVersioned = false
1726 depTag = t
1727 }
1728
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001729 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001730 depIsStatic := false
1731 switch depTag {
1732 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1733 depIsStatic = true
1734 }
1735 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001736 depIsStubs := dependentLibrary.buildStubs()
1737 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001738 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001739 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001740
1741 var useThisDep bool
1742 if depIsStubs && explicitlyVersioned {
1743 // Always respect dependency to the versioned stubs (i.e. libX#10)
1744 useThisDep = true
1745 } else if !depHasStubs {
1746 // Use non-stub variant if that is the only choice
1747 // (i.e. depending on a lib without stubs.version property)
1748 useThisDep = true
1749 } else if c.IsForPlatform() {
1750 // If not building for APEX, use stubs only when it is from
1751 // an APEX (and not from platform)
1752 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001753 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001754 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001755 // always link to non-stub variant
1756 useThisDep = !depIsStubs
1757 }
1758 } else {
1759 // If building for APEX, use stubs only when it is not from
1760 // the same APEX
1761 useThisDep = (depInSameApex != depIsStubs)
1762 }
1763
1764 if !useThisDep {
1765 return // stop processing this dep
1766 }
1767 }
1768
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001769 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Inseob Kim69378442019-06-03 19:10:47 +09001770 depPaths.IncludeDirs = append(depPaths.IncludeDirs, i.exportedDirs()...)
1771 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
1772 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedDeps()...)
1773 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001774
1775 if t.reexportFlags {
Inseob Kim69378442019-06-03 19:10:47 +09001776 reexportExporter(i)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001777 // 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 -07001778 // Re-exported shared library headers must be included as well since they can help us with type information
1779 // about template instantiations (instantiated from their headers).
Inseob Kim69378442019-06-03 19:10:47 +09001780 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
1781 // scripts.
1782 c.sabi.Properties.ReexportedIncludes = append(
1783 c.sabi.Properties.ReexportedIncludes, i.exportedDirs()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001784 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001785 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001786
Logan Chienf3511742017-10-31 18:04:35 +08001787 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001788 }
1789
Colin Cross26c34ed2016-09-30 17:10:16 -07001790 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001791 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001792
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001793 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001794 depFile := android.OptionalPath{}
1795
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001796 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001797 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001798 ptr = &depPaths.SharedLibs
1799 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001800 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001801 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001802 case earlySharedDepTag:
1803 ptr = &depPaths.EarlySharedLibs
1804 depPtr = &depPaths.EarlySharedLibsDeps
1805 depFile = ccDep.linker.(libraryInterface).toc()
1806 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001807 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001808 ptr = &depPaths.LateSharedLibs
1809 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001810 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001811 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001812 ptr = nil
1813 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001814 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001815 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001816 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001817 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001818 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001819 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001820 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001821 return
1822 }
1823
1824 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001825 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001826 for i := range missingDeps {
1827 missingDeps[i] += postfix
1828 }
1829 ctx.AddMissingDependencies(missingDeps)
1830 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001831 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001832 case headerDepTag:
1833 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001834 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001835 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001836 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001837 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001838 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001839 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001840 case dynamicLinkerDepTag:
1841 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001842 }
1843
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001844 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001845 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001846 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001847 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001848 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001849 return
1850 }
1851
1852 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001853 // in static libraries act as if they were whole static libraries. The same goes for
1854 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001855 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1856 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001857 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1858 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001859
Dan Willemsen581341d2017-02-09 16:16:31 -08001860 }
1861
Colin Cross26c34ed2016-09-30 17:10:16 -07001862 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001863 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001864 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001865 return
1866 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001867 *ptr = append(*ptr, linkFile.Path())
1868 }
1869
Colin Crossc99deeb2016-04-11 15:06:20 -07001870 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001871 dep := depFile
1872 if !dep.Valid() {
1873 dep = linkFile
1874 }
1875 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001876 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001877
Logan Chien43d34c32017-12-20 01:17:32 +08001878 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001879 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001880 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001881 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kim9516ee92019-05-09 10:56:13 +09001882 isLLndk := inList(libName, *llndkLibraries)
1883 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001884 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001885
1886 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1887 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1888 // core module instead.
1889 return libName
1890 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001891 // The vendor module in Make will have been renamed to not conflict with the core
1892 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001893 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001894 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001895 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001896 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1897 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001898 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02001899 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001900 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001901 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001902 }
Logan Chien43d34c32017-12-20 01:17:32 +08001903 }
1904
1905 // Export the shared libs to Make.
1906 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001907 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001908 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001909 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001910 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001911 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001912 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001913 c.Properties.ApexesProvidingSharedLibs = append(
1914 c.Properties.ApexesProvidingSharedLibs, an)
1915 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001916 }
1917 }
1918
Jiyong Park27b188b2017-07-18 13:23:39 +09001919 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001920 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001921 c.Properties.AndroidMkSharedLibs = append(
1922 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001923 case ndkStubDepTag, ndkLateStubDepTag:
1924 ndkStub := ccDep.linker.(*stubDecorator)
1925 c.Properties.AndroidMkSharedLibs = append(
1926 c.Properties.AndroidMkSharedLibs,
1927 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001928 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1929 c.Properties.AndroidMkStaticLibs = append(
1930 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001931 case runtimeDepTag:
1932 c.Properties.AndroidMkRuntimeLibs = append(
1933 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001934 case wholeStaticDepTag:
1935 c.Properties.AndroidMkWholeStaticLibs = append(
1936 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001937 }
Colin Crossca860ac2016-01-04 14:34:37 -08001938 })
1939
Jeff Gaston294356f2017-09-27 17:05:30 -07001940 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001941 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001942
Colin Crossdd84e052017-05-17 13:44:16 -07001943 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001944 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Inseob Kim69378442019-06-03 19:10:47 +09001945 depPaths.IncludeDirs = android.FirstUniqueStrings(depPaths.IncludeDirs)
1946 depPaths.SystemIncludeDirs = android.FirstUniqueStrings(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001947 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kim69378442019-06-03 19:10:47 +09001948 depPaths.ReexportedDirs = android.FirstUniqueStrings(depPaths.ReexportedDirs)
1949 depPaths.ReexportedSystemDirs = android.FirstUniqueStrings(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07001950 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09001951 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001952
1953 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09001954 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001955 }
Colin Crossdd84e052017-05-17 13:44:16 -07001956
Colin Crossca860ac2016-01-04 14:34:37 -08001957 return depPaths
1958}
1959
1960func (c *Module) InstallInData() bool {
1961 if c.installer == nil {
1962 return false
1963 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001964 return c.installer.inData()
1965}
1966
1967func (c *Module) InstallInSanitizerDir() bool {
1968 if c.installer == nil {
1969 return false
1970 }
1971 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001972 return true
1973 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001974 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001975}
1976
Jiyong Parkf9332f12018-02-01 00:54:12 +09001977func (c *Module) InstallInRecovery() bool {
1978 return c.inRecovery()
1979}
1980
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001981func (c *Module) HostToolPath() android.OptionalPath {
1982 if c.installer == nil {
1983 return android.OptionalPath{}
1984 }
1985 return c.installer.hostToolPath()
1986}
1987
Nan Zhangd4e641b2017-07-12 12:55:28 -07001988func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1989 return c.outputFile
1990}
1991
Colin Cross41955e82019-05-29 14:40:35 -07001992func (c *Module) OutputFiles(tag string) (android.Paths, error) {
1993 switch tag {
1994 case "":
1995 if c.outputFile.Valid() {
1996 return android.Paths{c.outputFile.Path()}, nil
1997 }
1998 return android.Paths{}, nil
1999 default:
2000 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002001 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002002}
2003
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002004func (c *Module) static() bool {
2005 if static, ok := c.linker.(interface {
2006 static() bool
2007 }); ok {
2008 return static.static()
2009 }
2010 return false
2011}
2012
Jiyong Park379de2f2018-12-19 02:47:14 +09002013func (c *Module) staticBinary() bool {
2014 if static, ok := c.linker.(interface {
2015 staticBinary() bool
2016 }); ok {
2017 return static.staticBinary()
2018 }
2019 return false
2020}
2021
Jooyung Han38002912019-05-16 04:01:54 +09002022func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
2023 name := actx.ModuleName()
Colin Crossb60190a2018-09-04 16:28:17 -07002024 if c.useVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002025 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2026 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002027 return "native:vndk"
2028 }
Jooyung Han38002912019-05-16 04:01:54 +09002029 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002030 }
Jooyung Han38002912019-05-16 04:01:54 +09002031 if c.isVndk() && !c.isVndkExt() {
2032 if Bool(c.VendorProperties.Vendor_available) {
2033 return "native:vndk"
2034 }
2035 return "native:vndk_private"
2036 }
2037 return "native:vendor"
Colin Crossb60190a2018-09-04 16:28:17 -07002038 } else if c.inRecovery() {
2039 return "native:recovery"
2040 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2041 return "native:ndk:none:none"
2042 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2043 //family, link := getNdkStlFamilyAndLinkType(c)
2044 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Jooyung Han38002912019-05-16 04:01:54 +09002045 } else if inList(name, *vndkUsingCoreVariantLibraries(actx.Config())) {
Vic Yangefd249e2018-11-12 20:19:56 -08002046 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002047 } else {
2048 return "native:platform"
2049 }
2050}
2051
Jiyong Park9d452992018-10-03 00:38:19 +09002052// Overrides ApexModule.IsInstallabeToApex()
2053// Only shared libraries are installable to APEX.
2054func (c *Module) IsInstallableToApex() bool {
2055 if shared, ok := c.linker.(interface {
2056 shared() bool
2057 }); ok {
2058 return shared.shared()
2059 }
2060 return false
2061}
2062
Inseob Kim1f086e22019-05-09 13:29:15 +09002063func (c *Module) installable() bool {
2064 return c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid()
2065}
2066
Jiyong Park3b1746a2019-01-29 11:15:04 +09002067func (c *Module) imageVariation() string {
2068 variation := "core"
2069 if c.useVndk() {
2070 variation = "vendor"
2071 } else if c.inRecovery() {
2072 variation = "recovery"
2073 }
2074 return variation
2075}
2076
bralee3f49f4d2019-03-04 06:58:15 +08002077func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
Colin Cross41955e82019-05-29 14:40:35 -07002078 outputFiles, err := c.OutputFiles("")
2079 if err != nil {
2080 panic(err)
2081 }
2082 dpInfo.Srcs = append(dpInfo.Srcs, outputFiles.Strings()...)
bralee3f49f4d2019-03-04 06:58:15 +08002083}
2084
Logan Chien41eabe62019-04-10 13:33:58 +08002085func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2086 if c.linker != nil {
2087 if library, ok := c.linker.(*libraryDecorator); ok {
2088 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2089 }
2090 }
2091}
2092
Colin Cross2ba19d92015-05-07 15:44:20 -07002093//
Colin Crosscfad1192015-11-02 16:43:11 -08002094// Defaults
2095//
Colin Crossca860ac2016-01-04 14:34:37 -08002096type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002097 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002098 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002099 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002100}
2101
Patrice Arrudac249c712019-03-19 17:00:29 -07002102// cc_defaults provides a set of properties that can be inherited by other cc
2103// modules. A module can use the properties from a cc_defaults using
2104// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2105// merged (when possible) by prepending the default module's values to the
2106// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002107func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002108 return DefaultsFactory()
2109}
2110
Colin Cross36242852017-06-23 15:06:31 -07002111func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002112 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002113
Colin Cross36242852017-06-23 15:06:31 -07002114 module.AddProperties(props...)
2115 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002116 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002117 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002118 &BaseCompilerProperties{},
2119 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002120 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002121 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002122 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002123 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002124 &TestProperties{},
2125 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002126 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002127 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002128 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002129 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002130 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002131 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002132 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002133 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002134 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002135 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002136 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002137 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002138 )
Colin Crosscfad1192015-11-02 16:43:11 -08002139
Colin Cross1f44a3a2017-07-07 14:33:33 -07002140 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002141 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002142
2143 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002144}
2145
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002146const (
2147 // coreMode is the variant used for framework-private libraries, or
2148 // SDK libraries. (which framework-private libraries can use)
2149 coreMode = "core"
2150
2151 // vendorMode is the variant used for /vendor code that compiles
2152 // against the VNDK.
2153 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002154
2155 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002156)
2157
Jiyong Park6a43f042017-10-12 23:05:00 +09002158func squashVendorSrcs(m *Module) {
2159 if lib, ok := m.compiler.(*libraryDecorator); ok {
2160 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2161 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2162
2163 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2164 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2165 }
2166}
2167
Jiyong Parkf9332f12018-02-01 00:54:12 +09002168func squashRecoverySrcs(m *Module) {
2169 if lib, ok := m.compiler.(*libraryDecorator); ok {
2170 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2171 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2172
2173 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2174 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2175 }
2176}
2177
Jiyong Parkda6eb592018-12-19 17:12:36 +09002178func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002179 if mctx.Os() != android.Android {
2180 return
2181 }
2182
Jiyong Park7ed9de32018-10-15 22:25:07 +09002183 if g, ok := mctx.Module().(*genrule.Module); ok {
2184 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002185 var coreVariantNeeded bool = false
2186 var vendorVariantNeeded bool = false
2187 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002188 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002189 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002190 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002191 coreVariantNeeded = true
2192 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002193 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002194 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002195 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002196 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002197 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002198 if Bool(props.Recovery_available) {
2199 recoveryVariantNeeded = true
2200 }
2201
Jiyong Park413cc742018-06-19 01:46:06 +09002202 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002203 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002204 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002205 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002206 recoveryVariantNeeded = false
2207 }
2208 }
2209
Jiyong Park3f736c92018-05-24 13:36:56 +09002210 var variants []string
2211 if coreVariantNeeded {
2212 variants = append(variants, coreMode)
2213 }
2214 if vendorVariantNeeded {
2215 variants = append(variants, vendorMode)
2216 }
2217 if recoveryVariantNeeded {
2218 variants = append(variants, recoveryMode)
2219 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002220 mod := mctx.CreateVariations(variants...)
2221 for i, v := range variants {
2222 if v == recoveryMode {
2223 m := mod[i].(*genrule.Module)
2224 m.Extra.(*GenruleExtraProperties).InRecovery = true
2225 }
2226 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002227 }
2228 }
2229
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002230 m, ok := mctx.Module().(*Module)
2231 if !ok {
2232 return
2233 }
2234
2235 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002236 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002237 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002238
2239 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002240 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002241 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002242 return
2243 }
Logan Chienf3511742017-10-31 18:04:35 +08002244
2245 if vndkdep := m.vndkdep; vndkdep != nil {
2246 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002247 if productSpecific {
2248 mctx.PropertyErrorf("product_specific",
2249 "product_specific must not be true when `vndk: {enabled: true}`")
2250 return
2251 }
Logan Chienf3511742017-10-31 18:04:35 +08002252 if vendorSpecific {
2253 if !vndkdep.isVndkExt() {
2254 mctx.PropertyErrorf("vndk",
2255 "must set `extends: \"...\"` to vndk extension")
2256 return
2257 }
2258 } else {
2259 if vndkdep.isVndkExt() {
2260 mctx.PropertyErrorf("vndk",
2261 "must set `vendor: true` to set `extends: %q`",
2262 m.getVndkExtendsModuleName())
2263 return
2264 }
2265 if m.VendorProperties.Vendor_available == nil {
2266 mctx.PropertyErrorf("vndk",
2267 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2268 return
2269 }
2270 }
2271 } else {
2272 if vndkdep.isVndkSp() {
2273 mctx.PropertyErrorf("vndk",
2274 "must set `enabled: true` to set `support_system_process: true`")
2275 return
2276 }
2277 if vndkdep.isVndkExt() {
2278 mctx.PropertyErrorf("vndk",
2279 "must set `enabled: true` to set `extends: %q`",
2280 m.getVndkExtendsModuleName())
2281 return
2282 }
Justin Yun8effde42017-06-23 19:24:43 +09002283 }
2284 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002285
Jiyong Parkf9332f12018-02-01 00:54:12 +09002286 var coreVariantNeeded bool = false
2287 var vendorVariantNeeded bool = false
2288 var recoveryVariantNeeded bool = false
2289
Justin Yun71549282017-11-17 12:10:28 +09002290 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002291 // If the device isn't compiling against the VNDK, we always
2292 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002293 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002294 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2295 // LL-NDK stubs only exist in the vendor variant, since the
2296 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002297 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002298 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2299 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002300 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002301 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002302 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2303 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002304 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002305 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002306 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002307 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002308 coreVariantNeeded = true
2309 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002310 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002311 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002312 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002313 } else {
2314 // This is either in /system (or similar: /data), or is a
2315 // modules built with the NDK. Modules built with the NDK
2316 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002317 coreVariantNeeded = true
2318 }
2319
2320 if Bool(m.Properties.Recovery_available) {
2321 recoveryVariantNeeded = true
2322 }
2323
2324 if m.ModuleBase.InstallInRecovery() {
2325 recoveryVariantNeeded = true
2326 coreVariantNeeded = false
2327 }
2328
Jiyong Park413cc742018-06-19 01:46:06 +09002329 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002330 primaryArch := mctx.Config().DevicePrimaryArchType()
2331 moduleArch := m.Target().Arch.ArchType
2332 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002333 recoveryVariantNeeded = false
2334 }
2335 }
2336
Jiyong Parkf9332f12018-02-01 00:54:12 +09002337 var variants []string
2338 if coreVariantNeeded {
2339 variants = append(variants, coreMode)
2340 }
2341 if vendorVariantNeeded {
2342 variants = append(variants, vendorMode)
2343 }
2344 if recoveryVariantNeeded {
2345 variants = append(variants, recoveryMode)
2346 }
2347 mod := mctx.CreateVariations(variants...)
2348 for i, v := range variants {
2349 if v == vendorMode {
2350 m := mod[i].(*Module)
2351 m.Properties.UseVndk = true
2352 squashVendorSrcs(m)
2353 } else if v == recoveryMode {
2354 m := mod[i].(*Module)
2355 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002356 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002357 squashRecoverySrcs(m)
2358 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002359 }
2360}
2361
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002362func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002363 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002364 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2365 }
Colin Cross6510f912017-11-29 00:27:14 -08002366 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002367}
2368
Colin Cross06a931b2015-10-28 17:23:31 -07002369var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002370var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002371var BoolPtr = proptools.BoolPtr
2372var String = proptools.String
2373var StringPtr = proptools.StringPtr