blob: e5a483d8f5c5208503c1f580f8cb0d26a8427d25 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Park6a43f042017-10-12 23:05:00 +090037 ctx.BottomUp("image", vendorMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070038 ctx.BottomUp("link", linkageMutator).Parallel()
Jiyong Parkd5b18a52017-08-03 21:22:50 +090039 ctx.BottomUp("vndk", vndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
42 ctx.BottomUp("begin", beginMutator).Parallel()
43 })
Colin Cross16b23492016-01-06 14:41:07 -080044
Colin Cross1e676be2016-10-12 14:38:15 -070045 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
46 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
47 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080048
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000049 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
50 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
51
Colin Cross1e676be2016-10-12 14:38:15 -070052 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
53 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080054
55 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080056 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070057
58 ctx.TopDown("lto_deps", ltoDepsMutator)
59 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070060 })
Colin Crossb98c8b02016-07-29 13:44:28 -070061
62 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070063}
64
Colin Crossca860ac2016-01-04 14:34:37 -080065type Deps struct {
66 SharedLibs, LateSharedLibs []string
67 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080068 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070069
Colin Cross5950f382016-12-13 12:50:57 -080070 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070071
Colin Cross81413472016-04-11 14:37:39 -070072 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070073
Dan Willemsenb40aab62016-04-20 14:21:14 -070074 GeneratedSources []string
75 GeneratedHeaders []string
76
Dan Willemsenb3454ab2016-09-28 17:34:58 -070077 ReexportGeneratedHeaders []string
78
Colin Cross97ba0732015-03-23 17:50:24 -070079 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070080 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070081}
82
Colin Crossca860ac2016-01-04 14:34:37 -080083type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070084 // Paths to .so files
85 SharedLibs, LateSharedLibs android.Paths
86 // Paths to the dependencies to use for .so files (.so.toc files)
87 SharedLibsDeps, LateSharedLibsDeps android.Paths
88 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070089 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070090
Colin Cross26c34ed2016-09-30 17:10:16 -070091 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070092 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080093 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070094 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Colin Cross26c34ed2016-09-30 17:10:16 -070096 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070097 GeneratedSources android.Paths
98 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070099
Dan Willemsen76f08272016-07-09 00:14:08 -0700100 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700101 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700102
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700104 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700105 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700109 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
110 ArFlags []string // Flags that apply to ar
111 AsFlags []string // Flags that apply to assembly source files
112 CFlags []string // Flags that apply to C and C++ source files
113 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
114 ConlyFlags []string // Flags that apply to C source files
115 CppFlags []string // Flags that apply to C++ source files
116 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
117 YaccFlags []string // Flags that apply to Yacc source files
118 protoFlags []string // Flags that apply to proto source files
Joe Onorato09e94ab2017-11-18 18:23:14 -0800119 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700120 aidlFlags []string // Flags that apply to aidl source files
121 rsFlags []string // Flags that apply to renderscript source files
122 LdFlags []string // Flags that apply to linker command lines
123 libFlags []string // Flags to add libraries early to the link order
124 TidyFlags []string // Flags that apply to clang-tidy
125 SAbiFlags []string // Flags that apply to header-abi-dumper
126 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700127
Colin Crossc3199482017-03-30 15:03:04 -0700128 // Global include flags that apply to C, C++, and assembly source files
129 // These must be after any module include flags, which will be in GlobalFlags.
130 SystemIncludeFlags []string
131
Colin Crossb98c8b02016-07-29 13:44:28 -0700132 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700133 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700134 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800135 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800136 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800137
138 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800139 DynamicLinker string
140
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700141 CFlagsDeps android.Paths // Files depended on by compiler flags
142 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800143
144 GroupStaticLibs bool
Colin Crossc472d572015-03-17 15:06:21 -0700145}
146
Colin Cross81413472016-04-11 14:37:39 -0700147type ObjectLinkerProperties struct {
148 // names of other cc_object modules to link into this module using partial linking
149 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700150
151 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800152 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700153}
154
Colin Crossca860ac2016-01-04 14:34:37 -0800155// Properties used to compile all C or C++ modules
156type BaseProperties struct {
157 // compile module with clang instead of gcc
158 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700159
160 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800161 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700162
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700163 AndroidMkSharedLibs []string `blueprint:"mutated"`
164 HideFromMake bool `blueprint:"mutated"`
165 PreventInstall bool `blueprint:"mutated"`
166
167 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800168
169 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
170 // file
171 Logtags []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700172}
173
174type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900175 // whether this module should be allowed to be directly depended by other
176 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
177 // If set to true, two variants will be built separately, one like
178 // normal, and the other limited to the set of libraries and headers
179 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700180 //
181 // The vendor variant may be used with a different (newer) /system,
182 // so it shouldn't have any unversioned runtime dependencies, or
183 // make assumptions about the system that may not be true in the
184 // future.
185 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900186 // If set to false, this module becomes inaccessible from /vendor modules.
187 //
188 // Default value is true when vndk: {enabled: true} or vendor: true.
189 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700190 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
191 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800192}
193
Colin Crossca860ac2016-01-04 14:34:37 -0800194type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800195 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800196}
197
Colin Crossca860ac2016-01-04 14:34:37 -0800198type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800199 static() bool
200 staticBinary() bool
201 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700202 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700203 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800204 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700205 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900206 isVndk() bool
207 isVndkSp() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800208 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700209 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700210 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800211}
212
213type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700214 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800215 ModuleContextIntf
216}
217
218type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700219 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800220 ModuleContextIntf
221}
222
Colin Cross37047f12016-12-13 17:06:13 -0800223type DepsContext interface {
224 android.BottomUpMutatorContext
225 ModuleContextIntf
226}
227
Colin Crossca860ac2016-01-04 14:34:37 -0800228type feature interface {
229 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800230 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800231 flags(ctx ModuleContext, flags Flags) Flags
232 props() []interface{}
233}
234
235type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700236 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800237 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800238 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700239 compilerProps() []interface{}
240
Colin Cross76fada02016-07-27 10:31:13 -0700241 appendCflags([]string)
242 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700243 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800244}
245
246type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700247 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800248 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700249 linkerFlags(ctx ModuleContext, flags Flags) Flags
250 linkerProps() []interface{}
251
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700252 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700253 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800254}
255
256type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700257 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700258 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800259 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700260 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700261 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800262}
263
Colin Crossc99deeb2016-04-11 15:06:20 -0700264type dependencyTag struct {
265 blueprint.BaseDependencyTag
266 name string
267 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700268
269 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700270}
271
272var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700273 sharedDepTag = dependencyTag{name: "shared", library: true}
274 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
275 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
276 staticDepTag = dependencyTag{name: "static", library: true}
277 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
278 lateStaticDepTag = dependencyTag{name: "late static", library: true}
279 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800280 headerDepTag = dependencyTag{name: "header", library: true}
281 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700282 genSourceDepTag = dependencyTag{name: "gen source"}
283 genHeaderDepTag = dependencyTag{name: "gen header"}
284 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
285 objDepTag = dependencyTag{name: "obj"}
286 crtBeginDepTag = dependencyTag{name: "crtbegin"}
287 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700288 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700289 reuseObjTag = dependencyTag{name: "reuse objects"}
290 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
291 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700292)
293
Colin Crossca860ac2016-01-04 14:34:37 -0800294// Module contains the properties and members used by all C/C++ module types, and implements
295// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
296// to construct the output file. Behavior can be customized with a Customizer interface
297type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700298 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700299 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700300
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700301 Properties BaseProperties
302 VendorProperties VendorProperties
303 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700304
Colin Crossca860ac2016-01-04 14:34:37 -0800305 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700306 hod android.HostOrDeviceSupported
307 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700308
Colin Crossca860ac2016-01-04 14:34:37 -0800309 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700310 features []feature
311 compiler compiler
312 linker linker
313 installer installer
314 stl *stl
315 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800316 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800317 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900318 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700319 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700320 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800321
322 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700323
Colin Cross635c3b02016-05-18 15:37:25 -0700324 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800325
Colin Crossb98c8b02016-07-29 13:44:28 -0700326 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700327
328 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800329
330 // Flags used to compile this module
331 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700332
333 // 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 -0800334 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700335 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800336 depsInLinkOrder android.Paths
337
338 // only non-nil when this is a shared library that reuses the objects of a static library
339 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700340}
341
Colin Cross36242852017-06-23 15:06:31 -0700342func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700343 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800344 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700345 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800346 }
347 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700348 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800349 }
350 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700351 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800352 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700353 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700354 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700355 }
Colin Cross16b23492016-01-06 14:41:07 -0800356 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700357 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800358 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800359 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700360 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800361 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800362 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700363 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800364 }
Justin Yun8effde42017-06-23 19:24:43 +0900365 if c.vndkdep != nil {
366 c.AddProperties(c.vndkdep.props()...)
367 }
Stephen Craneba090d12017-05-09 15:44:35 -0700368 if c.lto != nil {
369 c.AddProperties(c.lto.props()...)
370 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700371 if c.pgo != nil {
372 c.AddProperties(c.pgo.props()...)
373 }
Colin Crossca860ac2016-01-04 14:34:37 -0800374 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700375 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800376 }
Colin Crossc472d572015-03-17 15:06:21 -0700377
Colin Cross36242852017-06-23 15:06:31 -0700378 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700379
Colin Cross1f44a3a2017-07-07 14:33:33 -0700380 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700381
382 return c
Colin Crossc472d572015-03-17 15:06:21 -0700383}
384
Colin Crossb916a382016-07-29 17:28:03 -0700385// Returns true for dependency roots (binaries)
386// TODO(ccross): also handle dlopenable libraries
387func (c *Module) isDependencyRoot() bool {
388 if root, ok := c.linker.(interface {
389 isDependencyRoot() bool
390 }); ok {
391 return root.isDependencyRoot()
392 }
393 return false
394}
395
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700396func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700397 return c.Properties.UseVndk
398}
399
Justin Yun8effde42017-06-23 19:24:43 +0900400func (c *Module) isVndk() bool {
401 if c.vndkdep != nil {
402 return c.vndkdep.isVndk()
403 }
404 return false
405}
406
Jiyong Park82e2bf32017-08-16 14:05:54 +0900407// Returns true only when this module is configured to have core and vendor
408// variants.
409func (c *Module) hasVendorVariant() bool {
410 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
411}
412
Colin Crossca860ac2016-01-04 14:34:37 -0800413type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700414 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800415 moduleContextImpl
416}
417
Colin Cross37047f12016-12-13 17:06:13 -0800418type depsContext struct {
419 android.BottomUpMutatorContext
420 moduleContextImpl
421}
422
Colin Crossca860ac2016-01-04 14:34:37 -0800423type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700424 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800425 moduleContextImpl
426}
427
Jiyong Park2db76922017-11-08 16:03:48 +0900428func (ctx *moduleContext) SocSpecific() bool {
429 return ctx.ModuleContext.SocSpecific() ||
430 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700431}
432
Colin Crossca860ac2016-01-04 14:34:37 -0800433type moduleContextImpl struct {
434 mod *Module
435 ctx BaseModuleContext
436}
437
Colin Crossca860ac2016-01-04 14:34:37 -0800438func (ctx *moduleContextImpl) clang() bool {
439 return ctx.mod.clang(ctx.ctx)
440}
441
Colin Crossb98c8b02016-07-29 13:44:28 -0700442func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800443 return ctx.mod.toolchain(ctx.ctx)
444}
445
446func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000447 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800448}
449
450func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700451 if static, ok := ctx.mod.linker.(interface {
452 staticBinary() bool
453 }); ok {
454 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800455 }
Colin Crossb916a382016-07-29 17:28:03 -0700456 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800457}
458
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700459func (ctx *moduleContextImpl) useSdk() bool {
460 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800461 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700462 }
463 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800464}
465
466func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700467 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700468 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700469 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800470 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800471 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800472 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700473 }
474 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800475}
476
Justin Yun8effde42017-06-23 19:24:43 +0900477func (ctx *moduleContextImpl) isVndk() bool {
478 return ctx.mod.isVndk()
479}
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700480func (ctx *moduleContextImpl) useVndk() bool {
481 return ctx.mod.useVndk()
482}
Justin Yun8effde42017-06-23 19:24:43 +0900483
484func (ctx *moduleContextImpl) isVndkSp() bool {
485 if vndk := ctx.mod.vndkdep; vndk != nil {
486 return vndk.isVndkSp()
487 }
488 return false
489}
490
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800491// Create source abi dumps if the module belongs to the list of VndkLibraries.
492func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700493 return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800494}
495
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700496func (ctx *moduleContextImpl) selectedStl() string {
497 if stl := ctx.mod.stl; stl != nil {
498 return stl.Properties.SelectedStl
499 }
500 return ""
501}
502
Colin Crossce75d2c2016-10-06 16:12:58 -0700503func (ctx *moduleContextImpl) baseModuleName() string {
504 return ctx.mod.ModuleBase.BaseModuleName()
505}
506
Colin Cross635c3b02016-05-18 15:37:25 -0700507func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800508 return &Module{
509 hod: hod,
510 multilib: multilib,
511 }
512}
513
Colin Cross635c3b02016-05-18 15:37:25 -0700514func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800515 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700516 module.features = []feature{
517 &tidyFeature{},
518 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700519 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800520 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800521 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800522 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900523 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700524 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700525 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800526 return module
527}
528
Colin Crossce75d2c2016-10-06 16:12:58 -0700529func (c *Module) Prebuilt() *android.Prebuilt {
530 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
531 return p.prebuilt()
532 }
533 return nil
534}
535
536func (c *Module) Name() string {
537 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700538 if p, ok := c.linker.(interface {
539 Name(string) string
540 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700541 name = p.Name(name)
542 }
543 return name
544}
545
Jeff Gaston294356f2017-09-27 17:05:30 -0700546// orderDeps reorders dependencies into a list such that if module A depends on B, then
547// A will precede B in the resultant list.
548// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800549// Note that directSharedDeps should be the analogous static library for each shared lib dep
550func 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 -0700551 // If A depends on B, then
552 // Every list containing A will also contain B later in the list
553 // So, after concatenating all lists, the final instance of B will have come from the same
554 // original list as the final instance of A
555 // So, the final instance of B will be later in the concatenation than the final A
556 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
557 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800558 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700559 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800560 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
561 }
562 for _, dep := range directSharedDeps {
563 orderedAllDeps = append(orderedAllDeps, dep)
564 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700565 }
566
Colin Crossb6715442017-10-24 11:13:31 -0700567 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700568
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800569 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700570 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800571 // resultant list to only what the caller has chosen to include in directStaticDeps
572 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700573
574 return orderedAllDeps, orderedDeclaredDeps
575}
576
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800577func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
578 // convert Module to Path
579 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
580 staticDepFiles := []android.Path{}
581 for _, dep := range staticDeps {
582 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
583 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700584 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800585 sharedDepFiles := []android.Path{}
586 for _, sharedDep := range sharedDeps {
587 staticAnalogue := sharedDep.staticVariant
588 if staticAnalogue != nil {
589 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
590 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
591 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700592 }
593
594 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800595 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700596
597 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700598}
599
Colin Cross635c3b02016-05-18 15:37:25 -0700600func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700601
Colin Crossca860ac2016-01-04 14:34:37 -0800602 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700603 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800604 moduleContextImpl: moduleContextImpl{
605 mod: c,
606 },
607 }
608 ctx.ctx = ctx
609
Colin Crossf18e1102017-11-16 14:33:08 -0800610 deps := c.depsToPaths(ctx)
611 if ctx.Failed() {
612 return
613 }
614
Colin Crossca860ac2016-01-04 14:34:37 -0800615 flags := Flags{
616 Toolchain: c.toolchain(ctx),
617 Clang: c.clang(ctx),
618 }
Colin Crossca860ac2016-01-04 14:34:37 -0800619 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800620 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800621 }
622 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700623 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800624 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700625 if c.stl != nil {
626 flags = c.stl.flags(ctx, flags)
627 }
Colin Cross16b23492016-01-06 14:41:07 -0800628 if c.sanitize != nil {
629 flags = c.sanitize.flags(ctx, flags)
630 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800631 if c.coverage != nil {
632 flags = c.coverage.flags(ctx, flags)
633 }
Stephen Craneba090d12017-05-09 15:44:35 -0700634 if c.lto != nil {
635 flags = c.lto.flags(ctx, flags)
636 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700637 if c.pgo != nil {
638 flags = c.pgo.flags(ctx, flags)
639 }
Colin Crossca860ac2016-01-04 14:34:37 -0800640 for _, feature := range c.features {
641 flags = feature.flags(ctx, flags)
642 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800643 if ctx.Failed() {
644 return
645 }
646
Colin Crossb98c8b02016-07-29 13:44:28 -0700647 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
648 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
649 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800650
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800651 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
652 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700653 // We need access to all the flags seen by a source file.
654 if c.sabi != nil {
655 flags = c.sabi.flags(ctx, flags)
656 }
Colin Crossca860ac2016-01-04 14:34:37 -0800657 // Optimization to reduce size of build.ninja
658 // Replace the long list of flags for each file with a module-local variable
659 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
660 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
661 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
662 flags.CFlags = []string{"$cflags"}
663 flags.CppFlags = []string{"$cppflags"}
664 flags.AsFlags = []string{"$asflags"}
665
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700666 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800667 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700668 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800669 if ctx.Failed() {
670 return
671 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800672 }
673
Colin Crossca860ac2016-01-04 14:34:37 -0800674 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700675 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800676 if ctx.Failed() {
677 return
678 }
Colin Cross635c3b02016-05-18 15:37:25 -0700679 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700680 }
Colin Cross5049f022015-03-18 13:28:46 -0700681
Colin Crossce75d2c2016-10-06 16:12:58 -0700682 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
683 c.installer.install(ctx, c.outputFile.Path())
684 if ctx.Failed() {
685 return
Colin Crossca860ac2016-01-04 14:34:37 -0800686 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700687 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800688}
689
Colin Crossb98c8b02016-07-29 13:44:28 -0700690func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800691 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700692 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800693 }
Colin Crossca860ac2016-01-04 14:34:37 -0800694 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800695}
696
Colin Crossca860ac2016-01-04 14:34:37 -0800697func (c *Module) begin(ctx BaseModuleContext) {
698 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700699 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700700 }
Colin Crossca860ac2016-01-04 14:34:37 -0800701 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700702 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800703 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700704 if c.stl != nil {
705 c.stl.begin(ctx)
706 }
Colin Cross16b23492016-01-06 14:41:07 -0800707 if c.sanitize != nil {
708 c.sanitize.begin(ctx)
709 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800710 if c.coverage != nil {
711 c.coverage.begin(ctx)
712 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800713 if c.sabi != nil {
714 c.sabi.begin(ctx)
715 }
Justin Yun8effde42017-06-23 19:24:43 +0900716 if c.vndkdep != nil {
717 c.vndkdep.begin(ctx)
718 }
Stephen Craneba090d12017-05-09 15:44:35 -0700719 if c.lto != nil {
720 c.lto.begin(ctx)
721 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700722 if c.pgo != nil {
723 c.pgo.begin(ctx)
724 }
Colin Crossca860ac2016-01-04 14:34:37 -0800725 for _, feature := range c.features {
726 feature.begin(ctx)
727 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700728 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700729 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700730 if err != nil {
731 ctx.PropertyErrorf("sdk_version", err.Error())
732 }
Nan Zhang0007d812017-11-07 10:57:05 -0800733 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700734 }
Colin Crossca860ac2016-01-04 14:34:37 -0800735}
736
Colin Cross37047f12016-12-13 17:06:13 -0800737func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700738 deps := Deps{}
739
740 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700741 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700742 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700743 // Add the PGO dependency (the clang_rt.profile runtime library), which
744 // sometimes depends on symbols from libgcc, before libgcc gets added
745 // in linkerDeps().
746 if c.pgo != nil {
747 deps = c.pgo.deps(ctx, deps)
748 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700749 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700750 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700751 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700752 if c.stl != nil {
753 deps = c.stl.deps(ctx, deps)
754 }
Colin Cross16b23492016-01-06 14:41:07 -0800755 if c.sanitize != nil {
756 deps = c.sanitize.deps(ctx, deps)
757 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800758 if c.coverage != nil {
759 deps = c.coverage.deps(ctx, deps)
760 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800761 if c.sabi != nil {
762 deps = c.sabi.deps(ctx, deps)
763 }
Justin Yun8effde42017-06-23 19:24:43 +0900764 if c.vndkdep != nil {
765 deps = c.vndkdep.deps(ctx, deps)
766 }
Stephen Craneba090d12017-05-09 15:44:35 -0700767 if c.lto != nil {
768 deps = c.lto.deps(ctx, deps)
769 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700770 for _, feature := range c.features {
771 deps = feature.deps(ctx, deps)
772 }
773
Colin Crossb6715442017-10-24 11:13:31 -0700774 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
775 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
776 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
777 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
778 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
779 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700780
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700781 for _, lib := range deps.ReexportSharedLibHeaders {
782 if !inList(lib, deps.SharedLibs) {
783 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
784 }
785 }
786
787 for _, lib := range deps.ReexportStaticLibHeaders {
788 if !inList(lib, deps.StaticLibs) {
789 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
790 }
791 }
792
Colin Cross5950f382016-12-13 12:50:57 -0800793 for _, lib := range deps.ReexportHeaderLibHeaders {
794 if !inList(lib, deps.HeaderLibs) {
795 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
796 }
797 }
798
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700799 for _, gen := range deps.ReexportGeneratedHeaders {
800 if !inList(gen, deps.GeneratedHeaders) {
801 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
802 }
803 }
804
Colin Crossc99deeb2016-04-11 15:06:20 -0700805 return deps
806}
807
Dan Albert7e9d2952016-08-04 13:02:36 -0700808func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800809 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700810 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800811 moduleContextImpl: moduleContextImpl{
812 mod: c,
813 },
814 }
815 ctx.ctx = ctx
816
Colin Crossca860ac2016-01-04 14:34:37 -0800817 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700818}
819
Colin Cross1e676be2016-10-12 14:38:15 -0700820func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
821 if !c.Enabled() {
822 return
823 }
824
Colin Cross37047f12016-12-13 17:06:13 -0800825 ctx := &depsContext{
826 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700827 moduleContextImpl: moduleContextImpl{
828 mod: c,
829 },
830 }
831 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800832
Colin Crossc99deeb2016-04-11 15:06:20 -0700833 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800834
Dan Albert914449f2016-06-17 16:45:24 -0700835 variantNdkLibs := []string{}
836 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700837 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700838 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700839
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700840 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
841 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700842 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700843 // 1. Name of an NDK library that refers to a prebuilt module.
844 // For each of these, it adds the name of the prebuilt module (which will be in
845 // prebuilts/ndk) to the list of nonvariant libs.
846 // 2. Name of an NDK library that refers to an ndk_library module.
847 // For each of these, it adds the name of the ndk_library module to the list of
848 // variant libs.
849 // 3. Anything else (so anything that isn't an NDK library).
850 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700851 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700852 // The caller can then know to add the variantLibs dependencies differently from the
853 // nonvariantLibs
854 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
855 variantLibs = []string{}
856 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700857 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700858 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700859 if !inList(entry, ndkMigratedLibs) {
860 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
861 } else {
862 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
863 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700864 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700865 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700866 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700867 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700868 }
869 }
Dan Albert914449f2016-06-17 16:45:24 -0700870 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700871 }
872
Dan Albert914449f2016-06-17 16:45:24 -0700873 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
874 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900875 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700876 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700877
Colin Cross32ec36c2016-12-15 07:39:51 -0800878 for _, lib := range deps.HeaderLibs {
879 depTag := headerDepTag
880 if inList(lib, deps.ReexportHeaderLibHeaders) {
881 depTag = headerExportDepTag
882 }
883 actx.AddVariationDependencies(nil, depTag, lib)
884 }
Colin Cross5950f382016-12-13 12:50:57 -0800885
Colin Crossc99deeb2016-04-11 15:06:20 -0700886 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
887 deps.WholeStaticLibs...)
888
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700889 for _, lib := range deps.StaticLibs {
890 depTag := staticDepTag
891 if inList(lib, deps.ReexportStaticLibHeaders) {
892 depTag = staticExportDepTag
893 }
Colin Cross15a0d462016-07-14 14:49:58 -0700894 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700895 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700896
897 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
898 deps.LateStaticLibs...)
899
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700900 for _, lib := range deps.SharedLibs {
901 depTag := sharedDepTag
902 if inList(lib, deps.ReexportSharedLibHeaders) {
903 depTag = sharedExportDepTag
904 }
Colin Cross15a0d462016-07-14 14:49:58 -0700905 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700906 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700907
908 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
909 deps.LateSharedLibs...)
910
Colin Cross68861832016-07-08 10:41:41 -0700911 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700912
913 for _, gen := range deps.GeneratedHeaders {
914 depTag := genHeaderDepTag
915 if inList(gen, deps.ReexportGeneratedHeaders) {
916 depTag = genHeaderExportDepTag
917 }
918 actx.AddDependency(c, depTag, gen)
919 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700920
Colin Cross68861832016-07-08 10:41:41 -0700921 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700922
923 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700924 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800925 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700926 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700927 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700928 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700929 if deps.LinkerScript != "" {
930 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
931 }
Dan Albert914449f2016-06-17 16:45:24 -0700932
933 version := ctx.sdkVersion()
934 actx.AddVariationDependencies([]blueprint.Variation{
935 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
936 actx.AddVariationDependencies([]blueprint.Variation{
937 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700938}
Colin Cross21b9a242015-03-24 14:15:58 -0700939
Dan Albert7e9d2952016-08-04 13:02:36 -0700940func beginMutator(ctx android.BottomUpMutatorContext) {
941 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
942 c.beginMutator(ctx)
943 }
944}
945
Colin Crossca860ac2016-01-04 14:34:37 -0800946func (c *Module) clang(ctx BaseModuleContext) bool {
947 clang := Bool(c.Properties.Clang)
948
949 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -0800950 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800951 }
Colin Cross28344522015-04-22 13:07:53 -0700952
Colin Crossca860ac2016-01-04 14:34:37 -0800953 if !c.toolchain(ctx).ClangSupported() {
954 clang = false
955 }
956
957 return clang
958}
959
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700960// Whether a module can link to another module, taking into
961// account NDK linking.
962func checkLinkType(ctx android.ModuleContext, from *Module, to *Module) {
963 if from.Target().Os != android.Android {
964 // Host code is not restricted
965 return
966 }
967 if from.Properties.UseVndk {
968 // Though vendor code is limited by the vendor mutator,
969 // each vendor-available module needs to check
970 // link-type for VNDK.
971 if from.vndkdep != nil {
972 from.vndkdep.vndkCheckLinkType(ctx, to)
973 }
974 return
975 }
Nan Zhang0007d812017-11-07 10:57:05 -0800976 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700977 // Platform code can link to anything
978 return
979 }
980 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
981 // These are always allowed
982 return
983 }
984 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
985 // These are allowed, but they don't set sdk_version
986 return
987 }
988 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
989 // These are allowed, but they don't set sdk_version
990 return
991 }
992 if _, ok := to.linker.(*stubDecorator); ok {
993 // These aren't real libraries, but are the stub shared libraries that are included in
994 // the NDK.
995 return
996 }
Nan Zhang0007d812017-11-07 10:57:05 -0800997 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700998 // NDK code linking to platform code is never okay.
999 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1000 ctx.OtherModuleName(to))
1001 }
1002
1003 // At this point we know we have two NDK libraries, but we need to
1004 // check that we're not linking against anything built against a higher
1005 // API level, as it is only valid to link against older or equivalent
1006 // APIs.
1007
Nan Zhang0007d812017-11-07 10:57:05 -08001008 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001009 // Current can link against anything.
1010 return
Nan Zhang0007d812017-11-07 10:57:05 -08001011 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001012 // Current can't be linked against by anything else.
1013 ctx.ModuleErrorf("links %q built against newer API version %q",
1014 ctx.OtherModuleName(to), "current")
1015 }
1016
Nan Zhang0007d812017-11-07 10:57:05 -08001017 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001018 if err != nil {
1019 ctx.PropertyErrorf("sdk_version",
1020 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001021 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001022 }
Nan Zhang0007d812017-11-07 10:57:05 -08001023 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001024 if err != nil {
1025 ctx.PropertyErrorf("sdk_version",
1026 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001027 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001028 }
1029
1030 if toApi > fromApi {
1031 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001032 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001033 }
Dan Albert202fe492017-12-15 13:56:59 -08001034
1035 // Also check that the two STL choices are compatible.
1036 fromStl := from.stl.Properties.SelectedStl
1037 toStl := to.stl.Properties.SelectedStl
1038 if fromStl == "" || toStl == "" {
1039 // Libraries that don't use the STL are unrestricted.
1040 return
1041 }
1042
1043 if fromStl == "ndk_system" || toStl == "ndk_system" {
1044 // We can be permissive with the system "STL" since it is only the C++
1045 // ABI layer, but in the future we should make sure that everyone is
1046 // using either libc++ or nothing.
1047 return
1048 }
1049
1050 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1051 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1052 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1053 to.stl.Properties.SelectedStl)
1054 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001055}
1056
Colin Crossc99deeb2016-04-11 15:06:20 -07001057// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001058func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001059 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001060
Jeff Gaston294356f2017-09-27 17:05:30 -07001061 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001062 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001063
Colin Crossd11fcda2017-10-23 17:59:01 -07001064 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001065 depName := ctx.OtherModuleName(dep)
1066 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001067
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001068 ccDep, _ := dep.(*Module)
1069 if ccDep == nil {
1070 // handling for a few module types that aren't cc Module but that are also supported
1071 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001072 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001073 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001074 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001075 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001076 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1077 genRule.GeneratedSourceFiles()...)
1078 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001079 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001080 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001081 // Support exported headers from a generated_sources dependency
1082 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001083 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001084 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001085 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
1086 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001087 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001088 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001090 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001091 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
1092 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001093 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1094 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1095
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001096 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001097 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001098 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001099 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001100 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001101 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001102 files := genRule.GeneratedSourceFiles()
1103 if len(files) == 1 {
1104 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1105 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001106 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001107 }
1108 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001109 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001110 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001111 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001112 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001113 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001114 return
1115 }
1116
Colin Crossd11fcda2017-10-23 17:59:01 -07001117 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001118 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1119 return
1120 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001121 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001122 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001123 return
1124 }
1125
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001126 // re-exporting flags
1127 if depTag == reuseObjTag {
1128 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001129 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001130 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001131 depPaths.Objs = depPaths.Objs.Append(objs)
1132 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001133 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001134 return
1135 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001136 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001137 if t, ok := depTag.(dependencyTag); ok && t.library {
1138 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001139 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001140 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001141 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001142 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001143
1144 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001145 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001146 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001147 // 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 -07001148 // Re-exported shared library headers must be included as well since they can help us with type information
1149 // about template instantiations (instantiated from their headers).
1150 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001151 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001152 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001153
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001154 checkLinkType(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001155 }
1156
Colin Cross26c34ed2016-09-30 17:10:16 -07001157 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001158 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001159
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001160 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001161 depFile := android.OptionalPath{}
1162
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001163 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001164 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001165 ptr = &depPaths.SharedLibs
1166 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001167 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001168 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001169 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001170 ptr = &depPaths.LateSharedLibs
1171 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001172 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001173 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001174 ptr = nil
1175 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001176 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001177 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001178 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001179 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001180 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001181 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001182 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001183 return
1184 }
1185
1186 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001187 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001188 for i := range missingDeps {
1189 missingDeps[i] += postfix
1190 }
1191 ctx.AddMissingDependencies(missingDeps)
1192 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001193 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001194 case headerDepTag:
1195 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001196 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001197 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001198 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001199 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001200 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001201 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001202 }
1203
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001204 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001205 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001206 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001207 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001208 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001209 return
1210 }
1211
1212 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001213 // in static libraries act as if they were whole static libraries. The same goes for
1214 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001215 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1216 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001217 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1218 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001219
Dan Willemsen581341d2017-02-09 16:16:31 -08001220 }
1221
Colin Cross26c34ed2016-09-30 17:10:16 -07001222 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001223 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001224 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001225 return
1226 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001227 *ptr = append(*ptr, linkFile.Path())
1228 }
1229
Colin Crossc99deeb2016-04-11 15:06:20 -07001230 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001231 dep := depFile
1232 if !dep.Valid() {
1233 dep = linkFile
1234 }
1235 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001236 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001237
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001238 // Export the shared libs to Make.
1239 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001240 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001241 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001242 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001243 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001244 var makeLibName string
1245 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1246 if c.useVndk() && bothVendorAndCoreVariantsExist {
1247 // The vendor module in Make will have been renamed to not conflict with the core
1248 // module, so update the dependency name here accordingly.
1249 makeLibName = libName + vendorSuffix
1250 } else {
1251 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001252 }
1253 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001254 // they merely serve as Make dependencies and do not affect this lib itself.
1255 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001256 }
Colin Crossca860ac2016-01-04 14:34:37 -08001257 })
1258
Jeff Gaston294356f2017-09-27 17:05:30 -07001259 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001260 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001261
Colin Crossdd84e052017-05-17 13:44:16 -07001262 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001263 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001264 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001265 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001266 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1267
1268 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001269 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001270 }
Colin Crossdd84e052017-05-17 13:44:16 -07001271
Colin Crossca860ac2016-01-04 14:34:37 -08001272 return depPaths
1273}
1274
1275func (c *Module) InstallInData() bool {
1276 if c.installer == nil {
1277 return false
1278 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001279 return c.installer.inData()
1280}
1281
1282func (c *Module) InstallInSanitizerDir() bool {
1283 if c.installer == nil {
1284 return false
1285 }
1286 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001287 return true
1288 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001289 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001290}
1291
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001292func (c *Module) HostToolPath() android.OptionalPath {
1293 if c.installer == nil {
1294 return android.OptionalPath{}
1295 }
1296 return c.installer.hostToolPath()
1297}
1298
Nan Zhangd4e641b2017-07-12 12:55:28 -07001299func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1300 return c.outputFile
1301}
1302
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001303func (c *Module) Srcs() android.Paths {
1304 if c.outputFile.Valid() {
1305 return android.Paths{c.outputFile.Path()}
1306 }
1307 return android.Paths{}
1308}
1309
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001310func (c *Module) static() bool {
1311 if static, ok := c.linker.(interface {
1312 static() bool
1313 }); ok {
1314 return static.static()
1315 }
1316 return false
1317}
1318
Colin Cross2ba19d92015-05-07 15:44:20 -07001319//
Colin Crosscfad1192015-11-02 16:43:11 -08001320// Defaults
1321//
Colin Crossca860ac2016-01-04 14:34:37 -08001322type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001323 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001324 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001325}
1326
Colin Cross635c3b02016-05-18 15:37:25 -07001327func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001328}
1329
Colin Cross1e676be2016-10-12 14:38:15 -07001330func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1331}
1332
Colin Cross36242852017-06-23 15:06:31 -07001333func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001334 return DefaultsFactory()
1335}
1336
Colin Cross36242852017-06-23 15:06:31 -07001337func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001338 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001339
Colin Cross36242852017-06-23 15:06:31 -07001340 module.AddProperties(props...)
1341 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001342 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001343 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001344 &BaseCompilerProperties{},
1345 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001346 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001347 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001348 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001349 &TestProperties{},
1350 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001351 &UnusedProperties{},
1352 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001353 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001354 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001355 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001356 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001357 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001358 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001359 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001360 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001361 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001362 )
Colin Crosscfad1192015-11-02 16:43:11 -08001363
Colin Cross1f44a3a2017-07-07 14:33:33 -07001364 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001365
1366 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001367}
1368
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001369const (
1370 // coreMode is the variant used for framework-private libraries, or
1371 // SDK libraries. (which framework-private libraries can use)
1372 coreMode = "core"
1373
1374 // vendorMode is the variant used for /vendor code that compiles
1375 // against the VNDK.
1376 vendorMode = "vendor"
1377)
1378
Jiyong Park6a43f042017-10-12 23:05:00 +09001379func squashVendorSrcs(m *Module) {
1380 if lib, ok := m.compiler.(*libraryDecorator); ok {
1381 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1382 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1383
1384 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1385 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1386 }
1387}
1388
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001389func vendorMutator(mctx android.BottomUpMutatorContext) {
1390 if mctx.Os() != android.Android {
1391 return
1392 }
1393
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001394 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1395 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001396 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001397 mctx.CreateVariations(coreMode)
1398 } else if Bool(props.Vendor_available) {
1399 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001400 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001401 mctx.CreateVariations(vendorMode)
1402 } else {
1403 mctx.CreateVariations(coreMode)
1404 }
1405 }
1406 }
1407
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001408 m, ok := mctx.Module().(*Module)
1409 if !ok {
1410 return
1411 }
1412
1413 // Sanity check
Jiyong Park2db76922017-11-08 16:03:48 +09001414 if m.VendorProperties.Vendor_available != nil && (mctx.SocSpecific() || mctx.DeviceSpecific()) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001415 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001416 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001417 return
1418 }
Justin Yun8effde42017-06-23 19:24:43 +09001419 if vndk := m.vndkdep; vndk != nil {
Jiyong Park82e2bf32017-08-16 14:05:54 +09001420 if vndk.isVndk() && m.VendorProperties.Vendor_available == nil {
Justin Yun8effde42017-06-23 19:24:43 +09001421 mctx.PropertyErrorf("vndk",
Jiyong Park82e2bf32017-08-16 14:05:54 +09001422 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Justin Yun8effde42017-06-23 19:24:43 +09001423 return
1424 }
1425 if !vndk.isVndk() && vndk.isVndkSp() {
1426 mctx.PropertyErrorf("vndk",
1427 "must set `enabled: true` to set `support_system_process: true`")
1428 return
1429 }
1430 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001431
Justin Yun71549282017-11-17 12:10:28 +09001432 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001433 // If the device isn't compiling against the VNDK, we always
1434 // use the core mode.
1435 mctx.CreateVariations(coreMode)
1436 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1437 // LL-NDK stubs only exist in the vendor variant, since the
1438 // real libraries will be used in the core variant.
1439 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001440 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1441 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001442 mod := mctx.CreateVariations(vendorMode)
1443 vendor := mod[0].(*Module)
1444 vendor.Properties.UseVndk = true
Justin Yun71549282017-11-17 12:10:28 +09001445 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
1446 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1447 // PRODUCT_EXTRA_VNDK_VERSIONS.
1448 mod := mctx.CreateVariations(vendorMode)
1449 vendor := mod[0].(*Module)
1450 vendor.Properties.UseVndk = true
Jiyong Park82e2bf32017-08-16 14:05:54 +09001451 } else if m.hasVendorVariant() {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001452 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001453 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001454 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001455 vendor := mod[1].(*Module)
1456 vendor.Properties.UseVndk = true
1457 squashVendorSrcs(vendor)
Jiyong Park2db76922017-11-08 16:03:48 +09001458 } else if (mctx.SocSpecific() || mctx.DeviceSpecific()) && String(m.Properties.Sdk_version) == "" {
1459 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001460 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001461 vendor := mod[0].(*Module)
1462 vendor.Properties.UseVndk = true
1463 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001464 } else {
1465 // This is either in /system (or similar: /data), or is a
1466 // modules built with the NDK. Modules built with the NDK
1467 // will be restricted using the existing link type checks.
1468 mctx.CreateVariations(coreMode)
1469 }
1470}
1471
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001472func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001473 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001474 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1475 }
Colin Cross6510f912017-11-29 00:27:14 -08001476 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001477}
1478
Colin Cross06a931b2015-10-28 17:23:31 -07001479var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001480var BoolPtr = proptools.BoolPtr
1481var String = proptools.String
1482var StringPtr = proptools.StringPtr