blob: 4ad0670738ba2e0652f799827455776e84fcb920 [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)
Stephen Craneba090d12017-05-09 15:44:35 -070054
55 ctx.TopDown("lto_deps", ltoDepsMutator)
56 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070057 })
Colin Crossb98c8b02016-07-29 13:44:28 -070058
59 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070060}
61
Colin Crossca860ac2016-01-04 14:34:37 -080062type Deps struct {
63 SharedLibs, LateSharedLibs []string
64 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080065 HeaderLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070066
Colin Cross5950f382016-12-13 12:50:57 -080067 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070068
Colin Cross81413472016-04-11 14:37:39 -070069 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070070
Dan Willemsenb40aab62016-04-20 14:21:14 -070071 GeneratedSources []string
72 GeneratedHeaders []string
73
Dan Willemsenb3454ab2016-09-28 17:34:58 -070074 ReexportGeneratedHeaders []string
75
Colin Cross97ba0732015-03-23 17:50:24 -070076 CrtBegin, CrtEnd string
Colin Crossc472d572015-03-17 15:06:21 -070077}
78
Colin Crossca860ac2016-01-04 14:34:37 -080079type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070080 // Paths to .so files
81 SharedLibs, LateSharedLibs android.Paths
82 // Paths to the dependencies to use for .so files (.so.toc files)
83 SharedLibsDeps, LateSharedLibsDeps android.Paths
84 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -070085 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070086
Colin Cross26c34ed2016-09-30 17:10:16 -070087 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -070088 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -080089 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -070090 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -070091
Colin Cross26c34ed2016-09-30 17:10:16 -070092 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -070093 GeneratedSources android.Paths
94 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -070095
Dan Willemsen76f08272016-07-09 00:14:08 -070096 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -070097 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -070098
Colin Cross26c34ed2016-09-30 17:10:16 -070099 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700100 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700101}
102
Colin Crossca860ac2016-01-04 14:34:37 -0800103type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700104 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
105 ArFlags []string // Flags that apply to ar
106 AsFlags []string // Flags that apply to assembly source files
107 CFlags []string // Flags that apply to C and C++ source files
108 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
109 ConlyFlags []string // Flags that apply to C source files
110 CppFlags []string // Flags that apply to C++ source files
111 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
112 YaccFlags []string // Flags that apply to Yacc source files
113 protoFlags []string // Flags that apply to proto source files
114 aidlFlags []string // Flags that apply to aidl source files
115 rsFlags []string // Flags that apply to renderscript source files
116 LdFlags []string // Flags that apply to linker command lines
117 libFlags []string // Flags to add libraries early to the link order
118 TidyFlags []string // Flags that apply to clang-tidy
119 SAbiFlags []string // Flags that apply to header-abi-dumper
120 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700121
Colin Crossc3199482017-03-30 15:03:04 -0700122 // Global include flags that apply to C, C++, and assembly source files
123 // These must be after any module include flags, which will be in GlobalFlags.
124 SystemIncludeFlags []string
125
Colin Crossb98c8b02016-07-29 13:44:28 -0700126 Toolchain config.Toolchain
Colin Cross28344522015-04-22 13:07:53 -0700127 Clang bool
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700128 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800129 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800130 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800131
132 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800133 DynamicLinker string
134
Colin Cross635c3b02016-05-18 15:37:25 -0700135 CFlagsDeps android.Paths // Files depended on by compiler flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800136
137 GroupStaticLibs bool
Colin Crossc472d572015-03-17 15:06:21 -0700138}
139
Colin Cross81413472016-04-11 14:37:39 -0700140type ObjectLinkerProperties struct {
141 // names of other cc_object modules to link into this module using partial linking
142 Objs []string `android:"arch_variant"`
143}
144
Colin Crossca860ac2016-01-04 14:34:37 -0800145// Properties used to compile all C or C++ modules
146type BaseProperties struct {
147 // compile module with clang instead of gcc
148 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700149
150 // Minimum sdk version supported when compiling against the ndk
151 Sdk_version string
152
Colin Crossca860ac2016-01-04 14:34:37 -0800153 // don't insert default compiler flags into asflags, cflags,
154 // cppflags, conlyflags, ldflags, or include_dirs
155 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700156
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700157 // whether this module should be allowed to install onto /vendor as
158 // well as /system. The two variants will be built separately, one
159 // like normal, and the other limited to the set of libraries and
160 // headers that are exposed to /vendor modules.
161 //
162 // The vendor variant may be used with a different (newer) /system,
163 // so it shouldn't have any unversioned runtime dependencies, or
164 // make assumptions about the system that may not be true in the
165 // future.
166 //
167 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
168 Vendor_available *bool
169
Colin Crossc99deeb2016-04-11 15:06:20 -0700170 AndroidMkSharedLibs []string `blueprint:"mutated"`
Colin Crossbc6fb162016-05-24 15:39:04 -0700171 HideFromMake bool `blueprint:"mutated"`
Colin Crossb0f28952016-09-19 16:46:53 -0700172 PreventInstall bool `blueprint:"mutated"`
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700173
174 UseVndk bool `blueprint:"mutated"`
Colin Crossca860ac2016-01-04 14:34:37 -0800175}
176
Colin Crossca860ac2016-01-04 14:34:37 -0800177type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800178 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800179}
180
Colin Crossca860ac2016-01-04 14:34:37 -0800181type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800182 static() bool
183 staticBinary() bool
184 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700185 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800186 noDefaultCompilerFlags() bool
187 sdk() bool
188 sdkVersion() string
Dan Willemsend2ede872016-11-18 14:54:24 -0800189 vndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900190 isVndk() bool
191 isVndkSp() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800192 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700193 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700194 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800195}
196
197type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700198 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800199 ModuleContextIntf
200}
201
202type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700203 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800204 ModuleContextIntf
205}
206
Colin Cross37047f12016-12-13 17:06:13 -0800207type DepsContext interface {
208 android.BottomUpMutatorContext
209 ModuleContextIntf
210}
211
Colin Crossca860ac2016-01-04 14:34:37 -0800212type feature interface {
213 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800214 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800215 flags(ctx ModuleContext, flags Flags) Flags
216 props() []interface{}
217}
218
219type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700220 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800221 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700222 compilerFlags(ctx ModuleContext, flags Flags) Flags
223 compilerProps() []interface{}
224
Colin Cross76fada02016-07-27 10:31:13 -0700225 appendCflags([]string)
226 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700227 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800228}
229
230type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700231 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800232 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700233 linkerFlags(ctx ModuleContext, flags Flags) Flags
234 linkerProps() []interface{}
235
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700236 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700237 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800238}
239
240type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700241 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700242 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800243 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700244 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700245 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800246}
247
Colin Crossc99deeb2016-04-11 15:06:20 -0700248type dependencyTag struct {
249 blueprint.BaseDependencyTag
250 name string
251 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700252
253 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700254}
255
256var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700257 sharedDepTag = dependencyTag{name: "shared", library: true}
258 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
259 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
260 staticDepTag = dependencyTag{name: "static", library: true}
261 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
262 lateStaticDepTag = dependencyTag{name: "late static", library: true}
263 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800264 headerDepTag = dependencyTag{name: "header", library: true}
265 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700266 genSourceDepTag = dependencyTag{name: "gen source"}
267 genHeaderDepTag = dependencyTag{name: "gen header"}
268 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
269 objDepTag = dependencyTag{name: "obj"}
270 crtBeginDepTag = dependencyTag{name: "crtbegin"}
271 crtEndDepTag = dependencyTag{name: "crtend"}
272 reuseObjTag = dependencyTag{name: "reuse objects"}
273 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
274 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700275)
276
Colin Crossca860ac2016-01-04 14:34:37 -0800277// Module contains the properties and members used by all C/C++ module types, and implements
278// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
279// to construct the output file. Behavior can be customized with a Customizer interface
280type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700281 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700282 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700283
Colin Crossca860ac2016-01-04 14:34:37 -0800284 Properties BaseProperties
285 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700286
Colin Crossca860ac2016-01-04 14:34:37 -0800287 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700288 hod android.HostOrDeviceSupported
289 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700290
Colin Crossca860ac2016-01-04 14:34:37 -0800291 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700292 features []feature
293 compiler compiler
294 linker linker
295 installer installer
296 stl *stl
297 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800298 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800299 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900300 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700301 lto *lto
Colin Cross16b23492016-01-06 14:41:07 -0800302
303 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700304
Colin Cross635c3b02016-05-18 15:37:25 -0700305 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800306
Colin Crossb98c8b02016-07-29 13:44:28 -0700307 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700308
309 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800310
311 // Flags used to compile this module
312 flags Flags
Colin Crossc472d572015-03-17 15:06:21 -0700313}
314
Colin Cross36242852017-06-23 15:06:31 -0700315func (c *Module) Init() android.Module {
316 c.AddProperties(&c.Properties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800317 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700318 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800319 }
320 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700321 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800322 }
323 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700324 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800325 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700326 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700327 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700328 }
Colin Cross16b23492016-01-06 14:41:07 -0800329 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700330 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800331 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800332 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700333 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800334 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800335 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700336 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800337 }
Justin Yun8effde42017-06-23 19:24:43 +0900338 if c.vndkdep != nil {
339 c.AddProperties(c.vndkdep.props()...)
340 }
Stephen Craneba090d12017-05-09 15:44:35 -0700341 if c.lto != nil {
342 c.AddProperties(c.lto.props()...)
343 }
Colin Crossca860ac2016-01-04 14:34:37 -0800344 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700345 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800346 }
Colin Crossc472d572015-03-17 15:06:21 -0700347
Colin Cross36242852017-06-23 15:06:31 -0700348 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700349
Colin Cross1f44a3a2017-07-07 14:33:33 -0700350 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700351
352 return c
Colin Crossc472d572015-03-17 15:06:21 -0700353}
354
Colin Crossb916a382016-07-29 17:28:03 -0700355// Returns true for dependency roots (binaries)
356// TODO(ccross): also handle dlopenable libraries
357func (c *Module) isDependencyRoot() bool {
358 if root, ok := c.linker.(interface {
359 isDependencyRoot() bool
360 }); ok {
361 return root.isDependencyRoot()
362 }
363 return false
364}
365
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700366func (c *Module) vndk() bool {
367 return c.Properties.UseVndk
368}
369
Justin Yun8effde42017-06-23 19:24:43 +0900370func (c *Module) isVndk() bool {
371 if c.vndkdep != nil {
372 return c.vndkdep.isVndk()
373 }
374 return false
375}
376
Colin Crossca860ac2016-01-04 14:34:37 -0800377type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700378 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800379 moduleContextImpl
380}
381
Colin Cross37047f12016-12-13 17:06:13 -0800382type depsContext struct {
383 android.BottomUpMutatorContext
384 moduleContextImpl
385}
386
Colin Crossca860ac2016-01-04 14:34:37 -0800387type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700388 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800389 moduleContextImpl
390}
391
Justin Yun8effde42017-06-23 19:24:43 +0900392// Vendor returns true for vendor modules excluding VNDK libraries so that
393// they get installed onto the correct partition
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700394func (ctx *moduleContext) Vendor() bool {
Justin Yun8effde42017-06-23 19:24:43 +0900395 return ctx.ModuleContext.Vendor() || (ctx.mod.vndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700396}
397
Colin Crossca860ac2016-01-04 14:34:37 -0800398type moduleContextImpl struct {
399 mod *Module
400 ctx BaseModuleContext
401}
402
Colin Crossca860ac2016-01-04 14:34:37 -0800403func (ctx *moduleContextImpl) clang() bool {
404 return ctx.mod.clang(ctx.ctx)
405}
406
Colin Crossb98c8b02016-07-29 13:44:28 -0700407func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800408 return ctx.mod.toolchain(ctx.ctx)
409}
410
411func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700412 if static, ok := ctx.mod.linker.(interface {
413 static() bool
414 }); ok {
415 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800416 }
Colin Crossb916a382016-07-29 17:28:03 -0700417 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800418}
419
420func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700421 if static, ok := ctx.mod.linker.(interface {
422 staticBinary() bool
423 }); ok {
424 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800425 }
Colin Crossb916a382016-07-29 17:28:03 -0700426 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800427}
428
429func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
430 return Bool(ctx.mod.Properties.No_default_compiler_flags)
431}
432
433func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700434 if ctx.ctx.Device() && !ctx.vndk() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700435 return ctx.mod.Properties.Sdk_version != ""
436 }
437 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800438}
439
440func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700441 if ctx.ctx.Device() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700442 if ctx.vndk() {
443 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800444 } else {
445 return ctx.mod.Properties.Sdk_version
446 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700447 }
448 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800449}
450
Dan Willemsend2ede872016-11-18 14:54:24 -0800451func (ctx *moduleContextImpl) vndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700452 return ctx.mod.vndk()
Dan Willemsend2ede872016-11-18 14:54:24 -0800453}
454
Justin Yun8effde42017-06-23 19:24:43 +0900455func (ctx *moduleContextImpl) isVndk() bool {
456 return ctx.mod.isVndk()
457}
458
459func (ctx *moduleContextImpl) isVndkSp() bool {
460 if vndk := ctx.mod.vndkdep; vndk != nil {
461 return vndk.isVndkSp()
462 }
463 return false
464}
465
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800466// Create source abi dumps if the module belongs to the list of VndkLibraries.
467func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900468 return ctx.ctx.Device() && (ctx.mod.isVndk() || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800469}
470
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700471func (ctx *moduleContextImpl) selectedStl() string {
472 if stl := ctx.mod.stl; stl != nil {
473 return stl.Properties.SelectedStl
474 }
475 return ""
476}
477
Colin Crossce75d2c2016-10-06 16:12:58 -0700478func (ctx *moduleContextImpl) baseModuleName() string {
479 return ctx.mod.ModuleBase.BaseModuleName()
480}
481
Colin Cross635c3b02016-05-18 15:37:25 -0700482func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800483 return &Module{
484 hod: hod,
485 multilib: multilib,
486 }
487}
488
Colin Cross635c3b02016-05-18 15:37:25 -0700489func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800490 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700491 module.features = []feature{
492 &tidyFeature{},
493 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700494 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800495 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800496 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800497 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900498 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700499 module.lto = &lto{}
Colin Crossca860ac2016-01-04 14:34:37 -0800500 return module
501}
502
Colin Crossce75d2c2016-10-06 16:12:58 -0700503func (c *Module) Prebuilt() *android.Prebuilt {
504 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
505 return p.prebuilt()
506 }
507 return nil
508}
509
510func (c *Module) Name() string {
511 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700512 if p, ok := c.linker.(interface {
513 Name(string) string
514 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700515 name = p.Name(name)
516 }
517 return name
518}
519
Colin Cross635c3b02016-05-18 15:37:25 -0700520func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800521 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700522 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800523 moduleContextImpl: moduleContextImpl{
524 mod: c,
525 },
526 }
527 ctx.ctx = ctx
528
529 flags := Flags{
530 Toolchain: c.toolchain(ctx),
531 Clang: c.clang(ctx),
532 }
Colin Crossca860ac2016-01-04 14:34:37 -0800533 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700534 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800535 }
536 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700537 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800538 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700539 if c.stl != nil {
540 flags = c.stl.flags(ctx, flags)
541 }
Colin Cross16b23492016-01-06 14:41:07 -0800542 if c.sanitize != nil {
543 flags = c.sanitize.flags(ctx, flags)
544 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800545 if c.coverage != nil {
546 flags = c.coverage.flags(ctx, flags)
547 }
Stephen Craneba090d12017-05-09 15:44:35 -0700548 if c.lto != nil {
549 flags = c.lto.flags(ctx, flags)
550 }
Colin Crossca860ac2016-01-04 14:34:37 -0800551 for _, feature := range c.features {
552 flags = feature.flags(ctx, flags)
553 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800554 if ctx.Failed() {
555 return
556 }
557
Colin Crossb98c8b02016-07-29 13:44:28 -0700558 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
559 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
560 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800561
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800562 deps := c.depsToPaths(ctx)
563 if ctx.Failed() {
564 return
565 }
566 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
567 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700568 // We need access to all the flags seen by a source file.
569 if c.sabi != nil {
570 flags = c.sabi.flags(ctx, flags)
571 }
Colin Crossca860ac2016-01-04 14:34:37 -0800572 // Optimization to reduce size of build.ninja
573 // Replace the long list of flags for each file with a module-local variable
574 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
575 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
576 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
577 flags.CFlags = []string{"$cflags"}
578 flags.CppFlags = []string{"$cppflags"}
579 flags.AsFlags = []string{"$asflags"}
580
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700581 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800582 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700583 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800584 if ctx.Failed() {
585 return
586 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800587 }
588
Colin Crossca860ac2016-01-04 14:34:37 -0800589 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700590 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800591 if ctx.Failed() {
592 return
593 }
Colin Cross635c3b02016-05-18 15:37:25 -0700594 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700595 }
Colin Cross5049f022015-03-18 13:28:46 -0700596
Colin Crossce75d2c2016-10-06 16:12:58 -0700597 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
598 c.installer.install(ctx, c.outputFile.Path())
599 if ctx.Failed() {
600 return
Colin Crossca860ac2016-01-04 14:34:37 -0800601 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700602 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800603}
604
Colin Crossb98c8b02016-07-29 13:44:28 -0700605func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800606 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700607 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800608 }
Colin Crossca860ac2016-01-04 14:34:37 -0800609 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800610}
611
Colin Crossca860ac2016-01-04 14:34:37 -0800612func (c *Module) begin(ctx BaseModuleContext) {
613 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700614 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700615 }
Colin Crossca860ac2016-01-04 14:34:37 -0800616 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700617 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800618 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700619 if c.stl != nil {
620 c.stl.begin(ctx)
621 }
Colin Cross16b23492016-01-06 14:41:07 -0800622 if c.sanitize != nil {
623 c.sanitize.begin(ctx)
624 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800625 if c.coverage != nil {
626 c.coverage.begin(ctx)
627 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800628 if c.sabi != nil {
629 c.sabi.begin(ctx)
630 }
Justin Yun8effde42017-06-23 19:24:43 +0900631 if c.vndkdep != nil {
632 c.vndkdep.begin(ctx)
633 }
Stephen Craneba090d12017-05-09 15:44:35 -0700634 if c.lto != nil {
635 c.lto.begin(ctx)
636 }
Colin Crossca860ac2016-01-04 14:34:37 -0800637 for _, feature := range c.features {
638 feature.begin(ctx)
639 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700640 if ctx.sdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700641 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700642 if err != nil {
643 ctx.PropertyErrorf("sdk_version", err.Error())
644 }
Dan Albert90f7a4d2016-11-08 14:34:24 -0800645 c.Properties.Sdk_version = version
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700646 }
Colin Crossca860ac2016-01-04 14:34:37 -0800647}
648
Colin Cross37047f12016-12-13 17:06:13 -0800649func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700650 deps := Deps{}
651
652 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700653 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700654 }
655 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700656 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700657 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700658 if c.stl != nil {
659 deps = c.stl.deps(ctx, deps)
660 }
Colin Cross16b23492016-01-06 14:41:07 -0800661 if c.sanitize != nil {
662 deps = c.sanitize.deps(ctx, deps)
663 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800664 if c.coverage != nil {
665 deps = c.coverage.deps(ctx, deps)
666 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800667 if c.sabi != nil {
668 deps = c.sabi.deps(ctx, deps)
669 }
Justin Yun8effde42017-06-23 19:24:43 +0900670 if c.vndkdep != nil {
671 deps = c.vndkdep.deps(ctx, deps)
672 }
Stephen Craneba090d12017-05-09 15:44:35 -0700673 if c.lto != nil {
674 deps = c.lto.deps(ctx, deps)
675 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700676 for _, feature := range c.features {
677 deps = feature.deps(ctx, deps)
678 }
679
680 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
681 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
682 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
683 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
684 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
Colin Cross5950f382016-12-13 12:50:57 -0800685 deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700686
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700687 for _, lib := range deps.ReexportSharedLibHeaders {
688 if !inList(lib, deps.SharedLibs) {
689 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
690 }
691 }
692
693 for _, lib := range deps.ReexportStaticLibHeaders {
694 if !inList(lib, deps.StaticLibs) {
695 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
696 }
697 }
698
Colin Cross5950f382016-12-13 12:50:57 -0800699 for _, lib := range deps.ReexportHeaderLibHeaders {
700 if !inList(lib, deps.HeaderLibs) {
701 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
702 }
703 }
704
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700705 for _, gen := range deps.ReexportGeneratedHeaders {
706 if !inList(gen, deps.GeneratedHeaders) {
707 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
708 }
709 }
710
Colin Crossc99deeb2016-04-11 15:06:20 -0700711 return deps
712}
713
Dan Albert7e9d2952016-08-04 13:02:36 -0700714func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800715 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700716 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800717 moduleContextImpl: moduleContextImpl{
718 mod: c,
719 },
720 }
721 ctx.ctx = ctx
722
Colin Crossca860ac2016-01-04 14:34:37 -0800723 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700724}
725
Colin Cross1e676be2016-10-12 14:38:15 -0700726func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
727 if !c.Enabled() {
728 return
729 }
730
Colin Cross37047f12016-12-13 17:06:13 -0800731 ctx := &depsContext{
732 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700733 moduleContextImpl: moduleContextImpl{
734 mod: c,
735 },
736 }
737 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800738
Colin Crossc99deeb2016-04-11 15:06:20 -0700739 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800740
Dan Albert914449f2016-06-17 16:45:24 -0700741 variantNdkLibs := []string{}
742 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700743 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700744 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700745
Dan Albert914449f2016-06-17 16:45:24 -0700746 // Rewrites the names of shared libraries into the names of the NDK
747 // libraries where appropriate. This returns two slices.
748 //
749 // The first is a list of non-variant shared libraries (either rewritten
750 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
751 // because they are not NDK libraries).
752 //
753 // The second is a list of ndk_library modules. These need to be
754 // separated because they are a variation dependency and must be added
755 // in a different manner.
756 rewriteNdkLibs := func(list []string) ([]string, []string) {
757 variantLibs := []string{}
758 nonvariantLibs := []string{}
759 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700760 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700761 if !inList(entry, ndkMigratedLibs) {
762 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
763 } else {
764 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
765 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900766 } else if ctx.vndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700767 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700768 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700769 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700770 }
771 }
Dan Albert914449f2016-06-17 16:45:24 -0700772 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700773 }
774
Dan Albert914449f2016-06-17 16:45:24 -0700775 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
776 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900777 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700778 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700779
Colin Cross32ec36c2016-12-15 07:39:51 -0800780 for _, lib := range deps.HeaderLibs {
781 depTag := headerDepTag
782 if inList(lib, deps.ReexportHeaderLibHeaders) {
783 depTag = headerExportDepTag
784 }
785 actx.AddVariationDependencies(nil, depTag, lib)
786 }
Colin Cross5950f382016-12-13 12:50:57 -0800787
Colin Crossc99deeb2016-04-11 15:06:20 -0700788 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
789 deps.WholeStaticLibs...)
790
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700791 for _, lib := range deps.StaticLibs {
792 depTag := staticDepTag
793 if inList(lib, deps.ReexportStaticLibHeaders) {
794 depTag = staticExportDepTag
795 }
Colin Cross15a0d462016-07-14 14:49:58 -0700796 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700797 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700798
799 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
800 deps.LateStaticLibs...)
801
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700802 for _, lib := range deps.SharedLibs {
803 depTag := sharedDepTag
804 if inList(lib, deps.ReexportSharedLibHeaders) {
805 depTag = sharedExportDepTag
806 }
Colin Cross15a0d462016-07-14 14:49:58 -0700807 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700808 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700809
810 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
811 deps.LateSharedLibs...)
812
Colin Cross68861832016-07-08 10:41:41 -0700813 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700814
815 for _, gen := range deps.GeneratedHeaders {
816 depTag := genHeaderDepTag
817 if inList(gen, deps.ReexportGeneratedHeaders) {
818 depTag = genHeaderExportDepTag
819 }
820 actx.AddDependency(c, depTag, gen)
821 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700822
Colin Cross68861832016-07-08 10:41:41 -0700823 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700824
825 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700826 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800827 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700828 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700829 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700830 }
Dan Albert914449f2016-06-17 16:45:24 -0700831
832 version := ctx.sdkVersion()
833 actx.AddVariationDependencies([]blueprint.Variation{
834 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
835 actx.AddVariationDependencies([]blueprint.Variation{
836 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700837}
Colin Cross21b9a242015-03-24 14:15:58 -0700838
Dan Albert7e9d2952016-08-04 13:02:36 -0700839func beginMutator(ctx android.BottomUpMutatorContext) {
840 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
841 c.beginMutator(ctx)
842 }
843}
844
Colin Crossca860ac2016-01-04 14:34:37 -0800845func (c *Module) clang(ctx BaseModuleContext) bool {
846 clang := Bool(c.Properties.Clang)
847
848 if c.Properties.Clang == nil {
849 if ctx.Host() {
850 clang = true
851 }
852
853 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
854 clang = true
855 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800856 }
Colin Cross28344522015-04-22 13:07:53 -0700857
Colin Crossca860ac2016-01-04 14:34:37 -0800858 if !c.toolchain(ctx).ClangSupported() {
859 clang = false
860 }
861
862 return clang
863}
864
Colin Crossc99deeb2016-04-11 15:06:20 -0700865// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700866func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800867 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800868
Dan Willemsena96ff642016-06-07 12:34:45 -0700869 // Whether a module can link to another module, taking into
870 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700871 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700872 if from.Target().Os != android.Android {
873 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700874 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700875 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700876 if from.Properties.UseVndk {
Justin Yun8effde42017-06-23 19:24:43 +0900877 // Though vendor code is limited by the vendor mutator,
878 // each vendor-available module needs to check
879 // link-type for VNDK.
880 if from.vndkdep != nil {
881 from.vndkdep.vndkCheckLinkType(ctx, to)
882 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700883 return
884 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700885 if from.Properties.Sdk_version == "" {
886 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700887 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700888 }
Colin Crossb916a382016-07-29 17:28:03 -0700889 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700890 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700891 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700892 }
893 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
894 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700895 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700896 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700897 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
898 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700899 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700900 }
Colin Crossb916a382016-07-29 17:28:03 -0700901 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700902 // These aren't real libraries, but are the stub shared libraries that are included in
903 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700904 return
Dan Albert914449f2016-06-17 16:45:24 -0700905 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700906 if to.Properties.Sdk_version == "" {
907 // NDK code linking to platform code is never okay.
908 ctx.ModuleErrorf("depends on non-NDK-built library %q",
909 ctx.OtherModuleName(to))
910 }
911
912 // All this point we know we have two NDK libraries, but we need to
913 // check that we're not linking against anything built against a higher
914 // API level, as it is only valid to link against older or equivalent
915 // APIs.
916
917 if from.Properties.Sdk_version == "current" {
918 // Current can link against anything.
919 return
920 } else if to.Properties.Sdk_version == "current" {
921 // Current can't be linked against by anything else.
922 ctx.ModuleErrorf("links %q built against newer API version %q",
923 ctx.OtherModuleName(to), "current")
924 }
925
926 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
927 if err != nil {
928 ctx.PropertyErrorf("sdk_version",
929 "Invalid sdk_version value (must be int): %q",
930 from.Properties.Sdk_version)
931 }
932 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
933 if err != nil {
934 ctx.PropertyErrorf("sdk_version",
935 "Invalid sdk_version value (must be int): %q",
936 to.Properties.Sdk_version)
937 }
938
939 if toApi > fromApi {
940 ctx.ModuleErrorf("links %q built against newer API version %q",
941 ctx.OtherModuleName(to), to.Properties.Sdk_version)
942 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700943 }
944
Colin Crossc99deeb2016-04-11 15:06:20 -0700945 ctx.VisitDirectDeps(func(m blueprint.Module) {
946 name := ctx.OtherModuleName(m)
947 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800948
Colin Cross635c3b02016-05-18 15:37:25 -0700949 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700950 if a == nil {
951 ctx.ModuleErrorf("module %q not an android module", name)
952 return
Colin Crossca860ac2016-01-04 14:34:37 -0800953 }
Colin Crossca860ac2016-01-04 14:34:37 -0800954
Dan Willemsena96ff642016-06-07 12:34:45 -0700955 cc, _ := m.(*Module)
956 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700957 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800958 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700959 case genSourceDepTag:
960 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
961 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
962 genRule.GeneratedSourceFiles()...)
963 } else {
964 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
965 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700966 // Support exported headers from a generated_sources dependency
967 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700968 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700969 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
970 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
971 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800972 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700973 depPaths.Flags = append(depPaths.Flags, flags)
974 if tag == genHeaderExportDepTag {
975 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700976 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
977 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700978 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
979 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
980
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700981 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700982 } else {
983 ctx.ModuleErrorf("module %q is not a genrule", name)
984 }
985 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700986 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800987 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700988 return
989 }
990
991 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800992 if ctx.AConfig().AllowMissingDependencies() {
993 ctx.AddMissingDependencies([]string{name})
994 } else {
995 ctx.ModuleErrorf("depends on disabled module %q", name)
996 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700997 return
998 }
999
Colin Crossa1ad8d12016-06-01 17:09:44 -07001000 if a.Target().Os != ctx.Os() {
1001 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
1002 return
1003 }
1004
1005 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
1006 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001007 return
1008 }
1009
Colin Crossc99deeb2016-04-11 15:06:20 -07001010 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -08001011 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001012 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001013 depPaths.Objs = depPaths.Objs.Append(objs)
1014 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001015 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001016 return
1017 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001018 }
1019
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001020 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -07001021 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001022 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001023 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001024 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001025 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001026
1027 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001028 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001029 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001030 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jayant Chowdharyaf6eb712017-08-23 16:08:29 -07001031 // Re-exported shared library headers must be included as well since they can help us with type information
1032 // about template instantiations (instantiated from their headers).
1033 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001034 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001035 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001036
Dan Albert9e10cd42016-08-03 14:12:14 -07001037 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -07001038 }
1039
Colin Cross26c34ed2016-09-30 17:10:16 -07001040 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001041 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001042
Colin Cross26c34ed2016-09-30 17:10:16 -07001043 linkFile := cc.outputFile
1044 depFile := android.OptionalPath{}
1045
Colin Crossc99deeb2016-04-11 15:06:20 -07001046 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -07001047 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001048 ptr = &depPaths.SharedLibs
1049 depPtr = &depPaths.SharedLibsDeps
1050 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001051 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001052 ptr = &depPaths.LateSharedLibs
1053 depPtr = &depPaths.LateSharedLibsDeps
1054 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001055 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001056 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001057 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001058 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001059 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001060 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001061 staticLib, ok := cc.linker.(libraryInterface)
1062 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001063 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001064 return
1065 }
1066
1067 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1068 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1069 for i := range missingDeps {
1070 missingDeps[i] += postfix
1071 }
1072 ctx.AddMissingDependencies(missingDeps)
1073 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001074 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001075 case headerDepTag:
1076 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001077 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001078 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001079 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001080 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001081 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001082 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001083 }
1084
Dan Willemsen581341d2017-02-09 16:16:31 -08001085 switch tag {
1086 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1087 staticLib, ok := cc.linker.(libraryInterface)
1088 if !ok || !staticLib.static() {
1089 ctx.ModuleErrorf("module %q not a static library", name)
1090 return
1091 }
1092
1093 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001094 // in static libraries act as if they were whole static libraries. The same goes for
1095 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001096 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1097 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001098 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1099 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001100 }
1101
Colin Cross26c34ed2016-09-30 17:10:16 -07001102 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001103 if !linkFile.Valid() {
1104 ctx.ModuleErrorf("module %q missing output file", name)
1105 return
1106 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001107 *ptr = append(*ptr, linkFile.Path())
1108 }
1109
Colin Crossc99deeb2016-04-11 15:06:20 -07001110 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001111 dep := depFile
1112 if !dep.Valid() {
1113 dep = linkFile
1114 }
1115 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001116 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001117
1118 // Export the shared libs to the make world. In doing so, .vendor suffix
1119 // is added if the lib has both core and vendor variants and this module
1120 // is building against vndk. This is because the vendor variant will be
1121 // have .vendor suffix in its name in the make world. However, if the
1122 // lib is a vendor-only lib or this lib is not building against vndk,
1123 // then the suffix is not added.
1124 switch tag {
1125 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
1126 libName := strings.TrimSuffix(name, llndkLibrarySuffix)
1127 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001128 isLLndk := inList(libName, llndkLibraries)
Jiyong Park27b188b2017-07-18 13:23:39 +09001129 if c.vndk() && (Bool(cc.Properties.Vendor_available) || isLLndk) {
1130 libName += vendorSuffix
1131 }
1132 // Note: the order of libs in this list is not important because
1133 // they merely serve as dependencies in the make world and do not
1134 // affect this lib itself.
1135 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, libName)
1136 }
Colin Crossca860ac2016-01-04 14:34:37 -08001137 })
1138
Colin Crossdd84e052017-05-17 13:44:16 -07001139 // Dedup exported flags from dependencies
1140 depPaths.Flags = firstUniqueElements(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001141 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
1142 depPaths.ReexportedFlags = firstUniqueElements(depPaths.ReexportedFlags)
1143 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1144
1145 if c.sabi != nil {
1146 c.sabi.Properties.ReexportedIncludeFlags = firstUniqueElements(c.sabi.Properties.ReexportedIncludeFlags)
1147 }
Colin Crossdd84e052017-05-17 13:44:16 -07001148
Colin Crossca860ac2016-01-04 14:34:37 -08001149 return depPaths
1150}
1151
1152func (c *Module) InstallInData() bool {
1153 if c.installer == nil {
1154 return false
1155 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001156 return c.installer.inData()
1157}
1158
1159func (c *Module) InstallInSanitizerDir() bool {
1160 if c.installer == nil {
1161 return false
1162 }
1163 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001164 return true
1165 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001166 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001167}
1168
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001169func (c *Module) HostToolPath() android.OptionalPath {
1170 if c.installer == nil {
1171 return android.OptionalPath{}
1172 }
1173 return c.installer.hostToolPath()
1174}
1175
Nan Zhangd4e641b2017-07-12 12:55:28 -07001176func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1177 return c.outputFile
1178}
1179
Colin Cross2ba19d92015-05-07 15:44:20 -07001180//
Colin Crosscfad1192015-11-02 16:43:11 -08001181// Defaults
1182//
Colin Crossca860ac2016-01-04 14:34:37 -08001183type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001184 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001185 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001186}
1187
Colin Cross635c3b02016-05-18 15:37:25 -07001188func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001189}
1190
Colin Cross1e676be2016-10-12 14:38:15 -07001191func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1192}
1193
Colin Cross36242852017-06-23 15:06:31 -07001194func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001195 return DefaultsFactory()
1196}
1197
Colin Cross36242852017-06-23 15:06:31 -07001198func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001199 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001200
Colin Cross36242852017-06-23 15:06:31 -07001201 module.AddProperties(props...)
1202 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001203 &BaseProperties{},
1204 &BaseCompilerProperties{},
1205 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001206 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001207 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001208 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001209 &TestProperties{},
1210 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001211 &UnusedProperties{},
1212 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001213 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001214 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001215 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001216 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001217 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001218 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001219 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001220 &LTOProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001221 )
Colin Crosscfad1192015-11-02 16:43:11 -08001222
Colin Cross1f44a3a2017-07-07 14:33:33 -07001223 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001224
1225 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001226}
1227
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001228const (
1229 // coreMode is the variant used for framework-private libraries, or
1230 // SDK libraries. (which framework-private libraries can use)
1231 coreMode = "core"
1232
1233 // vendorMode is the variant used for /vendor code that compiles
1234 // against the VNDK.
1235 vendorMode = "vendor"
1236)
1237
1238func vendorMutator(mctx android.BottomUpMutatorContext) {
1239 if mctx.Os() != android.Android {
1240 return
1241 }
1242
1243 m, ok := mctx.Module().(*Module)
1244 if !ok {
1245 return
1246 }
1247
1248 // Sanity check
1249 if Bool(m.Properties.Vendor_available) && mctx.Vendor() {
1250 mctx.PropertyErrorf("vendor_available",
1251 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1252 return
1253 }
Justin Yun8effde42017-06-23 19:24:43 +09001254 if vndk := m.vndkdep; vndk != nil {
1255 if vndk.isVndk() && !Bool(m.Properties.Vendor_available) {
1256 mctx.PropertyErrorf("vndk",
1257 "has to define `vendor_available: true` to enable vndk")
1258 return
1259 }
1260 if !vndk.isVndk() && vndk.isVndkSp() {
1261 mctx.PropertyErrorf("vndk",
1262 "must set `enabled: true` to set `support_system_process: true`")
1263 return
1264 }
1265 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001266
1267 if !mctx.DeviceConfig().CompileVndk() {
1268 // If the device isn't compiling against the VNDK, we always
1269 // use the core mode.
1270 mctx.CreateVariations(coreMode)
1271 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1272 // LL-NDK stubs only exist in the vendor variant, since the
1273 // real libraries will be used in the core variant.
1274 mctx.CreateVariations(vendorMode)
1275 } else if Bool(m.Properties.Vendor_available) {
1276 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001277 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001278 mod := mctx.CreateVariations(coreMode, vendorMode)
1279 mod[1].(*Module).Properties.UseVndk = true
1280 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1281 // This will be available in /vendor only
1282 mod := mctx.CreateVariations(vendorMode)
1283 mod[0].(*Module).Properties.UseVndk = true
1284 } else {
1285 // This is either in /system (or similar: /data), or is a
1286 // modules built with the NDK. Modules built with the NDK
1287 // will be restricted using the existing link type checks.
1288 mctx.CreateVariations(coreMode)
1289 }
1290}
1291
Colin Crossdd84e052017-05-17 13:44:16 -07001292// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1293// modifies the slice contents in place, and returns a subslice of the original slice
1294func firstUniqueElements(list []string) []string {
1295 k := 0
1296outer:
1297 for i := 0; i < len(list); i++ {
1298 for j := 0; j < k; j++ {
1299 if list[i] == list[j] {
1300 continue outer
1301 }
1302 }
1303 list[k] = list[i]
1304 k++
1305 }
1306 return list[:k]
1307}
1308
Colin Cross74d1ec02015-04-28 13:30:13 -07001309// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1310// modifies the slice contents in place, and returns a subslice of the original slice
1311func lastUniqueElements(list []string) []string {
1312 totalSkip := 0
1313 for i := len(list) - 1; i >= totalSkip; i-- {
1314 skip := 0
1315 for j := i - 1; j >= totalSkip; j-- {
1316 if list[i] == list[j] {
1317 skip++
1318 } else {
1319 list[j+skip] = list[j]
1320 }
1321 }
1322 totalSkip += skip
1323 }
1324 return list[totalSkip:]
1325}
Colin Cross06a931b2015-10-28 17:23:31 -07001326
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001327func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1328 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1329 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1330 }
1331 return ctx.AConfig().PlatformSdkVersion()
1332}
1333
Colin Cross06a931b2015-10-28 17:23:31 -07001334var Bool = proptools.Bool