blob: 91bf9a6d0434bda1a7cf5e9b38fd7bc98e70fbce [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
Dan Willemsenab9f4262018-02-14 13:58:34 -0800137 ProtoRoot bool
Colin Crossca860ac2016-01-04 14:34:37 -0800138
139 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800140 DynamicLinker string
141
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700142 CFlagsDeps android.Paths // Files depended on by compiler flags
143 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800144
145 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800146 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700147}
148
Colin Cross81413472016-04-11 14:37:39 -0700149type ObjectLinkerProperties struct {
150 // names of other cc_object modules to link into this module using partial linking
151 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700152
153 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800154 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700155}
156
Colin Crossca860ac2016-01-04 14:34:37 -0800157// Properties used to compile all C or C++ modules
158type BaseProperties struct {
159 // compile module with clang instead of gcc
160 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700161
162 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800163 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700164
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700165 AndroidMkSharedLibs []string `blueprint:"mutated"`
166 HideFromMake bool `blueprint:"mutated"`
167 PreventInstall bool `blueprint:"mutated"`
168
169 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800170
171 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
172 // file
173 Logtags []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700174}
175
176type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900177 // whether this module should be allowed to be directly depended by other
178 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
179 // If set to true, two variants will be built separately, one like
180 // normal, and the other limited to the set of libraries and headers
181 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700182 //
183 // The vendor variant may be used with a different (newer) /system,
184 // so it shouldn't have any unversioned runtime dependencies, or
185 // make assumptions about the system that may not be true in the
186 // future.
187 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900188 // If set to false, this module becomes inaccessible from /vendor modules.
189 //
190 // Default value is true when vndk: {enabled: true} or vendor: true.
191 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700192 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
193 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800194}
195
Colin Crossca860ac2016-01-04 14:34:37 -0800196type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800197 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800198}
199
Colin Crossca860ac2016-01-04 14:34:37 -0800200type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800201 static() bool
202 staticBinary() bool
203 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700204 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700205 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800206 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700207 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900208 isVndk() bool
209 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800210 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800211 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700212 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700213 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800214 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800215 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800216}
217
218type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700219 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800220 ModuleContextIntf
221}
222
223type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700224 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800225 ModuleContextIntf
226}
227
Colin Cross37047f12016-12-13 17:06:13 -0800228type DepsContext interface {
229 android.BottomUpMutatorContext
230 ModuleContextIntf
231}
232
Colin Crossca860ac2016-01-04 14:34:37 -0800233type feature interface {
234 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800235 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800236 flags(ctx ModuleContext, flags Flags) Flags
237 props() []interface{}
238}
239
240type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700241 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800242 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800243 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700244 compilerProps() []interface{}
245
Colin Cross76fada02016-07-27 10:31:13 -0700246 appendCflags([]string)
247 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700248 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800249}
250
251type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700252 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800253 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700254 linkerFlags(ctx ModuleContext, flags Flags) Flags
255 linkerProps() []interface{}
256
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700257 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700258 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800259}
260
261type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700262 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700263 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800264 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700265 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700266 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800267}
268
Colin Crossc99deeb2016-04-11 15:06:20 -0700269type dependencyTag struct {
270 blueprint.BaseDependencyTag
271 name string
272 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700273
274 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700275}
276
277var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700278 sharedDepTag = dependencyTag{name: "shared", library: true}
279 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
280 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
281 staticDepTag = dependencyTag{name: "static", library: true}
282 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
283 lateStaticDepTag = dependencyTag{name: "late static", library: true}
284 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800285 headerDepTag = dependencyTag{name: "header", library: true}
286 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700287 genSourceDepTag = dependencyTag{name: "gen source"}
288 genHeaderDepTag = dependencyTag{name: "gen header"}
289 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
290 objDepTag = dependencyTag{name: "obj"}
291 crtBeginDepTag = dependencyTag{name: "crtbegin"}
292 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700293 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700294 reuseObjTag = dependencyTag{name: "reuse objects"}
295 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
296 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800297 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700298)
299
Colin Crossca860ac2016-01-04 14:34:37 -0800300// Module contains the properties and members used by all C/C++ module types, and implements
301// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
302// to construct the output file. Behavior can be customized with a Customizer interface
303type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700304 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700305 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700306
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700307 Properties BaseProperties
308 VendorProperties VendorProperties
309 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700310
Colin Crossca860ac2016-01-04 14:34:37 -0800311 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700312 hod android.HostOrDeviceSupported
313 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700314
Colin Crossca860ac2016-01-04 14:34:37 -0800315 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700316 features []feature
317 compiler compiler
318 linker linker
319 installer installer
320 stl *stl
321 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800322 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800323 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900324 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700325 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700326 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800327
328 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700329
Colin Cross635c3b02016-05-18 15:37:25 -0700330 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800331
Colin Crossb98c8b02016-07-29 13:44:28 -0700332 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700333
334 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800335
336 // Flags used to compile this module
337 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700338
339 // 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 -0800340 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700341 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800342 depsInLinkOrder android.Paths
343
344 // only non-nil when this is a shared library that reuses the objects of a static library
345 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700346}
347
Colin Cross36242852017-06-23 15:06:31 -0700348func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700349 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800350 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700351 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800352 }
353 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700354 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800355 }
356 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700357 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800358 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700359 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700360 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700361 }
Colin Cross16b23492016-01-06 14:41:07 -0800362 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700363 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800364 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800365 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700366 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800367 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800368 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700369 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800370 }
Justin Yun8effde42017-06-23 19:24:43 +0900371 if c.vndkdep != nil {
372 c.AddProperties(c.vndkdep.props()...)
373 }
Stephen Craneba090d12017-05-09 15:44:35 -0700374 if c.lto != nil {
375 c.AddProperties(c.lto.props()...)
376 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700377 if c.pgo != nil {
378 c.AddProperties(c.pgo.props()...)
379 }
Colin Crossca860ac2016-01-04 14:34:37 -0800380 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700381 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800382 }
Colin Crossc472d572015-03-17 15:06:21 -0700383
Colin Cross36242852017-06-23 15:06:31 -0700384 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700385
Colin Cross1f44a3a2017-07-07 14:33:33 -0700386 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700387
388 return c
Colin Crossc472d572015-03-17 15:06:21 -0700389}
390
Colin Crossb916a382016-07-29 17:28:03 -0700391// Returns true for dependency roots (binaries)
392// TODO(ccross): also handle dlopenable libraries
393func (c *Module) isDependencyRoot() bool {
394 if root, ok := c.linker.(interface {
395 isDependencyRoot() bool
396 }); ok {
397 return root.isDependencyRoot()
398 }
399 return false
400}
401
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700402func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700403 return c.Properties.UseVndk
404}
405
Justin Yun8effde42017-06-23 19:24:43 +0900406func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800407 if vndkdep := c.vndkdep; vndkdep != nil {
408 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900409 }
410 return false
411}
412
Yi Kong7e53c572018-02-14 18:16:12 +0800413func (c *Module) isPgoCompile() bool {
414 if pgo := c.pgo; pgo != nil {
415 return pgo.Properties.PgoCompile
416 }
417 return false
418}
419
Logan Chienf3511742017-10-31 18:04:35 +0800420func (c *Module) isVndkSp() bool {
421 if vndkdep := c.vndkdep; vndkdep != nil {
422 return vndkdep.isVndkSp()
423 }
424 return false
425}
426
427func (c *Module) isVndkExt() bool {
428 if vndkdep := c.vndkdep; vndkdep != nil {
429 return vndkdep.isVndkExt()
430 }
431 return false
432}
433
434func (c *Module) getVndkExtendsModuleName() string {
435 if vndkdep := c.vndkdep; vndkdep != nil {
436 return vndkdep.getVndkExtendsModuleName()
437 }
438 return ""
439}
440
Jiyong Park82e2bf32017-08-16 14:05:54 +0900441// Returns true only when this module is configured to have core and vendor
442// variants.
443func (c *Module) hasVendorVariant() bool {
444 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
445}
446
Colin Crossca860ac2016-01-04 14:34:37 -0800447type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700448 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800449 moduleContextImpl
450}
451
Colin Cross37047f12016-12-13 17:06:13 -0800452type depsContext struct {
453 android.BottomUpMutatorContext
454 moduleContextImpl
455}
456
Colin Crossca860ac2016-01-04 14:34:37 -0800457type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700458 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800459 moduleContextImpl
460}
461
Jiyong Park2db76922017-11-08 16:03:48 +0900462func (ctx *moduleContext) SocSpecific() bool {
463 return ctx.ModuleContext.SocSpecific() ||
464 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700465}
466
Colin Crossca860ac2016-01-04 14:34:37 -0800467type moduleContextImpl struct {
468 mod *Module
469 ctx BaseModuleContext
470}
471
Colin Crossca860ac2016-01-04 14:34:37 -0800472func (ctx *moduleContextImpl) clang() bool {
473 return ctx.mod.clang(ctx.ctx)
474}
475
Colin Crossb98c8b02016-07-29 13:44:28 -0700476func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800477 return ctx.mod.toolchain(ctx.ctx)
478}
479
480func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000481 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800482}
483
484func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700485 if static, ok := ctx.mod.linker.(interface {
486 staticBinary() bool
487 }); ok {
488 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800489 }
Colin Crossb916a382016-07-29 17:28:03 -0700490 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800491}
492
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700493func (ctx *moduleContextImpl) useSdk() bool {
494 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800495 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700496 }
497 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800498}
499
500func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700501 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700502 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700503 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800504 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800505 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800506 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700507 }
508 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800509}
510
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700511func (ctx *moduleContextImpl) useVndk() bool {
512 return ctx.mod.useVndk()
513}
Justin Yun8effde42017-06-23 19:24:43 +0900514
Logan Chienf3511742017-10-31 18:04:35 +0800515func (ctx *moduleContextImpl) isVndk() bool {
516 return ctx.mod.isVndk()
517}
518
Yi Kong7e53c572018-02-14 18:16:12 +0800519func (ctx *moduleContextImpl) isPgoCompile() bool {
520 return ctx.mod.isPgoCompile()
521}
522
Justin Yun8effde42017-06-23 19:24:43 +0900523func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800524 return ctx.mod.isVndkSp()
525}
526
527func (ctx *moduleContextImpl) isVndkExt() bool {
528 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900529}
530
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800531// Create source abi dumps if the module belongs to the list of VndkLibraries.
532func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800533 isUnsanitizedVariant := true
534 sanitize := ctx.mod.sanitize
535 if sanitize != nil {
536 isUnsanitizedVariant = sanitize.isUnsanitizedVariant()
537 }
Jayant Chowdhary22963cd2018-03-06 14:59:50 -0800538 vendorAvailable := Bool(ctx.mod.VendorProperties.Vendor_available)
539 return vendorAvailable && isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800540}
541
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700542func (ctx *moduleContextImpl) selectedStl() string {
543 if stl := ctx.mod.stl; stl != nil {
544 return stl.Properties.SelectedStl
545 }
546 return ""
547}
548
Colin Crossce75d2c2016-10-06 16:12:58 -0700549func (ctx *moduleContextImpl) baseModuleName() string {
550 return ctx.mod.ModuleBase.BaseModuleName()
551}
552
Logan Chienf3511742017-10-31 18:04:35 +0800553func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
554 return ctx.mod.getVndkExtendsModuleName()
555}
556
Colin Cross635c3b02016-05-18 15:37:25 -0700557func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800558 return &Module{
559 hod: hod,
560 multilib: multilib,
561 }
562}
563
Colin Cross635c3b02016-05-18 15:37:25 -0700564func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800565 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700566 module.features = []feature{
567 &tidyFeature{},
568 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700569 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800570 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800571 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800572 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900573 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700574 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700575 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800576 return module
577}
578
Colin Crossce75d2c2016-10-06 16:12:58 -0700579func (c *Module) Prebuilt() *android.Prebuilt {
580 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
581 return p.prebuilt()
582 }
583 return nil
584}
585
586func (c *Module) Name() string {
587 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700588 if p, ok := c.linker.(interface {
589 Name(string) string
590 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700591 name = p.Name(name)
592 }
593 return name
594}
595
Jeff Gaston294356f2017-09-27 17:05:30 -0700596// orderDeps reorders dependencies into a list such that if module A depends on B, then
597// A will precede B in the resultant list.
598// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800599// Note that directSharedDeps should be the analogous static library for each shared lib dep
600func 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 -0700601 // If A depends on B, then
602 // Every list containing A will also contain B later in the list
603 // So, after concatenating all lists, the final instance of B will have come from the same
604 // original list as the final instance of A
605 // So, the final instance of B will be later in the concatenation than the final A
606 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
607 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800608 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700609 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800610 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
611 }
612 for _, dep := range directSharedDeps {
613 orderedAllDeps = append(orderedAllDeps, dep)
614 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700615 }
616
Colin Crossb6715442017-10-24 11:13:31 -0700617 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700618
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800619 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700620 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800621 // resultant list to only what the caller has chosen to include in directStaticDeps
622 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700623
624 return orderedAllDeps, orderedDeclaredDeps
625}
626
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800627func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
628 // convert Module to Path
629 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
630 staticDepFiles := []android.Path{}
631 for _, dep := range staticDeps {
632 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
633 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700634 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800635 sharedDepFiles := []android.Path{}
636 for _, sharedDep := range sharedDeps {
637 staticAnalogue := sharedDep.staticVariant
638 if staticAnalogue != nil {
639 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
640 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
641 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700642 }
643
644 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800645 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700646
647 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700648}
649
Colin Cross635c3b02016-05-18 15:37:25 -0700650func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700651
Colin Crossca860ac2016-01-04 14:34:37 -0800652 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700653 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800654 moduleContextImpl: moduleContextImpl{
655 mod: c,
656 },
657 }
658 ctx.ctx = ctx
659
Colin Crossf18e1102017-11-16 14:33:08 -0800660 deps := c.depsToPaths(ctx)
661 if ctx.Failed() {
662 return
663 }
664
Colin Crossca860ac2016-01-04 14:34:37 -0800665 flags := Flags{
666 Toolchain: c.toolchain(ctx),
667 Clang: c.clang(ctx),
668 }
Colin Crossca860ac2016-01-04 14:34:37 -0800669 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800670 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800671 }
672 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700673 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800674 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700675 if c.stl != nil {
676 flags = c.stl.flags(ctx, flags)
677 }
Colin Cross16b23492016-01-06 14:41:07 -0800678 if c.sanitize != nil {
679 flags = c.sanitize.flags(ctx, flags)
680 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800681 if c.coverage != nil {
682 flags = c.coverage.flags(ctx, flags)
683 }
Stephen Craneba090d12017-05-09 15:44:35 -0700684 if c.lto != nil {
685 flags = c.lto.flags(ctx, flags)
686 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700687 if c.pgo != nil {
688 flags = c.pgo.flags(ctx, flags)
689 }
Colin Crossca860ac2016-01-04 14:34:37 -0800690 for _, feature := range c.features {
691 flags = feature.flags(ctx, flags)
692 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800693 if ctx.Failed() {
694 return
695 }
696
Colin Crossb98c8b02016-07-29 13:44:28 -0700697 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
698 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
699 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800700
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800701 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
702 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700703 // We need access to all the flags seen by a source file.
704 if c.sabi != nil {
705 flags = c.sabi.flags(ctx, flags)
706 }
Colin Crossca860ac2016-01-04 14:34:37 -0800707 // Optimization to reduce size of build.ninja
708 // Replace the long list of flags for each file with a module-local variable
709 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
710 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
711 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
712 flags.CFlags = []string{"$cflags"}
713 flags.CppFlags = []string{"$cppflags"}
714 flags.AsFlags = []string{"$asflags"}
715
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700716 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800717 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700718 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800719 if ctx.Failed() {
720 return
721 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800722 }
723
Colin Crossca860ac2016-01-04 14:34:37 -0800724 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700725 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800726 if ctx.Failed() {
727 return
728 }
Colin Cross635c3b02016-05-18 15:37:25 -0700729 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700730 }
Colin Cross5049f022015-03-18 13:28:46 -0700731
Colin Crossce75d2c2016-10-06 16:12:58 -0700732 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
733 c.installer.install(ctx, c.outputFile.Path())
734 if ctx.Failed() {
735 return
Colin Crossca860ac2016-01-04 14:34:37 -0800736 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700737 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800738}
739
Colin Crossb98c8b02016-07-29 13:44:28 -0700740func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800741 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700742 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800743 }
Colin Crossca860ac2016-01-04 14:34:37 -0800744 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800745}
746
Colin Crossca860ac2016-01-04 14:34:37 -0800747func (c *Module) begin(ctx BaseModuleContext) {
748 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700749 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700750 }
Colin Crossca860ac2016-01-04 14:34:37 -0800751 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700752 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800753 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700754 if c.stl != nil {
755 c.stl.begin(ctx)
756 }
Colin Cross16b23492016-01-06 14:41:07 -0800757 if c.sanitize != nil {
758 c.sanitize.begin(ctx)
759 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800760 if c.coverage != nil {
761 c.coverage.begin(ctx)
762 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800763 if c.sabi != nil {
764 c.sabi.begin(ctx)
765 }
Justin Yun8effde42017-06-23 19:24:43 +0900766 if c.vndkdep != nil {
767 c.vndkdep.begin(ctx)
768 }
Stephen Craneba090d12017-05-09 15:44:35 -0700769 if c.lto != nil {
770 c.lto.begin(ctx)
771 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700772 if c.pgo != nil {
773 c.pgo.begin(ctx)
774 }
Colin Crossca860ac2016-01-04 14:34:37 -0800775 for _, feature := range c.features {
776 feature.begin(ctx)
777 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700778 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700779 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700780 if err != nil {
781 ctx.PropertyErrorf("sdk_version", err.Error())
782 }
Nan Zhang0007d812017-11-07 10:57:05 -0800783 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700784 }
Colin Crossca860ac2016-01-04 14:34:37 -0800785}
786
Colin Cross37047f12016-12-13 17:06:13 -0800787func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700788 deps := Deps{}
789
790 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700791 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700792 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700793 // Add the PGO dependency (the clang_rt.profile runtime library), which
794 // sometimes depends on symbols from libgcc, before libgcc gets added
795 // in linkerDeps().
796 if c.pgo != nil {
797 deps = c.pgo.deps(ctx, deps)
798 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700799 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700800 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700801 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700802 if c.stl != nil {
803 deps = c.stl.deps(ctx, deps)
804 }
Colin Cross16b23492016-01-06 14:41:07 -0800805 if c.sanitize != nil {
806 deps = c.sanitize.deps(ctx, deps)
807 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800808 if c.coverage != nil {
809 deps = c.coverage.deps(ctx, deps)
810 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800811 if c.sabi != nil {
812 deps = c.sabi.deps(ctx, deps)
813 }
Justin Yun8effde42017-06-23 19:24:43 +0900814 if c.vndkdep != nil {
815 deps = c.vndkdep.deps(ctx, deps)
816 }
Stephen Craneba090d12017-05-09 15:44:35 -0700817 if c.lto != nil {
818 deps = c.lto.deps(ctx, deps)
819 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700820 for _, feature := range c.features {
821 deps = feature.deps(ctx, deps)
822 }
823
Colin Crossb6715442017-10-24 11:13:31 -0700824 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
825 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
826 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
827 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
828 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
829 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700830
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700831 for _, lib := range deps.ReexportSharedLibHeaders {
832 if !inList(lib, deps.SharedLibs) {
833 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
834 }
835 }
836
837 for _, lib := range deps.ReexportStaticLibHeaders {
838 if !inList(lib, deps.StaticLibs) {
839 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
840 }
841 }
842
Colin Cross5950f382016-12-13 12:50:57 -0800843 for _, lib := range deps.ReexportHeaderLibHeaders {
844 if !inList(lib, deps.HeaderLibs) {
845 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
846 }
847 }
848
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700849 for _, gen := range deps.ReexportGeneratedHeaders {
850 if !inList(gen, deps.GeneratedHeaders) {
851 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
852 }
853 }
854
Colin Crossc99deeb2016-04-11 15:06:20 -0700855 return deps
856}
857
Dan Albert7e9d2952016-08-04 13:02:36 -0700858func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800859 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700860 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800861 moduleContextImpl: moduleContextImpl{
862 mod: c,
863 },
864 }
865 ctx.ctx = ctx
866
Colin Crossca860ac2016-01-04 14:34:37 -0800867 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700868}
869
Colin Cross1e676be2016-10-12 14:38:15 -0700870func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
871 if !c.Enabled() {
872 return
873 }
874
Colin Cross37047f12016-12-13 17:06:13 -0800875 ctx := &depsContext{
876 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700877 moduleContextImpl: moduleContextImpl{
878 mod: c,
879 },
880 }
881 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800882
Colin Crossc99deeb2016-04-11 15:06:20 -0700883 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800884
Dan Albert914449f2016-06-17 16:45:24 -0700885 variantNdkLibs := []string{}
886 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700887 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700888 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700889
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700890 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
891 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700892 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700893 // 1. Name of an NDK library that refers to a prebuilt module.
894 // For each of these, it adds the name of the prebuilt module (which will be in
895 // prebuilts/ndk) to the list of nonvariant libs.
896 // 2. Name of an NDK library that refers to an ndk_library module.
897 // For each of these, it adds the name of the ndk_library module to the list of
898 // variant libs.
899 // 3. Anything else (so anything that isn't an NDK library).
900 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700901 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700902 // The caller can then know to add the variantLibs dependencies differently from the
903 // nonvariantLibs
904 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
905 variantLibs = []string{}
906 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700907 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700908 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700909 if !inList(entry, ndkMigratedLibs) {
910 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
911 } else {
912 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
913 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700914 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700915 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700916 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700917 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700918 }
919 }
Dan Albert914449f2016-06-17 16:45:24 -0700920 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700921 }
922
Dan Albert914449f2016-06-17 16:45:24 -0700923 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
924 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900925 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700926 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700927
Colin Cross32ec36c2016-12-15 07:39:51 -0800928 for _, lib := range deps.HeaderLibs {
929 depTag := headerDepTag
930 if inList(lib, deps.ReexportHeaderLibHeaders) {
931 depTag = headerExportDepTag
932 }
933 actx.AddVariationDependencies(nil, depTag, lib)
934 }
Colin Cross5950f382016-12-13 12:50:57 -0800935
Colin Crossc99deeb2016-04-11 15:06:20 -0700936 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
937 deps.WholeStaticLibs...)
938
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700939 for _, lib := range deps.StaticLibs {
940 depTag := staticDepTag
941 if inList(lib, deps.ReexportStaticLibHeaders) {
942 depTag = staticExportDepTag
943 }
Colin Cross15a0d462016-07-14 14:49:58 -0700944 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700945 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700946
947 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
948 deps.LateStaticLibs...)
949
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700950 for _, lib := range deps.SharedLibs {
951 depTag := sharedDepTag
952 if inList(lib, deps.ReexportSharedLibHeaders) {
953 depTag = sharedExportDepTag
954 }
Colin Cross15a0d462016-07-14 14:49:58 -0700955 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700956 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700957
958 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
959 deps.LateSharedLibs...)
960
Colin Cross68861832016-07-08 10:41:41 -0700961 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700962
963 for _, gen := range deps.GeneratedHeaders {
964 depTag := genHeaderDepTag
965 if inList(gen, deps.ReexportGeneratedHeaders) {
966 depTag = genHeaderExportDepTag
967 }
968 actx.AddDependency(c, depTag, gen)
969 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700970
Colin Cross68861832016-07-08 10:41:41 -0700971 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700972
973 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700974 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800975 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700976 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700977 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700978 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700979 if deps.LinkerScript != "" {
980 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
981 }
Dan Albert914449f2016-06-17 16:45:24 -0700982
983 version := ctx.sdkVersion()
984 actx.AddVariationDependencies([]blueprint.Variation{
985 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
986 actx.AddVariationDependencies([]blueprint.Variation{
987 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +0800988
989 if vndkdep := c.vndkdep; vndkdep != nil {
990 if vndkdep.isVndkExt() {
991 baseModuleMode := vendorMode
992 if actx.DeviceConfig().VndkVersion() == "" {
993 baseModuleMode = coreMode
994 }
995 actx.AddVariationDependencies([]blueprint.Variation{
996 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
997 vndkdep.getVndkExtendsModuleName())
998 }
999 }
Colin Cross6362e272015-10-29 15:25:03 -07001000}
Colin Cross21b9a242015-03-24 14:15:58 -07001001
Dan Albert7e9d2952016-08-04 13:02:36 -07001002func beginMutator(ctx android.BottomUpMutatorContext) {
1003 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1004 c.beginMutator(ctx)
1005 }
1006}
1007
Colin Crossca860ac2016-01-04 14:34:37 -08001008func (c *Module) clang(ctx BaseModuleContext) bool {
1009 clang := Bool(c.Properties.Clang)
1010
1011 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001012 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001013 }
Colin Cross28344522015-04-22 13:07:53 -07001014
Colin Crossca860ac2016-01-04 14:34:37 -08001015 if !c.toolchain(ctx).ClangSupported() {
1016 clang = false
1017 }
1018
1019 return clang
1020}
1021
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001022// Whether a module can link to another module, taking into
1023// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001024func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001025 if from.Target().Os != android.Android {
1026 // Host code is not restricted
1027 return
1028 }
1029 if from.Properties.UseVndk {
1030 // Though vendor code is limited by the vendor mutator,
1031 // each vendor-available module needs to check
1032 // link-type for VNDK.
1033 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001034 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001035 }
1036 return
1037 }
Nan Zhang0007d812017-11-07 10:57:05 -08001038 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001039 // Platform code can link to anything
1040 return
1041 }
1042 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1043 // These are always allowed
1044 return
1045 }
1046 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
1047 // These are allowed, but they don't set sdk_version
1048 return
1049 }
1050 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1051 // These are allowed, but they don't set sdk_version
1052 return
1053 }
1054 if _, ok := to.linker.(*stubDecorator); ok {
1055 // These aren't real libraries, but are the stub shared libraries that are included in
1056 // the NDK.
1057 return
1058 }
Nan Zhang0007d812017-11-07 10:57:05 -08001059 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001060 // NDK code linking to platform code is never okay.
1061 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1062 ctx.OtherModuleName(to))
1063 }
1064
1065 // At this point we know we have two NDK libraries, but we need to
1066 // check that we're not linking against anything built against a higher
1067 // API level, as it is only valid to link against older or equivalent
1068 // APIs.
1069
Nan Zhang0007d812017-11-07 10:57:05 -08001070 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001071 // Current can link against anything.
1072 return
Nan Zhang0007d812017-11-07 10:57:05 -08001073 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001074 // Current can't be linked against by anything else.
1075 ctx.ModuleErrorf("links %q built against newer API version %q",
1076 ctx.OtherModuleName(to), "current")
1077 }
1078
Nan Zhang0007d812017-11-07 10:57:05 -08001079 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001080 if err != nil {
1081 ctx.PropertyErrorf("sdk_version",
1082 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001083 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001084 }
Nan Zhang0007d812017-11-07 10:57:05 -08001085 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001086 if err != nil {
1087 ctx.PropertyErrorf("sdk_version",
1088 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001089 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001090 }
1091
1092 if toApi > fromApi {
1093 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001094 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001095 }
Dan Albert202fe492017-12-15 13:56:59 -08001096
1097 // Also check that the two STL choices are compatible.
1098 fromStl := from.stl.Properties.SelectedStl
1099 toStl := to.stl.Properties.SelectedStl
1100 if fromStl == "" || toStl == "" {
1101 // Libraries that don't use the STL are unrestricted.
1102 return
1103 }
1104
1105 if fromStl == "ndk_system" || toStl == "ndk_system" {
1106 // We can be permissive with the system "STL" since it is only the C++
1107 // ABI layer, but in the future we should make sure that everyone is
1108 // using either libc++ or nothing.
1109 return
1110 }
1111
1112 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1113 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1114 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1115 to.stl.Properties.SelectedStl)
1116 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001117}
1118
Colin Crossc99deeb2016-04-11 15:06:20 -07001119// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001120func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001121 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001122
Jeff Gaston294356f2017-09-27 17:05:30 -07001123 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001124 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001125
Colin Crossd11fcda2017-10-23 17:59:01 -07001126 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001127 depName := ctx.OtherModuleName(dep)
1128 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001129
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001130 ccDep, _ := dep.(*Module)
1131 if ccDep == nil {
1132 // handling for a few module types that aren't cc Module but that are also supported
1133 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001134 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001135 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001136 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001137 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001138 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1139 genRule.GeneratedSourceFiles()...)
1140 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001141 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001142 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001143 // Support exported headers from a generated_sources dependency
1144 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001145 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001146 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001147 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001148 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001149 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001150 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001151 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001152 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001153 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001154 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001155 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1156 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1157
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001158 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001159 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001160 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001161 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001162 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001163 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001164 files := genRule.GeneratedSourceFiles()
1165 if len(files) == 1 {
1166 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1167 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001168 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001169 }
1170 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001171 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001172 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001173 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001174 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001175 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001176 return
1177 }
1178
Colin Crossd11fcda2017-10-23 17:59:01 -07001179 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001180 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1181 return
1182 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001183 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001184 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001185 return
1186 }
1187
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001188 // re-exporting flags
1189 if depTag == reuseObjTag {
1190 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001191 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001192 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001193 depPaths.Objs = depPaths.Objs.Append(objs)
1194 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001195 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001196 return
1197 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001198 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001199 if t, ok := depTag.(dependencyTag); ok && t.library {
1200 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001201 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001202 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001203 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001204 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001205
1206 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001207 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001208 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001209 // 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 -07001210 // Re-exported shared library headers must be included as well since they can help us with type information
1211 // about template instantiations (instantiated from their headers).
1212 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001213 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001214 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001215
Logan Chienf3511742017-10-31 18:04:35 +08001216 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001217 }
1218
Colin Cross26c34ed2016-09-30 17:10:16 -07001219 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001220 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001221
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001222 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001223 depFile := android.OptionalPath{}
1224
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001225 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001226 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001227 ptr = &depPaths.SharedLibs
1228 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001229 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001230 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001231 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001232 ptr = &depPaths.LateSharedLibs
1233 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001234 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001235 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001236 ptr = nil
1237 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001238 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001239 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001240 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001241 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001242 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001243 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001244 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001245 return
1246 }
1247
1248 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001249 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001250 for i := range missingDeps {
1251 missingDeps[i] += postfix
1252 }
1253 ctx.AddMissingDependencies(missingDeps)
1254 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001255 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001256 case headerDepTag:
1257 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001258 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001259 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001260 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001261 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001262 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001263 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001264 }
1265
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001266 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001267 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001268 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001269 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001270 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001271 return
1272 }
1273
1274 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001275 // in static libraries act as if they were whole static libraries. The same goes for
1276 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001277 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1278 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001279 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1280 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001281
Dan Willemsen581341d2017-02-09 16:16:31 -08001282 }
1283
Colin Cross26c34ed2016-09-30 17:10:16 -07001284 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001285 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001286 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001287 return
1288 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001289 *ptr = append(*ptr, linkFile.Path())
1290 }
1291
Colin Crossc99deeb2016-04-11 15:06:20 -07001292 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001293 dep := depFile
1294 if !dep.Valid() {
1295 dep = linkFile
1296 }
1297 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001298 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001299
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001300 // Export the shared libs to Make.
1301 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001302 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001303 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001304 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001305 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001306 var makeLibName string
1307 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1308 if c.useVndk() && bothVendorAndCoreVariantsExist {
1309 // The vendor module in Make will have been renamed to not conflict with the core
1310 // module, so update the dependency name here accordingly.
1311 makeLibName = libName + vendorSuffix
1312 } else {
1313 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001314 }
1315 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001316 // they merely serve as Make dependencies and do not affect this lib itself.
1317 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001318 }
Colin Crossca860ac2016-01-04 14:34:37 -08001319 })
1320
Jeff Gaston294356f2017-09-27 17:05:30 -07001321 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001322 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001323
Colin Crossdd84e052017-05-17 13:44:16 -07001324 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001325 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001326 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001327 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001328 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1329
1330 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001331 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001332 }
Colin Crossdd84e052017-05-17 13:44:16 -07001333
Colin Crossca860ac2016-01-04 14:34:37 -08001334 return depPaths
1335}
1336
1337func (c *Module) InstallInData() bool {
1338 if c.installer == nil {
1339 return false
1340 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001341 return c.installer.inData()
1342}
1343
1344func (c *Module) InstallInSanitizerDir() bool {
1345 if c.installer == nil {
1346 return false
1347 }
1348 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001349 return true
1350 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001351 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001352}
1353
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001354func (c *Module) HostToolPath() android.OptionalPath {
1355 if c.installer == nil {
1356 return android.OptionalPath{}
1357 }
1358 return c.installer.hostToolPath()
1359}
1360
Nan Zhangd4e641b2017-07-12 12:55:28 -07001361func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1362 return c.outputFile
1363}
1364
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001365func (c *Module) Srcs() android.Paths {
1366 if c.outputFile.Valid() {
1367 return android.Paths{c.outputFile.Path()}
1368 }
1369 return android.Paths{}
1370}
1371
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001372func (c *Module) static() bool {
1373 if static, ok := c.linker.(interface {
1374 static() bool
1375 }); ok {
1376 return static.static()
1377 }
1378 return false
1379}
1380
Colin Cross2ba19d92015-05-07 15:44:20 -07001381//
Colin Crosscfad1192015-11-02 16:43:11 -08001382// Defaults
1383//
Colin Crossca860ac2016-01-04 14:34:37 -08001384type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001385 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001386 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001387}
1388
Colin Cross635c3b02016-05-18 15:37:25 -07001389func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001390}
1391
Colin Cross1e676be2016-10-12 14:38:15 -07001392func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1393}
1394
Colin Cross36242852017-06-23 15:06:31 -07001395func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001396 return DefaultsFactory()
1397}
1398
Colin Cross36242852017-06-23 15:06:31 -07001399func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001400 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001401
Colin Cross36242852017-06-23 15:06:31 -07001402 module.AddProperties(props...)
1403 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001404 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001405 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001406 &BaseCompilerProperties{},
1407 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001408 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001409 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001410 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001411 &TestProperties{},
1412 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001413 &UnusedProperties{},
1414 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001415 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001416 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001417 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001418 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001419 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001420 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001421 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001422 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001423 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001424 )
Colin Crosscfad1192015-11-02 16:43:11 -08001425
Colin Cross1f44a3a2017-07-07 14:33:33 -07001426 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001427
1428 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001429}
1430
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001431const (
1432 // coreMode is the variant used for framework-private libraries, or
1433 // SDK libraries. (which framework-private libraries can use)
1434 coreMode = "core"
1435
1436 // vendorMode is the variant used for /vendor code that compiles
1437 // against the VNDK.
1438 vendorMode = "vendor"
1439)
1440
Jiyong Park6a43f042017-10-12 23:05:00 +09001441func squashVendorSrcs(m *Module) {
1442 if lib, ok := m.compiler.(*libraryDecorator); ok {
1443 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1444 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1445
1446 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1447 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1448 }
1449}
1450
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001451func vendorMutator(mctx android.BottomUpMutatorContext) {
1452 if mctx.Os() != android.Android {
1453 return
1454 }
1455
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001456 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1457 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001458 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001459 mctx.CreateVariations(coreMode)
1460 } else if Bool(props.Vendor_available) {
1461 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001462 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001463 mctx.CreateVariations(vendorMode)
1464 } else {
1465 mctx.CreateVariations(coreMode)
1466 }
1467 }
1468 }
1469
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001470 m, ok := mctx.Module().(*Module)
1471 if !ok {
1472 return
1473 }
1474
1475 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001476 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1477
1478 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001479 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001480 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001481 return
1482 }
Logan Chienf3511742017-10-31 18:04:35 +08001483
1484 if vndkdep := m.vndkdep; vndkdep != nil {
1485 if vndkdep.isVndk() {
1486 if vendorSpecific {
1487 if !vndkdep.isVndkExt() {
1488 mctx.PropertyErrorf("vndk",
1489 "must set `extends: \"...\"` to vndk extension")
1490 return
1491 }
1492 } else {
1493 if vndkdep.isVndkExt() {
1494 mctx.PropertyErrorf("vndk",
1495 "must set `vendor: true` to set `extends: %q`",
1496 m.getVndkExtendsModuleName())
1497 return
1498 }
1499 if m.VendorProperties.Vendor_available == nil {
1500 mctx.PropertyErrorf("vndk",
1501 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1502 return
1503 }
1504 }
1505 } else {
1506 if vndkdep.isVndkSp() {
1507 mctx.PropertyErrorf("vndk",
1508 "must set `enabled: true` to set `support_system_process: true`")
1509 return
1510 }
1511 if vndkdep.isVndkExt() {
1512 mctx.PropertyErrorf("vndk",
1513 "must set `enabled: true` to set `extends: %q`",
1514 m.getVndkExtendsModuleName())
1515 return
1516 }
Justin Yun8effde42017-06-23 19:24:43 +09001517 }
1518 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001519
Justin Yun71549282017-11-17 12:10:28 +09001520 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001521 // If the device isn't compiling against the VNDK, we always
1522 // use the core mode.
1523 mctx.CreateVariations(coreMode)
1524 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1525 // LL-NDK stubs only exist in the vendor variant, since the
1526 // real libraries will be used in the core variant.
1527 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001528 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1529 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001530 mod := mctx.CreateVariations(vendorMode)
1531 vendor := mod[0].(*Module)
1532 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001533 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001534 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1535 // PRODUCT_EXTRA_VNDK_VERSIONS.
1536 mod := mctx.CreateVariations(vendorMode)
1537 vendor := mod[0].(*Module)
1538 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001539 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001540 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001541 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001542 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001543 vendor := mod[1].(*Module)
1544 vendor.Properties.UseVndk = true
1545 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001546 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001547 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001548 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001549 vendor := mod[0].(*Module)
1550 vendor.Properties.UseVndk = true
1551 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001552 } else {
1553 // This is either in /system (or similar: /data), or is a
1554 // modules built with the NDK. Modules built with the NDK
1555 // will be restricted using the existing link type checks.
1556 mctx.CreateVariations(coreMode)
1557 }
1558}
1559
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001560func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001561 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001562 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1563 }
Colin Cross6510f912017-11-29 00:27:14 -08001564 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001565}
1566
Colin Cross06a931b2015-10-28 17:23:31 -07001567var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001568var BoolPtr = proptools.BoolPtr
1569var String = proptools.String
1570var StringPtr = proptools.StringPtr