blob: 887f3943581fb5ff4605904f768c0392e70b317b [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 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700533 return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800534}
535
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700536func (ctx *moduleContextImpl) selectedStl() string {
537 if stl := ctx.mod.stl; stl != nil {
538 return stl.Properties.SelectedStl
539 }
540 return ""
541}
542
Colin Crossce75d2c2016-10-06 16:12:58 -0700543func (ctx *moduleContextImpl) baseModuleName() string {
544 return ctx.mod.ModuleBase.BaseModuleName()
545}
546
Logan Chienf3511742017-10-31 18:04:35 +0800547func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
548 return ctx.mod.getVndkExtendsModuleName()
549}
550
Colin Cross635c3b02016-05-18 15:37:25 -0700551func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800552 return &Module{
553 hod: hod,
554 multilib: multilib,
555 }
556}
557
Colin Cross635c3b02016-05-18 15:37:25 -0700558func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800559 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700560 module.features = []feature{
561 &tidyFeature{},
562 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700563 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800564 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800565 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800566 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900567 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700568 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700569 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800570 return module
571}
572
Colin Crossce75d2c2016-10-06 16:12:58 -0700573func (c *Module) Prebuilt() *android.Prebuilt {
574 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
575 return p.prebuilt()
576 }
577 return nil
578}
579
580func (c *Module) Name() string {
581 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700582 if p, ok := c.linker.(interface {
583 Name(string) string
584 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700585 name = p.Name(name)
586 }
587 return name
588}
589
Jeff Gaston294356f2017-09-27 17:05:30 -0700590// orderDeps reorders dependencies into a list such that if module A depends on B, then
591// A will precede B in the resultant list.
592// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800593// Note that directSharedDeps should be the analogous static library for each shared lib dep
594func 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 -0700595 // If A depends on B, then
596 // Every list containing A will also contain B later in the list
597 // So, after concatenating all lists, the final instance of B will have come from the same
598 // original list as the final instance of A
599 // So, the final instance of B will be later in the concatenation than the final A
600 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
601 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800602 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700603 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800604 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
605 }
606 for _, dep := range directSharedDeps {
607 orderedAllDeps = append(orderedAllDeps, dep)
608 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700609 }
610
Colin Crossb6715442017-10-24 11:13:31 -0700611 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700612
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800613 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700614 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800615 // resultant list to only what the caller has chosen to include in directStaticDeps
616 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700617
618 return orderedAllDeps, orderedDeclaredDeps
619}
620
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800621func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
622 // convert Module to Path
623 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
624 staticDepFiles := []android.Path{}
625 for _, dep := range staticDeps {
626 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
627 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700628 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800629 sharedDepFiles := []android.Path{}
630 for _, sharedDep := range sharedDeps {
631 staticAnalogue := sharedDep.staticVariant
632 if staticAnalogue != nil {
633 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
634 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
635 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700636 }
637
638 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800639 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700640
641 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700642}
643
Colin Cross635c3b02016-05-18 15:37:25 -0700644func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700645
Colin Crossca860ac2016-01-04 14:34:37 -0800646 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700647 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800648 moduleContextImpl: moduleContextImpl{
649 mod: c,
650 },
651 }
652 ctx.ctx = ctx
653
Colin Crossf18e1102017-11-16 14:33:08 -0800654 deps := c.depsToPaths(ctx)
655 if ctx.Failed() {
656 return
657 }
658
Colin Crossca860ac2016-01-04 14:34:37 -0800659 flags := Flags{
660 Toolchain: c.toolchain(ctx),
661 Clang: c.clang(ctx),
662 }
Colin Crossca860ac2016-01-04 14:34:37 -0800663 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800664 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800665 }
666 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700667 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800668 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700669 if c.stl != nil {
670 flags = c.stl.flags(ctx, flags)
671 }
Colin Cross16b23492016-01-06 14:41:07 -0800672 if c.sanitize != nil {
673 flags = c.sanitize.flags(ctx, flags)
674 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800675 if c.coverage != nil {
676 flags = c.coverage.flags(ctx, flags)
677 }
Stephen Craneba090d12017-05-09 15:44:35 -0700678 if c.lto != nil {
679 flags = c.lto.flags(ctx, flags)
680 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700681 if c.pgo != nil {
682 flags = c.pgo.flags(ctx, flags)
683 }
Colin Crossca860ac2016-01-04 14:34:37 -0800684 for _, feature := range c.features {
685 flags = feature.flags(ctx, flags)
686 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800687 if ctx.Failed() {
688 return
689 }
690
Colin Crossb98c8b02016-07-29 13:44:28 -0700691 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
692 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
693 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800694
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800695 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
696 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700697 // We need access to all the flags seen by a source file.
698 if c.sabi != nil {
699 flags = c.sabi.flags(ctx, flags)
700 }
Colin Crossca860ac2016-01-04 14:34:37 -0800701 // Optimization to reduce size of build.ninja
702 // Replace the long list of flags for each file with a module-local variable
703 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
704 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
705 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
706 flags.CFlags = []string{"$cflags"}
707 flags.CppFlags = []string{"$cppflags"}
708 flags.AsFlags = []string{"$asflags"}
709
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700710 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800711 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700712 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800713 if ctx.Failed() {
714 return
715 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800716 }
717
Colin Crossca860ac2016-01-04 14:34:37 -0800718 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700719 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800720 if ctx.Failed() {
721 return
722 }
Colin Cross635c3b02016-05-18 15:37:25 -0700723 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700724 }
Colin Cross5049f022015-03-18 13:28:46 -0700725
Colin Crossce75d2c2016-10-06 16:12:58 -0700726 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
727 c.installer.install(ctx, c.outputFile.Path())
728 if ctx.Failed() {
729 return
Colin Crossca860ac2016-01-04 14:34:37 -0800730 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700731 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800732}
733
Colin Crossb98c8b02016-07-29 13:44:28 -0700734func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800735 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700736 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800737 }
Colin Crossca860ac2016-01-04 14:34:37 -0800738 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800739}
740
Colin Crossca860ac2016-01-04 14:34:37 -0800741func (c *Module) begin(ctx BaseModuleContext) {
742 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700743 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700744 }
Colin Crossca860ac2016-01-04 14:34:37 -0800745 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700746 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800747 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700748 if c.stl != nil {
749 c.stl.begin(ctx)
750 }
Colin Cross16b23492016-01-06 14:41:07 -0800751 if c.sanitize != nil {
752 c.sanitize.begin(ctx)
753 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800754 if c.coverage != nil {
755 c.coverage.begin(ctx)
756 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800757 if c.sabi != nil {
758 c.sabi.begin(ctx)
759 }
Justin Yun8effde42017-06-23 19:24:43 +0900760 if c.vndkdep != nil {
761 c.vndkdep.begin(ctx)
762 }
Stephen Craneba090d12017-05-09 15:44:35 -0700763 if c.lto != nil {
764 c.lto.begin(ctx)
765 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700766 if c.pgo != nil {
767 c.pgo.begin(ctx)
768 }
Colin Crossca860ac2016-01-04 14:34:37 -0800769 for _, feature := range c.features {
770 feature.begin(ctx)
771 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700772 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700773 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700774 if err != nil {
775 ctx.PropertyErrorf("sdk_version", err.Error())
776 }
Nan Zhang0007d812017-11-07 10:57:05 -0800777 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700778 }
Colin Crossca860ac2016-01-04 14:34:37 -0800779}
780
Colin Cross37047f12016-12-13 17:06:13 -0800781func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700782 deps := Deps{}
783
784 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700785 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700786 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700787 // Add the PGO dependency (the clang_rt.profile runtime library), which
788 // sometimes depends on symbols from libgcc, before libgcc gets added
789 // in linkerDeps().
790 if c.pgo != nil {
791 deps = c.pgo.deps(ctx, deps)
792 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700793 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700794 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700795 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700796 if c.stl != nil {
797 deps = c.stl.deps(ctx, deps)
798 }
Colin Cross16b23492016-01-06 14:41:07 -0800799 if c.sanitize != nil {
800 deps = c.sanitize.deps(ctx, deps)
801 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800802 if c.coverage != nil {
803 deps = c.coverage.deps(ctx, deps)
804 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800805 if c.sabi != nil {
806 deps = c.sabi.deps(ctx, deps)
807 }
Justin Yun8effde42017-06-23 19:24:43 +0900808 if c.vndkdep != nil {
809 deps = c.vndkdep.deps(ctx, deps)
810 }
Stephen Craneba090d12017-05-09 15:44:35 -0700811 if c.lto != nil {
812 deps = c.lto.deps(ctx, deps)
813 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700814 for _, feature := range c.features {
815 deps = feature.deps(ctx, deps)
816 }
817
Colin Crossb6715442017-10-24 11:13:31 -0700818 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
819 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
820 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
821 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
822 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
823 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700824
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700825 for _, lib := range deps.ReexportSharedLibHeaders {
826 if !inList(lib, deps.SharedLibs) {
827 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
828 }
829 }
830
831 for _, lib := range deps.ReexportStaticLibHeaders {
832 if !inList(lib, deps.StaticLibs) {
833 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
834 }
835 }
836
Colin Cross5950f382016-12-13 12:50:57 -0800837 for _, lib := range deps.ReexportHeaderLibHeaders {
838 if !inList(lib, deps.HeaderLibs) {
839 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
840 }
841 }
842
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700843 for _, gen := range deps.ReexportGeneratedHeaders {
844 if !inList(gen, deps.GeneratedHeaders) {
845 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
846 }
847 }
848
Colin Crossc99deeb2016-04-11 15:06:20 -0700849 return deps
850}
851
Dan Albert7e9d2952016-08-04 13:02:36 -0700852func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800853 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700854 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800855 moduleContextImpl: moduleContextImpl{
856 mod: c,
857 },
858 }
859 ctx.ctx = ctx
860
Colin Crossca860ac2016-01-04 14:34:37 -0800861 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700862}
863
Colin Cross1e676be2016-10-12 14:38:15 -0700864func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
865 if !c.Enabled() {
866 return
867 }
868
Colin Cross37047f12016-12-13 17:06:13 -0800869 ctx := &depsContext{
870 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700871 moduleContextImpl: moduleContextImpl{
872 mod: c,
873 },
874 }
875 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800876
Colin Crossc99deeb2016-04-11 15:06:20 -0700877 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800878
Dan Albert914449f2016-06-17 16:45:24 -0700879 variantNdkLibs := []string{}
880 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700881 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700882 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700883
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700884 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
885 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700886 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700887 // 1. Name of an NDK library that refers to a prebuilt module.
888 // For each of these, it adds the name of the prebuilt module (which will be in
889 // prebuilts/ndk) to the list of nonvariant libs.
890 // 2. Name of an NDK library that refers to an ndk_library module.
891 // For each of these, it adds the name of the ndk_library module to the list of
892 // variant libs.
893 // 3. Anything else (so anything that isn't an NDK library).
894 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700895 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700896 // The caller can then know to add the variantLibs dependencies differently from the
897 // nonvariantLibs
898 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
899 variantLibs = []string{}
900 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700901 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700902 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700903 if !inList(entry, ndkMigratedLibs) {
904 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
905 } else {
906 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
907 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700908 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700909 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700910 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700911 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700912 }
913 }
Dan Albert914449f2016-06-17 16:45:24 -0700914 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700915 }
916
Dan Albert914449f2016-06-17 16:45:24 -0700917 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
918 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900919 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700920 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700921
Colin Cross32ec36c2016-12-15 07:39:51 -0800922 for _, lib := range deps.HeaderLibs {
923 depTag := headerDepTag
924 if inList(lib, deps.ReexportHeaderLibHeaders) {
925 depTag = headerExportDepTag
926 }
927 actx.AddVariationDependencies(nil, depTag, lib)
928 }
Colin Cross5950f382016-12-13 12:50:57 -0800929
Colin Crossc99deeb2016-04-11 15:06:20 -0700930 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
931 deps.WholeStaticLibs...)
932
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700933 for _, lib := range deps.StaticLibs {
934 depTag := staticDepTag
935 if inList(lib, deps.ReexportStaticLibHeaders) {
936 depTag = staticExportDepTag
937 }
Colin Cross15a0d462016-07-14 14:49:58 -0700938 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700939 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700940
941 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
942 deps.LateStaticLibs...)
943
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700944 for _, lib := range deps.SharedLibs {
945 depTag := sharedDepTag
946 if inList(lib, deps.ReexportSharedLibHeaders) {
947 depTag = sharedExportDepTag
948 }
Colin Cross15a0d462016-07-14 14:49:58 -0700949 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700950 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700951
952 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
953 deps.LateSharedLibs...)
954
Colin Cross68861832016-07-08 10:41:41 -0700955 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700956
957 for _, gen := range deps.GeneratedHeaders {
958 depTag := genHeaderDepTag
959 if inList(gen, deps.ReexportGeneratedHeaders) {
960 depTag = genHeaderExportDepTag
961 }
962 actx.AddDependency(c, depTag, gen)
963 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700964
Colin Cross68861832016-07-08 10:41:41 -0700965 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700966
967 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700968 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800969 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700970 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700971 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700972 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700973 if deps.LinkerScript != "" {
974 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
975 }
Dan Albert914449f2016-06-17 16:45:24 -0700976
977 version := ctx.sdkVersion()
978 actx.AddVariationDependencies([]blueprint.Variation{
979 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
980 actx.AddVariationDependencies([]blueprint.Variation{
981 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +0800982
983 if vndkdep := c.vndkdep; vndkdep != nil {
984 if vndkdep.isVndkExt() {
985 baseModuleMode := vendorMode
986 if actx.DeviceConfig().VndkVersion() == "" {
987 baseModuleMode = coreMode
988 }
989 actx.AddVariationDependencies([]blueprint.Variation{
990 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
991 vndkdep.getVndkExtendsModuleName())
992 }
993 }
Colin Cross6362e272015-10-29 15:25:03 -0700994}
Colin Cross21b9a242015-03-24 14:15:58 -0700995
Dan Albert7e9d2952016-08-04 13:02:36 -0700996func beginMutator(ctx android.BottomUpMutatorContext) {
997 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
998 c.beginMutator(ctx)
999 }
1000}
1001
Colin Crossca860ac2016-01-04 14:34:37 -08001002func (c *Module) clang(ctx BaseModuleContext) bool {
1003 clang := Bool(c.Properties.Clang)
1004
1005 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001006 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001007 }
Colin Cross28344522015-04-22 13:07:53 -07001008
Colin Crossca860ac2016-01-04 14:34:37 -08001009 if !c.toolchain(ctx).ClangSupported() {
1010 clang = false
1011 }
1012
1013 return clang
1014}
1015
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001016// Whether a module can link to another module, taking into
1017// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001018func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001019 if from.Target().Os != android.Android {
1020 // Host code is not restricted
1021 return
1022 }
1023 if from.Properties.UseVndk {
1024 // Though vendor code is limited by the vendor mutator,
1025 // each vendor-available module needs to check
1026 // link-type for VNDK.
1027 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001028 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001029 }
1030 return
1031 }
Nan Zhang0007d812017-11-07 10:57:05 -08001032 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001033 // Platform code can link to anything
1034 return
1035 }
1036 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1037 // These are always allowed
1038 return
1039 }
1040 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
1041 // These are allowed, but they don't set sdk_version
1042 return
1043 }
1044 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1045 // These are allowed, but they don't set sdk_version
1046 return
1047 }
1048 if _, ok := to.linker.(*stubDecorator); ok {
1049 // These aren't real libraries, but are the stub shared libraries that are included in
1050 // the NDK.
1051 return
1052 }
Nan Zhang0007d812017-11-07 10:57:05 -08001053 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001054 // NDK code linking to platform code is never okay.
1055 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1056 ctx.OtherModuleName(to))
1057 }
1058
1059 // At this point we know we have two NDK libraries, but we need to
1060 // check that we're not linking against anything built against a higher
1061 // API level, as it is only valid to link against older or equivalent
1062 // APIs.
1063
Nan Zhang0007d812017-11-07 10:57:05 -08001064 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001065 // Current can link against anything.
1066 return
Nan Zhang0007d812017-11-07 10:57:05 -08001067 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001068 // Current can't be linked against by anything else.
1069 ctx.ModuleErrorf("links %q built against newer API version %q",
1070 ctx.OtherModuleName(to), "current")
1071 }
1072
Nan Zhang0007d812017-11-07 10:57:05 -08001073 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001074 if err != nil {
1075 ctx.PropertyErrorf("sdk_version",
1076 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001077 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001078 }
Nan Zhang0007d812017-11-07 10:57:05 -08001079 toApi, err := strconv.Atoi(String(to.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(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001084 }
1085
1086 if toApi > fromApi {
1087 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001088 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089 }
Dan Albert202fe492017-12-15 13:56:59 -08001090
1091 // Also check that the two STL choices are compatible.
1092 fromStl := from.stl.Properties.SelectedStl
1093 toStl := to.stl.Properties.SelectedStl
1094 if fromStl == "" || toStl == "" {
1095 // Libraries that don't use the STL are unrestricted.
1096 return
1097 }
1098
1099 if fromStl == "ndk_system" || toStl == "ndk_system" {
1100 // We can be permissive with the system "STL" since it is only the C++
1101 // ABI layer, but in the future we should make sure that everyone is
1102 // using either libc++ or nothing.
1103 return
1104 }
1105
1106 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1107 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1108 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1109 to.stl.Properties.SelectedStl)
1110 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001111}
1112
Colin Crossc99deeb2016-04-11 15:06:20 -07001113// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001114func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001115 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001116
Jeff Gaston294356f2017-09-27 17:05:30 -07001117 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001118 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001119
Colin Crossd11fcda2017-10-23 17:59:01 -07001120 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001121 depName := ctx.OtherModuleName(dep)
1122 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001123
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001124 ccDep, _ := dep.(*Module)
1125 if ccDep == nil {
1126 // handling for a few module types that aren't cc Module but that are also supported
1127 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001128 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001129 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001130 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001131 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001132 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1133 genRule.GeneratedSourceFiles()...)
1134 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001135 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001136 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001137 // Support exported headers from a generated_sources dependency
1138 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001139 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001140 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001141 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001142 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001143 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001144 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001145 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001146 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001147 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001148 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001149 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1150 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1151
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001152 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001153 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001154 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001155 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001156 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001157 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001158 files := genRule.GeneratedSourceFiles()
1159 if len(files) == 1 {
1160 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1161 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001162 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001163 }
1164 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001165 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001166 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001167 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001168 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001169 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001170 return
1171 }
1172
Colin Crossd11fcda2017-10-23 17:59:01 -07001173 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001174 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1175 return
1176 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001177 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001179 return
1180 }
1181
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001182 // re-exporting flags
1183 if depTag == reuseObjTag {
1184 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001185 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001186 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001187 depPaths.Objs = depPaths.Objs.Append(objs)
1188 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001189 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001190 return
1191 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001192 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001193 if t, ok := depTag.(dependencyTag); ok && t.library {
1194 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001195 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001196 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001197 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001198 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001199
1200 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001201 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001202 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001203 // 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 -07001204 // Re-exported shared library headers must be included as well since they can help us with type information
1205 // about template instantiations (instantiated from their headers).
1206 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001207 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001208 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001209
Logan Chienf3511742017-10-31 18:04:35 +08001210 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001211 }
1212
Colin Cross26c34ed2016-09-30 17:10:16 -07001213 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001214 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001215
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001216 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001217 depFile := android.OptionalPath{}
1218
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001219 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001220 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001221 ptr = &depPaths.SharedLibs
1222 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001223 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001224 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001225 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001226 ptr = &depPaths.LateSharedLibs
1227 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001228 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001229 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001230 ptr = nil
1231 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001232 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001233 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001234 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001235 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001236 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001237 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001238 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001239 return
1240 }
1241
1242 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001243 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001244 for i := range missingDeps {
1245 missingDeps[i] += postfix
1246 }
1247 ctx.AddMissingDependencies(missingDeps)
1248 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001249 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001250 case headerDepTag:
1251 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001252 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001253 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001254 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001255 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001256 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001257 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001258 }
1259
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001260 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001261 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001262 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001263 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001264 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001265 return
1266 }
1267
1268 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001269 // in static libraries act as if they were whole static libraries. The same goes for
1270 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001271 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1272 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001273 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1274 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001275
Dan Willemsen581341d2017-02-09 16:16:31 -08001276 }
1277
Colin Cross26c34ed2016-09-30 17:10:16 -07001278 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001279 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001280 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001281 return
1282 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001283 *ptr = append(*ptr, linkFile.Path())
1284 }
1285
Colin Crossc99deeb2016-04-11 15:06:20 -07001286 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001287 dep := depFile
1288 if !dep.Valid() {
1289 dep = linkFile
1290 }
1291 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001292 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001293
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001294 // Export the shared libs to Make.
1295 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001296 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001297 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001298 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001299 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001300 var makeLibName string
1301 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1302 if c.useVndk() && bothVendorAndCoreVariantsExist {
1303 // The vendor module in Make will have been renamed to not conflict with the core
1304 // module, so update the dependency name here accordingly.
1305 makeLibName = libName + vendorSuffix
1306 } else {
1307 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001308 }
1309 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001310 // they merely serve as Make dependencies and do not affect this lib itself.
1311 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001312 }
Colin Crossca860ac2016-01-04 14:34:37 -08001313 })
1314
Jeff Gaston294356f2017-09-27 17:05:30 -07001315 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001316 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001317
Colin Crossdd84e052017-05-17 13:44:16 -07001318 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001319 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001320 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001321 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001322 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1323
1324 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001325 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001326 }
Colin Crossdd84e052017-05-17 13:44:16 -07001327
Colin Crossca860ac2016-01-04 14:34:37 -08001328 return depPaths
1329}
1330
1331func (c *Module) InstallInData() bool {
1332 if c.installer == nil {
1333 return false
1334 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001335 return c.installer.inData()
1336}
1337
1338func (c *Module) InstallInSanitizerDir() bool {
1339 if c.installer == nil {
1340 return false
1341 }
1342 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001343 return true
1344 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001345 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001346}
1347
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001348func (c *Module) HostToolPath() android.OptionalPath {
1349 if c.installer == nil {
1350 return android.OptionalPath{}
1351 }
1352 return c.installer.hostToolPath()
1353}
1354
Nan Zhangd4e641b2017-07-12 12:55:28 -07001355func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1356 return c.outputFile
1357}
1358
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001359func (c *Module) Srcs() android.Paths {
1360 if c.outputFile.Valid() {
1361 return android.Paths{c.outputFile.Path()}
1362 }
1363 return android.Paths{}
1364}
1365
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001366func (c *Module) static() bool {
1367 if static, ok := c.linker.(interface {
1368 static() bool
1369 }); ok {
1370 return static.static()
1371 }
1372 return false
1373}
1374
Colin Cross2ba19d92015-05-07 15:44:20 -07001375//
Colin Crosscfad1192015-11-02 16:43:11 -08001376// Defaults
1377//
Colin Crossca860ac2016-01-04 14:34:37 -08001378type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001379 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001380 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001381}
1382
Colin Cross635c3b02016-05-18 15:37:25 -07001383func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001384}
1385
Colin Cross1e676be2016-10-12 14:38:15 -07001386func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1387}
1388
Colin Cross36242852017-06-23 15:06:31 -07001389func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001390 return DefaultsFactory()
1391}
1392
Colin Cross36242852017-06-23 15:06:31 -07001393func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001394 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001395
Colin Cross36242852017-06-23 15:06:31 -07001396 module.AddProperties(props...)
1397 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001398 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001399 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001400 &BaseCompilerProperties{},
1401 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001402 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001403 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001404 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001405 &TestProperties{},
1406 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001407 &UnusedProperties{},
1408 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001409 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001410 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001411 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001412 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001413 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001414 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001415 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001416 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001417 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001418 )
Colin Crosscfad1192015-11-02 16:43:11 -08001419
Colin Cross1f44a3a2017-07-07 14:33:33 -07001420 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001421
1422 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001423}
1424
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001425const (
1426 // coreMode is the variant used for framework-private libraries, or
1427 // SDK libraries. (which framework-private libraries can use)
1428 coreMode = "core"
1429
1430 // vendorMode is the variant used for /vendor code that compiles
1431 // against the VNDK.
1432 vendorMode = "vendor"
1433)
1434
Jiyong Park6a43f042017-10-12 23:05:00 +09001435func squashVendorSrcs(m *Module) {
1436 if lib, ok := m.compiler.(*libraryDecorator); ok {
1437 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1438 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1439
1440 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1441 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1442 }
1443}
1444
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001445func vendorMutator(mctx android.BottomUpMutatorContext) {
1446 if mctx.Os() != android.Android {
1447 return
1448 }
1449
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001450 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1451 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001452 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001453 mctx.CreateVariations(coreMode)
1454 } else if Bool(props.Vendor_available) {
1455 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001456 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001457 mctx.CreateVariations(vendorMode)
1458 } else {
1459 mctx.CreateVariations(coreMode)
1460 }
1461 }
1462 }
1463
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001464 m, ok := mctx.Module().(*Module)
1465 if !ok {
1466 return
1467 }
1468
1469 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001470 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1471
1472 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001473 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001474 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001475 return
1476 }
Logan Chienf3511742017-10-31 18:04:35 +08001477
1478 if vndkdep := m.vndkdep; vndkdep != nil {
1479 if vndkdep.isVndk() {
1480 if vendorSpecific {
1481 if !vndkdep.isVndkExt() {
1482 mctx.PropertyErrorf("vndk",
1483 "must set `extends: \"...\"` to vndk extension")
1484 return
1485 }
1486 } else {
1487 if vndkdep.isVndkExt() {
1488 mctx.PropertyErrorf("vndk",
1489 "must set `vendor: true` to set `extends: %q`",
1490 m.getVndkExtendsModuleName())
1491 return
1492 }
1493 if m.VendorProperties.Vendor_available == nil {
1494 mctx.PropertyErrorf("vndk",
1495 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1496 return
1497 }
1498 }
1499 } else {
1500 if vndkdep.isVndkSp() {
1501 mctx.PropertyErrorf("vndk",
1502 "must set `enabled: true` to set `support_system_process: true`")
1503 return
1504 }
1505 if vndkdep.isVndkExt() {
1506 mctx.PropertyErrorf("vndk",
1507 "must set `enabled: true` to set `extends: %q`",
1508 m.getVndkExtendsModuleName())
1509 return
1510 }
Justin Yun8effde42017-06-23 19:24:43 +09001511 }
1512 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001513
Justin Yun71549282017-11-17 12:10:28 +09001514 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001515 // If the device isn't compiling against the VNDK, we always
1516 // use the core mode.
1517 mctx.CreateVariations(coreMode)
1518 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1519 // LL-NDK stubs only exist in the vendor variant, since the
1520 // real libraries will be used in the core variant.
1521 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001522 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1523 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001524 mod := mctx.CreateVariations(vendorMode)
1525 vendor := mod[0].(*Module)
1526 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001527 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001528 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1529 // PRODUCT_EXTRA_VNDK_VERSIONS.
1530 mod := mctx.CreateVariations(vendorMode)
1531 vendor := mod[0].(*Module)
1532 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001533 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001534 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001535 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001536 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001537 vendor := mod[1].(*Module)
1538 vendor.Properties.UseVndk = true
1539 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001540 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001541 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001542 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001543 vendor := mod[0].(*Module)
1544 vendor.Properties.UseVndk = true
1545 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001546 } else {
1547 // This is either in /system (or similar: /data), or is a
1548 // modules built with the NDK. Modules built with the NDK
1549 // will be restricted using the existing link type checks.
1550 mctx.CreateVariations(coreMode)
1551 }
1552}
1553
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001554func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001555 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001556 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1557 }
Colin Cross6510f912017-11-29 00:27:14 -08001558 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001559}
1560
Colin Cross06a931b2015-10-28 17:23:31 -07001561var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001562var BoolPtr = proptools.BoolPtr
1563var String = proptools.String
1564var StringPtr = proptools.StringPtr