blob: c17b95e54a4a5ab5e94746b0bd24e1272c4a89ed [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)
Jiyong Park4c35af02017-07-05 13:41:55 +0900731 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700732 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700733
Colin Cross32ec36c2016-12-15 07:39:51 -0800734 for _, lib := range deps.HeaderLibs {
735 depTag := headerDepTag
736 if inList(lib, deps.ReexportHeaderLibHeaders) {
737 depTag = headerExportDepTag
738 }
739 actx.AddVariationDependencies(nil, depTag, lib)
740 }
Colin Cross5950f382016-12-13 12:50:57 -0800741
Colin Crossc99deeb2016-04-11 15:06:20 -0700742 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
743 deps.WholeStaticLibs...)
744
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700745 for _, lib := range deps.StaticLibs {
746 depTag := staticDepTag
747 if inList(lib, deps.ReexportStaticLibHeaders) {
748 depTag = staticExportDepTag
749 }
Colin Cross15a0d462016-07-14 14:49:58 -0700750 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700751 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700752
753 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
754 deps.LateStaticLibs...)
755
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700756 for _, lib := range deps.SharedLibs {
757 depTag := sharedDepTag
758 if inList(lib, deps.ReexportSharedLibHeaders) {
759 depTag = sharedExportDepTag
760 }
Colin Cross15a0d462016-07-14 14:49:58 -0700761 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700762 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700763
764 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
765 deps.LateSharedLibs...)
766
Colin Cross68861832016-07-08 10:41:41 -0700767 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700768
769 for _, gen := range deps.GeneratedHeaders {
770 depTag := genHeaderDepTag
771 if inList(gen, deps.ReexportGeneratedHeaders) {
772 depTag = genHeaderExportDepTag
773 }
774 actx.AddDependency(c, depTag, gen)
775 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700776
Colin Cross68861832016-07-08 10:41:41 -0700777 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700778
779 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700780 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800781 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700782 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700783 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700784 }
Dan Albert914449f2016-06-17 16:45:24 -0700785
786 version := ctx.sdkVersion()
787 actx.AddVariationDependencies([]blueprint.Variation{
788 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
789 actx.AddVariationDependencies([]blueprint.Variation{
790 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700791}
Colin Cross21b9a242015-03-24 14:15:58 -0700792
Dan Albert7e9d2952016-08-04 13:02:36 -0700793func beginMutator(ctx android.BottomUpMutatorContext) {
794 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
795 c.beginMutator(ctx)
796 }
797}
798
Colin Crossca860ac2016-01-04 14:34:37 -0800799func (c *Module) clang(ctx BaseModuleContext) bool {
800 clang := Bool(c.Properties.Clang)
801
802 if c.Properties.Clang == nil {
803 if ctx.Host() {
804 clang = true
805 }
806
807 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
808 clang = true
809 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800810 }
Colin Cross28344522015-04-22 13:07:53 -0700811
Colin Crossca860ac2016-01-04 14:34:37 -0800812 if !c.toolchain(ctx).ClangSupported() {
813 clang = false
814 }
815
816 return clang
817}
818
Colin Crossc99deeb2016-04-11 15:06:20 -0700819// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700820func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800821 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800822
Dan Willemsena96ff642016-06-07 12:34:45 -0700823 // Whether a module can link to another module, taking into
824 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700825 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700826 if from.Target().Os != android.Android {
827 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700828 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700829 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700830 if from.Properties.UseVndk {
831 // Vendor code is already limited by the vendor mutator
832 return
833 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700834 if from.Properties.Sdk_version == "" {
835 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700836 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700837 }
Colin Crossb916a382016-07-29 17:28:03 -0700838 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700839 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700840 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700841 }
842 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
843 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700844 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700845 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700846 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
847 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700848 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700849 }
Colin Crossb916a382016-07-29 17:28:03 -0700850 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700851 // These aren't real libraries, but are the stub shared libraries that are included in
852 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700853 return
Dan Albert914449f2016-06-17 16:45:24 -0700854 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700855 if to.Properties.Sdk_version == "" {
856 // NDK code linking to platform code is never okay.
857 ctx.ModuleErrorf("depends on non-NDK-built library %q",
858 ctx.OtherModuleName(to))
859 }
860
861 // All this point we know we have two NDK libraries, but we need to
862 // check that we're not linking against anything built against a higher
863 // API level, as it is only valid to link against older or equivalent
864 // APIs.
865
866 if from.Properties.Sdk_version == "current" {
867 // Current can link against anything.
868 return
869 } else if to.Properties.Sdk_version == "current" {
870 // Current can't be linked against by anything else.
871 ctx.ModuleErrorf("links %q built against newer API version %q",
872 ctx.OtherModuleName(to), "current")
873 }
874
875 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
876 if err != nil {
877 ctx.PropertyErrorf("sdk_version",
878 "Invalid sdk_version value (must be int): %q",
879 from.Properties.Sdk_version)
880 }
881 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
882 if err != nil {
883 ctx.PropertyErrorf("sdk_version",
884 "Invalid sdk_version value (must be int): %q",
885 to.Properties.Sdk_version)
886 }
887
888 if toApi > fromApi {
889 ctx.ModuleErrorf("links %q built against newer API version %q",
890 ctx.OtherModuleName(to), to.Properties.Sdk_version)
891 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700892 }
893
Colin Crossc99deeb2016-04-11 15:06:20 -0700894 ctx.VisitDirectDeps(func(m blueprint.Module) {
895 name := ctx.OtherModuleName(m)
896 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800897
Colin Cross635c3b02016-05-18 15:37:25 -0700898 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700899 if a == nil {
900 ctx.ModuleErrorf("module %q not an android module", name)
901 return
Colin Crossca860ac2016-01-04 14:34:37 -0800902 }
Colin Crossca860ac2016-01-04 14:34:37 -0800903
Dan Willemsena96ff642016-06-07 12:34:45 -0700904 cc, _ := m.(*Module)
905 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700906 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800907 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700908 case genSourceDepTag:
909 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
910 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
911 genRule.GeneratedSourceFiles()...)
912 } else {
913 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
914 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700915 // Support exported headers from a generated_sources dependency
916 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700917 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700918 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
919 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
920 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800921 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700922 depPaths.Flags = append(depPaths.Flags, flags)
923 if tag == genHeaderExportDepTag {
924 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700925 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
926 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700927 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
928 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
929
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700930 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700931 } else {
932 ctx.ModuleErrorf("module %q is not a genrule", name)
933 }
934 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700935 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800936 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700937 return
938 }
939
940 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800941 if ctx.AConfig().AllowMissingDependencies() {
942 ctx.AddMissingDependencies([]string{name})
943 } else {
944 ctx.ModuleErrorf("depends on disabled module %q", name)
945 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700946 return
947 }
948
Colin Crossa1ad8d12016-06-01 17:09:44 -0700949 if a.Target().Os != ctx.Os() {
950 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
951 return
952 }
953
954 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
955 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700956 return
957 }
958
Colin Crossc99deeb2016-04-11 15:06:20 -0700959 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -0800960 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700961 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -0700962 depPaths.Objs = depPaths.Objs.Append(objs)
963 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700964 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -0800965 return
966 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700967 }
968
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700969 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700970 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700971 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -0700972 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -0700973 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700974 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700975
976 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700977 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700978 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700979 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
980 // Re-exported flags from shared library dependencies are not included as those shared libraries
981 // will be included in the vndk set.
982 if tag == staticExportDepTag || tag == headerExportDepTag {
983 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
984 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700985 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700986 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700987
Dan Albert9e10cd42016-08-03 14:12:14 -0700988 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700989 }
990
Colin Cross26c34ed2016-09-30 17:10:16 -0700991 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700992 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700993
Colin Cross26c34ed2016-09-30 17:10:16 -0700994 linkFile := cc.outputFile
995 depFile := android.OptionalPath{}
996
Colin Crossc99deeb2016-04-11 15:06:20 -0700997 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700998 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -0700999 ptr = &depPaths.SharedLibs
1000 depPtr = &depPaths.SharedLibsDeps
1001 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001002 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001003 ptr = &depPaths.LateSharedLibs
1004 depPtr = &depPaths.LateSharedLibsDeps
1005 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001006 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001007 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001008 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001009 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001010 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001011 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001012 staticLib, ok := cc.linker.(libraryInterface)
1013 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001014 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001015 return
1016 }
1017
1018 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1019 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1020 for i := range missingDeps {
1021 missingDeps[i] += postfix
1022 }
1023 ctx.AddMissingDependencies(missingDeps)
1024 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001025 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001026 case headerDepTag:
1027 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001028 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001029 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001030 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001031 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001032 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001033 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001034 }
1035
Dan Willemsen581341d2017-02-09 16:16:31 -08001036 switch tag {
1037 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1038 staticLib, ok := cc.linker.(libraryInterface)
1039 if !ok || !staticLib.static() {
1040 ctx.ModuleErrorf("module %q not a static library", name)
1041 return
1042 }
1043
1044 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001045 // in static libraries act as if they were whole static libraries. The same goes for
1046 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001047 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1048 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001049 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1050 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001051 }
1052
Colin Cross26c34ed2016-09-30 17:10:16 -07001053 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001054 if !linkFile.Valid() {
1055 ctx.ModuleErrorf("module %q missing output file", name)
1056 return
1057 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001058 *ptr = append(*ptr, linkFile.Path())
1059 }
1060
Colin Crossc99deeb2016-04-11 15:06:20 -07001061 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001062 dep := depFile
1063 if !dep.Valid() {
1064 dep = linkFile
1065 }
1066 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001067 }
1068 })
1069
Colin Crossdd84e052017-05-17 13:44:16 -07001070 // Dedup exported flags from dependencies
1071 depPaths.Flags = firstUniqueElements(depPaths.Flags)
1072
Colin Crossca860ac2016-01-04 14:34:37 -08001073 return depPaths
1074}
1075
1076func (c *Module) InstallInData() bool {
1077 if c.installer == nil {
1078 return false
1079 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001080 return c.installer.inData()
1081}
1082
1083func (c *Module) InstallInSanitizerDir() bool {
1084 if c.installer == nil {
1085 return false
1086 }
1087 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001088 return true
1089 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001090 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001091}
1092
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001093func (c *Module) HostToolPath() android.OptionalPath {
1094 if c.installer == nil {
1095 return android.OptionalPath{}
1096 }
1097 return c.installer.hostToolPath()
1098}
1099
Colin Cross2ba19d92015-05-07 15:44:20 -07001100//
Colin Crosscfad1192015-11-02 16:43:11 -08001101// Defaults
1102//
Colin Crossca860ac2016-01-04 14:34:37 -08001103type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001104 android.ModuleBase
1105 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -08001106}
1107
Colin Cross635c3b02016-05-18 15:37:25 -07001108func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001109}
1110
Colin Cross1e676be2016-10-12 14:38:15 -07001111func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1112}
1113
Colin Cross36242852017-06-23 15:06:31 -07001114func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001115 return DefaultsFactory()
1116}
1117
Colin Cross36242852017-06-23 15:06:31 -07001118func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001119 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001120
Colin Cross36242852017-06-23 15:06:31 -07001121 module.AddProperties(props...)
1122 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001123 &BaseProperties{},
1124 &BaseCompilerProperties{},
1125 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001126 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001127 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001128 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001129 &TestProperties{},
1130 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001131 &UnusedProperties{},
1132 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001133 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001134 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001135 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001136 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001137 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001138 &SAbiProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001139 )
Colin Crosscfad1192015-11-02 16:43:11 -08001140
Colin Cross36242852017-06-23 15:06:31 -07001141 android.InitDefaultsModule(module, module)
1142
1143 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001144}
1145
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001146const (
1147 // coreMode is the variant used for framework-private libraries, or
1148 // SDK libraries. (which framework-private libraries can use)
1149 coreMode = "core"
1150
1151 // vendorMode is the variant used for /vendor code that compiles
1152 // against the VNDK.
1153 vendorMode = "vendor"
1154)
1155
1156func vendorMutator(mctx android.BottomUpMutatorContext) {
1157 if mctx.Os() != android.Android {
1158 return
1159 }
1160
1161 m, ok := mctx.Module().(*Module)
1162 if !ok {
1163 return
1164 }
1165
1166 // Sanity check
1167 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1168 mctx.PropertyErrorf("vendor_available",
1169 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1170 return
1171 }
1172
1173 if !mctx.DeviceConfig().CompileVndk() {
1174 // If the device isn't compiling against the VNDK, we always
1175 // use the core mode.
1176 mctx.CreateVariations(coreMode)
1177 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1178 // LL-NDK stubs only exist in the vendor variant, since the
1179 // real libraries will be used in the core variant.
1180 mctx.CreateVariations(vendorMode)
1181 } else if Bool(m.Properties.Vendor_available) {
1182 // This will be available in both /system and /vendor
1183 mod := mctx.CreateVariations(coreMode, vendorMode)
1184 mod[1].(*Module).Properties.UseVndk = true
1185 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1186 // This will be available in /vendor only
1187 mod := mctx.CreateVariations(vendorMode)
1188 mod[0].(*Module).Properties.UseVndk = true
1189 } else {
1190 // This is either in /system (or similar: /data), or is a
1191 // modules built with the NDK. Modules built with the NDK
1192 // will be restricted using the existing link type checks.
1193 mctx.CreateVariations(coreMode)
1194 }
1195}
1196
Colin Crossdd84e052017-05-17 13:44:16 -07001197// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1198// modifies the slice contents in place, and returns a subslice of the original slice
1199func firstUniqueElements(list []string) []string {
1200 k := 0
1201outer:
1202 for i := 0; i < len(list); i++ {
1203 for j := 0; j < k; j++ {
1204 if list[i] == list[j] {
1205 continue outer
1206 }
1207 }
1208 list[k] = list[i]
1209 k++
1210 }
1211 return list[:k]
1212}
1213
Colin Cross74d1ec02015-04-28 13:30:13 -07001214// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1215// modifies the slice contents in place, and returns a subslice of the original slice
1216func lastUniqueElements(list []string) []string {
1217 totalSkip := 0
1218 for i := len(list) - 1; i >= totalSkip; i-- {
1219 skip := 0
1220 for j := i - 1; j >= totalSkip; j-- {
1221 if list[i] == list[j] {
1222 skip++
1223 } else {
1224 list[j+skip] = list[j]
1225 }
1226 }
1227 totalSkip += skip
1228 }
1229 return list[totalSkip:]
1230}
Colin Cross06a931b2015-10-28 17:23:31 -07001231
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001232func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1233 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1234 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1235 }
1236 return ctx.AConfig().PlatformSdkVersion()
1237}
1238
Colin Cross06a931b2015-10-28 17:23:31 -07001239var Bool = proptools.Bool