blob: 13d0e3b282df109b4b5092b89639e3e69dee95a2 [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 {
950 if ctx.Host() {
951 clang = true
952 }
953
Colin Cross6510f912017-11-29 00:27:14 -0800954 if ctx.Device() && ctx.Config().DeviceUsesClang() {
Colin Crossca860ac2016-01-04 14:34:37 -0800955 clang = true
956 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800957 }
Colin Cross28344522015-04-22 13:07:53 -0700958
Colin Crossca860ac2016-01-04 14:34:37 -0800959 if !c.toolchain(ctx).ClangSupported() {
960 clang = false
961 }
962
963 return clang
964}
965
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700966// Whether a module can link to another module, taking into
967// account NDK linking.
968func checkLinkType(ctx android.ModuleContext, from *Module, to *Module) {
969 if from.Target().Os != android.Android {
970 // Host code is not restricted
971 return
972 }
973 if from.Properties.UseVndk {
974 // Though vendor code is limited by the vendor mutator,
975 // each vendor-available module needs to check
976 // link-type for VNDK.
977 if from.vndkdep != nil {
978 from.vndkdep.vndkCheckLinkType(ctx, to)
979 }
980 return
981 }
Nan Zhang0007d812017-11-07 10:57:05 -0800982 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700983 // Platform code can link to anything
984 return
985 }
986 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
987 // These are always allowed
988 return
989 }
990 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
991 // These are allowed, but they don't set sdk_version
992 return
993 }
994 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
995 // These are allowed, but they don't set sdk_version
996 return
997 }
998 if _, ok := to.linker.(*stubDecorator); ok {
999 // These aren't real libraries, but are the stub shared libraries that are included in
1000 // the NDK.
1001 return
1002 }
Nan Zhang0007d812017-11-07 10:57:05 -08001003 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001004 // NDK code linking to platform code is never okay.
1005 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1006 ctx.OtherModuleName(to))
1007 }
1008
1009 // At this point we know we have two NDK libraries, but we need to
1010 // check that we're not linking against anything built against a higher
1011 // API level, as it is only valid to link against older or equivalent
1012 // APIs.
1013
Nan Zhang0007d812017-11-07 10:57:05 -08001014 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001015 // Current can link against anything.
1016 return
Nan Zhang0007d812017-11-07 10:57:05 -08001017 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001018 // Current can't be linked against by anything else.
1019 ctx.ModuleErrorf("links %q built against newer API version %q",
1020 ctx.OtherModuleName(to), "current")
1021 }
1022
Nan Zhang0007d812017-11-07 10:57:05 -08001023 fromApi, err := strconv.Atoi(String(from.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(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001028 }
Nan Zhang0007d812017-11-07 10:57:05 -08001029 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001030 if err != nil {
1031 ctx.PropertyErrorf("sdk_version",
1032 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001033 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001034 }
1035
1036 if toApi > fromApi {
1037 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001038 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001039 }
Dan Albert202fe492017-12-15 13:56:59 -08001040
1041 // Also check that the two STL choices are compatible.
1042 fromStl := from.stl.Properties.SelectedStl
1043 toStl := to.stl.Properties.SelectedStl
1044 if fromStl == "" || toStl == "" {
1045 // Libraries that don't use the STL are unrestricted.
1046 return
1047 }
1048
1049 if fromStl == "ndk_system" || toStl == "ndk_system" {
1050 // We can be permissive with the system "STL" since it is only the C++
1051 // ABI layer, but in the future we should make sure that everyone is
1052 // using either libc++ or nothing.
1053 return
1054 }
1055
1056 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1057 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1058 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1059 to.stl.Properties.SelectedStl)
1060 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001061}
1062
Colin Crossc99deeb2016-04-11 15:06:20 -07001063// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001064func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001065 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001066
Jeff Gaston294356f2017-09-27 17:05:30 -07001067 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001068 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001069
Colin Crossd11fcda2017-10-23 17:59:01 -07001070 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001071 depName := ctx.OtherModuleName(dep)
1072 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001073
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001074 ccDep, _ := dep.(*Module)
1075 if ccDep == nil {
1076 // handling for a few module types that aren't cc Module but that are also supported
1077 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001078 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001079 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001080 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001081 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001082 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1083 genRule.GeneratedSourceFiles()...)
1084 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001085 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001086 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001087 // Support exported headers from a generated_sources dependency
1088 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001089 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001090 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001091 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
1092 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001093 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001094 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001095 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001096 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001097 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
1098 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001099 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1100 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1101
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001102 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001103 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001104 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001105 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001106 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001107 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001108 files := genRule.GeneratedSourceFiles()
1109 if len(files) == 1 {
1110 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1111 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001112 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001113 }
1114 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001115 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001116 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001117 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001118 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001119 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001120 return
1121 }
1122
Colin Crossd11fcda2017-10-23 17:59:01 -07001123 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001124 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1125 return
1126 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001127 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001128 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001129 return
1130 }
1131
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001132 // re-exporting flags
1133 if depTag == reuseObjTag {
1134 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001135 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001136 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001137 depPaths.Objs = depPaths.Objs.Append(objs)
1138 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001139 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001140 return
1141 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001142 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001143 if t, ok := depTag.(dependencyTag); ok && t.library {
1144 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001145 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001146 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001147 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001148 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001149
1150 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001151 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001152 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001153 // 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 -07001154 // Re-exported shared library headers must be included as well since they can help us with type information
1155 // about template instantiations (instantiated from their headers).
1156 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001157 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001158 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001159
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001160 checkLinkType(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001161 }
1162
Colin Cross26c34ed2016-09-30 17:10:16 -07001163 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001164 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001165
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001166 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001167 depFile := android.OptionalPath{}
1168
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001169 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001170 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001171 ptr = &depPaths.SharedLibs
1172 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001173 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001174 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001175 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001176 ptr = &depPaths.LateSharedLibs
1177 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001179 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001180 ptr = nil
1181 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001182 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001183 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001184 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001185 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001186 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001187 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001188 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001189 return
1190 }
1191
1192 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001193 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001194 for i := range missingDeps {
1195 missingDeps[i] += postfix
1196 }
1197 ctx.AddMissingDependencies(missingDeps)
1198 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001199 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001200 case headerDepTag:
1201 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001202 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001203 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001204 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001205 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001206 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001207 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001208 }
1209
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001210 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001211 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001212 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001213 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001214 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001215 return
1216 }
1217
1218 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001219 // in static libraries act as if they were whole static libraries. The same goes for
1220 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001221 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1222 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001223 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1224 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001225
Dan Willemsen581341d2017-02-09 16:16:31 -08001226 }
1227
Colin Cross26c34ed2016-09-30 17:10:16 -07001228 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001229 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001230 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001231 return
1232 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001233 *ptr = append(*ptr, linkFile.Path())
1234 }
1235
Colin Crossc99deeb2016-04-11 15:06:20 -07001236 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001237 dep := depFile
1238 if !dep.Valid() {
1239 dep = linkFile
1240 }
1241 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001242 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001243
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001244 // Export the shared libs to Make.
1245 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001246 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001247 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001248 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001249 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001250 var makeLibName string
1251 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1252 if c.useVndk() && bothVendorAndCoreVariantsExist {
1253 // The vendor module in Make will have been renamed to not conflict with the core
1254 // module, so update the dependency name here accordingly.
1255 makeLibName = libName + vendorSuffix
1256 } else {
1257 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001258 }
1259 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001260 // they merely serve as Make dependencies and do not affect this lib itself.
1261 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001262 }
Colin Crossca860ac2016-01-04 14:34:37 -08001263 })
1264
Jeff Gaston294356f2017-09-27 17:05:30 -07001265 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001266 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001267
Colin Crossdd84e052017-05-17 13:44:16 -07001268 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001269 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001270 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001271 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001272 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1273
1274 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001275 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001276 }
Colin Crossdd84e052017-05-17 13:44:16 -07001277
Colin Crossca860ac2016-01-04 14:34:37 -08001278 return depPaths
1279}
1280
1281func (c *Module) InstallInData() bool {
1282 if c.installer == nil {
1283 return false
1284 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001285 return c.installer.inData()
1286}
1287
1288func (c *Module) InstallInSanitizerDir() bool {
1289 if c.installer == nil {
1290 return false
1291 }
1292 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001293 return true
1294 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001295 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001296}
1297
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001298func (c *Module) HostToolPath() android.OptionalPath {
1299 if c.installer == nil {
1300 return android.OptionalPath{}
1301 }
1302 return c.installer.hostToolPath()
1303}
1304
Nan Zhangd4e641b2017-07-12 12:55:28 -07001305func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1306 return c.outputFile
1307}
1308
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001309func (c *Module) Srcs() android.Paths {
1310 if c.outputFile.Valid() {
1311 return android.Paths{c.outputFile.Path()}
1312 }
1313 return android.Paths{}
1314}
1315
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001316func (c *Module) static() bool {
1317 if static, ok := c.linker.(interface {
1318 static() bool
1319 }); ok {
1320 return static.static()
1321 }
1322 return false
1323}
1324
Colin Cross2ba19d92015-05-07 15:44:20 -07001325//
Colin Crosscfad1192015-11-02 16:43:11 -08001326// Defaults
1327//
Colin Crossca860ac2016-01-04 14:34:37 -08001328type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001329 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001330 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001331}
1332
Colin Cross635c3b02016-05-18 15:37:25 -07001333func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001334}
1335
Colin Cross1e676be2016-10-12 14:38:15 -07001336func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1337}
1338
Colin Cross36242852017-06-23 15:06:31 -07001339func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001340 return DefaultsFactory()
1341}
1342
Colin Cross36242852017-06-23 15:06:31 -07001343func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001344 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001345
Colin Cross36242852017-06-23 15:06:31 -07001346 module.AddProperties(props...)
1347 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001348 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001349 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001350 &BaseCompilerProperties{},
1351 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001352 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001353 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001354 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001355 &TestProperties{},
1356 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001357 &UnusedProperties{},
1358 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001359 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001360 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001361 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001362 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001363 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001364 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001365 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001366 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001367 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001368 )
Colin Crosscfad1192015-11-02 16:43:11 -08001369
Colin Cross1f44a3a2017-07-07 14:33:33 -07001370 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001371
1372 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001373}
1374
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001375const (
1376 // coreMode is the variant used for framework-private libraries, or
1377 // SDK libraries. (which framework-private libraries can use)
1378 coreMode = "core"
1379
1380 // vendorMode is the variant used for /vendor code that compiles
1381 // against the VNDK.
1382 vendorMode = "vendor"
1383)
1384
Jiyong Park6a43f042017-10-12 23:05:00 +09001385func squashVendorSrcs(m *Module) {
1386 if lib, ok := m.compiler.(*libraryDecorator); ok {
1387 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1388 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1389
1390 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1391 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1392 }
1393}
1394
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001395func vendorMutator(mctx android.BottomUpMutatorContext) {
1396 if mctx.Os() != android.Android {
1397 return
1398 }
1399
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001400 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1401 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001402 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001403 mctx.CreateVariations(coreMode)
1404 } else if Bool(props.Vendor_available) {
1405 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001406 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001407 mctx.CreateVariations(vendorMode)
1408 } else {
1409 mctx.CreateVariations(coreMode)
1410 }
1411 }
1412 }
1413
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001414 m, ok := mctx.Module().(*Module)
1415 if !ok {
1416 return
1417 }
1418
1419 // Sanity check
Jiyong Park2db76922017-11-08 16:03:48 +09001420 if m.VendorProperties.Vendor_available != nil && (mctx.SocSpecific() || mctx.DeviceSpecific()) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001421 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001422 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001423 return
1424 }
Justin Yun8effde42017-06-23 19:24:43 +09001425 if vndk := m.vndkdep; vndk != nil {
Jiyong Park82e2bf32017-08-16 14:05:54 +09001426 if vndk.isVndk() && m.VendorProperties.Vendor_available == nil {
Justin Yun8effde42017-06-23 19:24:43 +09001427 mctx.PropertyErrorf("vndk",
Jiyong Park82e2bf32017-08-16 14:05:54 +09001428 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Justin Yun8effde42017-06-23 19:24:43 +09001429 return
1430 }
1431 if !vndk.isVndk() && vndk.isVndkSp() {
1432 mctx.PropertyErrorf("vndk",
1433 "must set `enabled: true` to set `support_system_process: true`")
1434 return
1435 }
1436 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001437
Justin Yun71549282017-11-17 12:10:28 +09001438 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001439 // If the device isn't compiling against the VNDK, we always
1440 // use the core mode.
1441 mctx.CreateVariations(coreMode)
1442 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1443 // LL-NDK stubs only exist in the vendor variant, since the
1444 // real libraries will be used in the core variant.
1445 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001446 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1447 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001448 mod := mctx.CreateVariations(vendorMode)
1449 vendor := mod[0].(*Module)
1450 vendor.Properties.UseVndk = true
Justin Yun71549282017-11-17 12:10:28 +09001451 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
1452 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1453 // PRODUCT_EXTRA_VNDK_VERSIONS.
1454 mod := mctx.CreateVariations(vendorMode)
1455 vendor := mod[0].(*Module)
1456 vendor.Properties.UseVndk = true
Jiyong Park82e2bf32017-08-16 14:05:54 +09001457 } else if m.hasVendorVariant() {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001458 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001459 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001460 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001461 vendor := mod[1].(*Module)
1462 vendor.Properties.UseVndk = true
1463 squashVendorSrcs(vendor)
Jiyong Park2db76922017-11-08 16:03:48 +09001464 } else if (mctx.SocSpecific() || mctx.DeviceSpecific()) && String(m.Properties.Sdk_version) == "" {
1465 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001466 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001467 vendor := mod[0].(*Module)
1468 vendor.Properties.UseVndk = true
1469 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001470 } else {
1471 // This is either in /system (or similar: /data), or is a
1472 // modules built with the NDK. Modules built with the NDK
1473 // will be restricted using the existing link type checks.
1474 mctx.CreateVariations(coreMode)
1475 }
1476}
1477
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001478func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001479 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001480 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1481 }
Colin Cross6510f912017-11-29 00:27:14 -08001482 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001483}
1484
Colin Cross06a931b2015-10-28 17:23:31 -07001485var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001486var BoolPtr = proptools.BoolPtr
1487var String = proptools.String
1488var StringPtr = proptools.StringPtr