blob: f65441fa67e07e8547f9e011bcfa91b01c434c87 [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 Park6a43f042017-10-12 23:05:00 +090037 ctx.BottomUp("image", vendorMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070038 ctx.BottomUp("link", linkageMutator).Parallel()
Jiyong Parkd5b18a52017-08-03 21:22:50 +090039 ctx.BottomUp("vndk", vndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
42 ctx.BottomUp("begin", beginMutator).Parallel()
43 })
Colin Cross16b23492016-01-06 14:41:07 -080044
Colin Cross1e676be2016-10-12 14:38:15 -070045 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
46 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
47 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080048
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000049 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
50 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
51
Colin Cross1e676be2016-10-12 14:38:15 -070052 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
53 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080054
55 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080056 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070057
58 ctx.TopDown("lto_deps", ltoDepsMutator)
59 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070060 })
Colin Crossb98c8b02016-07-29 13:44:28 -070061
62 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070063}
64
Colin Crossca860ac2016-01-04 14:34:37 -080065type Deps struct {
66 SharedLibs, LateSharedLibs []string
67 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080068 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070069
Colin Cross5950f382016-12-13 12:50:57 -080070 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070071
Colin Cross81413472016-04-11 14:37:39 -070072 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070073
Dan Willemsenb40aab62016-04-20 14:21:14 -070074 GeneratedSources []string
75 GeneratedHeaders []string
76
Dan Willemsenb3454ab2016-09-28 17:34:58 -070077 ReexportGeneratedHeaders []string
78
Colin Cross97ba0732015-03-23 17:50:24 -070079 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070080 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070081}
82
Colin Crossca860ac2016-01-04 14:34:37 -080083type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070084 // Paths to .so files
85 SharedLibs, LateSharedLibs android.Paths
86 // Paths to the dependencies to use for .so files (.so.toc files)
87 SharedLibsDeps, LateSharedLibsDeps android.Paths
88 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070089 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070090
Colin Cross26c34ed2016-09-30 17:10:16 -070091 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070092 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080093 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070094 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Colin Cross26c34ed2016-09-30 17:10:16 -070096 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070097 GeneratedSources android.Paths
98 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070099
Dan Willemsen76f08272016-07-09 00:14:08 -0700100 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700101 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700102
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700104 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700105 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700109 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
110 ArFlags []string // Flags that apply to ar
111 AsFlags []string // Flags that apply to assembly source files
112 CFlags []string // Flags that apply to C and C++ source files
113 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
114 ConlyFlags []string // Flags that apply to C source files
115 CppFlags []string // Flags that apply to C++ source files
116 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
117 YaccFlags []string // Flags that apply to Yacc source files
118 protoFlags []string // Flags that apply to proto source files
Joe Onorato09e94ab2017-11-18 18:23:14 -0800119 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700120 aidlFlags []string // Flags that apply to aidl source files
121 rsFlags []string // Flags that apply to renderscript source files
122 LdFlags []string // Flags that apply to linker command lines
123 libFlags []string // Flags to add libraries early to the link order
124 TidyFlags []string // Flags that apply to clang-tidy
125 SAbiFlags []string // Flags that apply to header-abi-dumper
126 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700127
Colin Crossc3199482017-03-30 15:03:04 -0700128 // Global include flags that apply to C, C++, and assembly source files
129 // These must be after any module include flags, which will be in GlobalFlags.
130 SystemIncludeFlags []string
131
Colin Crossb98c8b02016-07-29 13:44:28 -0700132 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700133 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700134 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800135 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800136 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800137
138 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800139 DynamicLinker string
140
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700141 CFlagsDeps android.Paths // Files depended on by compiler flags
142 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800143
144 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800145 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700146}
147
Colin Cross81413472016-04-11 14:37:39 -0700148type ObjectLinkerProperties struct {
149 // names of other cc_object modules to link into this module using partial linking
150 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700151
152 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800153 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700154}
155
Colin Crossca860ac2016-01-04 14:34:37 -0800156// Properties used to compile all C or C++ modules
157type BaseProperties struct {
158 // compile module with clang instead of gcc
159 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700160
161 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800162 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700163
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700164 AndroidMkSharedLibs []string `blueprint:"mutated"`
165 HideFromMake bool `blueprint:"mutated"`
166 PreventInstall bool `blueprint:"mutated"`
167
168 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800169
170 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
171 // file
172 Logtags []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700173}
174
175type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900176 // whether this module should be allowed to be directly depended by other
177 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
178 // If set to true, two variants will be built separately, one like
179 // normal, and the other limited to the set of libraries and headers
180 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700181 //
182 // The vendor variant may be used with a different (newer) /system,
183 // so it shouldn't have any unversioned runtime dependencies, or
184 // make assumptions about the system that may not be true in the
185 // future.
186 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900187 // If set to false, this module becomes inaccessible from /vendor modules.
188 //
189 // Default value is true when vndk: {enabled: true} or vendor: true.
190 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700191 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
192 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800193}
194
Colin Crossca860ac2016-01-04 14:34:37 -0800195type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800196 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800197}
198
Colin Crossca860ac2016-01-04 14:34:37 -0800199type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800200 static() bool
201 staticBinary() bool
202 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700203 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700204 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800205 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700206 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900207 isVndk() bool
208 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800209 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800210 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700211 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700212 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800213 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800214 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800215}
216
217type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700218 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800219 ModuleContextIntf
220}
221
222type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700223 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800224 ModuleContextIntf
225}
226
Colin Cross37047f12016-12-13 17:06:13 -0800227type DepsContext interface {
228 android.BottomUpMutatorContext
229 ModuleContextIntf
230}
231
Colin Crossca860ac2016-01-04 14:34:37 -0800232type feature interface {
233 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800234 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800235 flags(ctx ModuleContext, flags Flags) Flags
236 props() []interface{}
237}
238
239type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700240 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800241 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800242 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700243 compilerProps() []interface{}
244
Colin Cross76fada02016-07-27 10:31:13 -0700245 appendCflags([]string)
246 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700247 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800248}
249
250type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700251 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800252 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700253 linkerFlags(ctx ModuleContext, flags Flags) Flags
254 linkerProps() []interface{}
255
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700256 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700257 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800258}
259
260type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700261 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700262 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800263 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700264 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700265 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800266}
267
Colin Crossc99deeb2016-04-11 15:06:20 -0700268type dependencyTag struct {
269 blueprint.BaseDependencyTag
270 name string
271 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700272
273 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700274}
275
276var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700277 sharedDepTag = dependencyTag{name: "shared", library: true}
278 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
279 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
280 staticDepTag = dependencyTag{name: "static", library: true}
281 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
282 lateStaticDepTag = dependencyTag{name: "late static", library: true}
283 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800284 headerDepTag = dependencyTag{name: "header", library: true}
285 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700286 genSourceDepTag = dependencyTag{name: "gen source"}
287 genHeaderDepTag = dependencyTag{name: "gen header"}
288 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
289 objDepTag = dependencyTag{name: "obj"}
290 crtBeginDepTag = dependencyTag{name: "crtbegin"}
291 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700292 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700293 reuseObjTag = dependencyTag{name: "reuse objects"}
294 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
295 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800296 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700297)
298
Colin Crossca860ac2016-01-04 14:34:37 -0800299// Module contains the properties and members used by all C/C++ module types, and implements
300// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
301// to construct the output file. Behavior can be customized with a Customizer interface
302type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700303 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700304 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700305
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700306 Properties BaseProperties
307 VendorProperties VendorProperties
308 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700309
Colin Crossca860ac2016-01-04 14:34:37 -0800310 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700311 hod android.HostOrDeviceSupported
312 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700313
Colin Crossca860ac2016-01-04 14:34:37 -0800314 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700315 features []feature
316 compiler compiler
317 linker linker
318 installer installer
319 stl *stl
320 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800321 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800322 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900323 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700324 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700325 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800326
327 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700328
Colin Cross635c3b02016-05-18 15:37:25 -0700329 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800330
Colin Crossb98c8b02016-07-29 13:44:28 -0700331 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700332
333 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800334
335 // Flags used to compile this module
336 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700337
338 // 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 -0800339 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700340 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800341 depsInLinkOrder android.Paths
342
343 // only non-nil when this is a shared library that reuses the objects of a static library
344 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700345}
346
Colin Cross36242852017-06-23 15:06:31 -0700347func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700348 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800349 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700350 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800351 }
352 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700353 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800354 }
355 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700356 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800357 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700358 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700359 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700360 }
Colin Cross16b23492016-01-06 14:41:07 -0800361 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700362 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800363 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800364 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700365 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800366 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800367 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700368 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800369 }
Justin Yun8effde42017-06-23 19:24:43 +0900370 if c.vndkdep != nil {
371 c.AddProperties(c.vndkdep.props()...)
372 }
Stephen Craneba090d12017-05-09 15:44:35 -0700373 if c.lto != nil {
374 c.AddProperties(c.lto.props()...)
375 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700376 if c.pgo != nil {
377 c.AddProperties(c.pgo.props()...)
378 }
Colin Crossca860ac2016-01-04 14:34:37 -0800379 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700380 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800381 }
Colin Crossc472d572015-03-17 15:06:21 -0700382
Colin Cross36242852017-06-23 15:06:31 -0700383 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700384
Colin Cross1f44a3a2017-07-07 14:33:33 -0700385 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700386
387 return c
Colin Crossc472d572015-03-17 15:06:21 -0700388}
389
Colin Crossb916a382016-07-29 17:28:03 -0700390// Returns true for dependency roots (binaries)
391// TODO(ccross): also handle dlopenable libraries
392func (c *Module) isDependencyRoot() bool {
393 if root, ok := c.linker.(interface {
394 isDependencyRoot() bool
395 }); ok {
396 return root.isDependencyRoot()
397 }
398 return false
399}
400
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700401func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700402 return c.Properties.UseVndk
403}
404
Justin Yun8effde42017-06-23 19:24:43 +0900405func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800406 if vndkdep := c.vndkdep; vndkdep != nil {
407 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900408 }
409 return false
410}
411
Yi Kong7e53c572018-02-14 18:16:12 +0800412func (c *Module) isPgoCompile() bool {
413 if pgo := c.pgo; pgo != nil {
414 return pgo.Properties.PgoCompile
415 }
416 return false
417}
418
Logan Chienf3511742017-10-31 18:04:35 +0800419func (c *Module) isVndkSp() bool {
420 if vndkdep := c.vndkdep; vndkdep != nil {
421 return vndkdep.isVndkSp()
422 }
423 return false
424}
425
426func (c *Module) isVndkExt() bool {
427 if vndkdep := c.vndkdep; vndkdep != nil {
428 return vndkdep.isVndkExt()
429 }
430 return false
431}
432
433func (c *Module) getVndkExtendsModuleName() string {
434 if vndkdep := c.vndkdep; vndkdep != nil {
435 return vndkdep.getVndkExtendsModuleName()
436 }
437 return ""
438}
439
Jiyong Park82e2bf32017-08-16 14:05:54 +0900440// Returns true only when this module is configured to have core and vendor
441// variants.
442func (c *Module) hasVendorVariant() bool {
443 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
444}
445
Colin Crossca860ac2016-01-04 14:34:37 -0800446type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700447 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800448 moduleContextImpl
449}
450
Colin Cross37047f12016-12-13 17:06:13 -0800451type depsContext struct {
452 android.BottomUpMutatorContext
453 moduleContextImpl
454}
455
Colin Crossca860ac2016-01-04 14:34:37 -0800456type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700457 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800458 moduleContextImpl
459}
460
Jiyong Park2db76922017-11-08 16:03:48 +0900461func (ctx *moduleContext) SocSpecific() bool {
462 return ctx.ModuleContext.SocSpecific() ||
463 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700464}
465
Colin Crossca860ac2016-01-04 14:34:37 -0800466type moduleContextImpl struct {
467 mod *Module
468 ctx BaseModuleContext
469}
470
Colin Crossca860ac2016-01-04 14:34:37 -0800471func (ctx *moduleContextImpl) clang() bool {
472 return ctx.mod.clang(ctx.ctx)
473}
474
Colin Crossb98c8b02016-07-29 13:44:28 -0700475func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800476 return ctx.mod.toolchain(ctx.ctx)
477}
478
479func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000480 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800481}
482
483func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700484 if static, ok := ctx.mod.linker.(interface {
485 staticBinary() bool
486 }); ok {
487 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800488 }
Colin Crossb916a382016-07-29 17:28:03 -0700489 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800490}
491
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700492func (ctx *moduleContextImpl) useSdk() bool {
493 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800494 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700495 }
496 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800497}
498
499func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700500 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700501 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700502 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800503 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800504 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800505 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700506 }
507 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800508}
509
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700510func (ctx *moduleContextImpl) useVndk() bool {
511 return ctx.mod.useVndk()
512}
Justin Yun8effde42017-06-23 19:24:43 +0900513
Logan Chienf3511742017-10-31 18:04:35 +0800514func (ctx *moduleContextImpl) isVndk() bool {
515 return ctx.mod.isVndk()
516}
517
Yi Kong7e53c572018-02-14 18:16:12 +0800518func (ctx *moduleContextImpl) isPgoCompile() bool {
519 return ctx.mod.isPgoCompile()
520}
521
Justin Yun8effde42017-06-23 19:24:43 +0900522func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800523 return ctx.mod.isVndkSp()
524}
525
526func (ctx *moduleContextImpl) isVndkExt() bool {
527 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900528}
529
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800530// Create source abi dumps if the module belongs to the list of VndkLibraries.
531func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700532 return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800533}
534
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700535func (ctx *moduleContextImpl) selectedStl() string {
536 if stl := ctx.mod.stl; stl != nil {
537 return stl.Properties.SelectedStl
538 }
539 return ""
540}
541
Colin Crossce75d2c2016-10-06 16:12:58 -0700542func (ctx *moduleContextImpl) baseModuleName() string {
543 return ctx.mod.ModuleBase.BaseModuleName()
544}
545
Logan Chienf3511742017-10-31 18:04:35 +0800546func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
547 return ctx.mod.getVndkExtendsModuleName()
548}
549
Colin Cross635c3b02016-05-18 15:37:25 -0700550func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800551 return &Module{
552 hod: hod,
553 multilib: multilib,
554 }
555}
556
Colin Cross635c3b02016-05-18 15:37:25 -0700557func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800558 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700559 module.features = []feature{
560 &tidyFeature{},
561 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700562 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800563 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800564 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800565 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900566 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700567 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700568 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800569 return module
570}
571
Colin Crossce75d2c2016-10-06 16:12:58 -0700572func (c *Module) Prebuilt() *android.Prebuilt {
573 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
574 return p.prebuilt()
575 }
576 return nil
577}
578
579func (c *Module) Name() string {
580 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700581 if p, ok := c.linker.(interface {
582 Name(string) string
583 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700584 name = p.Name(name)
585 }
586 return name
587}
588
Jeff Gaston294356f2017-09-27 17:05:30 -0700589// orderDeps reorders dependencies into a list such that if module A depends on B, then
590// A will precede B in the resultant list.
591// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800592// Note that directSharedDeps should be the analogous static library for each shared lib dep
593func 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 -0700594 // If A depends on B, then
595 // Every list containing A will also contain B later in the list
596 // So, after concatenating all lists, the final instance of B will have come from the same
597 // original list as the final instance of A
598 // So, the final instance of B will be later in the concatenation than the final A
599 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
600 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800601 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700602 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800603 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
604 }
605 for _, dep := range directSharedDeps {
606 orderedAllDeps = append(orderedAllDeps, dep)
607 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700608 }
609
Colin Crossb6715442017-10-24 11:13:31 -0700610 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700611
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800612 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700613 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800614 // resultant list to only what the caller has chosen to include in directStaticDeps
615 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700616
617 return orderedAllDeps, orderedDeclaredDeps
618}
619
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800620func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
621 // convert Module to Path
622 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
623 staticDepFiles := []android.Path{}
624 for _, dep := range staticDeps {
625 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
626 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700627 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800628 sharedDepFiles := []android.Path{}
629 for _, sharedDep := range sharedDeps {
630 staticAnalogue := sharedDep.staticVariant
631 if staticAnalogue != nil {
632 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
633 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
634 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700635 }
636
637 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800638 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700639
640 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700641}
642
Colin Cross635c3b02016-05-18 15:37:25 -0700643func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700644
Colin Crossca860ac2016-01-04 14:34:37 -0800645 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700646 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800647 moduleContextImpl: moduleContextImpl{
648 mod: c,
649 },
650 }
651 ctx.ctx = ctx
652
Colin Crossf18e1102017-11-16 14:33:08 -0800653 deps := c.depsToPaths(ctx)
654 if ctx.Failed() {
655 return
656 }
657
Colin Crossca860ac2016-01-04 14:34:37 -0800658 flags := Flags{
659 Toolchain: c.toolchain(ctx),
660 Clang: c.clang(ctx),
661 }
Colin Crossca860ac2016-01-04 14:34:37 -0800662 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800663 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800664 }
665 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700666 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800667 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700668 if c.stl != nil {
669 flags = c.stl.flags(ctx, flags)
670 }
Colin Cross16b23492016-01-06 14:41:07 -0800671 if c.sanitize != nil {
672 flags = c.sanitize.flags(ctx, flags)
673 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800674 if c.coverage != nil {
675 flags = c.coverage.flags(ctx, flags)
676 }
Stephen Craneba090d12017-05-09 15:44:35 -0700677 if c.lto != nil {
678 flags = c.lto.flags(ctx, flags)
679 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700680 if c.pgo != nil {
681 flags = c.pgo.flags(ctx, flags)
682 }
Colin Crossca860ac2016-01-04 14:34:37 -0800683 for _, feature := range c.features {
684 flags = feature.flags(ctx, flags)
685 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800686 if ctx.Failed() {
687 return
688 }
689
Colin Crossb98c8b02016-07-29 13:44:28 -0700690 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
691 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
692 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800693
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800694 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
695 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700696 // We need access to all the flags seen by a source file.
697 if c.sabi != nil {
698 flags = c.sabi.flags(ctx, flags)
699 }
Colin Crossca860ac2016-01-04 14:34:37 -0800700 // Optimization to reduce size of build.ninja
701 // Replace the long list of flags for each file with a module-local variable
702 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
703 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
704 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
705 flags.CFlags = []string{"$cflags"}
706 flags.CppFlags = []string{"$cppflags"}
707 flags.AsFlags = []string{"$asflags"}
708
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700709 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800710 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700711 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800712 if ctx.Failed() {
713 return
714 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800715 }
716
Colin Crossca860ac2016-01-04 14:34:37 -0800717 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700718 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800719 if ctx.Failed() {
720 return
721 }
Colin Cross635c3b02016-05-18 15:37:25 -0700722 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700723 }
Colin Cross5049f022015-03-18 13:28:46 -0700724
Colin Crossce75d2c2016-10-06 16:12:58 -0700725 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
726 c.installer.install(ctx, c.outputFile.Path())
727 if ctx.Failed() {
728 return
Colin Crossca860ac2016-01-04 14:34:37 -0800729 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700730 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800731}
732
Colin Crossb98c8b02016-07-29 13:44:28 -0700733func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800734 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700735 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800736 }
Colin Crossca860ac2016-01-04 14:34:37 -0800737 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800738}
739
Colin Crossca860ac2016-01-04 14:34:37 -0800740func (c *Module) begin(ctx BaseModuleContext) {
741 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700742 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700743 }
Colin Crossca860ac2016-01-04 14:34:37 -0800744 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700745 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800746 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700747 if c.stl != nil {
748 c.stl.begin(ctx)
749 }
Colin Cross16b23492016-01-06 14:41:07 -0800750 if c.sanitize != nil {
751 c.sanitize.begin(ctx)
752 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800753 if c.coverage != nil {
754 c.coverage.begin(ctx)
755 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800756 if c.sabi != nil {
757 c.sabi.begin(ctx)
758 }
Justin Yun8effde42017-06-23 19:24:43 +0900759 if c.vndkdep != nil {
760 c.vndkdep.begin(ctx)
761 }
Stephen Craneba090d12017-05-09 15:44:35 -0700762 if c.lto != nil {
763 c.lto.begin(ctx)
764 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700765 if c.pgo != nil {
766 c.pgo.begin(ctx)
767 }
Colin Crossca860ac2016-01-04 14:34:37 -0800768 for _, feature := range c.features {
769 feature.begin(ctx)
770 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700771 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700772 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700773 if err != nil {
774 ctx.PropertyErrorf("sdk_version", err.Error())
775 }
Nan Zhang0007d812017-11-07 10:57:05 -0800776 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700777 }
Colin Crossca860ac2016-01-04 14:34:37 -0800778}
779
Colin Cross37047f12016-12-13 17:06:13 -0800780func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700781 deps := Deps{}
782
783 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700784 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700785 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700786 // Add the PGO dependency (the clang_rt.profile runtime library), which
787 // sometimes depends on symbols from libgcc, before libgcc gets added
788 // in linkerDeps().
789 if c.pgo != nil {
790 deps = c.pgo.deps(ctx, deps)
791 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700792 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700793 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700794 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700795 if c.stl != nil {
796 deps = c.stl.deps(ctx, deps)
797 }
Colin Cross16b23492016-01-06 14:41:07 -0800798 if c.sanitize != nil {
799 deps = c.sanitize.deps(ctx, deps)
800 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800801 if c.coverage != nil {
802 deps = c.coverage.deps(ctx, deps)
803 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800804 if c.sabi != nil {
805 deps = c.sabi.deps(ctx, deps)
806 }
Justin Yun8effde42017-06-23 19:24:43 +0900807 if c.vndkdep != nil {
808 deps = c.vndkdep.deps(ctx, deps)
809 }
Stephen Craneba090d12017-05-09 15:44:35 -0700810 if c.lto != nil {
811 deps = c.lto.deps(ctx, deps)
812 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700813 for _, feature := range c.features {
814 deps = feature.deps(ctx, deps)
815 }
816
Colin Crossb6715442017-10-24 11:13:31 -0700817 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
818 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
819 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
820 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
821 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
822 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700823
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700824 for _, lib := range deps.ReexportSharedLibHeaders {
825 if !inList(lib, deps.SharedLibs) {
826 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
827 }
828 }
829
830 for _, lib := range deps.ReexportStaticLibHeaders {
831 if !inList(lib, deps.StaticLibs) {
832 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
833 }
834 }
835
Colin Cross5950f382016-12-13 12:50:57 -0800836 for _, lib := range deps.ReexportHeaderLibHeaders {
837 if !inList(lib, deps.HeaderLibs) {
838 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
839 }
840 }
841
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700842 for _, gen := range deps.ReexportGeneratedHeaders {
843 if !inList(gen, deps.GeneratedHeaders) {
844 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
845 }
846 }
847
Colin Crossc99deeb2016-04-11 15:06:20 -0700848 return deps
849}
850
Dan Albert7e9d2952016-08-04 13:02:36 -0700851func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800852 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700853 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800854 moduleContextImpl: moduleContextImpl{
855 mod: c,
856 },
857 }
858 ctx.ctx = ctx
859
Colin Crossca860ac2016-01-04 14:34:37 -0800860 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700861}
862
Colin Cross1e676be2016-10-12 14:38:15 -0700863func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
864 if !c.Enabled() {
865 return
866 }
867
Colin Cross37047f12016-12-13 17:06:13 -0800868 ctx := &depsContext{
869 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700870 moduleContextImpl: moduleContextImpl{
871 mod: c,
872 },
873 }
874 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800875
Colin Crossc99deeb2016-04-11 15:06:20 -0700876 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800877
Dan Albert914449f2016-06-17 16:45:24 -0700878 variantNdkLibs := []string{}
879 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700880 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700881 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700882
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700883 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
884 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700885 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700886 // 1. Name of an NDK library that refers to a prebuilt module.
887 // For each of these, it adds the name of the prebuilt module (which will be in
888 // prebuilts/ndk) to the list of nonvariant libs.
889 // 2. Name of an NDK library that refers to an ndk_library module.
890 // For each of these, it adds the name of the ndk_library module to the list of
891 // variant libs.
892 // 3. Anything else (so anything that isn't an NDK library).
893 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700894 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700895 // The caller can then know to add the variantLibs dependencies differently from the
896 // nonvariantLibs
897 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
898 variantLibs = []string{}
899 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700900 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700901 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700902 if !inList(entry, ndkMigratedLibs) {
903 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
904 } else {
905 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
906 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700907 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700908 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700909 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700910 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700911 }
912 }
Dan Albert914449f2016-06-17 16:45:24 -0700913 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700914 }
915
Dan Albert914449f2016-06-17 16:45:24 -0700916 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
917 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900918 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700919 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700920
Colin Cross32ec36c2016-12-15 07:39:51 -0800921 for _, lib := range deps.HeaderLibs {
922 depTag := headerDepTag
923 if inList(lib, deps.ReexportHeaderLibHeaders) {
924 depTag = headerExportDepTag
925 }
926 actx.AddVariationDependencies(nil, depTag, lib)
927 }
Colin Cross5950f382016-12-13 12:50:57 -0800928
Colin Crossc99deeb2016-04-11 15:06:20 -0700929 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
930 deps.WholeStaticLibs...)
931
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700932 for _, lib := range deps.StaticLibs {
933 depTag := staticDepTag
934 if inList(lib, deps.ReexportStaticLibHeaders) {
935 depTag = staticExportDepTag
936 }
Colin Cross15a0d462016-07-14 14:49:58 -0700937 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700938 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700939
940 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
941 deps.LateStaticLibs...)
942
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700943 for _, lib := range deps.SharedLibs {
944 depTag := sharedDepTag
945 if inList(lib, deps.ReexportSharedLibHeaders) {
946 depTag = sharedExportDepTag
947 }
Colin Cross15a0d462016-07-14 14:49:58 -0700948 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700949 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700950
951 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
952 deps.LateSharedLibs...)
953
Colin Cross68861832016-07-08 10:41:41 -0700954 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700955
956 for _, gen := range deps.GeneratedHeaders {
957 depTag := genHeaderDepTag
958 if inList(gen, deps.ReexportGeneratedHeaders) {
959 depTag = genHeaderExportDepTag
960 }
961 actx.AddDependency(c, depTag, gen)
962 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700963
Colin Cross68861832016-07-08 10:41:41 -0700964 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700965
966 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700967 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800968 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700969 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700970 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700971 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700972 if deps.LinkerScript != "" {
973 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
974 }
Dan Albert914449f2016-06-17 16:45:24 -0700975
976 version := ctx.sdkVersion()
977 actx.AddVariationDependencies([]blueprint.Variation{
978 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
979 actx.AddVariationDependencies([]blueprint.Variation{
980 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +0800981
982 if vndkdep := c.vndkdep; vndkdep != nil {
983 if vndkdep.isVndkExt() {
984 baseModuleMode := vendorMode
985 if actx.DeviceConfig().VndkVersion() == "" {
986 baseModuleMode = coreMode
987 }
988 actx.AddVariationDependencies([]blueprint.Variation{
989 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
990 vndkdep.getVndkExtendsModuleName())
991 }
992 }
Colin Cross6362e272015-10-29 15:25:03 -0700993}
Colin Cross21b9a242015-03-24 14:15:58 -0700994
Dan Albert7e9d2952016-08-04 13:02:36 -0700995func beginMutator(ctx android.BottomUpMutatorContext) {
996 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
997 c.beginMutator(ctx)
998 }
999}
1000
Colin Crossca860ac2016-01-04 14:34:37 -08001001func (c *Module) clang(ctx BaseModuleContext) bool {
1002 clang := Bool(c.Properties.Clang)
1003
1004 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001005 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001006 }
Colin Cross28344522015-04-22 13:07:53 -07001007
Colin Crossca860ac2016-01-04 14:34:37 -08001008 if !c.toolchain(ctx).ClangSupported() {
1009 clang = false
1010 }
1011
1012 return clang
1013}
1014
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001015// Whether a module can link to another module, taking into
1016// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001017func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001018 if from.Target().Os != android.Android {
1019 // Host code is not restricted
1020 return
1021 }
1022 if from.Properties.UseVndk {
1023 // Though vendor code is limited by the vendor mutator,
1024 // each vendor-available module needs to check
1025 // link-type for VNDK.
1026 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001027 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001028 }
1029 return
1030 }
Nan Zhang0007d812017-11-07 10:57:05 -08001031 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001032 // Platform code can link to anything
1033 return
1034 }
1035 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1036 // These are always allowed
1037 return
1038 }
1039 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
1040 // These are allowed, but they don't set sdk_version
1041 return
1042 }
1043 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1044 // These are allowed, but they don't set sdk_version
1045 return
1046 }
1047 if _, ok := to.linker.(*stubDecorator); ok {
1048 // These aren't real libraries, but are the stub shared libraries that are included in
1049 // the NDK.
1050 return
1051 }
Nan Zhang0007d812017-11-07 10:57:05 -08001052 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001053 // NDK code linking to platform code is never okay.
1054 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1055 ctx.OtherModuleName(to))
1056 }
1057
1058 // At this point we know we have two NDK libraries, but we need to
1059 // check that we're not linking against anything built against a higher
1060 // API level, as it is only valid to link against older or equivalent
1061 // APIs.
1062
Nan Zhang0007d812017-11-07 10:57:05 -08001063 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001064 // Current can link against anything.
1065 return
Nan Zhang0007d812017-11-07 10:57:05 -08001066 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001067 // Current can't be linked against by anything else.
1068 ctx.ModuleErrorf("links %q built against newer API version %q",
1069 ctx.OtherModuleName(to), "current")
1070 }
1071
Nan Zhang0007d812017-11-07 10:57:05 -08001072 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001073 if err != nil {
1074 ctx.PropertyErrorf("sdk_version",
1075 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001076 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001077 }
Nan Zhang0007d812017-11-07 10:57:05 -08001078 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001079 if err != nil {
1080 ctx.PropertyErrorf("sdk_version",
1081 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001082 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001083 }
1084
1085 if toApi > fromApi {
1086 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001087 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001088 }
Dan Albert202fe492017-12-15 13:56:59 -08001089
1090 // Also check that the two STL choices are compatible.
1091 fromStl := from.stl.Properties.SelectedStl
1092 toStl := to.stl.Properties.SelectedStl
1093 if fromStl == "" || toStl == "" {
1094 // Libraries that don't use the STL are unrestricted.
1095 return
1096 }
1097
1098 if fromStl == "ndk_system" || toStl == "ndk_system" {
1099 // We can be permissive with the system "STL" since it is only the C++
1100 // ABI layer, but in the future we should make sure that everyone is
1101 // using either libc++ or nothing.
1102 return
1103 }
1104
1105 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1106 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1107 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1108 to.stl.Properties.SelectedStl)
1109 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001110}
1111
Colin Crossc99deeb2016-04-11 15:06:20 -07001112// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001113func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001114 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001115
Jeff Gaston294356f2017-09-27 17:05:30 -07001116 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001117 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001118
Colin Crossd11fcda2017-10-23 17:59:01 -07001119 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001120 depName := ctx.OtherModuleName(dep)
1121 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001122
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001123 ccDep, _ := dep.(*Module)
1124 if ccDep == nil {
1125 // handling for a few module types that aren't cc Module but that are also supported
1126 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001127 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001128 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001129 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001130 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001131 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1132 genRule.GeneratedSourceFiles()...)
1133 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001134 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001135 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001136 // Support exported headers from a generated_sources dependency
1137 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001138 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001139 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001140 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
1141 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001142 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001143 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001144 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001145 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001146 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
1147 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001148 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1149 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1150
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001151 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001152 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001153 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001154 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001155 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001156 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001157 files := genRule.GeneratedSourceFiles()
1158 if len(files) == 1 {
1159 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1160 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001161 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001162 }
1163 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001164 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001165 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001166 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001167 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001168 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001169 return
1170 }
1171
Colin Crossd11fcda2017-10-23 17:59:01 -07001172 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001173 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1174 return
1175 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001176 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001177 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001178 return
1179 }
1180
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001181 // re-exporting flags
1182 if depTag == reuseObjTag {
1183 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001184 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001185 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001186 depPaths.Objs = depPaths.Objs.Append(objs)
1187 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001188 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001189 return
1190 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001191 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001192 if t, ok := depTag.(dependencyTag); ok && t.library {
1193 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001194 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001195 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001196 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001197 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001198
1199 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001200 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001201 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001202 // 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 -07001203 // Re-exported shared library headers must be included as well since they can help us with type information
1204 // about template instantiations (instantiated from their headers).
1205 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001206 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001207 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001208
Logan Chienf3511742017-10-31 18:04:35 +08001209 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001210 }
1211
Colin Cross26c34ed2016-09-30 17:10:16 -07001212 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001213 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001214
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001215 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001216 depFile := android.OptionalPath{}
1217
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001218 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001219 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001220 ptr = &depPaths.SharedLibs
1221 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001222 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001223 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001224 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001225 ptr = &depPaths.LateSharedLibs
1226 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001227 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001228 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001229 ptr = nil
1230 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001231 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001232 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001233 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001234 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001235 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001236 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001237 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001238 return
1239 }
1240
1241 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001242 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001243 for i := range missingDeps {
1244 missingDeps[i] += postfix
1245 }
1246 ctx.AddMissingDependencies(missingDeps)
1247 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001248 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001249 case headerDepTag:
1250 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001251 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001252 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001253 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001254 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001255 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001256 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001257 }
1258
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001259 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001260 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001261 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001262 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001263 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001264 return
1265 }
1266
1267 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001268 // in static libraries act as if they were whole static libraries. The same goes for
1269 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001270 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1271 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001272 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1273 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001274
Dan Willemsen581341d2017-02-09 16:16:31 -08001275 }
1276
Colin Cross26c34ed2016-09-30 17:10:16 -07001277 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001278 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001279 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001280 return
1281 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001282 *ptr = append(*ptr, linkFile.Path())
1283 }
1284
Colin Crossc99deeb2016-04-11 15:06:20 -07001285 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001286 dep := depFile
1287 if !dep.Valid() {
1288 dep = linkFile
1289 }
1290 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001291 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001292
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001293 // Export the shared libs to Make.
1294 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001295 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001296 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001297 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001298 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001299 var makeLibName string
1300 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1301 if c.useVndk() && bothVendorAndCoreVariantsExist {
1302 // The vendor module in Make will have been renamed to not conflict with the core
1303 // module, so update the dependency name here accordingly.
1304 makeLibName = libName + vendorSuffix
1305 } else {
1306 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001307 }
1308 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001309 // they merely serve as Make dependencies and do not affect this lib itself.
1310 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001311 }
Colin Crossca860ac2016-01-04 14:34:37 -08001312 })
1313
Jeff Gaston294356f2017-09-27 17:05:30 -07001314 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001315 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001316
Colin Crossdd84e052017-05-17 13:44:16 -07001317 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001318 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001319 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001320 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001321 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1322
1323 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001324 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001325 }
Colin Crossdd84e052017-05-17 13:44:16 -07001326
Colin Crossca860ac2016-01-04 14:34:37 -08001327 return depPaths
1328}
1329
1330func (c *Module) InstallInData() bool {
1331 if c.installer == nil {
1332 return false
1333 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001334 return c.installer.inData()
1335}
1336
1337func (c *Module) InstallInSanitizerDir() bool {
1338 if c.installer == nil {
1339 return false
1340 }
1341 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001342 return true
1343 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001344 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001345}
1346
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001347func (c *Module) HostToolPath() android.OptionalPath {
1348 if c.installer == nil {
1349 return android.OptionalPath{}
1350 }
1351 return c.installer.hostToolPath()
1352}
1353
Nan Zhangd4e641b2017-07-12 12:55:28 -07001354func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1355 return c.outputFile
1356}
1357
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001358func (c *Module) Srcs() android.Paths {
1359 if c.outputFile.Valid() {
1360 return android.Paths{c.outputFile.Path()}
1361 }
1362 return android.Paths{}
1363}
1364
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001365func (c *Module) static() bool {
1366 if static, ok := c.linker.(interface {
1367 static() bool
1368 }); ok {
1369 return static.static()
1370 }
1371 return false
1372}
1373
Colin Cross2ba19d92015-05-07 15:44:20 -07001374//
Colin Crosscfad1192015-11-02 16:43:11 -08001375// Defaults
1376//
Colin Crossca860ac2016-01-04 14:34:37 -08001377type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001378 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001379 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001380}
1381
Colin Cross635c3b02016-05-18 15:37:25 -07001382func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001383}
1384
Colin Cross1e676be2016-10-12 14:38:15 -07001385func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1386}
1387
Colin Cross36242852017-06-23 15:06:31 -07001388func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001389 return DefaultsFactory()
1390}
1391
Colin Cross36242852017-06-23 15:06:31 -07001392func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001393 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001394
Colin Cross36242852017-06-23 15:06:31 -07001395 module.AddProperties(props...)
1396 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001397 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001398 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001399 &BaseCompilerProperties{},
1400 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001401 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001402 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001403 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001404 &TestProperties{},
1405 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001406 &UnusedProperties{},
1407 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001408 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001409 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001410 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001411 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001412 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001413 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001414 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001415 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001416 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001417 )
Colin Crosscfad1192015-11-02 16:43:11 -08001418
Colin Cross1f44a3a2017-07-07 14:33:33 -07001419 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001420
1421 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001422}
1423
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001424const (
1425 // coreMode is the variant used for framework-private libraries, or
1426 // SDK libraries. (which framework-private libraries can use)
1427 coreMode = "core"
1428
1429 // vendorMode is the variant used for /vendor code that compiles
1430 // against the VNDK.
1431 vendorMode = "vendor"
1432)
1433
Jiyong Park6a43f042017-10-12 23:05:00 +09001434func squashVendorSrcs(m *Module) {
1435 if lib, ok := m.compiler.(*libraryDecorator); ok {
1436 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1437 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1438
1439 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1440 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1441 }
1442}
1443
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001444func vendorMutator(mctx android.BottomUpMutatorContext) {
1445 if mctx.Os() != android.Android {
1446 return
1447 }
1448
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001449 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1450 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001451 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001452 mctx.CreateVariations(coreMode)
1453 } else if Bool(props.Vendor_available) {
1454 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001455 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001456 mctx.CreateVariations(vendorMode)
1457 } else {
1458 mctx.CreateVariations(coreMode)
1459 }
1460 }
1461 }
1462
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001463 m, ok := mctx.Module().(*Module)
1464 if !ok {
1465 return
1466 }
1467
1468 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001469 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1470
1471 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001472 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001473 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001474 return
1475 }
Logan Chienf3511742017-10-31 18:04:35 +08001476
1477 if vndkdep := m.vndkdep; vndkdep != nil {
1478 if vndkdep.isVndk() {
1479 if vendorSpecific {
1480 if !vndkdep.isVndkExt() {
1481 mctx.PropertyErrorf("vndk",
1482 "must set `extends: \"...\"` to vndk extension")
1483 return
1484 }
1485 } else {
1486 if vndkdep.isVndkExt() {
1487 mctx.PropertyErrorf("vndk",
1488 "must set `vendor: true` to set `extends: %q`",
1489 m.getVndkExtendsModuleName())
1490 return
1491 }
1492 if m.VendorProperties.Vendor_available == nil {
1493 mctx.PropertyErrorf("vndk",
1494 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1495 return
1496 }
1497 }
1498 } else {
1499 if vndkdep.isVndkSp() {
1500 mctx.PropertyErrorf("vndk",
1501 "must set `enabled: true` to set `support_system_process: true`")
1502 return
1503 }
1504 if vndkdep.isVndkExt() {
1505 mctx.PropertyErrorf("vndk",
1506 "must set `enabled: true` to set `extends: %q`",
1507 m.getVndkExtendsModuleName())
1508 return
1509 }
Justin Yun8effde42017-06-23 19:24:43 +09001510 }
1511 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001512
Justin Yun71549282017-11-17 12:10:28 +09001513 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001514 // If the device isn't compiling against the VNDK, we always
1515 // use the core mode.
1516 mctx.CreateVariations(coreMode)
1517 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1518 // LL-NDK stubs only exist in the vendor variant, since the
1519 // real libraries will be used in the core variant.
1520 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001521 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1522 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001523 mod := mctx.CreateVariations(vendorMode)
1524 vendor := mod[0].(*Module)
1525 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001526 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001527 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1528 // PRODUCT_EXTRA_VNDK_VERSIONS.
1529 mod := mctx.CreateVariations(vendorMode)
1530 vendor := mod[0].(*Module)
1531 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001532 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001533 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001534 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001535 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001536 vendor := mod[1].(*Module)
1537 vendor.Properties.UseVndk = true
1538 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001539 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001540 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001541 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001542 vendor := mod[0].(*Module)
1543 vendor.Properties.UseVndk = true
1544 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001545 } else {
1546 // This is either in /system (or similar: /data), or is a
1547 // modules built with the NDK. Modules built with the NDK
1548 // will be restricted using the existing link type checks.
1549 mctx.CreateVariations(coreMode)
1550 }
1551}
1552
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001553func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001554 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001555 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1556 }
Colin Cross6510f912017-11-29 00:27:14 -08001557 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001558}
1559
Colin Cross06a931b2015-10-28 17:23:31 -07001560var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001561var BoolPtr = proptools.BoolPtr
1562var String = proptools.String
1563var StringPtr = proptools.StringPtr