blob: bde8041eafd0ead60c29a503bb06d9156fc74f0c [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 (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkf9332f12018-02-01 00:54:12 +090037 ctx.BottomUp("image", imageMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070038 ctx.BottomUp("link", linkageMutator).Parallel()
Jiyong Parkd5b18a52017-08-03 21:22:50 +090039 ctx.BottomUp("vndk", vndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
42 ctx.BottomUp("begin", beginMutator).Parallel()
43 })
Colin Cross16b23492016-01-06 14:41:07 -080044
Colin Cross1e676be2016-10-12 14:38:15 -070045 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
46 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
47 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080048
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000049 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
50 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
51
Colin Cross1e676be2016-10-12 14:38:15 -070052 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
53 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080054
Colin Cross6b753602018-06-21 13:03:07 -070055 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Ivan Lozano30c5db22018-02-21 15:49:20 -080056
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000057 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080058 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070059
60 ctx.TopDown("lto_deps", ltoDepsMutator)
61 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070062 })
Colin Crossb98c8b02016-07-29 13:44:28 -070063
64 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070065}
66
Colin Crossca860ac2016-01-04 14:34:37 -080067type Deps struct {
68 SharedLibs, LateSharedLibs []string
69 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080070 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080071 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070072
Colin Cross5950f382016-12-13 12:50:57 -080073 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070074
Colin Cross81413472016-04-11 14:37:39 -070075 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070076
Dan Willemsenb40aab62016-04-20 14:21:14 -070077 GeneratedSources []string
78 GeneratedHeaders []string
79
Dan Willemsenb3454ab2016-09-28 17:34:58 -070080 ReexportGeneratedHeaders []string
81
Colin Cross97ba0732015-03-23 17:50:24 -070082 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070083 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070084}
85
Colin Crossca860ac2016-01-04 14:34:37 -080086type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070087 // Paths to .so files
88 SharedLibs, LateSharedLibs android.Paths
89 // Paths to the dependencies to use for .so files (.so.toc files)
90 SharedLibsDeps, LateSharedLibsDeps android.Paths
91 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070092 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070093
Colin Cross26c34ed2016-09-30 17:10:16 -070094 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070095 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080096 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070097 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070098
Colin Cross26c34ed2016-09-30 17:10:16 -070099 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700100 GeneratedSources android.Paths
101 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700102
Dan Willemsen76f08272016-07-09 00:14:08 -0700103 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700104 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700105
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700107 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700108 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700109}
110
Colin Crossca860ac2016-01-04 14:34:37 -0800111type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700112 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
113 ArFlags []string // Flags that apply to ar
114 AsFlags []string // Flags that apply to assembly source files
115 CFlags []string // Flags that apply to C and C++ source files
116 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
117 ConlyFlags []string // Flags that apply to C source files
118 CppFlags []string // Flags that apply to C++ source files
119 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
120 YaccFlags []string // Flags that apply to Yacc source files
121 protoFlags []string // Flags that apply to proto source files
Joe Onorato09e94ab2017-11-18 18:23:14 -0800122 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700123 aidlFlags []string // Flags that apply to aidl source files
124 rsFlags []string // Flags that apply to renderscript source files
125 LdFlags []string // Flags that apply to linker command lines
126 libFlags []string // Flags to add libraries early to the link order
127 TidyFlags []string // Flags that apply to clang-tidy
128 SAbiFlags []string // Flags that apply to header-abi-dumper
129 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700130
Colin Crossc3199482017-03-30 15:03:04 -0700131 // Global include flags that apply to C, C++, and assembly source files
132 // These must be after any module include flags, which will be in GlobalFlags.
133 SystemIncludeFlags []string
134
Colin Crossb98c8b02016-07-29 13:44:28 -0700135 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700136 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700137 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800138 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800139 SAbiDump bool
Dan Willemsenab9f4262018-02-14 13:58:34 -0800140 ProtoRoot bool
Colin Crossca860ac2016-01-04 14:34:37 -0800141
142 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800143 DynamicLinker string
144
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700145 CFlagsDeps android.Paths // Files depended on by compiler flags
146 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800147
148 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800149 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700150}
151
Colin Cross81413472016-04-11 14:37:39 -0700152type ObjectLinkerProperties struct {
153 // names of other cc_object modules to link into this module using partial linking
154 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700155
156 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800157 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700158}
159
Colin Crossca860ac2016-01-04 14:34:37 -0800160// Properties used to compile all C or C++ modules
161type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700162 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800163 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700164
Dan Willemsen742a5452018-07-23 17:19:36 -0700165 // Some internals still need GCC (toolchain_library)
166 Gcc bool `blueprint:"mutated"`
167
Colin Cross7d5136f2015-05-11 13:39:40 -0700168 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800169 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700170
Logan Chien43d34c32017-12-20 01:17:32 +0800171 AndroidMkSharedLibs []string `blueprint:"mutated"`
172 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
173 HideFromMake bool `blueprint:"mutated"`
174 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700175
176 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800177
178 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
179 // file
180 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900181
182 // Make this module available when building for recovery
183 Recovery_available *bool
184
185 InRecovery bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700186}
187
188type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900189 // whether this module should be allowed to be directly depended by other
190 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
191 // If set to true, two variants will be built separately, one like
192 // normal, and the other limited to the set of libraries and headers
193 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700194 //
195 // The vendor variant may be used with a different (newer) /system,
196 // so it shouldn't have any unversioned runtime dependencies, or
197 // make assumptions about the system that may not be true in the
198 // future.
199 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900200 // If set to false, this module becomes inaccessible from /vendor modules.
201 //
202 // Default value is true when vndk: {enabled: true} or vendor: true.
203 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700204 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
205 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900206
207 // whether this module is capable of being loaded with other instance
208 // (possibly an older version) of the same module in the same process.
209 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
210 // can be double loaded in a vendor process if the library is also a
211 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
212 // explicitly marked as `double_loadable: true` by the owner, or the dependency
213 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
214 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800215}
216
Colin Crossca860ac2016-01-04 14:34:37 -0800217type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800218 static() bool
219 staticBinary() bool
220 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700221 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700222 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800223 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700224 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900225 isVndk() bool
226 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800227 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900228 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800229 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700230 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700231 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800232 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800233 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800234}
235
236type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700237 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800238 ModuleContextIntf
239}
240
241type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700242 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800243 ModuleContextIntf
244}
245
Colin Cross37047f12016-12-13 17:06:13 -0800246type DepsContext interface {
247 android.BottomUpMutatorContext
248 ModuleContextIntf
249}
250
Colin Crossca860ac2016-01-04 14:34:37 -0800251type feature interface {
252 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800253 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800254 flags(ctx ModuleContext, flags Flags) Flags
255 props() []interface{}
256}
257
258type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700259 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800260 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800261 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700262 compilerProps() []interface{}
263
Colin Cross76fada02016-07-27 10:31:13 -0700264 appendCflags([]string)
265 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700266 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800267}
268
269type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700270 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800271 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700272 linkerFlags(ctx ModuleContext, flags Flags) Flags
273 linkerProps() []interface{}
274
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700275 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700276 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800277}
278
279type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700280 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700281 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800282 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700283 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700284 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800285}
286
Colin Crossc99deeb2016-04-11 15:06:20 -0700287type dependencyTag struct {
288 blueprint.BaseDependencyTag
289 name string
290 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700291
292 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700293}
294
295var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700296 sharedDepTag = dependencyTag{name: "shared", library: true}
297 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
298 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
299 staticDepTag = dependencyTag{name: "static", library: true}
300 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
301 lateStaticDepTag = dependencyTag{name: "late static", library: true}
302 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800303 headerDepTag = dependencyTag{name: "header", library: true}
304 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700305 genSourceDepTag = dependencyTag{name: "gen source"}
306 genHeaderDepTag = dependencyTag{name: "gen header"}
307 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
308 objDepTag = dependencyTag{name: "obj"}
309 crtBeginDepTag = dependencyTag{name: "crtbegin"}
310 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700311 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700312 reuseObjTag = dependencyTag{name: "reuse objects"}
313 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
314 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800315 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800316 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700317)
318
Colin Crossca860ac2016-01-04 14:34:37 -0800319// Module contains the properties and members used by all C/C++ module types, and implements
320// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
321// to construct the output file. Behavior can be customized with a Customizer interface
322type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700323 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700324 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700325
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700326 Properties BaseProperties
327 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700328
Colin Crossca860ac2016-01-04 14:34:37 -0800329 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700330 hod android.HostOrDeviceSupported
331 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700332
Colin Crossca860ac2016-01-04 14:34:37 -0800333 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700334 features []feature
335 compiler compiler
336 linker linker
337 installer installer
338 stl *stl
339 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800340 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800341 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900342 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700343 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700344 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800345
346 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700347
Colin Cross635c3b02016-05-18 15:37:25 -0700348 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800349
Colin Crossb98c8b02016-07-29 13:44:28 -0700350 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700351
352 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800353
354 // Flags used to compile this module
355 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700356
357 // 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 -0800358 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700359 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800360 depsInLinkOrder android.Paths
361
362 // only non-nil when this is a shared library that reuses the objects of a static library
363 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700364}
365
Colin Cross36242852017-06-23 15:06:31 -0700366func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700367 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800368 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700369 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800370 }
371 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700372 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800373 }
374 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700375 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800376 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700377 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700378 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700379 }
Colin Cross16b23492016-01-06 14:41:07 -0800380 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700381 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800382 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800383 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700384 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800385 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800386 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700387 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800388 }
Justin Yun8effde42017-06-23 19:24:43 +0900389 if c.vndkdep != nil {
390 c.AddProperties(c.vndkdep.props()...)
391 }
Stephen Craneba090d12017-05-09 15:44:35 -0700392 if c.lto != nil {
393 c.AddProperties(c.lto.props()...)
394 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700395 if c.pgo != nil {
396 c.AddProperties(c.pgo.props()...)
397 }
Colin Crossca860ac2016-01-04 14:34:37 -0800398 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700399 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800400 }
Colin Crossc472d572015-03-17 15:06:21 -0700401
Colin Cross36242852017-06-23 15:06:31 -0700402 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700403
Colin Cross1f44a3a2017-07-07 14:33:33 -0700404 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700405
406 return c
Colin Crossc472d572015-03-17 15:06:21 -0700407}
408
Colin Crossb916a382016-07-29 17:28:03 -0700409// Returns true for dependency roots (binaries)
410// TODO(ccross): also handle dlopenable libraries
411func (c *Module) isDependencyRoot() bool {
412 if root, ok := c.linker.(interface {
413 isDependencyRoot() bool
414 }); ok {
415 return root.isDependencyRoot()
416 }
417 return false
418}
419
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700420func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700421 return c.Properties.UseVndk
422}
423
Justin Yun8effde42017-06-23 19:24:43 +0900424func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800425 if vndkdep := c.vndkdep; vndkdep != nil {
426 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900427 }
428 return false
429}
430
Yi Kong7e53c572018-02-14 18:16:12 +0800431func (c *Module) isPgoCompile() bool {
432 if pgo := c.pgo; pgo != nil {
433 return pgo.Properties.PgoCompile
434 }
435 return false
436}
437
Logan Chienf3511742017-10-31 18:04:35 +0800438func (c *Module) isVndkSp() bool {
439 if vndkdep := c.vndkdep; vndkdep != nil {
440 return vndkdep.isVndkSp()
441 }
442 return false
443}
444
445func (c *Module) isVndkExt() bool {
446 if vndkdep := c.vndkdep; vndkdep != nil {
447 return vndkdep.isVndkExt()
448 }
449 return false
450}
451
452func (c *Module) getVndkExtendsModuleName() string {
453 if vndkdep := c.vndkdep; vndkdep != nil {
454 return vndkdep.getVndkExtendsModuleName()
455 }
456 return ""
457}
458
Jiyong Park82e2bf32017-08-16 14:05:54 +0900459// Returns true only when this module is configured to have core and vendor
460// variants.
461func (c *Module) hasVendorVariant() bool {
462 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
463}
464
Jiyong Parkf9332f12018-02-01 00:54:12 +0900465func (c *Module) inRecovery() bool {
466 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
467}
468
469func (c *Module) onlyInRecovery() bool {
470 return c.ModuleBase.InstallInRecovery()
471}
472
Colin Crossca860ac2016-01-04 14:34:37 -0800473type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700474 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800475 moduleContextImpl
476}
477
Colin Cross37047f12016-12-13 17:06:13 -0800478type depsContext struct {
479 android.BottomUpMutatorContext
480 moduleContextImpl
481}
482
Colin Crossca860ac2016-01-04 14:34:37 -0800483type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700484 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800485 moduleContextImpl
486}
487
Jiyong Park2db76922017-11-08 16:03:48 +0900488func (ctx *moduleContext) SocSpecific() bool {
489 return ctx.ModuleContext.SocSpecific() ||
490 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700491}
492
Colin Crossca860ac2016-01-04 14:34:37 -0800493type moduleContextImpl struct {
494 mod *Module
495 ctx BaseModuleContext
496}
497
Colin Crossca860ac2016-01-04 14:34:37 -0800498func (ctx *moduleContextImpl) clang() bool {
499 return ctx.mod.clang(ctx.ctx)
500}
501
Colin Crossb98c8b02016-07-29 13:44:28 -0700502func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800503 return ctx.mod.toolchain(ctx.ctx)
504}
505
506func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000507 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800508}
509
510func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700511 if static, ok := ctx.mod.linker.(interface {
512 staticBinary() bool
513 }); ok {
514 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800515 }
Colin Crossb916a382016-07-29 17:28:03 -0700516 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800517}
518
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700519func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900520 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800521 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700522 }
523 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800524}
525
526func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700527 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700528 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900529 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700530 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900531 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
532 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
533 return "current"
534 }
535 return platform_vndk_ver
536 }
537 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800538 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900539 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700540 }
541 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800542}
543
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700544func (ctx *moduleContextImpl) useVndk() bool {
545 return ctx.mod.useVndk()
546}
Justin Yun8effde42017-06-23 19:24:43 +0900547
Logan Chienf3511742017-10-31 18:04:35 +0800548func (ctx *moduleContextImpl) isVndk() bool {
549 return ctx.mod.isVndk()
550}
551
Yi Kong7e53c572018-02-14 18:16:12 +0800552func (ctx *moduleContextImpl) isPgoCompile() bool {
553 return ctx.mod.isPgoCompile()
554}
555
Justin Yun8effde42017-06-23 19:24:43 +0900556func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800557 return ctx.mod.isVndkSp()
558}
559
560func (ctx *moduleContextImpl) isVndkExt() bool {
561 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900562}
563
Jiyong Parkf9332f12018-02-01 00:54:12 +0900564func (ctx *moduleContextImpl) inRecovery() bool {
565 return ctx.mod.inRecovery()
566}
567
Logan Chien2f2b8902018-07-10 15:01:19 +0800568// Check whether ABI dumps should be created for this module.
569func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
570 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
571 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800572 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800573 if sanitize := ctx.mod.sanitize; sanitize != nil {
574 if !sanitize.isVariantOnProductionDevice() {
575 return false
576 }
577 }
578 if !ctx.ctx.Device() {
579 // Host modules do not need ABI dumps.
580 return false
581 }
582 if inList(ctx.baseModuleName(), llndkLibraries) {
583 return true
584 }
585 if ctx.useVndk() && ctx.isVndk() {
586 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
587 // VNDK-private.
588 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
589 }
590 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800591}
592
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700593func (ctx *moduleContextImpl) selectedStl() string {
594 if stl := ctx.mod.stl; stl != nil {
595 return stl.Properties.SelectedStl
596 }
597 return ""
598}
599
Colin Crossce75d2c2016-10-06 16:12:58 -0700600func (ctx *moduleContextImpl) baseModuleName() string {
601 return ctx.mod.ModuleBase.BaseModuleName()
602}
603
Logan Chienf3511742017-10-31 18:04:35 +0800604func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
605 return ctx.mod.getVndkExtendsModuleName()
606}
607
Colin Cross635c3b02016-05-18 15:37:25 -0700608func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800609 return &Module{
610 hod: hod,
611 multilib: multilib,
612 }
613}
614
Colin Cross635c3b02016-05-18 15:37:25 -0700615func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800616 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700617 module.features = []feature{
618 &tidyFeature{},
619 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700620 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800621 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800622 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800623 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900624 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700625 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700626 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800627 return module
628}
629
Colin Crossce75d2c2016-10-06 16:12:58 -0700630func (c *Module) Prebuilt() *android.Prebuilt {
631 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
632 return p.prebuilt()
633 }
634 return nil
635}
636
637func (c *Module) Name() string {
638 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700639 if p, ok := c.linker.(interface {
640 Name(string) string
641 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700642 name = p.Name(name)
643 }
644 return name
645}
646
Jeff Gaston294356f2017-09-27 17:05:30 -0700647// orderDeps reorders dependencies into a list such that if module A depends on B, then
648// A will precede B in the resultant list.
649// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800650// Note that directSharedDeps should be the analogous static library for each shared lib dep
651func 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 -0700652 // If A depends on B, then
653 // Every list containing A will also contain B later in the list
654 // So, after concatenating all lists, the final instance of B will have come from the same
655 // original list as the final instance of A
656 // So, the final instance of B will be later in the concatenation than the final A
657 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
658 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800659 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700660 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800661 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
662 }
663 for _, dep := range directSharedDeps {
664 orderedAllDeps = append(orderedAllDeps, dep)
665 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700666 }
667
Colin Crossb6715442017-10-24 11:13:31 -0700668 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700669
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800670 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700671 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800672 // resultant list to only what the caller has chosen to include in directStaticDeps
673 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700674
675 return orderedAllDeps, orderedDeclaredDeps
676}
677
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800678func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
679 // convert Module to Path
680 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
681 staticDepFiles := []android.Path{}
682 for _, dep := range staticDeps {
683 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
684 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700685 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800686 sharedDepFiles := []android.Path{}
687 for _, sharedDep := range sharedDeps {
688 staticAnalogue := sharedDep.staticVariant
689 if staticAnalogue != nil {
690 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
691 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
692 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700693 }
694
695 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800696 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700697
698 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700699}
700
Colin Cross635c3b02016-05-18 15:37:25 -0700701func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800702 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700703 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800704 moduleContextImpl: moduleContextImpl{
705 mod: c,
706 },
707 }
708 ctx.ctx = ctx
709
Colin Crossf18e1102017-11-16 14:33:08 -0800710 deps := c.depsToPaths(ctx)
711 if ctx.Failed() {
712 return
713 }
714
Colin Crossca860ac2016-01-04 14:34:37 -0800715 flags := Flags{
716 Toolchain: c.toolchain(ctx),
717 Clang: c.clang(ctx),
718 }
Colin Crossca860ac2016-01-04 14:34:37 -0800719 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800720 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800721 }
722 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700723 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800724 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700725 if c.stl != nil {
726 flags = c.stl.flags(ctx, flags)
727 }
Colin Cross16b23492016-01-06 14:41:07 -0800728 if c.sanitize != nil {
729 flags = c.sanitize.flags(ctx, flags)
730 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800731 if c.coverage != nil {
732 flags = c.coverage.flags(ctx, flags)
733 }
Stephen Craneba090d12017-05-09 15:44:35 -0700734 if c.lto != nil {
735 flags = c.lto.flags(ctx, flags)
736 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700737 if c.pgo != nil {
738 flags = c.pgo.flags(ctx, flags)
739 }
Colin Crossca860ac2016-01-04 14:34:37 -0800740 for _, feature := range c.features {
741 flags = feature.flags(ctx, flags)
742 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800743 if ctx.Failed() {
744 return
745 }
746
Colin Crossb98c8b02016-07-29 13:44:28 -0700747 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
748 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
749 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800750
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800751 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
752 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700753 // We need access to all the flags seen by a source file.
754 if c.sabi != nil {
755 flags = c.sabi.flags(ctx, flags)
756 }
Colin Crossca860ac2016-01-04 14:34:37 -0800757 // Optimization to reduce size of build.ninja
758 // Replace the long list of flags for each file with a module-local variable
759 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
760 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
761 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
762 flags.CFlags = []string{"$cflags"}
763 flags.CppFlags = []string{"$cppflags"}
764 flags.AsFlags = []string{"$asflags"}
765
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700766 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800767 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700768 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800769 if ctx.Failed() {
770 return
771 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800772 }
773
Colin Crossca860ac2016-01-04 14:34:37 -0800774 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700775 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800776 if ctx.Failed() {
777 return
778 }
Colin Cross635c3b02016-05-18 15:37:25 -0700779 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700780 }
Colin Cross5049f022015-03-18 13:28:46 -0700781
Colin Crossce75d2c2016-10-06 16:12:58 -0700782 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
783 c.installer.install(ctx, c.outputFile.Path())
784 if ctx.Failed() {
785 return
Colin Crossca860ac2016-01-04 14:34:37 -0800786 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700787 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800788}
789
Colin Crossb98c8b02016-07-29 13:44:28 -0700790func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800791 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700792 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800793 }
Colin Crossca860ac2016-01-04 14:34:37 -0800794 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800795}
796
Colin Crossca860ac2016-01-04 14:34:37 -0800797func (c *Module) begin(ctx BaseModuleContext) {
798 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700799 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700800 }
Colin Crossca860ac2016-01-04 14:34:37 -0800801 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700802 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800803 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700804 if c.stl != nil {
805 c.stl.begin(ctx)
806 }
Colin Cross16b23492016-01-06 14:41:07 -0800807 if c.sanitize != nil {
808 c.sanitize.begin(ctx)
809 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800810 if c.coverage != nil {
811 c.coverage.begin(ctx)
812 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800813 if c.sabi != nil {
814 c.sabi.begin(ctx)
815 }
Justin Yun8effde42017-06-23 19:24:43 +0900816 if c.vndkdep != nil {
817 c.vndkdep.begin(ctx)
818 }
Stephen Craneba090d12017-05-09 15:44:35 -0700819 if c.lto != nil {
820 c.lto.begin(ctx)
821 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700822 if c.pgo != nil {
823 c.pgo.begin(ctx)
824 }
Colin Crossca860ac2016-01-04 14:34:37 -0800825 for _, feature := range c.features {
826 feature.begin(ctx)
827 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700828 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700829 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700830 if err != nil {
831 ctx.PropertyErrorf("sdk_version", err.Error())
832 }
Nan Zhang0007d812017-11-07 10:57:05 -0800833 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700834 }
Colin Crossca860ac2016-01-04 14:34:37 -0800835}
836
Colin Cross37047f12016-12-13 17:06:13 -0800837func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700838 deps := Deps{}
839
840 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700841 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700842 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000843 // Add the PGO dependency (the clang_rt.profile runtime library), which
844 // sometimes depends on symbols from libgcc, before libgcc gets added
845 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700846 if c.pgo != nil {
847 deps = c.pgo.deps(ctx, deps)
848 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700849 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700850 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700851 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700852 if c.stl != nil {
853 deps = c.stl.deps(ctx, deps)
854 }
Colin Cross16b23492016-01-06 14:41:07 -0800855 if c.sanitize != nil {
856 deps = c.sanitize.deps(ctx, deps)
857 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000858 if c.coverage != nil {
859 deps = c.coverage.deps(ctx, deps)
860 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800861 if c.sabi != nil {
862 deps = c.sabi.deps(ctx, deps)
863 }
Justin Yun8effde42017-06-23 19:24:43 +0900864 if c.vndkdep != nil {
865 deps = c.vndkdep.deps(ctx, deps)
866 }
Stephen Craneba090d12017-05-09 15:44:35 -0700867 if c.lto != nil {
868 deps = c.lto.deps(ctx, deps)
869 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700870 for _, feature := range c.features {
871 deps = feature.deps(ctx, deps)
872 }
873
Colin Crossb6715442017-10-24 11:13:31 -0700874 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
875 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
876 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
877 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
878 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
879 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800880 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700881
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700882 for _, lib := range deps.ReexportSharedLibHeaders {
883 if !inList(lib, deps.SharedLibs) {
884 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
885 }
886 }
887
888 for _, lib := range deps.ReexportStaticLibHeaders {
889 if !inList(lib, deps.StaticLibs) {
890 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
891 }
892 }
893
Colin Cross5950f382016-12-13 12:50:57 -0800894 for _, lib := range deps.ReexportHeaderLibHeaders {
895 if !inList(lib, deps.HeaderLibs) {
896 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
897 }
898 }
899
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700900 for _, gen := range deps.ReexportGeneratedHeaders {
901 if !inList(gen, deps.GeneratedHeaders) {
902 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
903 }
904 }
905
Colin Crossc99deeb2016-04-11 15:06:20 -0700906 return deps
907}
908
Dan Albert7e9d2952016-08-04 13:02:36 -0700909func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800910 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700911 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800912 moduleContextImpl: moduleContextImpl{
913 mod: c,
914 },
915 }
916 ctx.ctx = ctx
917
Colin Crossca860ac2016-01-04 14:34:37 -0800918 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700919}
920
Colin Cross1e676be2016-10-12 14:38:15 -0700921func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
922 if !c.Enabled() {
923 return
924 }
925
Colin Cross37047f12016-12-13 17:06:13 -0800926 ctx := &depsContext{
927 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700928 moduleContextImpl: moduleContextImpl{
929 mod: c,
930 },
931 }
932 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800933
Colin Crossc99deeb2016-04-11 15:06:20 -0700934 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800935
Dan Albert914449f2016-06-17 16:45:24 -0700936 variantNdkLibs := []string{}
937 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700938 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700939 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700940
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700941 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
942 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700943 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700944 // 1. Name of an NDK library that refers to a prebuilt module.
945 // For each of these, it adds the name of the prebuilt module (which will be in
946 // prebuilts/ndk) to the list of nonvariant libs.
947 // 2. Name of an NDK library that refers to an ndk_library module.
948 // For each of these, it adds the name of the ndk_library module to the list of
949 // variant libs.
950 // 3. Anything else (so anything that isn't an NDK library).
951 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700952 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700953 // The caller can then know to add the variantLibs dependencies differently from the
954 // nonvariantLibs
955 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
956 variantLibs = []string{}
957 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700958 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700959 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700960 if !inList(entry, ndkMigratedLibs) {
961 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
962 } else {
963 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
964 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700965 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700966 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +0900967 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(entry, vendorPublicLibraries) {
968 vendorPublicLib := entry + vendorPublicLibrarySuffix
969 if actx.OtherModuleExists(vendorPublicLib) {
970 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
971 } else {
972 // This can happen if vendor_public_library module is defined in a
973 // namespace that isn't visible to the current module. In that case,
974 // link to the original library.
975 nonvariantLibs = append(nonvariantLibs, entry)
976 }
Dan Albert914449f2016-06-17 16:45:24 -0700977 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700978 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700979 }
980 }
Dan Albert914449f2016-06-17 16:45:24 -0700981 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700982 }
983
Dan Albert914449f2016-06-17 16:45:24 -0700984 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
985 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900986 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700987 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700988
Colin Cross32ec36c2016-12-15 07:39:51 -0800989 for _, lib := range deps.HeaderLibs {
990 depTag := headerDepTag
991 if inList(lib, deps.ReexportHeaderLibHeaders) {
992 depTag = headerExportDepTag
993 }
994 actx.AddVariationDependencies(nil, depTag, lib)
995 }
Colin Cross5950f382016-12-13 12:50:57 -0800996
Dan Willemsen59339a22018-07-22 21:18:45 -0700997 actx.AddVariationDependencies([]blueprint.Variation{
998 {Mutator: "link", Variation: "static"},
999 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001000
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001001 for _, lib := range deps.StaticLibs {
1002 depTag := staticDepTag
1003 if inList(lib, deps.ReexportStaticLibHeaders) {
1004 depTag = staticExportDepTag
1005 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001006 actx.AddVariationDependencies([]blueprint.Variation{
1007 {Mutator: "link", Variation: "static"},
1008 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001009 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001010
Dan Willemsen59339a22018-07-22 21:18:45 -07001011 actx.AddVariationDependencies([]blueprint.Variation{
1012 {Mutator: "link", Variation: "static"},
1013 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001014
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001015 for _, lib := range deps.SharedLibs {
1016 depTag := sharedDepTag
1017 if inList(lib, deps.ReexportSharedLibHeaders) {
1018 depTag = sharedExportDepTag
1019 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001020 actx.AddVariationDependencies([]blueprint.Variation{
1021 {Mutator: "link", Variation: "shared"},
1022 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001023 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001024
Dan Willemsen59339a22018-07-22 21:18:45 -07001025 actx.AddVariationDependencies([]blueprint.Variation{
1026 {Mutator: "link", Variation: "shared"},
1027 }, lateSharedDepTag, deps.LateSharedLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001028
Dan Willemsen59339a22018-07-22 21:18:45 -07001029 actx.AddVariationDependencies([]blueprint.Variation{
1030 {Mutator: "link", Variation: "shared"},
1031 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001032
Colin Cross68861832016-07-08 10:41:41 -07001033 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001034
1035 for _, gen := range deps.GeneratedHeaders {
1036 depTag := genHeaderDepTag
1037 if inList(gen, deps.ReexportGeneratedHeaders) {
1038 depTag = genHeaderExportDepTag
1039 }
1040 actx.AddDependency(c, depTag, gen)
1041 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001042
Colin Cross68861832016-07-08 10:41:41 -07001043 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001044
1045 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -07001046 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001047 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001048 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -07001049 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001050 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001051 if deps.LinkerScript != "" {
1052 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
1053 }
Dan Albert914449f2016-06-17 16:45:24 -07001054
1055 version := ctx.sdkVersion()
1056 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001057 {Mutator: "ndk_api", Variation: version},
1058 {Mutator: "link", Variation: "shared"},
1059 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001060 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001061 {Mutator: "ndk_api", Variation: version},
1062 {Mutator: "link", Variation: "shared"},
1063 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001064
1065 if vndkdep := c.vndkdep; vndkdep != nil {
1066 if vndkdep.isVndkExt() {
1067 baseModuleMode := vendorMode
1068 if actx.DeviceConfig().VndkVersion() == "" {
1069 baseModuleMode = coreMode
1070 }
1071 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001072 {Mutator: "image", Variation: baseModuleMode},
1073 {Mutator: "link", Variation: "shared"},
1074 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001075 }
1076 }
Colin Cross6362e272015-10-29 15:25:03 -07001077}
Colin Cross21b9a242015-03-24 14:15:58 -07001078
Dan Albert7e9d2952016-08-04 13:02:36 -07001079func beginMutator(ctx android.BottomUpMutatorContext) {
1080 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1081 c.beginMutator(ctx)
1082 }
1083}
1084
Colin Crossca860ac2016-01-04 14:34:37 -08001085func (c *Module) clang(ctx BaseModuleContext) bool {
Dan Willemsen742a5452018-07-23 17:19:36 -07001086 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1087 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
Colin Cross3f40fa42015-01-30 17:27:36 -08001088 }
Colin Cross28344522015-04-22 13:07:53 -07001089
Colin Crossca860ac2016-01-04 14:34:37 -08001090 if !c.toolchain(ctx).ClangSupported() {
Dan Willemsen742a5452018-07-23 17:19:36 -07001091 panic("GCC is no longer supported")
Colin Crossca860ac2016-01-04 14:34:37 -08001092 }
1093
Dan Willemsen742a5452018-07-23 17:19:36 -07001094 return !c.Properties.Gcc
Colin Crossca860ac2016-01-04 14:34:37 -08001095}
1096
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001097// Whether a module can link to another module, taking into
1098// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001099func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001100 if from.Target().Os != android.Android {
1101 // Host code is not restricted
1102 return
1103 }
1104 if from.Properties.UseVndk {
1105 // Though vendor code is limited by the vendor mutator,
1106 // each vendor-available module needs to check
1107 // link-type for VNDK.
1108 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001109 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001110 }
1111 return
1112 }
Nan Zhang0007d812017-11-07 10:57:05 -08001113 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001114 // Platform code can link to anything
1115 return
1116 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001117 if from.inRecovery() {
1118 // Recovery code is not NDK
1119 return
1120 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001121 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1122 // These are always allowed
1123 return
1124 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001125 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1126 // These are allowed, but they don't set sdk_version
1127 return
1128 }
1129 if _, ok := to.linker.(*stubDecorator); ok {
1130 // These aren't real libraries, but are the stub shared libraries that are included in
1131 // the NDK.
1132 return
1133 }
Nan Zhang0007d812017-11-07 10:57:05 -08001134 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001135 // NDK code linking to platform code is never okay.
1136 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1137 ctx.OtherModuleName(to))
1138 }
1139
1140 // At this point we know we have two NDK libraries, but we need to
1141 // check that we're not linking against anything built against a higher
1142 // API level, as it is only valid to link against older or equivalent
1143 // APIs.
1144
Inseob Kim01a28722018-04-11 09:48:45 +09001145 // Current can link against anything.
1146 if String(from.Properties.Sdk_version) != "current" {
1147 // Otherwise we need to check.
1148 if String(to.Properties.Sdk_version) == "current" {
1149 // Current can't be linked against by anything else.
1150 ctx.ModuleErrorf("links %q built against newer API version %q",
1151 ctx.OtherModuleName(to), "current")
1152 } else {
1153 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1154 if err != nil {
1155 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001156 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001157 String(from.Properties.Sdk_version))
1158 }
1159 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1160 if err != nil {
1161 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001162 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001163 String(to.Properties.Sdk_version))
1164 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001165
Inseob Kim01a28722018-04-11 09:48:45 +09001166 if toApi > fromApi {
1167 ctx.ModuleErrorf("links %q built against newer API version %q",
1168 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1169 }
1170 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001171 }
Dan Albert202fe492017-12-15 13:56:59 -08001172
1173 // Also check that the two STL choices are compatible.
1174 fromStl := from.stl.Properties.SelectedStl
1175 toStl := to.stl.Properties.SelectedStl
1176 if fromStl == "" || toStl == "" {
1177 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001178 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001179 // We can be permissive with the system "STL" since it is only the C++
1180 // ABI layer, but in the future we should make sure that everyone is
1181 // using either libc++ or nothing.
Inseob Kimda2171a2018-04-11 15:41:38 +09001182 } else if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
Dan Albert202fe492017-12-15 13:56:59 -08001183 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1184 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1185 to.stl.Properties.SelectedStl)
1186 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001187}
1188
Jiyong Park5fb8c102018-04-09 12:03:06 +09001189// Tests whether the dependent library is okay to be double loaded inside a single process.
1190// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1191// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1192// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1193func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1194 if _, ok := from.linker.(*libraryDecorator); !ok {
1195 return
1196 }
1197
1198 if inList(ctx.ModuleName(), llndkLibraries) ||
1199 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1200 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1201 depIsVndkSp := false
1202 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1203 depIsVndkSp = true
1204 }
1205 depIsVndk := false
1206 if to.vndkdep != nil && to.vndkdep.isVndk() {
1207 depIsVndk = true
1208 }
1209 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1210 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
1211 ctx.ModuleErrorf("links VNDK library %q that isn't double_loadable.",
1212 ctx.OtherModuleName(to))
1213 }
1214 }
1215}
1216
Colin Crossc99deeb2016-04-11 15:06:20 -07001217// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001218func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001219 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001220
Jeff Gaston294356f2017-09-27 17:05:30 -07001221 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001222 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001223
Colin Crossd11fcda2017-10-23 17:59:01 -07001224 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001225 depName := ctx.OtherModuleName(dep)
1226 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001227
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001228 ccDep, _ := dep.(*Module)
1229 if ccDep == nil {
1230 // handling for a few module types that aren't cc Module but that are also supported
1231 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001232 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001233 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001234 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1235 genRule.GeneratedSourceFiles()...)
1236 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001237 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001238 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001239 // Support exported headers from a generated_sources dependency
1240 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001241 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001242 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001243 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001244 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001245 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001246 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001247 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001248 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001249 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001250 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001251 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1252 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1253
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001254 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001255 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001256 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001257 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001258 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001259 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001260 files := genRule.GeneratedSourceFiles()
1261 if len(files) == 1 {
1262 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1263 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001264 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001265 }
1266 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001267 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001268 }
Colin Crossca860ac2016-01-04 14:34:37 -08001269 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001270 return
1271 }
1272
Colin Crossd11fcda2017-10-23 17:59:01 -07001273 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001274 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1275 return
1276 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001277 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001278 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001279 return
1280 }
1281
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001282 // re-exporting flags
1283 if depTag == reuseObjTag {
1284 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001285 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001286 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001287 depPaths.Objs = depPaths.Objs.Append(objs)
1288 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001289 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001290 return
1291 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001292 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001293 if t, ok := depTag.(dependencyTag); ok && t.library {
1294 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001295 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001296 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001297 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001298 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001299
1300 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001301 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001302 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001303 // 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 -07001304 // Re-exported shared library headers must be included as well since they can help us with type information
1305 // about template instantiations (instantiated from their headers).
1306 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001307 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001308 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001309
Logan Chienf3511742017-10-31 18:04:35 +08001310 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001311 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001312 }
1313
Colin Cross26c34ed2016-09-30 17:10:16 -07001314 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001315 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001316
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001317 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001318 depFile := android.OptionalPath{}
1319
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001320 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001321 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001322 ptr = &depPaths.SharedLibs
1323 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001324 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001325 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001326 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001327 ptr = &depPaths.LateSharedLibs
1328 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001329 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001330 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001331 ptr = nil
1332 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001333 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001334 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001335 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001336 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001337 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001338 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001339 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001340 return
1341 }
1342
1343 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001344 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001345 for i := range missingDeps {
1346 missingDeps[i] += postfix
1347 }
1348 ctx.AddMissingDependencies(missingDeps)
1349 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001350 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001351 case headerDepTag:
1352 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001353 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001354 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001355 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001356 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001357 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001358 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001359 }
1360
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001361 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001362 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001363 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001364 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001365 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001366 return
1367 }
1368
1369 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001370 // in static libraries act as if they were whole static libraries. The same goes for
1371 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001372 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1373 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001374 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1375 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001376
Dan Willemsen581341d2017-02-09 16:16:31 -08001377 }
1378
Colin Cross26c34ed2016-09-30 17:10:16 -07001379 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001380 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001381 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001382 return
1383 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001384 *ptr = append(*ptr, linkFile.Path())
1385 }
1386
Colin Crossc99deeb2016-04-11 15:06:20 -07001387 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001388 dep := depFile
1389 if !dep.Valid() {
1390 dep = linkFile
1391 }
1392 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001393 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001394
Logan Chien43d34c32017-12-20 01:17:32 +08001395 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001396 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001397 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001398 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001399 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001400 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001401 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1402 if c.useVndk() && bothVendorAndCoreVariantsExist {
1403 // The vendor module in Make will have been renamed to not conflict with the core
1404 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001405 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001406 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001407 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001408 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1409 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001410 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001411 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001412 }
Logan Chien43d34c32017-12-20 01:17:32 +08001413 }
1414
1415 // Export the shared libs to Make.
1416 switch depTag {
1417 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Park27b188b2017-07-18 13:23:39 +09001418 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001419 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001420 c.Properties.AndroidMkSharedLibs = append(
1421 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
1422 case runtimeDepTag:
1423 c.Properties.AndroidMkRuntimeLibs = append(
1424 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001425 }
Colin Crossca860ac2016-01-04 14:34:37 -08001426 })
1427
Jeff Gaston294356f2017-09-27 17:05:30 -07001428 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001429 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001430
Colin Crossdd84e052017-05-17 13:44:16 -07001431 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001432 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001433 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001434 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001435 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1436
1437 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001438 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001439 }
Colin Crossdd84e052017-05-17 13:44:16 -07001440
Colin Crossca860ac2016-01-04 14:34:37 -08001441 return depPaths
1442}
1443
1444func (c *Module) InstallInData() bool {
1445 if c.installer == nil {
1446 return false
1447 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001448 return c.installer.inData()
1449}
1450
1451func (c *Module) InstallInSanitizerDir() bool {
1452 if c.installer == nil {
1453 return false
1454 }
1455 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001456 return true
1457 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001458 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001459}
1460
Jiyong Parkf9332f12018-02-01 00:54:12 +09001461func (c *Module) InstallInRecovery() bool {
1462 return c.inRecovery()
1463}
1464
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001465func (c *Module) HostToolPath() android.OptionalPath {
1466 if c.installer == nil {
1467 return android.OptionalPath{}
1468 }
1469 return c.installer.hostToolPath()
1470}
1471
Nan Zhangd4e641b2017-07-12 12:55:28 -07001472func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1473 return c.outputFile
1474}
1475
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001476func (c *Module) Srcs() android.Paths {
1477 if c.outputFile.Valid() {
1478 return android.Paths{c.outputFile.Path()}
1479 }
1480 return android.Paths{}
1481}
1482
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001483func (c *Module) static() bool {
1484 if static, ok := c.linker.(interface {
1485 static() bool
1486 }); ok {
1487 return static.static()
1488 }
1489 return false
1490}
1491
Colin Cross2ba19d92015-05-07 15:44:20 -07001492//
Colin Crosscfad1192015-11-02 16:43:11 -08001493// Defaults
1494//
Colin Crossca860ac2016-01-04 14:34:37 -08001495type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001496 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001497 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001498}
1499
Colin Cross635c3b02016-05-18 15:37:25 -07001500func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001501}
1502
Colin Cross1e676be2016-10-12 14:38:15 -07001503func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1504}
1505
Colin Cross36242852017-06-23 15:06:31 -07001506func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001507 return DefaultsFactory()
1508}
1509
Colin Cross36242852017-06-23 15:06:31 -07001510func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001511 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001512
Colin Cross36242852017-06-23 15:06:31 -07001513 module.AddProperties(props...)
1514 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001515 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001516 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001517 &BaseCompilerProperties{},
1518 &BaseLinkerProperties{},
Chih-Hung Hsieh86814712018-05-23 18:30:46 -07001519 &MoreBaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001520 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001521 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001522 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001523 &TestProperties{},
1524 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001525 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001526 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001527 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001528 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001529 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001530 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001531 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001532 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001533 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001534 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001535 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001536 )
Colin Crosscfad1192015-11-02 16:43:11 -08001537
Colin Cross1f44a3a2017-07-07 14:33:33 -07001538 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001539
1540 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001541}
1542
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001543const (
1544 // coreMode is the variant used for framework-private libraries, or
1545 // SDK libraries. (which framework-private libraries can use)
1546 coreMode = "core"
1547
1548 // vendorMode is the variant used for /vendor code that compiles
1549 // against the VNDK.
1550 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001551
1552 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001553)
1554
Jiyong Park6a43f042017-10-12 23:05:00 +09001555func squashVendorSrcs(m *Module) {
1556 if lib, ok := m.compiler.(*libraryDecorator); ok {
1557 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1558 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1559
1560 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1561 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1562 }
1563}
1564
Jiyong Parkf9332f12018-02-01 00:54:12 +09001565func squashRecoverySrcs(m *Module) {
1566 if lib, ok := m.compiler.(*libraryDecorator); ok {
1567 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1568 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1569
1570 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1571 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1572 }
1573}
1574
1575func imageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001576 if mctx.Os() != android.Android {
1577 return
1578 }
1579
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001580 if genrule, ok := mctx.Module().(*genrule.Module); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001581 if props, ok := genrule.Extra.(*GenruleExtraProperties); ok {
1582 var coreVariantNeeded bool = false
1583 var vendorVariantNeeded bool = false
1584 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001585 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001586 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001587 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001588 coreVariantNeeded = true
1589 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001590 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001591 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001592 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001593 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001594 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001595 if Bool(props.Recovery_available) {
1596 recoveryVariantNeeded = true
1597 }
1598
Jiyong Park413cc742018-06-19 01:46:06 +09001599 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001600 primaryArch := mctx.Config().DevicePrimaryArchType()
1601 moduleArch := genrule.Target().Arch.ArchType
1602 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001603 recoveryVariantNeeded = false
1604 }
1605 }
1606
Jiyong Park3f736c92018-05-24 13:36:56 +09001607 var variants []string
1608 if coreVariantNeeded {
1609 variants = append(variants, coreMode)
1610 }
1611 if vendorVariantNeeded {
1612 variants = append(variants, vendorMode)
1613 }
1614 if recoveryVariantNeeded {
1615 variants = append(variants, recoveryMode)
1616 }
1617 mctx.CreateVariations(variants...)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001618 }
1619 }
1620
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001621 m, ok := mctx.Module().(*Module)
1622 if !ok {
1623 return
1624 }
1625
1626 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001627 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1628
1629 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001630 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001631 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001632 return
1633 }
Logan Chienf3511742017-10-31 18:04:35 +08001634
1635 if vndkdep := m.vndkdep; vndkdep != nil {
1636 if vndkdep.isVndk() {
1637 if vendorSpecific {
1638 if !vndkdep.isVndkExt() {
1639 mctx.PropertyErrorf("vndk",
1640 "must set `extends: \"...\"` to vndk extension")
1641 return
1642 }
1643 } else {
1644 if vndkdep.isVndkExt() {
1645 mctx.PropertyErrorf("vndk",
1646 "must set `vendor: true` to set `extends: %q`",
1647 m.getVndkExtendsModuleName())
1648 return
1649 }
1650 if m.VendorProperties.Vendor_available == nil {
1651 mctx.PropertyErrorf("vndk",
1652 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1653 return
1654 }
1655 }
1656 } else {
1657 if vndkdep.isVndkSp() {
1658 mctx.PropertyErrorf("vndk",
1659 "must set `enabled: true` to set `support_system_process: true`")
1660 return
1661 }
1662 if vndkdep.isVndkExt() {
1663 mctx.PropertyErrorf("vndk",
1664 "must set `enabled: true` to set `extends: %q`",
1665 m.getVndkExtendsModuleName())
1666 return
1667 }
Justin Yun8effde42017-06-23 19:24:43 +09001668 }
1669 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001670
Jiyong Parkf9332f12018-02-01 00:54:12 +09001671 var coreVariantNeeded bool = false
1672 var vendorVariantNeeded bool = false
1673 var recoveryVariantNeeded bool = false
1674
Justin Yun71549282017-11-17 12:10:28 +09001675 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001676 // If the device isn't compiling against the VNDK, we always
1677 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001678 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001679 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1680 // LL-NDK stubs only exist in the vendor variant, since the
1681 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001682 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001683 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1684 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001685 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001686 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001687 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1688 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001689 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001690 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001691 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001692 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001693 coreVariantNeeded = true
1694 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001695 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001696 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001697 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001698 } else {
1699 // This is either in /system (or similar: /data), or is a
1700 // modules built with the NDK. Modules built with the NDK
1701 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001702 coreVariantNeeded = true
1703 }
1704
1705 if Bool(m.Properties.Recovery_available) {
1706 recoveryVariantNeeded = true
1707 }
1708
1709 if m.ModuleBase.InstallInRecovery() {
1710 recoveryVariantNeeded = true
1711 coreVariantNeeded = false
1712 }
1713
Jiyong Park413cc742018-06-19 01:46:06 +09001714 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001715 primaryArch := mctx.Config().DevicePrimaryArchType()
1716 moduleArch := m.Target().Arch.ArchType
1717 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001718 recoveryVariantNeeded = false
1719 }
1720 }
1721
Jiyong Parkf9332f12018-02-01 00:54:12 +09001722 var variants []string
1723 if coreVariantNeeded {
1724 variants = append(variants, coreMode)
1725 }
1726 if vendorVariantNeeded {
1727 variants = append(variants, vendorMode)
1728 }
1729 if recoveryVariantNeeded {
1730 variants = append(variants, recoveryMode)
1731 }
1732 mod := mctx.CreateVariations(variants...)
1733 for i, v := range variants {
1734 if v == vendorMode {
1735 m := mod[i].(*Module)
1736 m.Properties.UseVndk = true
1737 squashVendorSrcs(m)
1738 } else if v == recoveryMode {
1739 m := mod[i].(*Module)
1740 m.Properties.InRecovery = true
1741 squashRecoverySrcs(m)
1742 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001743 }
1744}
1745
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001746func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001747 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001748 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1749 }
Colin Cross6510f912017-11-29 00:27:14 -08001750 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001751}
1752
Colin Cross06a931b2015-10-28 17:23:31 -07001753var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001754var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001755var BoolPtr = proptools.BoolPtr
1756var String = proptools.String
1757var StringPtr = proptools.StringPtr