blob: 9cc7dfa38bbe8823512507821a40b56f42abde4e [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
Logan Chienf3511742017-10-31 18:04:35 +0800208 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800209 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700210 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700211 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800212 getVndkExtendsModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800213}
214
215type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700216 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800217 ModuleContextIntf
218}
219
220type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700221 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800222 ModuleContextIntf
223}
224
Colin Cross37047f12016-12-13 17:06:13 -0800225type DepsContext interface {
226 android.BottomUpMutatorContext
227 ModuleContextIntf
228}
229
Colin Crossca860ac2016-01-04 14:34:37 -0800230type feature interface {
231 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800232 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800233 flags(ctx ModuleContext, flags Flags) Flags
234 props() []interface{}
235}
236
237type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700238 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800239 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800240 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700241 compilerProps() []interface{}
242
Colin Cross76fada02016-07-27 10:31:13 -0700243 appendCflags([]string)
244 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700245 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800246}
247
248type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700249 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800250 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700251 linkerFlags(ctx ModuleContext, flags Flags) Flags
252 linkerProps() []interface{}
253
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700254 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700255 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800256}
257
258type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700259 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700260 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800261 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700262 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700263 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800264}
265
Colin Crossc99deeb2016-04-11 15:06:20 -0700266type dependencyTag struct {
267 blueprint.BaseDependencyTag
268 name string
269 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700270
271 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700272}
273
274var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700275 sharedDepTag = dependencyTag{name: "shared", library: true}
276 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
277 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
278 staticDepTag = dependencyTag{name: "static", library: true}
279 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
280 lateStaticDepTag = dependencyTag{name: "late static", library: true}
281 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800282 headerDepTag = dependencyTag{name: "header", library: true}
283 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700284 genSourceDepTag = dependencyTag{name: "gen source"}
285 genHeaderDepTag = dependencyTag{name: "gen header"}
286 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
287 objDepTag = dependencyTag{name: "obj"}
288 crtBeginDepTag = dependencyTag{name: "crtbegin"}
289 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700290 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700291 reuseObjTag = dependencyTag{name: "reuse objects"}
292 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
293 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800294 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700295)
296
Colin Crossca860ac2016-01-04 14:34:37 -0800297// Module contains the properties and members used by all C/C++ module types, and implements
298// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
299// to construct the output file. Behavior can be customized with a Customizer interface
300type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700301 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700302 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700303
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700304 Properties BaseProperties
305 VendorProperties VendorProperties
306 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700307
Colin Crossca860ac2016-01-04 14:34:37 -0800308 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700309 hod android.HostOrDeviceSupported
310 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700311
Colin Crossca860ac2016-01-04 14:34:37 -0800312 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700313 features []feature
314 compiler compiler
315 linker linker
316 installer installer
317 stl *stl
318 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800319 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800320 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900321 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700322 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700323 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800324
325 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700326
Colin Cross635c3b02016-05-18 15:37:25 -0700327 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800328
Colin Crossb98c8b02016-07-29 13:44:28 -0700329 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700330
331 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800332
333 // Flags used to compile this module
334 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700335
336 // 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 -0800337 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700338 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800339 depsInLinkOrder android.Paths
340
341 // only non-nil when this is a shared library that reuses the objects of a static library
342 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700343}
344
Colin Cross36242852017-06-23 15:06:31 -0700345func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700346 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800347 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700348 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800349 }
350 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700351 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800352 }
353 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700354 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800355 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700356 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700357 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700358 }
Colin Cross16b23492016-01-06 14:41:07 -0800359 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700360 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800361 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800362 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700363 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800364 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800365 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700366 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800367 }
Justin Yun8effde42017-06-23 19:24:43 +0900368 if c.vndkdep != nil {
369 c.AddProperties(c.vndkdep.props()...)
370 }
Stephen Craneba090d12017-05-09 15:44:35 -0700371 if c.lto != nil {
372 c.AddProperties(c.lto.props()...)
373 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700374 if c.pgo != nil {
375 c.AddProperties(c.pgo.props()...)
376 }
Colin Crossca860ac2016-01-04 14:34:37 -0800377 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700378 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800379 }
Colin Crossc472d572015-03-17 15:06:21 -0700380
Colin Cross36242852017-06-23 15:06:31 -0700381 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700382
Colin Cross1f44a3a2017-07-07 14:33:33 -0700383 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700384
385 return c
Colin Crossc472d572015-03-17 15:06:21 -0700386}
387
Colin Crossb916a382016-07-29 17:28:03 -0700388// Returns true for dependency roots (binaries)
389// TODO(ccross): also handle dlopenable libraries
390func (c *Module) isDependencyRoot() bool {
391 if root, ok := c.linker.(interface {
392 isDependencyRoot() bool
393 }); ok {
394 return root.isDependencyRoot()
395 }
396 return false
397}
398
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700399func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700400 return c.Properties.UseVndk
401}
402
Justin Yun8effde42017-06-23 19:24:43 +0900403func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800404 if vndkdep := c.vndkdep; vndkdep != nil {
405 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900406 }
407 return false
408}
409
Logan Chienf3511742017-10-31 18:04:35 +0800410func (c *Module) isVndkSp() bool {
411 if vndkdep := c.vndkdep; vndkdep != nil {
412 return vndkdep.isVndkSp()
413 }
414 return false
415}
416
417func (c *Module) isVndkExt() bool {
418 if vndkdep := c.vndkdep; vndkdep != nil {
419 return vndkdep.isVndkExt()
420 }
421 return false
422}
423
424func (c *Module) getVndkExtendsModuleName() string {
425 if vndkdep := c.vndkdep; vndkdep != nil {
426 return vndkdep.getVndkExtendsModuleName()
427 }
428 return ""
429}
430
Jiyong Park82e2bf32017-08-16 14:05:54 +0900431// Returns true only when this module is configured to have core and vendor
432// variants.
433func (c *Module) hasVendorVariant() bool {
434 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
435}
436
Colin Crossca860ac2016-01-04 14:34:37 -0800437type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700438 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800439 moduleContextImpl
440}
441
Colin Cross37047f12016-12-13 17:06:13 -0800442type depsContext struct {
443 android.BottomUpMutatorContext
444 moduleContextImpl
445}
446
Colin Crossca860ac2016-01-04 14:34:37 -0800447type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700448 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800449 moduleContextImpl
450}
451
Jiyong Park2db76922017-11-08 16:03:48 +0900452func (ctx *moduleContext) SocSpecific() bool {
453 return ctx.ModuleContext.SocSpecific() ||
454 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700455}
456
Colin Crossca860ac2016-01-04 14:34:37 -0800457type moduleContextImpl struct {
458 mod *Module
459 ctx BaseModuleContext
460}
461
Colin Crossca860ac2016-01-04 14:34:37 -0800462func (ctx *moduleContextImpl) clang() bool {
463 return ctx.mod.clang(ctx.ctx)
464}
465
Colin Crossb98c8b02016-07-29 13:44:28 -0700466func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800467 return ctx.mod.toolchain(ctx.ctx)
468}
469
470func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000471 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800472}
473
474func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700475 if static, ok := ctx.mod.linker.(interface {
476 staticBinary() bool
477 }); ok {
478 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800479 }
Colin Crossb916a382016-07-29 17:28:03 -0700480 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800481}
482
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700483func (ctx *moduleContextImpl) useSdk() bool {
484 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800485 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700486 }
487 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800488}
489
490func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700491 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700492 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700493 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800494 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800495 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800496 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700497 }
498 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800499}
500
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700501func (ctx *moduleContextImpl) useVndk() bool {
502 return ctx.mod.useVndk()
503}
Justin Yun8effde42017-06-23 19:24:43 +0900504
Logan Chienf3511742017-10-31 18:04:35 +0800505func (ctx *moduleContextImpl) isVndk() bool {
506 return ctx.mod.isVndk()
507}
508
Justin Yun8effde42017-06-23 19:24:43 +0900509func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800510 return ctx.mod.isVndkSp()
511}
512
513func (ctx *moduleContextImpl) isVndkExt() bool {
514 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900515}
516
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800517// Create source abi dumps if the module belongs to the list of VndkLibraries.
518func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700519 return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800520}
521
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700522func (ctx *moduleContextImpl) selectedStl() string {
523 if stl := ctx.mod.stl; stl != nil {
524 return stl.Properties.SelectedStl
525 }
526 return ""
527}
528
Colin Crossce75d2c2016-10-06 16:12:58 -0700529func (ctx *moduleContextImpl) baseModuleName() string {
530 return ctx.mod.ModuleBase.BaseModuleName()
531}
532
Logan Chienf3511742017-10-31 18:04:35 +0800533func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
534 return ctx.mod.getVndkExtendsModuleName()
535}
536
Colin Cross635c3b02016-05-18 15:37:25 -0700537func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800538 return &Module{
539 hod: hod,
540 multilib: multilib,
541 }
542}
543
Colin Cross635c3b02016-05-18 15:37:25 -0700544func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800545 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700546 module.features = []feature{
547 &tidyFeature{},
548 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700549 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800550 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800551 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800552 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900553 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700554 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700555 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800556 return module
557}
558
Colin Crossce75d2c2016-10-06 16:12:58 -0700559func (c *Module) Prebuilt() *android.Prebuilt {
560 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
561 return p.prebuilt()
562 }
563 return nil
564}
565
566func (c *Module) Name() string {
567 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700568 if p, ok := c.linker.(interface {
569 Name(string) string
570 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700571 name = p.Name(name)
572 }
573 return name
574}
575
Jeff Gaston294356f2017-09-27 17:05:30 -0700576// orderDeps reorders dependencies into a list such that if module A depends on B, then
577// A will precede B in the resultant list.
578// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800579// Note that directSharedDeps should be the analogous static library for each shared lib dep
580func 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 -0700581 // If A depends on B, then
582 // Every list containing A will also contain B later in the list
583 // So, after concatenating all lists, the final instance of B will have come from the same
584 // original list as the final instance of A
585 // So, the final instance of B will be later in the concatenation than the final A
586 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
587 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800588 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700589 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800590 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
591 }
592 for _, dep := range directSharedDeps {
593 orderedAllDeps = append(orderedAllDeps, dep)
594 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700595 }
596
Colin Crossb6715442017-10-24 11:13:31 -0700597 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700598
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800599 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700600 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800601 // resultant list to only what the caller has chosen to include in directStaticDeps
602 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700603
604 return orderedAllDeps, orderedDeclaredDeps
605}
606
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800607func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
608 // convert Module to Path
609 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
610 staticDepFiles := []android.Path{}
611 for _, dep := range staticDeps {
612 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
613 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700614 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800615 sharedDepFiles := []android.Path{}
616 for _, sharedDep := range sharedDeps {
617 staticAnalogue := sharedDep.staticVariant
618 if staticAnalogue != nil {
619 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
620 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
621 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700622 }
623
624 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800625 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700626
627 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700628}
629
Colin Cross635c3b02016-05-18 15:37:25 -0700630func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700631
Colin Crossca860ac2016-01-04 14:34:37 -0800632 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700633 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800634 moduleContextImpl: moduleContextImpl{
635 mod: c,
636 },
637 }
638 ctx.ctx = ctx
639
Colin Crossf18e1102017-11-16 14:33:08 -0800640 deps := c.depsToPaths(ctx)
641 if ctx.Failed() {
642 return
643 }
644
Colin Crossca860ac2016-01-04 14:34:37 -0800645 flags := Flags{
646 Toolchain: c.toolchain(ctx),
647 Clang: c.clang(ctx),
648 }
Colin Crossca860ac2016-01-04 14:34:37 -0800649 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800650 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800651 }
652 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700653 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800654 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700655 if c.stl != nil {
656 flags = c.stl.flags(ctx, flags)
657 }
Colin Cross16b23492016-01-06 14:41:07 -0800658 if c.sanitize != nil {
659 flags = c.sanitize.flags(ctx, flags)
660 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800661 if c.coverage != nil {
662 flags = c.coverage.flags(ctx, flags)
663 }
Stephen Craneba090d12017-05-09 15:44:35 -0700664 if c.lto != nil {
665 flags = c.lto.flags(ctx, flags)
666 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700667 if c.pgo != nil {
668 flags = c.pgo.flags(ctx, flags)
669 }
Colin Crossca860ac2016-01-04 14:34:37 -0800670 for _, feature := range c.features {
671 flags = feature.flags(ctx, flags)
672 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800673 if ctx.Failed() {
674 return
675 }
676
Colin Crossb98c8b02016-07-29 13:44:28 -0700677 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
678 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
679 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800680
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800681 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
682 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700683 // We need access to all the flags seen by a source file.
684 if c.sabi != nil {
685 flags = c.sabi.flags(ctx, flags)
686 }
Colin Crossca860ac2016-01-04 14:34:37 -0800687 // Optimization to reduce size of build.ninja
688 // Replace the long list of flags for each file with a module-local variable
689 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
690 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
691 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
692 flags.CFlags = []string{"$cflags"}
693 flags.CppFlags = []string{"$cppflags"}
694 flags.AsFlags = []string{"$asflags"}
695
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700696 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800697 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700698 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800699 if ctx.Failed() {
700 return
701 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800702 }
703
Colin Crossca860ac2016-01-04 14:34:37 -0800704 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700705 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800706 if ctx.Failed() {
707 return
708 }
Colin Cross635c3b02016-05-18 15:37:25 -0700709 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700710 }
Colin Cross5049f022015-03-18 13:28:46 -0700711
Colin Crossce75d2c2016-10-06 16:12:58 -0700712 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
713 c.installer.install(ctx, c.outputFile.Path())
714 if ctx.Failed() {
715 return
Colin Crossca860ac2016-01-04 14:34:37 -0800716 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700717 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800718}
719
Colin Crossb98c8b02016-07-29 13:44:28 -0700720func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800721 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700722 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800723 }
Colin Crossca860ac2016-01-04 14:34:37 -0800724 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800725}
726
Colin Crossca860ac2016-01-04 14:34:37 -0800727func (c *Module) begin(ctx BaseModuleContext) {
728 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700729 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700730 }
Colin Crossca860ac2016-01-04 14:34:37 -0800731 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700732 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800733 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700734 if c.stl != nil {
735 c.stl.begin(ctx)
736 }
Colin Cross16b23492016-01-06 14:41:07 -0800737 if c.sanitize != nil {
738 c.sanitize.begin(ctx)
739 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800740 if c.coverage != nil {
741 c.coverage.begin(ctx)
742 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800743 if c.sabi != nil {
744 c.sabi.begin(ctx)
745 }
Justin Yun8effde42017-06-23 19:24:43 +0900746 if c.vndkdep != nil {
747 c.vndkdep.begin(ctx)
748 }
Stephen Craneba090d12017-05-09 15:44:35 -0700749 if c.lto != nil {
750 c.lto.begin(ctx)
751 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700752 if c.pgo != nil {
753 c.pgo.begin(ctx)
754 }
Colin Crossca860ac2016-01-04 14:34:37 -0800755 for _, feature := range c.features {
756 feature.begin(ctx)
757 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700758 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700759 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700760 if err != nil {
761 ctx.PropertyErrorf("sdk_version", err.Error())
762 }
Nan Zhang0007d812017-11-07 10:57:05 -0800763 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700764 }
Colin Crossca860ac2016-01-04 14:34:37 -0800765}
766
Colin Cross37047f12016-12-13 17:06:13 -0800767func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700768 deps := Deps{}
769
770 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700771 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700772 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700773 // Add the PGO dependency (the clang_rt.profile runtime library), which
774 // sometimes depends on symbols from libgcc, before libgcc gets added
775 // in linkerDeps().
776 if c.pgo != nil {
777 deps = c.pgo.deps(ctx, deps)
778 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700779 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700780 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700781 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700782 if c.stl != nil {
783 deps = c.stl.deps(ctx, deps)
784 }
Colin Cross16b23492016-01-06 14:41:07 -0800785 if c.sanitize != nil {
786 deps = c.sanitize.deps(ctx, deps)
787 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800788 if c.coverage != nil {
789 deps = c.coverage.deps(ctx, deps)
790 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800791 if c.sabi != nil {
792 deps = c.sabi.deps(ctx, deps)
793 }
Justin Yun8effde42017-06-23 19:24:43 +0900794 if c.vndkdep != nil {
795 deps = c.vndkdep.deps(ctx, deps)
796 }
Stephen Craneba090d12017-05-09 15:44:35 -0700797 if c.lto != nil {
798 deps = c.lto.deps(ctx, deps)
799 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700800 for _, feature := range c.features {
801 deps = feature.deps(ctx, deps)
802 }
803
Colin Crossb6715442017-10-24 11:13:31 -0700804 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
805 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
806 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
807 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
808 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
809 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700810
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700811 for _, lib := range deps.ReexportSharedLibHeaders {
812 if !inList(lib, deps.SharedLibs) {
813 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
814 }
815 }
816
817 for _, lib := range deps.ReexportStaticLibHeaders {
818 if !inList(lib, deps.StaticLibs) {
819 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
820 }
821 }
822
Colin Cross5950f382016-12-13 12:50:57 -0800823 for _, lib := range deps.ReexportHeaderLibHeaders {
824 if !inList(lib, deps.HeaderLibs) {
825 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
826 }
827 }
828
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700829 for _, gen := range deps.ReexportGeneratedHeaders {
830 if !inList(gen, deps.GeneratedHeaders) {
831 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
832 }
833 }
834
Colin Crossc99deeb2016-04-11 15:06:20 -0700835 return deps
836}
837
Dan Albert7e9d2952016-08-04 13:02:36 -0700838func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800839 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700840 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800841 moduleContextImpl: moduleContextImpl{
842 mod: c,
843 },
844 }
845 ctx.ctx = ctx
846
Colin Crossca860ac2016-01-04 14:34:37 -0800847 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700848}
849
Colin Cross1e676be2016-10-12 14:38:15 -0700850func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
851 if !c.Enabled() {
852 return
853 }
854
Colin Cross37047f12016-12-13 17:06:13 -0800855 ctx := &depsContext{
856 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700857 moduleContextImpl: moduleContextImpl{
858 mod: c,
859 },
860 }
861 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800862
Colin Crossc99deeb2016-04-11 15:06:20 -0700863 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800864
Dan Albert914449f2016-06-17 16:45:24 -0700865 variantNdkLibs := []string{}
866 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700867 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700868 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700869
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700870 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
871 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700872 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700873 // 1. Name of an NDK library that refers to a prebuilt module.
874 // For each of these, it adds the name of the prebuilt module (which will be in
875 // prebuilts/ndk) to the list of nonvariant libs.
876 // 2. Name of an NDK library that refers to an ndk_library module.
877 // For each of these, it adds the name of the ndk_library module to the list of
878 // variant libs.
879 // 3. Anything else (so anything that isn't an NDK library).
880 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700881 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700882 // The caller can then know to add the variantLibs dependencies differently from the
883 // nonvariantLibs
884 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
885 variantLibs = []string{}
886 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700887 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700888 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700889 if !inList(entry, ndkMigratedLibs) {
890 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
891 } else {
892 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
893 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700894 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700895 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700896 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700897 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700898 }
899 }
Dan Albert914449f2016-06-17 16:45:24 -0700900 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700901 }
902
Dan Albert914449f2016-06-17 16:45:24 -0700903 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
904 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900905 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700906 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700907
Colin Cross32ec36c2016-12-15 07:39:51 -0800908 for _, lib := range deps.HeaderLibs {
909 depTag := headerDepTag
910 if inList(lib, deps.ReexportHeaderLibHeaders) {
911 depTag = headerExportDepTag
912 }
913 actx.AddVariationDependencies(nil, depTag, lib)
914 }
Colin Cross5950f382016-12-13 12:50:57 -0800915
Colin Crossc99deeb2016-04-11 15:06:20 -0700916 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
917 deps.WholeStaticLibs...)
918
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700919 for _, lib := range deps.StaticLibs {
920 depTag := staticDepTag
921 if inList(lib, deps.ReexportStaticLibHeaders) {
922 depTag = staticExportDepTag
923 }
Colin Cross15a0d462016-07-14 14:49:58 -0700924 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700925 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700926
927 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
928 deps.LateStaticLibs...)
929
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700930 for _, lib := range deps.SharedLibs {
931 depTag := sharedDepTag
932 if inList(lib, deps.ReexportSharedLibHeaders) {
933 depTag = sharedExportDepTag
934 }
Colin Cross15a0d462016-07-14 14:49:58 -0700935 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700936 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700937
938 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
939 deps.LateSharedLibs...)
940
Colin Cross68861832016-07-08 10:41:41 -0700941 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700942
943 for _, gen := range deps.GeneratedHeaders {
944 depTag := genHeaderDepTag
945 if inList(gen, deps.ReexportGeneratedHeaders) {
946 depTag = genHeaderExportDepTag
947 }
948 actx.AddDependency(c, depTag, gen)
949 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700950
Colin Cross68861832016-07-08 10:41:41 -0700951 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700952
953 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700954 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800955 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700956 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700957 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700958 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700959 if deps.LinkerScript != "" {
960 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
961 }
Dan Albert914449f2016-06-17 16:45:24 -0700962
963 version := ctx.sdkVersion()
964 actx.AddVariationDependencies([]blueprint.Variation{
965 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
966 actx.AddVariationDependencies([]blueprint.Variation{
967 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +0800968
969 if vndkdep := c.vndkdep; vndkdep != nil {
970 if vndkdep.isVndkExt() {
971 baseModuleMode := vendorMode
972 if actx.DeviceConfig().VndkVersion() == "" {
973 baseModuleMode = coreMode
974 }
975 actx.AddVariationDependencies([]blueprint.Variation{
976 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
977 vndkdep.getVndkExtendsModuleName())
978 }
979 }
Colin Cross6362e272015-10-29 15:25:03 -0700980}
Colin Cross21b9a242015-03-24 14:15:58 -0700981
Dan Albert7e9d2952016-08-04 13:02:36 -0700982func beginMutator(ctx android.BottomUpMutatorContext) {
983 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
984 c.beginMutator(ctx)
985 }
986}
987
Colin Crossca860ac2016-01-04 14:34:37 -0800988func (c *Module) clang(ctx BaseModuleContext) bool {
989 clang := Bool(c.Properties.Clang)
990
991 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -0800992 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -0800993 }
Colin Cross28344522015-04-22 13:07:53 -0700994
Colin Crossca860ac2016-01-04 14:34:37 -0800995 if !c.toolchain(ctx).ClangSupported() {
996 clang = false
997 }
998
999 return clang
1000}
1001
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001002// Whether a module can link to another module, taking into
1003// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001004func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001005 if from.Target().Os != android.Android {
1006 // Host code is not restricted
1007 return
1008 }
1009 if from.Properties.UseVndk {
1010 // Though vendor code is limited by the vendor mutator,
1011 // each vendor-available module needs to check
1012 // link-type for VNDK.
1013 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001014 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001015 }
1016 return
1017 }
Nan Zhang0007d812017-11-07 10:57:05 -08001018 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001019 // Platform code can link to anything
1020 return
1021 }
1022 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1023 // These are always allowed
1024 return
1025 }
1026 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
1027 // These are allowed, but they don't set sdk_version
1028 return
1029 }
1030 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1031 // These are allowed, but they don't set sdk_version
1032 return
1033 }
1034 if _, ok := to.linker.(*stubDecorator); ok {
1035 // These aren't real libraries, but are the stub shared libraries that are included in
1036 // the NDK.
1037 return
1038 }
Nan Zhang0007d812017-11-07 10:57:05 -08001039 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001040 // NDK code linking to platform code is never okay.
1041 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1042 ctx.OtherModuleName(to))
1043 }
1044
1045 // At this point we know we have two NDK libraries, but we need to
1046 // check that we're not linking against anything built against a higher
1047 // API level, as it is only valid to link against older or equivalent
1048 // APIs.
1049
Nan Zhang0007d812017-11-07 10:57:05 -08001050 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001051 // Current can link against anything.
1052 return
Nan Zhang0007d812017-11-07 10:57:05 -08001053 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001054 // Current can't be linked against by anything else.
1055 ctx.ModuleErrorf("links %q built against newer API version %q",
1056 ctx.OtherModuleName(to), "current")
1057 }
1058
Nan Zhang0007d812017-11-07 10:57:05 -08001059 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001060 if err != nil {
1061 ctx.PropertyErrorf("sdk_version",
1062 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001063 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001064 }
Nan Zhang0007d812017-11-07 10:57:05 -08001065 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001066 if err != nil {
1067 ctx.PropertyErrorf("sdk_version",
1068 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001069 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001070 }
1071
1072 if toApi > fromApi {
1073 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001074 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001075 }
Dan Albert202fe492017-12-15 13:56:59 -08001076
1077 // Also check that the two STL choices are compatible.
1078 fromStl := from.stl.Properties.SelectedStl
1079 toStl := to.stl.Properties.SelectedStl
1080 if fromStl == "" || toStl == "" {
1081 // Libraries that don't use the STL are unrestricted.
1082 return
1083 }
1084
1085 if fromStl == "ndk_system" || toStl == "ndk_system" {
1086 // We can be permissive with the system "STL" since it is only the C++
1087 // ABI layer, but in the future we should make sure that everyone is
1088 // using either libc++ or nothing.
1089 return
1090 }
1091
1092 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1093 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1094 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1095 to.stl.Properties.SelectedStl)
1096 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001097}
1098
Colin Crossc99deeb2016-04-11 15:06:20 -07001099// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001100func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001101 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001102
Jeff Gaston294356f2017-09-27 17:05:30 -07001103 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001104 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001105
Colin Crossd11fcda2017-10-23 17:59:01 -07001106 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001107 depName := ctx.OtherModuleName(dep)
1108 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001109
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001110 ccDep, _ := dep.(*Module)
1111 if ccDep == nil {
1112 // handling for a few module types that aren't cc Module but that are also supported
1113 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001114 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001115 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001116 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001117 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001118 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1119 genRule.GeneratedSourceFiles()...)
1120 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001121 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001122 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001123 // Support exported headers from a generated_sources dependency
1124 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001125 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001126 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001127 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
1128 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001129 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001130 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001131 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001132 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001133 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
1134 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001135 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1136 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1137
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001138 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001139 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001140 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001141 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001142 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001143 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001144 files := genRule.GeneratedSourceFiles()
1145 if len(files) == 1 {
1146 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1147 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001148 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001149 }
1150 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001151 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001152 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001153 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001154 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001155 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001156 return
1157 }
1158
Colin Crossd11fcda2017-10-23 17:59:01 -07001159 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001160 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1161 return
1162 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001163 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001164 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001165 return
1166 }
1167
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001168 // re-exporting flags
1169 if depTag == reuseObjTag {
1170 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001171 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001172 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001173 depPaths.Objs = depPaths.Objs.Append(objs)
1174 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001175 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001176 return
1177 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001178 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001179 if t, ok := depTag.(dependencyTag); ok && t.library {
1180 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001181 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001182 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001183 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001184 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001185
1186 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001187 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001188 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001189 // 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 -07001190 // Re-exported shared library headers must be included as well since they can help us with type information
1191 // about template instantiations (instantiated from their headers).
1192 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001193 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001194 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001195
Logan Chienf3511742017-10-31 18:04:35 +08001196 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001197 }
1198
Colin Cross26c34ed2016-09-30 17:10:16 -07001199 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001200 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001201
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001202 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001203 depFile := android.OptionalPath{}
1204
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001205 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001206 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001207 ptr = &depPaths.SharedLibs
1208 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001209 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001210 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001211 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001212 ptr = &depPaths.LateSharedLibs
1213 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001214 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001215 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001216 ptr = nil
1217 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001218 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001219 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001220 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001221 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001222 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001223 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001224 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001225 return
1226 }
1227
1228 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001229 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001230 for i := range missingDeps {
1231 missingDeps[i] += postfix
1232 }
1233 ctx.AddMissingDependencies(missingDeps)
1234 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001235 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001236 case headerDepTag:
1237 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001238 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001239 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001240 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001241 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001242 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001243 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001244 }
1245
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001246 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001247 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001248 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001249 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001250 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001251 return
1252 }
1253
1254 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001255 // in static libraries act as if they were whole static libraries. The same goes for
1256 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001257 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1258 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001259 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1260 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001261
Dan Willemsen581341d2017-02-09 16:16:31 -08001262 }
1263
Colin Cross26c34ed2016-09-30 17:10:16 -07001264 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001265 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001266 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001267 return
1268 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001269 *ptr = append(*ptr, linkFile.Path())
1270 }
1271
Colin Crossc99deeb2016-04-11 15:06:20 -07001272 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001273 dep := depFile
1274 if !dep.Valid() {
1275 dep = linkFile
1276 }
1277 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001278 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001279
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001280 // Export the shared libs to Make.
1281 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001282 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001283 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001284 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001285 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001286 var makeLibName string
1287 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1288 if c.useVndk() && bothVendorAndCoreVariantsExist {
1289 // The vendor module in Make will have been renamed to not conflict with the core
1290 // module, so update the dependency name here accordingly.
1291 makeLibName = libName + vendorSuffix
1292 } else {
1293 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001294 }
1295 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001296 // they merely serve as Make dependencies and do not affect this lib itself.
1297 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001298 }
Colin Crossca860ac2016-01-04 14:34:37 -08001299 })
1300
Jeff Gaston294356f2017-09-27 17:05:30 -07001301 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001302 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001303
Colin Crossdd84e052017-05-17 13:44:16 -07001304 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001305 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001306 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001307 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001308 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1309
1310 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001311 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001312 }
Colin Crossdd84e052017-05-17 13:44:16 -07001313
Colin Crossca860ac2016-01-04 14:34:37 -08001314 return depPaths
1315}
1316
1317func (c *Module) InstallInData() bool {
1318 if c.installer == nil {
1319 return false
1320 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001321 return c.installer.inData()
1322}
1323
1324func (c *Module) InstallInSanitizerDir() bool {
1325 if c.installer == nil {
1326 return false
1327 }
1328 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001329 return true
1330 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001331 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001332}
1333
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001334func (c *Module) HostToolPath() android.OptionalPath {
1335 if c.installer == nil {
1336 return android.OptionalPath{}
1337 }
1338 return c.installer.hostToolPath()
1339}
1340
Nan Zhangd4e641b2017-07-12 12:55:28 -07001341func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1342 return c.outputFile
1343}
1344
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001345func (c *Module) Srcs() android.Paths {
1346 if c.outputFile.Valid() {
1347 return android.Paths{c.outputFile.Path()}
1348 }
1349 return android.Paths{}
1350}
1351
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001352func (c *Module) static() bool {
1353 if static, ok := c.linker.(interface {
1354 static() bool
1355 }); ok {
1356 return static.static()
1357 }
1358 return false
1359}
1360
Colin Cross2ba19d92015-05-07 15:44:20 -07001361//
Colin Crosscfad1192015-11-02 16:43:11 -08001362// Defaults
1363//
Colin Crossca860ac2016-01-04 14:34:37 -08001364type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001365 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001366 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001367}
1368
Colin Cross635c3b02016-05-18 15:37:25 -07001369func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001370}
1371
Colin Cross1e676be2016-10-12 14:38:15 -07001372func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1373}
1374
Colin Cross36242852017-06-23 15:06:31 -07001375func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001376 return DefaultsFactory()
1377}
1378
Colin Cross36242852017-06-23 15:06:31 -07001379func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001380 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001381
Colin Cross36242852017-06-23 15:06:31 -07001382 module.AddProperties(props...)
1383 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001384 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001385 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001386 &BaseCompilerProperties{},
1387 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001388 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001389 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001390 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001391 &TestProperties{},
1392 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001393 &UnusedProperties{},
1394 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001395 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001396 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001397 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001398 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001399 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001400 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001401 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001402 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001403 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001404 )
Colin Crosscfad1192015-11-02 16:43:11 -08001405
Colin Cross1f44a3a2017-07-07 14:33:33 -07001406 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001407
1408 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001409}
1410
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001411const (
1412 // coreMode is the variant used for framework-private libraries, or
1413 // SDK libraries. (which framework-private libraries can use)
1414 coreMode = "core"
1415
1416 // vendorMode is the variant used for /vendor code that compiles
1417 // against the VNDK.
1418 vendorMode = "vendor"
1419)
1420
Jiyong Park6a43f042017-10-12 23:05:00 +09001421func squashVendorSrcs(m *Module) {
1422 if lib, ok := m.compiler.(*libraryDecorator); ok {
1423 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1424 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1425
1426 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1427 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1428 }
1429}
1430
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001431func vendorMutator(mctx android.BottomUpMutatorContext) {
1432 if mctx.Os() != android.Android {
1433 return
1434 }
1435
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001436 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1437 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001438 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001439 mctx.CreateVariations(coreMode)
1440 } else if Bool(props.Vendor_available) {
1441 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001442 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001443 mctx.CreateVariations(vendorMode)
1444 } else {
1445 mctx.CreateVariations(coreMode)
1446 }
1447 }
1448 }
1449
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001450 m, ok := mctx.Module().(*Module)
1451 if !ok {
1452 return
1453 }
1454
1455 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001456 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1457
1458 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001459 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001460 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001461 return
1462 }
Logan Chienf3511742017-10-31 18:04:35 +08001463
1464 if vndkdep := m.vndkdep; vndkdep != nil {
1465 if vndkdep.isVndk() {
1466 if vendorSpecific {
1467 if !vndkdep.isVndkExt() {
1468 mctx.PropertyErrorf("vndk",
1469 "must set `extends: \"...\"` to vndk extension")
1470 return
1471 }
1472 } else {
1473 if vndkdep.isVndkExt() {
1474 mctx.PropertyErrorf("vndk",
1475 "must set `vendor: true` to set `extends: %q`",
1476 m.getVndkExtendsModuleName())
1477 return
1478 }
1479 if m.VendorProperties.Vendor_available == nil {
1480 mctx.PropertyErrorf("vndk",
1481 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1482 return
1483 }
1484 }
1485 } else {
1486 if vndkdep.isVndkSp() {
1487 mctx.PropertyErrorf("vndk",
1488 "must set `enabled: true` to set `support_system_process: true`")
1489 return
1490 }
1491 if vndkdep.isVndkExt() {
1492 mctx.PropertyErrorf("vndk",
1493 "must set `enabled: true` to set `extends: %q`",
1494 m.getVndkExtendsModuleName())
1495 return
1496 }
Justin Yun8effde42017-06-23 19:24:43 +09001497 }
1498 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001499
Justin Yun71549282017-11-17 12:10:28 +09001500 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001501 // If the device isn't compiling against the VNDK, we always
1502 // use the core mode.
1503 mctx.CreateVariations(coreMode)
1504 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1505 // LL-NDK stubs only exist in the vendor variant, since the
1506 // real libraries will be used in the core variant.
1507 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001508 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1509 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001510 mod := mctx.CreateVariations(vendorMode)
1511 vendor := mod[0].(*Module)
1512 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001513 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001514 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1515 // PRODUCT_EXTRA_VNDK_VERSIONS.
1516 mod := mctx.CreateVariations(vendorMode)
1517 vendor := mod[0].(*Module)
1518 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001519 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001520 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001521 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001522 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001523 vendor := mod[1].(*Module)
1524 vendor.Properties.UseVndk = true
1525 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001526 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001527 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001528 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001529 vendor := mod[0].(*Module)
1530 vendor.Properties.UseVndk = true
1531 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001532 } else {
1533 // This is either in /system (or similar: /data), or is a
1534 // modules built with the NDK. Modules built with the NDK
1535 // will be restricted using the existing link type checks.
1536 mctx.CreateVariations(coreMode)
1537 }
1538}
1539
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001540func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001541 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001542 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1543 }
Colin Cross6510f912017-11-29 00:27:14 -08001544 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001545}
1546
Colin Cross06a931b2015-10-28 17:23:31 -07001547var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001548var BoolPtr = proptools.BoolPtr
1549var String = proptools.String
1550var StringPtr = proptools.StringPtr