blob: b8cbf26a06e1976cebf44b1b3557685aabea0f3b [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 Crosse40b4ea2018-10-02 22:25:58 -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()
Jiyong Park25fc6a92018-11-18 18:02:45 +090042 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070043 ctx.BottomUp("begin", BeginMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070044 })
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross1e676be2016-10-12 14:38:15 -070046 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
48 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070050 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
51 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
52
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000053 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
54 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
55
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080056 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
57 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
58
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
60 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080061
Colin Cross6b753602018-06-21 13:03:07 -070062 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Ivan Lozano30c5db22018-02-21 15:49:20 -080063
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000064 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080065 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070066
67 ctx.TopDown("lto_deps", ltoDepsMutator)
68 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070069 })
Colin Crossb98c8b02016-07-29 13:44:28 -070070
71 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070072}
73
Colin Crossca860ac2016-01-04 14:34:37 -080074type Deps struct {
75 SharedLibs, LateSharedLibs []string
76 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080077 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080078 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070079
Colin Cross5950f382016-12-13 12:50:57 -080080 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070081
Colin Cross81413472016-04-11 14:37:39 -070082 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070083
Dan Willemsenb40aab62016-04-20 14:21:14 -070084 GeneratedSources []string
85 GeneratedHeaders []string
86
Dan Willemsenb3454ab2016-09-28 17:34:58 -070087 ReexportGeneratedHeaders []string
88
Colin Cross97ba0732015-03-23 17:50:24 -070089 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070090
91 // Used for host bionic
92 LinkerFlagsFile string
93 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070094}
95
Colin Crossca860ac2016-01-04 14:34:37 -080096type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070097 // Paths to .so files
98 SharedLibs, LateSharedLibs android.Paths
99 // Paths to the dependencies to use for .so files (.so.toc files)
100 SharedLibsDeps, LateSharedLibsDeps android.Paths
101 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700102 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Colin Cross26c34ed2016-09-30 17:10:16 -0700104 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700105 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800106 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700107 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700110 GeneratedSources android.Paths
111 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112
Dan Willemsen76f08272016-07-09 00:14:08 -0700113 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700114 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700117 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700118
119 // Path to the file container flags to use with the linker
120 LinkerFlagsFile android.OptionalPath
121
122 // Path to the dynamic linker binary
123 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124}
125
Colin Crossca860ac2016-01-04 14:34:37 -0800126type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700127 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
128 ArFlags []string // Flags that apply to ar
129 AsFlags []string // Flags that apply to assembly source files
130 CFlags []string // Flags that apply to C and C++ source files
131 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
132 ConlyFlags []string // Flags that apply to C source files
133 CppFlags []string // Flags that apply to C++ source files
134 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
135 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700136 aidlFlags []string // Flags that apply to aidl source files
137 rsFlags []string // Flags that apply to renderscript source files
138 LdFlags []string // Flags that apply to linker command lines
139 libFlags []string // Flags to add libraries early to the link order
140 TidyFlags []string // Flags that apply to clang-tidy
141 SAbiFlags []string // Flags that apply to header-abi-dumper
142 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700143
Colin Crossc3199482017-03-30 15:03:04 -0700144 // Global include flags that apply to C, C++, and assembly source files
145 // These must be after any module include flags, which will be in GlobalFlags.
146 SystemIncludeFlags []string
147
Colin Crossb98c8b02016-07-29 13:44:28 -0700148 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700149 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800150 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800151 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800152
153 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800154 DynamicLinker string
155
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700156 CFlagsDeps android.Paths // Files depended on by compiler flags
157 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800158
159 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800160
161 protoDeps android.Paths
162 protoFlags []string // Flags that apply to proto source files
163 protoOutTypeFlag string // The output type, --cpp_out for example
164 protoOutParams []string // Flags that modify the output of proto generated files
165 protoC bool // Whether to use C instead of C++
166 protoOptionsFile bool // Whether to look for a .options file next to the .proto
167 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700168}
169
Colin Cross81413472016-04-11 14:37:39 -0700170type ObjectLinkerProperties struct {
171 // names of other cc_object modules to link into this module using partial linking
172 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700173
174 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800175 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700176}
177
Colin Crossca860ac2016-01-04 14:34:37 -0800178// Properties used to compile all C or C++ modules
179type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700180 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800181 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700182
183 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800184 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700185
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +0000186 AndroidMkSharedLibs []string `blueprint:"mutated"`
187 AndroidMkStaticLibs []string `blueprint:"mutated"`
188 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
189 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
190 HideFromMake bool `blueprint:"mutated"`
191 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700192
193 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800194
195 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
196 // file
197 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900198
199 // Make this module available when building for recovery
200 Recovery_available *bool
201
202 InRecovery bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700203}
204
205type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900206 // whether this module should be allowed to be directly depended by other
207 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
208 // If set to true, two variants will be built separately, one like
209 // normal, and the other limited to the set of libraries and headers
210 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700211 //
212 // The vendor variant may be used with a different (newer) /system,
213 // so it shouldn't have any unversioned runtime dependencies, or
214 // make assumptions about the system that may not be true in the
215 // future.
216 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900217 // If set to false, this module becomes inaccessible from /vendor modules.
218 //
219 // Default value is true when vndk: {enabled: true} or vendor: true.
220 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700221 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
222 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900223
224 // whether this module is capable of being loaded with other instance
225 // (possibly an older version) of the same module in the same process.
226 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
227 // can be double loaded in a vendor process if the library is also a
228 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
229 // explicitly marked as `double_loadable: true` by the owner, or the dependency
230 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
231 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800232}
233
Colin Crossca860ac2016-01-04 14:34:37 -0800234type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800235 static() bool
236 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700237 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700238 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800239 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700240 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900241 isVndk() bool
242 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800243 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900244 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800245 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700246 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700247 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800248 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800249 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800250 useClangLld(actx ModuleContext) bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900251 isApex() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800252}
253
254type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700255 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800256 ModuleContextIntf
257}
258
259type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700260 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800261 ModuleContextIntf
262}
263
Colin Cross37047f12016-12-13 17:06:13 -0800264type DepsContext interface {
265 android.BottomUpMutatorContext
266 ModuleContextIntf
267}
268
Colin Crossca860ac2016-01-04 14:34:37 -0800269type feature interface {
270 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800271 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800272 flags(ctx ModuleContext, flags Flags) Flags
273 props() []interface{}
274}
275
276type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700277 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800278 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800279 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700280 compilerProps() []interface{}
281
Colin Cross76fada02016-07-27 10:31:13 -0700282 appendCflags([]string)
283 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700284 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800285}
286
287type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700288 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800289 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700290 linkerFlags(ctx ModuleContext, flags Flags) Flags
291 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800292 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700293
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700294 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700295 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800296}
297
298type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700299 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700300 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800301 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700302 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700303 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800304}
305
Colin Crossc99deeb2016-04-11 15:06:20 -0700306type dependencyTag struct {
307 blueprint.BaseDependencyTag
308 name string
309 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700310
311 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900312
313 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700314}
315
316var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700317 sharedDepTag = dependencyTag{name: "shared", library: true}
318 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
319 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
320 staticDepTag = dependencyTag{name: "static", library: true}
321 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
322 lateStaticDepTag = dependencyTag{name: "late static", library: true}
323 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800324 headerDepTag = dependencyTag{name: "header", library: true}
325 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700326 genSourceDepTag = dependencyTag{name: "gen source"}
327 genHeaderDepTag = dependencyTag{name: "gen header"}
328 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
329 objDepTag = dependencyTag{name: "obj"}
330 crtBeginDepTag = dependencyTag{name: "crtbegin"}
331 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700332 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
333 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700334 reuseObjTag = dependencyTag{name: "reuse objects"}
335 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
336 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800337 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800338 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700339)
340
Colin Crossca860ac2016-01-04 14:34:37 -0800341// Module contains the properties and members used by all C/C++ module types, and implements
342// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
343// to construct the output file. Behavior can be customized with a Customizer interface
344type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700345 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700346 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900347 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700348
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700349 Properties BaseProperties
350 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700351
Colin Crossca860ac2016-01-04 14:34:37 -0800352 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700353 hod android.HostOrDeviceSupported
354 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700355
Colin Crossca860ac2016-01-04 14:34:37 -0800356 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700357 features []feature
358 compiler compiler
359 linker linker
360 installer installer
361 stl *stl
362 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800363 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800364 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900365 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700366 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700367 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800368 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800369
370 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700371
Colin Cross635c3b02016-05-18 15:37:25 -0700372 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800373
Colin Crossb98c8b02016-07-29 13:44:28 -0700374 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700375
376 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800377
378 // Flags used to compile this module
379 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700380
381 // 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 -0800382 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700383 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800384 depsInLinkOrder android.Paths
385
386 // only non-nil when this is a shared library that reuses the objects of a static library
387 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700388}
389
Jiyong Parkc20eee32018-09-05 22:36:17 +0900390func (c *Module) OutputFile() android.OptionalPath {
391 return c.outputFile
392}
393
Colin Cross36242852017-06-23 15:06:31 -0700394func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700395 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800396 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700397 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800398 }
399 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700400 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800401 }
402 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700403 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800404 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700405 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700406 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700407 }
Colin Cross16b23492016-01-06 14:41:07 -0800408 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700409 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800410 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800411 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700412 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800413 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800414 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700415 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800416 }
Justin Yun8effde42017-06-23 19:24:43 +0900417 if c.vndkdep != nil {
418 c.AddProperties(c.vndkdep.props()...)
419 }
Stephen Craneba090d12017-05-09 15:44:35 -0700420 if c.lto != nil {
421 c.AddProperties(c.lto.props()...)
422 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700423 if c.pgo != nil {
424 c.AddProperties(c.pgo.props()...)
425 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800426 if c.xom != nil {
427 c.AddProperties(c.xom.props()...)
428 }
Colin Crossca860ac2016-01-04 14:34:37 -0800429 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700430 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800431 }
Colin Crossc472d572015-03-17 15:06:21 -0700432
Colin Crossa9d8bee2018-10-02 13:59:46 -0700433 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
434 switch class {
435 case android.Device:
436 return ctx.Config().DevicePrefer32BitExecutables()
437 case android.HostCross:
438 // Windows builds always prefer 32-bit
439 return true
440 default:
441 return false
442 }
443 })
Colin Cross36242852017-06-23 15:06:31 -0700444 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700445
Colin Cross1f44a3a2017-07-07 14:33:33 -0700446 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700447
Jiyong Park9d452992018-10-03 00:38:19 +0900448 android.InitApexModule(c)
449
Colin Cross36242852017-06-23 15:06:31 -0700450 return c
Colin Crossc472d572015-03-17 15:06:21 -0700451}
452
Colin Crossb916a382016-07-29 17:28:03 -0700453// Returns true for dependency roots (binaries)
454// TODO(ccross): also handle dlopenable libraries
455func (c *Module) isDependencyRoot() bool {
456 if root, ok := c.linker.(interface {
457 isDependencyRoot() bool
458 }); ok {
459 return root.isDependencyRoot()
460 }
461 return false
462}
463
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700464func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700465 return c.Properties.UseVndk
466}
467
Justin Yun8effde42017-06-23 19:24:43 +0900468func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800469 if vndkdep := c.vndkdep; vndkdep != nil {
470 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900471 }
472 return false
473}
474
Yi Kong7e53c572018-02-14 18:16:12 +0800475func (c *Module) isPgoCompile() bool {
476 if pgo := c.pgo; pgo != nil {
477 return pgo.Properties.PgoCompile
478 }
479 return false
480}
481
Logan Chienf3511742017-10-31 18:04:35 +0800482func (c *Module) isVndkSp() bool {
483 if vndkdep := c.vndkdep; vndkdep != nil {
484 return vndkdep.isVndkSp()
485 }
486 return false
487}
488
489func (c *Module) isVndkExt() bool {
490 if vndkdep := c.vndkdep; vndkdep != nil {
491 return vndkdep.isVndkExt()
492 }
493 return false
494}
495
496func (c *Module) getVndkExtendsModuleName() string {
497 if vndkdep := c.vndkdep; vndkdep != nil {
498 return vndkdep.getVndkExtendsModuleName()
499 }
500 return ""
501}
502
Jiyong Park82e2bf32017-08-16 14:05:54 +0900503// Returns true only when this module is configured to have core and vendor
504// variants.
505func (c *Module) hasVendorVariant() bool {
506 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
507}
508
Jiyong Parkf9332f12018-02-01 00:54:12 +0900509func (c *Module) inRecovery() bool {
510 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
511}
512
513func (c *Module) onlyInRecovery() bool {
514 return c.ModuleBase.InstallInRecovery()
515}
516
Jiyong Park25fc6a92018-11-18 18:02:45 +0900517func (c *Module) IsStubs() bool {
518 if library, ok := c.linker.(*libraryDecorator); ok {
519 return library.buildStubs()
520 }
521 return false
522}
523
524func (c *Module) HasStubsVariants() bool {
525 if library, ok := c.linker.(*libraryDecorator); ok {
526 return len(library.Properties.Stubs.Versions) > 0
527 }
528 return false
529}
530
Colin Crossca860ac2016-01-04 14:34:37 -0800531type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700532 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800533 moduleContextImpl
534}
535
Colin Cross37047f12016-12-13 17:06:13 -0800536type depsContext struct {
537 android.BottomUpMutatorContext
538 moduleContextImpl
539}
540
Colin Crossca860ac2016-01-04 14:34:37 -0800541type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700542 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800543 moduleContextImpl
544}
545
Jiyong Park2db76922017-11-08 16:03:48 +0900546func (ctx *moduleContext) SocSpecific() bool {
547 return ctx.ModuleContext.SocSpecific() ||
548 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700549}
550
Colin Crossca860ac2016-01-04 14:34:37 -0800551type moduleContextImpl struct {
552 mod *Module
553 ctx BaseModuleContext
554}
555
Colin Crossb98c8b02016-07-29 13:44:28 -0700556func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800557 return ctx.mod.toolchain(ctx.ctx)
558}
559
560func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000561 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800562}
563
564func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700565 if static, ok := ctx.mod.linker.(interface {
566 staticBinary() bool
567 }); ok {
568 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800569 }
Colin Crossb916a382016-07-29 17:28:03 -0700570 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800571}
572
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700573func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900574 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800575 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700576 }
577 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800578}
579
580func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700581 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700582 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900583 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700584 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900585 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
586 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
587 return "current"
588 }
589 return platform_vndk_ver
590 }
591 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800592 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900593 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700594 }
595 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800596}
597
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700598func (ctx *moduleContextImpl) useVndk() bool {
599 return ctx.mod.useVndk()
600}
Justin Yun8effde42017-06-23 19:24:43 +0900601
Logan Chienf3511742017-10-31 18:04:35 +0800602func (ctx *moduleContextImpl) isVndk() bool {
603 return ctx.mod.isVndk()
604}
605
Yi Kong7e53c572018-02-14 18:16:12 +0800606func (ctx *moduleContextImpl) isPgoCompile() bool {
607 return ctx.mod.isPgoCompile()
608}
609
Justin Yun8effde42017-06-23 19:24:43 +0900610func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800611 return ctx.mod.isVndkSp()
612}
613
614func (ctx *moduleContextImpl) isVndkExt() bool {
615 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900616}
617
Jiyong Parkf9332f12018-02-01 00:54:12 +0900618func (ctx *moduleContextImpl) inRecovery() bool {
619 return ctx.mod.inRecovery()
620}
621
Logan Chien2f2b8902018-07-10 15:01:19 +0800622// Check whether ABI dumps should be created for this module.
623func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
624 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
625 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800626 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800627 if sanitize := ctx.mod.sanitize; sanitize != nil {
628 if !sanitize.isVariantOnProductionDevice() {
629 return false
630 }
631 }
632 if !ctx.ctx.Device() {
633 // Host modules do not need ABI dumps.
634 return false
635 }
636 if inList(ctx.baseModuleName(), llndkLibraries) {
637 return true
638 }
Logan Chienf4b79c62018-08-02 02:27:02 +0800639 if inList(ctx.baseModuleName(), ndkMigratedLibs) {
640 return true
641 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800642 if ctx.useVndk() && ctx.isVndk() {
643 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
644 // VNDK-private.
645 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
646 }
647 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800648}
649
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700650func (ctx *moduleContextImpl) selectedStl() string {
651 if stl := ctx.mod.stl; stl != nil {
652 return stl.Properties.SelectedStl
653 }
654 return ""
655}
656
Ivan Lozanobd721262018-11-27 14:33:03 -0800657func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
658 return ctx.mod.linker.useClangLld(actx)
659}
660
Colin Crossce75d2c2016-10-06 16:12:58 -0700661func (ctx *moduleContextImpl) baseModuleName() string {
662 return ctx.mod.ModuleBase.BaseModuleName()
663}
664
Logan Chienf3511742017-10-31 18:04:35 +0800665func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
666 return ctx.mod.getVndkExtendsModuleName()
667}
668
Jiyong Park25fc6a92018-11-18 18:02:45 +0900669// Tests if this module is built for APEX
670func (ctx *moduleContextImpl) isApex() bool {
671 return ctx.mod.ApexName() != ""
672}
673
Colin Cross635c3b02016-05-18 15:37:25 -0700674func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800675 return &Module{
676 hod: hod,
677 multilib: multilib,
678 }
679}
680
Colin Cross635c3b02016-05-18 15:37:25 -0700681func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800682 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700683 module.features = []feature{
684 &tidyFeature{},
685 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700686 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800687 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800688 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800689 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900690 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700691 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700692 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800693 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800694 return module
695}
696
Colin Crossce75d2c2016-10-06 16:12:58 -0700697func (c *Module) Prebuilt() *android.Prebuilt {
698 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
699 return p.prebuilt()
700 }
701 return nil
702}
703
704func (c *Module) Name() string {
705 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700706 if p, ok := c.linker.(interface {
707 Name(string) string
708 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700709 name = p.Name(name)
710 }
711 return name
712}
713
Jeff Gaston294356f2017-09-27 17:05:30 -0700714// orderDeps reorders dependencies into a list such that if module A depends on B, then
715// A will precede B in the resultant list.
716// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800717// Note that directSharedDeps should be the analogous static library for each shared lib dep
718func 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 -0700719 // If A depends on B, then
720 // Every list containing A will also contain B later in the list
721 // So, after concatenating all lists, the final instance of B will have come from the same
722 // original list as the final instance of A
723 // So, the final instance of B will be later in the concatenation than the final A
724 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
725 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800726 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700727 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800728 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
729 }
730 for _, dep := range directSharedDeps {
731 orderedAllDeps = append(orderedAllDeps, dep)
732 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700733 }
734
Colin Crossb6715442017-10-24 11:13:31 -0700735 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700736
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800737 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700738 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800739 // resultant list to only what the caller has chosen to include in directStaticDeps
740 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700741
742 return orderedAllDeps, orderedDeclaredDeps
743}
744
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800745func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
746 // convert Module to Path
747 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
748 staticDepFiles := []android.Path{}
749 for _, dep := range staticDeps {
750 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
751 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700752 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800753 sharedDepFiles := []android.Path{}
754 for _, sharedDep := range sharedDeps {
755 staticAnalogue := sharedDep.staticVariant
756 if staticAnalogue != nil {
757 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
758 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
759 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700760 }
761
762 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800763 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700764
765 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700766}
767
Colin Cross635c3b02016-05-18 15:37:25 -0700768func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800769 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700770 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800771 moduleContextImpl: moduleContextImpl{
772 mod: c,
773 },
774 }
775 ctx.ctx = ctx
776
Colin Crossf18e1102017-11-16 14:33:08 -0800777 deps := c.depsToPaths(ctx)
778 if ctx.Failed() {
779 return
780 }
781
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700782 if c.Properties.Clang != nil && *c.Properties.Clang == false {
783 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
784 }
785
Colin Crossca860ac2016-01-04 14:34:37 -0800786 flags := Flags{
787 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800788 }
Colin Crossca860ac2016-01-04 14:34:37 -0800789 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800790 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800791 }
792 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700793 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800794 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700795 if c.stl != nil {
796 flags = c.stl.flags(ctx, flags)
797 }
Colin Cross16b23492016-01-06 14:41:07 -0800798 if c.sanitize != nil {
799 flags = c.sanitize.flags(ctx, flags)
800 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800801 if c.coverage != nil {
802 flags = c.coverage.flags(ctx, flags)
803 }
Stephen Craneba090d12017-05-09 15:44:35 -0700804 if c.lto != nil {
805 flags = c.lto.flags(ctx, flags)
806 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700807 if c.pgo != nil {
808 flags = c.pgo.flags(ctx, flags)
809 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800810 if c.xom != nil {
811 flags = c.xom.flags(ctx, flags)
812 }
Colin Crossca860ac2016-01-04 14:34:37 -0800813 for _, feature := range c.features {
814 flags = feature.flags(ctx, flags)
815 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800816 if ctx.Failed() {
817 return
818 }
819
Colin Crossb98c8b02016-07-29 13:44:28 -0700820 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
821 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
822 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800823
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800824 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
825 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700826 // We need access to all the flags seen by a source file.
827 if c.sabi != nil {
828 flags = c.sabi.flags(ctx, flags)
829 }
Colin Crossca860ac2016-01-04 14:34:37 -0800830 // Optimization to reduce size of build.ninja
831 // Replace the long list of flags for each file with a module-local variable
832 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
833 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
834 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
835 flags.CFlags = []string{"$cflags"}
836 flags.CppFlags = []string{"$cppflags"}
837 flags.AsFlags = []string{"$asflags"}
838
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700839 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800840 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700841 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800842 if ctx.Failed() {
843 return
844 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800845 }
846
Colin Crossca860ac2016-01-04 14:34:37 -0800847 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700848 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800849 if ctx.Failed() {
850 return
851 }
Colin Cross635c3b02016-05-18 15:37:25 -0700852 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700853 }
Colin Cross5049f022015-03-18 13:28:46 -0700854
Jiyong Park9d452992018-10-03 00:38:19 +0900855 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700856 c.installer.install(ctx, c.outputFile.Path())
857 if ctx.Failed() {
858 return
Colin Crossca860ac2016-01-04 14:34:37 -0800859 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700860 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800861}
862
Colin Crossb98c8b02016-07-29 13:44:28 -0700863func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800864 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700865 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800866 }
Colin Crossca860ac2016-01-04 14:34:37 -0800867 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800868}
869
Colin Crossca860ac2016-01-04 14:34:37 -0800870func (c *Module) begin(ctx BaseModuleContext) {
871 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700872 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700873 }
Colin Crossca860ac2016-01-04 14:34:37 -0800874 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700875 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800876 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700877 if c.stl != nil {
878 c.stl.begin(ctx)
879 }
Colin Cross16b23492016-01-06 14:41:07 -0800880 if c.sanitize != nil {
881 c.sanitize.begin(ctx)
882 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800883 if c.coverage != nil {
884 c.coverage.begin(ctx)
885 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800886 if c.sabi != nil {
887 c.sabi.begin(ctx)
888 }
Justin Yun8effde42017-06-23 19:24:43 +0900889 if c.vndkdep != nil {
890 c.vndkdep.begin(ctx)
891 }
Stephen Craneba090d12017-05-09 15:44:35 -0700892 if c.lto != nil {
893 c.lto.begin(ctx)
894 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700895 if c.pgo != nil {
896 c.pgo.begin(ctx)
897 }
Colin Crossca860ac2016-01-04 14:34:37 -0800898 for _, feature := range c.features {
899 feature.begin(ctx)
900 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700901 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700902 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700903 if err != nil {
904 ctx.PropertyErrorf("sdk_version", err.Error())
905 }
Nan Zhang0007d812017-11-07 10:57:05 -0800906 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700907 }
Colin Crossca860ac2016-01-04 14:34:37 -0800908}
909
Colin Cross37047f12016-12-13 17:06:13 -0800910func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700911 deps := Deps{}
912
913 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700914 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700915 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000916 // Add the PGO dependency (the clang_rt.profile runtime library), which
917 // sometimes depends on symbols from libgcc, before libgcc gets added
918 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700919 if c.pgo != nil {
920 deps = c.pgo.deps(ctx, deps)
921 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700922 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700923 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700924 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700925 if c.stl != nil {
926 deps = c.stl.deps(ctx, deps)
927 }
Colin Cross16b23492016-01-06 14:41:07 -0800928 if c.sanitize != nil {
929 deps = c.sanitize.deps(ctx, deps)
930 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000931 if c.coverage != nil {
932 deps = c.coverage.deps(ctx, deps)
933 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800934 if c.sabi != nil {
935 deps = c.sabi.deps(ctx, deps)
936 }
Justin Yun8effde42017-06-23 19:24:43 +0900937 if c.vndkdep != nil {
938 deps = c.vndkdep.deps(ctx, deps)
939 }
Stephen Craneba090d12017-05-09 15:44:35 -0700940 if c.lto != nil {
941 deps = c.lto.deps(ctx, deps)
942 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700943 for _, feature := range c.features {
944 deps = feature.deps(ctx, deps)
945 }
946
Colin Crossb6715442017-10-24 11:13:31 -0700947 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
948 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
949 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
950 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
951 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
952 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800953 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700954
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700955 for _, lib := range deps.ReexportSharedLibHeaders {
956 if !inList(lib, deps.SharedLibs) {
957 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
958 }
959 }
960
961 for _, lib := range deps.ReexportStaticLibHeaders {
962 if !inList(lib, deps.StaticLibs) {
963 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
964 }
965 }
966
Colin Cross5950f382016-12-13 12:50:57 -0800967 for _, lib := range deps.ReexportHeaderLibHeaders {
968 if !inList(lib, deps.HeaderLibs) {
969 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
970 }
971 }
972
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700973 for _, gen := range deps.ReexportGeneratedHeaders {
974 if !inList(gen, deps.GeneratedHeaders) {
975 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
976 }
977 }
978
Colin Crossc99deeb2016-04-11 15:06:20 -0700979 return deps
980}
981
Dan Albert7e9d2952016-08-04 13:02:36 -0700982func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800983 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700984 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800985 moduleContextImpl: moduleContextImpl{
986 mod: c,
987 },
988 }
989 ctx.ctx = ctx
990
Colin Crossca860ac2016-01-04 14:34:37 -0800991 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700992}
993
Jiyong Park7ed9de32018-10-15 22:25:07 +0900994// Split name#version into name and version
995func stubsLibNameAndVersion(name string) (string, string) {
996 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
997 version := name[sharp+1:]
998 libname := name[:sharp]
999 return libname, version
1000 }
1001 return name, ""
1002}
1003
Colin Cross1e676be2016-10-12 14:38:15 -07001004func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001005 ctx := &depsContext{
1006 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001007 moduleContextImpl: moduleContextImpl{
1008 mod: c,
1009 },
1010 }
1011 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001012
Colin Crossc99deeb2016-04-11 15:06:20 -07001013 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001014
Dan Albert914449f2016-06-17 16:45:24 -07001015 variantNdkLibs := []string{}
1016 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001017 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001018 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001019
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001020 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1021 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001022 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001023 // 1. Name of an NDK library that refers to a prebuilt module.
1024 // For each of these, it adds the name of the prebuilt module (which will be in
1025 // prebuilts/ndk) to the list of nonvariant libs.
1026 // 2. Name of an NDK library that refers to an ndk_library module.
1027 // For each of these, it adds the name of the ndk_library module to the list of
1028 // variant libs.
1029 // 3. Anything else (so anything that isn't an NDK library).
1030 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001031 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001032 // The caller can then know to add the variantLibs dependencies differently from the
1033 // nonvariantLibs
1034 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1035 variantLibs = []string{}
1036 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001037 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001038 // strip #version suffix out
1039 name, _ := stubsLibNameAndVersion(entry)
1040 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1041 if !inList(name, ndkMigratedLibs) {
1042 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001043 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001044 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001045 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001046 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1047 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1048 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1049 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001050 if actx.OtherModuleExists(vendorPublicLib) {
1051 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1052 } else {
1053 // This can happen if vendor_public_library module is defined in a
1054 // namespace that isn't visible to the current module. In that case,
1055 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001056 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001057 }
Dan Albert914449f2016-06-17 16:45:24 -07001058 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001059 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001060 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001061 }
1062 }
Dan Albert914449f2016-06-17 16:45:24 -07001063 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001064 }
1065
Dan Albert914449f2016-06-17 16:45:24 -07001066 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1067 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001068 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001069 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001070
Jiyong Park7ed9de32018-10-15 22:25:07 +09001071 if c.linker != nil {
1072 if library, ok := c.linker.(*libraryDecorator); ok {
1073 if library.buildStubs() {
1074 // Stubs lib does not have dependency to other libraries. Don't proceed.
1075 return
1076 }
1077 }
1078 }
1079
Colin Cross32ec36c2016-12-15 07:39:51 -08001080 for _, lib := range deps.HeaderLibs {
1081 depTag := headerDepTag
1082 if inList(lib, deps.ReexportHeaderLibHeaders) {
1083 depTag = headerExportDepTag
1084 }
1085 actx.AddVariationDependencies(nil, depTag, lib)
1086 }
Colin Cross5950f382016-12-13 12:50:57 -08001087
Dan Willemsen59339a22018-07-22 21:18:45 -07001088 actx.AddVariationDependencies([]blueprint.Variation{
1089 {Mutator: "link", Variation: "static"},
1090 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001091
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001092 for _, lib := range deps.StaticLibs {
1093 depTag := staticDepTag
1094 if inList(lib, deps.ReexportStaticLibHeaders) {
1095 depTag = staticExportDepTag
1096 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001097 actx.AddVariationDependencies([]blueprint.Variation{
1098 {Mutator: "link", Variation: "static"},
1099 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001100 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001101
Dan Willemsen59339a22018-07-22 21:18:45 -07001102 actx.AddVariationDependencies([]blueprint.Variation{
1103 {Mutator: "link", Variation: "static"},
1104 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001105
Jiyong Park25fc6a92018-11-18 18:02:45 +09001106 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1107 var variations []blueprint.Variation
1108 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
1109 versionVariantAvail := ctx.Os() == android.Android && !ctx.useVndk() && !c.inRecovery()
1110 if version != "" && versionVariantAvail {
1111 // Version is explicitly specified. i.e. libFoo#30
1112 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1113 depTag.explicitlyVersioned = true
1114 }
1115 actx.AddVariationDependencies(variations, depTag, name)
1116
1117 // If the version is not specified, add dependency to the latest stubs library.
1118 // The stubs library will be used when the depending module is built for APEX and
1119 // the dependent module is not in the same APEX.
1120 latestVersion := latestStubsVersionFor(actx.Config(), name)
1121 if version == "" && latestVersion != "" && versionVariantAvail {
1122 actx.AddVariationDependencies([]blueprint.Variation{
1123 {Mutator: "link", Variation: "shared"},
1124 {Mutator: "version", Variation: latestVersion},
1125 }, depTag, name)
1126 // Note that depTag.explicitlyVersioned is false in this case.
1127 }
1128 }
1129
Jiyong Park7ed9de32018-10-15 22:25:07 +09001130 // shared lib names without the #version suffix
1131 var sharedLibNames []string
1132
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001133 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001134 name, version := stubsLibNameAndVersion(lib)
1135 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001136 depTag := sharedDepTag
1137 if inList(lib, deps.ReexportSharedLibHeaders) {
1138 depTag = sharedExportDepTag
1139 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001140 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001141 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001142
Jiyong Park7ed9de32018-10-15 22:25:07 +09001143 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001144 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001145 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1146 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1147 // linking against both the stubs lib and the non-stubs lib at the same time.
1148 continue
1149 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001150 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001151 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001152
Dan Willemsen59339a22018-07-22 21:18:45 -07001153 actx.AddVariationDependencies([]blueprint.Variation{
1154 {Mutator: "link", Variation: "shared"},
1155 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001156
Colin Cross68861832016-07-08 10:41:41 -07001157 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001158
1159 for _, gen := range deps.GeneratedHeaders {
1160 depTag := genHeaderDepTag
1161 if inList(gen, deps.ReexportGeneratedHeaders) {
1162 depTag = genHeaderExportDepTag
1163 }
1164 actx.AddDependency(c, depTag, gen)
1165 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001166
Colin Cross42d48b72018-08-29 14:10:52 -07001167 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001168
1169 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001170 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001171 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001172 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001173 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001174 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001175 if deps.LinkerFlagsFile != "" {
1176 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1177 }
1178 if deps.DynamicLinker != "" {
1179 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001180 }
Dan Albert914449f2016-06-17 16:45:24 -07001181
1182 version := ctx.sdkVersion()
1183 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001184 {Mutator: "ndk_api", Variation: version},
1185 {Mutator: "link", Variation: "shared"},
1186 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001187 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001188 {Mutator: "ndk_api", Variation: version},
1189 {Mutator: "link", Variation: "shared"},
1190 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001191
1192 if vndkdep := c.vndkdep; vndkdep != nil {
1193 if vndkdep.isVndkExt() {
1194 baseModuleMode := vendorMode
1195 if actx.DeviceConfig().VndkVersion() == "" {
1196 baseModuleMode = coreMode
1197 }
1198 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001199 {Mutator: "image", Variation: baseModuleMode},
1200 {Mutator: "link", Variation: "shared"},
1201 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001202 }
1203 }
Colin Cross6362e272015-10-29 15:25:03 -07001204}
Colin Cross21b9a242015-03-24 14:15:58 -07001205
Colin Crosse40b4ea2018-10-02 22:25:58 -07001206func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001207 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1208 c.beginMutator(ctx)
1209 }
1210}
1211
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001212// Whether a module can link to another module, taking into
1213// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001214func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001215 if from.Target().Os != android.Android {
1216 // Host code is not restricted
1217 return
1218 }
1219 if from.Properties.UseVndk {
1220 // Though vendor code is limited by the vendor mutator,
1221 // each vendor-available module needs to check
1222 // link-type for VNDK.
1223 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001224 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001225 }
1226 return
1227 }
Nan Zhang0007d812017-11-07 10:57:05 -08001228 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001229 // Platform code can link to anything
1230 return
1231 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001232 if from.inRecovery() {
1233 // Recovery code is not NDK
1234 return
1235 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001236 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1237 // These are always allowed
1238 return
1239 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001240 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1241 // These are allowed, but they don't set sdk_version
1242 return
1243 }
1244 if _, ok := to.linker.(*stubDecorator); ok {
1245 // These aren't real libraries, but are the stub shared libraries that are included in
1246 // the NDK.
1247 return
1248 }
Nan Zhang0007d812017-11-07 10:57:05 -08001249 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001250 // NDK code linking to platform code is never okay.
1251 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1252 ctx.OtherModuleName(to))
1253 }
1254
1255 // At this point we know we have two NDK libraries, but we need to
1256 // check that we're not linking against anything built against a higher
1257 // API level, as it is only valid to link against older or equivalent
1258 // APIs.
1259
Inseob Kim01a28722018-04-11 09:48:45 +09001260 // Current can link against anything.
1261 if String(from.Properties.Sdk_version) != "current" {
1262 // Otherwise we need to check.
1263 if String(to.Properties.Sdk_version) == "current" {
1264 // Current can't be linked against by anything else.
1265 ctx.ModuleErrorf("links %q built against newer API version %q",
1266 ctx.OtherModuleName(to), "current")
1267 } else {
1268 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1269 if err != nil {
1270 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001271 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001272 String(from.Properties.Sdk_version))
1273 }
1274 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1275 if err != nil {
1276 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001277 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001278 String(to.Properties.Sdk_version))
1279 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001280
Inseob Kim01a28722018-04-11 09:48:45 +09001281 if toApi > fromApi {
1282 ctx.ModuleErrorf("links %q built against newer API version %q",
1283 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1284 }
1285 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001286 }
Dan Albert202fe492017-12-15 13:56:59 -08001287
1288 // Also check that the two STL choices are compatible.
1289 fromStl := from.stl.Properties.SelectedStl
1290 toStl := to.stl.Properties.SelectedStl
1291 if fromStl == "" || toStl == "" {
1292 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001293 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001294 // We can be permissive with the system "STL" since it is only the C++
1295 // ABI layer, but in the future we should make sure that everyone is
1296 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001297 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001298 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1299 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1300 to.stl.Properties.SelectedStl)
1301 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001302}
1303
Jiyong Park5fb8c102018-04-09 12:03:06 +09001304// Tests whether the dependent library is okay to be double loaded inside a single process.
1305// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1306// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1307// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1308func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1309 if _, ok := from.linker.(*libraryDecorator); !ok {
1310 return
1311 }
1312
1313 if inList(ctx.ModuleName(), llndkLibraries) ||
1314 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1315 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1316 depIsVndkSp := false
1317 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1318 depIsVndkSp = true
1319 }
1320 depIsVndk := false
1321 if to.vndkdep != nil && to.vndkdep.isVndk() {
1322 depIsVndk = true
1323 }
1324 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1325 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001326 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1327 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001328 ctx.OtherModuleName(to))
1329 }
1330 }
1331}
1332
Colin Crossc99deeb2016-04-11 15:06:20 -07001333// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001334func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001335 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001336
Jeff Gaston294356f2017-09-27 17:05:30 -07001337 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001338 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001339
Colin Crossd11fcda2017-10-23 17:59:01 -07001340 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001341 depName := ctx.OtherModuleName(dep)
1342 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001343
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001344 ccDep, _ := dep.(*Module)
1345 if ccDep == nil {
1346 // handling for a few module types that aren't cc Module but that are also supported
1347 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001348 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001349 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001350 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1351 genRule.GeneratedSourceFiles()...)
1352 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001353 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001354 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001355 // Support exported headers from a generated_sources dependency
1356 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001357 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001358 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001359 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001360 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001361 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001362 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001363 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001364 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001365 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001366 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001367 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1368 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1369
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001370 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001371 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001372 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001373 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001374 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001375 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001376 files := genRule.GeneratedSourceFiles()
1377 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001378 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001379 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001380 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 -07001381 }
1382 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001383 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001384 }
Colin Crossca860ac2016-01-04 14:34:37 -08001385 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001386 return
1387 }
1388
Colin Crossd11fcda2017-10-23 17:59:01 -07001389 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001390 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1391 return
1392 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001393 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001394 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001395 return
1396 }
1397
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001398 // re-exporting flags
1399 if depTag == reuseObjTag {
1400 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001401 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001402 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001403 depPaths.Objs = depPaths.Objs.Append(objs)
1404 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001405 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001406 return
1407 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001408 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001409
1410 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1411 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1412 // won't be matched to sharedDepTag and lateSharedDepTag.
1413 explicitlyVersioned := false
1414 if t, ok := depTag.(dependencyTag); ok {
1415 explicitlyVersioned = t.explicitlyVersioned
1416 t.explicitlyVersioned = false
1417 depTag = t
1418 }
1419
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001420 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001421 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
1422 depIsStubs := dependentLibrary.buildStubs()
1423 depHasStubs := ccDep.HasStubsVariants()
1424 depNameWithTarget := depName + "-" + ccDep.Target().String()
1425 depInSameApex := android.DirectlyInApex(ctx.Config(), c.ApexName(), depNameWithTarget)
1426 depInPlatform := !android.DirectlyInAnyApex(ctx.Config(), depNameWithTarget)
1427
1428 var useThisDep bool
1429 if depIsStubs && explicitlyVersioned {
1430 // Always respect dependency to the versioned stubs (i.e. libX#10)
1431 useThisDep = true
1432 } else if !depHasStubs {
1433 // Use non-stub variant if that is the only choice
1434 // (i.e. depending on a lib without stubs.version property)
1435 useThisDep = true
1436 } else if c.IsForPlatform() {
1437 // If not building for APEX, use stubs only when it is from
1438 // an APEX (and not from platform)
1439 useThisDep = (depInPlatform != depIsStubs)
1440 if c.inRecovery() {
1441 // However, for recovery modules, since there is no APEX there,
1442 // always link to non-stub variant
1443 useThisDep = !depIsStubs
1444 }
1445 } else {
1446 // If building for APEX, use stubs only when it is not from
1447 // the same APEX
1448 useThisDep = (depInSameApex != depIsStubs)
1449 }
1450
1451 if !useThisDep {
1452 return // stop processing this dep
1453 }
1454 }
1455
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001456 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001457 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001458 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001459 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001460 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001461
1462 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001463 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001464 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001465 // 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 -07001466 // Re-exported shared library headers must be included as well since they can help us with type information
1467 // about template instantiations (instantiated from their headers).
1468 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001469 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001470 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001471
Logan Chienf3511742017-10-31 18:04:35 +08001472 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001473 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001474 }
1475
Colin Cross26c34ed2016-09-30 17:10:16 -07001476 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001477 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001478
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001479 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001480 depFile := android.OptionalPath{}
1481
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001482 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001483 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001484 ptr = &depPaths.SharedLibs
1485 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001486 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001487 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001488 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001489 ptr = &depPaths.LateSharedLibs
1490 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001491 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001492 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001493 ptr = nil
1494 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001495 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001496 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001497 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001498 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001499 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001500 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001501 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001502 return
1503 }
1504
1505 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001506 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001507 for i := range missingDeps {
1508 missingDeps[i] += postfix
1509 }
1510 ctx.AddMissingDependencies(missingDeps)
1511 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001512 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001513 case headerDepTag:
1514 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001515 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001516 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001517 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001518 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001519 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001520 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001521 case dynamicLinkerDepTag:
1522 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001523 }
1524
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001525 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001526 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001527 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001528 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001529 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001530 return
1531 }
1532
1533 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001534 // in static libraries act as if they were whole static libraries. The same goes for
1535 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001536 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1537 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001538 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1539 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001540
Dan Willemsen581341d2017-02-09 16:16:31 -08001541 }
1542
Colin Cross26c34ed2016-09-30 17:10:16 -07001543 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001544 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001545 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001546 return
1547 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001548 *ptr = append(*ptr, linkFile.Path())
1549 }
1550
Colin Crossc99deeb2016-04-11 15:06:20 -07001551 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001552 dep := depFile
1553 if !dep.Valid() {
1554 dep = linkFile
1555 }
1556 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001557 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001558
Logan Chien43d34c32017-12-20 01:17:32 +08001559 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001560 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001561 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001562 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001563 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001564 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001565 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1566 if c.useVndk() && bothVendorAndCoreVariantsExist {
1567 // The vendor module in Make will have been renamed to not conflict with the core
1568 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001569 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001570 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001571 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001572 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1573 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001574 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001575 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001576 }
Logan Chien43d34c32017-12-20 01:17:32 +08001577 }
1578
1579 // Export the shared libs to Make.
1580 switch depTag {
1581 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Park27b188b2017-07-18 13:23:39 +09001582 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001583 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001584 c.Properties.AndroidMkSharedLibs = append(
1585 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001586 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1587 c.Properties.AndroidMkStaticLibs = append(
1588 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001589 case runtimeDepTag:
1590 c.Properties.AndroidMkRuntimeLibs = append(
1591 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001592 case wholeStaticDepTag:
1593 c.Properties.AndroidMkWholeStaticLibs = append(
1594 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001595 }
Colin Crossca860ac2016-01-04 14:34:37 -08001596 })
1597
Jeff Gaston294356f2017-09-27 17:05:30 -07001598 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001599 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001600
Colin Crossdd84e052017-05-17 13:44:16 -07001601 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001602 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001603 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001604 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001605 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1606
1607 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001608 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001609 }
Colin Crossdd84e052017-05-17 13:44:16 -07001610
Colin Crossca860ac2016-01-04 14:34:37 -08001611 return depPaths
1612}
1613
1614func (c *Module) InstallInData() bool {
1615 if c.installer == nil {
1616 return false
1617 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001618 return c.installer.inData()
1619}
1620
1621func (c *Module) InstallInSanitizerDir() bool {
1622 if c.installer == nil {
1623 return false
1624 }
1625 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001626 return true
1627 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001628 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001629}
1630
Jiyong Parkf9332f12018-02-01 00:54:12 +09001631func (c *Module) InstallInRecovery() bool {
1632 return c.inRecovery()
1633}
1634
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001635func (c *Module) HostToolPath() android.OptionalPath {
1636 if c.installer == nil {
1637 return android.OptionalPath{}
1638 }
1639 return c.installer.hostToolPath()
1640}
1641
Nan Zhangd4e641b2017-07-12 12:55:28 -07001642func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1643 return c.outputFile
1644}
1645
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001646func (c *Module) Srcs() android.Paths {
1647 if c.outputFile.Valid() {
1648 return android.Paths{c.outputFile.Path()}
1649 }
1650 return android.Paths{}
1651}
1652
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001653func (c *Module) static() bool {
1654 if static, ok := c.linker.(interface {
1655 static() bool
1656 }); ok {
1657 return static.static()
1658 }
1659 return false
1660}
1661
Colin Crossb60190a2018-09-04 16:28:17 -07001662func (c *Module) getMakeLinkType() string {
1663 if c.useVndk() {
1664 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1665 if inList(c.Name(), vndkPrivateLibraries) {
1666 return "native:vndk_private"
1667 } else {
1668 return "native:vndk"
1669 }
1670 } else {
1671 return "native:vendor"
1672 }
1673 } else if c.inRecovery() {
1674 return "native:recovery"
1675 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1676 return "native:ndk:none:none"
1677 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1678 //family, link := getNdkStlFamilyAndLinkType(c)
1679 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1680 } else {
1681 return "native:platform"
1682 }
1683}
1684
Jiyong Park9d452992018-10-03 00:38:19 +09001685// Overrides ApexModule.IsInstallabeToApex()
1686// Only shared libraries are installable to APEX.
1687func (c *Module) IsInstallableToApex() bool {
1688 if shared, ok := c.linker.(interface {
1689 shared() bool
1690 }); ok {
1691 return shared.shared()
1692 }
1693 return false
1694}
1695
Colin Cross2ba19d92015-05-07 15:44:20 -07001696//
Colin Crosscfad1192015-11-02 16:43:11 -08001697// Defaults
1698//
Colin Crossca860ac2016-01-04 14:34:37 -08001699type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001700 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001701 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001702 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001703}
1704
Colin Cross635c3b02016-05-18 15:37:25 -07001705func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001706}
1707
Colin Cross1e676be2016-10-12 14:38:15 -07001708func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1709}
1710
Colin Cross36242852017-06-23 15:06:31 -07001711func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001712 return DefaultsFactory()
1713}
1714
Colin Cross36242852017-06-23 15:06:31 -07001715func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001716 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001717
Colin Cross36242852017-06-23 15:06:31 -07001718 module.AddProperties(props...)
1719 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001720 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001721 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001722 &BaseCompilerProperties{},
1723 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001724 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001725 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001726 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001727 &TestProperties{},
1728 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001729 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001730 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001731 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001732 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001733 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001734 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001735 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001736 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001737 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001738 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001739 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001740 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001741 )
Colin Crosscfad1192015-11-02 16:43:11 -08001742
Colin Cross1f44a3a2017-07-07 14:33:33 -07001743 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001744 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001745
1746 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001747}
1748
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001749const (
1750 // coreMode is the variant used for framework-private libraries, or
1751 // SDK libraries. (which framework-private libraries can use)
1752 coreMode = "core"
1753
1754 // vendorMode is the variant used for /vendor code that compiles
1755 // against the VNDK.
1756 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001757
1758 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001759)
1760
Jiyong Park6a43f042017-10-12 23:05:00 +09001761func squashVendorSrcs(m *Module) {
1762 if lib, ok := m.compiler.(*libraryDecorator); ok {
1763 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1764 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1765
1766 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1767 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1768 }
1769}
1770
Jiyong Parkf9332f12018-02-01 00:54:12 +09001771func squashRecoverySrcs(m *Module) {
1772 if lib, ok := m.compiler.(*libraryDecorator); ok {
1773 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1774 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1775
1776 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1777 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1778 }
1779}
1780
1781func imageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001782 if mctx.Os() != android.Android {
1783 return
1784 }
1785
Jiyong Park7ed9de32018-10-15 22:25:07 +09001786 if g, ok := mctx.Module().(*genrule.Module); ok {
1787 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001788 var coreVariantNeeded bool = false
1789 var vendorVariantNeeded bool = false
1790 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001791 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001792 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001793 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001794 coreVariantNeeded = true
1795 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001796 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001797 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001798 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001799 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001800 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001801 if Bool(props.Recovery_available) {
1802 recoveryVariantNeeded = true
1803 }
1804
Jiyong Park413cc742018-06-19 01:46:06 +09001805 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001806 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001807 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001808 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001809 recoveryVariantNeeded = false
1810 }
1811 }
1812
Jiyong Park3f736c92018-05-24 13:36:56 +09001813 var variants []string
1814 if coreVariantNeeded {
1815 variants = append(variants, coreMode)
1816 }
1817 if vendorVariantNeeded {
1818 variants = append(variants, vendorMode)
1819 }
1820 if recoveryVariantNeeded {
1821 variants = append(variants, recoveryMode)
1822 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001823 mod := mctx.CreateVariations(variants...)
1824 for i, v := range variants {
1825 if v == recoveryMode {
1826 m := mod[i].(*genrule.Module)
1827 m.Extra.(*GenruleExtraProperties).InRecovery = true
1828 }
1829 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001830 }
1831 }
1832
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001833 m, ok := mctx.Module().(*Module)
1834 if !ok {
1835 return
1836 }
1837
1838 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001839 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09001840 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08001841
1842 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001843 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001844 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001845 return
1846 }
Logan Chienf3511742017-10-31 18:04:35 +08001847
1848 if vndkdep := m.vndkdep; vndkdep != nil {
1849 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09001850 if productSpecific {
1851 mctx.PropertyErrorf("product_specific",
1852 "product_specific must not be true when `vndk: {enabled: true}`")
1853 return
1854 }
Logan Chienf3511742017-10-31 18:04:35 +08001855 if vendorSpecific {
1856 if !vndkdep.isVndkExt() {
1857 mctx.PropertyErrorf("vndk",
1858 "must set `extends: \"...\"` to vndk extension")
1859 return
1860 }
1861 } else {
1862 if vndkdep.isVndkExt() {
1863 mctx.PropertyErrorf("vndk",
1864 "must set `vendor: true` to set `extends: %q`",
1865 m.getVndkExtendsModuleName())
1866 return
1867 }
1868 if m.VendorProperties.Vendor_available == nil {
1869 mctx.PropertyErrorf("vndk",
1870 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1871 return
1872 }
1873 }
1874 } else {
1875 if vndkdep.isVndkSp() {
1876 mctx.PropertyErrorf("vndk",
1877 "must set `enabled: true` to set `support_system_process: true`")
1878 return
1879 }
1880 if vndkdep.isVndkExt() {
1881 mctx.PropertyErrorf("vndk",
1882 "must set `enabled: true` to set `extends: %q`",
1883 m.getVndkExtendsModuleName())
1884 return
1885 }
Justin Yun8effde42017-06-23 19:24:43 +09001886 }
1887 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001888
Jiyong Parkf9332f12018-02-01 00:54:12 +09001889 var coreVariantNeeded bool = false
1890 var vendorVariantNeeded bool = false
1891 var recoveryVariantNeeded bool = false
1892
Justin Yun71549282017-11-17 12:10:28 +09001893 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001894 // If the device isn't compiling against the VNDK, we always
1895 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001896 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001897 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1898 // LL-NDK stubs only exist in the vendor variant, since the
1899 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001900 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001901 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1902 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001903 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001904 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001905 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1906 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001907 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001908 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001909 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001910 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001911 coreVariantNeeded = true
1912 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001913 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001914 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001915 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001916 } else {
1917 // This is either in /system (or similar: /data), or is a
1918 // modules built with the NDK. Modules built with the NDK
1919 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001920 coreVariantNeeded = true
1921 }
1922
1923 if Bool(m.Properties.Recovery_available) {
1924 recoveryVariantNeeded = true
1925 }
1926
1927 if m.ModuleBase.InstallInRecovery() {
1928 recoveryVariantNeeded = true
1929 coreVariantNeeded = false
1930 }
1931
Jiyong Park413cc742018-06-19 01:46:06 +09001932 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001933 primaryArch := mctx.Config().DevicePrimaryArchType()
1934 moduleArch := m.Target().Arch.ArchType
1935 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001936 recoveryVariantNeeded = false
1937 }
1938 }
1939
Jiyong Parkf9332f12018-02-01 00:54:12 +09001940 var variants []string
1941 if coreVariantNeeded {
1942 variants = append(variants, coreMode)
1943 }
1944 if vendorVariantNeeded {
1945 variants = append(variants, vendorMode)
1946 }
1947 if recoveryVariantNeeded {
1948 variants = append(variants, recoveryMode)
1949 }
1950 mod := mctx.CreateVariations(variants...)
1951 for i, v := range variants {
1952 if v == vendorMode {
1953 m := mod[i].(*Module)
1954 m.Properties.UseVndk = true
1955 squashVendorSrcs(m)
1956 } else if v == recoveryMode {
1957 m := mod[i].(*Module)
1958 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09001959 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001960 squashRecoverySrcs(m)
1961 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001962 }
1963}
1964
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001965func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001966 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001967 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1968 }
Colin Cross6510f912017-11-29 00:27:14 -08001969 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001970}
1971
Colin Cross06a931b2015-10-28 17:23:31 -07001972var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001973var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001974var BoolPtr = proptools.BoolPtr
1975var String = proptools.String
1976var StringPtr = proptools.StringPtr