blob: ce28a3bf4918e9d68f6e1f2d3a27e42bbbc78f50 [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 Parkda6eb592018-12-19 17:12:36 +090037 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070038 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +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
Jiyong Parkde866cb2018-12-07 23:08:36 +0900186 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"`
192 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700193
194 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800195
196 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
197 // file
198 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900199
200 // Make this module available when building for recovery
201 Recovery_available *bool
202
203 InRecovery bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700204}
205
206type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900207 // whether this module should be allowed to be directly depended by other
208 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
209 // If set to true, two variants will be built separately, one like
210 // normal, and the other limited to the set of libraries and headers
211 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700212 //
213 // The vendor variant may be used with a different (newer) /system,
214 // so it shouldn't have any unversioned runtime dependencies, or
215 // make assumptions about the system that may not be true in the
216 // future.
217 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900218 // If set to false, this module becomes inaccessible from /vendor modules.
219 //
220 // Default value is true when vndk: {enabled: true} or vendor: true.
221 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700222 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
223 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900224
225 // whether this module is capable of being loaded with other instance
226 // (possibly an older version) of the same module in the same process.
227 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
228 // can be double loaded in a vendor process if the library is also a
229 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
230 // explicitly marked as `double_loadable: true` by the owner, or the dependency
231 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
232 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800233}
234
Colin Crossca860ac2016-01-04 14:34:37 -0800235type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800236 static() bool
237 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700238 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700239 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800240 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700241 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900242 isVndk() bool
243 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800244 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900245 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800246 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700247 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700248 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800249 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800250 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800251 useClangLld(actx ModuleContext) bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900252 isApex() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800253}
254
255type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700256 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800257 ModuleContextIntf
258}
259
260type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700261 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800262 ModuleContextIntf
263}
264
Colin Cross37047f12016-12-13 17:06:13 -0800265type DepsContext interface {
266 android.BottomUpMutatorContext
267 ModuleContextIntf
268}
269
Colin Crossca860ac2016-01-04 14:34:37 -0800270type feature interface {
271 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800272 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800273 flags(ctx ModuleContext, flags Flags) Flags
274 props() []interface{}
275}
276
277type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700278 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800279 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800280 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700281 compilerProps() []interface{}
282
Colin Cross76fada02016-07-27 10:31:13 -0700283 appendCflags([]string)
284 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700285 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800286}
287
288type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700289 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800290 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700291 linkerFlags(ctx ModuleContext, flags Flags) Flags
292 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800293 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700294
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700295 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700296 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800297}
298
299type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700300 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700301 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800302 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700303 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700304 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800305}
306
Colin Crossc99deeb2016-04-11 15:06:20 -0700307type dependencyTag struct {
308 blueprint.BaseDependencyTag
309 name string
310 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700311
312 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900313
314 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700315}
316
317var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700318 sharedDepTag = dependencyTag{name: "shared", library: true}
319 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
320 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
321 staticDepTag = dependencyTag{name: "static", library: true}
322 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
323 lateStaticDepTag = dependencyTag{name: "late static", library: true}
324 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800325 headerDepTag = dependencyTag{name: "header", library: true}
326 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700327 genSourceDepTag = dependencyTag{name: "gen source"}
328 genHeaderDepTag = dependencyTag{name: "gen header"}
329 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
330 objDepTag = dependencyTag{name: "obj"}
331 crtBeginDepTag = dependencyTag{name: "crtbegin"}
332 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700333 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
334 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700335 reuseObjTag = dependencyTag{name: "reuse objects"}
336 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
337 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800338 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800339 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700340)
341
Colin Crossca860ac2016-01-04 14:34:37 -0800342// Module contains the properties and members used by all C/C++ module types, and implements
343// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
344// to construct the output file. Behavior can be customized with a Customizer interface
345type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700346 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700347 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900348 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700349
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700350 Properties BaseProperties
351 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700352
Colin Crossca860ac2016-01-04 14:34:37 -0800353 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700354 hod android.HostOrDeviceSupported
355 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700356
Colin Crossca860ac2016-01-04 14:34:37 -0800357 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700358 features []feature
359 compiler compiler
360 linker linker
361 installer installer
362 stl *stl
363 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800364 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800365 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900366 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700367 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700368 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800369 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800370
371 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700372
Colin Cross635c3b02016-05-18 15:37:25 -0700373 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800374
Colin Crossb98c8b02016-07-29 13:44:28 -0700375 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700376
377 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800378
379 // Flags used to compile this module
380 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700381
382 // 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 -0800383 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700384 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800385 depsInLinkOrder android.Paths
386
387 // only non-nil when this is a shared library that reuses the objects of a static library
388 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700389}
390
Jiyong Parkc20eee32018-09-05 22:36:17 +0900391func (c *Module) OutputFile() android.OptionalPath {
392 return c.outputFile
393}
394
Colin Cross36242852017-06-23 15:06:31 -0700395func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700396 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800397 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700398 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800399 }
400 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700401 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800402 }
403 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700404 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800405 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700406 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700407 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700408 }
Colin Cross16b23492016-01-06 14:41:07 -0800409 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700410 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800411 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800412 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700413 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800414 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800415 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700416 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800417 }
Justin Yun8effde42017-06-23 19:24:43 +0900418 if c.vndkdep != nil {
419 c.AddProperties(c.vndkdep.props()...)
420 }
Stephen Craneba090d12017-05-09 15:44:35 -0700421 if c.lto != nil {
422 c.AddProperties(c.lto.props()...)
423 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700424 if c.pgo != nil {
425 c.AddProperties(c.pgo.props()...)
426 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800427 if c.xom != nil {
428 c.AddProperties(c.xom.props()...)
429 }
Colin Crossca860ac2016-01-04 14:34:37 -0800430 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700431 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800432 }
Colin Crossc472d572015-03-17 15:06:21 -0700433
Colin Crossa9d8bee2018-10-02 13:59:46 -0700434 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
435 switch class {
436 case android.Device:
437 return ctx.Config().DevicePrefer32BitExecutables()
438 case android.HostCross:
439 // Windows builds always prefer 32-bit
440 return true
441 default:
442 return false
443 }
444 })
Colin Cross36242852017-06-23 15:06:31 -0700445 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700446
Colin Cross1f44a3a2017-07-07 14:33:33 -0700447 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700448
Jiyong Park9d452992018-10-03 00:38:19 +0900449 android.InitApexModule(c)
450
Colin Cross36242852017-06-23 15:06:31 -0700451 return c
Colin Crossc472d572015-03-17 15:06:21 -0700452}
453
Colin Crossb916a382016-07-29 17:28:03 -0700454// Returns true for dependency roots (binaries)
455// TODO(ccross): also handle dlopenable libraries
456func (c *Module) isDependencyRoot() bool {
457 if root, ok := c.linker.(interface {
458 isDependencyRoot() bool
459 }); ok {
460 return root.isDependencyRoot()
461 }
462 return false
463}
464
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700465func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700466 return c.Properties.UseVndk
467}
468
Justin Yun8effde42017-06-23 19:24:43 +0900469func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800470 if vndkdep := c.vndkdep; vndkdep != nil {
471 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900472 }
473 return false
474}
475
Yi Kong7e53c572018-02-14 18:16:12 +0800476func (c *Module) isPgoCompile() bool {
477 if pgo := c.pgo; pgo != nil {
478 return pgo.Properties.PgoCompile
479 }
480 return false
481}
482
Logan Chienf3511742017-10-31 18:04:35 +0800483func (c *Module) isVndkSp() bool {
484 if vndkdep := c.vndkdep; vndkdep != nil {
485 return vndkdep.isVndkSp()
486 }
487 return false
488}
489
490func (c *Module) isVndkExt() bool {
491 if vndkdep := c.vndkdep; vndkdep != nil {
492 return vndkdep.isVndkExt()
493 }
494 return false
495}
496
497func (c *Module) getVndkExtendsModuleName() string {
498 if vndkdep := c.vndkdep; vndkdep != nil {
499 return vndkdep.getVndkExtendsModuleName()
500 }
501 return ""
502}
503
Jiyong Park82e2bf32017-08-16 14:05:54 +0900504// Returns true only when this module is configured to have core and vendor
505// variants.
506func (c *Module) hasVendorVariant() bool {
507 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
508}
509
Jiyong Parkf9332f12018-02-01 00:54:12 +0900510func (c *Module) inRecovery() bool {
511 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
512}
513
514func (c *Module) onlyInRecovery() bool {
515 return c.ModuleBase.InstallInRecovery()
516}
517
Jiyong Park25fc6a92018-11-18 18:02:45 +0900518func (c *Module) IsStubs() bool {
519 if library, ok := c.linker.(*libraryDecorator); ok {
520 return library.buildStubs()
521 }
522 return false
523}
524
525func (c *Module) HasStubsVariants() bool {
526 if library, ok := c.linker.(*libraryDecorator); ok {
527 return len(library.Properties.Stubs.Versions) > 0
528 }
529 return false
530}
531
Colin Crossca860ac2016-01-04 14:34:37 -0800532type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700533 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800534 moduleContextImpl
535}
536
Colin Cross37047f12016-12-13 17:06:13 -0800537type depsContext struct {
538 android.BottomUpMutatorContext
539 moduleContextImpl
540}
541
Colin Crossca860ac2016-01-04 14:34:37 -0800542type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700543 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800544 moduleContextImpl
545}
546
Jiyong Park2db76922017-11-08 16:03:48 +0900547func (ctx *moduleContext) SocSpecific() bool {
548 return ctx.ModuleContext.SocSpecific() ||
549 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700550}
551
Colin Crossca860ac2016-01-04 14:34:37 -0800552type moduleContextImpl struct {
553 mod *Module
554 ctx BaseModuleContext
555}
556
Colin Crossb98c8b02016-07-29 13:44:28 -0700557func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800558 return ctx.mod.toolchain(ctx.ctx)
559}
560
561func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000562 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800563}
564
565func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700566 if static, ok := ctx.mod.linker.(interface {
567 staticBinary() bool
568 }); ok {
569 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800570 }
Colin Crossb916a382016-07-29 17:28:03 -0700571 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800572}
573
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700574func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900575 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800576 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700577 }
578 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800579}
580
581func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700582 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700583 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900584 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700585 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900586 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
587 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
588 return "current"
589 }
590 return platform_vndk_ver
591 }
592 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800593 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900594 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700595 }
596 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800597}
598
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700599func (ctx *moduleContextImpl) useVndk() bool {
600 return ctx.mod.useVndk()
601}
Justin Yun8effde42017-06-23 19:24:43 +0900602
Logan Chienf3511742017-10-31 18:04:35 +0800603func (ctx *moduleContextImpl) isVndk() bool {
604 return ctx.mod.isVndk()
605}
606
Yi Kong7e53c572018-02-14 18:16:12 +0800607func (ctx *moduleContextImpl) isPgoCompile() bool {
608 return ctx.mod.isPgoCompile()
609}
610
Justin Yun8effde42017-06-23 19:24:43 +0900611func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800612 return ctx.mod.isVndkSp()
613}
614
615func (ctx *moduleContextImpl) isVndkExt() bool {
616 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900617}
618
Jiyong Parkf9332f12018-02-01 00:54:12 +0900619func (ctx *moduleContextImpl) inRecovery() bool {
620 return ctx.mod.inRecovery()
621}
622
Logan Chien2f2b8902018-07-10 15:01:19 +0800623// Check whether ABI dumps should be created for this module.
624func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
625 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
626 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800627 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800628 if sanitize := ctx.mod.sanitize; sanitize != nil {
629 if !sanitize.isVariantOnProductionDevice() {
630 return false
631 }
632 }
633 if !ctx.ctx.Device() {
634 // Host modules do not need ABI dumps.
635 return false
636 }
Logan Chienfa478c02018-12-28 16:25:39 +0800637 if !ctx.mod.IsForPlatform() {
638 // APEX variants do not need ABI dumps.
639 return false
640 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800641 if inList(ctx.baseModuleName(), llndkLibraries) {
642 return true
643 }
Logan Chienf4b79c62018-08-02 02:27:02 +0800644 if inList(ctx.baseModuleName(), ndkMigratedLibs) {
645 return true
646 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800647 if ctx.useVndk() && ctx.isVndk() {
648 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
649 // VNDK-private.
650 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
651 }
652 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800653}
654
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700655func (ctx *moduleContextImpl) selectedStl() string {
656 if stl := ctx.mod.stl; stl != nil {
657 return stl.Properties.SelectedStl
658 }
659 return ""
660}
661
Ivan Lozanobd721262018-11-27 14:33:03 -0800662func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
663 return ctx.mod.linker.useClangLld(actx)
664}
665
Colin Crossce75d2c2016-10-06 16:12:58 -0700666func (ctx *moduleContextImpl) baseModuleName() string {
667 return ctx.mod.ModuleBase.BaseModuleName()
668}
669
Logan Chienf3511742017-10-31 18:04:35 +0800670func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
671 return ctx.mod.getVndkExtendsModuleName()
672}
673
Jiyong Park25fc6a92018-11-18 18:02:45 +0900674// Tests if this module is built for APEX
675func (ctx *moduleContextImpl) isApex() bool {
676 return ctx.mod.ApexName() != ""
677}
678
Colin Cross635c3b02016-05-18 15:37:25 -0700679func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800680 return &Module{
681 hod: hod,
682 multilib: multilib,
683 }
684}
685
Colin Cross635c3b02016-05-18 15:37:25 -0700686func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800687 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700688 module.features = []feature{
689 &tidyFeature{},
690 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700691 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800692 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800693 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800694 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900695 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700696 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700697 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800698 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800699 return module
700}
701
Colin Crossce75d2c2016-10-06 16:12:58 -0700702func (c *Module) Prebuilt() *android.Prebuilt {
703 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
704 return p.prebuilt()
705 }
706 return nil
707}
708
709func (c *Module) Name() string {
710 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700711 if p, ok := c.linker.(interface {
712 Name(string) string
713 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700714 name = p.Name(name)
715 }
716 return name
717}
718
Jeff Gaston294356f2017-09-27 17:05:30 -0700719// orderDeps reorders dependencies into a list such that if module A depends on B, then
720// A will precede B in the resultant list.
721// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800722// Note that directSharedDeps should be the analogous static library for each shared lib dep
723func 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 -0700724 // If A depends on B, then
725 // Every list containing A will also contain B later in the list
726 // So, after concatenating all lists, the final instance of B will have come from the same
727 // original list as the final instance of A
728 // So, the final instance of B will be later in the concatenation than the final A
729 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
730 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800731 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700732 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800733 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
734 }
735 for _, dep := range directSharedDeps {
736 orderedAllDeps = append(orderedAllDeps, dep)
737 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700738 }
739
Colin Crossb6715442017-10-24 11:13:31 -0700740 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700741
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800742 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700743 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800744 // resultant list to only what the caller has chosen to include in directStaticDeps
745 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700746
747 return orderedAllDeps, orderedDeclaredDeps
748}
749
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800750func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
751 // convert Module to Path
752 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
753 staticDepFiles := []android.Path{}
754 for _, dep := range staticDeps {
755 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
756 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700757 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800758 sharedDepFiles := []android.Path{}
759 for _, sharedDep := range sharedDeps {
760 staticAnalogue := sharedDep.staticVariant
761 if staticAnalogue != nil {
762 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
763 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
764 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700765 }
766
767 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800768 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700769
770 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700771}
772
Colin Cross635c3b02016-05-18 15:37:25 -0700773func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800774 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700775 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800776 moduleContextImpl: moduleContextImpl{
777 mod: c,
778 },
779 }
780 ctx.ctx = ctx
781
Colin Crossf18e1102017-11-16 14:33:08 -0800782 deps := c.depsToPaths(ctx)
783 if ctx.Failed() {
784 return
785 }
786
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700787 if c.Properties.Clang != nil && *c.Properties.Clang == false {
788 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
789 }
790
Colin Crossca860ac2016-01-04 14:34:37 -0800791 flags := Flags{
792 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800793 }
Colin Crossca860ac2016-01-04 14:34:37 -0800794 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800795 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800796 }
797 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700798 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800799 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700800 if c.stl != nil {
801 flags = c.stl.flags(ctx, flags)
802 }
Colin Cross16b23492016-01-06 14:41:07 -0800803 if c.sanitize != nil {
804 flags = c.sanitize.flags(ctx, flags)
805 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800806 if c.coverage != nil {
807 flags = c.coverage.flags(ctx, flags)
808 }
Stephen Craneba090d12017-05-09 15:44:35 -0700809 if c.lto != nil {
810 flags = c.lto.flags(ctx, flags)
811 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700812 if c.pgo != nil {
813 flags = c.pgo.flags(ctx, flags)
814 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800815 if c.xom != nil {
816 flags = c.xom.flags(ctx, flags)
817 }
Colin Crossca860ac2016-01-04 14:34:37 -0800818 for _, feature := range c.features {
819 flags = feature.flags(ctx, flags)
820 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800821 if ctx.Failed() {
822 return
823 }
824
Colin Crossb98c8b02016-07-29 13:44:28 -0700825 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
826 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
827 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800828
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800829 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
830 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700831 // We need access to all the flags seen by a source file.
832 if c.sabi != nil {
833 flags = c.sabi.flags(ctx, flags)
834 }
Colin Crossca860ac2016-01-04 14:34:37 -0800835 // Optimization to reduce size of build.ninja
836 // Replace the long list of flags for each file with a module-local variable
837 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
838 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
839 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
840 flags.CFlags = []string{"$cflags"}
841 flags.CppFlags = []string{"$cppflags"}
842 flags.AsFlags = []string{"$asflags"}
843
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700844 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800845 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700846 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800847 if ctx.Failed() {
848 return
849 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800850 }
851
Colin Crossca860ac2016-01-04 14:34:37 -0800852 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700853 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800854 if ctx.Failed() {
855 return
856 }
Colin Cross635c3b02016-05-18 15:37:25 -0700857 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700858 }
Colin Cross5049f022015-03-18 13:28:46 -0700859
Jiyong Park9d452992018-10-03 00:38:19 +0900860 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700861 c.installer.install(ctx, c.outputFile.Path())
862 if ctx.Failed() {
863 return
Colin Crossca860ac2016-01-04 14:34:37 -0800864 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700865 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800866}
867
Colin Crossb98c8b02016-07-29 13:44:28 -0700868func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800869 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700870 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800871 }
Colin Crossca860ac2016-01-04 14:34:37 -0800872 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800873}
874
Colin Crossca860ac2016-01-04 14:34:37 -0800875func (c *Module) begin(ctx BaseModuleContext) {
876 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700877 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700878 }
Colin Crossca860ac2016-01-04 14:34:37 -0800879 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700880 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800881 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700882 if c.stl != nil {
883 c.stl.begin(ctx)
884 }
Colin Cross16b23492016-01-06 14:41:07 -0800885 if c.sanitize != nil {
886 c.sanitize.begin(ctx)
887 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800888 if c.coverage != nil {
889 c.coverage.begin(ctx)
890 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800891 if c.sabi != nil {
892 c.sabi.begin(ctx)
893 }
Justin Yun8effde42017-06-23 19:24:43 +0900894 if c.vndkdep != nil {
895 c.vndkdep.begin(ctx)
896 }
Stephen Craneba090d12017-05-09 15:44:35 -0700897 if c.lto != nil {
898 c.lto.begin(ctx)
899 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700900 if c.pgo != nil {
901 c.pgo.begin(ctx)
902 }
Colin Crossca860ac2016-01-04 14:34:37 -0800903 for _, feature := range c.features {
904 feature.begin(ctx)
905 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700906 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700907 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700908 if err != nil {
909 ctx.PropertyErrorf("sdk_version", err.Error())
910 }
Nan Zhang0007d812017-11-07 10:57:05 -0800911 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700912 }
Colin Crossca860ac2016-01-04 14:34:37 -0800913}
914
Colin Cross37047f12016-12-13 17:06:13 -0800915func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700916 deps := Deps{}
917
918 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700919 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700920 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000921 // Add the PGO dependency (the clang_rt.profile runtime library), which
922 // sometimes depends on symbols from libgcc, before libgcc gets added
923 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700924 if c.pgo != nil {
925 deps = c.pgo.deps(ctx, deps)
926 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700927 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700928 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700929 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700930 if c.stl != nil {
931 deps = c.stl.deps(ctx, deps)
932 }
Colin Cross16b23492016-01-06 14:41:07 -0800933 if c.sanitize != nil {
934 deps = c.sanitize.deps(ctx, deps)
935 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000936 if c.coverage != nil {
937 deps = c.coverage.deps(ctx, deps)
938 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800939 if c.sabi != nil {
940 deps = c.sabi.deps(ctx, deps)
941 }
Justin Yun8effde42017-06-23 19:24:43 +0900942 if c.vndkdep != nil {
943 deps = c.vndkdep.deps(ctx, deps)
944 }
Stephen Craneba090d12017-05-09 15:44:35 -0700945 if c.lto != nil {
946 deps = c.lto.deps(ctx, deps)
947 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700948 for _, feature := range c.features {
949 deps = feature.deps(ctx, deps)
950 }
951
Colin Crossb6715442017-10-24 11:13:31 -0700952 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
953 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
954 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
955 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
956 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
957 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800958 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700959
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700960 for _, lib := range deps.ReexportSharedLibHeaders {
961 if !inList(lib, deps.SharedLibs) {
962 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
963 }
964 }
965
966 for _, lib := range deps.ReexportStaticLibHeaders {
967 if !inList(lib, deps.StaticLibs) {
968 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
969 }
970 }
971
Colin Cross5950f382016-12-13 12:50:57 -0800972 for _, lib := range deps.ReexportHeaderLibHeaders {
973 if !inList(lib, deps.HeaderLibs) {
974 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
975 }
976 }
977
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700978 for _, gen := range deps.ReexportGeneratedHeaders {
979 if !inList(gen, deps.GeneratedHeaders) {
980 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
981 }
982 }
983
Colin Crossc99deeb2016-04-11 15:06:20 -0700984 return deps
985}
986
Dan Albert7e9d2952016-08-04 13:02:36 -0700987func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800988 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700989 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800990 moduleContextImpl: moduleContextImpl{
991 mod: c,
992 },
993 }
994 ctx.ctx = ctx
995
Colin Crossca860ac2016-01-04 14:34:37 -0800996 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700997}
998
Jiyong Park7ed9de32018-10-15 22:25:07 +0900999// Split name#version into name and version
1000func stubsLibNameAndVersion(name string) (string, string) {
1001 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1002 version := name[sharp+1:]
1003 libname := name[:sharp]
1004 return libname, version
1005 }
1006 return name, ""
1007}
1008
Colin Cross1e676be2016-10-12 14:38:15 -07001009func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001010 ctx := &depsContext{
1011 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001012 moduleContextImpl: moduleContextImpl{
1013 mod: c,
1014 },
1015 }
1016 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001017
Colin Crossc99deeb2016-04-11 15:06:20 -07001018 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001019
Dan Albert914449f2016-06-17 16:45:24 -07001020 variantNdkLibs := []string{}
1021 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001022 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001023 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001024
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001025 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1026 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001027 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001028 // 1. Name of an NDK library that refers to a prebuilt module.
1029 // For each of these, it adds the name of the prebuilt module (which will be in
1030 // prebuilts/ndk) to the list of nonvariant libs.
1031 // 2. Name of an NDK library that refers to an ndk_library module.
1032 // For each of these, it adds the name of the ndk_library module to the list of
1033 // variant libs.
1034 // 3. Anything else (so anything that isn't an NDK library).
1035 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001036 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001037 // The caller can then know to add the variantLibs dependencies differently from the
1038 // nonvariantLibs
1039 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1040 variantLibs = []string{}
1041 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001042 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001043 // strip #version suffix out
1044 name, _ := stubsLibNameAndVersion(entry)
1045 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1046 if !inList(name, ndkMigratedLibs) {
1047 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001048 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001049 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001050 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001051 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1052 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1053 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1054 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001055 if actx.OtherModuleExists(vendorPublicLib) {
1056 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1057 } else {
1058 // This can happen if vendor_public_library module is defined in a
1059 // namespace that isn't visible to the current module. In that case,
1060 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001061 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001062 }
Dan Albert914449f2016-06-17 16:45:24 -07001063 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001064 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001065 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001066 }
1067 }
Dan Albert914449f2016-06-17 16:45:24 -07001068 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001069 }
1070
Dan Albert914449f2016-06-17 16:45:24 -07001071 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1072 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001073 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001074 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001075
Jiyong Park7ed9de32018-10-15 22:25:07 +09001076 if c.linker != nil {
1077 if library, ok := c.linker.(*libraryDecorator); ok {
1078 if library.buildStubs() {
1079 // Stubs lib does not have dependency to other libraries. Don't proceed.
1080 return
1081 }
1082 }
1083 }
1084
Colin Cross32ec36c2016-12-15 07:39:51 -08001085 for _, lib := range deps.HeaderLibs {
1086 depTag := headerDepTag
1087 if inList(lib, deps.ReexportHeaderLibHeaders) {
1088 depTag = headerExportDepTag
1089 }
1090 actx.AddVariationDependencies(nil, depTag, lib)
1091 }
Colin Cross5950f382016-12-13 12:50:57 -08001092
Dan Willemsen59339a22018-07-22 21:18:45 -07001093 actx.AddVariationDependencies([]blueprint.Variation{
1094 {Mutator: "link", Variation: "static"},
1095 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001096
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001097 for _, lib := range deps.StaticLibs {
1098 depTag := staticDepTag
1099 if inList(lib, deps.ReexportStaticLibHeaders) {
1100 depTag = staticExportDepTag
1101 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001102 actx.AddVariationDependencies([]blueprint.Variation{
1103 {Mutator: "link", Variation: "static"},
1104 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001105 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001106
Dan Willemsen59339a22018-07-22 21:18:45 -07001107 actx.AddVariationDependencies([]blueprint.Variation{
1108 {Mutator: "link", Variation: "static"},
1109 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001110
Jiyong Park25fc6a92018-11-18 18:02:45 +09001111 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1112 var variations []blueprint.Variation
1113 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001114 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001115 if version != "" && versionVariantAvail {
1116 // Version is explicitly specified. i.e. libFoo#30
1117 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1118 depTag.explicitlyVersioned = true
1119 }
1120 actx.AddVariationDependencies(variations, depTag, name)
1121
1122 // If the version is not specified, add dependency to the latest stubs library.
1123 // The stubs library will be used when the depending module is built for APEX and
1124 // the dependent module is not in the same APEX.
1125 latestVersion := latestStubsVersionFor(actx.Config(), name)
1126 if version == "" && latestVersion != "" && versionVariantAvail {
1127 actx.AddVariationDependencies([]blueprint.Variation{
1128 {Mutator: "link", Variation: "shared"},
1129 {Mutator: "version", Variation: latestVersion},
1130 }, depTag, name)
1131 // Note that depTag.explicitlyVersioned is false in this case.
1132 }
1133 }
1134
Jiyong Park7ed9de32018-10-15 22:25:07 +09001135 // shared lib names without the #version suffix
1136 var sharedLibNames []string
1137
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001138 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001139 name, version := stubsLibNameAndVersion(lib)
1140 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001141 depTag := sharedDepTag
1142 if inList(lib, deps.ReexportSharedLibHeaders) {
1143 depTag = sharedExportDepTag
1144 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001145 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001146 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001147
Jiyong Park7ed9de32018-10-15 22:25:07 +09001148 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001149 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001150 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1151 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1152 // linking against both the stubs lib and the non-stubs lib at the same time.
1153 continue
1154 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001155 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001156 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001157
Dan Willemsen59339a22018-07-22 21:18:45 -07001158 actx.AddVariationDependencies([]blueprint.Variation{
1159 {Mutator: "link", Variation: "shared"},
1160 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001161
Colin Cross68861832016-07-08 10:41:41 -07001162 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001163
1164 for _, gen := range deps.GeneratedHeaders {
1165 depTag := genHeaderDepTag
1166 if inList(gen, deps.ReexportGeneratedHeaders) {
1167 depTag = genHeaderExportDepTag
1168 }
1169 actx.AddDependency(c, depTag, gen)
1170 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001171
Colin Cross42d48b72018-08-29 14:10:52 -07001172 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001173
1174 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001175 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001176 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001177 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001178 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001179 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001180 if deps.LinkerFlagsFile != "" {
1181 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1182 }
1183 if deps.DynamicLinker != "" {
1184 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001185 }
Dan Albert914449f2016-06-17 16:45:24 -07001186
1187 version := ctx.sdkVersion()
1188 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001189 {Mutator: "ndk_api", Variation: version},
1190 {Mutator: "link", Variation: "shared"},
1191 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001192 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001193 {Mutator: "ndk_api", Variation: version},
1194 {Mutator: "link", Variation: "shared"},
1195 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001196
1197 if vndkdep := c.vndkdep; vndkdep != nil {
1198 if vndkdep.isVndkExt() {
1199 baseModuleMode := vendorMode
1200 if actx.DeviceConfig().VndkVersion() == "" {
1201 baseModuleMode = coreMode
1202 }
1203 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001204 {Mutator: "image", Variation: baseModuleMode},
1205 {Mutator: "link", Variation: "shared"},
1206 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001207 }
1208 }
Colin Cross6362e272015-10-29 15:25:03 -07001209}
Colin Cross21b9a242015-03-24 14:15:58 -07001210
Colin Crosse40b4ea2018-10-02 22:25:58 -07001211func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001212 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1213 c.beginMutator(ctx)
1214 }
1215}
1216
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001217// Whether a module can link to another module, taking into
1218// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001219func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001220 if from.Target().Os != android.Android {
1221 // Host code is not restricted
1222 return
1223 }
1224 if from.Properties.UseVndk {
1225 // Though vendor code is limited by the vendor mutator,
1226 // each vendor-available module needs to check
1227 // link-type for VNDK.
1228 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001229 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001230 }
1231 return
1232 }
Nan Zhang0007d812017-11-07 10:57:05 -08001233 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001234 // Platform code can link to anything
1235 return
1236 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001237 if from.inRecovery() {
1238 // Recovery code is not NDK
1239 return
1240 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001241 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1242 // These are always allowed
1243 return
1244 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001245 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1246 // These are allowed, but they don't set sdk_version
1247 return
1248 }
1249 if _, ok := to.linker.(*stubDecorator); ok {
1250 // These aren't real libraries, but are the stub shared libraries that are included in
1251 // the NDK.
1252 return
1253 }
Nan Zhang0007d812017-11-07 10:57:05 -08001254 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001255 // NDK code linking to platform code is never okay.
1256 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1257 ctx.OtherModuleName(to))
1258 }
1259
1260 // At this point we know we have two NDK libraries, but we need to
1261 // check that we're not linking against anything built against a higher
1262 // API level, as it is only valid to link against older or equivalent
1263 // APIs.
1264
Inseob Kim01a28722018-04-11 09:48:45 +09001265 // Current can link against anything.
1266 if String(from.Properties.Sdk_version) != "current" {
1267 // Otherwise we need to check.
1268 if String(to.Properties.Sdk_version) == "current" {
1269 // Current can't be linked against by anything else.
1270 ctx.ModuleErrorf("links %q built against newer API version %q",
1271 ctx.OtherModuleName(to), "current")
1272 } else {
1273 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1274 if err != nil {
1275 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001276 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001277 String(from.Properties.Sdk_version))
1278 }
1279 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1280 if err != nil {
1281 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001282 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001283 String(to.Properties.Sdk_version))
1284 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001285
Inseob Kim01a28722018-04-11 09:48:45 +09001286 if toApi > fromApi {
1287 ctx.ModuleErrorf("links %q built against newer API version %q",
1288 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1289 }
1290 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001291 }
Dan Albert202fe492017-12-15 13:56:59 -08001292
1293 // Also check that the two STL choices are compatible.
1294 fromStl := from.stl.Properties.SelectedStl
1295 toStl := to.stl.Properties.SelectedStl
1296 if fromStl == "" || toStl == "" {
1297 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001298 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001299 // We can be permissive with the system "STL" since it is only the C++
1300 // ABI layer, but in the future we should make sure that everyone is
1301 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001302 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001303 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1304 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1305 to.stl.Properties.SelectedStl)
1306 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001307}
1308
Jiyong Park5fb8c102018-04-09 12:03:06 +09001309// Tests whether the dependent library is okay to be double loaded inside a single process.
1310// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1311// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1312// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1313func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1314 if _, ok := from.linker.(*libraryDecorator); !ok {
1315 return
1316 }
1317
1318 if inList(ctx.ModuleName(), llndkLibraries) ||
1319 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1320 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1321 depIsVndkSp := false
1322 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1323 depIsVndkSp = true
1324 }
1325 depIsVndk := false
1326 if to.vndkdep != nil && to.vndkdep.isVndk() {
1327 depIsVndk = true
1328 }
1329 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1330 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001331 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1332 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001333 ctx.OtherModuleName(to))
1334 }
1335 }
1336}
1337
Colin Crossc99deeb2016-04-11 15:06:20 -07001338// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001339func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001340 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001341
Jeff Gaston294356f2017-09-27 17:05:30 -07001342 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001343 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001344
Colin Crossd11fcda2017-10-23 17:59:01 -07001345 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001346 depName := ctx.OtherModuleName(dep)
1347 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001348
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001349 ccDep, _ := dep.(*Module)
1350 if ccDep == nil {
1351 // handling for a few module types that aren't cc Module but that are also supported
1352 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001353 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001354 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001355 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1356 genRule.GeneratedSourceFiles()...)
1357 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001358 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001359 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001360 // Support exported headers from a generated_sources dependency
1361 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001362 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001363 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001364 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001365 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001366 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001367 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001368 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001369 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001370 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001371 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001372 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1373 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1374
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001375 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001376 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001377 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001378 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001379 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001380 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001381 files := genRule.GeneratedSourceFiles()
1382 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001383 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001384 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001385 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 -07001386 }
1387 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001388 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001389 }
Colin Crossca860ac2016-01-04 14:34:37 -08001390 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001391 return
1392 }
1393
Colin Crossd11fcda2017-10-23 17:59:01 -07001394 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001395 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1396 return
1397 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001398 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001399 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001400 return
1401 }
1402
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001403 // re-exporting flags
1404 if depTag == reuseObjTag {
1405 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001406 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001407 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001408 depPaths.Objs = depPaths.Objs.Append(objs)
1409 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001410 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001411 return
1412 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001413 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001414
1415 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1416 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1417 // won't be matched to sharedDepTag and lateSharedDepTag.
1418 explicitlyVersioned := false
1419 if t, ok := depTag.(dependencyTag); ok {
1420 explicitlyVersioned = t.explicitlyVersioned
1421 t.explicitlyVersioned = false
1422 depTag = t
1423 }
1424
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001425 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001426 depIsStatic := false
1427 switch depTag {
1428 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1429 depIsStatic = true
1430 }
1431 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001432 depIsStubs := dependentLibrary.buildStubs()
1433 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001434 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
1435 depInPlatform := !android.DirectlyInAnyApex(depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001436
1437 var useThisDep bool
1438 if depIsStubs && explicitlyVersioned {
1439 // Always respect dependency to the versioned stubs (i.e. libX#10)
1440 useThisDep = true
1441 } else if !depHasStubs {
1442 // Use non-stub variant if that is the only choice
1443 // (i.e. depending on a lib without stubs.version property)
1444 useThisDep = true
1445 } else if c.IsForPlatform() {
1446 // If not building for APEX, use stubs only when it is from
1447 // an APEX (and not from platform)
1448 useThisDep = (depInPlatform != depIsStubs)
1449 if c.inRecovery() {
1450 // However, for recovery modules, since there is no APEX there,
1451 // always link to non-stub variant
1452 useThisDep = !depIsStubs
1453 }
1454 } else {
1455 // If building for APEX, use stubs only when it is not from
1456 // the same APEX
1457 useThisDep = (depInSameApex != depIsStubs)
1458 }
1459
1460 if !useThisDep {
1461 return // stop processing this dep
1462 }
1463 }
1464
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001465 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001466 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001467 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001468 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001469 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001470
1471 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001472 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001473 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001474 // 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 -07001475 // Re-exported shared library headers must be included as well since they can help us with type information
1476 // about template instantiations (instantiated from their headers).
1477 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001478 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001479 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001480
Logan Chienf3511742017-10-31 18:04:35 +08001481 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001482 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001483 }
1484
Colin Cross26c34ed2016-09-30 17:10:16 -07001485 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001486 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001487
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001488 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001489 depFile := android.OptionalPath{}
1490
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001491 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001492 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001493 ptr = &depPaths.SharedLibs
1494 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001495 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001496 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001497 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001498 ptr = &depPaths.LateSharedLibs
1499 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001500 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001501 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001502 ptr = nil
1503 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001504 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001505 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001506 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001507 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001508 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001509 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001510 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001511 return
1512 }
1513
1514 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001515 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001516 for i := range missingDeps {
1517 missingDeps[i] += postfix
1518 }
1519 ctx.AddMissingDependencies(missingDeps)
1520 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001521 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001522 case headerDepTag:
1523 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001524 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001525 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001526 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001527 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001528 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001529 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001530 case dynamicLinkerDepTag:
1531 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001532 }
1533
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001534 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001535 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001536 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001537 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001538 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001539 return
1540 }
1541
1542 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001543 // in static libraries act as if they were whole static libraries. The same goes for
1544 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001545 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1546 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001547 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1548 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001549
Dan Willemsen581341d2017-02-09 16:16:31 -08001550 }
1551
Colin Cross26c34ed2016-09-30 17:10:16 -07001552 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001553 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001554 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001555 return
1556 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001557 *ptr = append(*ptr, linkFile.Path())
1558 }
1559
Colin Crossc99deeb2016-04-11 15:06:20 -07001560 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001561 dep := depFile
1562 if !dep.Valid() {
1563 dep = linkFile
1564 }
1565 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001566 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001567
Logan Chien43d34c32017-12-20 01:17:32 +08001568 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001569 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001570 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001571 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001572 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001573 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001574 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1575 if c.useVndk() && bothVendorAndCoreVariantsExist {
1576 // The vendor module in Make will have been renamed to not conflict with the core
1577 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001578 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001579 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001580 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001581 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1582 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001583 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001584 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001585 }
Logan Chien43d34c32017-12-20 01:17:32 +08001586 }
1587
1588 // Export the shared libs to Make.
1589 switch depTag {
1590 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001591 // Dependency to the stubs lib which is already included in an APEX
1592 // is not added to the androidmk dependency
1593 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001594 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001595 // Also add the dependency to the APEX(es) providing the library so that
1596 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001597 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001598 c.Properties.ApexesProvidingSharedLibs = append(
1599 c.Properties.ApexesProvidingSharedLibs, an)
1600 }
1601 break
1602 }
1603 }
1604
Jiyong Park27b188b2017-07-18 13:23:39 +09001605 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001606 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001607 c.Properties.AndroidMkSharedLibs = append(
1608 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001609 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1610 c.Properties.AndroidMkStaticLibs = append(
1611 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001612 case runtimeDepTag:
1613 c.Properties.AndroidMkRuntimeLibs = append(
1614 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001615 case wholeStaticDepTag:
1616 c.Properties.AndroidMkWholeStaticLibs = append(
1617 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001618 }
Colin Crossca860ac2016-01-04 14:34:37 -08001619 })
1620
Jeff Gaston294356f2017-09-27 17:05:30 -07001621 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001622 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001623
Colin Crossdd84e052017-05-17 13:44:16 -07001624 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001625 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001626 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001627 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001628 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1629
1630 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001631 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001632 }
Colin Crossdd84e052017-05-17 13:44:16 -07001633
Colin Crossca860ac2016-01-04 14:34:37 -08001634 return depPaths
1635}
1636
1637func (c *Module) InstallInData() bool {
1638 if c.installer == nil {
1639 return false
1640 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001641 return c.installer.inData()
1642}
1643
1644func (c *Module) InstallInSanitizerDir() bool {
1645 if c.installer == nil {
1646 return false
1647 }
1648 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001649 return true
1650 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001651 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001652}
1653
Jiyong Parkf9332f12018-02-01 00:54:12 +09001654func (c *Module) InstallInRecovery() bool {
1655 return c.inRecovery()
1656}
1657
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001658func (c *Module) HostToolPath() android.OptionalPath {
1659 if c.installer == nil {
1660 return android.OptionalPath{}
1661 }
1662 return c.installer.hostToolPath()
1663}
1664
Nan Zhangd4e641b2017-07-12 12:55:28 -07001665func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1666 return c.outputFile
1667}
1668
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001669func (c *Module) Srcs() android.Paths {
1670 if c.outputFile.Valid() {
1671 return android.Paths{c.outputFile.Path()}
1672 }
1673 return android.Paths{}
1674}
1675
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001676func (c *Module) static() bool {
1677 if static, ok := c.linker.(interface {
1678 static() bool
1679 }); ok {
1680 return static.static()
1681 }
1682 return false
1683}
1684
Colin Crossb60190a2018-09-04 16:28:17 -07001685func (c *Module) getMakeLinkType() string {
1686 if c.useVndk() {
1687 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1688 if inList(c.Name(), vndkPrivateLibraries) {
1689 return "native:vndk_private"
1690 } else {
1691 return "native:vndk"
1692 }
1693 } else {
1694 return "native:vendor"
1695 }
1696 } else if c.inRecovery() {
1697 return "native:recovery"
1698 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1699 return "native:ndk:none:none"
1700 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1701 //family, link := getNdkStlFamilyAndLinkType(c)
1702 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1703 } else {
1704 return "native:platform"
1705 }
1706}
1707
Jiyong Park9d452992018-10-03 00:38:19 +09001708// Overrides ApexModule.IsInstallabeToApex()
1709// Only shared libraries are installable to APEX.
1710func (c *Module) IsInstallableToApex() bool {
1711 if shared, ok := c.linker.(interface {
1712 shared() bool
1713 }); ok {
1714 return shared.shared()
1715 }
1716 return false
1717}
1718
Colin Cross2ba19d92015-05-07 15:44:20 -07001719//
Colin Crosscfad1192015-11-02 16:43:11 -08001720// Defaults
1721//
Colin Crossca860ac2016-01-04 14:34:37 -08001722type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001723 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001724 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001725 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001726}
1727
Colin Cross635c3b02016-05-18 15:37:25 -07001728func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001729}
1730
Colin Cross1e676be2016-10-12 14:38:15 -07001731func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1732}
1733
Colin Cross36242852017-06-23 15:06:31 -07001734func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001735 return DefaultsFactory()
1736}
1737
Colin Cross36242852017-06-23 15:06:31 -07001738func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001739 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001740
Colin Cross36242852017-06-23 15:06:31 -07001741 module.AddProperties(props...)
1742 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001743 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001744 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001745 &BaseCompilerProperties{},
1746 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001747 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001748 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001749 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001750 &TestProperties{},
1751 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001752 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001753 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001754 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001755 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001756 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001757 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001758 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001759 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001760 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001761 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001762 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001763 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001764 )
Colin Crosscfad1192015-11-02 16:43:11 -08001765
Colin Cross1f44a3a2017-07-07 14:33:33 -07001766 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001767 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001768
1769 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001770}
1771
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001772const (
1773 // coreMode is the variant used for framework-private libraries, or
1774 // SDK libraries. (which framework-private libraries can use)
1775 coreMode = "core"
1776
1777 // vendorMode is the variant used for /vendor code that compiles
1778 // against the VNDK.
1779 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001780
1781 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001782)
1783
Jiyong Park6a43f042017-10-12 23:05:00 +09001784func squashVendorSrcs(m *Module) {
1785 if lib, ok := m.compiler.(*libraryDecorator); ok {
1786 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1787 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1788
1789 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1790 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1791 }
1792}
1793
Jiyong Parkf9332f12018-02-01 00:54:12 +09001794func squashRecoverySrcs(m *Module) {
1795 if lib, ok := m.compiler.(*libraryDecorator); ok {
1796 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1797 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1798
1799 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1800 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1801 }
1802}
1803
Jiyong Parkda6eb592018-12-19 17:12:36 +09001804func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001805 if mctx.Os() != android.Android {
1806 return
1807 }
1808
Jiyong Park7ed9de32018-10-15 22:25:07 +09001809 if g, ok := mctx.Module().(*genrule.Module); ok {
1810 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001811 var coreVariantNeeded bool = false
1812 var vendorVariantNeeded bool = false
1813 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001814 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001815 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001816 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001817 coreVariantNeeded = true
1818 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001819 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001820 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001821 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001822 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001823 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001824 if Bool(props.Recovery_available) {
1825 recoveryVariantNeeded = true
1826 }
1827
Jiyong Park413cc742018-06-19 01:46:06 +09001828 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001829 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001830 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001831 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001832 recoveryVariantNeeded = false
1833 }
1834 }
1835
Jiyong Park3f736c92018-05-24 13:36:56 +09001836 var variants []string
1837 if coreVariantNeeded {
1838 variants = append(variants, coreMode)
1839 }
1840 if vendorVariantNeeded {
1841 variants = append(variants, vendorMode)
1842 }
1843 if recoveryVariantNeeded {
1844 variants = append(variants, recoveryMode)
1845 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001846 mod := mctx.CreateVariations(variants...)
1847 for i, v := range variants {
1848 if v == recoveryMode {
1849 m := mod[i].(*genrule.Module)
1850 m.Extra.(*GenruleExtraProperties).InRecovery = true
1851 }
1852 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001853 }
1854 }
1855
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001856 m, ok := mctx.Module().(*Module)
1857 if !ok {
1858 return
1859 }
1860
1861 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001862 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09001863 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08001864
1865 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001866 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001867 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001868 return
1869 }
Logan Chienf3511742017-10-31 18:04:35 +08001870
1871 if vndkdep := m.vndkdep; vndkdep != nil {
1872 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09001873 if productSpecific {
1874 mctx.PropertyErrorf("product_specific",
1875 "product_specific must not be true when `vndk: {enabled: true}`")
1876 return
1877 }
Logan Chienf3511742017-10-31 18:04:35 +08001878 if vendorSpecific {
1879 if !vndkdep.isVndkExt() {
1880 mctx.PropertyErrorf("vndk",
1881 "must set `extends: \"...\"` to vndk extension")
1882 return
1883 }
1884 } else {
1885 if vndkdep.isVndkExt() {
1886 mctx.PropertyErrorf("vndk",
1887 "must set `vendor: true` to set `extends: %q`",
1888 m.getVndkExtendsModuleName())
1889 return
1890 }
1891 if m.VendorProperties.Vendor_available == nil {
1892 mctx.PropertyErrorf("vndk",
1893 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1894 return
1895 }
1896 }
1897 } else {
1898 if vndkdep.isVndkSp() {
1899 mctx.PropertyErrorf("vndk",
1900 "must set `enabled: true` to set `support_system_process: true`")
1901 return
1902 }
1903 if vndkdep.isVndkExt() {
1904 mctx.PropertyErrorf("vndk",
1905 "must set `enabled: true` to set `extends: %q`",
1906 m.getVndkExtendsModuleName())
1907 return
1908 }
Justin Yun8effde42017-06-23 19:24:43 +09001909 }
1910 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001911
Jiyong Parkf9332f12018-02-01 00:54:12 +09001912 var coreVariantNeeded bool = false
1913 var vendorVariantNeeded bool = false
1914 var recoveryVariantNeeded bool = false
1915
Justin Yun71549282017-11-17 12:10:28 +09001916 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001917 // If the device isn't compiling against the VNDK, we always
1918 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001919 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001920 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1921 // LL-NDK stubs only exist in the vendor variant, since the
1922 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001923 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001924 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1925 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001926 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001927 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001928 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1929 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001930 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001931 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001932 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001933 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001934 coreVariantNeeded = true
1935 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001936 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001937 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001938 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001939 } else {
1940 // This is either in /system (or similar: /data), or is a
1941 // modules built with the NDK. Modules built with the NDK
1942 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001943 coreVariantNeeded = true
1944 }
1945
1946 if Bool(m.Properties.Recovery_available) {
1947 recoveryVariantNeeded = true
1948 }
1949
1950 if m.ModuleBase.InstallInRecovery() {
1951 recoveryVariantNeeded = true
1952 coreVariantNeeded = false
1953 }
1954
Jiyong Park413cc742018-06-19 01:46:06 +09001955 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001956 primaryArch := mctx.Config().DevicePrimaryArchType()
1957 moduleArch := m.Target().Arch.ArchType
1958 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001959 recoveryVariantNeeded = false
1960 }
1961 }
1962
Jiyong Parkf9332f12018-02-01 00:54:12 +09001963 var variants []string
1964 if coreVariantNeeded {
1965 variants = append(variants, coreMode)
1966 }
1967 if vendorVariantNeeded {
1968 variants = append(variants, vendorMode)
1969 }
1970 if recoveryVariantNeeded {
1971 variants = append(variants, recoveryMode)
1972 }
1973 mod := mctx.CreateVariations(variants...)
1974 for i, v := range variants {
1975 if v == vendorMode {
1976 m := mod[i].(*Module)
1977 m.Properties.UseVndk = true
1978 squashVendorSrcs(m)
1979 } else if v == recoveryMode {
1980 m := mod[i].(*Module)
1981 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09001982 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001983 squashRecoverySrcs(m)
1984 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001985 }
1986}
1987
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001988func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001989 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001990 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1991 }
Colin Cross6510f912017-11-29 00:27:14 -08001992 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001993}
1994
Colin Cross06a931b2015-10-28 17:23:31 -07001995var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07001996var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08001997var BoolPtr = proptools.BoolPtr
1998var String = proptools.String
1999var StringPtr = proptools.StringPtr