blob: e91711eef3ce552bc8e52c262112d3857b852ac9 [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() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900505 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700506 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900507 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
508 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
509 return "current"
510 }
511 return platform_vndk_ver
512 }
513 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800514 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900515 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700516 }
517 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800518}
519
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700520func (ctx *moduleContextImpl) useVndk() bool {
521 return ctx.mod.useVndk()
522}
Justin Yun8effde42017-06-23 19:24:43 +0900523
Logan Chienf3511742017-10-31 18:04:35 +0800524func (ctx *moduleContextImpl) isVndk() bool {
525 return ctx.mod.isVndk()
526}
527
Yi Kong7e53c572018-02-14 18:16:12 +0800528func (ctx *moduleContextImpl) isPgoCompile() bool {
529 return ctx.mod.isPgoCompile()
530}
531
Justin Yun8effde42017-06-23 19:24:43 +0900532func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800533 return ctx.mod.isVndkSp()
534}
535
536func (ctx *moduleContextImpl) isVndkExt() bool {
537 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900538}
539
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800540// Create source abi dumps if the module belongs to the list of VndkLibraries.
541func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800542 isUnsanitizedVariant := true
543 sanitize := ctx.mod.sanitize
544 if sanitize != nil {
545 isUnsanitizedVariant = sanitize.isUnsanitizedVariant()
546 }
Jayant Chowdhary22963cd2018-03-06 14:59:50 -0800547 vendorAvailable := Bool(ctx.mod.VendorProperties.Vendor_available)
Jayant Chowdharyfa920fa2018-03-27 11:10:57 -0700548 return isUnsanitizedVariant && ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk() && vendorAvailable) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800549}
550
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700551func (ctx *moduleContextImpl) selectedStl() string {
552 if stl := ctx.mod.stl; stl != nil {
553 return stl.Properties.SelectedStl
554 }
555 return ""
556}
557
Colin Crossce75d2c2016-10-06 16:12:58 -0700558func (ctx *moduleContextImpl) baseModuleName() string {
559 return ctx.mod.ModuleBase.BaseModuleName()
560}
561
Logan Chienf3511742017-10-31 18:04:35 +0800562func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
563 return ctx.mod.getVndkExtendsModuleName()
564}
565
Colin Cross635c3b02016-05-18 15:37:25 -0700566func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800567 return &Module{
568 hod: hod,
569 multilib: multilib,
570 }
571}
572
Colin Cross635c3b02016-05-18 15:37:25 -0700573func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800574 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700575 module.features = []feature{
576 &tidyFeature{},
577 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700578 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800579 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800580 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800581 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900582 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700583 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700584 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800585 return module
586}
587
Colin Crossce75d2c2016-10-06 16:12:58 -0700588func (c *Module) Prebuilt() *android.Prebuilt {
589 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
590 return p.prebuilt()
591 }
592 return nil
593}
594
595func (c *Module) Name() string {
596 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700597 if p, ok := c.linker.(interface {
598 Name(string) string
599 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700600 name = p.Name(name)
601 }
602 return name
603}
604
Jeff Gaston294356f2017-09-27 17:05:30 -0700605// orderDeps reorders dependencies into a list such that if module A depends on B, then
606// A will precede B in the resultant list.
607// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800608// Note that directSharedDeps should be the analogous static library for each shared lib dep
609func 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 -0700610 // If A depends on B, then
611 // Every list containing A will also contain B later in the list
612 // So, after concatenating all lists, the final instance of B will have come from the same
613 // original list as the final instance of A
614 // So, the final instance of B will be later in the concatenation than the final A
615 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
616 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800617 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700618 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800619 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
620 }
621 for _, dep := range directSharedDeps {
622 orderedAllDeps = append(orderedAllDeps, dep)
623 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700624 }
625
Colin Crossb6715442017-10-24 11:13:31 -0700626 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700627
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800628 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700629 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800630 // resultant list to only what the caller has chosen to include in directStaticDeps
631 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700632
633 return orderedAllDeps, orderedDeclaredDeps
634}
635
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800636func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
637 // convert Module to Path
638 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
639 staticDepFiles := []android.Path{}
640 for _, dep := range staticDeps {
641 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
642 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700643 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800644 sharedDepFiles := []android.Path{}
645 for _, sharedDep := range sharedDeps {
646 staticAnalogue := sharedDep.staticVariant
647 if staticAnalogue != nil {
648 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
649 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
650 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700651 }
652
653 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800654 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700655
656 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700657}
658
Colin Cross635c3b02016-05-18 15:37:25 -0700659func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700660
Colin Crossca860ac2016-01-04 14:34:37 -0800661 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700662 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800663 moduleContextImpl: moduleContextImpl{
664 mod: c,
665 },
666 }
667 ctx.ctx = ctx
668
Colin Crossf18e1102017-11-16 14:33:08 -0800669 deps := c.depsToPaths(ctx)
670 if ctx.Failed() {
671 return
672 }
673
Colin Crossca860ac2016-01-04 14:34:37 -0800674 flags := Flags{
675 Toolchain: c.toolchain(ctx),
676 Clang: c.clang(ctx),
677 }
Colin Crossca860ac2016-01-04 14:34:37 -0800678 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800679 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800680 }
681 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700682 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800683 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700684 if c.stl != nil {
685 flags = c.stl.flags(ctx, flags)
686 }
Colin Cross16b23492016-01-06 14:41:07 -0800687 if c.sanitize != nil {
688 flags = c.sanitize.flags(ctx, flags)
689 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800690 if c.coverage != nil {
691 flags = c.coverage.flags(ctx, flags)
692 }
Stephen Craneba090d12017-05-09 15:44:35 -0700693 if c.lto != nil {
694 flags = c.lto.flags(ctx, flags)
695 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700696 if c.pgo != nil {
697 flags = c.pgo.flags(ctx, flags)
698 }
Colin Crossca860ac2016-01-04 14:34:37 -0800699 for _, feature := range c.features {
700 flags = feature.flags(ctx, flags)
701 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800702 if ctx.Failed() {
703 return
704 }
705
Colin Crossb98c8b02016-07-29 13:44:28 -0700706 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
707 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
708 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800709
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800710 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
711 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700712 // We need access to all the flags seen by a source file.
713 if c.sabi != nil {
714 flags = c.sabi.flags(ctx, flags)
715 }
Colin Crossca860ac2016-01-04 14:34:37 -0800716 // Optimization to reduce size of build.ninja
717 // Replace the long list of flags for each file with a module-local variable
718 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
719 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
720 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
721 flags.CFlags = []string{"$cflags"}
722 flags.CppFlags = []string{"$cppflags"}
723 flags.AsFlags = []string{"$asflags"}
724
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700725 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800726 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700727 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800728 if ctx.Failed() {
729 return
730 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800731 }
732
Colin Crossca860ac2016-01-04 14:34:37 -0800733 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700734 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800735 if ctx.Failed() {
736 return
737 }
Colin Cross635c3b02016-05-18 15:37:25 -0700738 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700739 }
Colin Cross5049f022015-03-18 13:28:46 -0700740
Colin Crossce75d2c2016-10-06 16:12:58 -0700741 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
742 c.installer.install(ctx, c.outputFile.Path())
743 if ctx.Failed() {
744 return
Colin Crossca860ac2016-01-04 14:34:37 -0800745 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700746 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800747}
748
Colin Crossb98c8b02016-07-29 13:44:28 -0700749func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800750 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700751 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800752 }
Colin Crossca860ac2016-01-04 14:34:37 -0800753 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800754}
755
Colin Crossca860ac2016-01-04 14:34:37 -0800756func (c *Module) begin(ctx BaseModuleContext) {
757 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700758 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700759 }
Colin Crossca860ac2016-01-04 14:34:37 -0800760 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700761 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800762 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700763 if c.stl != nil {
764 c.stl.begin(ctx)
765 }
Colin Cross16b23492016-01-06 14:41:07 -0800766 if c.sanitize != nil {
767 c.sanitize.begin(ctx)
768 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800769 if c.coverage != nil {
770 c.coverage.begin(ctx)
771 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800772 if c.sabi != nil {
773 c.sabi.begin(ctx)
774 }
Justin Yun8effde42017-06-23 19:24:43 +0900775 if c.vndkdep != nil {
776 c.vndkdep.begin(ctx)
777 }
Stephen Craneba090d12017-05-09 15:44:35 -0700778 if c.lto != nil {
779 c.lto.begin(ctx)
780 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700781 if c.pgo != nil {
782 c.pgo.begin(ctx)
783 }
Colin Crossca860ac2016-01-04 14:34:37 -0800784 for _, feature := range c.features {
785 feature.begin(ctx)
786 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700787 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700788 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700789 if err != nil {
790 ctx.PropertyErrorf("sdk_version", err.Error())
791 }
Nan Zhang0007d812017-11-07 10:57:05 -0800792 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700793 }
Colin Crossca860ac2016-01-04 14:34:37 -0800794}
795
Colin Cross37047f12016-12-13 17:06:13 -0800796func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700797 deps := Deps{}
798
799 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700800 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700801 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700802 // Add the PGO dependency (the clang_rt.profile runtime library), which
803 // sometimes depends on symbols from libgcc, before libgcc gets added
804 // in linkerDeps().
805 if c.pgo != nil {
806 deps = c.pgo.deps(ctx, deps)
807 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700808 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700809 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700810 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700811 if c.stl != nil {
812 deps = c.stl.deps(ctx, deps)
813 }
Colin Cross16b23492016-01-06 14:41:07 -0800814 if c.sanitize != nil {
815 deps = c.sanitize.deps(ctx, deps)
816 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800817 if c.coverage != nil {
818 deps = c.coverage.deps(ctx, deps)
819 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800820 if c.sabi != nil {
821 deps = c.sabi.deps(ctx, deps)
822 }
Justin Yun8effde42017-06-23 19:24:43 +0900823 if c.vndkdep != nil {
824 deps = c.vndkdep.deps(ctx, deps)
825 }
Stephen Craneba090d12017-05-09 15:44:35 -0700826 if c.lto != nil {
827 deps = c.lto.deps(ctx, deps)
828 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700829 for _, feature := range c.features {
830 deps = feature.deps(ctx, deps)
831 }
832
Colin Crossb6715442017-10-24 11:13:31 -0700833 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
834 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
835 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
836 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
837 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
838 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700839
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700840 for _, lib := range deps.ReexportSharedLibHeaders {
841 if !inList(lib, deps.SharedLibs) {
842 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
843 }
844 }
845
846 for _, lib := range deps.ReexportStaticLibHeaders {
847 if !inList(lib, deps.StaticLibs) {
848 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
849 }
850 }
851
Colin Cross5950f382016-12-13 12:50:57 -0800852 for _, lib := range deps.ReexportHeaderLibHeaders {
853 if !inList(lib, deps.HeaderLibs) {
854 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
855 }
856 }
857
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700858 for _, gen := range deps.ReexportGeneratedHeaders {
859 if !inList(gen, deps.GeneratedHeaders) {
860 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
861 }
862 }
863
Colin Crossc99deeb2016-04-11 15:06:20 -0700864 return deps
865}
866
Dan Albert7e9d2952016-08-04 13:02:36 -0700867func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800868 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700869 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800870 moduleContextImpl: moduleContextImpl{
871 mod: c,
872 },
873 }
874 ctx.ctx = ctx
875
Colin Crossca860ac2016-01-04 14:34:37 -0800876 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700877}
878
Colin Cross1e676be2016-10-12 14:38:15 -0700879func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
880 if !c.Enabled() {
881 return
882 }
883
Colin Cross37047f12016-12-13 17:06:13 -0800884 ctx := &depsContext{
885 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700886 moduleContextImpl: moduleContextImpl{
887 mod: c,
888 },
889 }
890 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800891
Colin Crossc99deeb2016-04-11 15:06:20 -0700892 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800893
Dan Albert914449f2016-06-17 16:45:24 -0700894 variantNdkLibs := []string{}
895 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700896 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700897 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700898
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700899 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
900 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700901 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700902 // 1. Name of an NDK library that refers to a prebuilt module.
903 // For each of these, it adds the name of the prebuilt module (which will be in
904 // prebuilts/ndk) to the list of nonvariant libs.
905 // 2. Name of an NDK library that refers to an ndk_library module.
906 // For each of these, it adds the name of the ndk_library module to the list of
907 // variant libs.
908 // 3. Anything else (so anything that isn't an NDK library).
909 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700910 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700911 // The caller can then know to add the variantLibs dependencies differently from the
912 // nonvariantLibs
913 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
914 variantLibs = []string{}
915 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700916 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700917 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700918 if !inList(entry, ndkMigratedLibs) {
919 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
920 } else {
921 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
922 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700923 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700924 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +0900925 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(entry, vendorPublicLibraries) {
926 vendorPublicLib := entry + vendorPublicLibrarySuffix
927 if actx.OtherModuleExists(vendorPublicLib) {
928 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
929 } else {
930 // This can happen if vendor_public_library module is defined in a
931 // namespace that isn't visible to the current module. In that case,
932 // link to the original library.
933 nonvariantLibs = append(nonvariantLibs, entry)
934 }
Dan Albert914449f2016-06-17 16:45:24 -0700935 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700936 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700937 }
938 }
Dan Albert914449f2016-06-17 16:45:24 -0700939 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700940 }
941
Dan Albert914449f2016-06-17 16:45:24 -0700942 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
943 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900944 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700945 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700946
Colin Cross32ec36c2016-12-15 07:39:51 -0800947 for _, lib := range deps.HeaderLibs {
948 depTag := headerDepTag
949 if inList(lib, deps.ReexportHeaderLibHeaders) {
950 depTag = headerExportDepTag
951 }
952 actx.AddVariationDependencies(nil, depTag, lib)
953 }
Colin Cross5950f382016-12-13 12:50:57 -0800954
Colin Crossc99deeb2016-04-11 15:06:20 -0700955 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
956 deps.WholeStaticLibs...)
957
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700958 for _, lib := range deps.StaticLibs {
959 depTag := staticDepTag
960 if inList(lib, deps.ReexportStaticLibHeaders) {
961 depTag = staticExportDepTag
962 }
Colin Cross15a0d462016-07-14 14:49:58 -0700963 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700964 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700965
966 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
967 deps.LateStaticLibs...)
968
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700969 for _, lib := range deps.SharedLibs {
970 depTag := sharedDepTag
971 if inList(lib, deps.ReexportSharedLibHeaders) {
972 depTag = sharedExportDepTag
973 }
Colin Cross15a0d462016-07-14 14:49:58 -0700974 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700975 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700976
977 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
978 deps.LateSharedLibs...)
979
Colin Cross68861832016-07-08 10:41:41 -0700980 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700981
982 for _, gen := range deps.GeneratedHeaders {
983 depTag := genHeaderDepTag
984 if inList(gen, deps.ReexportGeneratedHeaders) {
985 depTag = genHeaderExportDepTag
986 }
987 actx.AddDependency(c, depTag, gen)
988 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700989
Colin Cross68861832016-07-08 10:41:41 -0700990 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700991
992 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700993 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800994 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700995 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700996 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700997 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700998 if deps.LinkerScript != "" {
999 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
1000 }
Dan Albert914449f2016-06-17 16:45:24 -07001001
1002 version := ctx.sdkVersion()
1003 actx.AddVariationDependencies([]blueprint.Variation{
1004 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
1005 actx.AddVariationDependencies([]blueprint.Variation{
1006 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001007
1008 if vndkdep := c.vndkdep; vndkdep != nil {
1009 if vndkdep.isVndkExt() {
1010 baseModuleMode := vendorMode
1011 if actx.DeviceConfig().VndkVersion() == "" {
1012 baseModuleMode = coreMode
1013 }
1014 actx.AddVariationDependencies([]blueprint.Variation{
1015 {"image", baseModuleMode}, {"link", "shared"}}, vndkExtDepTag,
1016 vndkdep.getVndkExtendsModuleName())
1017 }
1018 }
Colin Cross6362e272015-10-29 15:25:03 -07001019}
Colin Cross21b9a242015-03-24 14:15:58 -07001020
Dan Albert7e9d2952016-08-04 13:02:36 -07001021func beginMutator(ctx android.BottomUpMutatorContext) {
1022 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1023 c.beginMutator(ctx)
1024 }
1025}
1026
Colin Crossca860ac2016-01-04 14:34:37 -08001027func (c *Module) clang(ctx BaseModuleContext) bool {
1028 clang := Bool(c.Properties.Clang)
1029
1030 if c.Properties.Clang == nil {
Stephen Hines6ea0f812018-01-11 11:56:19 -08001031 clang = true
Colin Cross3f40fa42015-01-30 17:27:36 -08001032 }
Colin Cross28344522015-04-22 13:07:53 -07001033
Colin Crossca860ac2016-01-04 14:34:37 -08001034 if !c.toolchain(ctx).ClangSupported() {
1035 clang = false
1036 }
1037
1038 return clang
1039}
1040
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001041// Whether a module can link to another module, taking into
1042// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001043func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001044 if from.Target().Os != android.Android {
1045 // Host code is not restricted
1046 return
1047 }
1048 if from.Properties.UseVndk {
1049 // Though vendor code is limited by the vendor mutator,
1050 // each vendor-available module needs to check
1051 // link-type for VNDK.
1052 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001053 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001054 }
1055 return
1056 }
Nan Zhang0007d812017-11-07 10:57:05 -08001057 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001058 // Platform code can link to anything
1059 return
1060 }
1061 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1062 // These are always allowed
1063 return
1064 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001065 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1066 // These are allowed, but they don't set sdk_version
1067 return
1068 }
1069 if _, ok := to.linker.(*stubDecorator); ok {
1070 // These aren't real libraries, but are the stub shared libraries that are included in
1071 // the NDK.
1072 return
1073 }
Nan Zhang0007d812017-11-07 10:57:05 -08001074 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001075 // NDK code linking to platform code is never okay.
1076 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1077 ctx.OtherModuleName(to))
1078 }
1079
1080 // At this point we know we have two NDK libraries, but we need to
1081 // check that we're not linking against anything built against a higher
1082 // API level, as it is only valid to link against older or equivalent
1083 // APIs.
1084
Nan Zhang0007d812017-11-07 10:57:05 -08001085 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001086 // Current can link against anything.
1087 return
Nan Zhang0007d812017-11-07 10:57:05 -08001088 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001089 // Current can't be linked against by anything else.
1090 ctx.ModuleErrorf("links %q built against newer API version %q",
1091 ctx.OtherModuleName(to), "current")
1092 }
1093
Nan Zhang0007d812017-11-07 10:57:05 -08001094 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001095 if err != nil {
1096 ctx.PropertyErrorf("sdk_version",
1097 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001098 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001099 }
Nan Zhang0007d812017-11-07 10:57:05 -08001100 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001101 if err != nil {
1102 ctx.PropertyErrorf("sdk_version",
1103 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001104 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001105 }
1106
1107 if toApi > fromApi {
1108 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001109 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001110 }
Dan Albert202fe492017-12-15 13:56:59 -08001111
1112 // Also check that the two STL choices are compatible.
1113 fromStl := from.stl.Properties.SelectedStl
1114 toStl := to.stl.Properties.SelectedStl
1115 if fromStl == "" || toStl == "" {
1116 // Libraries that don't use the STL are unrestricted.
1117 return
1118 }
1119
1120 if fromStl == "ndk_system" || toStl == "ndk_system" {
1121 // We can be permissive with the system "STL" since it is only the C++
1122 // ABI layer, but in the future we should make sure that everyone is
1123 // using either libc++ or nothing.
1124 return
1125 }
1126
1127 if getNdkStlFamily(ctx, from) != getNdkStlFamily(ctx, to) {
1128 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1129 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1130 to.stl.Properties.SelectedStl)
1131 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001132}
1133
Colin Crossc99deeb2016-04-11 15:06:20 -07001134// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001135func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001136 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001137
Jeff Gaston294356f2017-09-27 17:05:30 -07001138 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001139 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001140
Colin Crossd11fcda2017-10-23 17:59:01 -07001141 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001142 depName := ctx.OtherModuleName(dep)
1143 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001144
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001145 ccDep, _ := dep.(*Module)
1146 if ccDep == nil {
1147 // handling for a few module types that aren't cc Module but that are also supported
1148 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001149 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001150 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001151 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001152 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001153 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1154 genRule.GeneratedSourceFiles()...)
1155 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001156 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001157 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001158 // Support exported headers from a generated_sources dependency
1159 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001160 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001161 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001162 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001163 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001164 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001165 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001166 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001167 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001168 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001169 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001170 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1171 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1172
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001173 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001174 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001175 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001176 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001177 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001179 files := genRule.GeneratedSourceFiles()
1180 if len(files) == 1 {
1181 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1182 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001183 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001184 }
1185 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001186 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001187 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001188 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001189 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001190 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001191 return
1192 }
1193
Colin Crossd11fcda2017-10-23 17:59:01 -07001194 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001195 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1196 return
1197 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001198 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001199 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001200 return
1201 }
1202
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001203 // re-exporting flags
1204 if depTag == reuseObjTag {
1205 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001206 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001207 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001208 depPaths.Objs = depPaths.Objs.Append(objs)
1209 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001210 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001211 return
1212 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001213 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001214 if t, ok := depTag.(dependencyTag); ok && t.library {
1215 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001216 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001217 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001218 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001219 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001220
1221 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001222 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001223 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001224 // 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 -07001225 // Re-exported shared library headers must be included as well since they can help us with type information
1226 // about template instantiations (instantiated from their headers).
1227 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001228 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001229 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001230
Logan Chienf3511742017-10-31 18:04:35 +08001231 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001232 }
1233
Colin Cross26c34ed2016-09-30 17:10:16 -07001234 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001235 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001236
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001237 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001238 depFile := android.OptionalPath{}
1239
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001240 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001241 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001242 ptr = &depPaths.SharedLibs
1243 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001244 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001245 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001246 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001247 ptr = &depPaths.LateSharedLibs
1248 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001249 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001250 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001251 ptr = nil
1252 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001253 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001254 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001255 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001256 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001257 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001258 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001259 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001260 return
1261 }
1262
1263 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001264 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001265 for i := range missingDeps {
1266 missingDeps[i] += postfix
1267 }
1268 ctx.AddMissingDependencies(missingDeps)
1269 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001270 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001271 case headerDepTag:
1272 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001273 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001274 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001275 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001276 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001277 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001278 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001279 }
1280
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001281 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001282 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001283 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001284 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001285 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001286 return
1287 }
1288
1289 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001290 // in static libraries act as if they were whole static libraries. The same goes for
1291 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001292 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1293 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001294 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1295 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001296
Dan Willemsen581341d2017-02-09 16:16:31 -08001297 }
1298
Colin Cross26c34ed2016-09-30 17:10:16 -07001299 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001300 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001301 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001302 return
1303 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001304 *ptr = append(*ptr, linkFile.Path())
1305 }
1306
Colin Crossc99deeb2016-04-11 15:06:20 -07001307 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001308 dep := depFile
1309 if !dep.Valid() {
1310 dep = linkFile
1311 }
1312 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001313 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001314
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001315 // Export the shared libs to Make.
1316 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001317 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001318 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001319 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001320 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001321 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001322 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001323 var makeLibName string
1324 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1325 if c.useVndk() && bothVendorAndCoreVariantsExist {
1326 // The vendor module in Make will have been renamed to not conflict with the core
1327 // module, so update the dependency name here accordingly.
1328 makeLibName = libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001329 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
1330 makeLibName = libName + vendorPublicLibrarySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001331 } else {
1332 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001333 }
1334 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001335 // they merely serve as Make dependencies and do not affect this lib itself.
1336 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001337 }
Colin Crossca860ac2016-01-04 14:34:37 -08001338 })
1339
Jeff Gaston294356f2017-09-27 17:05:30 -07001340 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001341 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001342
Colin Crossdd84e052017-05-17 13:44:16 -07001343 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001344 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001345 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001346 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001347 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1348
1349 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001350 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001351 }
Colin Crossdd84e052017-05-17 13:44:16 -07001352
Colin Crossca860ac2016-01-04 14:34:37 -08001353 return depPaths
1354}
1355
1356func (c *Module) InstallInData() bool {
1357 if c.installer == nil {
1358 return false
1359 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001360 return c.installer.inData()
1361}
1362
1363func (c *Module) InstallInSanitizerDir() bool {
1364 if c.installer == nil {
1365 return false
1366 }
1367 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001368 return true
1369 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001370 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001371}
1372
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001373func (c *Module) HostToolPath() android.OptionalPath {
1374 if c.installer == nil {
1375 return android.OptionalPath{}
1376 }
1377 return c.installer.hostToolPath()
1378}
1379
Nan Zhangd4e641b2017-07-12 12:55:28 -07001380func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1381 return c.outputFile
1382}
1383
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001384func (c *Module) Srcs() android.Paths {
1385 if c.outputFile.Valid() {
1386 return android.Paths{c.outputFile.Path()}
1387 }
1388 return android.Paths{}
1389}
1390
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001391func (c *Module) static() bool {
1392 if static, ok := c.linker.(interface {
1393 static() bool
1394 }); ok {
1395 return static.static()
1396 }
1397 return false
1398}
1399
Colin Cross2ba19d92015-05-07 15:44:20 -07001400//
Colin Crosscfad1192015-11-02 16:43:11 -08001401// Defaults
1402//
Colin Crossca860ac2016-01-04 14:34:37 -08001403type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001404 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001405 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001406}
1407
Colin Cross635c3b02016-05-18 15:37:25 -07001408func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001409}
1410
Colin Cross1e676be2016-10-12 14:38:15 -07001411func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1412}
1413
Colin Cross36242852017-06-23 15:06:31 -07001414func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001415 return DefaultsFactory()
1416}
1417
Colin Cross36242852017-06-23 15:06:31 -07001418func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001419 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001420
Colin Cross36242852017-06-23 15:06:31 -07001421 module.AddProperties(props...)
1422 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001423 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001424 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001425 &BaseCompilerProperties{},
1426 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001427 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001428 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001429 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001430 &TestProperties{},
1431 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001432 &UnusedProperties{},
1433 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001434 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001435 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001436 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001437 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001438 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001439 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001440 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001441 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001442 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001443 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001444 )
Colin Crosscfad1192015-11-02 16:43:11 -08001445
Colin Cross1f44a3a2017-07-07 14:33:33 -07001446 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001447
1448 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001449}
1450
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001451const (
1452 // coreMode is the variant used for framework-private libraries, or
1453 // SDK libraries. (which framework-private libraries can use)
1454 coreMode = "core"
1455
1456 // vendorMode is the variant used for /vendor code that compiles
1457 // against the VNDK.
1458 vendorMode = "vendor"
1459)
1460
Jiyong Park6a43f042017-10-12 23:05:00 +09001461func squashVendorSrcs(m *Module) {
1462 if lib, ok := m.compiler.(*libraryDecorator); ok {
1463 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1464 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1465
1466 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1467 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1468 }
1469}
1470
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001471func vendorMutator(mctx android.BottomUpMutatorContext) {
1472 if mctx.Os() != android.Android {
1473 return
1474 }
1475
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001476 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1477 if props, ok := genrule.Extra.(*VendorProperties); ok {
Justin Yun71549282017-11-17 12:10:28 +09001478 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001479 mctx.CreateVariations(coreMode)
1480 } else if Bool(props.Vendor_available) {
1481 mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park2db76922017-11-08 16:03:48 +09001482 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001483 mctx.CreateVariations(vendorMode)
1484 } else {
1485 mctx.CreateVariations(coreMode)
1486 }
1487 }
1488 }
1489
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001490 m, ok := mctx.Module().(*Module)
1491 if !ok {
1492 return
1493 }
1494
1495 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001496 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
1497
1498 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001499 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001500 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001501 return
1502 }
Logan Chienf3511742017-10-31 18:04:35 +08001503
1504 if vndkdep := m.vndkdep; vndkdep != nil {
1505 if vndkdep.isVndk() {
1506 if vendorSpecific {
1507 if !vndkdep.isVndkExt() {
1508 mctx.PropertyErrorf("vndk",
1509 "must set `extends: \"...\"` to vndk extension")
1510 return
1511 }
1512 } else {
1513 if vndkdep.isVndkExt() {
1514 mctx.PropertyErrorf("vndk",
1515 "must set `vendor: true` to set `extends: %q`",
1516 m.getVndkExtendsModuleName())
1517 return
1518 }
1519 if m.VendorProperties.Vendor_available == nil {
1520 mctx.PropertyErrorf("vndk",
1521 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1522 return
1523 }
1524 }
1525 } else {
1526 if vndkdep.isVndkSp() {
1527 mctx.PropertyErrorf("vndk",
1528 "must set `enabled: true` to set `support_system_process: true`")
1529 return
1530 }
1531 if vndkdep.isVndkExt() {
1532 mctx.PropertyErrorf("vndk",
1533 "must set `enabled: true` to set `extends: %q`",
1534 m.getVndkExtendsModuleName())
1535 return
1536 }
Justin Yun8effde42017-06-23 19:24:43 +09001537 }
1538 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001539
Justin Yun71549282017-11-17 12:10:28 +09001540 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001541 // If the device isn't compiling against the VNDK, we always
1542 // use the core mode.
1543 mctx.CreateVariations(coreMode)
1544 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1545 // LL-NDK stubs only exist in the vendor variant, since the
1546 // real libraries will be used in the core variant.
1547 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001548 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1549 // ... and LL-NDK headers as well
Jiyong Parka46a4d52017-12-14 19:54:34 +09001550 mod := mctx.CreateVariations(vendorMode)
1551 vendor := mod[0].(*Module)
1552 vendor.Properties.UseVndk = true
Justin Yun312ccb92018-01-23 12:07:46 +09001553 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001554 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1555 // PRODUCT_EXTRA_VNDK_VERSIONS.
1556 mod := mctx.CreateVariations(vendorMode)
1557 vendor := mod[0].(*Module)
1558 vendor.Properties.UseVndk = true
Logan Chienf3511742017-10-31 18:04:35 +08001559 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001560 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001561 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001562 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001563 vendor := mod[1].(*Module)
1564 vendor.Properties.UseVndk = true
1565 squashVendorSrcs(vendor)
Logan Chienf3511742017-10-31 18:04:35 +08001566 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001567 // This will be available in /vendor (or /odm) only
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001568 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001569 vendor := mod[0].(*Module)
1570 vendor.Properties.UseVndk = true
1571 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001572 } else {
1573 // This is either in /system (or similar: /data), or is a
1574 // modules built with the NDK. Modules built with the NDK
1575 // will be restricted using the existing link type checks.
1576 mctx.CreateVariations(coreMode)
1577 }
1578}
1579
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001580func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08001581 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001582 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1583 }
Colin Cross6510f912017-11-29 00:27:14 -08001584 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001585}
1586
Colin Cross06a931b2015-10-28 17:23:31 -07001587var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001588var BoolPtr = proptools.BoolPtr
1589var String = proptools.String
1590var StringPtr = proptools.StringPtr