blob: 867b1969e87a0e02dbbcb90fd7c3b0e568559b35 [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 Crossca860ac2016-01-04 14:34:37 -0800307func (c *Module) Init() (blueprint.Module, []interface{}) {
308 props := []interface{}{&c.Properties, &c.unused}
Colin Crossca860ac2016-01-04 14:34:37 -0800309 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700310 props = append(props, c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800311 }
312 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700313 props = append(props, c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800314 }
315 if c.installer != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700316 props = append(props, c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800317 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700318 if c.stl != nil {
319 props = append(props, c.stl.props()...)
320 }
Colin Cross16b23492016-01-06 14:41:07 -0800321 if c.sanitize != nil {
322 props = append(props, c.sanitize.props()...)
323 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800324 if c.coverage != nil {
325 props = append(props, c.coverage.props()...)
326 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800327 if c.sabi != nil {
328 props = append(props, c.sabi.props()...)
329 }
Colin Crossca860ac2016-01-04 14:34:37 -0800330 for _, feature := range c.features {
331 props = append(props, feature.props()...)
332 }
Colin Crossc472d572015-03-17 15:06:21 -0700333
Colin Cross635c3b02016-05-18 15:37:25 -0700334 _, props = android.InitAndroidArchModule(c, c.hod, c.multilib, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700335
Colin Cross635c3b02016-05-18 15:37:25 -0700336 return android.InitDefaultableModule(c, c, props...)
Colin Crossc472d572015-03-17 15:06:21 -0700337}
338
Colin Crossb916a382016-07-29 17:28:03 -0700339// Returns true for dependency roots (binaries)
340// TODO(ccross): also handle dlopenable libraries
341func (c *Module) isDependencyRoot() bool {
342 if root, ok := c.linker.(interface {
343 isDependencyRoot() bool
344 }); ok {
345 return root.isDependencyRoot()
346 }
347 return false
348}
349
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700350func (c *Module) vndk() bool {
351 return c.Properties.UseVndk
352}
353
Colin Crossca860ac2016-01-04 14:34:37 -0800354type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700355 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800356 moduleContextImpl
357}
358
Colin Cross37047f12016-12-13 17:06:13 -0800359type depsContext struct {
360 android.BottomUpMutatorContext
361 moduleContextImpl
362}
363
Colin Crossca860ac2016-01-04 14:34:37 -0800364type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700365 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800366 moduleContextImpl
367}
368
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700369// Vendor returns true for vendor modules so that they get installed onto the
370// correct partition
371func (ctx *moduleContext) Vendor() bool {
372 return ctx.ModuleContext.Vendor() || ctx.moduleContextImpl.mod.Properties.UseVndk
373}
374
Colin Crossca860ac2016-01-04 14:34:37 -0800375type moduleContextImpl struct {
376 mod *Module
377 ctx BaseModuleContext
378}
379
Colin Crossca860ac2016-01-04 14:34:37 -0800380func (ctx *moduleContextImpl) clang() bool {
381 return ctx.mod.clang(ctx.ctx)
382}
383
Colin Crossb98c8b02016-07-29 13:44:28 -0700384func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800385 return ctx.mod.toolchain(ctx.ctx)
386}
387
388func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700389 if static, ok := ctx.mod.linker.(interface {
390 static() bool
391 }); ok {
392 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800393 }
Colin Crossb916a382016-07-29 17:28:03 -0700394 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800395}
396
397func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700398 if static, ok := ctx.mod.linker.(interface {
399 staticBinary() bool
400 }); ok {
401 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800402 }
Colin Crossb916a382016-07-29 17:28:03 -0700403 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800404}
405
406func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
407 return Bool(ctx.mod.Properties.No_default_compiler_flags)
408}
409
410func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700411 if ctx.ctx.Device() && !ctx.vndk() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700412 return ctx.mod.Properties.Sdk_version != ""
413 }
414 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800415}
416
417func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700418 if ctx.ctx.Device() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700419 if ctx.vndk() {
420 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800421 } else {
422 return ctx.mod.Properties.Sdk_version
423 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700424 }
425 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800426}
427
Dan Willemsend2ede872016-11-18 14:54:24 -0800428func (ctx *moduleContextImpl) vndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700429 return ctx.mod.vndk()
Dan Willemsend2ede872016-11-18 14:54:24 -0800430}
431
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800432// Create source abi dumps if the module belongs to the list of VndkLibraries.
433func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700434 return ctx.ctx.Device() && ((Bool(ctx.mod.Properties.Vendor_available)) || (inList(ctx.baseModuleName(), config.LLndkLibraries())))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800435}
436
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700437func (ctx *moduleContextImpl) selectedStl() string {
438 if stl := ctx.mod.stl; stl != nil {
439 return stl.Properties.SelectedStl
440 }
441 return ""
442}
443
Colin Crossce75d2c2016-10-06 16:12:58 -0700444func (ctx *moduleContextImpl) baseModuleName() string {
445 return ctx.mod.ModuleBase.BaseModuleName()
446}
447
Colin Cross635c3b02016-05-18 15:37:25 -0700448func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800449 return &Module{
450 hod: hod,
451 multilib: multilib,
452 }
453}
454
Colin Cross635c3b02016-05-18 15:37:25 -0700455func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800456 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700457 module.features = []feature{
458 &tidyFeature{},
459 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700460 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800461 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800462 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800463 module.sabi = &sabi{}
Colin Crossca860ac2016-01-04 14:34:37 -0800464 return module
465}
466
Colin Crossce75d2c2016-10-06 16:12:58 -0700467func (c *Module) Prebuilt() *android.Prebuilt {
468 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
469 return p.prebuilt()
470 }
471 return nil
472}
473
474func (c *Module) Name() string {
475 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700476 if p, ok := c.linker.(interface {
477 Name(string) string
478 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700479 name = p.Name(name)
480 }
481 return name
482}
483
Colin Cross635c3b02016-05-18 15:37:25 -0700484func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800485 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700486 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800487 moduleContextImpl: moduleContextImpl{
488 mod: c,
489 },
490 }
491 ctx.ctx = ctx
492
493 flags := Flags{
494 Toolchain: c.toolchain(ctx),
495 Clang: c.clang(ctx),
496 }
Colin Crossca860ac2016-01-04 14:34:37 -0800497 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700498 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800499 }
500 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700501 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800502 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700503 if c.stl != nil {
504 flags = c.stl.flags(ctx, flags)
505 }
Colin Cross16b23492016-01-06 14:41:07 -0800506 if c.sanitize != nil {
507 flags = c.sanitize.flags(ctx, flags)
508 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800509 if c.coverage != nil {
510 flags = c.coverage.flags(ctx, flags)
511 }
Colin Crossca860ac2016-01-04 14:34:37 -0800512 for _, feature := range c.features {
513 flags = feature.flags(ctx, flags)
514 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800515 if ctx.Failed() {
516 return
517 }
518
Colin Crossb98c8b02016-07-29 13:44:28 -0700519 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
520 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
521 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800522
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800523 deps := c.depsToPaths(ctx)
524 if ctx.Failed() {
525 return
526 }
527 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
528 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700529 // We need access to all the flags seen by a source file.
530 if c.sabi != nil {
531 flags = c.sabi.flags(ctx, flags)
532 }
Colin Crossca860ac2016-01-04 14:34:37 -0800533 // Optimization to reduce size of build.ninja
534 // Replace the long list of flags for each file with a module-local variable
535 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
536 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
537 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
538 flags.CFlags = []string{"$cflags"}
539 flags.CppFlags = []string{"$cppflags"}
540 flags.AsFlags = []string{"$asflags"}
541
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700542 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800543 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700544 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800545 if ctx.Failed() {
546 return
547 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800548 }
549
Colin Crossca860ac2016-01-04 14:34:37 -0800550 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700551 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800552 if ctx.Failed() {
553 return
554 }
Colin Cross635c3b02016-05-18 15:37:25 -0700555 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700556 }
Colin Cross5049f022015-03-18 13:28:46 -0700557
Colin Crossce75d2c2016-10-06 16:12:58 -0700558 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
559 c.installer.install(ctx, c.outputFile.Path())
560 if ctx.Failed() {
561 return
Colin Crossca860ac2016-01-04 14:34:37 -0800562 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700563 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800564}
565
Colin Crossb98c8b02016-07-29 13:44:28 -0700566func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800567 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700568 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800569 }
Colin Crossca860ac2016-01-04 14:34:37 -0800570 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800571}
572
Colin Crossca860ac2016-01-04 14:34:37 -0800573func (c *Module) begin(ctx BaseModuleContext) {
574 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700575 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700576 }
Colin Crossca860ac2016-01-04 14:34:37 -0800577 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700578 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800579 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700580 if c.stl != nil {
581 c.stl.begin(ctx)
582 }
Colin Cross16b23492016-01-06 14:41:07 -0800583 if c.sanitize != nil {
584 c.sanitize.begin(ctx)
585 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800586 if c.coverage != nil {
587 c.coverage.begin(ctx)
588 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800589 if c.sabi != nil {
590 c.sabi.begin(ctx)
591 }
Colin Crossca860ac2016-01-04 14:34:37 -0800592 for _, feature := range c.features {
593 feature.begin(ctx)
594 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700595 if ctx.sdk() {
596 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
597 if err != nil {
598 ctx.PropertyErrorf("sdk_version", err.Error())
599 }
Dan Albert90f7a4d2016-11-08 14:34:24 -0800600 c.Properties.Sdk_version = version
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700601 }
Colin Crossca860ac2016-01-04 14:34:37 -0800602}
603
Colin Cross37047f12016-12-13 17:06:13 -0800604func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700605 deps := Deps{}
606
607 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700608 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700609 }
610 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700611 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700612 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700613 if c.stl != nil {
614 deps = c.stl.deps(ctx, deps)
615 }
Colin Cross16b23492016-01-06 14:41:07 -0800616 if c.sanitize != nil {
617 deps = c.sanitize.deps(ctx, deps)
618 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800619 if c.coverage != nil {
620 deps = c.coverage.deps(ctx, deps)
621 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800622 if c.sabi != nil {
623 deps = c.sabi.deps(ctx, deps)
624 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700625 for _, feature := range c.features {
626 deps = feature.deps(ctx, deps)
627 }
628
629 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
630 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
631 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
632 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
633 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
Colin Cross5950f382016-12-13 12:50:57 -0800634 deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700635
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700636 for _, lib := range deps.ReexportSharedLibHeaders {
637 if !inList(lib, deps.SharedLibs) {
638 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
639 }
640 }
641
642 for _, lib := range deps.ReexportStaticLibHeaders {
643 if !inList(lib, deps.StaticLibs) {
644 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
645 }
646 }
647
Colin Cross5950f382016-12-13 12:50:57 -0800648 for _, lib := range deps.ReexportHeaderLibHeaders {
649 if !inList(lib, deps.HeaderLibs) {
650 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
651 }
652 }
653
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700654 for _, gen := range deps.ReexportGeneratedHeaders {
655 if !inList(gen, deps.GeneratedHeaders) {
656 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
657 }
658 }
659
Colin Crossc99deeb2016-04-11 15:06:20 -0700660 return deps
661}
662
Dan Albert7e9d2952016-08-04 13:02:36 -0700663func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800664 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700665 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800666 moduleContextImpl: moduleContextImpl{
667 mod: c,
668 },
669 }
670 ctx.ctx = ctx
671
Colin Crossca860ac2016-01-04 14:34:37 -0800672 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700673}
674
Colin Cross1e676be2016-10-12 14:38:15 -0700675func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
676 if !c.Enabled() {
677 return
678 }
679
Colin Cross37047f12016-12-13 17:06:13 -0800680 ctx := &depsContext{
681 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700682 moduleContextImpl: moduleContextImpl{
683 mod: c,
684 },
685 }
686 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800687
Colin Crossc99deeb2016-04-11 15:06:20 -0700688 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800689
Colin Crossb5bc4b42016-07-11 16:11:59 -0700690 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.SharedLibs...)
691 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, deps.LateSharedLibs...)
Dan Willemsen72d39932016-07-08 23:23:48 -0700692
Dan Albert914449f2016-06-17 16:45:24 -0700693 variantNdkLibs := []string{}
694 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700695 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700696 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700697
Dan Albert914449f2016-06-17 16:45:24 -0700698 // Rewrites the names of shared libraries into the names of the NDK
699 // libraries where appropriate. This returns two slices.
700 //
701 // The first is a list of non-variant shared libraries (either rewritten
702 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
703 // because they are not NDK libraries).
704 //
705 // The second is a list of ndk_library modules. These need to be
706 // separated because they are a variation dependency and must be added
707 // in a different manner.
708 rewriteNdkLibs := func(list []string) ([]string, []string) {
709 variantLibs := []string{}
710 nonvariantLibs := []string{}
711 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700712 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700713 if !inList(entry, ndkMigratedLibs) {
714 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
715 } else {
716 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
717 }
Dan Willemsenb916b802017-03-19 13:44:32 -0700718 } else if ctx.vndk() && inList(entry, config.LLndkLibraries()) {
719 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700720 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700721 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700722 }
723 }
Dan Albert914449f2016-06-17 16:45:24 -0700724 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700725 }
726
Dan Albert914449f2016-06-17 16:45:24 -0700727 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
728 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Dan Willemsen72d39932016-07-08 23:23:48 -0700729 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700730
Colin Cross32ec36c2016-12-15 07:39:51 -0800731 for _, lib := range deps.HeaderLibs {
732 depTag := headerDepTag
733 if inList(lib, deps.ReexportHeaderLibHeaders) {
734 depTag = headerExportDepTag
735 }
736 actx.AddVariationDependencies(nil, depTag, lib)
737 }
Colin Cross5950f382016-12-13 12:50:57 -0800738
Colin Crossc99deeb2016-04-11 15:06:20 -0700739 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
740 deps.WholeStaticLibs...)
741
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700742 for _, lib := range deps.StaticLibs {
743 depTag := staticDepTag
744 if inList(lib, deps.ReexportStaticLibHeaders) {
745 depTag = staticExportDepTag
746 }
Colin Cross15a0d462016-07-14 14:49:58 -0700747 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700748 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700749
750 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
751 deps.LateStaticLibs...)
752
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700753 for _, lib := range deps.SharedLibs {
754 depTag := sharedDepTag
755 if inList(lib, deps.ReexportSharedLibHeaders) {
756 depTag = sharedExportDepTag
757 }
Colin Cross15a0d462016-07-14 14:49:58 -0700758 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700759 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700760
761 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
762 deps.LateSharedLibs...)
763
Colin Cross68861832016-07-08 10:41:41 -0700764 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700765
766 for _, gen := range deps.GeneratedHeaders {
767 depTag := genHeaderDepTag
768 if inList(gen, deps.ReexportGeneratedHeaders) {
769 depTag = genHeaderExportDepTag
770 }
771 actx.AddDependency(c, depTag, gen)
772 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700773
Colin Cross68861832016-07-08 10:41:41 -0700774 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700775
776 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700777 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800778 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700779 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700780 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700781 }
Dan Albert914449f2016-06-17 16:45:24 -0700782
783 version := ctx.sdkVersion()
784 actx.AddVariationDependencies([]blueprint.Variation{
785 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
786 actx.AddVariationDependencies([]blueprint.Variation{
787 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700788}
Colin Cross21b9a242015-03-24 14:15:58 -0700789
Dan Albert7e9d2952016-08-04 13:02:36 -0700790func beginMutator(ctx android.BottomUpMutatorContext) {
791 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
792 c.beginMutator(ctx)
793 }
794}
795
Colin Crossca860ac2016-01-04 14:34:37 -0800796func (c *Module) clang(ctx BaseModuleContext) bool {
797 clang := Bool(c.Properties.Clang)
798
799 if c.Properties.Clang == nil {
800 if ctx.Host() {
801 clang = true
802 }
803
804 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
805 clang = true
806 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800807 }
Colin Cross28344522015-04-22 13:07:53 -0700808
Colin Crossca860ac2016-01-04 14:34:37 -0800809 if !c.toolchain(ctx).ClangSupported() {
810 clang = false
811 }
812
813 return clang
814}
815
Colin Crossc99deeb2016-04-11 15:06:20 -0700816// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700817func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800818 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800819
Dan Willemsena96ff642016-06-07 12:34:45 -0700820 // Whether a module can link to another module, taking into
821 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700822 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700823 if from.Target().Os != android.Android {
824 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700825 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700826 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700827 if from.Properties.UseVndk {
828 // Vendor code is already limited by the vendor mutator
829 return
830 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700831 if from.Properties.Sdk_version == "" {
832 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700833 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700834 }
Colin Crossb916a382016-07-29 17:28:03 -0700835 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700836 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700837 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700838 }
839 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
840 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700841 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700842 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700843 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
844 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700845 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700846 }
Colin Crossb916a382016-07-29 17:28:03 -0700847 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700848 // These aren't real libraries, but are the stub shared libraries that are included in
849 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700850 return
Dan Albert914449f2016-06-17 16:45:24 -0700851 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700852 if to.Properties.Sdk_version == "" {
853 // NDK code linking to platform code is never okay.
854 ctx.ModuleErrorf("depends on non-NDK-built library %q",
855 ctx.OtherModuleName(to))
856 }
857
858 // All this point we know we have two NDK libraries, but we need to
859 // check that we're not linking against anything built against a higher
860 // API level, as it is only valid to link against older or equivalent
861 // APIs.
862
863 if from.Properties.Sdk_version == "current" {
864 // Current can link against anything.
865 return
866 } else if to.Properties.Sdk_version == "current" {
867 // Current can't be linked against by anything else.
868 ctx.ModuleErrorf("links %q built against newer API version %q",
869 ctx.OtherModuleName(to), "current")
870 }
871
872 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
873 if err != nil {
874 ctx.PropertyErrorf("sdk_version",
875 "Invalid sdk_version value (must be int): %q",
876 from.Properties.Sdk_version)
877 }
878 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
879 if err != nil {
880 ctx.PropertyErrorf("sdk_version",
881 "Invalid sdk_version value (must be int): %q",
882 to.Properties.Sdk_version)
883 }
884
885 if toApi > fromApi {
886 ctx.ModuleErrorf("links %q built against newer API version %q",
887 ctx.OtherModuleName(to), to.Properties.Sdk_version)
888 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700889 }
890
Colin Crossc99deeb2016-04-11 15:06:20 -0700891 ctx.VisitDirectDeps(func(m blueprint.Module) {
892 name := ctx.OtherModuleName(m)
893 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800894
Colin Cross635c3b02016-05-18 15:37:25 -0700895 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700896 if a == nil {
897 ctx.ModuleErrorf("module %q not an android module", name)
898 return
Colin Crossca860ac2016-01-04 14:34:37 -0800899 }
Colin Crossca860ac2016-01-04 14:34:37 -0800900
Dan Willemsena96ff642016-06-07 12:34:45 -0700901 cc, _ := m.(*Module)
902 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700903 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800904 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700905 case genSourceDepTag:
906 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
907 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
908 genRule.GeneratedSourceFiles()...)
909 } else {
910 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
911 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700912 // Support exported headers from a generated_sources dependency
913 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700914 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700915 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
916 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
917 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800918 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700919 depPaths.Flags = append(depPaths.Flags, flags)
920 if tag == genHeaderExportDepTag {
921 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700922 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
923 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700924 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
925 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
926
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700927 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700928 } else {
929 ctx.ModuleErrorf("module %q is not a genrule", name)
930 }
931 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700932 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800933 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700934 return
935 }
936
937 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800938 if ctx.AConfig().AllowMissingDependencies() {
939 ctx.AddMissingDependencies([]string{name})
940 } else {
941 ctx.ModuleErrorf("depends on disabled module %q", name)
942 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700943 return
944 }
945
Colin Crossa1ad8d12016-06-01 17:09:44 -0700946 if a.Target().Os != ctx.Os() {
947 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
948 return
949 }
950
951 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
952 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700953 return
954 }
955
Colin Crossc99deeb2016-04-11 15:06:20 -0700956 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -0800957 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700958 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -0700959 depPaths.Objs = depPaths.Objs.Append(objs)
960 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700961 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -0800962 return
963 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700964 }
965
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700966 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -0700967 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -0700968 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -0700969 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -0700970 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700971 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700972
973 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -0700974 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700975 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700976 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
977 // Re-exported flags from shared library dependencies are not included as those shared libraries
978 // will be included in the vndk set.
979 if tag == staticExportDepTag || tag == headerExportDepTag {
980 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
981 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700982 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700983 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700984
Dan Albert9e10cd42016-08-03 14:12:14 -0700985 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -0700986 }
987
Colin Cross26c34ed2016-09-30 17:10:16 -0700988 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -0700989 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -0700990
Colin Cross26c34ed2016-09-30 17:10:16 -0700991 linkFile := cc.outputFile
992 depFile := android.OptionalPath{}
993
Colin Crossc99deeb2016-04-11 15:06:20 -0700994 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -0700995 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -0700996 ptr = &depPaths.SharedLibs
997 depPtr = &depPaths.SharedLibsDeps
998 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -0700999 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001000 ptr = &depPaths.LateSharedLibs
1001 depPtr = &depPaths.LateSharedLibsDeps
1002 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001003 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001004 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001005 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001006 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001007 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001008 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001009 staticLib, ok := cc.linker.(libraryInterface)
1010 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001011 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001012 return
1013 }
1014
1015 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1016 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1017 for i := range missingDeps {
1018 missingDeps[i] += postfix
1019 }
1020 ctx.AddMissingDependencies(missingDeps)
1021 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001022 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001023 case headerDepTag:
1024 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001025 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001026 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001027 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001028 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001029 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001030 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001031 }
1032
Dan Willemsen581341d2017-02-09 16:16:31 -08001033 switch tag {
1034 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1035 staticLib, ok := cc.linker.(libraryInterface)
1036 if !ok || !staticLib.static() {
1037 ctx.ModuleErrorf("module %q not a static library", name)
1038 return
1039 }
1040
1041 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001042 // in static libraries act as if they were whole static libraries. The same goes for
1043 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001044 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1045 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001046 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1047 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001048 }
1049
Colin Cross26c34ed2016-09-30 17:10:16 -07001050 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001051 if !linkFile.Valid() {
1052 ctx.ModuleErrorf("module %q missing output file", name)
1053 return
1054 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001055 *ptr = append(*ptr, linkFile.Path())
1056 }
1057
Colin Crossc99deeb2016-04-11 15:06:20 -07001058 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001059 dep := depFile
1060 if !dep.Valid() {
1061 dep = linkFile
1062 }
1063 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001064 }
1065 })
1066
Colin Crossdd84e052017-05-17 13:44:16 -07001067 // Dedup exported flags from dependencies
1068 depPaths.Flags = firstUniqueElements(depPaths.Flags)
1069
Colin Crossca860ac2016-01-04 14:34:37 -08001070 return depPaths
1071}
1072
1073func (c *Module) InstallInData() bool {
1074 if c.installer == nil {
1075 return false
1076 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001077 return c.installer.inData()
1078}
1079
1080func (c *Module) InstallInSanitizerDir() bool {
1081 if c.installer == nil {
1082 return false
1083 }
1084 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001085 return true
1086 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001087 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001088}
1089
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001090func (c *Module) HostToolPath() android.OptionalPath {
1091 if c.installer == nil {
1092 return android.OptionalPath{}
1093 }
1094 return c.installer.hostToolPath()
1095}
1096
Colin Cross2ba19d92015-05-07 15:44:20 -07001097//
Colin Crosscfad1192015-11-02 16:43:11 -08001098// Defaults
1099//
Colin Crossca860ac2016-01-04 14:34:37 -08001100type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001101 android.ModuleBase
1102 android.DefaultsModule
Colin Crosscfad1192015-11-02 16:43:11 -08001103}
1104
Colin Cross635c3b02016-05-18 15:37:25 -07001105func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001106}
1107
Colin Cross1e676be2016-10-12 14:38:15 -07001108func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1109}
1110
Colin Crossca860ac2016-01-04 14:34:37 -08001111func defaultsFactory() (blueprint.Module, []interface{}) {
Colin Crosse1d764e2016-08-18 14:18:32 -07001112 return DefaultsFactory()
1113}
1114
1115func DefaultsFactory(props ...interface{}) (blueprint.Module, []interface{}) {
Colin Crossca860ac2016-01-04 14:34:37 -08001116 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001117
Colin Crosse1d764e2016-08-18 14:18:32 -07001118 props = append(props,
Colin Crossca860ac2016-01-04 14:34:37 -08001119 &BaseProperties{},
1120 &BaseCompilerProperties{},
1121 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001122 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001123 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001124 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001125 &TestProperties{},
1126 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001127 &UnusedProperties{},
1128 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001129 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001130 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001131 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001132 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001133 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001134 &SAbiProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001135 )
Colin Crosscfad1192015-11-02 16:43:11 -08001136
Colin Crosse1d764e2016-08-18 14:18:32 -07001137 return android.InitDefaultsModule(module, module, props...)
Colin Crosscfad1192015-11-02 16:43:11 -08001138}
1139
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001140const (
1141 // coreMode is the variant used for framework-private libraries, or
1142 // SDK libraries. (which framework-private libraries can use)
1143 coreMode = "core"
1144
1145 // vendorMode is the variant used for /vendor code that compiles
1146 // against the VNDK.
1147 vendorMode = "vendor"
1148)
1149
1150func vendorMutator(mctx android.BottomUpMutatorContext) {
1151 if mctx.Os() != android.Android {
1152 return
1153 }
1154
1155 m, ok := mctx.Module().(*Module)
1156 if !ok {
1157 return
1158 }
1159
1160 // Sanity check
1161 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1162 mctx.PropertyErrorf("vendor_available",
1163 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1164 return
1165 }
1166
1167 if !mctx.DeviceConfig().CompileVndk() {
1168 // If the device isn't compiling against the VNDK, we always
1169 // use the core mode.
1170 mctx.CreateVariations(coreMode)
1171 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1172 // LL-NDK stubs only exist in the vendor variant, since the
1173 // real libraries will be used in the core variant.
1174 mctx.CreateVariations(vendorMode)
1175 } else if Bool(m.Properties.Vendor_available) {
1176 // This will be available in both /system and /vendor
1177 mod := mctx.CreateVariations(coreMode, vendorMode)
1178 mod[1].(*Module).Properties.UseVndk = true
1179 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1180 // This will be available in /vendor only
1181 mod := mctx.CreateVariations(vendorMode)
1182 mod[0].(*Module).Properties.UseVndk = true
1183 } else {
1184 // This is either in /system (or similar: /data), or is a
1185 // modules built with the NDK. Modules built with the NDK
1186 // will be restricted using the existing link type checks.
1187 mctx.CreateVariations(coreMode)
1188 }
1189}
1190
Colin Crossdd84e052017-05-17 13:44:16 -07001191// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1192// modifies the slice contents in place, and returns a subslice of the original slice
1193func firstUniqueElements(list []string) []string {
1194 k := 0
1195outer:
1196 for i := 0; i < len(list); i++ {
1197 for j := 0; j < k; j++ {
1198 if list[i] == list[j] {
1199 continue outer
1200 }
1201 }
1202 list[k] = list[i]
1203 k++
1204 }
1205 return list[:k]
1206}
1207
Colin Cross74d1ec02015-04-28 13:30:13 -07001208// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1209// modifies the slice contents in place, and returns a subslice of the original slice
1210func lastUniqueElements(list []string) []string {
1211 totalSkip := 0
1212 for i := len(list) - 1; i >= totalSkip; i-- {
1213 skip := 0
1214 for j := i - 1; j >= totalSkip; j-- {
1215 if list[i] == list[j] {
1216 skip++
1217 } else {
1218 list[j+skip] = list[j]
1219 }
1220 }
1221 totalSkip += skip
1222 }
1223 return list[totalSkip:]
1224}
Colin Cross06a931b2015-10-28 17:23:31 -07001225
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001226func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1227 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1228 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1229 }
1230 return ctx.AConfig().PlatformSdkVersion()
1231}
1232
Colin Cross06a931b2015-10-28 17:23:31 -07001233var Bool = proptools.Bool