blob: 983ffc0e86dc8a37c4c49efbd3ad680c02cb5725 [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()
Jiyong Parkd5b18a52017-08-03 21:22:50 +090038 ctx.BottomUp("vndk", vndkMutator).Parallel()
Dan Willemsen4416e5d2017-04-06 12:43:22 -070039 ctx.BottomUp("image", vendorMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
42 ctx.BottomUp("begin", beginMutator).Parallel()
43 })
Colin Cross16b23492016-01-06 14:41:07 -080044
Colin Cross1e676be2016-10-12 14:38:15 -070045 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
46 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
47 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080048
Colin Cross1e676be2016-10-12 14:38:15 -070049 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
50 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080051
52 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080053 ctx.TopDown("vndk_deps", sabiDepsMutator)
Colin Cross1e676be2016-10-12 14:38:15 -070054 })
Colin Crossb98c8b02016-07-29 13:44:28 -070055
56 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070057}
58
Colin Crossca860ac2016-01-04 14:34:37 -080059type Deps struct {
60 SharedLibs, LateSharedLibs []string
61 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080062 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070063
Colin Cross5950f382016-12-13 12:50:57 -080064 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070065
Colin Cross81413472016-04-11 14:37:39 -070066 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070067
Dan Willemsenb40aab62016-04-20 14:21:14 -070068 GeneratedSources []string
69 GeneratedHeaders []string
70
Dan Willemsenb3454ab2016-09-28 17:34:58 -070071 ReexportGeneratedHeaders []string
72
Colin Cross97ba0732015-03-23 17:50:24 -070073 CrtBegin, CrtEnd string
Colin Crossc472d572015-03-17 15:06:21 -070074}
75
Colin Crossca860ac2016-01-04 14:34:37 -080076type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070077 // Paths to .so files
78 SharedLibs, LateSharedLibs android.Paths
79 // Paths to the dependencies to use for .so files (.so.toc files)
80 SharedLibsDeps, LateSharedLibsDeps android.Paths
81 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070082 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070083
Colin Cross26c34ed2016-09-30 17:10:16 -070084 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070085 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080086 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070087 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070088
Colin Cross26c34ed2016-09-30 17:10:16 -070089 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070090 GeneratedSources android.Paths
91 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070092
Dan Willemsen76f08272016-07-09 00:14:08 -070093 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -070094 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070095
Colin Cross26c34ed2016-09-30 17:10:16 -070096 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -070097 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -070098}
99
Colin Crossca860ac2016-01-04 14:34:37 -0800100type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700101 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
102 ArFlags []string // Flags that apply to ar
103 AsFlags []string // Flags that apply to assembly source files
104 CFlags []string // Flags that apply to C and C++ source files
105 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
106 ConlyFlags []string // Flags that apply to C source files
107 CppFlags []string // Flags that apply to C++ source files
108 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
109 YaccFlags []string // Flags that apply to Yacc source files
110 protoFlags []string // Flags that apply to proto source files
111 aidlFlags []string // Flags that apply to aidl source files
112 rsFlags []string // Flags that apply to renderscript source files
113 LdFlags []string // Flags that apply to linker command lines
114 libFlags []string // Flags to add libraries early to the link order
115 TidyFlags []string // Flags that apply to clang-tidy
116 SAbiFlags []string // Flags that apply to header-abi-dumper
117 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700118
Colin Crossc3199482017-03-30 15:03:04 -0700119 // Global include flags that apply to C, C++, and assembly source files
120 // These must be after any module include flags, which will be in GlobalFlags.
121 SystemIncludeFlags []string
122
Colin Crossb98c8b02016-07-29 13:44:28 -0700123 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700124 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700125 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800126 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800127 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800128
129 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800130 DynamicLinker string
131
Colin Cross635c3b02016-05-18 15:37:25 -0700132 CFlagsDeps android.Paths // Files depended on by compiler flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800133
134 GroupStaticLibs bool
Colin Crossc472d572015-03-17 15:06:21 -0700135}
136
Colin Cross81413472016-04-11 14:37:39 -0700137type ObjectLinkerProperties struct {
138 // names of other cc_object modules to link into this module using partial linking
139 Objs []string `android:"arch_variant"`
140}
141
Colin Crossca860ac2016-01-04 14:34:37 -0800142// Properties used to compile all C or C++ modules
143type BaseProperties struct {
144 // compile module with clang instead of gcc
145 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700146
147 // Minimum sdk version supported when compiling against the ndk
148 Sdk_version string
149
Colin Crossca860ac2016-01-04 14:34:37 -0800150 // don't insert default compiler flags into asflags, cflags,
151 // cppflags, conlyflags, ldflags, or include_dirs
152 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700153
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700154 // whether this module should be allowed to install onto /vendor as
155 // well as /system. The two variants will be built separately, one
156 // like normal, and the other limited to the set of libraries and
157 // headers that are exposed to /vendor modules.
158 //
159 // The vendor variant may be used with a different (newer) /system,
160 // so it shouldn't have any unversioned runtime dependencies, or
161 // make assumptions about the system that may not be true in the
162 // future.
163 //
164 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
165 Vendor_available *bool
166
Colin Crossc99deeb2016-04-11 15:06:20 -0700167 AndroidMkSharedLibs []string `blueprint:"mutated"`
Colin Crossbc6fb162016-05-24 15:39:04 -0700168 HideFromMake bool `blueprint:"mutated"`
Colin Crossb0f28952016-09-19 16:46:53 -0700169 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700170
171 UseVndk bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800172}
173
Colin Crossca860ac2016-01-04 14:34:37 -0800174type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800175 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800176}
177
Colin Crossca860ac2016-01-04 14:34:37 -0800178type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800179 static() bool
180 staticBinary() bool
181 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700182 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800183 noDefaultCompilerFlags() bool
184 sdk() bool
185 sdkVersion() string
Dan Willemsend2ede872016-11-18 14:54:24 -0800186 vndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900187 isVndk() bool
188 isVndkSp() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800189 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700190 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700191 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800192}
193
194type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700195 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800196 ModuleContextIntf
197}
198
199type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700200 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800201 ModuleContextIntf
202}
203
Colin Cross37047f12016-12-13 17:06:13 -0800204type DepsContext interface {
205 android.BottomUpMutatorContext
206 ModuleContextIntf
207}
208
Colin Crossca860ac2016-01-04 14:34:37 -0800209type feature interface {
210 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800211 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800212 flags(ctx ModuleContext, flags Flags) Flags
213 props() []interface{}
214}
215
216type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700217 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800218 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700219 compilerFlags(ctx ModuleContext, flags Flags) Flags
220 compilerProps() []interface{}
221
Colin Cross76fada02016-07-27 10:31:13 -0700222 appendCflags([]string)
223 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700224 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800225}
226
227type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700228 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800229 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700230 linkerFlags(ctx ModuleContext, flags Flags) Flags
231 linkerProps() []interface{}
232
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700233 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700234 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800235}
236
237type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700238 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700239 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800240 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700241 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700242 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800243}
244
Colin Crossc99deeb2016-04-11 15:06:20 -0700245type dependencyTag struct {
246 blueprint.BaseDependencyTag
247 name string
248 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700249
250 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700251}
252
253var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700254 sharedDepTag = dependencyTag{name: "shared", library: true}
255 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
256 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
257 staticDepTag = dependencyTag{name: "static", library: true}
258 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
259 lateStaticDepTag = dependencyTag{name: "late static", library: true}
260 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800261 headerDepTag = dependencyTag{name: "header", library: true}
262 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700263 genSourceDepTag = dependencyTag{name: "gen source"}
264 genHeaderDepTag = dependencyTag{name: "gen header"}
265 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
266 objDepTag = dependencyTag{name: "obj"}
267 crtBeginDepTag = dependencyTag{name: "crtbegin"}
268 crtEndDepTag = dependencyTag{name: "crtend"}
269 reuseObjTag = dependencyTag{name: "reuse objects"}
270 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
271 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700272)
273
Colin Crossca860ac2016-01-04 14:34:37 -0800274// Module contains the properties and members used by all C/C++ module types, and implements
275// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
276// to construct the output file. Behavior can be customized with a Customizer interface
277type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700278 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700279 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700280
Colin Crossca860ac2016-01-04 14:34:37 -0800281 Properties BaseProperties
282 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700283
Colin Crossca860ac2016-01-04 14:34:37 -0800284 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700285 hod android.HostOrDeviceSupported
286 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700287
Colin Crossca860ac2016-01-04 14:34:37 -0800288 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700289 features []feature
290 compiler compiler
291 linker linker
292 installer installer
293 stl *stl
294 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800295 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800296 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900297 vndkdep *vndkdep
Colin Cross16b23492016-01-06 14:41:07 -0800298
299 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700300
Colin Cross635c3b02016-05-18 15:37:25 -0700301 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800302
Colin Crossb98c8b02016-07-29 13:44:28 -0700303 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700304
305 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800306
307 // Flags used to compile this module
308 flags Flags
Colin Crossc472d572015-03-17 15:06:21 -0700309}
310
Colin Cross36242852017-06-23 15:06:31 -0700311func (c *Module) Init() android.Module {
312 c.AddProperties(&c.Properties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800313 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700314 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800315 }
316 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700317 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800318 }
319 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700320 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800321 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700322 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700323 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700324 }
Colin Cross16b23492016-01-06 14:41:07 -0800325 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700326 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800327 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800328 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700329 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800330 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800331 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700332 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800333 }
Justin Yun8effde42017-06-23 19:24:43 +0900334 if c.vndkdep != nil {
335 c.AddProperties(c.vndkdep.props()...)
336 }
Colin Crossca860ac2016-01-04 14:34:37 -0800337 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700338 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800339 }
Colin Crossc472d572015-03-17 15:06:21 -0700340
Colin Cross36242852017-06-23 15:06:31 -0700341 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700342
Colin Cross1f44a3a2017-07-07 14:33:33 -0700343 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700344
345 return c
Colin Crossc472d572015-03-17 15:06:21 -0700346}
347
Colin Crossb916a382016-07-29 17:28:03 -0700348// Returns true for dependency roots (binaries)
349// TODO(ccross): also handle dlopenable libraries
350func (c *Module) isDependencyRoot() bool {
351 if root, ok := c.linker.(interface {
352 isDependencyRoot() bool
353 }); ok {
354 return root.isDependencyRoot()
355 }
356 return false
357}
358
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700359func (c *Module) vndk() bool {
360 return c.Properties.UseVndk
361}
362
Justin Yun8effde42017-06-23 19:24:43 +0900363func (c *Module) isVndk() bool {
364 if c.vndkdep != nil {
365 return c.vndkdep.isVndk()
366 }
367 return false
368}
369
Colin Crossca860ac2016-01-04 14:34:37 -0800370type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700371 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800372 moduleContextImpl
373}
374
Colin Cross37047f12016-12-13 17:06:13 -0800375type depsContext struct {
376 android.BottomUpMutatorContext
377 moduleContextImpl
378}
379
Colin Crossca860ac2016-01-04 14:34:37 -0800380type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700381 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800382 moduleContextImpl
383}
384
Justin Yun8effde42017-06-23 19:24:43 +0900385// Vendor returns true for vendor modules excluding VNDK libraries so that
386// they get installed onto the correct partition
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700387func (ctx *moduleContext) Vendor() bool {
Justin Yun8effde42017-06-23 19:24:43 +0900388 return ctx.ModuleContext.Vendor() || (ctx.mod.vndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700389}
390
Colin Crossca860ac2016-01-04 14:34:37 -0800391type moduleContextImpl struct {
392 mod *Module
393 ctx BaseModuleContext
394}
395
Colin Crossca860ac2016-01-04 14:34:37 -0800396func (ctx *moduleContextImpl) clang() bool {
397 return ctx.mod.clang(ctx.ctx)
398}
399
Colin Crossb98c8b02016-07-29 13:44:28 -0700400func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800401 return ctx.mod.toolchain(ctx.ctx)
402}
403
404func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700405 if static, ok := ctx.mod.linker.(interface {
406 static() bool
407 }); ok {
408 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800409 }
Colin Crossb916a382016-07-29 17:28:03 -0700410 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800411}
412
413func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700414 if static, ok := ctx.mod.linker.(interface {
415 staticBinary() bool
416 }); ok {
417 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800418 }
Colin Crossb916a382016-07-29 17:28:03 -0700419 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800420}
421
422func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
423 return Bool(ctx.mod.Properties.No_default_compiler_flags)
424}
425
426func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700427 if ctx.ctx.Device() && !ctx.vndk() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700428 return ctx.mod.Properties.Sdk_version != ""
429 }
430 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800431}
432
433func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700434 if ctx.ctx.Device() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700435 if ctx.vndk() {
436 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800437 } else {
438 return ctx.mod.Properties.Sdk_version
439 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700440 }
441 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800442}
443
Dan Willemsend2ede872016-11-18 14:54:24 -0800444func (ctx *moduleContextImpl) vndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700445 return ctx.mod.vndk()
Dan Willemsend2ede872016-11-18 14:54:24 -0800446}
447
Justin Yun8effde42017-06-23 19:24:43 +0900448func (ctx *moduleContextImpl) isVndk() bool {
449 return ctx.mod.isVndk()
450}
451
452func (ctx *moduleContextImpl) isVndkSp() bool {
453 if vndk := ctx.mod.vndkdep; vndk != nil {
454 return vndk.isVndkSp()
455 }
456 return false
457}
458
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800459// Create source abi dumps if the module belongs to the list of VndkLibraries.
460func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900461 return ctx.ctx.Device() && (ctx.mod.isVndk() || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800462}
463
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700464func (ctx *moduleContextImpl) selectedStl() string {
465 if stl := ctx.mod.stl; stl != nil {
466 return stl.Properties.SelectedStl
467 }
468 return ""
469}
470
Colin Crossce75d2c2016-10-06 16:12:58 -0700471func (ctx *moduleContextImpl) baseModuleName() string {
472 return ctx.mod.ModuleBase.BaseModuleName()
473}
474
Colin Cross635c3b02016-05-18 15:37:25 -0700475func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800476 return &Module{
477 hod: hod,
478 multilib: multilib,
479 }
480}
481
Colin Cross635c3b02016-05-18 15:37:25 -0700482func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800483 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700484 module.features = []feature{
485 &tidyFeature{},
486 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700487 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800488 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800489 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800490 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900491 module.vndkdep = &vndkdep{}
Colin Crossca860ac2016-01-04 14:34:37 -0800492 return module
493}
494
Colin Crossce75d2c2016-10-06 16:12:58 -0700495func (c *Module) Prebuilt() *android.Prebuilt {
496 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
497 return p.prebuilt()
498 }
499 return nil
500}
501
502func (c *Module) Name() string {
503 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700504 if p, ok := c.linker.(interface {
505 Name(string) string
506 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700507 name = p.Name(name)
508 }
509 return name
510}
511
Colin Cross635c3b02016-05-18 15:37:25 -0700512func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800513 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700514 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800515 moduleContextImpl: moduleContextImpl{
516 mod: c,
517 },
518 }
519 ctx.ctx = ctx
520
521 flags := Flags{
522 Toolchain: c.toolchain(ctx),
523 Clang: c.clang(ctx),
524 }
Colin Crossca860ac2016-01-04 14:34:37 -0800525 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700526 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800527 }
528 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700529 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800530 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700531 if c.stl != nil {
532 flags = c.stl.flags(ctx, flags)
533 }
Colin Cross16b23492016-01-06 14:41:07 -0800534 if c.sanitize != nil {
535 flags = c.sanitize.flags(ctx, flags)
536 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800537 if c.coverage != nil {
538 flags = c.coverage.flags(ctx, flags)
539 }
Colin Crossca860ac2016-01-04 14:34:37 -0800540 for _, feature := range c.features {
541 flags = feature.flags(ctx, flags)
542 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800543 if ctx.Failed() {
544 return
545 }
546
Colin Crossb98c8b02016-07-29 13:44:28 -0700547 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
548 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
549 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800550
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800551 deps := c.depsToPaths(ctx)
552 if ctx.Failed() {
553 return
554 }
555 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
556 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700557 // We need access to all the flags seen by a source file.
558 if c.sabi != nil {
559 flags = c.sabi.flags(ctx, flags)
560 }
Colin Crossca860ac2016-01-04 14:34:37 -0800561 // Optimization to reduce size of build.ninja
562 // Replace the long list of flags for each file with a module-local variable
563 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
564 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
565 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
566 flags.CFlags = []string{"$cflags"}
567 flags.CppFlags = []string{"$cppflags"}
568 flags.AsFlags = []string{"$asflags"}
569
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700570 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800571 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700572 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800573 if ctx.Failed() {
574 return
575 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800576 }
577
Colin Crossca860ac2016-01-04 14:34:37 -0800578 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700579 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800580 if ctx.Failed() {
581 return
582 }
Colin Cross635c3b02016-05-18 15:37:25 -0700583 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700584 }
Colin Cross5049f022015-03-18 13:28:46 -0700585
Colin Crossce75d2c2016-10-06 16:12:58 -0700586 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
587 c.installer.install(ctx, c.outputFile.Path())
588 if ctx.Failed() {
589 return
Colin Crossca860ac2016-01-04 14:34:37 -0800590 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700591 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800592}
593
Colin Crossb98c8b02016-07-29 13:44:28 -0700594func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800595 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700596 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800597 }
Colin Crossca860ac2016-01-04 14:34:37 -0800598 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800599}
600
Colin Crossca860ac2016-01-04 14:34:37 -0800601func (c *Module) begin(ctx BaseModuleContext) {
602 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700603 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700604 }
Colin Crossca860ac2016-01-04 14:34:37 -0800605 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700606 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800607 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700608 if c.stl != nil {
609 c.stl.begin(ctx)
610 }
Colin Cross16b23492016-01-06 14:41:07 -0800611 if c.sanitize != nil {
612 c.sanitize.begin(ctx)
613 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800614 if c.coverage != nil {
615 c.coverage.begin(ctx)
616 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800617 if c.sabi != nil {
618 c.sabi.begin(ctx)
619 }
Justin Yun8effde42017-06-23 19:24:43 +0900620 if c.vndkdep != nil {
621 c.vndkdep.begin(ctx)
622 }
Colin Crossca860ac2016-01-04 14:34:37 -0800623 for _, feature := range c.features {
624 feature.begin(ctx)
625 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700626 if ctx.sdk() {
627 version, err := normalizeNdkApiLevel(ctx.sdkVersion(), ctx.Arch())
628 if err != nil {
629 ctx.PropertyErrorf("sdk_version", err.Error())
630 }
Dan Albert90f7a4d2016-11-08 14:34:24 -0800631 c.Properties.Sdk_version = version
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700632 }
Colin Crossca860ac2016-01-04 14:34:37 -0800633}
634
Colin Cross37047f12016-12-13 17:06:13 -0800635func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700636 deps := Deps{}
637
638 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700639 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700640 }
641 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700642 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700643 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700644 if c.stl != nil {
645 deps = c.stl.deps(ctx, deps)
646 }
Colin Cross16b23492016-01-06 14:41:07 -0800647 if c.sanitize != nil {
648 deps = c.sanitize.deps(ctx, deps)
649 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800650 if c.coverage != nil {
651 deps = c.coverage.deps(ctx, deps)
652 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800653 if c.sabi != nil {
654 deps = c.sabi.deps(ctx, deps)
655 }
Justin Yun8effde42017-06-23 19:24:43 +0900656 if c.vndkdep != nil {
657 deps = c.vndkdep.deps(ctx, deps)
658 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700659 for _, feature := range c.features {
660 deps = feature.deps(ctx, deps)
661 }
662
663 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
664 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
665 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
666 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
667 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
Colin Cross5950f382016-12-13 12:50:57 -0800668 deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700669
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700670 for _, lib := range deps.ReexportSharedLibHeaders {
671 if !inList(lib, deps.SharedLibs) {
672 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
673 }
674 }
675
676 for _, lib := range deps.ReexportStaticLibHeaders {
677 if !inList(lib, deps.StaticLibs) {
678 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
679 }
680 }
681
Colin Cross5950f382016-12-13 12:50:57 -0800682 for _, lib := range deps.ReexportHeaderLibHeaders {
683 if !inList(lib, deps.HeaderLibs) {
684 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
685 }
686 }
687
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700688 for _, gen := range deps.ReexportGeneratedHeaders {
689 if !inList(gen, deps.GeneratedHeaders) {
690 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
691 }
692 }
693
Colin Crossc99deeb2016-04-11 15:06:20 -0700694 return deps
695}
696
Dan Albert7e9d2952016-08-04 13:02:36 -0700697func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800698 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700699 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800700 moduleContextImpl: moduleContextImpl{
701 mod: c,
702 },
703 }
704 ctx.ctx = ctx
705
Colin Crossca860ac2016-01-04 14:34:37 -0800706 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700707}
708
Colin Cross1e676be2016-10-12 14:38:15 -0700709func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
710 if !c.Enabled() {
711 return
712 }
713
Colin Cross37047f12016-12-13 17:06:13 -0800714 ctx := &depsContext{
715 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700716 moduleContextImpl: moduleContextImpl{
717 mod: c,
718 },
719 }
720 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800721
Colin Crossc99deeb2016-04-11 15:06:20 -0700722 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800723
Dan Albert914449f2016-06-17 16:45:24 -0700724 variantNdkLibs := []string{}
725 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700726 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700727 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700728
Dan Albert914449f2016-06-17 16:45:24 -0700729 // Rewrites the names of shared libraries into the names of the NDK
730 // libraries where appropriate. This returns two slices.
731 //
732 // The first is a list of non-variant shared libraries (either rewritten
733 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
734 // because they are not NDK libraries).
735 //
736 // The second is a list of ndk_library modules. These need to be
737 // separated because they are a variation dependency and must be added
738 // in a different manner.
739 rewriteNdkLibs := func(list []string) ([]string, []string) {
740 variantLibs := []string{}
741 nonvariantLibs := []string{}
742 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700743 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700744 if !inList(entry, ndkMigratedLibs) {
745 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
746 } else {
747 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
748 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900749 } else if ctx.vndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700750 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700751 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700752 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700753 }
754 }
Dan Albert914449f2016-06-17 16:45:24 -0700755 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700756 }
757
Dan Albert914449f2016-06-17 16:45:24 -0700758 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
759 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900760 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700761 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700762
Colin Cross32ec36c2016-12-15 07:39:51 -0800763 for _, lib := range deps.HeaderLibs {
764 depTag := headerDepTag
765 if inList(lib, deps.ReexportHeaderLibHeaders) {
766 depTag = headerExportDepTag
767 }
768 actx.AddVariationDependencies(nil, depTag, lib)
769 }
Colin Cross5950f382016-12-13 12:50:57 -0800770
Colin Crossc99deeb2016-04-11 15:06:20 -0700771 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
772 deps.WholeStaticLibs...)
773
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700774 for _, lib := range deps.StaticLibs {
775 depTag := staticDepTag
776 if inList(lib, deps.ReexportStaticLibHeaders) {
777 depTag = staticExportDepTag
778 }
Colin Cross15a0d462016-07-14 14:49:58 -0700779 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700780 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700781
782 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
783 deps.LateStaticLibs...)
784
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700785 for _, lib := range deps.SharedLibs {
786 depTag := sharedDepTag
787 if inList(lib, deps.ReexportSharedLibHeaders) {
788 depTag = sharedExportDepTag
789 }
Colin Cross15a0d462016-07-14 14:49:58 -0700790 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700791 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700792
793 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
794 deps.LateSharedLibs...)
795
Colin Cross68861832016-07-08 10:41:41 -0700796 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700797
798 for _, gen := range deps.GeneratedHeaders {
799 depTag := genHeaderDepTag
800 if inList(gen, deps.ReexportGeneratedHeaders) {
801 depTag = genHeaderExportDepTag
802 }
803 actx.AddDependency(c, depTag, gen)
804 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700805
Colin Cross68861832016-07-08 10:41:41 -0700806 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700807
808 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700809 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800810 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700811 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700812 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700813 }
Dan Albert914449f2016-06-17 16:45:24 -0700814
815 version := ctx.sdkVersion()
816 actx.AddVariationDependencies([]blueprint.Variation{
817 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
818 actx.AddVariationDependencies([]blueprint.Variation{
819 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700820}
Colin Cross21b9a242015-03-24 14:15:58 -0700821
Dan Albert7e9d2952016-08-04 13:02:36 -0700822func beginMutator(ctx android.BottomUpMutatorContext) {
823 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
824 c.beginMutator(ctx)
825 }
826}
827
Colin Crossca860ac2016-01-04 14:34:37 -0800828func (c *Module) clang(ctx BaseModuleContext) bool {
829 clang := Bool(c.Properties.Clang)
830
831 if c.Properties.Clang == nil {
832 if ctx.Host() {
833 clang = true
834 }
835
836 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
837 clang = true
838 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800839 }
Colin Cross28344522015-04-22 13:07:53 -0700840
Colin Crossca860ac2016-01-04 14:34:37 -0800841 if !c.toolchain(ctx).ClangSupported() {
842 clang = false
843 }
844
845 return clang
846}
847
Colin Crossc99deeb2016-04-11 15:06:20 -0700848// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700849func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800850 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800851
Dan Willemsena96ff642016-06-07 12:34:45 -0700852 // Whether a module can link to another module, taking into
853 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700854 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700855 if from.Target().Os != android.Android {
856 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700857 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700858 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700859 if from.Properties.UseVndk {
Justin Yun8effde42017-06-23 19:24:43 +0900860 // Though vendor code is limited by the vendor mutator,
861 // each vendor-available module needs to check
862 // link-type for VNDK.
863 if from.vndkdep != nil {
864 from.vndkdep.vndkCheckLinkType(ctx, to)
865 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700866 return
867 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700868 if from.Properties.Sdk_version == "" {
869 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700870 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700871 }
Colin Crossb916a382016-07-29 17:28:03 -0700872 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700873 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700874 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700875 }
876 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
877 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700878 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700879 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700880 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
881 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700882 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700883 }
Colin Crossb916a382016-07-29 17:28:03 -0700884 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700885 // These aren't real libraries, but are the stub shared libraries that are included in
886 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700887 return
Dan Albert914449f2016-06-17 16:45:24 -0700888 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700889 if to.Properties.Sdk_version == "" {
890 // NDK code linking to platform code is never okay.
891 ctx.ModuleErrorf("depends on non-NDK-built library %q",
892 ctx.OtherModuleName(to))
893 }
894
895 // All this point we know we have two NDK libraries, but we need to
896 // check that we're not linking against anything built against a higher
897 // API level, as it is only valid to link against older or equivalent
898 // APIs.
899
900 if from.Properties.Sdk_version == "current" {
901 // Current can link against anything.
902 return
903 } else if to.Properties.Sdk_version == "current" {
904 // Current can't be linked against by anything else.
905 ctx.ModuleErrorf("links %q built against newer API version %q",
906 ctx.OtherModuleName(to), "current")
907 }
908
909 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
910 if err != nil {
911 ctx.PropertyErrorf("sdk_version",
912 "Invalid sdk_version value (must be int): %q",
913 from.Properties.Sdk_version)
914 }
915 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
916 if err != nil {
917 ctx.PropertyErrorf("sdk_version",
918 "Invalid sdk_version value (must be int): %q",
919 to.Properties.Sdk_version)
920 }
921
922 if toApi > fromApi {
923 ctx.ModuleErrorf("links %q built against newer API version %q",
924 ctx.OtherModuleName(to), to.Properties.Sdk_version)
925 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700926 }
927
Colin Crossc99deeb2016-04-11 15:06:20 -0700928 ctx.VisitDirectDeps(func(m blueprint.Module) {
929 name := ctx.OtherModuleName(m)
930 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800931
Colin Cross635c3b02016-05-18 15:37:25 -0700932 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700933 if a == nil {
934 ctx.ModuleErrorf("module %q not an android module", name)
935 return
Colin Crossca860ac2016-01-04 14:34:37 -0800936 }
Colin Crossca860ac2016-01-04 14:34:37 -0800937
Dan Willemsena96ff642016-06-07 12:34:45 -0700938 cc, _ := m.(*Module)
939 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700940 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800941 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700942 case genSourceDepTag:
943 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
944 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
945 genRule.GeneratedSourceFiles()...)
946 } else {
947 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
948 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700949 // Support exported headers from a generated_sources dependency
950 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700951 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700952 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
953 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
954 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800955 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700956 depPaths.Flags = append(depPaths.Flags, flags)
957 if tag == genHeaderExportDepTag {
958 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700959 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
960 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700961 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
962 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
963
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700964 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700965 } else {
966 ctx.ModuleErrorf("module %q is not a genrule", name)
967 }
968 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700969 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800970 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700971 return
972 }
973
974 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800975 if ctx.AConfig().AllowMissingDependencies() {
976 ctx.AddMissingDependencies([]string{name})
977 } else {
978 ctx.ModuleErrorf("depends on disabled module %q", name)
979 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700980 return
981 }
982
Colin Crossa1ad8d12016-06-01 17:09:44 -0700983 if a.Target().Os != ctx.Os() {
984 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
985 return
986 }
987
988 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
989 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -0700990 return
991 }
992
Colin Crossc99deeb2016-04-11 15:06:20 -0700993 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -0800994 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700995 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -0700996 depPaths.Objs = depPaths.Objs.Append(objs)
997 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -0700998 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -0800999 return
1000 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001001 }
1002
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001003 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -07001004 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001005 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001006 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001007 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001008 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001009
1010 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001011 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001012 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001013 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1014 // Re-exported flags from shared library dependencies are not included as those shared libraries
1015 // will be included in the vndk set.
1016 if tag == staticExportDepTag || tag == headerExportDepTag {
1017 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
1018 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001019 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001020 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001021
Dan Albert9e10cd42016-08-03 14:12:14 -07001022 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -07001023 }
1024
Colin Cross26c34ed2016-09-30 17:10:16 -07001025 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001026 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001027
Colin Cross26c34ed2016-09-30 17:10:16 -07001028 linkFile := cc.outputFile
1029 depFile := android.OptionalPath{}
1030
Colin Crossc99deeb2016-04-11 15:06:20 -07001031 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -07001032 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001033 ptr = &depPaths.SharedLibs
1034 depPtr = &depPaths.SharedLibsDeps
1035 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001036 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001037 ptr = &depPaths.LateSharedLibs
1038 depPtr = &depPaths.LateSharedLibsDeps
1039 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001040 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001041 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001042 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001043 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001044 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001045 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001046 staticLib, ok := cc.linker.(libraryInterface)
1047 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001048 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001049 return
1050 }
1051
1052 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1053 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1054 for i := range missingDeps {
1055 missingDeps[i] += postfix
1056 }
1057 ctx.AddMissingDependencies(missingDeps)
1058 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001059 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001060 case headerDepTag:
1061 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001062 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001063 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001064 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001065 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001066 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001067 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001068 }
1069
Dan Willemsen581341d2017-02-09 16:16:31 -08001070 switch tag {
1071 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1072 staticLib, ok := cc.linker.(libraryInterface)
1073 if !ok || !staticLib.static() {
1074 ctx.ModuleErrorf("module %q not a static library", name)
1075 return
1076 }
1077
1078 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001079 // in static libraries act as if they were whole static libraries. The same goes for
1080 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001081 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1082 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001083 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1084 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001085 }
1086
Colin Cross26c34ed2016-09-30 17:10:16 -07001087 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001088 if !linkFile.Valid() {
1089 ctx.ModuleErrorf("module %q missing output file", name)
1090 return
1091 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001092 *ptr = append(*ptr, linkFile.Path())
1093 }
1094
Colin Crossc99deeb2016-04-11 15:06:20 -07001095 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001096 dep := depFile
1097 if !dep.Valid() {
1098 dep = linkFile
1099 }
1100 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001101 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001102
1103 // Export the shared libs to the make world. In doing so, .vendor suffix
1104 // is added if the lib has both core and vendor variants and this module
1105 // is building against vndk. This is because the vendor variant will be
1106 // have .vendor suffix in its name in the make world. However, if the
1107 // lib is a vendor-only lib or this lib is not building against vndk,
1108 // then the suffix is not added.
1109 switch tag {
1110 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
1111 libName := strings.TrimSuffix(name, llndkLibrarySuffix)
1112 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001113 isLLndk := inList(libName, llndkLibraries)
Jiyong Park27b188b2017-07-18 13:23:39 +09001114 if c.vndk() && (Bool(cc.Properties.Vendor_available) || isLLndk) {
1115 libName += vendorSuffix
1116 }
1117 // Note: the order of libs in this list is not important because
1118 // they merely serve as dependencies in the make world and do not
1119 // affect this lib itself.
1120 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, libName)
1121 }
Colin Crossca860ac2016-01-04 14:34:37 -08001122 })
1123
Colin Crossdd84e052017-05-17 13:44:16 -07001124 // Dedup exported flags from dependencies
1125 depPaths.Flags = firstUniqueElements(depPaths.Flags)
1126
Colin Crossca860ac2016-01-04 14:34:37 -08001127 return depPaths
1128}
1129
1130func (c *Module) InstallInData() bool {
1131 if c.installer == nil {
1132 return false
1133 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001134 return c.installer.inData()
1135}
1136
1137func (c *Module) InstallInSanitizerDir() bool {
1138 if c.installer == nil {
1139 return false
1140 }
1141 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001142 return true
1143 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001144 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001145}
1146
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001147func (c *Module) HostToolPath() android.OptionalPath {
1148 if c.installer == nil {
1149 return android.OptionalPath{}
1150 }
1151 return c.installer.hostToolPath()
1152}
1153
Colin Cross2ba19d92015-05-07 15:44:20 -07001154//
Colin Crosscfad1192015-11-02 16:43:11 -08001155// Defaults
1156//
Colin Crossca860ac2016-01-04 14:34:37 -08001157type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001158 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001159 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001160}
1161
Colin Cross635c3b02016-05-18 15:37:25 -07001162func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001163}
1164
Colin Cross1e676be2016-10-12 14:38:15 -07001165func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1166}
1167
Colin Cross36242852017-06-23 15:06:31 -07001168func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001169 return DefaultsFactory()
1170}
1171
Colin Cross36242852017-06-23 15:06:31 -07001172func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001173 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001174
Colin Cross36242852017-06-23 15:06:31 -07001175 module.AddProperties(props...)
1176 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001177 &BaseProperties{},
1178 &BaseCompilerProperties{},
1179 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001180 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001181 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001182 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001183 &TestProperties{},
1184 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001185 &UnusedProperties{},
1186 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001187 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001188 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001189 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001190 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001191 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001192 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001193 &VndkProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001194 )
Colin Crosscfad1192015-11-02 16:43:11 -08001195
Colin Cross1f44a3a2017-07-07 14:33:33 -07001196 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001197
1198 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001199}
1200
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001201const (
1202 // coreMode is the variant used for framework-private libraries, or
1203 // SDK libraries. (which framework-private libraries can use)
1204 coreMode = "core"
1205
1206 // vendorMode is the variant used for /vendor code that compiles
1207 // against the VNDK.
1208 vendorMode = "vendor"
1209)
1210
1211func vendorMutator(mctx android.BottomUpMutatorContext) {
1212 if mctx.Os() != android.Android {
1213 return
1214 }
1215
1216 m, ok := mctx.Module().(*Module)
1217 if !ok {
1218 return
1219 }
1220
1221 // Sanity check
1222 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1223 mctx.PropertyErrorf("vendor_available",
1224 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1225 return
1226 }
Justin Yun8effde42017-06-23 19:24:43 +09001227 if vndk := m.vndkdep; vndk != nil {
1228 if vndk.isVndk() && !Bool(m.Properties.Vendor_available) {
1229 mctx.PropertyErrorf("vndk",
1230 "has to define `vendor_available: true` to enable vndk")
1231 return
1232 }
1233 if !vndk.isVndk() && vndk.isVndkSp() {
1234 mctx.PropertyErrorf("vndk",
1235 "must set `enabled: true` to set `support_system_process: true`")
1236 return
1237 }
1238 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001239
1240 if !mctx.DeviceConfig().CompileVndk() {
1241 // If the device isn't compiling against the VNDK, we always
1242 // use the core mode.
1243 mctx.CreateVariations(coreMode)
1244 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1245 // LL-NDK stubs only exist in the vendor variant, since the
1246 // real libraries will be used in the core variant.
1247 mctx.CreateVariations(vendorMode)
1248 } else if Bool(m.Properties.Vendor_available) {
1249 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001250 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001251 mod := mctx.CreateVariations(coreMode, vendorMode)
1252 mod[1].(*Module).Properties.UseVndk = true
1253 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1254 // This will be available in /vendor only
1255 mod := mctx.CreateVariations(vendorMode)
1256 mod[0].(*Module).Properties.UseVndk = true
1257 } else {
1258 // This is either in /system (or similar: /data), or is a
1259 // modules built with the NDK. Modules built with the NDK
1260 // will be restricted using the existing link type checks.
1261 mctx.CreateVariations(coreMode)
1262 }
1263}
1264
Colin Crossdd84e052017-05-17 13:44:16 -07001265// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1266// modifies the slice contents in place, and returns a subslice of the original slice
1267func firstUniqueElements(list []string) []string {
1268 k := 0
1269outer:
1270 for i := 0; i < len(list); i++ {
1271 for j := 0; j < k; j++ {
1272 if list[i] == list[j] {
1273 continue outer
1274 }
1275 }
1276 list[k] = list[i]
1277 k++
1278 }
1279 return list[:k]
1280}
1281
Colin Cross74d1ec02015-04-28 13:30:13 -07001282// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1283// modifies the slice contents in place, and returns a subslice of the original slice
1284func lastUniqueElements(list []string) []string {
1285 totalSkip := 0
1286 for i := len(list) - 1; i >= totalSkip; i-- {
1287 skip := 0
1288 for j := i - 1; j >= totalSkip; j-- {
1289 if list[i] == list[j] {
1290 skip++
1291 } else {
1292 list[j+skip] = list[j]
1293 }
1294 }
1295 totalSkip += skip
1296 }
1297 return list[totalSkip:]
1298}
Colin Cross06a931b2015-10-28 17:23:31 -07001299
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001300func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1301 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1302 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1303 }
1304 return ctx.AConfig().PlatformSdkVersion()
1305}
1306
Colin Cross06a931b2015-10-28 17:23:31 -07001307var Bool = proptools.Bool