blob: 0f754a66102bfc31b0e25d36a8703c4ef2c4ba72 [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) {
37 ctx.BottomUp("link", linkageMutator).Parallel()
Dan Willemsen4416e5d2017-04-06 12:43:22 -070038 ctx.BottomUp("image", vendorMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070039 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
40 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
41 ctx.BottomUp("begin", beginMutator).Parallel()
42 })
Colin Cross16b23492016-01-06 14:41:07 -080043
Colin Cross1e676be2016-10-12 14:38:15 -070044 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
45 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
46 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080047
Colin Cross1e676be2016-10-12 14:38:15 -070048 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
49 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080050
51 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080052 ctx.TopDown("vndk_deps", sabiDepsMutator)
Colin Cross1e676be2016-10-12 14:38:15 -070053 })
Colin Crossb98c8b02016-07-29 13:44:28 -070054
55 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070056}
57
Colin Crossca860ac2016-01-04 14:34:37 -080058type Deps struct {
59 SharedLibs, LateSharedLibs []string
60 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080061 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070062
Colin Cross5950f382016-12-13 12:50:57 -080063 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070064
Colin Cross81413472016-04-11 14:37:39 -070065 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070066
Dan Willemsenb40aab62016-04-20 14:21:14 -070067 GeneratedSources []string
68 GeneratedHeaders []string
69
Dan Willemsenb3454ab2016-09-28 17:34:58 -070070 ReexportGeneratedHeaders []string
71
Colin Cross97ba0732015-03-23 17:50:24 -070072 CrtBegin, CrtEnd string
Colin Crossc472d572015-03-17 15:06:21 -070073}
74
Colin Crossca860ac2016-01-04 14:34:37 -080075type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070076 // Paths to .so files
77 SharedLibs, LateSharedLibs android.Paths
78 // Paths to the dependencies to use for .so files (.so.toc files)
79 SharedLibsDeps, LateSharedLibsDeps android.Paths
80 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070081 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070082
Colin Cross26c34ed2016-09-30 17:10:16 -070083 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070084 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080085 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070086 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070087
Colin Cross26c34ed2016-09-30 17:10:16 -070088 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070089 GeneratedSources android.Paths
90 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070091
Dan Willemsen76f08272016-07-09 00:14:08 -070092 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -070093 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070094
Colin Cross26c34ed2016-09-30 17:10:16 -070095 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -070096 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -070097}
98
Colin Crossca860ac2016-01-04 14:34:37 -080099type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700100 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
101 ArFlags []string // Flags that apply to ar
102 AsFlags []string // Flags that apply to assembly source files
103 CFlags []string // Flags that apply to C and C++ source files
104 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
105 ConlyFlags []string // Flags that apply to C source files
106 CppFlags []string // Flags that apply to C++ source files
107 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
108 YaccFlags []string // Flags that apply to Yacc source files
109 protoFlags []string // Flags that apply to proto source files
110 aidlFlags []string // Flags that apply to aidl source files
111 rsFlags []string // Flags that apply to renderscript source files
112 LdFlags []string // Flags that apply to linker command lines
113 libFlags []string // Flags to add libraries early to the link order
114 TidyFlags []string // Flags that apply to clang-tidy
115 SAbiFlags []string // Flags that apply to header-abi-dumper
116 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700117
Colin Crossc3199482017-03-30 15:03:04 -0700118 // Global include flags that apply to C, C++, and assembly source files
119 // These must be after any module include flags, which will be in GlobalFlags.
120 SystemIncludeFlags []string
121
Colin Crossb98c8b02016-07-29 13:44:28 -0700122 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700123 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700124 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800125 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800126 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800127
128 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800129 DynamicLinker string
130
Colin Cross635c3b02016-05-18 15:37:25 -0700131 CFlagsDeps android.Paths // Files depended on by compiler flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800132
133 GroupStaticLibs bool
Colin Crossc472d572015-03-17 15:06:21 -0700134}
135
Colin Cross81413472016-04-11 14:37:39 -0700136type ObjectLinkerProperties struct {
137 // names of other cc_object modules to link into this module using partial linking
138 Objs []string `android:"arch_variant"`
139}
140
Colin Crossca860ac2016-01-04 14:34:37 -0800141// Properties used to compile all C or C++ modules
142type BaseProperties struct {
143 // compile module with clang instead of gcc
144 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700145
146 // Minimum sdk version supported when compiling against the ndk
147 Sdk_version string
148
Colin Crossca860ac2016-01-04 14:34:37 -0800149 // don't insert default compiler flags into asflags, cflags,
150 // cppflags, conlyflags, ldflags, or include_dirs
151 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700152
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700153 // whether this module should be allowed to install onto /vendor as
154 // well as /system. The two variants will be built separately, one
155 // like normal, and the other limited to the set of libraries and
156 // headers that are exposed to /vendor modules.
157 //
158 // The vendor variant may be used with a different (newer) /system,
159 // so it shouldn't have any unversioned runtime dependencies, or
160 // make assumptions about the system that may not be true in the
161 // future.
162 //
163 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
164 Vendor_available *bool
165
Colin Crossc99deeb2016-04-11 15:06:20 -0700166 AndroidMkSharedLibs []string `blueprint:"mutated"`
Colin Crossbc6fb162016-05-24 15:39:04 -0700167 HideFromMake bool `blueprint:"mutated"`
Colin Crossb0f28952016-09-19 16:46:53 -0700168 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700169
170 UseVndk bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800171}
172
Colin Crossca860ac2016-01-04 14:34:37 -0800173type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800174 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800175}
176
Colin Crossca860ac2016-01-04 14:34:37 -0800177type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800178 static() bool
179 staticBinary() bool
180 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700181 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800182 noDefaultCompilerFlags() bool
183 sdk() bool
184 sdkVersion() string
Dan Willemsend2ede872016-11-18 14:54:24 -0800185 vndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900186 isVndk() bool
187 isVndkSp() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800188 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700189 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700190 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800191}
192
193type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700194 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800195 ModuleContextIntf
196}
197
198type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700199 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800200 ModuleContextIntf
201}
202
Colin Cross37047f12016-12-13 17:06:13 -0800203type DepsContext interface {
204 android.BottomUpMutatorContext
205 ModuleContextIntf
206}
207
Colin Crossca860ac2016-01-04 14:34:37 -0800208type feature interface {
209 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800210 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800211 flags(ctx ModuleContext, flags Flags) Flags
212 props() []interface{}
213}
214
215type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700216 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800217 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700218 compilerFlags(ctx ModuleContext, flags Flags) Flags
219 compilerProps() []interface{}
220
Colin Cross76fada02016-07-27 10:31:13 -0700221 appendCflags([]string)
222 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700223 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800224}
225
226type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700227 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800228 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700229 linkerFlags(ctx ModuleContext, flags Flags) Flags
230 linkerProps() []interface{}
231
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700232 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700233 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800234}
235
236type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700237 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700238 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800239 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700240 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700241 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800242}
243
Colin Crossc99deeb2016-04-11 15:06:20 -0700244type dependencyTag struct {
245 blueprint.BaseDependencyTag
246 name string
247 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700248
249 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700250}
251
252var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700253 sharedDepTag = dependencyTag{name: "shared", library: true}
254 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
255 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
256 staticDepTag = dependencyTag{name: "static", library: true}
257 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
258 lateStaticDepTag = dependencyTag{name: "late static", library: true}
259 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800260 headerDepTag = dependencyTag{name: "header", library: true}
261 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700262 genSourceDepTag = dependencyTag{name: "gen source"}
263 genHeaderDepTag = dependencyTag{name: "gen header"}
264 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
265 objDepTag = dependencyTag{name: "obj"}
266 crtBeginDepTag = dependencyTag{name: "crtbegin"}
267 crtEndDepTag = dependencyTag{name: "crtend"}
268 reuseObjTag = dependencyTag{name: "reuse objects"}
269 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
270 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700271)
272
Colin Crossca860ac2016-01-04 14:34:37 -0800273// Module contains the properties and members used by all C/C++ module types, and implements
274// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
275// to construct the output file. Behavior can be customized with a Customizer interface
276type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700277 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700278 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700279
Colin Crossca860ac2016-01-04 14:34:37 -0800280 Properties BaseProperties
281 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700282
Colin Crossca860ac2016-01-04 14:34:37 -0800283 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700284 hod android.HostOrDeviceSupported
285 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700286
Colin Crossca860ac2016-01-04 14:34:37 -0800287 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700288 features []feature
289 compiler compiler
290 linker linker
291 installer installer
292 stl *stl
293 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800294 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800295 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900296 vndkdep *vndkdep
Colin Cross16b23492016-01-06 14:41:07 -0800297
298 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700299
Colin Cross635c3b02016-05-18 15:37:25 -0700300 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800301
Colin Crossb98c8b02016-07-29 13:44:28 -0700302 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700303
304 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800305
306 // Flags used to compile this module
307 flags Flags
Colin Crossc472d572015-03-17 15:06:21 -0700308}
309
Colin Cross36242852017-06-23 15:06:31 -0700310func (c *Module) Init() android.Module {
311 c.AddProperties(&c.Properties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800312 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700313 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800314 }
315 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700316 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800317 }
318 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700319 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800320 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700321 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700322 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700323 }
Colin Cross16b23492016-01-06 14:41:07 -0800324 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700325 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800326 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800327 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700328 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800329 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800330 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700331 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800332 }
Justin Yun8effde42017-06-23 19:24:43 +0900333 if c.vndkdep != nil {
334 c.AddProperties(c.vndkdep.props()...)
335 }
Colin Crossca860ac2016-01-04 14:34:37 -0800336 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700337 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800338 }
Colin Crossc472d572015-03-17 15:06:21 -0700339
Colin Cross36242852017-06-23 15:06:31 -0700340 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700341
Colin Cross1f44a3a2017-07-07 14:33:33 -0700342 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700343
344 return c
Colin Crossc472d572015-03-17 15:06:21 -0700345}
346
Colin Crossb916a382016-07-29 17:28:03 -0700347// Returns true for dependency roots (binaries)
348// TODO(ccross): also handle dlopenable libraries
349func (c *Module) isDependencyRoot() bool {
350 if root, ok := c.linker.(interface {
351 isDependencyRoot() bool
352 }); ok {
353 return root.isDependencyRoot()
354 }
355 return false
356}
357
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700358func (c *Module) vndk() bool {
359 return c.Properties.UseVndk
360}
361
Justin Yun8effde42017-06-23 19:24:43 +0900362func (c *Module) isVndk() bool {
363 if c.vndkdep != nil {
364 return c.vndkdep.isVndk()
365 }
366 return false
367}
368
Colin Crossca860ac2016-01-04 14:34:37 -0800369type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700370 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800371 moduleContextImpl
372}
373
Colin Cross37047f12016-12-13 17:06:13 -0800374type depsContext struct {
375 android.BottomUpMutatorContext
376 moduleContextImpl
377}
378
Colin Crossca860ac2016-01-04 14:34:37 -0800379type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700380 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800381 moduleContextImpl
382}
383
Justin Yun8effde42017-06-23 19:24:43 +0900384// Vendor returns true for vendor modules excluding VNDK libraries so that
385// they get installed onto the correct partition
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700386func (ctx *moduleContext) Vendor() bool {
Justin Yun8effde42017-06-23 19:24:43 +0900387 return ctx.ModuleContext.Vendor() || (ctx.mod.vndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700388}
389
Colin Crossca860ac2016-01-04 14:34:37 -0800390type moduleContextImpl struct {
391 mod *Module
392 ctx BaseModuleContext
393}
394
Colin Crossca860ac2016-01-04 14:34:37 -0800395func (ctx *moduleContextImpl) clang() bool {
396 return ctx.mod.clang(ctx.ctx)
397}
398
Colin Crossb98c8b02016-07-29 13:44:28 -0700399func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800400 return ctx.mod.toolchain(ctx.ctx)
401}
402
403func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700404 if static, ok := ctx.mod.linker.(interface {
405 static() bool
406 }); ok {
407 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800408 }
Colin Crossb916a382016-07-29 17:28:03 -0700409 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800410}
411
412func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700413 if static, ok := ctx.mod.linker.(interface {
414 staticBinary() bool
415 }); ok {
416 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800417 }
Colin Crossb916a382016-07-29 17:28:03 -0700418 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800419}
420
421func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
422 return Bool(ctx.mod.Properties.No_default_compiler_flags)
423}
424
425func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700426 if ctx.ctx.Device() && !ctx.vndk() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700427 return ctx.mod.Properties.Sdk_version != ""
428 }
429 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800430}
431
432func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700433 if ctx.ctx.Device() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700434 if ctx.vndk() {
435 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800436 } else {
437 return ctx.mod.Properties.Sdk_version
438 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700439 }
440 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800441}
442
Dan Willemsend2ede872016-11-18 14:54:24 -0800443func (ctx *moduleContextImpl) vndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700444 return ctx.mod.vndk()
Dan Willemsend2ede872016-11-18 14:54:24 -0800445}
446
Justin Yun8effde42017-06-23 19:24:43 +0900447func (ctx *moduleContextImpl) isVndk() bool {
448 return ctx.mod.isVndk()
449}
450
451func (ctx *moduleContextImpl) isVndkSp() bool {
452 if vndk := ctx.mod.vndkdep; vndk != nil {
453 return vndk.isVndkSp()
454 }
455 return false
456}
457
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800458// Create source abi dumps if the module belongs to the list of VndkLibraries.
459func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Justin Yun8effde42017-06-23 19:24:43 +0900460 return ctx.ctx.Device() && (ctx.mod.isVndk() || inList(ctx.baseModuleName(), config.LLndkLibraries()))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800461}
462
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700463func (ctx *moduleContextImpl) selectedStl() string {
464 if stl := ctx.mod.stl; stl != nil {
465 return stl.Properties.SelectedStl
466 }
467 return ""
468}
469
Colin Crossce75d2c2016-10-06 16:12:58 -0700470func (ctx *moduleContextImpl) baseModuleName() string {
471 return ctx.mod.ModuleBase.BaseModuleName()
472}
473
Colin Cross635c3b02016-05-18 15:37:25 -0700474func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800475 return &Module{
476 hod: hod,
477 multilib: multilib,
478 }
479}
480
Colin Cross635c3b02016-05-18 15:37:25 -0700481func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800482 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700483 module.features = []feature{
484 &tidyFeature{},
485 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700486 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800487 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800488 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800489 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900490 module.vndkdep = &vndkdep{}
Colin Crossca860ac2016-01-04 14:34:37 -0800491 return module
492}
493
Colin Crossce75d2c2016-10-06 16:12:58 -0700494func (c *Module) Prebuilt() *android.Prebuilt {
495 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
496 return p.prebuilt()
497 }
498 return nil
499}
500
501func (c *Module) Name() string {
502 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700503 if p, ok := c.linker.(interface {
504 Name(string) string
505 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700506 name = p.Name(name)
507 }
508 return name
509}
510
Colin Cross635c3b02016-05-18 15:37:25 -0700511func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800512 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700513 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800514 moduleContextImpl: moduleContextImpl{
515 mod: c,
516 },
517 }
518 ctx.ctx = ctx
519
520 flags := Flags{
521 Toolchain: c.toolchain(ctx),
522 Clang: c.clang(ctx),
523 }
Colin Crossca860ac2016-01-04 14:34:37 -0800524 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700525 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800526 }
527 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700528 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800529 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700530 if c.stl != nil {
531 flags = c.stl.flags(ctx, flags)
532 }
Colin Cross16b23492016-01-06 14:41:07 -0800533 if c.sanitize != nil {
534 flags = c.sanitize.flags(ctx, flags)
535 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800536 if c.coverage != nil {
537 flags = c.coverage.flags(ctx, flags)
538 }
Colin Crossca860ac2016-01-04 14:34:37 -0800539 for _, feature := range c.features {
540 flags = feature.flags(ctx, flags)
541 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800542 if ctx.Failed() {
543 return
544 }
545
Colin Crossb98c8b02016-07-29 13:44:28 -0700546 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
547 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
548 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800549
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800550 deps := c.depsToPaths(ctx)
551 if ctx.Failed() {
552 return
553 }
554 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
555 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700556 // We need access to all the flags seen by a source file.
557 if c.sabi != nil {
558 flags = c.sabi.flags(ctx, flags)
559 }
Colin Crossca860ac2016-01-04 14:34:37 -0800560 // Optimization to reduce size of build.ninja
561 // Replace the long list of flags for each file with a module-local variable
562 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
563 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
564 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
565 flags.CFlags = []string{"$cflags"}
566 flags.CppFlags = []string{"$cppflags"}
567 flags.AsFlags = []string{"$asflags"}
568
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700569 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800570 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700571 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800572 if ctx.Failed() {
573 return
574 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800575 }
576
Colin Crossca860ac2016-01-04 14:34:37 -0800577 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700578 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800579 if ctx.Failed() {
580 return
581 }
Colin Cross635c3b02016-05-18 15:37:25 -0700582 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700583 }
Colin Cross5049f022015-03-18 13:28:46 -0700584
Colin Crossce75d2c2016-10-06 16:12:58 -0700585 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
586 c.installer.install(ctx, c.outputFile.Path())
587 if ctx.Failed() {
588 return
Colin Crossca860ac2016-01-04 14:34:37 -0800589 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700590 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800591}
592
Colin Crossb98c8b02016-07-29 13:44:28 -0700593func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800594 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700595 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800596 }
Colin Crossca860ac2016-01-04 14:34:37 -0800597 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800598}
599
Colin Crossca860ac2016-01-04 14:34:37 -0800600func (c *Module) begin(ctx BaseModuleContext) {
601 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700602 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700603 }
Colin Crossca860ac2016-01-04 14:34:37 -0800604 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700605 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800606 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700607 if c.stl != nil {
608 c.stl.begin(ctx)
609 }
Colin Cross16b23492016-01-06 14:41:07 -0800610 if c.sanitize != nil {
611 c.sanitize.begin(ctx)
612 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800613 if c.coverage != nil {
614 c.coverage.begin(ctx)
615 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800616 if c.sabi != nil {
617 c.sabi.begin(ctx)
618 }
Justin Yun8effde42017-06-23 19:24:43 +0900619 if c.vndkdep != nil {
620 c.vndkdep.begin(ctx)
621 }
Colin Crossca860ac2016-01-04 14:34:37 -0800622 for _, feature := range c.features {
623 feature.begin(ctx)
624 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700625 if ctx.sdk() {
626 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
627 if err != nil {
628 ctx.PropertyErrorf("sdk_version", err.Error())
629 }
Dan Albert90f7a4d2016-11-08 14:34:24 -0800630 c.Properties.Sdk_version = version
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700631 }
Colin Crossca860ac2016-01-04 14:34:37 -0800632}
633
Colin Cross37047f12016-12-13 17:06:13 -0800634func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700635 deps := Deps{}
636
637 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700638 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700639 }
640 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700641 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700642 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700643 if c.stl != nil {
644 deps = c.stl.deps(ctx, deps)
645 }
Colin Cross16b23492016-01-06 14:41:07 -0800646 if c.sanitize != nil {
647 deps = c.sanitize.deps(ctx, deps)
648 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800649 if c.coverage != nil {
650 deps = c.coverage.deps(ctx, deps)
651 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800652 if c.sabi != nil {
653 deps = c.sabi.deps(ctx, deps)
654 }
Justin Yun8effde42017-06-23 19:24:43 +0900655 if c.vndkdep != nil {
656 deps = c.vndkdep.deps(ctx, deps)
657 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700658 for _, feature := range c.features {
659 deps = feature.deps(ctx, deps)
660 }
661
662 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
663 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
664 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
665 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
666 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
Colin Cross5950f382016-12-13 12:50:57 -0800667 deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700668
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700669 for _, lib := range deps.ReexportSharedLibHeaders {
670 if !inList(lib, deps.SharedLibs) {
671 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
672 }
673 }
674
675 for _, lib := range deps.ReexportStaticLibHeaders {
676 if !inList(lib, deps.StaticLibs) {
677 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
678 }
679 }
680
Colin Cross5950f382016-12-13 12:50:57 -0800681 for _, lib := range deps.ReexportHeaderLibHeaders {
682 if !inList(lib, deps.HeaderLibs) {
683 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
684 }
685 }
686
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700687 for _, gen := range deps.ReexportGeneratedHeaders {
688 if !inList(gen, deps.GeneratedHeaders) {
689 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
690 }
691 }
692
Colin Crossc99deeb2016-04-11 15:06:20 -0700693 return deps
694}
695
Dan Albert7e9d2952016-08-04 13:02:36 -0700696func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800697 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700698 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800699 moduleContextImpl: moduleContextImpl{
700 mod: c,
701 },
702 }
703 ctx.ctx = ctx
704
Colin Crossca860ac2016-01-04 14:34:37 -0800705 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700706}
707
Colin Cross1e676be2016-10-12 14:38:15 -0700708func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
709 if !c.Enabled() {
710 return
711 }
712
Colin Cross37047f12016-12-13 17:06:13 -0800713 ctx := &depsContext{
714 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700715 moduleContextImpl: moduleContextImpl{
716 mod: c,
717 },
718 }
719 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800720
Colin Crossc99deeb2016-04-11 15:06:20 -0700721 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800722
Dan Albert914449f2016-06-17 16:45:24 -0700723 variantNdkLibs := []string{}
724 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700725 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700726 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700727
Dan Albert914449f2016-06-17 16:45:24 -0700728 // Rewrites the names of shared libraries into the names of the NDK
729 // libraries where appropriate. This returns two slices.
730 //
731 // The first is a list of non-variant shared libraries (either rewritten
732 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
733 // because they are not NDK libraries).
734 //
735 // The second is a list of ndk_library modules. These need to be
736 // separated because they are a variation dependency and must be added
737 // in a different manner.
738 rewriteNdkLibs := func(list []string) ([]string, []string) {
739 variantLibs := []string{}
740 nonvariantLibs := []string{}
741 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700742 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700743 if !inList(entry, ndkMigratedLibs) {
744 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
745 } else {
746 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
747 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700748 } else if ctx.vndk() && inList(entry, config.LLndkLibraries()) {
749 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700750 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700751 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700752 }
753 }
Dan Albert914449f2016-06-17 16:45:24 -0700754 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700755 }
756
Dan Albert914449f2016-06-17 16:45:24 -0700757 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
758 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900759 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700760 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700761
Colin Cross32ec36c2016-12-15 07:39:51 -0800762 for _, lib := range deps.HeaderLibs {
763 depTag := headerDepTag
764 if inList(lib, deps.ReexportHeaderLibHeaders) {
765 depTag = headerExportDepTag
766 }
767 actx.AddVariationDependencies(nil, depTag, lib)
768 }
Colin Cross5950f382016-12-13 12:50:57 -0800769
Colin Crossc99deeb2016-04-11 15:06:20 -0700770 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
771 deps.WholeStaticLibs...)
772
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700773 for _, lib := range deps.StaticLibs {
774 depTag := staticDepTag
775 if inList(lib, deps.ReexportStaticLibHeaders) {
776 depTag = staticExportDepTag
777 }
Colin Cross15a0d462016-07-14 14:49:58 -0700778 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700779 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700780
781 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
782 deps.LateStaticLibs...)
783
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700784 for _, lib := range deps.SharedLibs {
785 depTag := sharedDepTag
786 if inList(lib, deps.ReexportSharedLibHeaders) {
787 depTag = sharedExportDepTag
788 }
Colin Cross15a0d462016-07-14 14:49:58 -0700789 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700790 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700791
792 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
793 deps.LateSharedLibs...)
794
Colin Cross68861832016-07-08 10:41:41 -0700795 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700796
797 for _, gen := range deps.GeneratedHeaders {
798 depTag := genHeaderDepTag
799 if inList(gen, deps.ReexportGeneratedHeaders) {
800 depTag = genHeaderExportDepTag
801 }
802 actx.AddDependency(c, depTag, gen)
803 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700804
Colin Cross68861832016-07-08 10:41:41 -0700805 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700806
807 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700808 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800809 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700810 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700811 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700812 }
Dan Albert914449f2016-06-17 16:45:24 -0700813
814 version := ctx.sdkVersion()
815 actx.AddVariationDependencies([]blueprint.Variation{
816 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
817 actx.AddVariationDependencies([]blueprint.Variation{
818 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700819}
Colin Cross21b9a242015-03-24 14:15:58 -0700820
Dan Albert7e9d2952016-08-04 13:02:36 -0700821func beginMutator(ctx android.BottomUpMutatorContext) {
822 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
823 c.beginMutator(ctx)
824 }
825}
826
Colin Crossca860ac2016-01-04 14:34:37 -0800827func (c *Module) clang(ctx BaseModuleContext) bool {
828 clang := Bool(c.Properties.Clang)
829
830 if c.Properties.Clang == nil {
831 if ctx.Host() {
832 clang = true
833 }
834
835 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
836 clang = true
837 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800838 }
Colin Cross28344522015-04-22 13:07:53 -0700839
Colin Crossca860ac2016-01-04 14:34:37 -0800840 if !c.toolchain(ctx).ClangSupported() {
841 clang = false
842 }
843
844 return clang
845}
846
Colin Crossc99deeb2016-04-11 15:06:20 -0700847// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700848func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800849 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800850
Dan Willemsena96ff642016-06-07 12:34:45 -0700851 // Whether a module can link to another module, taking into
852 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700853 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700854 if from.Target().Os != android.Android {
855 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700856 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700857 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700858 if from.Properties.UseVndk {
Justin Yun8effde42017-06-23 19:24:43 +0900859 // Though vendor code is limited by the vendor mutator,
860 // each vendor-available module needs to check
861 // link-type for VNDK.
862 if from.vndkdep != nil {
863 from.vndkdep.vndkCheckLinkType(ctx, to)
864 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700865 return
866 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700867 if from.Properties.Sdk_version == "" {
868 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700869 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700870 }
Colin Crossb916a382016-07-29 17:28:03 -0700871 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700872 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700873 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700874 }
875 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
876 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700877 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700878 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700879 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
880 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700881 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700882 }
Colin Crossb916a382016-07-29 17:28:03 -0700883 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700884 // These aren't real libraries, but are the stub shared libraries that are included in
885 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700886 return
Dan Albert914449f2016-06-17 16:45:24 -0700887 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700888 if to.Properties.Sdk_version == "" {
889 // NDK code linking to platform code is never okay.
890 ctx.ModuleErrorf("depends on non-NDK-built library %q",
891 ctx.OtherModuleName(to))
892 }
893
894 // All this point we know we have two NDK libraries, but we need to
895 // check that we're not linking against anything built against a higher
896 // API level, as it is only valid to link against older or equivalent
897 // APIs.
898
899 if from.Properties.Sdk_version == "current" {
900 // Current can link against anything.
901 return
902 } else if to.Properties.Sdk_version == "current" {
903 // Current can't be linked against by anything else.
904 ctx.ModuleErrorf("links %q built against newer API version %q",
905 ctx.OtherModuleName(to), "current")
906 }
907
908 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
909 if err != nil {
910 ctx.PropertyErrorf("sdk_version",
911 "Invalid sdk_version value (must be int): %q",
912 from.Properties.Sdk_version)
913 }
914 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
915 if err != nil {
916 ctx.PropertyErrorf("sdk_version",
917 "Invalid sdk_version value (must be int): %q",
918 to.Properties.Sdk_version)
919 }
920
921 if toApi > fromApi {
922 ctx.ModuleErrorf("links %q built against newer API version %q",
923 ctx.OtherModuleName(to), to.Properties.Sdk_version)
924 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700925 }
926
Colin Crossc99deeb2016-04-11 15:06:20 -0700927 ctx.VisitDirectDeps(func(m blueprint.Module) {
928 name := ctx.OtherModuleName(m)
929 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800930
Colin Cross635c3b02016-05-18 15:37:25 -0700931 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700932 if a == nil {
933 ctx.ModuleErrorf("module %q not an android module", name)
934 return
Colin Crossca860ac2016-01-04 14:34:37 -0800935 }
Colin Crossca860ac2016-01-04 14:34:37 -0800936
Dan Willemsena96ff642016-06-07 12:34:45 -0700937 cc, _ := m.(*Module)
938 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700939 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800940 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700941 case genSourceDepTag:
942 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
943 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
944 genRule.GeneratedSourceFiles()...)
945 } else {
946 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
947 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700948 // Support exported headers from a generated_sources dependency
949 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700950 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700951 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
952 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
953 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800954 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700955 depPaths.Flags = append(depPaths.Flags, flags)
956 if tag == genHeaderExportDepTag {
957 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700958 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
959 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700960 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
961 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
962
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700963 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700964 } else {
965 ctx.ModuleErrorf("module %q is not a genrule", name)
966 }
967 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700968 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800969 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700970 return
971 }
972
973 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800974 if ctx.AConfig().AllowMissingDependencies() {
975 ctx.AddMissingDependencies([]string{name})
976 } else {
977 ctx.ModuleErrorf("depends on disabled module %q", name)
978 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700979 return
980 }
981
Colin Crossa1ad8d12016-06-01 17:09:44 -0700982 if a.Target().Os != ctx.Os() {
983 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
984 return
985 }
986
987 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
988 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700989 return
990 }
991
Colin Crossc99deeb2016-04-11 15:06:20 -0700992 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -0800993 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700994 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -0700995 depPaths.Objs = depPaths.Objs.Append(objs)
996 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700997 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -0800998 return
999 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001000 }
1001
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001002 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -07001003 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001004 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001005 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001006 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001007 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001008
1009 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001010 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001011 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001012 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1013 // Re-exported flags from shared library dependencies are not included as those shared libraries
1014 // will be included in the vndk set.
1015 if tag == staticExportDepTag || tag == headerExportDepTag {
1016 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
1017 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001018 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001019 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001020
Dan Albert9e10cd42016-08-03 14:12:14 -07001021 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -07001022 }
1023
Colin Cross26c34ed2016-09-30 17:10:16 -07001024 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001025 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001026
Colin Cross26c34ed2016-09-30 17:10:16 -07001027 linkFile := cc.outputFile
1028 depFile := android.OptionalPath{}
1029
Colin Crossc99deeb2016-04-11 15:06:20 -07001030 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -07001031 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001032 ptr = &depPaths.SharedLibs
1033 depPtr = &depPaths.SharedLibsDeps
1034 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001035 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001036 ptr = &depPaths.LateSharedLibs
1037 depPtr = &depPaths.LateSharedLibsDeps
1038 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001039 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001040 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001041 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001042 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001043 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001044 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001045 staticLib, ok := cc.linker.(libraryInterface)
1046 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001047 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001048 return
1049 }
1050
1051 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1052 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1053 for i := range missingDeps {
1054 missingDeps[i] += postfix
1055 }
1056 ctx.AddMissingDependencies(missingDeps)
1057 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001058 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001059 case headerDepTag:
1060 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001061 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001062 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001063 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001064 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001065 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001066 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001067 }
1068
Dan Willemsen581341d2017-02-09 16:16:31 -08001069 switch tag {
1070 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1071 staticLib, ok := cc.linker.(libraryInterface)
1072 if !ok || !staticLib.static() {
1073 ctx.ModuleErrorf("module %q not a static library", name)
1074 return
1075 }
1076
1077 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001078 // in static libraries act as if they were whole static libraries. The same goes for
1079 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001080 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1081 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001082 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1083 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001084 }
1085
Colin Cross26c34ed2016-09-30 17:10:16 -07001086 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001087 if !linkFile.Valid() {
1088 ctx.ModuleErrorf("module %q missing output file", name)
1089 return
1090 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001091 *ptr = append(*ptr, linkFile.Path())
1092 }
1093
Colin Crossc99deeb2016-04-11 15:06:20 -07001094 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001095 dep := depFile
1096 if !dep.Valid() {
1097 dep = linkFile
1098 }
1099 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001100 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001101
1102 // Export the shared libs to the make world. In doing so, .vendor suffix
1103 // is added if the lib has both core and vendor variants and this module
1104 // is building against vndk. This is because the vendor variant will be
1105 // have .vendor suffix in its name in the make world. However, if the
1106 // lib is a vendor-only lib or this lib is not building against vndk,
1107 // then the suffix is not added.
1108 switch tag {
1109 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
1110 libName := strings.TrimSuffix(name, llndkLibrarySuffix)
1111 libName = strings.TrimPrefix(libName, "prebuilt_")
1112 isLLndk := inList(libName, config.LLndkLibraries())
1113 if c.vndk() && (Bool(cc.Properties.Vendor_available) || isLLndk) {
1114 libName += vendorSuffix
1115 }
1116 // Note: the order of libs in this list is not important because
1117 // they merely serve as dependencies in the make world and do not
1118 // affect this lib itself.
1119 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, libName)
1120 }
Colin Crossca860ac2016-01-04 14:34:37 -08001121 })
1122
Colin Crossdd84e052017-05-17 13:44:16 -07001123 // Dedup exported flags from dependencies
1124 depPaths.Flags = firstUniqueElements(depPaths.Flags)
1125
Colin Crossca860ac2016-01-04 14:34:37 -08001126 return depPaths
1127}
1128
1129func (c *Module) InstallInData() bool {
1130 if c.installer == nil {
1131 return false
1132 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001133 return c.installer.inData()
1134}
1135
1136func (c *Module) InstallInSanitizerDir() bool {
1137 if c.installer == nil {
1138 return false
1139 }
1140 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001141 return true
1142 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001143 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001144}
1145
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001146func (c *Module) HostToolPath() android.OptionalPath {
1147 if c.installer == nil {
1148 return android.OptionalPath{}
1149 }
1150 return c.installer.hostToolPath()
1151}
1152
Colin Cross2ba19d92015-05-07 15:44:20 -07001153//
Colin Crosscfad1192015-11-02 16:43:11 -08001154// Defaults
1155//
Colin Crossca860ac2016-01-04 14:34:37 -08001156type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001157 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001158 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001159}
1160
Colin Cross635c3b02016-05-18 15:37:25 -07001161func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001162}
1163
Colin Cross1e676be2016-10-12 14:38:15 -07001164func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1165}
1166
Colin Cross36242852017-06-23 15:06:31 -07001167func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001168 return DefaultsFactory()
1169}
1170
Colin Cross36242852017-06-23 15:06:31 -07001171func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001172 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001173
Colin Cross36242852017-06-23 15:06:31 -07001174 module.AddProperties(props...)
1175 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001176 &BaseProperties{},
1177 &BaseCompilerProperties{},
1178 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001179 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001180 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001181 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001182 &TestProperties{},
1183 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001184 &UnusedProperties{},
1185 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001186 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001187 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001188 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001189 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001190 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001191 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001192 &VndkProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001193 )
Colin Crosscfad1192015-11-02 16:43:11 -08001194
Colin Cross1f44a3a2017-07-07 14:33:33 -07001195 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001196
1197 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001198}
1199
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001200const (
1201 // coreMode is the variant used for framework-private libraries, or
1202 // SDK libraries. (which framework-private libraries can use)
1203 coreMode = "core"
1204
1205 // vendorMode is the variant used for /vendor code that compiles
1206 // against the VNDK.
1207 vendorMode = "vendor"
1208)
1209
1210func vendorMutator(mctx android.BottomUpMutatorContext) {
1211 if mctx.Os() != android.Android {
1212 return
1213 }
1214
1215 m, ok := mctx.Module().(*Module)
1216 if !ok {
1217 return
1218 }
1219
1220 // Sanity check
1221 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1222 mctx.PropertyErrorf("vendor_available",
1223 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1224 return
1225 }
Justin Yun8effde42017-06-23 19:24:43 +09001226 if vndk := m.vndkdep; vndk != nil {
1227 if vndk.isVndk() && !Bool(m.Properties.Vendor_available) {
1228 mctx.PropertyErrorf("vndk",
1229 "has to define `vendor_available: true` to enable vndk")
1230 return
1231 }
1232 if !vndk.isVndk() && vndk.isVndkSp() {
1233 mctx.PropertyErrorf("vndk",
1234 "must set `enabled: true` to set `support_system_process: true`")
1235 return
1236 }
1237 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001238
1239 if !mctx.DeviceConfig().CompileVndk() {
1240 // If the device isn't compiling against the VNDK, we always
1241 // use the core mode.
1242 mctx.CreateVariations(coreMode)
1243 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1244 // LL-NDK stubs only exist in the vendor variant, since the
1245 // real libraries will be used in the core variant.
1246 mctx.CreateVariations(vendorMode)
1247 } else if Bool(m.Properties.Vendor_available) {
1248 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001249 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001250 mod := mctx.CreateVariations(coreMode, vendorMode)
1251 mod[1].(*Module).Properties.UseVndk = true
1252 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1253 // This will be available in /vendor only
1254 mod := mctx.CreateVariations(vendorMode)
1255 mod[0].(*Module).Properties.UseVndk = true
1256 } else {
1257 // This is either in /system (or similar: /data), or is a
1258 // modules built with the NDK. Modules built with the NDK
1259 // will be restricted using the existing link type checks.
1260 mctx.CreateVariations(coreMode)
1261 }
1262}
1263
Colin Crossdd84e052017-05-17 13:44:16 -07001264// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1265// modifies the slice contents in place, and returns a subslice of the original slice
1266func firstUniqueElements(list []string) []string {
1267 k := 0
1268outer:
1269 for i := 0; i < len(list); i++ {
1270 for j := 0; j < k; j++ {
1271 if list[i] == list[j] {
1272 continue outer
1273 }
1274 }
1275 list[k] = list[i]
1276 k++
1277 }
1278 return list[:k]
1279}
1280
Colin Cross74d1ec02015-04-28 13:30:13 -07001281// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1282// modifies the slice contents in place, and returns a subslice of the original slice
1283func lastUniqueElements(list []string) []string {
1284 totalSkip := 0
1285 for i := len(list) - 1; i >= totalSkip; i-- {
1286 skip := 0
1287 for j := i - 1; j >= totalSkip; j-- {
1288 if list[i] == list[j] {
1289 skip++
1290 } else {
1291 list[j+skip] = list[j]
1292 }
1293 }
1294 totalSkip += skip
1295 }
1296 return list[totalSkip:]
1297}
Colin Cross06a931b2015-10-28 17:23:31 -07001298
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001299func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1300 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1301 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1302 }
1303 return ctx.AConfig().PlatformSdkVersion()
1304}
1305
Colin Cross06a931b2015-10-28 17:23:31 -07001306var Bool = proptools.Bool