blob: a58a84dedc2e207f9828a7b3ba67ae194ce592f2 [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 }
538 return isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800539}
540
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700541func (ctx *moduleContextImpl) selectedStl() string {
542 if stl := ctx.mod.stl; stl != nil {
543 return stl.Properties.SelectedStl
544 }
545 return ""
546}
547
Colin Crossce75d2c2016-10-06 16:12:58 -0700548func (ctx *moduleContextImpl) baseModuleName() string {
549 return ctx.mod.ModuleBase.BaseModuleName()
550}
551
Logan Chienf3511742017-10-31 18:04:35 +0800552func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
553 return ctx.mod.getVndkExtendsModuleName()
554}
555
Colin Cross635c3b02016-05-18 15:37:25 -0700556func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800557 return &Module{
558 hod: hod,
559 multilib: multilib,
560 }
561}
562
Colin Cross635c3b02016-05-18 15:37:25 -0700563func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800564 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700565 module.features = []feature{
566 &tidyFeature{},
567 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700568 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800569 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800570 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800571 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900572 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700573 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700574 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800575 return module
576}
577
Colin Crossce75d2c2016-10-06 16:12:58 -0700578func (c *Module) Prebuilt() *android.Prebuilt {
579 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
580 return p.prebuilt()
581 }
582 return nil
583}
584
585func (c *Module) Name() string {
586 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700587 if p, ok := c.linker.(interface {
588 Name(string) string
589 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700590 name = p.Name(name)
591 }
592 return name
593}
594
Jeff Gaston294356f2017-09-27 17:05:30 -0700595// orderDeps reorders dependencies into a list such that if module A depends on B, then
596// A will precede B in the resultant list.
597// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800598// Note that directSharedDeps should be the analogous static library for each shared lib dep
599func 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 -0700600 // If A depends on B, then
601 // Every list containing A will also contain B later in the list
602 // So, after concatenating all lists, the final instance of B will have come from the same
603 // original list as the final instance of A
604 // So, the final instance of B will be later in the concatenation than the final A
605 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
606 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800607 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700608 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800609 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
610 }
611 for _, dep := range directSharedDeps {
612 orderedAllDeps = append(orderedAllDeps, dep)
613 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700614 }
615
Colin Crossb6715442017-10-24 11:13:31 -0700616 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700617
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800618 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700619 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800620 // resultant list to only what the caller has chosen to include in directStaticDeps
621 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700622
623 return orderedAllDeps, orderedDeclaredDeps
624}
625
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800626func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
627 // convert Module to Path
628 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
629 staticDepFiles := []android.Path{}
630 for _, dep := range staticDeps {
631 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
632 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700633 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800634 sharedDepFiles := []android.Path{}
635 for _, sharedDep := range sharedDeps {
636 staticAnalogue := sharedDep.staticVariant
637 if staticAnalogue != nil {
638 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
639 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
640 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700641 }
642
643 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800644 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700645
646 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700647}
648
Colin Cross635c3b02016-05-18 15:37:25 -0700649func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700650
Colin Crossca860ac2016-01-04 14:34:37 -0800651 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700652 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800653 moduleContextImpl: moduleContextImpl{
654 mod: c,
655 },
656 }
657 ctx.ctx = ctx
658
Colin Crossf18e1102017-11-16 14:33:08 -0800659 deps := c.depsToPaths(ctx)
660 if ctx.Failed() {
661 return
662 }
663
Colin Crossca860ac2016-01-04 14:34:37 -0800664 flags := Flags{
665 Toolchain: c.toolchain(ctx),
666 Clang: c.clang(ctx),
667 }
Colin Crossca860ac2016-01-04 14:34:37 -0800668 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800669 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800670 }
671 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700672 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800673 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700674 if c.stl != nil {
675 flags = c.stl.flags(ctx, flags)
676 }
Colin Cross16b23492016-01-06 14:41:07 -0800677 if c.sanitize != nil {
678 flags = c.sanitize.flags(ctx, flags)
679 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800680 if c.coverage != nil {
681 flags = c.coverage.flags(ctx, flags)
682 }
Stephen Craneba090d12017-05-09 15:44:35 -0700683 if c.lto != nil {
684 flags = c.lto.flags(ctx, flags)
685 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700686 if c.pgo != nil {
687 flags = c.pgo.flags(ctx, flags)
688 }
Colin Crossca860ac2016-01-04 14:34:37 -0800689 for _, feature := range c.features {
690 flags = feature.flags(ctx, flags)
691 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800692 if ctx.Failed() {
693 return
694 }
695
Colin Crossb98c8b02016-07-29 13:44:28 -0700696 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
697 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
698 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800699
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800700 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
701 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700702 // We need access to all the flags seen by a source file.
703 if c.sabi != nil {
704 flags = c.sabi.flags(ctx, flags)
705 }
Colin Crossca860ac2016-01-04 14:34:37 -0800706 // Optimization to reduce size of build.ninja
707 // Replace the long list of flags for each file with a module-local variable
708 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
709 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
710 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
711 flags.CFlags = []string{"$cflags"}
712 flags.CppFlags = []string{"$cppflags"}
713 flags.AsFlags = []string{"$asflags"}
714
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700715 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800716 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700717 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800718 if ctx.Failed() {
719 return
720 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800721 }
722
Colin Crossca860ac2016-01-04 14:34:37 -0800723 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700724 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800725 if ctx.Failed() {
726 return
727 }
Colin Cross635c3b02016-05-18 15:37:25 -0700728 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700729 }
Colin Cross5049f022015-03-18 13:28:46 -0700730
Colin Crossce75d2c2016-10-06 16:12:58 -0700731 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
732 c.installer.install(ctx, c.outputFile.Path())
733 if ctx.Failed() {
734 return
Colin Crossca860ac2016-01-04 14:34:37 -0800735 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700736 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800737}
738
Colin Crossb98c8b02016-07-29 13:44:28 -0700739func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800740 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700741 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800742 }
Colin Crossca860ac2016-01-04 14:34:37 -0800743 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800744}
745
Colin Crossca860ac2016-01-04 14:34:37 -0800746func (c *Module) begin(ctx BaseModuleContext) {
747 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700748 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700749 }
Colin Crossca860ac2016-01-04 14:34:37 -0800750 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700751 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800752 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700753 if c.stl != nil {
754 c.stl.begin(ctx)
755 }
Colin Cross16b23492016-01-06 14:41:07 -0800756 if c.sanitize != nil {
757 c.sanitize.begin(ctx)
758 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800759 if c.coverage != nil {
760 c.coverage.begin(ctx)
761 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800762 if c.sabi != nil {
763 c.sabi.begin(ctx)
764 }
Justin Yun8effde42017-06-23 19:24:43 +0900765 if c.vndkdep != nil {
766 c.vndkdep.begin(ctx)
767 }
Stephen Craneba090d12017-05-09 15:44:35 -0700768 if c.lto != nil {
769 c.lto.begin(ctx)
770 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700771 if c.pgo != nil {
772 c.pgo.begin(ctx)
773 }
Colin Crossca860ac2016-01-04 14:34:37 -0800774 for _, feature := range c.features {
775 feature.begin(ctx)
776 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700777 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700778 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700779 if err != nil {
780 ctx.PropertyErrorf("sdk_version", err.Error())
781 }
Nan Zhang0007d812017-11-07 10:57:05 -0800782 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700783 }
Colin Crossca860ac2016-01-04 14:34:37 -0800784}
785
Colin Cross37047f12016-12-13 17:06:13 -0800786func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700787 deps := Deps{}
788
789 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700790 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700791 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700792 // Add the PGO dependency (the clang_rt.profile runtime library), which
793 // sometimes depends on symbols from libgcc, before libgcc gets added
794 // in linkerDeps().
795 if c.pgo != nil {
796 deps = c.pgo.deps(ctx, deps)
797 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700798 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700799 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700800 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700801 if c.stl != nil {
802 deps = c.stl.deps(ctx, deps)
803 }
Colin Cross16b23492016-01-06 14:41:07 -0800804 if c.sanitize != nil {
805 deps = c.sanitize.deps(ctx, deps)
806 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800807 if c.coverage != nil {
808 deps = c.coverage.deps(ctx, deps)
809 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800810 if c.sabi != nil {
811 deps = c.sabi.deps(ctx, deps)
812 }
Justin Yun8effde42017-06-23 19:24:43 +0900813 if c.vndkdep != nil {
814 deps = c.vndkdep.deps(ctx, deps)
815 }
Stephen Craneba090d12017-05-09 15:44:35 -0700816 if c.lto != nil {
817 deps = c.lto.deps(ctx, deps)
818 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700819 for _, feature := range c.features {
820 deps = feature.deps(ctx, deps)
821 }
822
Colin Crossb6715442017-10-24 11:13:31 -0700823 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
824 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
825 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
826 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
827 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
828 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700829
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700830 for _, lib := range deps.ReexportSharedLibHeaders {
831 if !inList(lib, deps.SharedLibs) {
832 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
833 }
834 }
835
836 for _, lib := range deps.ReexportStaticLibHeaders {
837 if !inList(lib, deps.StaticLibs) {
838 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
839 }
840 }
841
Colin Cross5950f382016-12-13 12:50:57 -0800842 for _, lib := range deps.ReexportHeaderLibHeaders {
843 if !inList(lib, deps.HeaderLibs) {
844 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
845 }
846 }
847
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700848 for _, gen := range deps.ReexportGeneratedHeaders {
849 if !inList(gen, deps.GeneratedHeaders) {
850 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
851 }
852 }
853
Colin Crossc99deeb2016-04-11 15:06:20 -0700854 return deps
855}
856
Dan Albert7e9d2952016-08-04 13:02:36 -0700857func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800858 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700859 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800860 moduleContextImpl: moduleContextImpl{
861 mod: c,
862 },
863 }
864 ctx.ctx = ctx
865
Colin Crossca860ac2016-01-04 14:34:37 -0800866 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700867}
868
Colin Cross1e676be2016-10-12 14:38:15 -0700869func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
870 if !c.Enabled() {
871 return
872 }
873
Colin Cross37047f12016-12-13 17:06:13 -0800874 ctx := &depsContext{
875 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700876 moduleContextImpl: moduleContextImpl{
877 mod: c,
878 },
879 }
880 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800881
Colin Crossc99deeb2016-04-11 15:06:20 -0700882 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800883
Dan Albert914449f2016-06-17 16:45:24 -0700884 variantNdkLibs := []string{}
885 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700886 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700887 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700888
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700889 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
890 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700891 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700892 // 1. Name of an NDK library that refers to a prebuilt module.
893 // For each of these, it adds the name of the prebuilt module (which will be in
894 // prebuilts/ndk) to the list of nonvariant libs.
895 // 2. Name of an NDK library that refers to an ndk_library module.
896 // For each of these, it adds the name of the ndk_library module to the list of
897 // variant libs.
898 // 3. Anything else (so anything that isn't an NDK library).
899 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700900 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700901 // The caller can then know to add the variantLibs dependencies differently from the
902 // nonvariantLibs
903 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
904 variantLibs = []string{}
905 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700906 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700907 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700908 if !inList(entry, ndkMigratedLibs) {
909 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
910 } else {
911 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
912 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700913 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700914 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700915 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700916 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700917 }
918 }
Dan Albert914449f2016-06-17 16:45:24 -0700919 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700920 }
921
Dan Albert914449f2016-06-17 16:45:24 -0700922 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
923 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900924 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700925 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700926
Colin Cross32ec36c2016-12-15 07:39:51 -0800927 for _, lib := range deps.HeaderLibs {
928 depTag := headerDepTag
929 if inList(lib, deps.ReexportHeaderLibHeaders) {
930 depTag = headerExportDepTag
931 }
932 actx.AddVariationDependencies(nil, depTag, lib)
933 }
Colin Cross5950f382016-12-13 12:50:57 -0800934
Colin Crossc99deeb2016-04-11 15:06:20 -0700935 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
936 deps.WholeStaticLibs...)
937
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700938 for _, lib := range deps.StaticLibs {
939 depTag := staticDepTag
940 if inList(lib, deps.ReexportStaticLibHeaders) {
941 depTag = staticExportDepTag
942 }
Colin Cross15a0d462016-07-14 14:49:58 -0700943 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700944 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700945
946 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
947 deps.LateStaticLibs...)
948
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700949 for _, lib := range deps.SharedLibs {
950 depTag := sharedDepTag
951 if inList(lib, deps.ReexportSharedLibHeaders) {
952 depTag = sharedExportDepTag
953 }
Colin Cross15a0d462016-07-14 14:49:58 -0700954 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700955 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700956
957 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
958 deps.LateSharedLibs...)
959
Colin Cross68861832016-07-08 10:41:41 -0700960 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700961
962 for _, gen := range deps.GeneratedHeaders {
963 depTag := genHeaderDepTag
964 if inList(gen, deps.ReexportGeneratedHeaders) {
965 depTag = genHeaderExportDepTag
966 }
967 actx.AddDependency(c, depTag, gen)
968 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700969
Colin Cross68861832016-07-08 10:41:41 -0700970 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700971
972 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700973 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800974 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700975 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700976 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700977 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700978 if deps.LinkerScript != "" {
979 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
980 }
Dan Albert914449f2016-06-17 16:45:24 -0700981
982 version := ctx.sdkVersion()
983 actx.AddVariationDependencies([]blueprint.Variation{
984 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
985 actx.AddVariationDependencies([]blueprint.Variation{
986 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +0800987
988 if vndkdep := c.vndkdep; vndkdep != nil {
989 if vndkdep.isVndkExt() {
990 baseModuleMode := vendorMode
991 if actx.DeviceConfig().VndkVersion() == "" {
992 baseModuleMode = coreMode
993 }
994 actx.AddVariationDependencies([]blueprint.Variation{
995 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
996 vndkdep.getVndkExtendsModuleName())
997 }
998 }
Colin Cross6362e272015-10-29 15:25:03 -0700999}
Colin Cross21b9a242015-03-24 14:15:58 -07001000
Dan Albert7e9d2952016-08-04 13:02:36 -07001001func beginMutator(ctx android.BottomUpMutatorContext) {
1002 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1003 c.beginMutator(ctx)
1004 }
1005}
1006
Colin Crossca860ac2016-01-04 14:34:37 -08001007func (c *Module) clang(ctx BaseModuleContext) bool {
1008 clang := Bool(c.Properties.Clang)
1009
1010 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001011 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001012 }
Colin Cross28344522015-04-22 13:07:53 -07001013
Colin Crossca860ac2016-01-04 14:34:37 -08001014 if !c.toolchain(ctx).ClangSupported() {
1015 clang = false
1016 }
1017
1018 return clang
1019}
1020
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001021// Whether a module can link to another module, taking into
1022// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001023func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001024 if from.Target().Os != android.Android {
1025 // Host code is not restricted
1026 return
1027 }
1028 if from.Properties.UseVndk {
1029 // Though vendor code is limited by the vendor mutator,
1030 // each vendor-available module needs to check
1031 // link-type for VNDK.
1032 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001033 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001034 }
1035 return
1036 }
Nan Zhang0007d812017-11-07 10:57:05 -08001037 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001038 // Platform code can link to anything
1039 return
1040 }
1041 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1042 // These are always allowed
1043 return
1044 }
1045 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
1046 // These are allowed, but they don't set sdk_version
1047 return
1048 }
1049 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1050 // These are allowed, but they don't set sdk_version
1051 return
1052 }
1053 if _, ok := to.linker.(*stubDecorator); ok {
1054 // These aren't real libraries, but are the stub shared libraries that are included in
1055 // the NDK.
1056 return
1057 }
Nan Zhang0007d812017-11-07 10:57:05 -08001058 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001059 // NDK code linking to platform code is never okay.
1060 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1061 ctx.OtherModuleName(to))
1062 }
1063
1064 // At this point we know we have two NDK libraries, but we need to
1065 // check that we're not linking against anything built against a higher
1066 // API level, as it is only valid to link against older or equivalent
1067 // APIs.
1068
Nan Zhang0007d812017-11-07 10:57:05 -08001069 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001070 // Current can link against anything.
1071 return
Nan Zhang0007d812017-11-07 10:57:05 -08001072 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001073 // Current can't be linked against by anything else.
1074 ctx.ModuleErrorf("links %q built against newer API version %q",
1075 ctx.OtherModuleName(to), "current")
1076 }
1077
Nan Zhang0007d812017-11-07 10:57:05 -08001078 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001079 if err != nil {
1080 ctx.PropertyErrorf("sdk_version",
1081 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001082 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001083 }
Nan Zhang0007d812017-11-07 10:57:05 -08001084 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001085 if err != nil {
1086 ctx.PropertyErrorf("sdk_version",
1087 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001088 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089 }
1090
1091 if toApi > fromApi {
1092 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001093 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001094 }
Dan Albert202fe492017-12-15 13:56:59 -08001095
1096 // Also check that the two STL choices are compatible.
1097 fromStl := from.stl.Properties.SelectedStl
1098 toStl := to.stl.Properties.SelectedStl
1099 if fromStl == "" || toStl == "" {
1100 // Libraries that don't use the STL are unrestricted.
1101 return
1102 }
1103
1104 if fromStl == "ndk_system" || toStl == "ndk_system" {
1105 // We can be permissive with the system "STL" since it is only the C++
1106 // ABI layer, but in the future we should make sure that everyone is
1107 // using either libc++ or nothing.
1108 return
1109 }
1110
1111 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1112 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1113 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1114 to.stl.Properties.SelectedStl)
1115 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001116}
1117
Colin Crossc99deeb2016-04-11 15:06:20 -07001118// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001119func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001120 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001121
Jeff Gaston294356f2017-09-27 17:05:30 -07001122 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001123 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001124
Colin Crossd11fcda2017-10-23 17:59:01 -07001125 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001126 depName := ctx.OtherModuleName(dep)
1127 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001128
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001129 ccDep, _ := dep.(*Module)
1130 if ccDep == nil {
1131 // handling for a few module types that aren't cc Module but that are also supported
1132 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001133 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001134 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001135 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001136 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001137 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1138 genRule.GeneratedSourceFiles()...)
1139 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001140 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001141 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001142 // Support exported headers from a generated_sources dependency
1143 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001144 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001145 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001146 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001147 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001148 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001149 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001150 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001151 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001152 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001153 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001154 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1155 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1156
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001157 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001158 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001159 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001160 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001161 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001162 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001163 files := genRule.GeneratedSourceFiles()
1164 if len(files) == 1 {
1165 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1166 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001167 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001168 }
1169 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001170 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001171 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001172 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001173 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001174 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001175 return
1176 }
1177
Colin Crossd11fcda2017-10-23 17:59:01 -07001178 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001179 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1180 return
1181 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001182 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001183 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001184 return
1185 }
1186
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001187 // re-exporting flags
1188 if depTag == reuseObjTag {
1189 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001190 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001191 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001192 depPaths.Objs = depPaths.Objs.Append(objs)
1193 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001194 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001195 return
1196 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001197 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001198 if t, ok := depTag.(dependencyTag); ok && t.library {
1199 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001200 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001201 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001202 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001203 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001204
1205 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001206 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001207 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001208 // 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 -07001209 // Re-exported shared library headers must be included as well since they can help us with type information
1210 // about template instantiations (instantiated from their headers).
1211 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001212 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001213 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001214
Logan Chienf3511742017-10-31 18:04:35 +08001215 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001216 }
1217
Colin Cross26c34ed2016-09-30 17:10:16 -07001218 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001219 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001220
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001221 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001222 depFile := android.OptionalPath{}
1223
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001224 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001225 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001226 ptr = &depPaths.SharedLibs
1227 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001228 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001229 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001230 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001231 ptr = &depPaths.LateSharedLibs
1232 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001233 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001234 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001235 ptr = nil
1236 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001237 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001238 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001239 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001240 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001241 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001242 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001243 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001244 return
1245 }
1246
1247 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001248 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001249 for i := range missingDeps {
1250 missingDeps[i] += postfix
1251 }
1252 ctx.AddMissingDependencies(missingDeps)
1253 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001254 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001255 case headerDepTag:
1256 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001257 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001258 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001259 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001260 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001261 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001262 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001263 }
1264
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001265 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001266 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001267 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001268 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001269 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001270 return
1271 }
1272
1273 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001274 // in static libraries act as if they were whole static libraries. The same goes for
1275 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001276 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1277 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001278 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1279 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001280
Dan Willemsen581341d2017-02-09 16:16:31 -08001281 }
1282
Colin Cross26c34ed2016-09-30 17:10:16 -07001283 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001284 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001285 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001286 return
1287 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001288 *ptr = append(*ptr, linkFile.Path())
1289 }
1290
Colin Crossc99deeb2016-04-11 15:06:20 -07001291 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001292 dep := depFile
1293 if !dep.Valid() {
1294 dep = linkFile
1295 }
1296 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001297 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001298
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001299 // Export the shared libs to Make.
1300 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001301 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001302 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001303 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001304 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001305 var makeLibName string
1306 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1307 if c.useVndk() && bothVendorAndCoreVariantsExist {
1308 // The vendor module in Make will have been renamed to not conflict with the core
1309 // module, so update the dependency name here accordingly.
1310 makeLibName = libName + vendorSuffix
1311 } else {
1312 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001313 }
1314 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001315 // they merely serve as Make dependencies and do not affect this lib itself.
1316 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001317 }
Colin Crossca860ac2016-01-04 14:34:37 -08001318 })
1319
Jeff Gaston294356f2017-09-27 17:05:30 -07001320 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001321 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001322
Colin Crossdd84e052017-05-17 13:44:16 -07001323 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001324 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001325 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001326 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001327 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1328
1329 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001330 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001331 }
Colin Crossdd84e052017-05-17 13:44:16 -07001332
Colin Crossca860ac2016-01-04 14:34:37 -08001333 return depPaths
1334}
1335
1336func (c *Module) InstallInData() bool {
1337 if c.installer == nil {
1338 return false
1339 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001340 return c.installer.inData()
1341}
1342
1343func (c *Module) InstallInSanitizerDir() bool {
1344 if c.installer == nil {
1345 return false
1346 }
1347 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001348 return true
1349 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001350 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001351}
1352
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001353func (c *Module) HostToolPath() android.OptionalPath {
1354 if c.installer == nil {
1355 return android.OptionalPath{}
1356 }
1357 return c.installer.hostToolPath()
1358}
1359
Nan Zhangd4e641b2017-07-12 12:55:28 -07001360func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1361 return c.outputFile
1362}
1363
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001364func (c *Module) Srcs() android.Paths {
1365 if c.outputFile.Valid() {
1366 return android.Paths{c.outputFile.Path()}
1367 }
1368 return android.Paths{}
1369}
1370
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001371func (c *Module) static() bool {
1372 if static, ok := c.linker.(interface {
1373 static() bool
1374 }); ok {
1375 return static.static()
1376 }
1377 return false
1378}
1379
Colin Cross2ba19d92015-05-07 15:44:20 -07001380//
Colin Crosscfad1192015-11-02 16:43:11 -08001381// Defaults
1382//
Colin Crossca860ac2016-01-04 14:34:37 -08001383type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001384 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001385 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001386}
1387
Colin Cross635c3b02016-05-18 15:37:25 -07001388func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001389}
1390
Colin Cross1e676be2016-10-12 14:38:15 -07001391func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1392}
1393
Colin Cross36242852017-06-23 15:06:31 -07001394func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001395 return DefaultsFactory()
1396}
1397
Colin Cross36242852017-06-23 15:06:31 -07001398func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001399 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001400
Colin Cross36242852017-06-23 15:06:31 -07001401 module.AddProperties(props...)
1402 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001403 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001404 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001405 &BaseCompilerProperties{},
1406 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001407 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001408 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001409 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001410 &TestProperties{},
1411 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001412 &UnusedProperties{},
1413 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001414 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001415 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001416 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001417 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001418 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001419 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001420 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001421 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001422 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001423 )
Colin Crosscfad1192015-11-02 16:43:11 -08001424
Colin Cross1f44a3a2017-07-07 14:33:33 -07001425 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001426
1427 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001428}
1429
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001430const (
1431 // coreMode is the variant used for framework-private libraries, or
1432 // SDK libraries. (which framework-private libraries can use)
1433 coreMode = "core"
1434
1435 // vendorMode is the variant used for /vendor code that compiles
1436 // against the VNDK.
1437 vendorMode = "vendor"
1438)
1439
Jiyong Park6a43f042017-10-12 23:05:00 +09001440func squashVendorSrcs(m *Module) {
1441 if lib, ok := m.compiler.(*libraryDecorator); ok {
1442 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1443 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1444
1445 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1446 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1447 }
1448}
1449
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001450func vendorMutator(mctx android.BottomUpMutatorContext) {
1451 if mctx.Os() != android.Android {
1452 return
1453 }
1454
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001455 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1456 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001457 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001458 mctx.CreateVariations(coreMode)
1459 } else if Bool(props.Vendor_available) {
1460 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001461 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001462 mctx.CreateVariations(vendorMode)
1463 } else {
1464 mctx.CreateVariations(coreMode)
1465 }
1466 }
1467 }
1468
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001469 m, ok := mctx.Module().(*Module)
1470 if !ok {
1471 return
1472 }
1473
1474 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001475 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1476
1477 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001478 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001479 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001480 return
1481 }
Logan Chienf3511742017-10-31 18:04:35 +08001482
1483 if vndkdep := m.vndkdep; vndkdep != nil {
1484 if vndkdep.isVndk() {
1485 if vendorSpecific {
1486 if !vndkdep.isVndkExt() {
1487 mctx.PropertyErrorf("vndk",
1488 "must set `extends: \"...\"` to vndk extension")
1489 return
1490 }
1491 } else {
1492 if vndkdep.isVndkExt() {
1493 mctx.PropertyErrorf("vndk",
1494 "must set `vendor: true` to set `extends: %q`",
1495 m.getVndkExtendsModuleName())
1496 return
1497 }
1498 if m.VendorProperties.Vendor_available == nil {
1499 mctx.PropertyErrorf("vndk",
1500 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1501 return
1502 }
1503 }
1504 } else {
1505 if vndkdep.isVndkSp() {
1506 mctx.PropertyErrorf("vndk",
1507 "must set `enabled: true` to set `support_system_process: true`")
1508 return
1509 }
1510 if vndkdep.isVndkExt() {
1511 mctx.PropertyErrorf("vndk",
1512 "must set `enabled: true` to set `extends: %q`",
1513 m.getVndkExtendsModuleName())
1514 return
1515 }
Justin Yun8effde42017-06-23 19:24:43 +09001516 }
1517 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001518
Justin Yun71549282017-11-17 12:10:28 +09001519 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001520 // If the device isn't compiling against the VNDK, we always
1521 // use the core mode.
1522 mctx.CreateVariations(coreMode)
1523 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1524 // LL-NDK stubs only exist in the vendor variant, since the
1525 // real libraries will be used in the core variant.
1526 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001527 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1528 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001529 mod := mctx.CreateVariations(vendorMode)
1530 vendor := mod[0].(*Module)
1531 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001532 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001533 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1534 // PRODUCT_EXTRA_VNDK_VERSIONS.
1535 mod := mctx.CreateVariations(vendorMode)
1536 vendor := mod[0].(*Module)
1537 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001538 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001539 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001540 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001541 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001542 vendor := mod[1].(*Module)
1543 vendor.Properties.UseVndk = true
1544 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001545 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001546 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001547 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001548 vendor := mod[0].(*Module)
1549 vendor.Properties.UseVndk = true
1550 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001551 } else {
1552 // This is either in /system (or similar: /data), or is a
1553 // modules built with the NDK. Modules built with the NDK
1554 // will be restricted using the existing link type checks.
1555 mctx.CreateVariations(coreMode)
1556 }
1557}
1558
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001559func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001560 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001561 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1562 }
Colin Cross6510f912017-11-29 00:27:14 -08001563 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001564}
1565
Colin Cross06a931b2015-10-28 17:23:31 -07001566var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001567var BoolPtr = proptools.BoolPtr
1568var String = proptools.String
1569var StringPtr = proptools.StringPtr