blob: 43825ca31eb562081a071ba746526f663c08e98e [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 {
Colin Cross28344522015-04-22 13:07:53 -0700100 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
Vishwath Mohan83d9f712017-03-16 11:01:23 -0700101 ArFlags []string // Flags that apply to ar
Colin Cross28344522015-04-22 13:07:53 -0700102 AsFlags []string // Flags that apply to assembly source files
103 CFlags []string // Flags that apply to C and C++ source files
104 ConlyFlags []string // Flags that apply to C source files
105 CppFlags []string // Flags that apply to C++ source files
106 YaccFlags []string // Flags that apply to Yacc source files
Colin Cross0c461f12016-10-20 16:11:43 -0700107 protoFlags []string // Flags that apply to proto source files
Dan Willemsene1240db2016-11-03 14:28:51 -0700108 aidlFlags []string // Flags that apply to aidl source files
Colin Cross2a252be2017-05-01 17:37:24 -0700109 rsFlags []string // Flags that apply to renderscript source files
Colin Cross28344522015-04-22 13:07:53 -0700110 LdFlags []string // Flags that apply to linker command lines
Colin Cross16b23492016-01-06 14:41:07 -0800111 libFlags []string // Flags to add libraries early to the link order
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700112 TidyFlags []string // Flags that apply to clang-tidy
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800113 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross91e90042016-12-02 17:13:24 -0800114 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700115
Colin Crossc3199482017-03-30 15:03:04 -0700116 // Global include flags that apply to C, C++, and assembly source files
117 // These must be after any module include flags, which will be in GlobalFlags.
118 SystemIncludeFlags []string
119
Colin Crossb98c8b02016-07-29 13:44:28 -0700120 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700121 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700122 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800123 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800124 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800125
126 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800127 DynamicLinker string
128
Colin Cross635c3b02016-05-18 15:37:25 -0700129 CFlagsDeps android.Paths // Files depended on by compiler flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800130
131 GroupStaticLibs bool
Colin Crossc472d572015-03-17 15:06:21 -0700132}
133
Colin Cross81413472016-04-11 14:37:39 -0700134type ObjectLinkerProperties struct {
135 // names of other cc_object modules to link into this module using partial linking
136 Objs []string `android:"arch_variant"`
137}
138
Colin Crossca860ac2016-01-04 14:34:37 -0800139// Properties used to compile all C or C++ modules
140type BaseProperties struct {
141 // compile module with clang instead of gcc
142 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700143
144 // Minimum sdk version supported when compiling against the ndk
145 Sdk_version string
146
Colin Crossca860ac2016-01-04 14:34:37 -0800147 // don't insert default compiler flags into asflags, cflags,
148 // cppflags, conlyflags, ldflags, or include_dirs
149 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700150
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700151 // whether this module should be allowed to install onto /vendor as
152 // well as /system. The two variants will be built separately, one
153 // like normal, and the other limited to the set of libraries and
154 // headers that are exposed to /vendor modules.
155 //
156 // The vendor variant may be used with a different (newer) /system,
157 // so it shouldn't have any unversioned runtime dependencies, or
158 // make assumptions about the system that may not be true in the
159 // future.
160 //
161 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
162 Vendor_available *bool
163
Colin Crossc99deeb2016-04-11 15:06:20 -0700164 AndroidMkSharedLibs []string `blueprint:"mutated"`
Colin Crossbc6fb162016-05-24 15:39:04 -0700165 HideFromMake bool `blueprint:"mutated"`
Colin Crossb0f28952016-09-19 16:46:53 -0700166 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700167
168 UseVndk bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800169}
170
Colin Crossca860ac2016-01-04 14:34:37 -0800171type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800172 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800173}
174
Colin Crossca860ac2016-01-04 14:34:37 -0800175type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800176 static() bool
177 staticBinary() bool
178 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700179 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800180 noDefaultCompilerFlags() bool
181 sdk() bool
182 sdkVersion() string
Dan Willemsend2ede872016-11-18 14:54:24 -0800183 vndk() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800184 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700185 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700186 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800187}
188
189type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700190 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800191 ModuleContextIntf
192}
193
194type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700195 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800196 ModuleContextIntf
197}
198
Colin Cross37047f12016-12-13 17:06:13 -0800199type DepsContext interface {
200 android.BottomUpMutatorContext
201 ModuleContextIntf
202}
203
Colin Crossca860ac2016-01-04 14:34:37 -0800204type feature interface {
205 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800206 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800207 flags(ctx ModuleContext, flags Flags) Flags
208 props() []interface{}
209}
210
211type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700212 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800213 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700214 compilerFlags(ctx ModuleContext, flags Flags) Flags
215 compilerProps() []interface{}
216
Colin Cross76fada02016-07-27 10:31:13 -0700217 appendCflags([]string)
218 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700219 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800220}
221
222type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700223 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800224 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700225 linkerFlags(ctx ModuleContext, flags Flags) Flags
226 linkerProps() []interface{}
227
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700228 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700229 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800230}
231
232type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700233 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700234 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800235 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700236 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700237 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800238}
239
Colin Crossc99deeb2016-04-11 15:06:20 -0700240type dependencyTag struct {
241 blueprint.BaseDependencyTag
242 name string
243 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700244
245 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700246}
247
248var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700249 sharedDepTag = dependencyTag{name: "shared", library: true}
250 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
251 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
252 staticDepTag = dependencyTag{name: "static", library: true}
253 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
254 lateStaticDepTag = dependencyTag{name: "late static", library: true}
255 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800256 headerDepTag = dependencyTag{name: "header", library: true}
257 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700258 genSourceDepTag = dependencyTag{name: "gen source"}
259 genHeaderDepTag = dependencyTag{name: "gen header"}
260 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
261 objDepTag = dependencyTag{name: "obj"}
262 crtBeginDepTag = dependencyTag{name: "crtbegin"}
263 crtEndDepTag = dependencyTag{name: "crtend"}
264 reuseObjTag = dependencyTag{name: "reuse objects"}
265 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
266 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700267)
268
Colin Crossca860ac2016-01-04 14:34:37 -0800269// Module contains the properties and members used by all C/C++ module types, and implements
270// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
271// to construct the output file. Behavior can be customized with a Customizer interface
272type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700273 android.ModuleBase
274 android.DefaultableModule
Colin Crossc472d572015-03-17 15:06:21 -0700275
Colin Crossca860ac2016-01-04 14:34:37 -0800276 Properties BaseProperties
277 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700278
Colin Crossca860ac2016-01-04 14:34:37 -0800279 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700280 hod android.HostOrDeviceSupported
281 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700282
Colin Crossca860ac2016-01-04 14:34:37 -0800283 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700284 features []feature
285 compiler compiler
286 linker linker
287 installer installer
288 stl *stl
289 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800290 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800291 sabi *sabi
Colin Cross16b23492016-01-06 14:41:07 -0800292
293 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700294
Colin Cross635c3b02016-05-18 15:37:25 -0700295 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800296
Colin Crossb98c8b02016-07-29 13:44:28 -0700297 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700298
299 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800300
301 // Flags used to compile this module
302 flags Flags
Colin Crossc472d572015-03-17 15:06:21 -0700303}
304
Colin Crossca860ac2016-01-04 14:34:37 -0800305func (c *Module) Init() (blueprint.Module, []interface{}) {
306 props := []interface{}{&c.Properties, &c.unused}
Colin Crossca860ac2016-01-04 14:34:37 -0800307 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700308 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800309 }
310 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700311 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800312 }
313 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700314 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800315 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700316 if c.stl != nil {
317 props = append(props, c.stl.props()...)
318 }
Colin Cross16b23492016-01-06 14:41:07 -0800319 if c.sanitize != nil {
320 props = append(props, c.sanitize.props()...)
321 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800322 if c.coverage != nil {
323 props = append(props, c.coverage.props()...)
324 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800325 if c.sabi != nil {
326 props = append(props, c.sabi.props()...)
327 }
Colin Crossca860ac2016-01-04 14:34:37 -0800328 for _, feature := range c.features {
329 props = append(props, feature.props()...)
330 }
Colin Crossc472d572015-03-17 15:06:21 -0700331
Colin Cross635c3b02016-05-18 15:37:25 -0700332 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700333
Colin Cross635c3b02016-05-18 15:37:25 -0700334 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700335}
336
Colin Crossb916a382016-07-29 17:28:03 -0700337// Returns true for dependency roots (binaries)
338// TODO(ccross): also handle dlopenable libraries
339func (c *Module) isDependencyRoot() bool {
340 if root, ok := c.linker.(interface {
341 isDependencyRoot() bool
342 }); ok {
343 return root.isDependencyRoot()
344 }
345 return false
346}
347
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700348func (c *Module) vndk() bool {
349 return c.Properties.UseVndk
350}
351
Colin Crossca860ac2016-01-04 14:34:37 -0800352type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700353 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800354 moduleContextImpl
355}
356
Colin Cross37047f12016-12-13 17:06:13 -0800357type depsContext struct {
358 android.BottomUpMutatorContext
359 moduleContextImpl
360}
361
Colin Crossca860ac2016-01-04 14:34:37 -0800362type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700363 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800364 moduleContextImpl
365}
366
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700367// Vendor returns true for vendor modules so that they get installed onto the
368// correct partition
369func (ctx *moduleContext) Vendor() bool {
370 return ctx.ModuleContext.Vendor() || ctx.moduleContextImpl.mod.Properties.UseVndk
371}
372
Colin Crossca860ac2016-01-04 14:34:37 -0800373type moduleContextImpl struct {
374 mod *Module
375 ctx BaseModuleContext
376}
377
Colin Crossca860ac2016-01-04 14:34:37 -0800378func (ctx *moduleContextImpl) clang() bool {
379 return ctx.mod.clang(ctx.ctx)
380}
381
Colin Crossb98c8b02016-07-29 13:44:28 -0700382func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800383 return ctx.mod.toolchain(ctx.ctx)
384}
385
386func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700387 if static, ok := ctx.mod.linker.(interface {
388 static() bool
389 }); ok {
390 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800391 }
Colin Crossb916a382016-07-29 17:28:03 -0700392 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800393}
394
395func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700396 if static, ok := ctx.mod.linker.(interface {
397 staticBinary() bool
398 }); ok {
399 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800400 }
Colin Crossb916a382016-07-29 17:28:03 -0700401 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800402}
403
404func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
405 return Bool(ctx.mod.Properties.No_default_compiler_flags)
406}
407
408func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700409 if ctx.ctx.Device() && !ctx.vndk() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700410 return ctx.mod.Properties.Sdk_version != ""
411 }
412 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800413}
414
415func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700416 if ctx.ctx.Device() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700417 if ctx.vndk() {
418 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800419 } else {
420 return ctx.mod.Properties.Sdk_version
421 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700422 }
423 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800424}
425
Dan Willemsend2ede872016-11-18 14:54:24 -0800426func (ctx *moduleContextImpl) vndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700427 return ctx.mod.vndk()
Dan Willemsend2ede872016-11-18 14:54:24 -0800428}
429
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800430// Create source abi dumps if the module belongs to the list of VndkLibraries.
431func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700432 return ctx.ctx.Device() && ((Bool(ctx.mod.Properties.Vendor_available)) || (inList(ctx.baseModuleName(), config.LLndkLibraries())))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800433}
434
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700435func (ctx *moduleContextImpl) selectedStl() string {
436 if stl := ctx.mod.stl; stl != nil {
437 return stl.Properties.SelectedStl
438 }
439 return ""
440}
441
Colin Crossce75d2c2016-10-06 16:12:58 -0700442func (ctx *moduleContextImpl) baseModuleName() string {
443 return ctx.mod.ModuleBase.BaseModuleName()
444}
445
Colin Cross635c3b02016-05-18 15:37:25 -0700446func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800447 return &Module{
448 hod: hod,
449 multilib: multilib,
450 }
451}
452
Colin Cross635c3b02016-05-18 15:37:25 -0700453func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800454 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700455 module.features = []feature{
456 &tidyFeature{},
457 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700458 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800459 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800460 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800461 module.sabi = &sabi{}
Colin Crossca860ac2016-01-04 14:34:37 -0800462 return module
463}
464
Colin Crossce75d2c2016-10-06 16:12:58 -0700465func (c *Module) Prebuilt() *android.Prebuilt {
466 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
467 return p.prebuilt()
468 }
469 return nil
470}
471
472func (c *Module) Name() string {
473 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700474 if p, ok := c.linker.(interface {
475 Name(string) string
476 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700477 name = p.Name(name)
478 }
479 return name
480}
481
Colin Cross635c3b02016-05-18 15:37:25 -0700482func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800483 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700484 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800485 moduleContextImpl: moduleContextImpl{
486 mod: c,
487 },
488 }
489 ctx.ctx = ctx
490
491 flags := Flags{
492 Toolchain: c.toolchain(ctx),
493 Clang: c.clang(ctx),
494 }
Colin Crossca860ac2016-01-04 14:34:37 -0800495 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700496 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800497 }
498 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700499 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800500 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700501 if c.stl != nil {
502 flags = c.stl.flags(ctx, flags)
503 }
Colin Cross16b23492016-01-06 14:41:07 -0800504 if c.sanitize != nil {
505 flags = c.sanitize.flags(ctx, flags)
506 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800507 if c.coverage != nil {
508 flags = c.coverage.flags(ctx, flags)
509 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800510 if c.sabi != nil {
511 flags = c.sabi.flags(ctx, flags)
512 }
Colin Crossca860ac2016-01-04 14:34:37 -0800513 for _, feature := range c.features {
514 flags = feature.flags(ctx, flags)
515 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800516 if ctx.Failed() {
517 return
518 }
519
Colin Crossb98c8b02016-07-29 13:44:28 -0700520 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
521 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
522 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800523
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800524 deps := c.depsToPaths(ctx)
525 if ctx.Failed() {
526 return
527 }
528 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
529 c.flags = flags
530
Colin Crossca860ac2016-01-04 14:34:37 -0800531 // Optimization to reduce size of build.ninja
532 // Replace the long list of flags for each file with a module-local variable
533 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
534 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
535 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
536 flags.CFlags = []string{"$cflags"}
537 flags.CppFlags = []string{"$cppflags"}
538 flags.AsFlags = []string{"$asflags"}
539
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700540 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800541 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700542 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800543 if ctx.Failed() {
544 return
545 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800546 }
547
Colin Crossca860ac2016-01-04 14:34:37 -0800548 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700549 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800550 if ctx.Failed() {
551 return
552 }
Colin Cross635c3b02016-05-18 15:37:25 -0700553 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700554 }
Colin Cross5049f022015-03-18 13:28:46 -0700555
Colin Crossce75d2c2016-10-06 16:12:58 -0700556 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
557 c.installer.install(ctx, c.outputFile.Path())
558 if ctx.Failed() {
559 return
Colin Crossca860ac2016-01-04 14:34:37 -0800560 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700561 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800562}
563
Colin Crossb98c8b02016-07-29 13:44:28 -0700564func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800565 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700566 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800567 }
Colin Crossca860ac2016-01-04 14:34:37 -0800568 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800569}
570
Colin Crossca860ac2016-01-04 14:34:37 -0800571func (c *Module) begin(ctx BaseModuleContext) {
572 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700573 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700574 }
Colin Crossca860ac2016-01-04 14:34:37 -0800575 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700576 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800577 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700578 if c.stl != nil {
579 c.stl.begin(ctx)
580 }
Colin Cross16b23492016-01-06 14:41:07 -0800581 if c.sanitize != nil {
582 c.sanitize.begin(ctx)
583 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800584 if c.coverage != nil {
585 c.coverage.begin(ctx)
586 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800587 if c.sabi != nil {
588 c.sabi.begin(ctx)
589 }
Colin Crossca860ac2016-01-04 14:34:37 -0800590 for _, feature := range c.features {
591 feature.begin(ctx)
592 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700593 if ctx.sdk() {
594 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
595 if err != nil {
596 ctx.PropertyErrorf("sdk_version", err.Error())
597 }
Dan Albert90f7a4d2016-11-08 14:34:24 -0800598 c.Properties.Sdk_version = version
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700599 }
Colin Crossca860ac2016-01-04 14:34:37 -0800600}
601
Colin Cross37047f12016-12-13 17:06:13 -0800602func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700603 deps := Deps{}
604
605 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700606 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700607 }
608 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700609 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700610 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700611 if c.stl != nil {
612 deps = c.stl.deps(ctx, deps)
613 }
Colin Cross16b23492016-01-06 14:41:07 -0800614 if c.sanitize != nil {
615 deps = c.sanitize.deps(ctx, deps)
616 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800617 if c.coverage != nil {
618 deps = c.coverage.deps(ctx, deps)
619 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800620 if c.sabi != nil {
621 deps = c.sabi.deps(ctx, deps)
622 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700623 for _, feature := range c.features {
624 deps = feature.deps(ctx, deps)
625 }
626
627 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
628 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
629 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
630 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
631 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
Colin Cross5950f382016-12-13 12:50:57 -0800632 deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700633
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700634 for _, lib := range deps.ReexportSharedLibHeaders {
635 if !inList(lib, deps.SharedLibs) {
636 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
637 }
638 }
639
640 for _, lib := range deps.ReexportStaticLibHeaders {
641 if !inList(lib, deps.StaticLibs) {
642 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
643 }
644 }
645
Colin Cross5950f382016-12-13 12:50:57 -0800646 for _, lib := range deps.ReexportHeaderLibHeaders {
647 if !inList(lib, deps.HeaderLibs) {
648 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
649 }
650 }
651
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700652 for _, gen := range deps.ReexportGeneratedHeaders {
653 if !inList(gen, deps.GeneratedHeaders) {
654 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
655 }
656 }
657
Colin Crossc99deeb2016-04-11 15:06:20 -0700658 return deps
659}
660
Dan Albert7e9d2952016-08-04 13:02:36 -0700661func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800662 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700663 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800664 moduleContextImpl: moduleContextImpl{
665 mod: c,
666 },
667 }
668 ctx.ctx = ctx
669
Colin Crossca860ac2016-01-04 14:34:37 -0800670 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700671}
672
Colin Cross1e676be2016-10-12 14:38:15 -0700673func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
674 if !c.Enabled() {
675 return
676 }
677
Colin Cross37047f12016-12-13 17:06:13 -0800678 ctx := &depsContext{
679 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700680 moduleContextImpl: moduleContextImpl{
681 mod: c,
682 },
683 }
684 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800685
Colin Crossc99deeb2016-04-11 15:06:20 -0700686 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800687
Colin Crossb5bc4b42016-07-11 16:11:59 -0700688 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
689 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700690
Dan Albert914449f2016-06-17 16:45:24 -0700691 variantNdkLibs := []string{}
692 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700693 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700694 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700695
Dan Albert914449f2016-06-17 16:45:24 -0700696 // Rewrites the names of shared libraries into the names of the NDK
697 // libraries where appropriate. This returns two slices.
698 //
699 // The first is a list of non-variant shared libraries (either rewritten
700 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
701 // because they are not NDK libraries).
702 //
703 // The second is a list of ndk_library modules. These need to be
704 // separated because they are a variation dependency and must be added
705 // in a different manner.
706 rewriteNdkLibs := func(list []string) ([]string, []string) {
707 variantLibs := []string{}
708 nonvariantLibs := []string{}
709 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700710 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700711 if !inList(entry, ndkMigratedLibs) {
712 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
713 } else {
714 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
715 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700716 } else if ctx.vndk() && inList(entry, config.LLndkLibraries()) {
717 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700718 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700719 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700720 }
721 }
Dan Albert914449f2016-06-17 16:45:24 -0700722 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700723 }
724
Dan Albert914449f2016-06-17 16:45:24 -0700725 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
726 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700727 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700728
Colin Cross32ec36c2016-12-15 07:39:51 -0800729 for _, lib := range deps.HeaderLibs {
730 depTag := headerDepTag
731 if inList(lib, deps.ReexportHeaderLibHeaders) {
732 depTag = headerExportDepTag
733 }
734 actx.AddVariationDependencies(nil, depTag, lib)
735 }
Colin Cross5950f382016-12-13 12:50:57 -0800736
Colin Crossc99deeb2016-04-11 15:06:20 -0700737 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
738 deps.WholeStaticLibs...)
739
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700740 for _, lib := range deps.StaticLibs {
741 depTag := staticDepTag
742 if inList(lib, deps.ReexportStaticLibHeaders) {
743 depTag = staticExportDepTag
744 }
Colin Cross15a0d462016-07-14 14:49:58 -0700745 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700746 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700747
748 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
749 deps.LateStaticLibs...)
750
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700751 for _, lib := range deps.SharedLibs {
752 depTag := sharedDepTag
753 if inList(lib, deps.ReexportSharedLibHeaders) {
754 depTag = sharedExportDepTag
755 }
Colin Cross15a0d462016-07-14 14:49:58 -0700756 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700757 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700758
759 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
760 deps.LateSharedLibs...)
761
Colin Cross68861832016-07-08 10:41:41 -0700762 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700763
764 for _, gen := range deps.GeneratedHeaders {
765 depTag := genHeaderDepTag
766 if inList(gen, deps.ReexportGeneratedHeaders) {
767 depTag = genHeaderExportDepTag
768 }
769 actx.AddDependency(c, depTag, gen)
770 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700771
Colin Cross68861832016-07-08 10:41:41 -0700772 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700773
774 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700775 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800776 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700777 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700778 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700779 }
Dan Albert914449f2016-06-17 16:45:24 -0700780
781 version := ctx.sdkVersion()
782 actx.AddVariationDependencies([]blueprint.Variation{
783 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
784 actx.AddVariationDependencies([]blueprint.Variation{
785 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700786}
Colin Cross21b9a242015-03-24 14:15:58 -0700787
Dan Albert7e9d2952016-08-04 13:02:36 -0700788func beginMutator(ctx android.BottomUpMutatorContext) {
789 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
790 c.beginMutator(ctx)
791 }
792}
793
Colin Crossca860ac2016-01-04 14:34:37 -0800794func (c *Module) clang(ctx BaseModuleContext) bool {
795 clang := Bool(c.Properties.Clang)
796
797 if c.Properties.Clang == nil {
798 if ctx.Host() {
799 clang = true
800 }
801
802 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
803 clang = true
804 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800805 }
Colin Cross28344522015-04-22 13:07:53 -0700806
Colin Crossca860ac2016-01-04 14:34:37 -0800807 if !c.toolchain(ctx).ClangSupported() {
808 clang = false
809 }
810
811 return clang
812}
813
Colin Crossc99deeb2016-04-11 15:06:20 -0700814// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700815func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800816 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800817
Dan Willemsena96ff642016-06-07 12:34:45 -0700818 // Whether a module can link to another module, taking into
819 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700820 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700821 if from.Target().Os != android.Android {
822 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700823 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700824 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700825 if from.Properties.UseVndk {
826 // Vendor code is already limited by the vendor mutator
827 return
828 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700829 if from.Properties.Sdk_version == "" {
830 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700831 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700832 }
Colin Crossb916a382016-07-29 17:28:03 -0700833 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700834 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700835 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700836 }
837 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
838 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700839 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700840 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700841 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
842 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700843 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700844 }
Colin Crossb916a382016-07-29 17:28:03 -0700845 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700846 // These aren't real libraries, but are the stub shared libraries that are included in
847 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700848 return
Dan Albert914449f2016-06-17 16:45:24 -0700849 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700850 if to.Properties.Sdk_version == "" {
851 // NDK code linking to platform code is never okay.
852 ctx.ModuleErrorf("depends on non-NDK-built library %q",
853 ctx.OtherModuleName(to))
854 }
855
856 // All this point we know we have two NDK libraries, but we need to
857 // check that we're not linking against anything built against a higher
858 // API level, as it is only valid to link against older or equivalent
859 // APIs.
860
861 if from.Properties.Sdk_version == "current" {
862 // Current can link against anything.
863 return
864 } else if to.Properties.Sdk_version == "current" {
865 // Current can't be linked against by anything else.
866 ctx.ModuleErrorf("links %q built against newer API version %q",
867 ctx.OtherModuleName(to), "current")
868 }
869
870 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
871 if err != nil {
872 ctx.PropertyErrorf("sdk_version",
873 "Invalid sdk_version value (must be int): %q",
874 from.Properties.Sdk_version)
875 }
876 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
877 if err != nil {
878 ctx.PropertyErrorf("sdk_version",
879 "Invalid sdk_version value (must be int): %q",
880 to.Properties.Sdk_version)
881 }
882
883 if toApi > fromApi {
884 ctx.ModuleErrorf("links %q built against newer API version %q",
885 ctx.OtherModuleName(to), to.Properties.Sdk_version)
886 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700887 }
888
Colin Crossc99deeb2016-04-11 15:06:20 -0700889 ctx.VisitDirectDeps(func(m blueprint.Module) {
890 name := ctx.OtherModuleName(m)
891 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800892
Colin Cross635c3b02016-05-18 15:37:25 -0700893 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700894 if a == nil {
895 ctx.ModuleErrorf("module %q not an android module", name)
896 return
Colin Crossca860ac2016-01-04 14:34:37 -0800897 }
Colin Crossca860ac2016-01-04 14:34:37 -0800898
Dan Willemsena96ff642016-06-07 12:34:45 -0700899 cc, _ := m.(*Module)
900 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700901 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800902 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700903 case genSourceDepTag:
904 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
905 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
906 genRule.GeneratedSourceFiles()...)
907 } else {
908 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
909 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700910 // Support exported headers from a generated_sources dependency
911 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700912 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700913 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
914 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
915 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800916 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700917 depPaths.Flags = append(depPaths.Flags, flags)
918 if tag == genHeaderExportDepTag {
919 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700920 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
921 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700922 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
923 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
924
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700925 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700926 } else {
927 ctx.ModuleErrorf("module %q is not a genrule", name)
928 }
929 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700930 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800931 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700932 return
933 }
934
935 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800936 if ctx.AConfig().AllowMissingDependencies() {
937 ctx.AddMissingDependencies([]string{name})
938 } else {
939 ctx.ModuleErrorf("depends on disabled module %q", name)
940 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700941 return
942 }
943
Colin Crossa1ad8d12016-06-01 17:09:44 -0700944 if a.Target().Os != ctx.Os() {
945 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
946 return
947 }
948
949 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
950 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700951 return
952 }
953
Colin Crossc99deeb2016-04-11 15:06:20 -0700954 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -0800955 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700956 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -0700957 depPaths.Objs = depPaths.Objs.Append(objs)
958 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700959 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -0800960 return
961 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700962 }
963
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700964 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700965 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700966 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -0700967 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -0700968 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700969 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700970
971 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700972 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700973 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700974 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
975 // Re-exported flags from shared library dependencies are not included as those shared libraries
976 // will be included in the vndk set.
977 if tag == staticExportDepTag || tag == headerExportDepTag {
978 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
979 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700980 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700981 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700982
Dan Albert9e10cd42016-08-03 14:12:14 -0700983 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700984 }
985
Colin Cross26c34ed2016-09-30 17:10:16 -0700986 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700987 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700988
Colin Cross26c34ed2016-09-30 17:10:16 -0700989 linkFile := cc.outputFile
990 depFile := android.OptionalPath{}
991
Colin Crossc99deeb2016-04-11 15:06:20 -0700992 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700993 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -0700994 ptr = &depPaths.SharedLibs
995 depPtr = &depPaths.SharedLibsDeps
996 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -0700997 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -0700998 ptr = &depPaths.LateSharedLibs
999 depPtr = &depPaths.LateSharedLibsDeps
1000 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001001 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001002 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001003 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001004 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001005 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001006 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001007 staticLib, ok := cc.linker.(libraryInterface)
1008 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001009 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001010 return
1011 }
1012
1013 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1014 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1015 for i := range missingDeps {
1016 missingDeps[i] += postfix
1017 }
1018 ctx.AddMissingDependencies(missingDeps)
1019 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001020 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001021 case headerDepTag:
1022 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001023 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001024 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001025 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001026 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001027 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001028 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001029 }
1030
Dan Willemsen581341d2017-02-09 16:16:31 -08001031 switch tag {
1032 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1033 staticLib, ok := cc.linker.(libraryInterface)
1034 if !ok || !staticLib.static() {
1035 ctx.ModuleErrorf("module %q not a static library", name)
1036 return
1037 }
1038
1039 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001040 // in static libraries act as if they were whole static libraries. The same goes for
1041 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001042 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1043 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001044 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1045 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001046 }
1047
Colin Cross26c34ed2016-09-30 17:10:16 -07001048 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001049 if !linkFile.Valid() {
1050 ctx.ModuleErrorf("module %q missing output file", name)
1051 return
1052 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001053 *ptr = append(*ptr, linkFile.Path())
1054 }
1055
Colin Crossc99deeb2016-04-11 15:06:20 -07001056 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001057 dep := depFile
1058 if !dep.Valid() {
1059 dep = linkFile
1060 }
1061 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001062 }
1063 })
1064
Colin Crossdd84e052017-05-17 13:44:16 -07001065 // Dedup exported flags from dependencies
1066 depPaths.Flags = firstUniqueElements(depPaths.Flags)
1067
Colin Crossca860ac2016-01-04 14:34:37 -08001068 return depPaths
1069}
1070
1071func (c *Module) InstallInData() bool {
1072 if c.installer == nil {
1073 return false
1074 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001075 return c.installer.inData()
1076}
1077
1078func (c *Module) InstallInSanitizerDir() bool {
1079 if c.installer == nil {
1080 return false
1081 }
1082 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001083 return true
1084 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001085 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001086}
1087
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001088func (c *Module) HostToolPath() android.OptionalPath {
1089 if c.installer == nil {
1090 return android.OptionalPath{}
1091 }
1092 return c.installer.hostToolPath()
1093}
1094
Colin Cross2ba19d92015-05-07 15:44:20 -07001095//
Colin Crosscfad1192015-11-02 16:43:11 -08001096// Defaults
1097//
Colin Crossca860ac2016-01-04 14:34:37 -08001098type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001099 android.ModuleBase
1100 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -08001101}
1102
Colin Cross635c3b02016-05-18 15:37:25 -07001103func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001104}
1105
Colin Cross1e676be2016-10-12 14:38:15 -07001106func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1107}
1108
Colin Crossca860ac2016-01-04 14:34:37 -08001109func defaultsFactory() (blueprint.Module, []interface{}) {
Colin Crosse1d764e2016-08-18 14:18:32 -07001110 return DefaultsFactory()
1111}
1112
1113func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
Colin Crossca860ac2016-01-04 14:34:37 -08001114 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001115
Colin Crosse1d764e2016-08-18 14:18:32 -07001116 props = append(props,
Colin Crossca860ac2016-01-04 14:34:37 -08001117 &BaseProperties{},
1118 &BaseCompilerProperties{},
1119 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001120 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001121 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001122 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001123 &TestProperties{},
1124 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001125 &UnusedProperties{},
1126 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001127 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001128 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001129 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001130 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001131 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001132 &SAbiProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001133 )
Colin Crosscfad1192015-11-02 16:43:11 -08001134
Colin Crosse1d764e2016-08-18 14:18:32 -07001135 return android.InitDefaultsModule(module, module, props...)
Colin Crosscfad1192015-11-02 16:43:11 -08001136}
1137
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001138const (
1139 // coreMode is the variant used for framework-private libraries, or
1140 // SDK libraries. (which framework-private libraries can use)
1141 coreMode = "core"
1142
1143 // vendorMode is the variant used for /vendor code that compiles
1144 // against the VNDK.
1145 vendorMode = "vendor"
1146)
1147
1148func vendorMutator(mctx android.BottomUpMutatorContext) {
1149 if mctx.Os() != android.Android {
1150 return
1151 }
1152
1153 m, ok := mctx.Module().(*Module)
1154 if !ok {
1155 return
1156 }
1157
1158 // Sanity check
1159 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1160 mctx.PropertyErrorf("vendor_available",
1161 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1162 return
1163 }
1164
1165 if !mctx.DeviceConfig().CompileVndk() {
1166 // If the device isn't compiling against the VNDK, we always
1167 // use the core mode.
1168 mctx.CreateVariations(coreMode)
1169 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1170 // LL-NDK stubs only exist in the vendor variant, since the
1171 // real libraries will be used in the core variant.
1172 mctx.CreateVariations(vendorMode)
1173 } else if Bool(m.Properties.Vendor_available) {
1174 // This will be available in both /system and /vendor
1175 mod := mctx.CreateVariations(coreMode, vendorMode)
1176 mod[1].(*Module).Properties.UseVndk = true
1177 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1178 // This will be available in /vendor only
1179 mod := mctx.CreateVariations(vendorMode)
1180 mod[0].(*Module).Properties.UseVndk = true
1181 } else {
1182 // This is either in /system (or similar: /data), or is a
1183 // modules built with the NDK. Modules built with the NDK
1184 // will be restricted using the existing link type checks.
1185 mctx.CreateVariations(coreMode)
1186 }
1187}
1188
Colin Crossdd84e052017-05-17 13:44:16 -07001189// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1190// modifies the slice contents in place, and returns a subslice of the original slice
1191func firstUniqueElements(list []string) []string {
1192 k := 0
1193outer:
1194 for i := 0; i < len(list); i++ {
1195 for j := 0; j < k; j++ {
1196 if list[i] == list[j] {
1197 continue outer
1198 }
1199 }
1200 list[k] = list[i]
1201 k++
1202 }
1203 return list[:k]
1204}
1205
Colin Cross74d1ec02015-04-28 13:30:13 -07001206// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1207// modifies the slice contents in place, and returns a subslice of the original slice
1208func lastUniqueElements(list []string) []string {
1209 totalSkip := 0
1210 for i := len(list) - 1; i >= totalSkip; i-- {
1211 skip := 0
1212 for j := i - 1; j >= totalSkip; j-- {
1213 if list[i] == list[j] {
1214 skip++
1215 } else {
1216 list[j+skip] = list[j]
1217 }
1218 }
1219 totalSkip += skip
1220 }
1221 return list[totalSkip:]
1222}
Colin Cross06a931b2015-10-28 17:23:31 -07001223
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001224func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1225 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1226 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1227 }
1228 return ctx.AConfig().PlatformSdkVersion()
1229}
1230
Colin Cross06a931b2015-10-28 17:23:31 -07001231var Bool = proptools.Bool