blob: 384b24073c023da28c22fdbcb3f78ed2693b8e0f [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Park6a43f042017-10-12 23:05:00 +090037 ctx.BottomUp("image", vendorMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070038 ctx.BottomUp("link", linkageMutator).Parallel()
Jiyong Parkd5b18a52017-08-03 21:22:50 +090039 ctx.BottomUp("vndk", vndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
42 ctx.BottomUp("begin", beginMutator).Parallel()
43 })
Colin Cross16b23492016-01-06 14:41:07 -080044
Colin Cross1e676be2016-10-12 14:38:15 -070045 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
46 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
47 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080048
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000049 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
50 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
51
Colin Cross1e676be2016-10-12 14:38:15 -070052 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
53 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080054
55 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080056 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070057
58 ctx.TopDown("lto_deps", ltoDepsMutator)
59 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070060 })
Colin Crossb98c8b02016-07-29 13:44:28 -070061
62 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070063}
64
Colin Crossca860ac2016-01-04 14:34:37 -080065type Deps struct {
66 SharedLibs, LateSharedLibs []string
67 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080068 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070069
Colin Cross5950f382016-12-13 12:50:57 -080070 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070071
Colin Cross81413472016-04-11 14:37:39 -070072 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070073
Dan Willemsenb40aab62016-04-20 14:21:14 -070074 GeneratedSources []string
75 GeneratedHeaders []string
76
Dan Willemsenb3454ab2016-09-28 17:34:58 -070077 ReexportGeneratedHeaders []string
78
Colin Cross97ba0732015-03-23 17:50:24 -070079 CrtBegin, CrtEnd string
Dan Willemsenc77a0b32017-09-18 23:19:12 -070080 LinkerScript string
Colin Crossc472d572015-03-17 15:06:21 -070081}
82
Colin Crossca860ac2016-01-04 14:34:37 -080083type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070084 // Paths to .so files
85 SharedLibs, LateSharedLibs android.Paths
86 // Paths to the dependencies to use for .so files (.so.toc files)
87 SharedLibsDeps, LateSharedLibsDeps android.Paths
88 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070089 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070090
Colin Cross26c34ed2016-09-30 17:10:16 -070091 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070092 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080093 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070094 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Colin Cross26c34ed2016-09-30 17:10:16 -070096 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070097 GeneratedSources android.Paths
98 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070099
Dan Willemsen76f08272016-07-09 00:14:08 -0700100 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700101 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700102
Colin Cross26c34ed2016-09-30 17:10:16 -0700103 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700104 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700105 LinkerScript android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700106}
107
Colin Crossca860ac2016-01-04 14:34:37 -0800108type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700109 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
110 ArFlags []string // Flags that apply to ar
111 AsFlags []string // Flags that apply to assembly source files
112 CFlags []string // Flags that apply to C and C++ source files
113 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
114 ConlyFlags []string // Flags that apply to C source files
115 CppFlags []string // Flags that apply to C++ source files
116 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
117 YaccFlags []string // Flags that apply to Yacc source files
118 protoFlags []string // Flags that apply to proto source files
119 aidlFlags []string // Flags that apply to aidl source files
120 rsFlags []string // Flags that apply to renderscript source files
121 LdFlags []string // Flags that apply to linker command lines
122 libFlags []string // Flags to add libraries early to the link order
123 TidyFlags []string // Flags that apply to clang-tidy
124 SAbiFlags []string // Flags that apply to header-abi-dumper
125 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700126
Colin Crossc3199482017-03-30 15:03:04 -0700127 // Global include flags that apply to C, C++, and assembly source files
128 // These must be after any module include flags, which will be in GlobalFlags.
129 SystemIncludeFlags []string
130
Colin Crossb98c8b02016-07-29 13:44:28 -0700131 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700132 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700133 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800134 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800135 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800136
137 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800138 DynamicLinker string
139
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700140 CFlagsDeps android.Paths // Files depended on by compiler flags
141 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800142
143 GroupStaticLibs bool
Colin Crossc472d572015-03-17 15:06:21 -0700144}
145
Colin Cross81413472016-04-11 14:37:39 -0700146type ObjectLinkerProperties struct {
147 // names of other cc_object modules to link into this module using partial linking
148 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700149
150 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800151 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700152}
153
Colin Crossca860ac2016-01-04 14:34:37 -0800154// Properties used to compile all C or C++ modules
155type BaseProperties struct {
156 // compile module with clang instead of gcc
157 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700158
159 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800160 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700161
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700162 AndroidMkSharedLibs []string `blueprint:"mutated"`
163 HideFromMake bool `blueprint:"mutated"`
164 PreventInstall bool `blueprint:"mutated"`
165
166 UseVndk bool `blueprint:"mutated"`
167}
168
169type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900170 // whether this module should be allowed to be directly depended by other
171 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
172 // If set to true, two variants will be built separately, one like
173 // normal, and the other limited to the set of libraries and headers
174 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700175 //
176 // The vendor variant may be used with a different (newer) /system,
177 // so it shouldn't have any unversioned runtime dependencies, or
178 // make assumptions about the system that may not be true in the
179 // future.
180 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900181 // If set to false, this module becomes inaccessible from /vendor modules.
182 //
183 // Default value is true when vndk: {enabled: true} or vendor: true.
184 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700185 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
186 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800187}
188
Colin Crossca860ac2016-01-04 14:34:37 -0800189type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800190 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800191}
192
Colin Crossca860ac2016-01-04 14:34:37 -0800193type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800194 static() bool
195 staticBinary() bool
196 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700197 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700198 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800199 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700200 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900201 isVndk() bool
202 isVndkSp() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800203 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700204 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700205 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800206}
207
208type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700209 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800210 ModuleContextIntf
211}
212
213type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700214 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800215 ModuleContextIntf
216}
217
Colin Cross37047f12016-12-13 17:06:13 -0800218type DepsContext interface {
219 android.BottomUpMutatorContext
220 ModuleContextIntf
221}
222
Colin Crossca860ac2016-01-04 14:34:37 -0800223type feature interface {
224 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800225 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800226 flags(ctx ModuleContext, flags Flags) Flags
227 props() []interface{}
228}
229
230type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700231 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800232 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800233 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700234 compilerProps() []interface{}
235
Colin Cross76fada02016-07-27 10:31:13 -0700236 appendCflags([]string)
237 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700238 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800239}
240
241type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700242 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800243 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700244 linkerFlags(ctx ModuleContext, flags Flags) Flags
245 linkerProps() []interface{}
246
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700247 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700248 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800249}
250
251type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700252 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700253 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800254 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700255 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700256 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800257}
258
Colin Crossc99deeb2016-04-11 15:06:20 -0700259type dependencyTag struct {
260 blueprint.BaseDependencyTag
261 name string
262 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700263
264 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700265}
266
267var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700268 sharedDepTag = dependencyTag{name: "shared", library: true}
269 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
270 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
271 staticDepTag = dependencyTag{name: "static", library: true}
272 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
273 lateStaticDepTag = dependencyTag{name: "late static", library: true}
274 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800275 headerDepTag = dependencyTag{name: "header", library: true}
276 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700277 genSourceDepTag = dependencyTag{name: "gen source"}
278 genHeaderDepTag = dependencyTag{name: "gen header"}
279 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
280 objDepTag = dependencyTag{name: "obj"}
281 crtBeginDepTag = dependencyTag{name: "crtbegin"}
282 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700283 linkerScriptDepTag = dependencyTag{name: "linker script"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700284 reuseObjTag = dependencyTag{name: "reuse objects"}
285 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
286 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700287)
288
Colin Crossca860ac2016-01-04 14:34:37 -0800289// Module contains the properties and members used by all C/C++ module types, and implements
290// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
291// to construct the output file. Behavior can be customized with a Customizer interface
292type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700293 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700294 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700295
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700296 Properties BaseProperties
297 VendorProperties VendorProperties
298 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700299
Colin Crossca860ac2016-01-04 14:34:37 -0800300 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700301 hod android.HostOrDeviceSupported
302 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700303
Colin Crossca860ac2016-01-04 14:34:37 -0800304 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700305 features []feature
306 compiler compiler
307 linker linker
308 installer installer
309 stl *stl
310 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800311 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800312 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900313 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700314 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700315 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800316
317 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700318
Colin Cross635c3b02016-05-18 15:37:25 -0700319 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800320
Colin Crossb98c8b02016-07-29 13:44:28 -0700321 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700322
323 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800324
325 // Flags used to compile this module
326 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700327
328 // When calling a linker, if module A depends on module B, then A must precede B in its command
329 // line invocation. staticDepsInLinkOrder stores the proper ordering of all of the transitive
330 // deps of this module
331 staticDepsInLinkOrder android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700332}
333
Colin Cross36242852017-06-23 15:06:31 -0700334func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700335 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800336 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700337 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800338 }
339 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700340 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800341 }
342 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700343 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800344 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700345 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700346 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700347 }
Colin Cross16b23492016-01-06 14:41:07 -0800348 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700349 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800350 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800351 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700352 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800353 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800354 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700355 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800356 }
Justin Yun8effde42017-06-23 19:24:43 +0900357 if c.vndkdep != nil {
358 c.AddProperties(c.vndkdep.props()...)
359 }
Stephen Craneba090d12017-05-09 15:44:35 -0700360 if c.lto != nil {
361 c.AddProperties(c.lto.props()...)
362 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700363 if c.pgo != nil {
364 c.AddProperties(c.pgo.props()...)
365 }
Colin Crossca860ac2016-01-04 14:34:37 -0800366 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700367 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800368 }
Colin Crossc472d572015-03-17 15:06:21 -0700369
Colin Cross36242852017-06-23 15:06:31 -0700370 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700371
Colin Cross1f44a3a2017-07-07 14:33:33 -0700372 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700373
374 return c
Colin Crossc472d572015-03-17 15:06:21 -0700375}
376
Colin Crossb916a382016-07-29 17:28:03 -0700377// Returns true for dependency roots (binaries)
378// TODO(ccross): also handle dlopenable libraries
379func (c *Module) isDependencyRoot() bool {
380 if root, ok := c.linker.(interface {
381 isDependencyRoot() bool
382 }); ok {
383 return root.isDependencyRoot()
384 }
385 return false
386}
387
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700388func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700389 return c.Properties.UseVndk
390}
391
Justin Yun8effde42017-06-23 19:24:43 +0900392func (c *Module) isVndk() bool {
393 if c.vndkdep != nil {
394 return c.vndkdep.isVndk()
395 }
396 return false
397}
398
Jiyong Park82e2bf32017-08-16 14:05:54 +0900399// Returns true only when this module is configured to have core and vendor
400// variants.
401func (c *Module) hasVendorVariant() bool {
402 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
403}
404
Colin Crossca860ac2016-01-04 14:34:37 -0800405type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700406 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800407 moduleContextImpl
408}
409
Colin Cross37047f12016-12-13 17:06:13 -0800410type depsContext struct {
411 android.BottomUpMutatorContext
412 moduleContextImpl
413}
414
Colin Crossca860ac2016-01-04 14:34:37 -0800415type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700416 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800417 moduleContextImpl
418}
419
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700420func (ctx *moduleContext) InstallOnVendorPartition() bool {
421 return ctx.ModuleContext.InstallOnVendorPartition() || (ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700422}
423
Colin Crossca860ac2016-01-04 14:34:37 -0800424type moduleContextImpl struct {
425 mod *Module
426 ctx BaseModuleContext
427}
428
Colin Crossca860ac2016-01-04 14:34:37 -0800429func (ctx *moduleContextImpl) clang() bool {
430 return ctx.mod.clang(ctx.ctx)
431}
432
Colin Crossb98c8b02016-07-29 13:44:28 -0700433func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800434 return ctx.mod.toolchain(ctx.ctx)
435}
436
437func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000438 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800439}
440
441func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700442 if static, ok := ctx.mod.linker.(interface {
443 staticBinary() bool
444 }); ok {
445 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800446 }
Colin Crossb916a382016-07-29 17:28:03 -0700447 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800448}
449
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700450func (ctx *moduleContextImpl) useSdk() bool {
451 if ctx.ctx.Device() && !ctx.useVndk() {
Nan Zhang0007d812017-11-07 10:57:05 -0800452 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700453 }
454 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800455}
456
457func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700458 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700459 if ctx.useVndk() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700460 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800461 } else {
Nan Zhang0007d812017-11-07 10:57:05 -0800462 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsend2ede872016-11-18 14:54:24 -0800463 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700464 }
465 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800466}
467
Justin Yun8effde42017-06-23 19:24:43 +0900468func (ctx *moduleContextImpl) isVndk() bool {
469 return ctx.mod.isVndk()
470}
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700471func (ctx *moduleContextImpl) useVndk() bool {
472 return ctx.mod.useVndk()
473}
Justin Yun8effde42017-06-23 19:24:43 +0900474
475func (ctx *moduleContextImpl) isVndkSp() bool {
476 if vndk := ctx.mod.vndkdep; vndk != nil {
477 return vndk.isVndkSp()
478 }
479 return false
480}
481
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800482// Create source abi dumps if the module belongs to the list of VndkLibraries.
483func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700484 return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800485}
486
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700487func (ctx *moduleContextImpl) selectedStl() string {
488 if stl := ctx.mod.stl; stl != nil {
489 return stl.Properties.SelectedStl
490 }
491 return ""
492}
493
Colin Crossce75d2c2016-10-06 16:12:58 -0700494func (ctx *moduleContextImpl) baseModuleName() string {
495 return ctx.mod.ModuleBase.BaseModuleName()
496}
497
Colin Cross635c3b02016-05-18 15:37:25 -0700498func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800499 return &Module{
500 hod: hod,
501 multilib: multilib,
502 }
503}
504
Colin Cross635c3b02016-05-18 15:37:25 -0700505func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800506 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700507 module.features = []feature{
508 &tidyFeature{},
509 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700510 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800511 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800512 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800513 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900514 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700515 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700516 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -0800517 return module
518}
519
Colin Crossce75d2c2016-10-06 16:12:58 -0700520func (c *Module) Prebuilt() *android.Prebuilt {
521 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
522 return p.prebuilt()
523 }
524 return nil
525}
526
527func (c *Module) Name() string {
528 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700529 if p, ok := c.linker.(interface {
530 Name(string) string
531 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700532 name = p.Name(name)
533 }
534 return name
535}
536
Jeff Gaston294356f2017-09-27 17:05:30 -0700537// orderDeps reorders dependencies into a list such that if module A depends on B, then
538// A will precede B in the resultant list.
539// This is convenient for passing into a linker.
540func orderDeps(directDeps []android.Path, transitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) {
541 // If A depends on B, then
542 // Every list containing A will also contain B later in the list
543 // So, after concatenating all lists, the final instance of B will have come from the same
544 // original list as the final instance of A
545 // So, the final instance of B will be later in the concatenation than the final A
546 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
547 // list than B
548 for _, dep := range directDeps {
549 orderedAllDeps = append(orderedAllDeps, dep)
550 orderedAllDeps = append(orderedAllDeps, transitiveDeps[dep]...)
551 }
552
Colin Crossb6715442017-10-24 11:13:31 -0700553 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700554
555 // We don't want to add any new dependencies into directDeps (to allow the caller to
556 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
557 // resultant list to only what the caller has chosen to include in directDeps
558 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directDeps)
559
560 return orderedAllDeps, orderedDeclaredDeps
561}
562
563func orderStaticModuleDeps(module *Module, deps []*Module) (results []android.Path) {
564 // make map of transitive dependencies
565 transitiveStaticDepNames := make(map[android.Path][]android.Path, len(deps))
566 for _, dep := range deps {
567 transitiveStaticDepNames[dep.outputFile.Path()] = dep.staticDepsInLinkOrder
568 }
569 // get the output file for each declared dependency
570 depFiles := []android.Path{}
571 for _, dep := range deps {
572 depFiles = append(depFiles, dep.outputFile.Path())
573 }
574
575 // reorder the dependencies based on transitive dependencies
576 module.staticDepsInLinkOrder, results = orderDeps(depFiles, transitiveStaticDepNames)
577
578 return results
579
580}
581
Colin Cross635c3b02016-05-18 15:37:25 -0700582func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700583
Colin Crossca860ac2016-01-04 14:34:37 -0800584 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700585 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800586 moduleContextImpl: moduleContextImpl{
587 mod: c,
588 },
589 }
590 ctx.ctx = ctx
591
Colin Crossf18e1102017-11-16 14:33:08 -0800592 deps := c.depsToPaths(ctx)
593 if ctx.Failed() {
594 return
595 }
596
Colin Crossca860ac2016-01-04 14:34:37 -0800597 flags := Flags{
598 Toolchain: c.toolchain(ctx),
599 Clang: c.clang(ctx),
600 }
Colin Crossca860ac2016-01-04 14:34:37 -0800601 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800602 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800603 }
604 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700605 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800606 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700607 if c.stl != nil {
608 flags = c.stl.flags(ctx, flags)
609 }
Colin Cross16b23492016-01-06 14:41:07 -0800610 if c.sanitize != nil {
611 flags = c.sanitize.flags(ctx, flags)
612 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800613 if c.coverage != nil {
614 flags = c.coverage.flags(ctx, flags)
615 }
Stephen Craneba090d12017-05-09 15:44:35 -0700616 if c.lto != nil {
617 flags = c.lto.flags(ctx, flags)
618 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700619 if c.pgo != nil {
620 flags = c.pgo.flags(ctx, flags)
621 }
Colin Crossca860ac2016-01-04 14:34:37 -0800622 for _, feature := range c.features {
623 flags = feature.flags(ctx, flags)
624 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800625 if ctx.Failed() {
626 return
627 }
628
Colin Crossb98c8b02016-07-29 13:44:28 -0700629 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
630 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
631 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800632
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800633 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
634 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700635 // We need access to all the flags seen by a source file.
636 if c.sabi != nil {
637 flags = c.sabi.flags(ctx, flags)
638 }
Colin Crossca860ac2016-01-04 14:34:37 -0800639 // Optimization to reduce size of build.ninja
640 // Replace the long list of flags for each file with a module-local variable
641 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
642 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
643 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
644 flags.CFlags = []string{"$cflags"}
645 flags.CppFlags = []string{"$cppflags"}
646 flags.AsFlags = []string{"$asflags"}
647
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700648 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800649 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700650 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800651 if ctx.Failed() {
652 return
653 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800654 }
655
Colin Crossca860ac2016-01-04 14:34:37 -0800656 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700657 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800658 if ctx.Failed() {
659 return
660 }
Colin Cross635c3b02016-05-18 15:37:25 -0700661 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700662 }
Colin Cross5049f022015-03-18 13:28:46 -0700663
Colin Crossce75d2c2016-10-06 16:12:58 -0700664 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
665 c.installer.install(ctx, c.outputFile.Path())
666 if ctx.Failed() {
667 return
Colin Crossca860ac2016-01-04 14:34:37 -0800668 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700669 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800670}
671
Colin Crossb98c8b02016-07-29 13:44:28 -0700672func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800673 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700674 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800675 }
Colin Crossca860ac2016-01-04 14:34:37 -0800676 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800677}
678
Colin Crossca860ac2016-01-04 14:34:37 -0800679func (c *Module) begin(ctx BaseModuleContext) {
680 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700681 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700682 }
Colin Crossca860ac2016-01-04 14:34:37 -0800683 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700684 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800685 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700686 if c.stl != nil {
687 c.stl.begin(ctx)
688 }
Colin Cross16b23492016-01-06 14:41:07 -0800689 if c.sanitize != nil {
690 c.sanitize.begin(ctx)
691 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800692 if c.coverage != nil {
693 c.coverage.begin(ctx)
694 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800695 if c.sabi != nil {
696 c.sabi.begin(ctx)
697 }
Justin Yun8effde42017-06-23 19:24:43 +0900698 if c.vndkdep != nil {
699 c.vndkdep.begin(ctx)
700 }
Stephen Craneba090d12017-05-09 15:44:35 -0700701 if c.lto != nil {
702 c.lto.begin(ctx)
703 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700704 if c.pgo != nil {
705 c.pgo.begin(ctx)
706 }
Colin Crossca860ac2016-01-04 14:34:37 -0800707 for _, feature := range c.features {
708 feature.begin(ctx)
709 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700710 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700711 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700712 if err != nil {
713 ctx.PropertyErrorf("sdk_version", err.Error())
714 }
Nan Zhang0007d812017-11-07 10:57:05 -0800715 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700716 }
Colin Crossca860ac2016-01-04 14:34:37 -0800717}
718
Colin Cross37047f12016-12-13 17:06:13 -0800719func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700720 deps := Deps{}
721
722 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700723 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700724 }
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700725 // Add the PGO dependency (the clang_rt.profile runtime library), which
726 // sometimes depends on symbols from libgcc, before libgcc gets added
727 // in linkerDeps().
728 if c.pgo != nil {
729 deps = c.pgo.deps(ctx, deps)
730 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700731 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700732 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700733 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700734 if c.stl != nil {
735 deps = c.stl.deps(ctx, deps)
736 }
Colin Cross16b23492016-01-06 14:41:07 -0800737 if c.sanitize != nil {
738 deps = c.sanitize.deps(ctx, deps)
739 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800740 if c.coverage != nil {
741 deps = c.coverage.deps(ctx, deps)
742 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800743 if c.sabi != nil {
744 deps = c.sabi.deps(ctx, deps)
745 }
Justin Yun8effde42017-06-23 19:24:43 +0900746 if c.vndkdep != nil {
747 deps = c.vndkdep.deps(ctx, deps)
748 }
Stephen Craneba090d12017-05-09 15:44:35 -0700749 if c.lto != nil {
750 deps = c.lto.deps(ctx, deps)
751 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700752 for _, feature := range c.features {
753 deps = feature.deps(ctx, deps)
754 }
755
Colin Crossb6715442017-10-24 11:13:31 -0700756 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
757 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
758 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
759 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
760 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
761 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700762
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700763 for _, lib := range deps.ReexportSharedLibHeaders {
764 if !inList(lib, deps.SharedLibs) {
765 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
766 }
767 }
768
769 for _, lib := range deps.ReexportStaticLibHeaders {
770 if !inList(lib, deps.StaticLibs) {
771 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
772 }
773 }
774
Colin Cross5950f382016-12-13 12:50:57 -0800775 for _, lib := range deps.ReexportHeaderLibHeaders {
776 if !inList(lib, deps.HeaderLibs) {
777 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
778 }
779 }
780
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700781 for _, gen := range deps.ReexportGeneratedHeaders {
782 if !inList(gen, deps.GeneratedHeaders) {
783 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
784 }
785 }
786
Colin Crossc99deeb2016-04-11 15:06:20 -0700787 return deps
788}
789
Dan Albert7e9d2952016-08-04 13:02:36 -0700790func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800791 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700792 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800793 moduleContextImpl: moduleContextImpl{
794 mod: c,
795 },
796 }
797 ctx.ctx = ctx
798
Colin Crossca860ac2016-01-04 14:34:37 -0800799 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700800}
801
Colin Cross1e676be2016-10-12 14:38:15 -0700802func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
803 if !c.Enabled() {
804 return
805 }
806
Colin Cross37047f12016-12-13 17:06:13 -0800807 ctx := &depsContext{
808 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700809 moduleContextImpl: moduleContextImpl{
810 mod: c,
811 },
812 }
813 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800814
Colin Crossc99deeb2016-04-11 15:06:20 -0700815 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800816
Dan Albert914449f2016-06-17 16:45:24 -0700817 variantNdkLibs := []string{}
818 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700819 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700820 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700821
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700822 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
823 // of names:
Dan Albert914449f2016-06-17 16:45:24 -0700824 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700825 // 1. Name of an NDK library that refers to a prebuilt module.
826 // For each of these, it adds the name of the prebuilt module (which will be in
827 // prebuilts/ndk) to the list of nonvariant libs.
828 // 2. Name of an NDK library that refers to an ndk_library module.
829 // For each of these, it adds the name of the ndk_library module to the list of
830 // variant libs.
831 // 3. Anything else (so anything that isn't an NDK library).
832 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -0700833 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700834 // The caller can then know to add the variantLibs dependencies differently from the
835 // nonvariantLibs
836 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
837 variantLibs = []string{}
838 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -0700839 for _, entry := range list {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700840 if ctx.useSdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700841 if !inList(entry, ndkMigratedLibs) {
842 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
843 } else {
844 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
845 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700846 } else if ctx.useVndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700847 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700848 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700849 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700850 }
851 }
Dan Albert914449f2016-06-17 16:45:24 -0700852 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700853 }
854
Dan Albert914449f2016-06-17 16:45:24 -0700855 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
856 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900857 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700858 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700859
Colin Cross32ec36c2016-12-15 07:39:51 -0800860 for _, lib := range deps.HeaderLibs {
861 depTag := headerDepTag
862 if inList(lib, deps.ReexportHeaderLibHeaders) {
863 depTag = headerExportDepTag
864 }
865 actx.AddVariationDependencies(nil, depTag, lib)
866 }
Colin Cross5950f382016-12-13 12:50:57 -0800867
Colin Crossc99deeb2016-04-11 15:06:20 -0700868 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
869 deps.WholeStaticLibs...)
870
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700871 for _, lib := range deps.StaticLibs {
872 depTag := staticDepTag
873 if inList(lib, deps.ReexportStaticLibHeaders) {
874 depTag = staticExportDepTag
875 }
Colin Cross15a0d462016-07-14 14:49:58 -0700876 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700877 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700878
879 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
880 deps.LateStaticLibs...)
881
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700882 for _, lib := range deps.SharedLibs {
883 depTag := sharedDepTag
884 if inList(lib, deps.ReexportSharedLibHeaders) {
885 depTag = sharedExportDepTag
886 }
Colin Cross15a0d462016-07-14 14:49:58 -0700887 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700888 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700889
890 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
891 deps.LateSharedLibs...)
892
Colin Cross68861832016-07-08 10:41:41 -0700893 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700894
895 for _, gen := range deps.GeneratedHeaders {
896 depTag := genHeaderDepTag
897 if inList(gen, deps.ReexportGeneratedHeaders) {
898 depTag = genHeaderExportDepTag
899 }
900 actx.AddDependency(c, depTag, gen)
901 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700902
Colin Cross68861832016-07-08 10:41:41 -0700903 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700904
905 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700906 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800907 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700908 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700909 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700910 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -0700911 if deps.LinkerScript != "" {
912 actx.AddDependency(c, linkerScriptDepTag, deps.LinkerScript)
913 }
Dan Albert914449f2016-06-17 16:45:24 -0700914
915 version := ctx.sdkVersion()
916 actx.AddVariationDependencies([]blueprint.Variation{
917 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
918 actx.AddVariationDependencies([]blueprint.Variation{
919 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700920}
Colin Cross21b9a242015-03-24 14:15:58 -0700921
Dan Albert7e9d2952016-08-04 13:02:36 -0700922func beginMutator(ctx android.BottomUpMutatorContext) {
923 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
924 c.beginMutator(ctx)
925 }
926}
927
Colin Crossca860ac2016-01-04 14:34:37 -0800928func (c *Module) clang(ctx BaseModuleContext) bool {
929 clang := Bool(c.Properties.Clang)
930
931 if c.Properties.Clang == nil {
932 if ctx.Host() {
933 clang = true
934 }
935
936 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
937 clang = true
938 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800939 }
Colin Cross28344522015-04-22 13:07:53 -0700940
Colin Crossca860ac2016-01-04 14:34:37 -0800941 if !c.toolchain(ctx).ClangSupported() {
942 clang = false
943 }
944
945 return clang
946}
947
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700948// Whether a module can link to another module, taking into
949// account NDK linking.
950func checkLinkType(ctx android.ModuleContext, from *Module, to *Module) {
951 if from.Target().Os != android.Android {
952 // Host code is not restricted
953 return
954 }
955 if from.Properties.UseVndk {
956 // Though vendor code is limited by the vendor mutator,
957 // each vendor-available module needs to check
958 // link-type for VNDK.
959 if from.vndkdep != nil {
960 from.vndkdep.vndkCheckLinkType(ctx, to)
961 }
962 return
963 }
Nan Zhang0007d812017-11-07 10:57:05 -0800964 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700965 // Platform code can link to anything
966 return
967 }
968 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
969 // These are always allowed
970 return
971 }
972 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
973 // These are allowed, but they don't set sdk_version
974 return
975 }
976 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
977 // These are allowed, but they don't set sdk_version
978 return
979 }
980 if _, ok := to.linker.(*stubDecorator); ok {
981 // These aren't real libraries, but are the stub shared libraries that are included in
982 // the NDK.
983 return
984 }
Nan Zhang0007d812017-11-07 10:57:05 -0800985 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700986 // NDK code linking to platform code is never okay.
987 ctx.ModuleErrorf("depends on non-NDK-built library %q",
988 ctx.OtherModuleName(to))
989 }
990
991 // At this point we know we have two NDK libraries, but we need to
992 // check that we're not linking against anything built against a higher
993 // API level, as it is only valid to link against older or equivalent
994 // APIs.
995
Nan Zhang0007d812017-11-07 10:57:05 -0800996 if String(from.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700997 // Current can link against anything.
998 return
Nan Zhang0007d812017-11-07 10:57:05 -0800999 } else if String(to.Properties.Sdk_version) == "current" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001000 // Current can't be linked against by anything else.
1001 ctx.ModuleErrorf("links %q built against newer API version %q",
1002 ctx.OtherModuleName(to), "current")
1003 }
1004
Nan Zhang0007d812017-11-07 10:57:05 -08001005 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001006 if err != nil {
1007 ctx.PropertyErrorf("sdk_version",
1008 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001009 String(from.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001010 }
Nan Zhang0007d812017-11-07 10:57:05 -08001011 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001012 if err != nil {
1013 ctx.PropertyErrorf("sdk_version",
1014 "Invalid sdk_version value (must be int): %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001015 String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001016 }
1017
1018 if toApi > fromApi {
1019 ctx.ModuleErrorf("links %q built against newer API version %q",
Nan Zhang0007d812017-11-07 10:57:05 -08001020 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001021 }
1022}
1023
Colin Crossc99deeb2016-04-11 15:06:20 -07001024// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001025func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001026 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001027
Jeff Gaston294356f2017-09-27 17:05:30 -07001028 directStaticDeps := []*Module{}
1029
Colin Crossd11fcda2017-10-23 17:59:01 -07001030 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001031 depName := ctx.OtherModuleName(dep)
1032 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001033
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001034 ccDep, _ := dep.(*Module)
1035 if ccDep == nil {
1036 // handling for a few module types that aren't cc Module but that are also supported
1037 switch depTag {
Colin Cross068e0fe2016-12-13 15:23:47 -08001038 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -07001039 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -07001040 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001041 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001042 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1043 genRule.GeneratedSourceFiles()...)
1044 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001045 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001046 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001047 // Support exported headers from a generated_sources dependency
1048 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001049 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001050 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001051 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
1052 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001053 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001054 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001055 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001056 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001057 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
1058 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001059 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1060 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1061
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001062 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001063 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001064 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001065 }
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001066 case linkerScriptDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001067 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001068 files := genRule.GeneratedSourceFiles()
1069 if len(files) == 1 {
1070 depPaths.LinkerScript = android.OptionalPathForPath(files[0])
1071 } else if len(files) > 1 {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001072 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001073 }
1074 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001075 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001076 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001077 default:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001078 ctx.ModuleErrorf("depends on non-cc module %q", depName)
Colin Crossca860ac2016-01-04 14:34:37 -08001079 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001080 return
1081 }
1082
Colin Crossd11fcda2017-10-23 17:59:01 -07001083 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001084 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1085 return
1086 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001087 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001088 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001089 return
1090 }
1091
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001092 // re-exporting flags
1093 if depTag == reuseObjTag {
1094 if l, ok := ccDep.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001095 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001096 depPaths.Objs = depPaths.Objs.Append(objs)
1097 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001098 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001099 return
1100 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001101 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001102 if t, ok := depTag.(dependencyTag); ok && t.library {
1103 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001104 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001105 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001106 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001107 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001108
1109 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001110 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001111 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001112 // 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 -07001113 // Re-exported shared library headers must be included as well since they can help us with type information
1114 // about template instantiations (instantiated from their headers).
1115 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001116 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001117 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001118
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001119 checkLinkType(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001120 }
1121
Colin Cross26c34ed2016-09-30 17:10:16 -07001122 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001123 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001124
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001125 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001126 depFile := android.OptionalPath{}
1127
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001128 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001129 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001130 ptr = &depPaths.SharedLibs
1131 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001132 depFile = ccDep.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001133 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001134 ptr = &depPaths.LateSharedLibs
1135 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001136 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001137 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001138 ptr = nil
1139 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001140 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001141 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001142 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001143 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001144 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001145 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001146 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001147 return
1148 }
1149
1150 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001151 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001152 for i := range missingDeps {
1153 missingDeps[i] += postfix
1154 }
1155 ctx.AddMissingDependencies(missingDeps)
1156 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001157 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001158 case headerDepTag:
1159 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001160 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001161 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001162 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001163 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001164 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001165 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001166 }
1167
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001168 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001169 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001170 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001171 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001172 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001173 return
1174 }
1175
1176 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001177 // in static libraries act as if they were whole static libraries. The same goes for
1178 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001179 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1180 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001181 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1182 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001183
Dan Willemsen581341d2017-02-09 16:16:31 -08001184 }
1185
Colin Cross26c34ed2016-09-30 17:10:16 -07001186 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001187 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001188 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001189 return
1190 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001191 *ptr = append(*ptr, linkFile.Path())
1192 }
1193
Colin Crossc99deeb2016-04-11 15:06:20 -07001194 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001195 dep := depFile
1196 if !dep.Valid() {
1197 dep = linkFile
1198 }
1199 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001200 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001201
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001202 // Export the shared libs to Make.
1203 switch depTag {
Jiyong Park27b188b2017-07-18 13:23:39 +09001204 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001205 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001206 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001207 isLLndk := inList(libName, llndkLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001208 var makeLibName string
1209 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1210 if c.useVndk() && bothVendorAndCoreVariantsExist {
1211 // The vendor module in Make will have been renamed to not conflict with the core
1212 // module, so update the dependency name here accordingly.
1213 makeLibName = libName + vendorSuffix
1214 } else {
1215 makeLibName = libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001216 }
1217 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001218 // they merely serve as Make dependencies and do not affect this lib itself.
1219 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName)
Jiyong Park27b188b2017-07-18 13:23:39 +09001220 }
Colin Crossca860ac2016-01-04 14:34:37 -08001221 })
1222
Jeff Gaston294356f2017-09-27 17:05:30 -07001223 // use the ordered dependencies as this module's dependencies
1224 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps)...)
1225
Colin Crossdd84e052017-05-17 13:44:16 -07001226 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001227 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001228 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001229 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001230 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1231
1232 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001233 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001234 }
Colin Crossdd84e052017-05-17 13:44:16 -07001235
Colin Crossca860ac2016-01-04 14:34:37 -08001236 return depPaths
1237}
1238
1239func (c *Module) InstallInData() bool {
1240 if c.installer == nil {
1241 return false
1242 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001243 return c.installer.inData()
1244}
1245
1246func (c *Module) InstallInSanitizerDir() bool {
1247 if c.installer == nil {
1248 return false
1249 }
1250 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001251 return true
1252 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001253 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001254}
1255
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001256func (c *Module) HostToolPath() android.OptionalPath {
1257 if c.installer == nil {
1258 return android.OptionalPath{}
1259 }
1260 return c.installer.hostToolPath()
1261}
1262
Nan Zhangd4e641b2017-07-12 12:55:28 -07001263func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1264 return c.outputFile
1265}
1266
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001267func (c *Module) Srcs() android.Paths {
1268 if c.outputFile.Valid() {
1269 return android.Paths{c.outputFile.Path()}
1270 }
1271 return android.Paths{}
1272}
1273
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001274func (c *Module) static() bool {
1275 if static, ok := c.linker.(interface {
1276 static() bool
1277 }); ok {
1278 return static.static()
1279 }
1280 return false
1281}
1282
Colin Cross2ba19d92015-05-07 15:44:20 -07001283//
Colin Crosscfad1192015-11-02 16:43:11 -08001284// Defaults
1285//
Colin Crossca860ac2016-01-04 14:34:37 -08001286type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001287 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001288 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001289}
1290
Colin Cross635c3b02016-05-18 15:37:25 -07001291func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001292}
1293
Colin Cross1e676be2016-10-12 14:38:15 -07001294func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1295}
1296
Colin Cross36242852017-06-23 15:06:31 -07001297func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001298 return DefaultsFactory()
1299}
1300
Colin Cross36242852017-06-23 15:06:31 -07001301func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001302 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001303
Colin Cross36242852017-06-23 15:06:31 -07001304 module.AddProperties(props...)
1305 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001306 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001307 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001308 &BaseCompilerProperties{},
1309 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001310 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001311 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001312 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001313 &TestProperties{},
1314 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001315 &UnusedProperties{},
1316 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001317 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001318 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001319 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001320 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001321 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001322 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001323 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001324 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001325 &PgoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001326 )
Colin Crosscfad1192015-11-02 16:43:11 -08001327
Colin Cross1f44a3a2017-07-07 14:33:33 -07001328 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001329
1330 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001331}
1332
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001333const (
1334 // coreMode is the variant used for framework-private libraries, or
1335 // SDK libraries. (which framework-private libraries can use)
1336 coreMode = "core"
1337
1338 // vendorMode is the variant used for /vendor code that compiles
1339 // against the VNDK.
1340 vendorMode = "vendor"
1341)
1342
Jiyong Park6a43f042017-10-12 23:05:00 +09001343func squashVendorSrcs(m *Module) {
1344 if lib, ok := m.compiler.(*libraryDecorator); ok {
1345 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1346 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1347
1348 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1349 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1350 }
1351}
1352
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001353func vendorMutator(mctx android.BottomUpMutatorContext) {
1354 if mctx.Os() != android.Android {
1355 return
1356 }
1357
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001358 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1359 if props, ok := genrule.Extra.(*VendorProperties); ok {
1360 if !mctx.DeviceConfig().CompileVndk() {
1361 mctx.CreateVariations(coreMode)
1362 } else if Bool(props.Vendor_available) {
1363 mctx.CreateVariations(coreMode, vendorMode)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001364 } else if mctx.InstallOnVendorPartition() {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001365 mctx.CreateVariations(vendorMode)
1366 } else {
1367 mctx.CreateVariations(coreMode)
1368 }
1369 }
1370 }
1371
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001372 m, ok := mctx.Module().(*Module)
1373 if !ok {
1374 return
1375 }
1376
1377 // Sanity check
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001378 if m.VendorProperties.Vendor_available != nil && mctx.InstallOnVendorPartition() {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001379 mctx.PropertyErrorf("vendor_available",
1380 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1381 return
1382 }
Justin Yun8effde42017-06-23 19:24:43 +09001383 if vndk := m.vndkdep; vndk != nil {
Jiyong Park82e2bf32017-08-16 14:05:54 +09001384 if vndk.isVndk() && m.VendorProperties.Vendor_available == nil {
Justin Yun8effde42017-06-23 19:24:43 +09001385 mctx.PropertyErrorf("vndk",
Jiyong Park82e2bf32017-08-16 14:05:54 +09001386 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Justin Yun8effde42017-06-23 19:24:43 +09001387 return
1388 }
1389 if !vndk.isVndk() && vndk.isVndkSp() {
1390 mctx.PropertyErrorf("vndk",
1391 "must set `enabled: true` to set `support_system_process: true`")
1392 return
1393 }
1394 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001395
1396 if !mctx.DeviceConfig().CompileVndk() {
1397 // If the device isn't compiling against the VNDK, we always
1398 // use the core mode.
1399 mctx.CreateVariations(coreMode)
1400 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1401 // LL-NDK stubs only exist in the vendor variant, since the
1402 // real libraries will be used in the core variant.
1403 mctx.CreateVariations(vendorMode)
Jiyong Park2a454122017-10-19 15:59:33 +09001404 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1405 // ... and LL-NDK headers as well
1406 mctx.CreateVariations(vendorMode)
Jiyong Park82e2bf32017-08-16 14:05:54 +09001407 } else if m.hasVendorVariant() {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001408 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001409 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001410 mod := mctx.CreateVariations(coreMode, vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001411 vendor := mod[1].(*Module)
1412 vendor.Properties.UseVndk = true
1413 squashVendorSrcs(vendor)
Nan Zhang0007d812017-11-07 10:57:05 -08001414 } else if mctx.InstallOnVendorPartition() && String(m.Properties.Sdk_version) == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001415 // This will be available in /vendor only
1416 mod := mctx.CreateVariations(vendorMode)
Jiyong Park6a43f042017-10-12 23:05:00 +09001417 vendor := mod[0].(*Module)
1418 vendor.Properties.UseVndk = true
1419 squashVendorSrcs(vendor)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001420 } else {
1421 // This is either in /system (or similar: /data), or is a
1422 // modules built with the NDK. Modules built with the NDK
1423 // will be restricted using the existing link type checks.
1424 mctx.CreateVariations(coreMode)
1425 }
1426}
1427
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001428func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1429 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1430 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1431 }
1432 return ctx.AConfig().PlatformSdkVersion()
1433}
1434
Colin Cross06a931b2015-10-28 17:23:31 -07001435var Bool = proptools.Bool
Nan Zhang0007d812017-11-07 10:57:05 -08001436var BoolPtr = proptools.BoolPtr
1437var String = proptools.String
1438var StringPtr = proptools.StringPtr