blob: 0e1d8962b5d9b1a9809ff3d2071d602ac11f1029 [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"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700143
144 // if set, add an extra objcopy --prefix-symbols= step
145 Prefix_symbols string
Colin Cross81413472016-04-11 14:37:39 -0700146}
147
Colin Crossca860ac2016-01-04 14:34:37 -0800148// Properties used to compile all C or C++ modules
149type BaseProperties struct {
150 // compile module with clang instead of gcc
151 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700152
153 // Minimum sdk version supported when compiling against the ndk
154 Sdk_version string
155
Colin Crossca860ac2016-01-04 14:34:37 -0800156 // don't insert default compiler flags into asflags, cflags,
157 // cppflags, conlyflags, ldflags, or include_dirs
158 No_default_compiler_flags *bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700159
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700160 AndroidMkSharedLibs []string `blueprint:"mutated"`
161 HideFromMake bool `blueprint:"mutated"`
162 PreventInstall bool `blueprint:"mutated"`
163
164 UseVndk bool `blueprint:"mutated"`
165}
166
167type VendorProperties struct {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700168 // whether this module should be allowed to install onto /vendor as
169 // well as /system. The two variants will be built separately, one
170 // like normal, and the other limited to the set of libraries and
171 // headers that are exposed to /vendor modules.
172 //
173 // The vendor variant may be used with a different (newer) /system,
174 // so it shouldn't have any unversioned runtime dependencies, or
175 // make assumptions about the system that may not be true in the
176 // future.
177 //
178 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
179 Vendor_available *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800180}
181
Colin Crossca860ac2016-01-04 14:34:37 -0800182type UnusedProperties struct {
Dan Willemsen581341d2017-02-09 16:16:31 -0800183 Tags []string
Colin Crosscfad1192015-11-02 16:43:11 -0800184}
185
Colin Crossca860ac2016-01-04 14:34:37 -0800186type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800187 static() bool
188 staticBinary() bool
189 clang() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700190 toolchain() config.Toolchain
Colin Crossca860ac2016-01-04 14:34:37 -0800191 noDefaultCompilerFlags() bool
192 sdk() bool
193 sdkVersion() string
Dan Willemsend2ede872016-11-18 14:54:24 -0800194 vndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900195 isVndk() bool
196 isVndkSp() bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800197 createVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700198 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700199 baseModuleName() string
Colin Crossca860ac2016-01-04 14:34:37 -0800200}
201
202type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700203 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800204 ModuleContextIntf
205}
206
207type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700208 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800209 ModuleContextIntf
210}
211
Colin Cross37047f12016-12-13 17:06:13 -0800212type DepsContext interface {
213 android.BottomUpMutatorContext
214 ModuleContextIntf
215}
216
Colin Crossca860ac2016-01-04 14:34:37 -0800217type feature interface {
218 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800219 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800220 flags(ctx ModuleContext, flags Flags) Flags
221 props() []interface{}
222}
223
224type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700225 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800226 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700227 compilerFlags(ctx ModuleContext, flags Flags) Flags
228 compilerProps() []interface{}
229
Colin Cross76fada02016-07-27 10:31:13 -0700230 appendCflags([]string)
231 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700232 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800233}
234
235type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700236 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800237 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700238 linkerFlags(ctx ModuleContext, flags Flags) Flags
239 linkerProps() []interface{}
240
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700241 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700242 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800243}
244
245type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700246 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700247 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800248 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700249 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700250 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800251}
252
Colin Crossc99deeb2016-04-11 15:06:20 -0700253type dependencyTag struct {
254 blueprint.BaseDependencyTag
255 name string
256 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700257
258 reexportFlags bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700259}
260
261var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700262 sharedDepTag = dependencyTag{name: "shared", library: true}
263 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
264 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
265 staticDepTag = dependencyTag{name: "static", library: true}
266 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
267 lateStaticDepTag = dependencyTag{name: "late static", library: true}
268 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800269 headerDepTag = dependencyTag{name: "header", library: true}
270 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700271 genSourceDepTag = dependencyTag{name: "gen source"}
272 genHeaderDepTag = dependencyTag{name: "gen header"}
273 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
274 objDepTag = dependencyTag{name: "obj"}
275 crtBeginDepTag = dependencyTag{name: "crtbegin"}
276 crtEndDepTag = dependencyTag{name: "crtend"}
277 reuseObjTag = dependencyTag{name: "reuse objects"}
278 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
279 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Colin Crossc99deeb2016-04-11 15:06:20 -0700280)
281
Colin Crossca860ac2016-01-04 14:34:37 -0800282// Module contains the properties and members used by all C/C++ module types, and implements
283// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
284// to construct the output file. Behavior can be customized with a Customizer interface
285type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700286 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700287 android.DefaultableModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700288
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700289 Properties BaseProperties
290 VendorProperties VendorProperties
291 unused UnusedProperties
Colin Crossfa138792015-04-24 17:31:52 -0700292
Colin Crossca860ac2016-01-04 14:34:37 -0800293 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700294 hod android.HostOrDeviceSupported
295 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700296
Colin Crossca860ac2016-01-04 14:34:37 -0800297 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700298 features []feature
299 compiler compiler
300 linker linker
301 installer installer
302 stl *stl
303 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800304 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800305 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900306 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700307 lto *lto
Colin Cross16b23492016-01-06 14:41:07 -0800308
309 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700310
Colin Cross635c3b02016-05-18 15:37:25 -0700311 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800312
Colin Crossb98c8b02016-07-29 13:44:28 -0700313 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700314
315 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800316
317 // Flags used to compile this module
318 flags Flags
Colin Crossc472d572015-03-17 15:06:21 -0700319}
320
Colin Cross36242852017-06-23 15:06:31 -0700321func (c *Module) Init() android.Module {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700322 c.AddProperties(&c.Properties, &c.VendorProperties, &c.unused)
Colin Crossca860ac2016-01-04 14:34:37 -0800323 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700324 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800325 }
326 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700327 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800328 }
329 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700330 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800331 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700332 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700333 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700334 }
Colin Cross16b23492016-01-06 14:41:07 -0800335 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700336 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800337 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800338 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700339 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800340 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800341 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700342 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800343 }
Justin Yun8effde42017-06-23 19:24:43 +0900344 if c.vndkdep != nil {
345 c.AddProperties(c.vndkdep.props()...)
346 }
Stephen Craneba090d12017-05-09 15:44:35 -0700347 if c.lto != nil {
348 c.AddProperties(c.lto.props()...)
349 }
Colin Crossca860ac2016-01-04 14:34:37 -0800350 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700351 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800352 }
Colin Crossc472d572015-03-17 15:06:21 -0700353
Colin Cross36242852017-06-23 15:06:31 -0700354 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700355
Colin Cross1f44a3a2017-07-07 14:33:33 -0700356 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700357
358 return c
Colin Crossc472d572015-03-17 15:06:21 -0700359}
360
Colin Crossb916a382016-07-29 17:28:03 -0700361// Returns true for dependency roots (binaries)
362// TODO(ccross): also handle dlopenable libraries
363func (c *Module) isDependencyRoot() bool {
364 if root, ok := c.linker.(interface {
365 isDependencyRoot() bool
366 }); ok {
367 return root.isDependencyRoot()
368 }
369 return false
370}
371
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700372func (c *Module) vndk() bool {
373 return c.Properties.UseVndk
374}
375
Justin Yun8effde42017-06-23 19:24:43 +0900376func (c *Module) isVndk() bool {
377 if c.vndkdep != nil {
378 return c.vndkdep.isVndk()
379 }
380 return false
381}
382
Colin Crossca860ac2016-01-04 14:34:37 -0800383type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700384 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800385 moduleContextImpl
386}
387
Colin Cross37047f12016-12-13 17:06:13 -0800388type depsContext struct {
389 android.BottomUpMutatorContext
390 moduleContextImpl
391}
392
Colin Crossca860ac2016-01-04 14:34:37 -0800393type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700394 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800395 moduleContextImpl
396}
397
Justin Yun8effde42017-06-23 19:24:43 +0900398// Vendor returns true for vendor modules excluding VNDK libraries so that
399// they get installed onto the correct partition
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700400func (ctx *moduleContext) Vendor() bool {
Justin Yun8effde42017-06-23 19:24:43 +0900401 return ctx.ModuleContext.Vendor() || (ctx.mod.vndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700402}
403
Colin Crossca860ac2016-01-04 14:34:37 -0800404type moduleContextImpl struct {
405 mod *Module
406 ctx BaseModuleContext
407}
408
Colin Crossca860ac2016-01-04 14:34:37 -0800409func (ctx *moduleContextImpl) clang() bool {
410 return ctx.mod.clang(ctx.ctx)
411}
412
Colin Crossb98c8b02016-07-29 13:44:28 -0700413func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800414 return ctx.mod.toolchain(ctx.ctx)
415}
416
417func (ctx *moduleContextImpl) static() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700418 if static, ok := ctx.mod.linker.(interface {
419 static() bool
420 }); ok {
421 return static.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800422 }
Colin Crossb916a382016-07-29 17:28:03 -0700423 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800424}
425
426func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700427 if static, ok := ctx.mod.linker.(interface {
428 staticBinary() bool
429 }); ok {
430 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800431 }
Colin Crossb916a382016-07-29 17:28:03 -0700432 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800433}
434
435func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
436 return Bool(ctx.mod.Properties.No_default_compiler_flags)
437}
438
439func (ctx *moduleContextImpl) sdk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700440 if ctx.ctx.Device() && !ctx.vndk() {
Dan Willemsena96ff642016-06-07 12:34:45 -0700441 return ctx.mod.Properties.Sdk_version != ""
442 }
443 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800444}
445
446func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700447 if ctx.ctx.Device() {
Dan Willemsen11b26142017-03-19 18:30:37 -0700448 if ctx.vndk() {
449 return "current"
Dan Willemsend2ede872016-11-18 14:54:24 -0800450 } else {
451 return ctx.mod.Properties.Sdk_version
452 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700453 }
454 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800455}
456
Dan Willemsend2ede872016-11-18 14:54:24 -0800457func (ctx *moduleContextImpl) vndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700458 return ctx.mod.vndk()
Dan Willemsend2ede872016-11-18 14:54:24 -0800459}
460
Justin Yun8effde42017-06-23 19:24:43 +0900461func (ctx *moduleContextImpl) isVndk() bool {
462 return ctx.mod.isVndk()
463}
464
465func (ctx *moduleContextImpl) isVndkSp() bool {
466 if vndk := ctx.mod.vndkdep; vndk != nil {
467 return vndk.isVndkSp()
468 }
469 return false
470}
471
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800472// Create source abi dumps if the module belongs to the list of VndkLibraries.
473func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
Jayant Chowdharya4fce192017-09-06 13:10:03 -0700474 return ctx.ctx.Device() && ((ctx.vndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800475}
476
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700477func (ctx *moduleContextImpl) selectedStl() string {
478 if stl := ctx.mod.stl; stl != nil {
479 return stl.Properties.SelectedStl
480 }
481 return ""
482}
483
Colin Crossce75d2c2016-10-06 16:12:58 -0700484func (ctx *moduleContextImpl) baseModuleName() string {
485 return ctx.mod.ModuleBase.BaseModuleName()
486}
487
Colin Cross635c3b02016-05-18 15:37:25 -0700488func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800489 return &Module{
490 hod: hod,
491 multilib: multilib,
492 }
493}
494
Colin Cross635c3b02016-05-18 15:37:25 -0700495func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800496 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700497 module.features = []feature{
498 &tidyFeature{},
499 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700500 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800501 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800502 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800503 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900504 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700505 module.lto = &lto{}
Colin Crossca860ac2016-01-04 14:34:37 -0800506 return module
507}
508
Colin Crossce75d2c2016-10-06 16:12:58 -0700509func (c *Module) Prebuilt() *android.Prebuilt {
510 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
511 return p.prebuilt()
512 }
513 return nil
514}
515
516func (c *Module) Name() string {
517 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700518 if p, ok := c.linker.(interface {
519 Name(string) string
520 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700521 name = p.Name(name)
522 }
523 return name
524}
525
Colin Cross635c3b02016-05-18 15:37:25 -0700526func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800527 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700528 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800529 moduleContextImpl: moduleContextImpl{
530 mod: c,
531 },
532 }
533 ctx.ctx = ctx
534
535 flags := Flags{
536 Toolchain: c.toolchain(ctx),
537 Clang: c.clang(ctx),
538 }
Colin Crossca860ac2016-01-04 14:34:37 -0800539 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700540 flags = c.compiler.compilerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800541 }
542 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700543 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800544 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700545 if c.stl != nil {
546 flags = c.stl.flags(ctx, flags)
547 }
Colin Cross16b23492016-01-06 14:41:07 -0800548 if c.sanitize != nil {
549 flags = c.sanitize.flags(ctx, flags)
550 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800551 if c.coverage != nil {
552 flags = c.coverage.flags(ctx, flags)
553 }
Stephen Craneba090d12017-05-09 15:44:35 -0700554 if c.lto != nil {
555 flags = c.lto.flags(ctx, flags)
556 }
Colin Crossca860ac2016-01-04 14:34:37 -0800557 for _, feature := range c.features {
558 flags = feature.flags(ctx, flags)
559 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800560 if ctx.Failed() {
561 return
562 }
563
Colin Crossb98c8b02016-07-29 13:44:28 -0700564 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
565 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
566 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800567
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800568 deps := c.depsToPaths(ctx)
569 if ctx.Failed() {
570 return
571 }
572 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
573 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700574 // We need access to all the flags seen by a source file.
575 if c.sabi != nil {
576 flags = c.sabi.flags(ctx, flags)
577 }
Colin Crossca860ac2016-01-04 14:34:37 -0800578 // Optimization to reduce size of build.ninja
579 // Replace the long list of flags for each file with a module-local variable
580 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
581 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
582 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
583 flags.CFlags = []string{"$cflags"}
584 flags.CppFlags = []string{"$cppflags"}
585 flags.AsFlags = []string{"$asflags"}
586
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700587 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800588 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700589 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800590 if ctx.Failed() {
591 return
592 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800593 }
594
Colin Crossca860ac2016-01-04 14:34:37 -0800595 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700596 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800597 if ctx.Failed() {
598 return
599 }
Colin Cross635c3b02016-05-18 15:37:25 -0700600 c.outputFile = android.OptionalPathForPath(outputFile)
Colin Crossce75d2c2016-10-06 16:12:58 -0700601 }
Colin Cross5049f022015-03-18 13:28:46 -0700602
Colin Crossce75d2c2016-10-06 16:12:58 -0700603 if c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid() {
604 c.installer.install(ctx, c.outputFile.Path())
605 if ctx.Failed() {
606 return
Colin Crossca860ac2016-01-04 14:34:37 -0800607 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700608 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800609}
610
Colin Crossb98c8b02016-07-29 13:44:28 -0700611func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800612 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700613 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800614 }
Colin Crossca860ac2016-01-04 14:34:37 -0800615 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800616}
617
Colin Crossca860ac2016-01-04 14:34:37 -0800618func (c *Module) begin(ctx BaseModuleContext) {
619 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700620 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700621 }
Colin Crossca860ac2016-01-04 14:34:37 -0800622 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700623 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800624 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700625 if c.stl != nil {
626 c.stl.begin(ctx)
627 }
Colin Cross16b23492016-01-06 14:41:07 -0800628 if c.sanitize != nil {
629 c.sanitize.begin(ctx)
630 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800631 if c.coverage != nil {
632 c.coverage.begin(ctx)
633 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800634 if c.sabi != nil {
635 c.sabi.begin(ctx)
636 }
Justin Yun8effde42017-06-23 19:24:43 +0900637 if c.vndkdep != nil {
638 c.vndkdep.begin(ctx)
639 }
Stephen Craneba090d12017-05-09 15:44:35 -0700640 if c.lto != nil {
641 c.lto.begin(ctx)
642 }
Colin Crossca860ac2016-01-04 14:34:37 -0800643 for _, feature := range c.features {
644 feature.begin(ctx)
645 }
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700646 if ctx.sdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700647 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700648 if err != nil {
649 ctx.PropertyErrorf("sdk_version", err.Error())
650 }
Dan Albert90f7a4d2016-11-08 14:34:24 -0800651 c.Properties.Sdk_version = version
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700652 }
Colin Crossca860ac2016-01-04 14:34:37 -0800653}
654
Colin Cross37047f12016-12-13 17:06:13 -0800655func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700656 deps := Deps{}
657
658 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700659 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700660 }
661 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700662 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700663 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700664 if c.stl != nil {
665 deps = c.stl.deps(ctx, deps)
666 }
Colin Cross16b23492016-01-06 14:41:07 -0800667 if c.sanitize != nil {
668 deps = c.sanitize.deps(ctx, deps)
669 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800670 if c.coverage != nil {
671 deps = c.coverage.deps(ctx, deps)
672 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800673 if c.sabi != nil {
674 deps = c.sabi.deps(ctx, deps)
675 }
Justin Yun8effde42017-06-23 19:24:43 +0900676 if c.vndkdep != nil {
677 deps = c.vndkdep.deps(ctx, deps)
678 }
Stephen Craneba090d12017-05-09 15:44:35 -0700679 if c.lto != nil {
680 deps = c.lto.deps(ctx, deps)
681 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700682 for _, feature := range c.features {
683 deps = feature.deps(ctx, deps)
684 }
685
686 deps.WholeStaticLibs = lastUniqueElements(deps.WholeStaticLibs)
687 deps.StaticLibs = lastUniqueElements(deps.StaticLibs)
688 deps.LateStaticLibs = lastUniqueElements(deps.LateStaticLibs)
689 deps.SharedLibs = lastUniqueElements(deps.SharedLibs)
690 deps.LateSharedLibs = lastUniqueElements(deps.LateSharedLibs)
Colin Cross5950f382016-12-13 12:50:57 -0800691 deps.HeaderLibs = lastUniqueElements(deps.HeaderLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700692
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700693 for _, lib := range deps.ReexportSharedLibHeaders {
694 if !inList(lib, deps.SharedLibs) {
695 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
696 }
697 }
698
699 for _, lib := range deps.ReexportStaticLibHeaders {
700 if !inList(lib, deps.StaticLibs) {
701 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
702 }
703 }
704
Colin Cross5950f382016-12-13 12:50:57 -0800705 for _, lib := range deps.ReexportHeaderLibHeaders {
706 if !inList(lib, deps.HeaderLibs) {
707 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
708 }
709 }
710
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700711 for _, gen := range deps.ReexportGeneratedHeaders {
712 if !inList(gen, deps.GeneratedHeaders) {
713 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
714 }
715 }
716
Colin Crossc99deeb2016-04-11 15:06:20 -0700717 return deps
718}
719
Dan Albert7e9d2952016-08-04 13:02:36 -0700720func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800721 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700722 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800723 moduleContextImpl: moduleContextImpl{
724 mod: c,
725 },
726 }
727 ctx.ctx = ctx
728
Colin Crossca860ac2016-01-04 14:34:37 -0800729 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -0700730}
731
Colin Cross1e676be2016-10-12 14:38:15 -0700732func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
733 if !c.Enabled() {
734 return
735 }
736
Colin Cross37047f12016-12-13 17:06:13 -0800737 ctx := &depsContext{
738 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -0700739 moduleContextImpl: moduleContextImpl{
740 mod: c,
741 },
742 }
743 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -0800744
Colin Crossc99deeb2016-04-11 15:06:20 -0700745 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800746
Dan Albert914449f2016-06-17 16:45:24 -0700747 variantNdkLibs := []string{}
748 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -0700749 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -0700750 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -0700751
Dan Albert914449f2016-06-17 16:45:24 -0700752 // Rewrites the names of shared libraries into the names of the NDK
753 // libraries where appropriate. This returns two slices.
754 //
755 // The first is a list of non-variant shared libraries (either rewritten
756 // NDK libraries to the modules in prebuilts/ndk, or not rewritten
757 // because they are not NDK libraries).
758 //
759 // The second is a list of ndk_library modules. These need to be
760 // separated because they are a variation dependency and must be added
761 // in a different manner.
762 rewriteNdkLibs := func(list []string) ([]string, []string) {
763 variantLibs := []string{}
764 nonvariantLibs := []string{}
765 for _, entry := range list {
Dan Willemsenb916b802017-03-19 13:44:32 -0700766 if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
Dan Albert914449f2016-06-17 16:45:24 -0700767 if !inList(entry, ndkMigratedLibs) {
768 nonvariantLibs = append(nonvariantLibs, entry+".ndk."+version)
769 } else {
770 variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
771 }
Jiyong Parkd5b18a52017-08-03 21:22:50 +0900772 } else if ctx.vndk() && inList(entry, llndkLibraries) {
Dan Willemsenb916b802017-03-19 13:44:32 -0700773 nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -0700774 } else {
Dan Willemsen7cbf5f82017-03-28 00:08:30 -0700775 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -0700776 }
777 }
Dan Albert914449f2016-06-17 16:45:24 -0700778 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -0700779 }
780
Dan Albert914449f2016-06-17 16:45:24 -0700781 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
782 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +0900783 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -0700784 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700785
Colin Cross32ec36c2016-12-15 07:39:51 -0800786 for _, lib := range deps.HeaderLibs {
787 depTag := headerDepTag
788 if inList(lib, deps.ReexportHeaderLibHeaders) {
789 depTag = headerExportDepTag
790 }
791 actx.AddVariationDependencies(nil, depTag, lib)
792 }
Colin Cross5950f382016-12-13 12:50:57 -0800793
Colin Crossc99deeb2016-04-11 15:06:20 -0700794 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, wholeStaticDepTag,
795 deps.WholeStaticLibs...)
796
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700797 for _, lib := range deps.StaticLibs {
798 depTag := staticDepTag
799 if inList(lib, deps.ReexportStaticLibHeaders) {
800 depTag = staticExportDepTag
801 }
Colin Cross15a0d462016-07-14 14:49:58 -0700802 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700803 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700804
805 actx.AddVariationDependencies([]blueprint.Variation{{"link", "static"}}, lateStaticDepTag,
806 deps.LateStaticLibs...)
807
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700808 for _, lib := range deps.SharedLibs {
809 depTag := sharedDepTag
810 if inList(lib, deps.ReexportSharedLibHeaders) {
811 depTag = sharedExportDepTag
812 }
Colin Cross15a0d462016-07-14 14:49:58 -0700813 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700814 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700815
816 actx.AddVariationDependencies([]blueprint.Variation{{"link", "shared"}}, lateSharedDepTag,
817 deps.LateSharedLibs...)
818
Colin Cross68861832016-07-08 10:41:41 -0700819 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700820
821 for _, gen := range deps.GeneratedHeaders {
822 depTag := genHeaderDepTag
823 if inList(gen, deps.ReexportGeneratedHeaders) {
824 depTag = genHeaderExportDepTag
825 }
826 actx.AddDependency(c, depTag, gen)
827 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700828
Colin Cross68861832016-07-08 10:41:41 -0700829 actx.AddDependency(c, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -0700830
831 if deps.CrtBegin != "" {
Colin Cross68861832016-07-08 10:41:41 -0700832 actx.AddDependency(c, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -0800833 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700834 if deps.CrtEnd != "" {
Colin Cross68861832016-07-08 10:41:41 -0700835 actx.AddDependency(c, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -0700836 }
Dan Albert914449f2016-06-17 16:45:24 -0700837
838 version := ctx.sdkVersion()
839 actx.AddVariationDependencies([]blueprint.Variation{
840 {"ndk_api", version}, {"link", "shared"}}, ndkStubDepTag, variantNdkLibs...)
841 actx.AddVariationDependencies([]blueprint.Variation{
842 {"ndk_api", version}, {"link", "shared"}}, ndkLateStubDepTag, variantLateNdkLibs...)
Colin Cross6362e272015-10-29 15:25:03 -0700843}
Colin Cross21b9a242015-03-24 14:15:58 -0700844
Dan Albert7e9d2952016-08-04 13:02:36 -0700845func beginMutator(ctx android.BottomUpMutatorContext) {
846 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
847 c.beginMutator(ctx)
848 }
849}
850
Colin Crossca860ac2016-01-04 14:34:37 -0800851func (c *Module) clang(ctx BaseModuleContext) bool {
852 clang := Bool(c.Properties.Clang)
853
854 if c.Properties.Clang == nil {
855 if ctx.Host() {
856 clang = true
857 }
858
859 if ctx.Device() && ctx.AConfig().DeviceUsesClang() {
860 clang = true
861 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800862 }
Colin Cross28344522015-04-22 13:07:53 -0700863
Colin Crossca860ac2016-01-04 14:34:37 -0800864 if !c.toolchain(ctx).ClangSupported() {
865 clang = false
866 }
867
868 return clang
869}
870
Colin Crossc99deeb2016-04-11 15:06:20 -0700871// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -0700872func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -0800873 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -0800874
Dan Willemsena96ff642016-06-07 12:34:45 -0700875 // Whether a module can link to another module, taking into
876 // account NDK linking.
Dan Albert9e10cd42016-08-03 14:12:14 -0700877 checkLinkType := func(from, to *Module) {
Dan Willemsena96ff642016-06-07 12:34:45 -0700878 if from.Target().Os != android.Android {
879 // Host code is not restricted
Dan Albert9e10cd42016-08-03 14:12:14 -0700880 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700881 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700882 if from.Properties.UseVndk {
Justin Yun8effde42017-06-23 19:24:43 +0900883 // Though vendor code is limited by the vendor mutator,
884 // each vendor-available module needs to check
885 // link-type for VNDK.
886 if from.vndkdep != nil {
887 from.vndkdep.vndkCheckLinkType(ctx, to)
888 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700889 return
890 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700891 if from.Properties.Sdk_version == "" {
892 // Platform code can link to anything
Dan Albert9e10cd42016-08-03 14:12:14 -0700893 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700894 }
Colin Crossb916a382016-07-29 17:28:03 -0700895 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
Dan Willemsena96ff642016-06-07 12:34:45 -0700896 // These are always allowed
Dan Albert9e10cd42016-08-03 14:12:14 -0700897 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700898 }
899 if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
900 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700901 return
Dan Willemsena96ff642016-06-07 12:34:45 -0700902 }
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700903 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
904 // These are allowed, but don't set sdk_version
Dan Albert9e10cd42016-08-03 14:12:14 -0700905 return
Dan Willemsen3c316bc2016-07-07 20:41:36 -0700906 }
Colin Crossb916a382016-07-29 17:28:03 -0700907 if _, ok := to.linker.(*stubDecorator); ok {
Dan Albert914449f2016-06-17 16:45:24 -0700908 // These aren't real libraries, but are the stub shared libraries that are included in
909 // the NDK.
Dan Albert9e10cd42016-08-03 14:12:14 -0700910 return
Dan Albert914449f2016-06-17 16:45:24 -0700911 }
Dan Albert9e10cd42016-08-03 14:12:14 -0700912 if to.Properties.Sdk_version == "" {
913 // NDK code linking to platform code is never okay.
914 ctx.ModuleErrorf("depends on non-NDK-built library %q",
915 ctx.OtherModuleName(to))
916 }
917
918 // All this point we know we have two NDK libraries, but we need to
919 // check that we're not linking against anything built against a higher
920 // API level, as it is only valid to link against older or equivalent
921 // APIs.
922
923 if from.Properties.Sdk_version == "current" {
924 // Current can link against anything.
925 return
926 } else if to.Properties.Sdk_version == "current" {
927 // Current can't be linked against by anything else.
928 ctx.ModuleErrorf("links %q built against newer API version %q",
929 ctx.OtherModuleName(to), "current")
930 }
931
932 fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
933 if err != nil {
934 ctx.PropertyErrorf("sdk_version",
935 "Invalid sdk_version value (must be int): %q",
936 from.Properties.Sdk_version)
937 }
938 toApi, err := strconv.Atoi(to.Properties.Sdk_version)
939 if err != nil {
940 ctx.PropertyErrorf("sdk_version",
941 "Invalid sdk_version value (must be int): %q",
942 to.Properties.Sdk_version)
943 }
944
945 if toApi > fromApi {
946 ctx.ModuleErrorf("links %q built against newer API version %q",
947 ctx.OtherModuleName(to), to.Properties.Sdk_version)
948 }
Dan Willemsena96ff642016-06-07 12:34:45 -0700949 }
950
Colin Crossc99deeb2016-04-11 15:06:20 -0700951 ctx.VisitDirectDeps(func(m blueprint.Module) {
952 name := ctx.OtherModuleName(m)
953 tag := ctx.OtherModuleDependencyTag(m)
Colin Crossca860ac2016-01-04 14:34:37 -0800954
Colin Cross635c3b02016-05-18 15:37:25 -0700955 a, _ := m.(android.Module)
Colin Crossc99deeb2016-04-11 15:06:20 -0700956 if a == nil {
957 ctx.ModuleErrorf("module %q not an android module", name)
958 return
Colin Crossca860ac2016-01-04 14:34:37 -0800959 }
Colin Crossca860ac2016-01-04 14:34:37 -0800960
Dan Willemsena96ff642016-06-07 12:34:45 -0700961 cc, _ := m.(*Module)
962 if cc == nil {
Dan Willemsenb40aab62016-04-20 14:21:14 -0700963 switch tag {
Colin Cross068e0fe2016-12-13 15:23:47 -0800964 case android.DefaultsDepTag, android.SourceDepTag:
Dan Willemsend6ba0d52017-09-13 15:46:47 -0700965 // Nothing to do
Dan Willemsenb40aab62016-04-20 14:21:14 -0700966 case genSourceDepTag:
967 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
968 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
969 genRule.GeneratedSourceFiles()...)
970 } else {
971 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
972 }
Colin Crosse90bfd12017-04-26 16:59:26 -0700973 // Support exported headers from a generated_sources dependency
974 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700975 case genHeaderDepTag, genHeaderExportDepTag:
Dan Willemsenb40aab62016-04-20 14:21:14 -0700976 if genRule, ok := m.(genrule.SourceFileGenerator); ok {
977 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
978 genRule.GeneratedSourceFiles()...)
Colin Cross5ed99c62016-11-22 12:55:55 -0800979 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700980 depPaths.Flags = append(depPaths.Flags, flags)
981 if tag == genHeaderExportDepTag {
982 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -0700983 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
984 genRule.GeneratedSourceFiles()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -0700985 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
986 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
987
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700988 }
Dan Willemsenb40aab62016-04-20 14:21:14 -0700989 } else {
990 ctx.ModuleErrorf("module %q is not a genrule", name)
991 }
992 default:
Colin Crossc99deeb2016-04-11 15:06:20 -0700993 ctx.ModuleErrorf("depends on non-cc module %q", name)
Colin Crossca860ac2016-01-04 14:34:37 -0800994 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700995 return
996 }
997
998 if !a.Enabled() {
Colin Crossa8f5e9a2016-12-13 12:51:11 -0800999 if ctx.AConfig().AllowMissingDependencies() {
1000 ctx.AddMissingDependencies([]string{name})
1001 } else {
1002 ctx.ModuleErrorf("depends on disabled module %q", name)
1003 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001004 return
1005 }
1006
Colin Crossa1ad8d12016-06-01 17:09:44 -07001007 if a.Target().Os != ctx.Os() {
1008 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
1009 return
1010 }
1011
1012 if a.Target().Arch.ArchType != ctx.Arch().ArchType {
1013 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001014 return
1015 }
1016
Colin Crossc99deeb2016-04-11 15:06:20 -07001017 if tag == reuseObjTag {
Colin Crossbba99042016-11-23 15:45:05 -08001018 if l, ok := cc.compiler.(libraryInterface); ok {
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001019 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001020 depPaths.Objs = depPaths.Objs.Append(objs)
1021 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001022 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001023 return
1024 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001025 }
1026
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001027 if t, ok := tag.(dependencyTag); ok && t.library {
Dan Willemsena96ff642016-06-07 12:34:45 -07001028 if i, ok := cc.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001029 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001030 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001031 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001032 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001033
1034 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001035 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001036 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001037 // 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 -07001038 // Re-exported shared library headers must be included as well since they can help us with type information
1039 // about template instantiations (instantiated from their headers).
1040 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001041 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001042 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001043
Dan Albert9e10cd42016-08-03 14:12:14 -07001044 checkLinkType(c, cc)
Colin Crossc99deeb2016-04-11 15:06:20 -07001045 }
1046
Colin Cross26c34ed2016-09-30 17:10:16 -07001047 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001048 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001049
Colin Cross26c34ed2016-09-30 17:10:16 -07001050 linkFile := cc.outputFile
1051 depFile := android.OptionalPath{}
1052
Colin Crossc99deeb2016-04-11 15:06:20 -07001053 switch tag {
Dan Albert914449f2016-06-17 16:45:24 -07001054 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001055 ptr = &depPaths.SharedLibs
1056 depPtr = &depPaths.SharedLibsDeps
1057 depFile = cc.linker.(libraryInterface).toc()
Dan Albert914449f2016-06-17 16:45:24 -07001058 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001059 ptr = &depPaths.LateSharedLibs
1060 depPtr = &depPaths.LateSharedLibsDeps
1061 depFile = cc.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001062 case staticDepTag, staticExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001063 ptr = &depPaths.StaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001064 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001065 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001066 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001067 ptr = &depPaths.WholeStaticLibs
Colin Crossb916a382016-07-29 17:28:03 -07001068 staticLib, ok := cc.linker.(libraryInterface)
1069 if !ok || !staticLib.static() {
Dan Willemsena96ff642016-06-07 12:34:45 -07001070 ctx.ModuleErrorf("module %q not a static library", name)
Colin Crossc99deeb2016-04-11 15:06:20 -07001071 return
1072 }
1073
1074 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
1075 postfix := " (required by " + ctx.OtherModuleName(m) + ")"
1076 for i := range missingDeps {
1077 missingDeps[i] += postfix
1078 }
1079 ctx.AddMissingDependencies(missingDeps)
1080 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001081 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001082 case headerDepTag:
1083 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001084 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001085 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001086 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001087 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001088 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001089 depPaths.CrtEnd = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001090 }
1091
Dan Willemsen581341d2017-02-09 16:16:31 -08001092 switch tag {
1093 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1094 staticLib, ok := cc.linker.(libraryInterface)
1095 if !ok || !staticLib.static() {
1096 ctx.ModuleErrorf("module %q not a static library", name)
1097 return
1098 }
1099
1100 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001101 // in static libraries act as if they were whole static libraries. The same goes for
1102 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001103 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1104 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001105 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1106 staticLib.objs().sAbiDumpFiles...)
Dan Willemsen581341d2017-02-09 16:16:31 -08001107 }
1108
Colin Cross26c34ed2016-09-30 17:10:16 -07001109 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001110 if !linkFile.Valid() {
1111 ctx.ModuleErrorf("module %q missing output file", name)
1112 return
1113 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001114 *ptr = append(*ptr, linkFile.Path())
1115 }
1116
Colin Crossc99deeb2016-04-11 15:06:20 -07001117 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001118 dep := depFile
1119 if !dep.Valid() {
1120 dep = linkFile
1121 }
1122 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001123 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001124
1125 // Export the shared libs to the make world. In doing so, .vendor suffix
1126 // is added if the lib has both core and vendor variants and this module
1127 // is building against vndk. This is because the vendor variant will be
1128 // have .vendor suffix in its name in the make world. However, if the
1129 // lib is a vendor-only lib or this lib is not building against vndk,
1130 // then the suffix is not added.
1131 switch tag {
1132 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
1133 libName := strings.TrimSuffix(name, llndkLibrarySuffix)
1134 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001135 isLLndk := inList(libName, llndkLibraries)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001136 if c.vndk() && (Bool(cc.VendorProperties.Vendor_available) || isLLndk) {
Jiyong Park27b188b2017-07-18 13:23:39 +09001137 libName += vendorSuffix
1138 }
1139 // Note: the order of libs in this list is not important because
1140 // they merely serve as dependencies in the make world and do not
1141 // affect this lib itself.
1142 c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, libName)
1143 }
Colin Crossca860ac2016-01-04 14:34:37 -08001144 })
1145
Colin Crossdd84e052017-05-17 13:44:16 -07001146 // Dedup exported flags from dependencies
1147 depPaths.Flags = firstUniqueElements(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001148 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
1149 depPaths.ReexportedFlags = firstUniqueElements(depPaths.ReexportedFlags)
1150 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1151
1152 if c.sabi != nil {
1153 c.sabi.Properties.ReexportedIncludeFlags = firstUniqueElements(c.sabi.Properties.ReexportedIncludeFlags)
1154 }
Colin Crossdd84e052017-05-17 13:44:16 -07001155
Colin Crossca860ac2016-01-04 14:34:37 -08001156 return depPaths
1157}
1158
1159func (c *Module) InstallInData() bool {
1160 if c.installer == nil {
1161 return false
1162 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001163 return c.installer.inData()
1164}
1165
1166func (c *Module) InstallInSanitizerDir() bool {
1167 if c.installer == nil {
1168 return false
1169 }
1170 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001171 return true
1172 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001173 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001174}
1175
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001176func (c *Module) HostToolPath() android.OptionalPath {
1177 if c.installer == nil {
1178 return android.OptionalPath{}
1179 }
1180 return c.installer.hostToolPath()
1181}
1182
Nan Zhangd4e641b2017-07-12 12:55:28 -07001183func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1184 return c.outputFile
1185}
1186
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001187func (c *Module) Srcs() android.Paths {
1188 if c.outputFile.Valid() {
1189 return android.Paths{c.outputFile.Path()}
1190 }
1191 return android.Paths{}
1192}
1193
Colin Cross2ba19d92015-05-07 15:44:20 -07001194//
Colin Crosscfad1192015-11-02 16:43:11 -08001195// Defaults
1196//
Colin Crossca860ac2016-01-04 14:34:37 -08001197type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001198 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001199 android.DefaultsModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001200}
1201
Colin Cross635c3b02016-05-18 15:37:25 -07001202func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001203}
1204
Colin Cross1e676be2016-10-12 14:38:15 -07001205func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1206}
1207
Colin Cross36242852017-06-23 15:06:31 -07001208func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001209 return DefaultsFactory()
1210}
1211
Colin Cross36242852017-06-23 15:06:31 -07001212func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001213 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001214
Colin Cross36242852017-06-23 15:06:31 -07001215 module.AddProperties(props...)
1216 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001217 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001218 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001219 &BaseCompilerProperties{},
1220 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001221 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001222 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001223 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001224 &TestProperties{},
1225 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001226 &UnusedProperties{},
1227 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001228 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001229 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001230 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001231 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001232 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001233 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001234 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001235 &LTOProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001236 )
Colin Crosscfad1192015-11-02 16:43:11 -08001237
Colin Cross1f44a3a2017-07-07 14:33:33 -07001238 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001239
1240 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001241}
1242
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001243const (
1244 // coreMode is the variant used for framework-private libraries, or
1245 // SDK libraries. (which framework-private libraries can use)
1246 coreMode = "core"
1247
1248 // vendorMode is the variant used for /vendor code that compiles
1249 // against the VNDK.
1250 vendorMode = "vendor"
1251)
1252
1253func vendorMutator(mctx android.BottomUpMutatorContext) {
1254 if mctx.Os() != android.Android {
1255 return
1256 }
1257
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001258 if genrule, ok := mctx.Module().(*genrule.Module); ok {
1259 if props, ok := genrule.Extra.(*VendorProperties); ok {
1260 if !mctx.DeviceConfig().CompileVndk() {
1261 mctx.CreateVariations(coreMode)
1262 } else if Bool(props.Vendor_available) {
1263 mctx.CreateVariations(coreMode, vendorMode)
1264 } else if mctx.Vendor() {
1265 mctx.CreateVariations(vendorMode)
1266 } else {
1267 mctx.CreateVariations(coreMode)
1268 }
1269 }
1270 }
1271
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001272 m, ok := mctx.Module().(*Module)
1273 if !ok {
1274 return
1275 }
1276
1277 // Sanity check
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001278 if Bool(m.VendorProperties.Vendor_available) && mctx.Vendor() {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001279 mctx.PropertyErrorf("vendor_available",
1280 "doesn't make sense at the same time as `vendor: true` or `proprietary: true`")
1281 return
1282 }
Justin Yun8effde42017-06-23 19:24:43 +09001283 if vndk := m.vndkdep; vndk != nil {
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001284 if vndk.isVndk() && !Bool(m.VendorProperties.Vendor_available) {
Justin Yun8effde42017-06-23 19:24:43 +09001285 mctx.PropertyErrorf("vndk",
1286 "has to define `vendor_available: true` to enable vndk")
1287 return
1288 }
1289 if !vndk.isVndk() && vndk.isVndkSp() {
1290 mctx.PropertyErrorf("vndk",
1291 "must set `enabled: true` to set `support_system_process: true`")
1292 return
1293 }
1294 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001295
1296 if !mctx.DeviceConfig().CompileVndk() {
1297 // If the device isn't compiling against the VNDK, we always
1298 // use the core mode.
1299 mctx.CreateVariations(coreMode)
1300 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1301 // LL-NDK stubs only exist in the vendor variant, since the
1302 // real libraries will be used in the core variant.
1303 mctx.CreateVariations(vendorMode)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001304 } else if Bool(m.VendorProperties.Vendor_available) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001305 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001306 // or a /system directory that is available to vendor.
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001307 mod := mctx.CreateVariations(coreMode, vendorMode)
1308 mod[1].(*Module).Properties.UseVndk = true
1309 } else if mctx.Vendor() && m.Properties.Sdk_version == "" {
1310 // This will be available in /vendor only
1311 mod := mctx.CreateVariations(vendorMode)
1312 mod[0].(*Module).Properties.UseVndk = true
1313 } else {
1314 // This is either in /system (or similar: /data), or is a
1315 // modules built with the NDK. Modules built with the NDK
1316 // will be restricted using the existing link type checks.
1317 mctx.CreateVariations(coreMode)
1318 }
1319}
1320
Colin Crossdd84e052017-05-17 13:44:16 -07001321// firstUniqueElements returns all unique elements of a slice, keeping the first copy of each
1322// modifies the slice contents in place, and returns a subslice of the original slice
1323func firstUniqueElements(list []string) []string {
1324 k := 0
1325outer:
1326 for i := 0; i < len(list); i++ {
1327 for j := 0; j < k; j++ {
1328 if list[i] == list[j] {
1329 continue outer
1330 }
1331 }
1332 list[k] = list[i]
1333 k++
1334 }
1335 return list[:k]
1336}
1337
Colin Cross74d1ec02015-04-28 13:30:13 -07001338// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
1339// modifies the slice contents in place, and returns a subslice of the original slice
1340func lastUniqueElements(list []string) []string {
1341 totalSkip := 0
1342 for i := len(list) - 1; i >= totalSkip; i-- {
1343 skip := 0
1344 for j := i - 1; j >= totalSkip; j-- {
1345 if list[i] == list[j] {
1346 skip++
1347 } else {
1348 list[j+skip] = list[j]
1349 }
1350 }
1351 totalSkip += skip
1352 }
1353 return list[totalSkip:]
1354}
Colin Cross06a931b2015-10-28 17:23:31 -07001355
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07001356func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
1357 if ctx.AConfig().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
1358 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
1359 }
1360 return ctx.AConfig().PlatformSdkVersion()
1361}
1362
Colin Cross06a931b2015-10-28 17:23:31 -07001363var Bool = proptools.Bool