blob: a3f4c1d2222ab1f1b7e0277d363d70a3aff6596f [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
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800186 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700187 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700188 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800189}
190
191type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700192 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800193 ModuleContextIntf
194}
195
196type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700197 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800198 ModuleContextIntf
199}
200
Colin Cross37047f12016-12-13 17:06:13 -0800201type DepsContext interface {
202 android.BottomUpMutatorContext
203 ModuleContextIntf
204}
205
Colin Crossca860ac2016-01-04 14:34:37 -0800206type feature interface {
207 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800208 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800209 flags(ctx ModuleContext, flags Flags) Flags
210 props() []interface{}
211}
212
213type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700214 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800215 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700216 compilerFlags(ctx ModuleContext, flags Flags) Flags
217 compilerProps() []interface{}
218
Colin Cross76fada02016-07-27 10:31:13 -0700219 appendCflags([]string)
220 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700221 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800222}
223
224type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700225 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800226 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700227 linkerFlags(ctx ModuleContext, flags Flags) Flags
228 linkerProps() []interface{}
229
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700230 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700231 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800232}
233
234type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700235 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700236 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800237 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700238 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700239 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800240}
241
Colin Crossc99deeb2016-04-11 15:06:20 -0700242type dependencyTag struct {
243 blueprint.BaseDependencyTag
244 name string
245 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700246
247 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700248}
249
250var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700251 sharedDepTag = dependencyTag{name: "shared", library: true}
252 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
253 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
254 staticDepTag = dependencyTag{name: "static", library: true}
255 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
256 lateStaticDepTag = dependencyTag{name: "late static", library: true}
257 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800258 headerDepTag = dependencyTag{name: "header", library: true}
259 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700260 genSourceDepTag = dependencyTag{name: "gen source"}
261 genHeaderDepTag = dependencyTag{name: "gen header"}
262 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
263 objDepTag = dependencyTag{name: "obj"}
264 crtBeginDepTag = dependencyTag{name: "crtbegin"}
265 crtEndDepTag = dependencyTag{name: "crtend"}
266 reuseObjTag = dependencyTag{name: "reuse objects"}
267 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
268 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700269)
270
Colin Crossca860ac2016-01-04 14:34:37 -0800271// Module contains the properties and members used by all C/C++ module types, and implements
272// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
273// to construct the output file. Behavior can be customized with a Customizer interface
274type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700275 android.ModuleBase
276 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700277
Colin Crossca860ac2016-01-04 14:34:37 -0800278 Properties BaseProperties
279 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700280
Colin Crossca860ac2016-01-04 14:34:37 -0800281 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700282 hod android.HostOrDeviceSupported
283 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700284
Colin Crossca860ac2016-01-04 14:34:37 -0800285 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700286 features []feature
287 compiler compiler
288 linker linker
289 installer installer
290 stl *stl
291 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800292 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800293 sabi *sabi
Colin Cross16b23492016-01-06 14:41:07 -0800294
295 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700296
Colin Cross635c3b02016-05-18 15:37:25 -0700297 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800298
Colin Crossb98c8b02016-07-29 13:44:28 -0700299 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700300
301 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800302
303 // Flags used to compile this module
304 flags Flags
Colin Crossc472d572015-03-17 15:06:21 -0700305}
306
Colin Cross36242852017-06-23 15:06:31 -0700307func (c *Module) Init() android.Module {
308 c.AddProperties(&c.Properties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800309 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700310 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800311 }
312 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700313 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800314 }
315 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700316 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800317 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700318 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700319 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700320 }
Colin Cross16b23492016-01-06 14:41:07 -0800321 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700322 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800323 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800324 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700325 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800326 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800327 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700328 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800329 }
Colin Crossca860ac2016-01-04 14:34:37 -0800330 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700331 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800332 }
Colin Crossc472d572015-03-17 15:06:21 -0700333
Colin Cross36242852017-06-23 15:06:31 -0700334 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700335
Colin Cross36242852017-06-23 15:06:31 -0700336 android.InitDefaultableModule(c, c)
337
338 return c
Colin Crossc472d572015-03-17 15:06:21 -0700339}
340
Colin Crossb916a382016-07-29 17:28:03 -0700341// Returns true for dependency roots (binaries)
342// TODO(ccross): also handle dlopenable libraries
343func (c *Module) isDependencyRoot() bool {
344 if root, ok := c.linker.(interface {
345 isDependencyRoot() bool
346 }); ok {
347 return root.isDependencyRoot()
348 }
349 return false
350}
351
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700352func (c *Module) vndk() bool {
353 return c.Properties.UseVndk
354}
355
Colin Crossca860ac2016-01-04 14:34:37 -0800356type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700357 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800358 moduleContextImpl
359}
360
Colin Cross37047f12016-12-13 17:06:13 -0800361type depsContext struct {
362 android.BottomUpMutatorContext
363 moduleContextImpl
364}
365
Colin Crossca860ac2016-01-04 14:34:37 -0800366type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700367 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800368 moduleContextImpl
369}
370
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700371// Vendor returns true for vendor modules so that they get installed onto the
372// correct partition
373func (ctx *moduleContext) Vendor() bool {
374 return ctx.ModuleContext.Vendor() || ctx.moduleContextImpl.mod.Properties.UseVndk
375}
376
Colin Crossca860ac2016-01-04 14:34:37 -0800377type moduleContextImpl struct {
378 mod *Module
379 ctx BaseModuleContext
380}
381
Colin Crossca860ac2016-01-04 14:34:37 -0800382func (ctx *moduleContextImpl) clang() bool {
383 return ctx.mod.clang(ctx.ctx)
384}
385
Colin Crossb98c8b02016-07-29 13:44:28 -0700386func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800387 return ctx.mod.toolchain(ctx.ctx)
388}
389
390func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700391 if static, ok := ctx.mod.linker.(interface {
392 static() bool
393 }); ok {
394 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800395 }
Colin Crossb916a382016-07-29 17:28:03 -0700396 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800397}
398
399func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700400 if static, ok := ctx.mod.linker.(interface {
401 staticBinary() bool
402 }); ok {
403 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800404 }
Colin Crossb916a382016-07-29 17:28:03 -0700405 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800406}
407
408func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
409 return Bool(ctx.mod.Properties.No_default_compiler_flags)
410}
411
412func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700413 if ctx.ctx.Device() && !ctx.vndk() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700414 return ctx.mod.Properties.Sdk_version != ""
415 }
416 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800417}
418
419func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700420 if ctx.ctx.Device() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700421 if ctx.vndk() {
422 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800423 } else {
424 return ctx.mod.Properties.Sdk_version
425 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700426 }
427 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800428}
429
Dan Willemsend2ede872016-11-18 14:54:24 -0800430func (ctx *moduleContextImpl) vndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700431 return ctx.mod.vndk()
Dan Willemsend2ede872016-11-18 14:54:24 -0800432}
433
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800434// Create source abi dumps if the module belongs to the list of VndkLibraries.
435func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700436 return ctx.ctx.Device() && ((Bool(ctx.mod.Properties.Vendor_available)) || (inList(ctx.baseModuleName(), config.LLndkLibraries())))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800437}
438
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700439func (ctx *moduleContextImpl) selectedStl() string {
440 if stl := ctx.mod.stl; stl != nil {
441 return stl.Properties.SelectedStl
442 }
443 return ""
444}
445
Colin Crossce75d2c2016-10-06 16:12:58 -0700446func (ctx *moduleContextImpl) baseModuleName() string {
447 return ctx.mod.ModuleBase.BaseModuleName()
448}
449
Colin Cross635c3b02016-05-18 15:37:25 -0700450func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800451 return &Module{
452 hod: hod,
453 multilib: multilib,
454 }
455}
456
Colin Cross635c3b02016-05-18 15:37:25 -0700457func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800458 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700459 module.features = []feature{
460 &tidyFeature{},
461 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700462 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800463 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800464 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800465 module.sabi = &sabi{}
Colin Crossca860ac2016-01-04 14:34:37 -0800466 return module
467}
468
Colin Crossce75d2c2016-10-06 16:12:58 -0700469func (c *Module) Prebuilt() *android.Prebuilt {
470 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
471 return p.prebuilt()
472 }
473 return nil
474}
475
476func (c *Module) Name() string {
477 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700478 if p, ok := c.linker.(interface {
479 Name(string) string
480 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700481 name = p.Name(name)
482 }
483 return name
484}
485
Colin Cross635c3b02016-05-18 15:37:25 -0700486func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800487 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700488 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800489 moduleContextImpl: moduleContextImpl{
490 mod: c,
491 },
492 }
493 ctx.ctx = ctx
494
495 flags := Flags{
496 Toolchain: c.toolchain(ctx),
497 Clang: c.clang(ctx),
498 }
Colin Crossca860ac2016-01-04 14:34:37 -0800499 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700500 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800501 }
502 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700503 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800504 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700505 if c.stl != nil {
506 flags = c.stl.flags(ctx, flags)
507 }
Colin Cross16b23492016-01-06 14:41:07 -0800508 if c.sanitize != nil {
509 flags = c.sanitize.flags(ctx, flags)
510 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800511 if c.coverage != nil {
512 flags = c.coverage.flags(ctx, flags)
513 }
Colin Crossca860ac2016-01-04 14:34:37 -0800514 for _, feature := range c.features {
515 flags = feature.flags(ctx, flags)
516 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800517 if ctx.Failed() {
518 return
519 }
520
Colin Crossb98c8b02016-07-29 13:44:28 -0700521 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
522 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
523 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800524
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800525 deps := c.depsToPaths(ctx)
526 if ctx.Failed() {
527 return
528 }
529 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
530 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700531 // We need access to all the flags seen by a source file.
532 if c.sabi != nil {
533 flags = c.sabi.flags(ctx, flags)
534 }
Colin Crossca860ac2016-01-04 14:34:37 -0800535 // Optimization to reduce size of build.ninja
536 // Replace the long list of flags for each file with a module-local variable
537 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
538 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
539 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
540 flags.CFlags = []string{"$cflags"}
541 flags.CppFlags = []string{"$cppflags"}
542 flags.AsFlags = []string{"$asflags"}
543
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700544 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800545 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700546 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800547 if ctx.Failed() {
548 return
549 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800550 }
551
Colin Crossca860ac2016-01-04 14:34:37 -0800552 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700553 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800554 if ctx.Failed() {
555 return
556 }
Colin Cross635c3b02016-05-18 15:37:25 -0700557 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700558 }
Colin Cross5049f022015-03-18 13:28:46 -0700559
Colin Crossce75d2c2016-10-06 16:12:58 -0700560 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
561 c.installer.install(ctx, c.outputFile.Path())
562 if ctx.Failed() {
563 return
Colin Crossca860ac2016-01-04 14:34:37 -0800564 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700565 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800566}
567
Colin Crossb98c8b02016-07-29 13:44:28 -0700568func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800569 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700570 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800571 }
Colin Crossca860ac2016-01-04 14:34:37 -0800572 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800573}
574
Colin Crossca860ac2016-01-04 14:34:37 -0800575func (c *Module) begin(ctx BaseModuleContext) {
576 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700577 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700578 }
Colin Crossca860ac2016-01-04 14:34:37 -0800579 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700580 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800581 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700582 if c.stl != nil {
583 c.stl.begin(ctx)
584 }
Colin Cross16b23492016-01-06 14:41:07 -0800585 if c.sanitize != nil {
586 c.sanitize.begin(ctx)
587 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800588 if c.coverage != nil {
589 c.coverage.begin(ctx)
590 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800591 if c.sabi != nil {
592 c.sabi.begin(ctx)
593 }
Colin Crossca860ac2016-01-04 14:34:37 -0800594 for _, feature := range c.features {
595 feature.begin(ctx)
596 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700597 if ctx.sdk() {
598 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
599 if err != nil {
600 ctx.PropertyErrorf("sdk_version", err.Error())
601 }
Dan Albert90f7a4d2016-11-08 14:34:24 -0800602 c.Properties.Sdk_version = version
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700603 }
Colin Crossca860ac2016-01-04 14:34:37 -0800604}
605
Colin Cross37047f12016-12-13 17:06:13 -0800606func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700607 deps := Deps{}
608
609 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700610 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700611 }
612 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700613 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700614 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700615 if c.stl != nil {
616 deps = c.stl.deps(ctx, deps)
617 }
Colin Cross16b23492016-01-06 14:41:07 -0800618 if c.sanitize != nil {
619 deps = c.sanitize.deps(ctx, deps)
620 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800621 if c.coverage != nil {
622 deps = c.coverage.deps(ctx, deps)
623 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800624 if c.sabi != nil {
625 deps = c.sabi.deps(ctx, deps)
626 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700627 for _, feature := range c.features {
628 deps = feature.deps(ctx, deps)
629 }
630
631 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
632 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
633 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
634 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
635 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
Colin Cross5950f382016-12-13 12:50:57 -0800636 deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700637
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700638 for _, lib := range deps.ReexportSharedLibHeaders {
639 if !inList(lib, deps.SharedLibs) {
640 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
641 }
642 }
643
644 for _, lib := range deps.ReexportStaticLibHeaders {
645 if !inList(lib, deps.StaticLibs) {
646 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
647 }
648 }
649
Colin Cross5950f382016-12-13 12:50:57 -0800650 for _, lib := range deps.ReexportHeaderLibHeaders {
651 if !inList(lib, deps.HeaderLibs) {
652 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
653 }
654 }
655
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700656 for _, gen := range deps.ReexportGeneratedHeaders {
657 if !inList(gen, deps.GeneratedHeaders) {
658 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
659 }
660 }
661
Colin Crossc99deeb2016-04-11 15:06:20 -0700662 return deps
663}
664
Dan Albert7e9d2952016-08-04 13:02:36 -0700665func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800666 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700667 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800668 moduleContextImpl: moduleContextImpl{
669 mod: c,
670 },
671 }
672 ctx.ctx = ctx
673
Colin Crossca860ac2016-01-04 14:34:37 -0800674 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700675}
676
Colin Cross1e676be2016-10-12 14:38:15 -0700677func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
678 if !c.Enabled() {
679 return
680 }
681
Colin Cross37047f12016-12-13 17:06:13 -0800682 ctx := &depsContext{
683 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700684 moduleContextImpl: moduleContextImpl{
685 mod: c,
686 },
687 }
688 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800689
Colin Crossc99deeb2016-04-11 15:06:20 -0700690 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800691
Colin Crossb5bc4b42016-07-11 16:11:59 -0700692 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
693 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700694
Dan Albert914449f2016-06-17 16:45:24 -0700695 variantNdkLibs := []string{}
696 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700697 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700698 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700699
Dan Albert914449f2016-06-17 16:45:24 -0700700 // Rewrites the names of shared libraries into the names of the NDK
701 // libraries where appropriate. This returns two slices.
702 //
703 // The first is a list of non-variant shared libraries (either rewritten
704 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
705 // because they are not NDK libraries).
706 //
707 // The second is a list of ndk_library modules. These need to be
708 // separated because they are a variation dependency and must be added
709 // in a different manner.
710 rewriteNdkLibs := func(list []string) ([]string, []string) {
711 variantLibs := []string{}
712 nonvariantLibs := []string{}
713 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700714 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700715 if !inList(entry, ndkMigratedLibs) {
716 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
717 } else {
718 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
719 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700720 } else if ctx.vndk() && inList(entry, config.LLndkLibraries()) {
721 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700722 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700723 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700724 }
725 }
Dan Albert914449f2016-06-17 16:45:24 -0700726 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700727 }
728
Dan Albert914449f2016-06-17 16:45:24 -0700729 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
730 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700731 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700732
Colin Cross32ec36c2016-12-15 07:39:51 -0800733 for _, lib := range deps.HeaderLibs {
734 depTag := headerDepTag
735 if inList(lib, deps.ReexportHeaderLibHeaders) {
736 depTag = headerExportDepTag
737 }
738 actx.AddVariationDependencies(nil, depTag, lib)
739 }
Colin Cross5950f382016-12-13 12:50:57 -0800740
Colin Crossc99deeb2016-04-11 15:06:20 -0700741 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
742 deps.WholeStaticLibs...)
743
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700744 for _, lib := range deps.StaticLibs {
745 depTag := staticDepTag
746 if inList(lib, deps.ReexportStaticLibHeaders) {
747 depTag = staticExportDepTag
748 }
Colin Cross15a0d462016-07-14 14:49:58 -0700749 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700750 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700751
752 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
753 deps.LateStaticLibs...)
754
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700755 for _, lib := range deps.SharedLibs {
756 depTag := sharedDepTag
757 if inList(lib, deps.ReexportSharedLibHeaders) {
758 depTag = sharedExportDepTag
759 }
Colin Cross15a0d462016-07-14 14:49:58 -0700760 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700761 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700762
763 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
764 deps.LateSharedLibs...)
765
Colin Cross68861832016-07-08 10:41:41 -0700766 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700767
768 for _, gen := range deps.GeneratedHeaders {
769 depTag := genHeaderDepTag
770 if inList(gen, deps.ReexportGeneratedHeaders) {
771 depTag = genHeaderExportDepTag
772 }
773 actx.AddDependency(c, depTag, gen)
774 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700775
Colin Cross68861832016-07-08 10:41:41 -0700776 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700777
778 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700779 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800780 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700781 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700782 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700783 }
Dan Albert914449f2016-06-17 16:45:24 -0700784
785 version := ctx.sdkVersion()
786 actx.AddVariationDependencies([]blueprint.Variation{
787 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
788 actx.AddVariationDependencies([]blueprint.Variation{
789 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700790}
Colin Cross21b9a242015-03-24 14:15:58 -0700791
Dan Albert7e9d2952016-08-04 13:02:36 -0700792func beginMutator(ctx android.BottomUpMutatorContext) {
793 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
794 c.beginMutator(ctx)
795 }
796}
797
Colin Crossca860ac2016-01-04 14:34:37 -0800798func (c *Module) clang(ctx BaseModuleContext) bool {
799 clang := Bool(c.Properties.Clang)
800
801 if c.Properties.Clang == nil {
802 if ctx.Host() {
803 clang = true
804 }
805
806 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
807 clang = true
808 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800809 }
Colin Cross28344522015-04-22 13:07:53 -0700810
Colin Crossca860ac2016-01-04 14:34:37 -0800811 if !c.toolchain(ctx).ClangSupported() {
812 clang = false
813 }
814
815 return clang
816}
817
Colin Crossc99deeb2016-04-11 15:06:20 -0700818// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700819func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800820 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800821
Dan Willemsena96ff642016-06-07 12:34:45 -0700822 // Whether a module can link to another module, taking into
823 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700824 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700825 if from.Target().Os != android.Android {
826 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700827 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700828 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700829 if from.Properties.UseVndk {
830 // Vendor code is already limited by the vendor mutator
831 return
832 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700833 if from.Properties.Sdk_version == "" {
834 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700835 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700836 }
Colin Crossb916a382016-07-29 17:28:03 -0700837 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700838 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700839 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700840 }
841 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
842 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700843 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700844 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700845 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
846 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700847 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700848 }
Colin Crossb916a382016-07-29 17:28:03 -0700849 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700850 // These aren't real libraries, but are the stub shared libraries that are included in
851 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700852 return
Dan Albert914449f2016-06-17 16:45:24 -0700853 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700854 if to.Properties.Sdk_version == "" {
855 // NDK code linking to platform code is never okay.
856 ctx.ModuleErrorf("depends on non-NDK-built library %q",
857 ctx.OtherModuleName(to))
858 }
859
860 // All this point we know we have two NDK libraries, but we need to
861 // check that we're not linking against anything built against a higher
862 // API level, as it is only valid to link against older or equivalent
863 // APIs.
864
865 if from.Properties.Sdk_version == "current" {
866 // Current can link against anything.
867 return
868 } else if to.Properties.Sdk_version == "current" {
869 // Current can't be linked against by anything else.
870 ctx.ModuleErrorf("links %q built against newer API version %q",
871 ctx.OtherModuleName(to), "current")
872 }
873
874 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
875 if err != nil {
876 ctx.PropertyErrorf("sdk_version",
877 "Invalid sdk_version value (must be int): %q",
878 from.Properties.Sdk_version)
879 }
880 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
881 if err != nil {
882 ctx.PropertyErrorf("sdk_version",
883 "Invalid sdk_version value (must be int): %q",
884 to.Properties.Sdk_version)
885 }
886
887 if toApi > fromApi {
888 ctx.ModuleErrorf("links %q built against newer API version %q",
889 ctx.OtherModuleName(to), to.Properties.Sdk_version)
890 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700891 }
892
Colin Crossc99deeb2016-04-11 15:06:20 -0700893 ctx.VisitDirectDeps(func(m blueprint.Module) {
894 name := ctx.OtherModuleName(m)
895 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800896
Colin Cross635c3b02016-05-18 15:37:25 -0700897 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700898 if a == nil {
899 ctx.ModuleErrorf("module %q not an android module", name)
900 return
Colin Crossca860ac2016-01-04 14:34:37 -0800901 }
Colin Crossca860ac2016-01-04 14:34:37 -0800902
Dan Willemsena96ff642016-06-07 12:34:45 -0700903 cc, _ := m.(*Module)
904 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700905 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800906 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700907 case genSourceDepTag:
908 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
909 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
910 genRule.GeneratedSourceFiles()...)
911 } else {
912 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
913 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700914 // Support exported headers from a generated_sources dependency
915 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700916 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700917 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
918 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
919 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800920 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700921 depPaths.Flags = append(depPaths.Flags, flags)
922 if tag == genHeaderExportDepTag {
923 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700924 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
925 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700926 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
927 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
928
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700929 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700930 } else {
931 ctx.ModuleErrorf("module %q is not a genrule", name)
932 }
933 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700934 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800935 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700936 return
937 }
938
939 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800940 if ctx.AConfig().AllowMissingDependencies() {
941 ctx.AddMissingDependencies([]string{name})
942 } else {
943 ctx.ModuleErrorf("depends on disabled module %q", name)
944 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700945 return
946 }
947
Colin Crossa1ad8d12016-06-01 17:09:44 -0700948 if a.Target().Os != ctx.Os() {
949 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
950 return
951 }
952
953 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
954 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700955 return
956 }
957
Colin Crossc99deeb2016-04-11 15:06:20 -0700958 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -0800959 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700960 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -0700961 depPaths.Objs = depPaths.Objs.Append(objs)
962 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700963 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -0800964 return
965 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700966 }
967
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700968 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700969 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700970 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -0700971 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -0700972 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700973 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700974
975 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700976 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700977 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700978 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
979 // Re-exported flags from shared library dependencies are not included as those shared libraries
980 // will be included in the vndk set.
981 if tag == staticExportDepTag || tag == headerExportDepTag {
982 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
983 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700984 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700985 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700986
Dan Albert9e10cd42016-08-03 14:12:14 -0700987 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700988 }
989
Colin Cross26c34ed2016-09-30 17:10:16 -0700990 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700991 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700992
Colin Cross26c34ed2016-09-30 17:10:16 -0700993 linkFile := cc.outputFile
994 depFile := android.OptionalPath{}
995
Colin Crossc99deeb2016-04-11 15:06:20 -0700996 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700997 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -0700998 ptr = &depPaths.SharedLibs
999 depPtr = &depPaths.SharedLibsDeps
1000 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001001 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001002 ptr = &depPaths.LateSharedLibs
1003 depPtr = &depPaths.LateSharedLibsDeps
1004 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001005 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001006 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001007 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001008 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001009 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001010 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001011 staticLib, ok := cc.linker.(libraryInterface)
1012 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001013 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001014 return
1015 }
1016
1017 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1018 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1019 for i := range missingDeps {
1020 missingDeps[i] += postfix
1021 }
1022 ctx.AddMissingDependencies(missingDeps)
1023 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001024 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001025 case headerDepTag:
1026 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001027 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001028 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001029 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001030 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001031 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001032 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001033 }
1034
Dan Willemsen581341d2017-02-09 16:16:31 -08001035 switch tag {
1036 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1037 staticLib, ok := cc.linker.(libraryInterface)
1038 if !ok || !staticLib.static() {
1039 ctx.ModuleErrorf("module %q not a static library", name)
1040 return
1041 }
1042
1043 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001044 // in static libraries act as if they were whole static libraries. The same goes for
1045 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001046 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1047 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001048 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1049 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001050 }
1051
Colin Cross26c34ed2016-09-30 17:10:16 -07001052 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001053 if !linkFile.Valid() {
1054 ctx.ModuleErrorf("module %q missing output file", name)
1055 return
1056 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001057 *ptr = append(*ptr, linkFile.Path())
1058 }
1059
Colin Crossc99deeb2016-04-11 15:06:20 -07001060 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001061 dep := depFile
1062 if !dep.Valid() {
1063 dep = linkFile
1064 }
1065 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001066 }
1067 })
1068
Colin Crossdd84e052017-05-17 13:44:16 -07001069 // Dedup exported flags from dependencies
1070 depPaths.Flags = firstUniqueElements(depPaths.Flags)
1071
Colin Crossca860ac2016-01-04 14:34:37 -08001072 return depPaths
1073}
1074
1075func (c *Module) InstallInData() bool {
1076 if c.installer == nil {
1077 return false
1078 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001079 return c.installer.inData()
1080}
1081
1082func (c *Module) InstallInSanitizerDir() bool {
1083 if c.installer == nil {
1084 return false
1085 }
1086 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001087 return true
1088 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001089 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001090}
1091
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001092func (c *Module) HostToolPath() android.OptionalPath {
1093 if c.installer == nil {
1094 return android.OptionalPath{}
1095 }
1096 return c.installer.hostToolPath()
1097}
1098
Colin Cross2ba19d92015-05-07 15:44:20 -07001099//
Colin Crosscfad1192015-11-02 16:43:11 -08001100// Defaults
1101//
Colin Crossca860ac2016-01-04 14:34:37 -08001102type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001103 android.ModuleBase
1104 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -08001105}
1106
Colin Cross635c3b02016-05-18 15:37:25 -07001107func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001108}
1109
Colin Cross1e676be2016-10-12 14:38:15 -07001110func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1111}
1112
Colin Cross36242852017-06-23 15:06:31 -07001113func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001114 return DefaultsFactory()
1115}
1116
Colin Cross36242852017-06-23 15:06:31 -07001117func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001118 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001119
Colin Cross36242852017-06-23 15:06:31 -07001120 module.AddProperties(props...)
1121 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001122 &BaseProperties{},
1123 &BaseCompilerProperties{},
1124 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001125 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001126 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001127 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001128 &TestProperties{},
1129 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001130 &UnusedProperties{},
1131 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001132 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001133 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001134 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001135 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001136 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001137 &SAbiProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001138 )
Colin Crosscfad1192015-11-02 16:43:11 -08001139
Colin Cross36242852017-06-23 15:06:31 -07001140 android.InitDefaultsModule(module, module)
1141
1142 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001143}
1144
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001145const (
1146 // coreMode is the variant used for framework-private libraries, or
1147 // SDK libraries. (which framework-private libraries can use)
1148 coreMode = "core"
1149
1150 // vendorMode is the variant used for /vendor code that compiles
1151 // against the VNDK.
1152 vendorMode = "vendor"
1153)
1154
1155func vendorMutator(mctx android.BottomUpMutatorContext) {
1156 if mctx.Os() != android.Android {
1157 return
1158 }
1159
1160 m, ok := mctx.Module().(*Module)
1161 if !ok {
1162 return
1163 }
1164
1165 // Sanity check
1166 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1167 mctx.PropertyErrorf("vendor_available",
1168 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1169 return
1170 }
1171
1172 if !mctx.DeviceConfig().CompileVndk() {
1173 // If the device isn't compiling against the VNDK, we always
1174 // use the core mode.
1175 mctx.CreateVariations(coreMode)
1176 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1177 // LL-NDK stubs only exist in the vendor variant, since the
1178 // real libraries will be used in the core variant.
1179 mctx.CreateVariations(vendorMode)
1180 } else if Bool(m.Properties.Vendor_available) {
1181 // This will be available in both /system and /vendor
1182 mod := mctx.CreateVariations(coreMode, vendorMode)
1183 mod[1].(*Module).Properties.UseVndk = true
1184 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1185 // This will be available in /vendor only
1186 mod := mctx.CreateVariations(vendorMode)
1187 mod[0].(*Module).Properties.UseVndk = true
1188 } else {
1189 // This is either in /system (or similar: /data), or is a
1190 // modules built with the NDK. Modules built with the NDK
1191 // will be restricted using the existing link type checks.
1192 mctx.CreateVariations(coreMode)
1193 }
1194}
1195
Colin Crossdd84e052017-05-17 13:44:16 -07001196// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1197// modifies the slice contents in place, and returns a subslice of the original slice
1198func firstUniqueElements(list []string) []string {
1199 k := 0
1200outer:
1201 for i := 0; i < len(list); i++ {
1202 for j := 0; j < k; j++ {
1203 if list[i] == list[j] {
1204 continue outer
1205 }
1206 }
1207 list[k] = list[i]
1208 k++
1209 }
1210 return list[:k]
1211}
1212
Colin Cross74d1ec02015-04-28 13:30:13 -07001213// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1214// modifies the slice contents in place, and returns a subslice of the original slice
1215func lastUniqueElements(list []string) []string {
1216 totalSkip := 0
1217 for i := len(list) - 1; i >= totalSkip; i-- {
1218 skip := 0
1219 for j := i - 1; j >= totalSkip; j-- {
1220 if list[i] == list[j] {
1221 skip++
1222 } else {
1223 list[j+skip] = list[j]
1224 }
1225 }
1226 totalSkip += skip
1227 }
1228 return list[totalSkip:]
1229}
Colin Cross06a931b2015-10-28 17:23:31 -07001230
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001231func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1232 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1233 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1234 }
1235 return ctx.AConfig().PlatformSdkVersion()
1236}
1237
Colin Cross06a931b2015-10-28 17:23:31 -07001238var Bool = proptools.Bool