blob: 4d26e84def0e57fd59ed939762b8fe9637ce561f [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
Ivan Lozano30c5db22018-02-21 15:49:20 -080055 ctx.TopDown("minimal_runtime_deps", minimalRuntimeDepsMutator())
56
Dan Willemsen581341d2017-02-09 16:16:31 -080057 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080058 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070059
60 ctx.TopDown("lto_deps", ltoDepsMutator)
61 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070062 })
Colin Crossb98c8b02016-07-29 13:44:28 -070063
64 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070065}
66
Colin Crossca860ac2016-01-04 14:34:37 -080067type Deps struct {
68 SharedLibs, LateSharedLibs []string
69 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080070 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070071
Colin Cross5950f382016-12-13 12:50:57 -080072 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070073
Colin Cross81413472016-04-11 14:37:39 -070074 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070075
Dan Willemsenb40aab62016-04-20 14:21:14 -070076 GeneratedSources []string
77 GeneratedHeaders []string
78
Dan Willemsenb3454ab2016-09-28 17:34:58 -070079 ReexportGeneratedHeaders []string
80
Colin Cross97ba0732015-03-23 17:50:24 -070081 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070082 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070083}
84
Colin Crossca860ac2016-01-04 14:34:37 -080085type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070086 // Paths to .so files
87 SharedLibs, LateSharedLibs android.Paths
88 // Paths to the dependencies to use for .so files (.so.toc files)
89 SharedLibsDeps, LateSharedLibsDeps android.Paths
90 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070091 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070092
Colin Cross26c34ed2016-09-30 17:10:16 -070093 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070094 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080095 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070096 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070097
Colin Cross26c34ed2016-09-30 17:10:16 -070098 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070099 GeneratedSources android.Paths
100 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700101
Dan Willemsen76f08272016-07-09 00:14:08 -0700102 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700103 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700106 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700107 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108}
109
Colin Crossca860ac2016-01-04 14:34:37 -0800110type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700111 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
112 ArFlags []string // Flags that apply to ar
113 AsFlags []string // Flags that apply to assembly source files
114 CFlags []string // Flags that apply to C and C++ source files
115 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
116 ConlyFlags []string // Flags that apply to C source files
117 CppFlags []string // Flags that apply to C++ source files
118 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
119 YaccFlags []string // Flags that apply to Yacc source files
120 protoFlags []string // Flags that apply to proto source files
Joe Onorato09e94ab2017-11-18 18:23:14 -0800121 protoOutParams []string // Flags that modify the output of proto generated files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700122 aidlFlags []string // Flags that apply to aidl source files
123 rsFlags []string // Flags that apply to renderscript source files
124 LdFlags []string // Flags that apply to linker command lines
125 libFlags []string // Flags to add libraries early to the link order
126 TidyFlags []string // Flags that apply to clang-tidy
127 SAbiFlags []string // Flags that apply to header-abi-dumper
128 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700129
Colin Crossc3199482017-03-30 15:03:04 -0700130 // Global include flags that apply to C, C++, and assembly source files
131 // These must be after any module include flags, which will be in GlobalFlags.
132 SystemIncludeFlags []string
133
Colin Crossb98c8b02016-07-29 13:44:28 -0700134 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700135 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700136 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800137 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800138 SAbiDump bool
Dan Willemsenab9f4262018-02-14 13:58:34 -0800139 ProtoRoot bool
Colin Crossca860ac2016-01-04 14:34:37 -0800140
141 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800142 DynamicLinker string
143
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700144 CFlagsDeps android.Paths // Files depended on by compiler flags
145 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800146
147 GroupStaticLibs bool
Zhizhou Yang51be6322018-02-08 18:32:11 -0800148 ArGoldPlugin bool // Whether LLVM gold plugin option is passed to llvm-ar
Colin Crossc472d572015-03-17 15:06:21 -0700149}
150
Colin Cross81413472016-04-11 14:37:39 -0700151type ObjectLinkerProperties struct {
152 // names of other cc_object modules to link into this module using partial linking
153 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700154
155 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800156 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700157}
158
Colin Crossca860ac2016-01-04 14:34:37 -0800159// Properties used to compile all C or C++ modules
160type BaseProperties struct {
161 // compile module with clang instead of gcc
162 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700163
164 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800165 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700166
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700167 AndroidMkSharedLibs []string `blueprint:"mutated"`
168 HideFromMake bool `blueprint:"mutated"`
169 PreventInstall bool `blueprint:"mutated"`
170
171 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800172
173 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
174 // file
175 Logtags []string
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700176}
177
178type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900179 // whether this module should be allowed to be directly depended by other
180 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
181 // If set to true, two variants will be built separately, one like
182 // normal, and the other limited to the set of libraries and headers
183 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700184 //
185 // The vendor variant may be used with a different (newer) /system,
186 // so it shouldn't have any unversioned runtime dependencies, or
187 // make assumptions about the system that may not be true in the
188 // future.
189 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900190 // If set to false, this module becomes inaccessible from /vendor modules.
191 //
192 // Default value is true when vndk: {enabled: true} or vendor: true.
193 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700194 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
195 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800196}
197
Colin Crossca860ac2016-01-04 14:34:37 -0800198type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800199 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800200}
201
Colin Crossca860ac2016-01-04 14:34:37 -0800202type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800203 static() bool
204 staticBinary() bool
205 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700206 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700207 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800208 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700209 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900210 isVndk() bool
211 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800212 isVndkExt() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800213 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700214 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700215 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800216 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800217 isPgoCompile() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800218}
219
220type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700221 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800222 ModuleContextIntf
223}
224
225type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700226 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800227 ModuleContextIntf
228}
229
Colin Cross37047f12016-12-13 17:06:13 -0800230type DepsContext interface {
231 android.BottomUpMutatorContext
232 ModuleContextIntf
233}
234
Colin Crossca860ac2016-01-04 14:34:37 -0800235type feature interface {
236 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800237 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800238 flags(ctx ModuleContext, flags Flags) Flags
239 props() []interface{}
240}
241
242type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700243 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800244 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800245 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700246 compilerProps() []interface{}
247
Colin Cross76fada02016-07-27 10:31:13 -0700248 appendCflags([]string)
249 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700250 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800251}
252
253type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700254 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800255 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700256 linkerFlags(ctx ModuleContext, flags Flags) Flags
257 linkerProps() []interface{}
258
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700259 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700260 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800261}
262
263type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700264 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700265 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800266 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700267 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700268 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800269}
270
Colin Crossc99deeb2016-04-11 15:06:20 -0700271type dependencyTag struct {
272 blueprint.BaseDependencyTag
273 name string
274 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700275
276 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700277}
278
279var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700280 sharedDepTag = dependencyTag{name: "shared", library: true}
281 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
282 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
283 staticDepTag = dependencyTag{name: "static", library: true}
284 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
285 lateStaticDepTag = dependencyTag{name: "late static", library: true}
286 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800287 headerDepTag = dependencyTag{name: "header", library: true}
288 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700289 genSourceDepTag = dependencyTag{name: "gen source"}
290 genHeaderDepTag = dependencyTag{name: "gen header"}
291 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
292 objDepTag = dependencyTag{name: "obj"}
293 crtBeginDepTag = dependencyTag{name: "crtbegin"}
294 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700295 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700296 reuseObjTag = dependencyTag{name: "reuse objects"}
297 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
298 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800299 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700300)
301
Colin Crossca860ac2016-01-04 14:34:37 -0800302// Module contains the properties and members used by all C/C++ module types, and implements
303// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
304// to construct the output file. Behavior can be customized with a Customizer interface
305type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700306 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700307 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700308
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700309 Properties BaseProperties
310 VendorProperties VendorProperties
311 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700312
Colin Crossca860ac2016-01-04 14:34:37 -0800313 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700314 hod android.HostOrDeviceSupported
315 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700316
Colin Crossca860ac2016-01-04 14:34:37 -0800317 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700318 features []feature
319 compiler compiler
320 linker linker
321 installer installer
322 stl *stl
323 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800324 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800325 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900326 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700327 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700328 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800329
330 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700331
Colin Cross635c3b02016-05-18 15:37:25 -0700332 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800333
Colin Crossb98c8b02016-07-29 13:44:28 -0700334 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700335
336 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800337
338 // Flags used to compile this module
339 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700340
341 // 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 -0800342 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700343 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800344 depsInLinkOrder android.Paths
345
346 // only non-nil when this is a shared library that reuses the objects of a static library
347 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700348}
349
Colin Cross36242852017-06-23 15:06:31 -0700350func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700351 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800352 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700353 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800354 }
355 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700356 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800357 }
358 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700359 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800360 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700361 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700362 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700363 }
Colin Cross16b23492016-01-06 14:41:07 -0800364 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700365 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800366 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800367 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700368 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800369 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800370 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700371 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800372 }
Justin Yun8effde42017-06-23 19:24:43 +0900373 if c.vndkdep != nil {
374 c.AddProperties(c.vndkdep.props()...)
375 }
Stephen Craneba090d12017-05-09 15:44:35 -0700376 if c.lto != nil {
377 c.AddProperties(c.lto.props()...)
378 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700379 if c.pgo != nil {
380 c.AddProperties(c.pgo.props()...)
381 }
Colin Crossca860ac2016-01-04 14:34:37 -0800382 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700383 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800384 }
Colin Crossc472d572015-03-17 15:06:21 -0700385
Colin Cross36242852017-06-23 15:06:31 -0700386 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700387
Colin Cross1f44a3a2017-07-07 14:33:33 -0700388 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700389
390 return c
Colin Crossc472d572015-03-17 15:06:21 -0700391}
392
Colin Crossb916a382016-07-29 17:28:03 -0700393// Returns true for dependency roots (binaries)
394// TODO(ccross): also handle dlopenable libraries
395func (c *Module) isDependencyRoot() bool {
396 if root, ok := c.linker.(interface {
397 isDependencyRoot() bool
398 }); ok {
399 return root.isDependencyRoot()
400 }
401 return false
402}
403
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700404func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700405 return c.Properties.UseVndk
406}
407
Justin Yun8effde42017-06-23 19:24:43 +0900408func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800409 if vndkdep := c.vndkdep; vndkdep != nil {
410 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900411 }
412 return false
413}
414
Yi Kong7e53c572018-02-14 18:16:12 +0800415func (c *Module) isPgoCompile() bool {
416 if pgo := c.pgo; pgo != nil {
417 return pgo.Properties.PgoCompile
418 }
419 return false
420}
421
Logan Chienf3511742017-10-31 18:04:35 +0800422func (c *Module) isVndkSp() bool {
423 if vndkdep := c.vndkdep; vndkdep != nil {
424 return vndkdep.isVndkSp()
425 }
426 return false
427}
428
429func (c *Module) isVndkExt() bool {
430 if vndkdep := c.vndkdep; vndkdep != nil {
431 return vndkdep.isVndkExt()
432 }
433 return false
434}
435
436func (c *Module) getVndkExtendsModuleName() string {
437 if vndkdep := c.vndkdep; vndkdep != nil {
438 return vndkdep.getVndkExtendsModuleName()
439 }
440 return ""
441}
442
Jiyong Park82e2bf32017-08-16 14:05:54 +0900443// Returns true only when this module is configured to have core and vendor
444// variants.
445func (c *Module) hasVendorVariant() bool {
446 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
447}
448
Colin Crossca860ac2016-01-04 14:34:37 -0800449type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700450 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800451 moduleContextImpl
452}
453
Colin Cross37047f12016-12-13 17:06:13 -0800454type depsContext struct {
455 android.BottomUpMutatorContext
456 moduleContextImpl
457}
458
Colin Crossca860ac2016-01-04 14:34:37 -0800459type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700460 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800461 moduleContextImpl
462}
463
Jiyong Park2db76922017-11-08 16:03:48 +0900464func (ctx *moduleContext) SocSpecific() bool {
465 return ctx.ModuleContext.SocSpecific() ||
466 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700467}
468
Colin Crossca860ac2016-01-04 14:34:37 -0800469type moduleContextImpl struct {
470 mod *Module
471 ctx BaseModuleContext
472}
473
Colin Crossca860ac2016-01-04 14:34:37 -0800474func (ctx *moduleContextImpl) clang() bool {
475 return ctx.mod.clang(ctx.ctx)
476}
477
Colin Crossb98c8b02016-07-29 13:44:28 -0700478func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800479 return ctx.mod.toolchain(ctx.ctx)
480}
481
482func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000483 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800484}
485
486func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700487 if static, ok := ctx.mod.linker.(interface {
488 staticBinary() bool
489 }); ok {
490 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800491 }
Colin Crossb916a382016-07-29 17:28:03 -0700492 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800493}
494
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700495func (ctx *moduleContextImpl) useSdk() bool {
496 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800497 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700498 }
499 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800500}
501
502func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700503 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700504 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700505 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800506 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800507 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800508 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700509 }
510 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800511}
512
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700513func (ctx *moduleContextImpl) useVndk() bool {
514 return ctx.mod.useVndk()
515}
Justin Yun8effde42017-06-23 19:24:43 +0900516
Logan Chienf3511742017-10-31 18:04:35 +0800517func (ctx *moduleContextImpl) isVndk() bool {
518 return ctx.mod.isVndk()
519}
520
Yi Kong7e53c572018-02-14 18:16:12 +0800521func (ctx *moduleContextImpl) isPgoCompile() bool {
522 return ctx.mod.isPgoCompile()
523}
524
Justin Yun8effde42017-06-23 19:24:43 +0900525func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800526 return ctx.mod.isVndkSp()
527}
528
529func (ctx *moduleContextImpl) isVndkExt() bool {
530 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900531}
532
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800533// Create source abi dumps if the module belongs to the list of VndkLibraries.
534func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800535 isUnsanitizedVariant := true
536 sanitize := ctx.mod.sanitize
537 if sanitize != nil {
538 isUnsanitizedVariant = sanitize.isUnsanitizedVariant()
539 }
Jayant Chowdhary22963cd2018-03-06 14:59:50 -0800540 vendorAvailable := Bool(ctx.mod.VendorProperties.Vendor_available)
541 return vendorAvailable && isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800542}
543
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700544func (ctx *moduleContextImpl) selectedStl() string {
545 if stl := ctx.mod.stl; stl != nil {
546 return stl.Properties.SelectedStl
547 }
548 return ""
549}
550
Colin Crossce75d2c2016-10-06 16:12:58 -0700551func (ctx *moduleContextImpl) baseModuleName() string {
552 return ctx.mod.ModuleBase.BaseModuleName()
553}
554
Logan Chienf3511742017-10-31 18:04:35 +0800555func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
556 return ctx.mod.getVndkExtendsModuleName()
557}
558
Colin Cross635c3b02016-05-18 15:37:25 -0700559func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800560 return &Module{
561 hod: hod,
562 multilib: multilib,
563 }
564}
565
Colin Cross635c3b02016-05-18 15:37:25 -0700566func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800567 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700568 module.features = []feature{
569 &tidyFeature{},
570 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700571 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800572 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800573 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800574 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900575 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700576 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700577 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800578 return module
579}
580
Colin Crossce75d2c2016-10-06 16:12:58 -0700581func (c *Module) Prebuilt() *android.Prebuilt {
582 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
583 return p.prebuilt()
584 }
585 return nil
586}
587
588func (c *Module) Name() string {
589 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700590 if p, ok := c.linker.(interface {
591 Name(string) string
592 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700593 name = p.Name(name)
594 }
595 return name
596}
597
Jeff Gaston294356f2017-09-27 17:05:30 -0700598// orderDeps reorders dependencies into a list such that if module A depends on B, then
599// A will precede B in the resultant list.
600// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800601// Note that directSharedDeps should be the analogous static library for each shared lib dep
602func 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 -0700603 // If A depends on B, then
604 // Every list containing A will also contain B later in the list
605 // So, after concatenating all lists, the final instance of B will have come from the same
606 // original list as the final instance of A
607 // So, the final instance of B will be later in the concatenation than the final A
608 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
609 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800610 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700611 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800612 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
613 }
614 for _, dep := range directSharedDeps {
615 orderedAllDeps = append(orderedAllDeps, dep)
616 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700617 }
618
Colin Crossb6715442017-10-24 11:13:31 -0700619 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700620
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800621 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700622 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800623 // resultant list to only what the caller has chosen to include in directStaticDeps
624 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700625
626 return orderedAllDeps, orderedDeclaredDeps
627}
628
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800629func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
630 // convert Module to Path
631 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
632 staticDepFiles := []android.Path{}
633 for _, dep := range staticDeps {
634 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
635 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700636 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800637 sharedDepFiles := []android.Path{}
638 for _, sharedDep := range sharedDeps {
639 staticAnalogue := sharedDep.staticVariant
640 if staticAnalogue != nil {
641 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
642 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
643 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700644 }
645
646 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800647 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700648
649 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700650}
651
Colin Cross635c3b02016-05-18 15:37:25 -0700652func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700653
Colin Crossca860ac2016-01-04 14:34:37 -0800654 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700655 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800656 moduleContextImpl: moduleContextImpl{
657 mod: c,
658 },
659 }
660 ctx.ctx = ctx
661
Colin Crossf18e1102017-11-16 14:33:08 -0800662 deps := c.depsToPaths(ctx)
663 if ctx.Failed() {
664 return
665 }
666
Colin Crossca860ac2016-01-04 14:34:37 -0800667 flags := Flags{
668 Toolchain: c.toolchain(ctx),
669 Clang: c.clang(ctx),
670 }
Colin Crossca860ac2016-01-04 14:34:37 -0800671 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800672 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800673 }
674 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700675 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800676 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700677 if c.stl != nil {
678 flags = c.stl.flags(ctx, flags)
679 }
Colin Cross16b23492016-01-06 14:41:07 -0800680 if c.sanitize != nil {
681 flags = c.sanitize.flags(ctx, flags)
682 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800683 if c.coverage != nil {
684 flags = c.coverage.flags(ctx, flags)
685 }
Stephen Craneba090d12017-05-09 15:44:35 -0700686 if c.lto != nil {
687 flags = c.lto.flags(ctx, flags)
688 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700689 if c.pgo != nil {
690 flags = c.pgo.flags(ctx, flags)
691 }
Colin Crossca860ac2016-01-04 14:34:37 -0800692 for _, feature := range c.features {
693 flags = feature.flags(ctx, flags)
694 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800695 if ctx.Failed() {
696 return
697 }
698
Colin Crossb98c8b02016-07-29 13:44:28 -0700699 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
700 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
701 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800702
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800703 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
704 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700705 // We need access to all the flags seen by a source file.
706 if c.sabi != nil {
707 flags = c.sabi.flags(ctx, flags)
708 }
Colin Crossca860ac2016-01-04 14:34:37 -0800709 // Optimization to reduce size of build.ninja
710 // Replace the long list of flags for each file with a module-local variable
711 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
712 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
713 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
714 flags.CFlags = []string{"$cflags"}
715 flags.CppFlags = []string{"$cppflags"}
716 flags.AsFlags = []string{"$asflags"}
717
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700718 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800719 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700720 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800721 if ctx.Failed() {
722 return
723 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800724 }
725
Colin Crossca860ac2016-01-04 14:34:37 -0800726 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700727 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800728 if ctx.Failed() {
729 return
730 }
Colin Cross635c3b02016-05-18 15:37:25 -0700731 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700732 }
Colin Cross5049f022015-03-18 13:28:46 -0700733
Colin Crossce75d2c2016-10-06 16:12:58 -0700734 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
735 c.installer.install(ctx, c.outputFile.Path())
736 if ctx.Failed() {
737 return
Colin Crossca860ac2016-01-04 14:34:37 -0800738 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700739 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800740}
741
Colin Crossb98c8b02016-07-29 13:44:28 -0700742func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800743 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700744 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800745 }
Colin Crossca860ac2016-01-04 14:34:37 -0800746 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800747}
748
Colin Crossca860ac2016-01-04 14:34:37 -0800749func (c *Module) begin(ctx BaseModuleContext) {
750 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700751 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700752 }
Colin Crossca860ac2016-01-04 14:34:37 -0800753 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700754 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800755 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700756 if c.stl != nil {
757 c.stl.begin(ctx)
758 }
Colin Cross16b23492016-01-06 14:41:07 -0800759 if c.sanitize != nil {
760 c.sanitize.begin(ctx)
761 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800762 if c.coverage != nil {
763 c.coverage.begin(ctx)
764 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800765 if c.sabi != nil {
766 c.sabi.begin(ctx)
767 }
Justin Yun8effde42017-06-23 19:24:43 +0900768 if c.vndkdep != nil {
769 c.vndkdep.begin(ctx)
770 }
Stephen Craneba090d12017-05-09 15:44:35 -0700771 if c.lto != nil {
772 c.lto.begin(ctx)
773 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700774 if c.pgo != nil {
775 c.pgo.begin(ctx)
776 }
Colin Crossca860ac2016-01-04 14:34:37 -0800777 for _, feature := range c.features {
778 feature.begin(ctx)
779 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700780 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700781 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700782 if err != nil {
783 ctx.PropertyErrorf("sdk_version", err.Error())
784 }
Nan Zhang0007d812017-11-07 10:57:05 -0800785 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700786 }
Colin Crossca860ac2016-01-04 14:34:37 -0800787}
788
Colin Cross37047f12016-12-13 17:06:13 -0800789func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700790 deps := Deps{}
791
792 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700793 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700794 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700795 // Add the PGO dependency (the clang_rt.profile runtime library), which
796 // sometimes depends on symbols from libgcc, before libgcc gets added
797 // in linkerDeps().
798 if c.pgo != nil {
799 deps = c.pgo.deps(ctx, deps)
800 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700801 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700802 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700803 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700804 if c.stl != nil {
805 deps = c.stl.deps(ctx, deps)
806 }
Colin Cross16b23492016-01-06 14:41:07 -0800807 if c.sanitize != nil {
808 deps = c.sanitize.deps(ctx, deps)
809 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800810 if c.coverage != nil {
811 deps = c.coverage.deps(ctx, deps)
812 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800813 if c.sabi != nil {
814 deps = c.sabi.deps(ctx, deps)
815 }
Justin Yun8effde42017-06-23 19:24:43 +0900816 if c.vndkdep != nil {
817 deps = c.vndkdep.deps(ctx, deps)
818 }
Stephen Craneba090d12017-05-09 15:44:35 -0700819 if c.lto != nil {
820 deps = c.lto.deps(ctx, deps)
821 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700822 for _, feature := range c.features {
823 deps = feature.deps(ctx, deps)
824 }
825
Colin Crossb6715442017-10-24 11:13:31 -0700826 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
827 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
828 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
829 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
830 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
831 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700832
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700833 for _, lib := range deps.ReexportSharedLibHeaders {
834 if !inList(lib, deps.SharedLibs) {
835 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
836 }
837 }
838
839 for _, lib := range deps.ReexportStaticLibHeaders {
840 if !inList(lib, deps.StaticLibs) {
841 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
842 }
843 }
844
Colin Cross5950f382016-12-13 12:50:57 -0800845 for _, lib := range deps.ReexportHeaderLibHeaders {
846 if !inList(lib, deps.HeaderLibs) {
847 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
848 }
849 }
850
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700851 for _, gen := range deps.ReexportGeneratedHeaders {
852 if !inList(gen, deps.GeneratedHeaders) {
853 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
854 }
855 }
856
Colin Crossc99deeb2016-04-11 15:06:20 -0700857 return deps
858}
859
Dan Albert7e9d2952016-08-04 13:02:36 -0700860func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800861 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700862 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800863 moduleContextImpl: moduleContextImpl{
864 mod: c,
865 },
866 }
867 ctx.ctx = ctx
868
Colin Crossca860ac2016-01-04 14:34:37 -0800869 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700870}
871
Colin Cross1e676be2016-10-12 14:38:15 -0700872func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
873 if !c.Enabled() {
874 return
875 }
876
Colin Cross37047f12016-12-13 17:06:13 -0800877 ctx := &depsContext{
878 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700879 moduleContextImpl: moduleContextImpl{
880 mod: c,
881 },
882 }
883 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800884
Colin Crossc99deeb2016-04-11 15:06:20 -0700885 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800886
Dan Albert914449f2016-06-17 16:45:24 -0700887 variantNdkLibs := []string{}
888 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700889 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700890 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700891
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700892 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
893 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700894 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700895 // 1. Name of an NDK library that refers to a prebuilt module.
896 // For each of these, it adds the name of the prebuilt module (which will be in
897 // prebuilts/ndk) to the list of nonvariant libs.
898 // 2. Name of an NDK library that refers to an ndk_library module.
899 // For each of these, it adds the name of the ndk_library module to the list of
900 // variant libs.
901 // 3. Anything else (so anything that isn't an NDK library).
902 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700903 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700904 // The caller can then know to add the variantLibs dependencies differently from the
905 // nonvariantLibs
906 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
907 variantLibs = []string{}
908 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700909 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700910 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700911 if !inList(entry, ndkMigratedLibs) {
912 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
913 } else {
914 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
915 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700916 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700917 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700918 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700919 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700920 }
921 }
Dan Albert914449f2016-06-17 16:45:24 -0700922 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700923 }
924
Dan Albert914449f2016-06-17 16:45:24 -0700925 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
926 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900927 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700928 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700929
Colin Cross32ec36c2016-12-15 07:39:51 -0800930 for _, lib := range deps.HeaderLibs {
931 depTag := headerDepTag
932 if inList(lib, deps.ReexportHeaderLibHeaders) {
933 depTag = headerExportDepTag
934 }
935 actx.AddVariationDependencies(nil, depTag, lib)
936 }
Colin Cross5950f382016-12-13 12:50:57 -0800937
Colin Crossc99deeb2016-04-11 15:06:20 -0700938 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
939 deps.WholeStaticLibs...)
940
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700941 for _, lib := range deps.StaticLibs {
942 depTag := staticDepTag
943 if inList(lib, deps.ReexportStaticLibHeaders) {
944 depTag = staticExportDepTag
945 }
Colin Cross15a0d462016-07-14 14:49:58 -0700946 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700947 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700948
949 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
950 deps.LateStaticLibs...)
951
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700952 for _, lib := range deps.SharedLibs {
953 depTag := sharedDepTag
954 if inList(lib, deps.ReexportSharedLibHeaders) {
955 depTag = sharedExportDepTag
956 }
Colin Cross15a0d462016-07-14 14:49:58 -0700957 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700958 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700959
960 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
961 deps.LateSharedLibs...)
962
Colin Cross68861832016-07-08 10:41:41 -0700963 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700964
965 for _, gen := range deps.GeneratedHeaders {
966 depTag := genHeaderDepTag
967 if inList(gen, deps.ReexportGeneratedHeaders) {
968 depTag = genHeaderExportDepTag
969 }
970 actx.AddDependency(c, depTag, gen)
971 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700972
Colin Cross68861832016-07-08 10:41:41 -0700973 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700974
975 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700976 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800977 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700978 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700979 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700980 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700981 if deps.LinkerScript != "" {
982 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
983 }
Dan Albert914449f2016-06-17 16:45:24 -0700984
985 version := ctx.sdkVersion()
986 actx.AddVariationDependencies([]blueprint.Variation{
987 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
988 actx.AddVariationDependencies([]blueprint.Variation{
989 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +0800990
991 if vndkdep := c.vndkdep; vndkdep != nil {
992 if vndkdep.isVndkExt() {
993 baseModuleMode := vendorMode
994 if actx.DeviceConfig().VndkVersion() == "" {
995 baseModuleMode = coreMode
996 }
997 actx.AddVariationDependencies([]blueprint.Variation{
998 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
999 vndkdep.getVndkExtendsModuleName())
1000 }
1001 }
Colin Cross6362e272015-10-29 15:25:03 -07001002}
Colin Cross21b9a242015-03-24 14:15:58 -07001003
Dan Albert7e9d2952016-08-04 13:02:36 -07001004func beginMutator(ctx android.BottomUpMutatorContext) {
1005 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1006 c.beginMutator(ctx)
1007 }
1008}
1009
Colin Crossca860ac2016-01-04 14:34:37 -08001010func (c *Module) clang(ctx BaseModuleContext) bool {
1011 clang := Bool(c.Properties.Clang)
1012
1013 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001014 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001015 }
Colin Cross28344522015-04-22 13:07:53 -07001016
Colin Crossca860ac2016-01-04 14:34:37 -08001017 if !c.toolchain(ctx).ClangSupported() {
1018 clang = false
1019 }
1020
1021 return clang
1022}
1023
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001024// Whether a module can link to another module, taking into
1025// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001026func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001027 if from.Target().Os != android.Android {
1028 // Host code is not restricted
1029 return
1030 }
1031 if from.Properties.UseVndk {
1032 // Though vendor code is limited by the vendor mutator,
1033 // each vendor-available module needs to check
1034 // link-type for VNDK.
1035 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001036 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001037 }
1038 return
1039 }
Nan Zhang0007d812017-11-07 10:57:05 -08001040 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001041 // Platform code can link to anything
1042 return
1043 }
1044 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1045 // These are always allowed
1046 return
1047 }
1048 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
1049 // These are allowed, but they don't set sdk_version
1050 return
1051 }
1052 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1053 // These are allowed, but they don't set sdk_version
1054 return
1055 }
1056 if _, ok := to.linker.(*stubDecorator); ok {
1057 // These aren't real libraries, but are the stub shared libraries that are included in
1058 // the NDK.
1059 return
1060 }
Nan Zhang0007d812017-11-07 10:57:05 -08001061 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001062 // NDK code linking to platform code is never okay.
1063 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1064 ctx.OtherModuleName(to))
1065 }
1066
1067 // At this point we know we have two NDK libraries, but we need to
1068 // check that we're not linking against anything built against a higher
1069 // API level, as it is only valid to link against older or equivalent
1070 // APIs.
1071
Nan Zhang0007d812017-11-07 10:57:05 -08001072 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001073 // Current can link against anything.
1074 return
Nan Zhang0007d812017-11-07 10:57:05 -08001075 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001076 // Current can't be linked against by anything else.
1077 ctx.ModuleErrorf("links %q built against newer API version %q",
1078 ctx.OtherModuleName(to), "current")
1079 }
1080
Nan Zhang0007d812017-11-07 10:57:05 -08001081 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001082 if err != nil {
1083 ctx.PropertyErrorf("sdk_version",
1084 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001085 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001086 }
Nan Zhang0007d812017-11-07 10:57:05 -08001087 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001088 if err != nil {
1089 ctx.PropertyErrorf("sdk_version",
1090 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001091 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001092 }
1093
1094 if toApi > fromApi {
1095 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001096 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001097 }
Dan Albert202fe492017-12-15 13:56:59 -08001098
1099 // Also check that the two STL choices are compatible.
1100 fromStl := from.stl.Properties.SelectedStl
1101 toStl := to.stl.Properties.SelectedStl
1102 if fromStl == "" || toStl == "" {
1103 // Libraries that don't use the STL are unrestricted.
1104 return
1105 }
1106
1107 if fromStl == "ndk_system" || toStl == "ndk_system" {
1108 // We can be permissive with the system "STL" since it is only the C++
1109 // ABI layer, but in the future we should make sure that everyone is
1110 // using either libc++ or nothing.
1111 return
1112 }
1113
1114 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1115 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1116 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1117 to.stl.Properties.SelectedStl)
1118 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001119}
1120
Colin Crossc99deeb2016-04-11 15:06:20 -07001121// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001122func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001123 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001124
Jeff Gaston294356f2017-09-27 17:05:30 -07001125 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001126 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001127
Colin Crossd11fcda2017-10-23 17:59:01 -07001128 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001129 depName := ctx.OtherModuleName(dep)
1130 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001131
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001132 ccDep, _ := dep.(*Module)
1133 if ccDep == nil {
1134 // handling for a few module types that aren't cc Module but that are also supported
1135 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001136 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001137 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001138 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001139 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001140 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1141 genRule.GeneratedSourceFiles()...)
1142 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001143 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001144 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001145 // Support exported headers from a generated_sources dependency
1146 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001147 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001148 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001149 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001150 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001151 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001152 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001153 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001154 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001155 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001156 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001157 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1158 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1159
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001160 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001161 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001162 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001163 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001164 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001165 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001166 files := genRule.GeneratedSourceFiles()
1167 if len(files) == 1 {
1168 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1169 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001170 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001171 }
1172 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001173 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001174 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001175 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001176 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001177 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001178 return
1179 }
1180
Colin Crossd11fcda2017-10-23 17:59:01 -07001181 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001182 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1183 return
1184 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001185 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001186 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001187 return
1188 }
1189
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001190 // re-exporting flags
1191 if depTag == reuseObjTag {
1192 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001193 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001194 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001195 depPaths.Objs = depPaths.Objs.Append(objs)
1196 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001197 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001198 return
1199 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001200 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001201 if t, ok := depTag.(dependencyTag); ok && t.library {
1202 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001203 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001204 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001205 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001206 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001207
1208 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001209 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001210 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001211 // 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 -07001212 // Re-exported shared library headers must be included as well since they can help us with type information
1213 // about template instantiations (instantiated from their headers).
1214 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001215 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001216 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001217
Logan Chienf3511742017-10-31 18:04:35 +08001218 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001219 }
1220
Colin Cross26c34ed2016-09-30 17:10:16 -07001221 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001222 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001223
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001224 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001225 depFile := android.OptionalPath{}
1226
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001227 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001228 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001229 ptr = &depPaths.SharedLibs
1230 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001231 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001232 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001233 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001234 ptr = &depPaths.LateSharedLibs
1235 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001236 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001237 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001238 ptr = nil
1239 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001240 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001241 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001242 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001243 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001244 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001245 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001246 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001247 return
1248 }
1249
1250 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001251 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001252 for i := range missingDeps {
1253 missingDeps[i] += postfix
1254 }
1255 ctx.AddMissingDependencies(missingDeps)
1256 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001257 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001258 case headerDepTag:
1259 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001260 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001261 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001262 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001263 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001264 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001265 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001266 }
1267
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001268 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001269 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001270 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001271 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001272 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001273 return
1274 }
1275
1276 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001277 // in static libraries act as if they were whole static libraries. The same goes for
1278 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001279 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1280 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001281 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1282 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001283
Dan Willemsen581341d2017-02-09 16:16:31 -08001284 }
1285
Colin Cross26c34ed2016-09-30 17:10:16 -07001286 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001287 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001288 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001289 return
1290 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001291 *ptr = append(*ptr, linkFile.Path())
1292 }
1293
Colin Crossc99deeb2016-04-11 15:06:20 -07001294 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001295 dep := depFile
1296 if !dep.Valid() {
1297 dep = linkFile
1298 }
1299 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001300 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001301
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001302 // Export the shared libs to Make.
1303 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001304 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001305 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001306 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001307 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001308 var makeLibName string
1309 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1310 if c.useVndk() && bothVendorAndCoreVariantsExist {
1311 // The vendor module in Make will have been renamed to not conflict with the core
1312 // module, so update the dependency name here accordingly.
1313 makeLibName = libName + vendorSuffix
1314 } else {
1315 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001316 }
1317 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001318 // they merely serve as Make dependencies and do not affect this lib itself.
1319 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001320 }
Colin Crossca860ac2016-01-04 14:34:37 -08001321 })
1322
Jeff Gaston294356f2017-09-27 17:05:30 -07001323 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001324 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001325
Colin Crossdd84e052017-05-17 13:44:16 -07001326 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001327 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001328 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001329 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001330 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1331
1332 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001333 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001334 }
Colin Crossdd84e052017-05-17 13:44:16 -07001335
Colin Crossca860ac2016-01-04 14:34:37 -08001336 return depPaths
1337}
1338
1339func (c *Module) InstallInData() bool {
1340 if c.installer == nil {
1341 return false
1342 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001343 return c.installer.inData()
1344}
1345
1346func (c *Module) InstallInSanitizerDir() bool {
1347 if c.installer == nil {
1348 return false
1349 }
1350 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001351 return true
1352 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001353 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001354}
1355
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001356func (c *Module) HostToolPath() android.OptionalPath {
1357 if c.installer == nil {
1358 return android.OptionalPath{}
1359 }
1360 return c.installer.hostToolPath()
1361}
1362
Nan Zhangd4e641b2017-07-12 12:55:28 -07001363func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1364 return c.outputFile
1365}
1366
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001367func (c *Module) Srcs() android.Paths {
1368 if c.outputFile.Valid() {
1369 return android.Paths{c.outputFile.Path()}
1370 }
1371 return android.Paths{}
1372}
1373
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001374func (c *Module) static() bool {
1375 if static, ok := c.linker.(interface {
1376 static() bool
1377 }); ok {
1378 return static.static()
1379 }
1380 return false
1381}
1382
Colin Cross2ba19d92015-05-07 15:44:20 -07001383//
Colin Crosscfad1192015-11-02 16:43:11 -08001384// Defaults
1385//
Colin Crossca860ac2016-01-04 14:34:37 -08001386type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001387 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001388 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001389}
1390
Colin Cross635c3b02016-05-18 15:37:25 -07001391func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001392}
1393
Colin Cross1e676be2016-10-12 14:38:15 -07001394func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1395}
1396
Colin Cross36242852017-06-23 15:06:31 -07001397func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001398 return DefaultsFactory()
1399}
1400
Colin Cross36242852017-06-23 15:06:31 -07001401func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001402 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001403
Colin Cross36242852017-06-23 15:06:31 -07001404 module.AddProperties(props...)
1405 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001406 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001407 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001408 &BaseCompilerProperties{},
1409 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001410 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001411 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001412 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001413 &TestProperties{},
1414 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001415 &UnusedProperties{},
1416 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001417 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001418 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001419 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001420 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001421 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001422 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001423 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001424 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001425 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001426 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001427 )
Colin Crosscfad1192015-11-02 16:43:11 -08001428
Colin Cross1f44a3a2017-07-07 14:33:33 -07001429 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001430
1431 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001432}
1433
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001434const (
1435 // coreMode is the variant used for framework-private libraries, or
1436 // SDK libraries. (which framework-private libraries can use)
1437 coreMode = "core"
1438
1439 // vendorMode is the variant used for /vendor code that compiles
1440 // against the VNDK.
1441 vendorMode = "vendor"
1442)
1443
Jiyong Park6a43f042017-10-12 23:05:00 +09001444func squashVendorSrcs(m *Module) {
1445 if lib, ok := m.compiler.(*libraryDecorator); ok {
1446 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1447 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1448
1449 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1450 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1451 }
1452}
1453
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001454func vendorMutator(mctx android.BottomUpMutatorContext) {
1455 if mctx.Os() != android.Android {
1456 return
1457 }
1458
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001459 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1460 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001461 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001462 mctx.CreateVariations(coreMode)
1463 } else if Bool(props.Vendor_available) {
1464 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001465 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001466 mctx.CreateVariations(vendorMode)
1467 } else {
1468 mctx.CreateVariations(coreMode)
1469 }
1470 }
1471 }
1472
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001473 m, ok := mctx.Module().(*Module)
1474 if !ok {
1475 return
1476 }
1477
1478 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001479 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1480
1481 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001482 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001483 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001484 return
1485 }
Logan Chienf3511742017-10-31 18:04:35 +08001486
1487 if vndkdep := m.vndkdep; vndkdep != nil {
1488 if vndkdep.isVndk() {
1489 if vendorSpecific {
1490 if !vndkdep.isVndkExt() {
1491 mctx.PropertyErrorf("vndk",
1492 "must set `extends: \"...\"` to vndk extension")
1493 return
1494 }
1495 } else {
1496 if vndkdep.isVndkExt() {
1497 mctx.PropertyErrorf("vndk",
1498 "must set `vendor: true` to set `extends: %q`",
1499 m.getVndkExtendsModuleName())
1500 return
1501 }
1502 if m.VendorProperties.Vendor_available == nil {
1503 mctx.PropertyErrorf("vndk",
1504 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1505 return
1506 }
1507 }
1508 } else {
1509 if vndkdep.isVndkSp() {
1510 mctx.PropertyErrorf("vndk",
1511 "must set `enabled: true` to set `support_system_process: true`")
1512 return
1513 }
1514 if vndkdep.isVndkExt() {
1515 mctx.PropertyErrorf("vndk",
1516 "must set `enabled: true` to set `extends: %q`",
1517 m.getVndkExtendsModuleName())
1518 return
1519 }
Justin Yun8effde42017-06-23 19:24:43 +09001520 }
1521 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001522
Justin Yun71549282017-11-17 12:10:28 +09001523 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001524 // If the device isn't compiling against the VNDK, we always
1525 // use the core mode.
1526 mctx.CreateVariations(coreMode)
1527 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1528 // LL-NDK stubs only exist in the vendor variant, since the
1529 // real libraries will be used in the core variant.
1530 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001531 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1532 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001533 mod := mctx.CreateVariations(vendorMode)
1534 vendor := mod[0].(*Module)
1535 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001536 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001537 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1538 // PRODUCT_EXTRA_VNDK_VERSIONS.
1539 mod := mctx.CreateVariations(vendorMode)
1540 vendor := mod[0].(*Module)
1541 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001542 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001543 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001544 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001545 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001546 vendor := mod[1].(*Module)
1547 vendor.Properties.UseVndk = true
1548 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001549 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001550 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001551 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001552 vendor := mod[0].(*Module)
1553 vendor.Properties.UseVndk = true
1554 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001555 } else {
1556 // This is either in /system (or similar: /data), or is a
1557 // modules built with the NDK. Modules built with the NDK
1558 // will be restricted using the existing link type checks.
1559 mctx.CreateVariations(coreMode)
1560 }
1561}
1562
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001563func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001564 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001565 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1566 }
Colin Cross6510f912017-11-29 00:27:14 -08001567 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001568}
1569
Colin Cross06a931b2015-10-28 17:23:31 -07001570var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001571var BoolPtr = proptools.BoolPtr
1572var String = proptools.String
1573var StringPtr = proptools.StringPtr