blob: 3824a3be077c424d04b51b1389dd5b4322c3a6c3 [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
Colin Crossb5bc4b42016-07-11 16:11:59 -0700723 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
724 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700725
Dan Albert914449f2016-06-17 16:45:24 -0700726 variantNdkLibs := []string{}
727 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700728 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700729 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700730
Dan Albert914449f2016-06-17 16:45:24 -0700731 // Rewrites the names of shared libraries into the names of the NDK
732 // libraries where appropriate. This returns two slices.
733 //
734 // The first is a list of non-variant shared libraries (either rewritten
735 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
736 // because they are not NDK libraries).
737 //
738 // The second is a list of ndk_library modules. These need to be
739 // separated because they are a variation dependency and must be added
740 // in a different manner.
741 rewriteNdkLibs := func(list []string) ([]string, []string) {
742 variantLibs := []string{}
743 nonvariantLibs := []string{}
744 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700745 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700746 if !inList(entry, ndkMigratedLibs) {
747 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
748 } else {
749 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
750 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700751 } else if ctx.vndk() && inList(entry, config.LLndkLibraries()) {
752 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700753 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700754 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700755 }
756 }
Dan Albert914449f2016-06-17 16:45:24 -0700757 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700758 }
759
Dan Albert914449f2016-06-17 16:45:24 -0700760 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
761 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900762 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700763 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700764
Colin Cross32ec36c2016-12-15 07:39:51 -0800765 for _, lib := range deps.HeaderLibs {
766 depTag := headerDepTag
767 if inList(lib, deps.ReexportHeaderLibHeaders) {
768 depTag = headerExportDepTag
769 }
770 actx.AddVariationDependencies(nil, depTag, lib)
771 }
Colin Cross5950f382016-12-13 12:50:57 -0800772
Colin Crossc99deeb2016-04-11 15:06:20 -0700773 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
774 deps.WholeStaticLibs...)
775
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700776 for _, lib := range deps.StaticLibs {
777 depTag := staticDepTag
778 if inList(lib, deps.ReexportStaticLibHeaders) {
779 depTag = staticExportDepTag
780 }
Colin Cross15a0d462016-07-14 14:49:58 -0700781 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700782 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700783
784 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
785 deps.LateStaticLibs...)
786
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700787 for _, lib := range deps.SharedLibs {
788 depTag := sharedDepTag
789 if inList(lib, deps.ReexportSharedLibHeaders) {
790 depTag = sharedExportDepTag
791 }
Colin Cross15a0d462016-07-14 14:49:58 -0700792 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700793 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700794
795 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
796 deps.LateSharedLibs...)
797
Colin Cross68861832016-07-08 10:41:41 -0700798 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700799
800 for _, gen := range deps.GeneratedHeaders {
801 depTag := genHeaderDepTag
802 if inList(gen, deps.ReexportGeneratedHeaders) {
803 depTag = genHeaderExportDepTag
804 }
805 actx.AddDependency(c, depTag, gen)
806 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700807
Colin Cross68861832016-07-08 10:41:41 -0700808 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700809
810 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700811 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800812 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700813 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700814 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700815 }
Dan Albert914449f2016-06-17 16:45:24 -0700816
817 version := ctx.sdkVersion()
818 actx.AddVariationDependencies([]blueprint.Variation{
819 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
820 actx.AddVariationDependencies([]blueprint.Variation{
821 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700822}
Colin Cross21b9a242015-03-24 14:15:58 -0700823
Dan Albert7e9d2952016-08-04 13:02:36 -0700824func beginMutator(ctx android.BottomUpMutatorContext) {
825 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
826 c.beginMutator(ctx)
827 }
828}
829
Colin Crossca860ac2016-01-04 14:34:37 -0800830func (c *Module) clang(ctx BaseModuleContext) bool {
831 clang := Bool(c.Properties.Clang)
832
833 if c.Properties.Clang == nil {
834 if ctx.Host() {
835 clang = true
836 }
837
838 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
839 clang = true
840 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800841 }
Colin Cross28344522015-04-22 13:07:53 -0700842
Colin Crossca860ac2016-01-04 14:34:37 -0800843 if !c.toolchain(ctx).ClangSupported() {
844 clang = false
845 }
846
847 return clang
848}
849
Colin Crossc99deeb2016-04-11 15:06:20 -0700850// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700851func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800852 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800853
Dan Willemsena96ff642016-06-07 12:34:45 -0700854 // Whether a module can link to another module, taking into
855 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700856 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700857 if from.Target().Os != android.Android {
858 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700859 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700860 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700861 if from.Properties.UseVndk {
Justin Yun8effde42017-06-23 19:24:43 +0900862 // Though vendor code is limited by the vendor mutator,
863 // each vendor-available module needs to check
864 // link-type for VNDK.
865 if from.vndkdep != nil {
866 from.vndkdep.vndkCheckLinkType(ctx, to)
867 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700868 return
869 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700870 if from.Properties.Sdk_version == "" {
871 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700872 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700873 }
Colin Crossb916a382016-07-29 17:28:03 -0700874 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700875 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700876 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700877 }
878 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
879 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700880 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700881 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700882 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
883 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700884 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700885 }
Colin Crossb916a382016-07-29 17:28:03 -0700886 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700887 // These aren't real libraries, but are the stub shared libraries that are included in
888 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700889 return
Dan Albert914449f2016-06-17 16:45:24 -0700890 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700891 if to.Properties.Sdk_version == "" {
892 // NDK code linking to platform code is never okay.
893 ctx.ModuleErrorf("depends on non-NDK-built library %q",
894 ctx.OtherModuleName(to))
895 }
896
897 // All this point we know we have two NDK libraries, but we need to
898 // check that we're not linking against anything built against a higher
899 // API level, as it is only valid to link against older or equivalent
900 // APIs.
901
902 if from.Properties.Sdk_version == "current" {
903 // Current can link against anything.
904 return
905 } else if to.Properties.Sdk_version == "current" {
906 // Current can't be linked against by anything else.
907 ctx.ModuleErrorf("links %q built against newer API version %q",
908 ctx.OtherModuleName(to), "current")
909 }
910
911 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
912 if err != nil {
913 ctx.PropertyErrorf("sdk_version",
914 "Invalid sdk_version value (must be int): %q",
915 from.Properties.Sdk_version)
916 }
917 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
918 if err != nil {
919 ctx.PropertyErrorf("sdk_version",
920 "Invalid sdk_version value (must be int): %q",
921 to.Properties.Sdk_version)
922 }
923
924 if toApi > fromApi {
925 ctx.ModuleErrorf("links %q built against newer API version %q",
926 ctx.OtherModuleName(to), to.Properties.Sdk_version)
927 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700928 }
929
Colin Crossc99deeb2016-04-11 15:06:20 -0700930 ctx.VisitDirectDeps(func(m blueprint.Module) {
931 name := ctx.OtherModuleName(m)
932 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800933
Colin Cross635c3b02016-05-18 15:37:25 -0700934 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700935 if a == nil {
936 ctx.ModuleErrorf("module %q not an android module", name)
937 return
Colin Crossca860ac2016-01-04 14:34:37 -0800938 }
Colin Crossca860ac2016-01-04 14:34:37 -0800939
Dan Willemsena96ff642016-06-07 12:34:45 -0700940 cc, _ := m.(*Module)
941 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700942 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800943 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700944 case genSourceDepTag:
945 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
946 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
947 genRule.GeneratedSourceFiles()...)
948 } else {
949 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
950 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700951 // Support exported headers from a generated_sources dependency
952 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700953 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700954 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
955 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
956 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800957 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700958 depPaths.Flags = append(depPaths.Flags, flags)
959 if tag == genHeaderExportDepTag {
960 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700961 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
962 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700963 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
964 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
965
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700966 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700967 } else {
968 ctx.ModuleErrorf("module %q is not a genrule", name)
969 }
970 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700971 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800972 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700973 return
974 }
975
976 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800977 if ctx.AConfig().AllowMissingDependencies() {
978 ctx.AddMissingDependencies([]string{name})
979 } else {
980 ctx.ModuleErrorf("depends on disabled module %q", name)
981 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700982 return
983 }
984
Colin Crossa1ad8d12016-06-01 17:09:44 -0700985 if a.Target().Os != ctx.Os() {
986 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
987 return
988 }
989
990 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
991 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700992 return
993 }
994
Colin Crossc99deeb2016-04-11 15:06:20 -0700995 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -0800996 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700997 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -0700998 depPaths.Objs = depPaths.Objs.Append(objs)
999 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001000 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001001 return
1002 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001003 }
1004
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001005 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -07001006 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001007 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001008 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001009 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001010 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001011
1012 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001013 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001014 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001015 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1016 // Re-exported flags from shared library dependencies are not included as those shared libraries
1017 // will be included in the vndk set.
1018 if tag == staticExportDepTag || tag == headerExportDepTag {
1019 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
1020 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001021 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001022 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001023
Dan Albert9e10cd42016-08-03 14:12:14 -07001024 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -07001025 }
1026
Colin Cross26c34ed2016-09-30 17:10:16 -07001027 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001028 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001029
Colin Cross26c34ed2016-09-30 17:10:16 -07001030 linkFile := cc.outputFile
1031 depFile := android.OptionalPath{}
1032
Colin Crossc99deeb2016-04-11 15:06:20 -07001033 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -07001034 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001035 ptr = &depPaths.SharedLibs
1036 depPtr = &depPaths.SharedLibsDeps
1037 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001038 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001039 ptr = &depPaths.LateSharedLibs
1040 depPtr = &depPaths.LateSharedLibsDeps
1041 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001042 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001043 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001044 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001045 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001046 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001047 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001048 staticLib, ok := cc.linker.(libraryInterface)
1049 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001050 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001051 return
1052 }
1053
1054 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1055 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1056 for i := range missingDeps {
1057 missingDeps[i] += postfix
1058 }
1059 ctx.AddMissingDependencies(missingDeps)
1060 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001061 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001062 case headerDepTag:
1063 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001064 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001065 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001066 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001067 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001068 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001069 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001070 }
1071
Dan Willemsen581341d2017-02-09 16:16:31 -08001072 switch tag {
1073 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1074 staticLib, ok := cc.linker.(libraryInterface)
1075 if !ok || !staticLib.static() {
1076 ctx.ModuleErrorf("module %q not a static library", name)
1077 return
1078 }
1079
1080 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001081 // in static libraries act as if they were whole static libraries. The same goes for
1082 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001083 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1084 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001085 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1086 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001087 }
1088
Colin Cross26c34ed2016-09-30 17:10:16 -07001089 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001090 if !linkFile.Valid() {
1091 ctx.ModuleErrorf("module %q missing output file", name)
1092 return
1093 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001094 *ptr = append(*ptr, linkFile.Path())
1095 }
1096
Colin Crossc99deeb2016-04-11 15:06:20 -07001097 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001098 dep := depFile
1099 if !dep.Valid() {
1100 dep = linkFile
1101 }
1102 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001103 }
1104 })
1105
Colin Crossdd84e052017-05-17 13:44:16 -07001106 // Dedup exported flags from dependencies
1107 depPaths.Flags = firstUniqueElements(depPaths.Flags)
1108
Colin Crossca860ac2016-01-04 14:34:37 -08001109 return depPaths
1110}
1111
1112func (c *Module) InstallInData() bool {
1113 if c.installer == nil {
1114 return false
1115 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001116 return c.installer.inData()
1117}
1118
1119func (c *Module) InstallInSanitizerDir() bool {
1120 if c.installer == nil {
1121 return false
1122 }
1123 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001124 return true
1125 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001126 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001127}
1128
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001129func (c *Module) HostToolPath() android.OptionalPath {
1130 if c.installer == nil {
1131 return android.OptionalPath{}
1132 }
1133 return c.installer.hostToolPath()
1134}
1135
Colin Cross2ba19d92015-05-07 15:44:20 -07001136//
Colin Crosscfad1192015-11-02 16:43:11 -08001137// Defaults
1138//
Colin Crossca860ac2016-01-04 14:34:37 -08001139type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001140 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001141 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001142}
1143
Colin Cross635c3b02016-05-18 15:37:25 -07001144func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001145}
1146
Colin Cross1e676be2016-10-12 14:38:15 -07001147func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1148}
1149
Colin Cross36242852017-06-23 15:06:31 -07001150func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001151 return DefaultsFactory()
1152}
1153
Colin Cross36242852017-06-23 15:06:31 -07001154func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001155 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001156
Colin Cross36242852017-06-23 15:06:31 -07001157 module.AddProperties(props...)
1158 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001159 &BaseProperties{},
1160 &BaseCompilerProperties{},
1161 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001162 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001163 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001164 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001165 &TestProperties{},
1166 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001167 &UnusedProperties{},
1168 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001169 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001170 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001171 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001172 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001173 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001174 &SAbiProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001175 )
Colin Crosscfad1192015-11-02 16:43:11 -08001176
Colin Cross1f44a3a2017-07-07 14:33:33 -07001177 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001178
1179 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001180}
1181
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001182const (
1183 // coreMode is the variant used for framework-private libraries, or
1184 // SDK libraries. (which framework-private libraries can use)
1185 coreMode = "core"
1186
1187 // vendorMode is the variant used for /vendor code that compiles
1188 // against the VNDK.
1189 vendorMode = "vendor"
1190)
1191
1192func vendorMutator(mctx android.BottomUpMutatorContext) {
1193 if mctx.Os() != android.Android {
1194 return
1195 }
1196
1197 m, ok := mctx.Module().(*Module)
1198 if !ok {
1199 return
1200 }
1201
1202 // Sanity check
1203 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1204 mctx.PropertyErrorf("vendor_available",
1205 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1206 return
1207 }
Justin Yun8effde42017-06-23 19:24:43 +09001208 if vndk := m.vndkdep; vndk != nil {
1209 if vndk.isVndk() && !Bool(m.Properties.Vendor_available) {
1210 mctx.PropertyErrorf("vndk",
1211 "has to define `vendor_available: true` to enable vndk")
1212 return
1213 }
1214 if !vndk.isVndk() && vndk.isVndkSp() {
1215 mctx.PropertyErrorf("vndk",
1216 "must set `enabled: true` to set `support_system_process: true`")
1217 return
1218 }
1219 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001220
1221 if !mctx.DeviceConfig().CompileVndk() {
1222 // If the device isn't compiling against the VNDK, we always
1223 // use the core mode.
1224 mctx.CreateVariations(coreMode)
1225 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1226 // LL-NDK stubs only exist in the vendor variant, since the
1227 // real libraries will be used in the core variant.
1228 mctx.CreateVariations(vendorMode)
1229 } else if Bool(m.Properties.Vendor_available) {
1230 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001231 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001232 mod := mctx.CreateVariations(coreMode, vendorMode)
1233 mod[1].(*Module).Properties.UseVndk = true
1234 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1235 // This will be available in /vendor only
1236 mod := mctx.CreateVariations(vendorMode)
1237 mod[0].(*Module).Properties.UseVndk = true
1238 } else {
1239 // This is either in /system (or similar: /data), or is a
1240 // modules built with the NDK. Modules built with the NDK
1241 // will be restricted using the existing link type checks.
1242 mctx.CreateVariations(coreMode)
1243 }
1244}
1245
Colin Crossdd84e052017-05-17 13:44:16 -07001246// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1247// modifies the slice contents in place, and returns a subslice of the original slice
1248func firstUniqueElements(list []string) []string {
1249 k := 0
1250outer:
1251 for i := 0; i < len(list); i++ {
1252 for j := 0; j < k; j++ {
1253 if list[i] == list[j] {
1254 continue outer
1255 }
1256 }
1257 list[k] = list[i]
1258 k++
1259 }
1260 return list[:k]
1261}
1262
Colin Cross74d1ec02015-04-28 13:30:13 -07001263// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1264// modifies the slice contents in place, and returns a subslice of the original slice
1265func lastUniqueElements(list []string) []string {
1266 totalSkip := 0
1267 for i := len(list) - 1; i >= totalSkip; i-- {
1268 skip := 0
1269 for j := i - 1; j >= totalSkip; j-- {
1270 if list[i] == list[j] {
1271 skip++
1272 } else {
1273 list[j+skip] = list[j]
1274 }
1275 }
1276 totalSkip += skip
1277 }
1278 return list[totalSkip:]
1279}
Colin Cross06a931b2015-10-28 17:23:31 -07001280
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001281func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1282 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1283 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1284 }
1285 return ctx.AConfig().PlatformSdkVersion()
1286}
1287
Colin Cross06a931b2015-10-28 17:23:31 -07001288var Bool = proptools.Bool