blob: 4717b726d962fd712bbc2f5df179c798da86a04f [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) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090037 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070038 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090042 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070043 ctx.BottomUp("begin", BeginMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070044 })
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross1e676be2016-10-12 14:38:15 -070046 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
48 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070050 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
51 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
52
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000053 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
54 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
55
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080056 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
57 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
58
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
60 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080061
Colin Cross6b753602018-06-21 13:03:07 -070062 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090063 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080064
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000065 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080066 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070067
68 ctx.TopDown("lto_deps", ltoDepsMutator)
69 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070070 })
Colin Crossb98c8b02016-07-29 13:44:28 -070071
72 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070073}
74
Colin Crossca860ac2016-01-04 14:34:37 -080075type Deps struct {
76 SharedLibs, LateSharedLibs []string
77 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080078 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080079 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070080
Colin Cross5950f382016-12-13 12:50:57 -080081 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070082
Colin Cross81413472016-04-11 14:37:39 -070083 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070084
Dan Willemsenb40aab62016-04-20 14:21:14 -070085 GeneratedSources []string
86 GeneratedHeaders []string
87
Dan Willemsenb3454ab2016-09-28 17:34:58 -070088 ReexportGeneratedHeaders []string
89
Colin Cross97ba0732015-03-23 17:50:24 -070090 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070091
92 // Used for host bionic
93 LinkerFlagsFile string
94 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070095}
96
Colin Crossca860ac2016-01-04 14:34:37 -080097type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070098 // Paths to .so files
99 SharedLibs, LateSharedLibs android.Paths
100 // Paths to the dependencies to use for .so files (.so.toc files)
101 SharedLibsDeps, LateSharedLibsDeps android.Paths
102 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700103 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700106 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800107 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700108 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700109
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700111 GeneratedSources android.Paths
112 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700113
Dan Willemsen76f08272016-07-09 00:14:08 -0700114 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700115 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116
Colin Cross26c34ed2016-09-30 17:10:16 -0700117 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700118 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Path to the file container flags to use with the linker
121 LinkerFlagsFile android.OptionalPath
122
123 // Path to the dynamic linker binary
124 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125}
126
Colin Crossca860ac2016-01-04 14:34:37 -0800127type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700128 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
129 ArFlags []string // Flags that apply to ar
130 AsFlags []string // Flags that apply to assembly source files
131 CFlags []string // Flags that apply to C and C++ source files
132 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
133 ConlyFlags []string // Flags that apply to C source files
134 CppFlags []string // Flags that apply to C++ source files
135 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
136 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700137 aidlFlags []string // Flags that apply to aidl source files
138 rsFlags []string // Flags that apply to renderscript source files
139 LdFlags []string // Flags that apply to linker command lines
140 libFlags []string // Flags to add libraries early to the link order
141 TidyFlags []string // Flags that apply to clang-tidy
142 SAbiFlags []string // Flags that apply to header-abi-dumper
143 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700144
Colin Crossc3199482017-03-30 15:03:04 -0700145 // Global include flags that apply to C, C++, and assembly source files
146 // These must be after any module include flags, which will be in GlobalFlags.
147 SystemIncludeFlags []string
148
Colin Crossb98c8b02016-07-29 13:44:28 -0700149 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700150 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800151 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800152 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800153
154 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800155 DynamicLinker string
156
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700157 CFlagsDeps android.Paths // Files depended on by compiler flags
158 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800159
160 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800161
162 protoDeps android.Paths
163 protoFlags []string // Flags that apply to proto source files
164 protoOutTypeFlag string // The output type, --cpp_out for example
165 protoOutParams []string // Flags that modify the output of proto generated files
166 protoC bool // Whether to use C instead of C++
167 protoOptionsFile bool // Whether to look for a .options file next to the .proto
168 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700169}
170
Colin Cross81413472016-04-11 14:37:39 -0700171type ObjectLinkerProperties struct {
172 // names of other cc_object modules to link into this module using partial linking
173 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700174
175 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800176 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700177}
178
Colin Crossca860ac2016-01-04 14:34:37 -0800179// Properties used to compile all C or C++ modules
180type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700181 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800182 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700183
184 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800185 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700186
Jiyong Parkde866cb2018-12-07 23:08:36 +0900187 AndroidMkSharedLibs []string `blueprint:"mutated"`
188 AndroidMkStaticLibs []string `blueprint:"mutated"`
189 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
190 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
191 HideFromMake bool `blueprint:"mutated"`
192 PreventInstall bool `blueprint:"mutated"`
193 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700194
195 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800196
197 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
198 // file
199 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900200
201 // Make this module available when building for recovery
202 Recovery_available *bool
203
204 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900205
206 // Allows this module to use non-APEX version of libraries. Useful
207 // for building binaries that are started before APEXes are activated.
208 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700209}
210
211type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900212 // whether this module should be allowed to be directly depended by other
213 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
214 // If set to true, two variants will be built separately, one like
215 // normal, and the other limited to the set of libraries and headers
216 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700217 //
218 // The vendor variant may be used with a different (newer) /system,
219 // so it shouldn't have any unversioned runtime dependencies, or
220 // make assumptions about the system that may not be true in the
221 // future.
222 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900223 // If set to false, this module becomes inaccessible from /vendor modules.
224 //
225 // Default value is true when vndk: {enabled: true} or vendor: true.
226 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700227 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
228 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900229
230 // whether this module is capable of being loaded with other instance
231 // (possibly an older version) of the same module in the same process.
232 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
233 // can be double loaded in a vendor process if the library is also a
234 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
235 // explicitly marked as `double_loadable: true` by the owner, or the dependency
236 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
237 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800238}
239
Colin Crossca860ac2016-01-04 14:34:37 -0800240type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800241 static() bool
242 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700243 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700244 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800245 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700246 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900247 isVndk() bool
248 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800249 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900250 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800251 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700252 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700253 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800254 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800255 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800256 useClangLld(actx ModuleContext) bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900257 isApex() bool
Jiyong Parkb0788572018-12-20 22:10:17 +0900258 hasStubsVariants() bool
259 isStubs() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800260}
261
262type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700263 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800264 ModuleContextIntf
265}
266
267type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700268 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800269 ModuleContextIntf
270}
271
Colin Cross37047f12016-12-13 17:06:13 -0800272type DepsContext interface {
273 android.BottomUpMutatorContext
274 ModuleContextIntf
275}
276
Colin Crossca860ac2016-01-04 14:34:37 -0800277type feature interface {
278 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800279 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800280 flags(ctx ModuleContext, flags Flags) Flags
281 props() []interface{}
282}
283
284type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700285 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800286 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800287 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700288 compilerProps() []interface{}
289
Colin Cross76fada02016-07-27 10:31:13 -0700290 appendCflags([]string)
291 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700292 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800293}
294
295type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700296 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800297 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700298 linkerFlags(ctx ModuleContext, flags Flags) Flags
299 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800300 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700301
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700302 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700303 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800304}
305
306type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700307 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700308 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800309 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700310 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700311 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800312}
313
Colin Crossc99deeb2016-04-11 15:06:20 -0700314type dependencyTag struct {
315 blueprint.BaseDependencyTag
316 name string
317 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700318
319 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900320
321 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700322}
323
324var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700325 sharedDepTag = dependencyTag{name: "shared", library: true}
326 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
327 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
328 staticDepTag = dependencyTag{name: "static", library: true}
329 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
330 lateStaticDepTag = dependencyTag{name: "late static", library: true}
331 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800332 headerDepTag = dependencyTag{name: "header", library: true}
333 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700334 genSourceDepTag = dependencyTag{name: "gen source"}
335 genHeaderDepTag = dependencyTag{name: "gen header"}
336 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
337 objDepTag = dependencyTag{name: "obj"}
338 crtBeginDepTag = dependencyTag{name: "crtbegin"}
339 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700340 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
341 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700342 reuseObjTag = dependencyTag{name: "reuse objects"}
343 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
344 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800345 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800346 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700347)
348
Colin Crossca860ac2016-01-04 14:34:37 -0800349// Module contains the properties and members used by all C/C++ module types, and implements
350// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
351// to construct the output file. Behavior can be customized with a Customizer interface
352type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700353 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700354 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900355 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700356
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700357 Properties BaseProperties
358 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700359
Colin Crossca860ac2016-01-04 14:34:37 -0800360 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700361 hod android.HostOrDeviceSupported
362 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700363
Colin Crossca860ac2016-01-04 14:34:37 -0800364 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700365 features []feature
366 compiler compiler
367 linker linker
368 installer installer
369 stl *stl
370 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800371 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800372 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900373 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700374 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700375 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800376 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800377
378 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700379
Colin Cross635c3b02016-05-18 15:37:25 -0700380 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800381
Colin Crossb98c8b02016-07-29 13:44:28 -0700382 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700383
384 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800385
386 // Flags used to compile this module
387 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700388
389 // When calling a linker, if module A depends on module B, then A must precede B in its command
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800390 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700391 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800392 depsInLinkOrder android.Paths
393
394 // only non-nil when this is a shared library that reuses the objects of a static library
395 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700396}
397
Jiyong Parkc20eee32018-09-05 22:36:17 +0900398func (c *Module) OutputFile() android.OptionalPath {
399 return c.outputFile
400}
401
Colin Cross36242852017-06-23 15:06:31 -0700402func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700403 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800404 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700405 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800406 }
407 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700408 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800409 }
410 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700411 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800412 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700413 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700414 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700415 }
Colin Cross16b23492016-01-06 14:41:07 -0800416 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700417 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800418 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800419 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700420 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800421 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800422 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700423 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800424 }
Justin Yun8effde42017-06-23 19:24:43 +0900425 if c.vndkdep != nil {
426 c.AddProperties(c.vndkdep.props()...)
427 }
Stephen Craneba090d12017-05-09 15:44:35 -0700428 if c.lto != nil {
429 c.AddProperties(c.lto.props()...)
430 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700431 if c.pgo != nil {
432 c.AddProperties(c.pgo.props()...)
433 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800434 if c.xom != nil {
435 c.AddProperties(c.xom.props()...)
436 }
Colin Crossca860ac2016-01-04 14:34:37 -0800437 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700438 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800439 }
Colin Crossc472d572015-03-17 15:06:21 -0700440
Colin Crossa9d8bee2018-10-02 13:59:46 -0700441 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
442 switch class {
443 case android.Device:
444 return ctx.Config().DevicePrefer32BitExecutables()
445 case android.HostCross:
446 // Windows builds always prefer 32-bit
447 return true
448 default:
449 return false
450 }
451 })
Colin Cross36242852017-06-23 15:06:31 -0700452 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700453
Colin Cross1f44a3a2017-07-07 14:33:33 -0700454 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700455
Jiyong Park9d452992018-10-03 00:38:19 +0900456 android.InitApexModule(c)
457
Colin Cross36242852017-06-23 15:06:31 -0700458 return c
Colin Crossc472d572015-03-17 15:06:21 -0700459}
460
Colin Crossb916a382016-07-29 17:28:03 -0700461// Returns true for dependency roots (binaries)
462// TODO(ccross): also handle dlopenable libraries
463func (c *Module) isDependencyRoot() bool {
464 if root, ok := c.linker.(interface {
465 isDependencyRoot() bool
466 }); ok {
467 return root.isDependencyRoot()
468 }
469 return false
470}
471
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700472func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700473 return c.Properties.UseVndk
474}
475
Justin Yun8effde42017-06-23 19:24:43 +0900476func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800477 if vndkdep := c.vndkdep; vndkdep != nil {
478 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900479 }
480 return false
481}
482
Yi Kong7e53c572018-02-14 18:16:12 +0800483func (c *Module) isPgoCompile() bool {
484 if pgo := c.pgo; pgo != nil {
485 return pgo.Properties.PgoCompile
486 }
487 return false
488}
489
Logan Chienf3511742017-10-31 18:04:35 +0800490func (c *Module) isVndkSp() bool {
491 if vndkdep := c.vndkdep; vndkdep != nil {
492 return vndkdep.isVndkSp()
493 }
494 return false
495}
496
497func (c *Module) isVndkExt() bool {
498 if vndkdep := c.vndkdep; vndkdep != nil {
499 return vndkdep.isVndkExt()
500 }
501 return false
502}
503
504func (c *Module) getVndkExtendsModuleName() string {
505 if vndkdep := c.vndkdep; vndkdep != nil {
506 return vndkdep.getVndkExtendsModuleName()
507 }
508 return ""
509}
510
Jiyong Park82e2bf32017-08-16 14:05:54 +0900511// Returns true only when this module is configured to have core and vendor
512// variants.
513func (c *Module) hasVendorVariant() bool {
514 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
515}
516
Jiyong Parkf9332f12018-02-01 00:54:12 +0900517func (c *Module) inRecovery() bool {
518 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
519}
520
521func (c *Module) onlyInRecovery() bool {
522 return c.ModuleBase.InstallInRecovery()
523}
524
Jiyong Park25fc6a92018-11-18 18:02:45 +0900525func (c *Module) IsStubs() bool {
526 if library, ok := c.linker.(*libraryDecorator); ok {
527 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900528 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
529 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900530 }
531 return false
532}
533
534func (c *Module) HasStubsVariants() bool {
535 if library, ok := c.linker.(*libraryDecorator); ok {
536 return len(library.Properties.Stubs.Versions) > 0
537 }
538 return false
539}
540
Colin Crossca860ac2016-01-04 14:34:37 -0800541type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700542 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800543 moduleContextImpl
544}
545
Colin Cross37047f12016-12-13 17:06:13 -0800546type depsContext struct {
547 android.BottomUpMutatorContext
548 moduleContextImpl
549}
550
Colin Crossca860ac2016-01-04 14:34:37 -0800551type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700552 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800553 moduleContextImpl
554}
555
Jiyong Park2db76922017-11-08 16:03:48 +0900556func (ctx *moduleContext) SocSpecific() bool {
557 return ctx.ModuleContext.SocSpecific() ||
558 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700559}
560
Colin Crossca860ac2016-01-04 14:34:37 -0800561type moduleContextImpl struct {
562 mod *Module
563 ctx BaseModuleContext
564}
565
Colin Crossb98c8b02016-07-29 13:44:28 -0700566func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800567 return ctx.mod.toolchain(ctx.ctx)
568}
569
570func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000571 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800572}
573
574func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900575 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800576}
577
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700578func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900579 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800580 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700581 }
582 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800583}
584
585func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700586 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700587 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900588 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700589 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900590 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
591 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
592 return "current"
593 }
594 return platform_vndk_ver
595 }
596 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800597 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900598 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700599 }
600 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800601}
602
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700603func (ctx *moduleContextImpl) useVndk() bool {
604 return ctx.mod.useVndk()
605}
Justin Yun8effde42017-06-23 19:24:43 +0900606
Logan Chienf3511742017-10-31 18:04:35 +0800607func (ctx *moduleContextImpl) isVndk() bool {
608 return ctx.mod.isVndk()
609}
610
Yi Kong7e53c572018-02-14 18:16:12 +0800611func (ctx *moduleContextImpl) isPgoCompile() bool {
612 return ctx.mod.isPgoCompile()
613}
614
Justin Yun8effde42017-06-23 19:24:43 +0900615func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800616 return ctx.mod.isVndkSp()
617}
618
619func (ctx *moduleContextImpl) isVndkExt() bool {
620 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900621}
622
Jiyong Parkf9332f12018-02-01 00:54:12 +0900623func (ctx *moduleContextImpl) inRecovery() bool {
624 return ctx.mod.inRecovery()
625}
626
Logan Chien2f2b8902018-07-10 15:01:19 +0800627// Check whether ABI dumps should be created for this module.
628func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
629 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
630 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800631 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800632 if sanitize := ctx.mod.sanitize; sanitize != nil {
633 if !sanitize.isVariantOnProductionDevice() {
634 return false
635 }
636 }
637 if !ctx.ctx.Device() {
638 // Host modules do not need ABI dumps.
639 return false
640 }
Logan Chienfa478c02018-12-28 16:25:39 +0800641 if !ctx.mod.IsForPlatform() {
642 // APEX variants do not need ABI dumps.
643 return false
644 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800645 if inList(ctx.baseModuleName(), llndkLibraries) {
646 return true
647 }
Logan Chienf4b79c62018-08-02 02:27:02 +0800648 if inList(ctx.baseModuleName(), ndkMigratedLibs) {
649 return true
650 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800651 if ctx.useVndk() && ctx.isVndk() {
652 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
653 // VNDK-private.
654 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
655 }
656 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800657}
658
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700659func (ctx *moduleContextImpl) selectedStl() string {
660 if stl := ctx.mod.stl; stl != nil {
661 return stl.Properties.SelectedStl
662 }
663 return ""
664}
665
Ivan Lozanobd721262018-11-27 14:33:03 -0800666func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
667 return ctx.mod.linker.useClangLld(actx)
668}
669
Colin Crossce75d2c2016-10-06 16:12:58 -0700670func (ctx *moduleContextImpl) baseModuleName() string {
671 return ctx.mod.ModuleBase.BaseModuleName()
672}
673
Logan Chienf3511742017-10-31 18:04:35 +0800674func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
675 return ctx.mod.getVndkExtendsModuleName()
676}
677
Jiyong Park25fc6a92018-11-18 18:02:45 +0900678// Tests if this module is built for APEX
679func (ctx *moduleContextImpl) isApex() bool {
680 return ctx.mod.ApexName() != ""
681}
682
Jiyong Parkb0788572018-12-20 22:10:17 +0900683func (ctx *moduleContextImpl) hasStubsVariants() bool {
684 return ctx.mod.HasStubsVariants()
685}
686
687func (ctx *moduleContextImpl) isStubs() bool {
688 return ctx.mod.IsStubs()
689}
690
Colin Cross635c3b02016-05-18 15:37:25 -0700691func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800692 return &Module{
693 hod: hod,
694 multilib: multilib,
695 }
696}
697
Colin Cross635c3b02016-05-18 15:37:25 -0700698func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800699 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700700 module.features = []feature{
701 &tidyFeature{},
702 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700703 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800704 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800705 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800706 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900707 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700708 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700709 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800710 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800711 return module
712}
713
Colin Crossce75d2c2016-10-06 16:12:58 -0700714func (c *Module) Prebuilt() *android.Prebuilt {
715 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
716 return p.prebuilt()
717 }
718 return nil
719}
720
721func (c *Module) Name() string {
722 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700723 if p, ok := c.linker.(interface {
724 Name(string) string
725 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700726 name = p.Name(name)
727 }
728 return name
729}
730
Jeff Gaston294356f2017-09-27 17:05:30 -0700731// orderDeps reorders dependencies into a list such that if module A depends on B, then
732// A will precede B in the resultant list.
733// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800734// Note that directSharedDeps should be the analogous static library for each shared lib dep
735func orderDeps(directStaticDeps []android.Path, directSharedDeps []android.Path, allTransitiveDeps map[android.Path][]android.Path) (orderedAllDeps []android.Path, orderedDeclaredDeps []android.Path) {
Jeff Gaston294356f2017-09-27 17:05:30 -0700736 // If A depends on B, then
737 // Every list containing A will also contain B later in the list
738 // So, after concatenating all lists, the final instance of B will have come from the same
739 // original list as the final instance of A
740 // So, the final instance of B will be later in the concatenation than the final A
741 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
742 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800743 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700744 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800745 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
746 }
747 for _, dep := range directSharedDeps {
748 orderedAllDeps = append(orderedAllDeps, dep)
749 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700750 }
751
Colin Crossb6715442017-10-24 11:13:31 -0700752 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700753
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800754 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700755 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800756 // resultant list to only what the caller has chosen to include in directStaticDeps
757 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700758
759 return orderedAllDeps, orderedDeclaredDeps
760}
761
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800762func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
763 // convert Module to Path
764 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
765 staticDepFiles := []android.Path{}
766 for _, dep := range staticDeps {
767 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
768 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700769 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800770 sharedDepFiles := []android.Path{}
771 for _, sharedDep := range sharedDeps {
772 staticAnalogue := sharedDep.staticVariant
773 if staticAnalogue != nil {
774 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
775 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
776 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700777 }
778
779 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800780 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700781
782 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700783}
784
Colin Cross635c3b02016-05-18 15:37:25 -0700785func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800786 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700787 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800788 moduleContextImpl: moduleContextImpl{
789 mod: c,
790 },
791 }
792 ctx.ctx = ctx
793
Colin Crossf18e1102017-11-16 14:33:08 -0800794 deps := c.depsToPaths(ctx)
795 if ctx.Failed() {
796 return
797 }
798
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700799 if c.Properties.Clang != nil && *c.Properties.Clang == false {
800 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
801 }
802
Colin Crossca860ac2016-01-04 14:34:37 -0800803 flags := Flags{
804 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800805 }
Colin Crossca860ac2016-01-04 14:34:37 -0800806 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800807 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800808 }
809 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700810 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800811 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700812 if c.stl != nil {
813 flags = c.stl.flags(ctx, flags)
814 }
Colin Cross16b23492016-01-06 14:41:07 -0800815 if c.sanitize != nil {
816 flags = c.sanitize.flags(ctx, flags)
817 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800818 if c.coverage != nil {
819 flags = c.coverage.flags(ctx, flags)
820 }
Stephen Craneba090d12017-05-09 15:44:35 -0700821 if c.lto != nil {
822 flags = c.lto.flags(ctx, flags)
823 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700824 if c.pgo != nil {
825 flags = c.pgo.flags(ctx, flags)
826 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800827 if c.xom != nil {
828 flags = c.xom.flags(ctx, flags)
829 }
Colin Crossca860ac2016-01-04 14:34:37 -0800830 for _, feature := range c.features {
831 flags = feature.flags(ctx, flags)
832 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800833 if ctx.Failed() {
834 return
835 }
836
Colin Crossb98c8b02016-07-29 13:44:28 -0700837 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
838 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
839 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800840
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800841 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
842 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700843 // We need access to all the flags seen by a source file.
844 if c.sabi != nil {
845 flags = c.sabi.flags(ctx, flags)
846 }
Colin Crossca860ac2016-01-04 14:34:37 -0800847 // Optimization to reduce size of build.ninja
848 // Replace the long list of flags for each file with a module-local variable
849 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
850 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
851 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
852 flags.CFlags = []string{"$cflags"}
853 flags.CppFlags = []string{"$cppflags"}
854 flags.AsFlags = []string{"$asflags"}
855
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700856 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800857 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700858 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800859 if ctx.Failed() {
860 return
861 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800862 }
863
Colin Crossca860ac2016-01-04 14:34:37 -0800864 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700865 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800866 if ctx.Failed() {
867 return
868 }
Colin Cross635c3b02016-05-18 15:37:25 -0700869 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900870
871 // If a lib is directly included in any of the APEXes, unhide the stubs
872 // variant having the latest version gets visible to make. In addition,
873 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
874 // force anything in the make world to link against the stubs library.
875 // (unless it is explicitly referenced via .bootstrap suffix or the
876 // module is marked with 'bootstrap: true').
877 if c.HasStubsVariants() && android.DirectlyInAnyApex(ctx.baseModuleName()) &&
878 !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
879 c.Properties.HideFromMake = false // unhide
880 // Note: this is still non-installable
881 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700882 }
Colin Cross5049f022015-03-18 13:28:46 -0700883
Jiyong Park9d452992018-10-03 00:38:19 +0900884 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700885 c.installer.install(ctx, c.outputFile.Path())
886 if ctx.Failed() {
887 return
Colin Crossca860ac2016-01-04 14:34:37 -0800888 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700889 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800890}
891
Jiyong Park379de2f2018-12-19 02:47:14 +0900892func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800893 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700894 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800895 }
Colin Crossca860ac2016-01-04 14:34:37 -0800896 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800897}
898
Colin Crossca860ac2016-01-04 14:34:37 -0800899func (c *Module) begin(ctx BaseModuleContext) {
900 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700901 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700902 }
Colin Crossca860ac2016-01-04 14:34:37 -0800903 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700904 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800905 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700906 if c.stl != nil {
907 c.stl.begin(ctx)
908 }
Colin Cross16b23492016-01-06 14:41:07 -0800909 if c.sanitize != nil {
910 c.sanitize.begin(ctx)
911 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800912 if c.coverage != nil {
913 c.coverage.begin(ctx)
914 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800915 if c.sabi != nil {
916 c.sabi.begin(ctx)
917 }
Justin Yun8effde42017-06-23 19:24:43 +0900918 if c.vndkdep != nil {
919 c.vndkdep.begin(ctx)
920 }
Stephen Craneba090d12017-05-09 15:44:35 -0700921 if c.lto != nil {
922 c.lto.begin(ctx)
923 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700924 if c.pgo != nil {
925 c.pgo.begin(ctx)
926 }
Colin Crossca860ac2016-01-04 14:34:37 -0800927 for _, feature := range c.features {
928 feature.begin(ctx)
929 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700930 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700931 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700932 if err != nil {
933 ctx.PropertyErrorf("sdk_version", err.Error())
934 }
Nan Zhang0007d812017-11-07 10:57:05 -0800935 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700936 }
Colin Crossca860ac2016-01-04 14:34:37 -0800937}
938
Colin Cross37047f12016-12-13 17:06:13 -0800939func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700940 deps := Deps{}
941
942 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700943 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700944 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000945 // Add the PGO dependency (the clang_rt.profile runtime library), which
946 // sometimes depends on symbols from libgcc, before libgcc gets added
947 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700948 if c.pgo != nil {
949 deps = c.pgo.deps(ctx, deps)
950 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700951 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700952 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700953 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700954 if c.stl != nil {
955 deps = c.stl.deps(ctx, deps)
956 }
Colin Cross16b23492016-01-06 14:41:07 -0800957 if c.sanitize != nil {
958 deps = c.sanitize.deps(ctx, deps)
959 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000960 if c.coverage != nil {
961 deps = c.coverage.deps(ctx, deps)
962 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800963 if c.sabi != nil {
964 deps = c.sabi.deps(ctx, deps)
965 }
Justin Yun8effde42017-06-23 19:24:43 +0900966 if c.vndkdep != nil {
967 deps = c.vndkdep.deps(ctx, deps)
968 }
Stephen Craneba090d12017-05-09 15:44:35 -0700969 if c.lto != nil {
970 deps = c.lto.deps(ctx, deps)
971 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700972 for _, feature := range c.features {
973 deps = feature.deps(ctx, deps)
974 }
975
Colin Crossb6715442017-10-24 11:13:31 -0700976 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
977 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
978 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
979 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
980 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
981 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800982 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700983
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700984 for _, lib := range deps.ReexportSharedLibHeaders {
985 if !inList(lib, deps.SharedLibs) {
986 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
987 }
988 }
989
990 for _, lib := range deps.ReexportStaticLibHeaders {
991 if !inList(lib, deps.StaticLibs) {
992 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
993 }
994 }
995
Colin Cross5950f382016-12-13 12:50:57 -0800996 for _, lib := range deps.ReexportHeaderLibHeaders {
997 if !inList(lib, deps.HeaderLibs) {
998 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
999 }
1000 }
1001
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001002 for _, gen := range deps.ReexportGeneratedHeaders {
1003 if !inList(gen, deps.GeneratedHeaders) {
1004 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1005 }
1006 }
1007
Colin Crossc99deeb2016-04-11 15:06:20 -07001008 return deps
1009}
1010
Dan Albert7e9d2952016-08-04 13:02:36 -07001011func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001012 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001013 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001014 moduleContextImpl: moduleContextImpl{
1015 mod: c,
1016 },
1017 }
1018 ctx.ctx = ctx
1019
Colin Crossca860ac2016-01-04 14:34:37 -08001020 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001021}
1022
Jiyong Park7ed9de32018-10-15 22:25:07 +09001023// Split name#version into name and version
1024func stubsLibNameAndVersion(name string) (string, string) {
1025 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1026 version := name[sharp+1:]
1027 libname := name[:sharp]
1028 return libname, version
1029 }
1030 return name, ""
1031}
1032
Colin Cross1e676be2016-10-12 14:38:15 -07001033func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001034 ctx := &depsContext{
1035 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001036 moduleContextImpl: moduleContextImpl{
1037 mod: c,
1038 },
1039 }
1040 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001041
Colin Crossc99deeb2016-04-11 15:06:20 -07001042 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001043
Dan Albert914449f2016-06-17 16:45:24 -07001044 variantNdkLibs := []string{}
1045 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001046 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001047 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001048
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001049 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1050 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001051 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001052 // 1. Name of an NDK library that refers to a prebuilt module.
1053 // For each of these, it adds the name of the prebuilt module (which will be in
1054 // prebuilts/ndk) to the list of nonvariant libs.
1055 // 2. Name of an NDK library that refers to an ndk_library module.
1056 // For each of these, it adds the name of the ndk_library module to the list of
1057 // variant libs.
1058 // 3. Anything else (so anything that isn't an NDK library).
1059 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001060 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001061 // The caller can then know to add the variantLibs dependencies differently from the
1062 // nonvariantLibs
1063 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1064 variantLibs = []string{}
1065 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001066 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001067 // strip #version suffix out
1068 name, _ := stubsLibNameAndVersion(entry)
1069 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1070 if !inList(name, ndkMigratedLibs) {
1071 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001072 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001073 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001074 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001075 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1076 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1077 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1078 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001079 if actx.OtherModuleExists(vendorPublicLib) {
1080 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1081 } else {
1082 // This can happen if vendor_public_library module is defined in a
1083 // namespace that isn't visible to the current module. In that case,
1084 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001085 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001086 }
Dan Albert914449f2016-06-17 16:45:24 -07001087 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001088 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001089 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001090 }
1091 }
Dan Albert914449f2016-06-17 16:45:24 -07001092 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001093 }
1094
Dan Albert914449f2016-06-17 16:45:24 -07001095 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1096 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001097 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001098 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001099
Jiyong Park7ed9de32018-10-15 22:25:07 +09001100 if c.linker != nil {
1101 if library, ok := c.linker.(*libraryDecorator); ok {
1102 if library.buildStubs() {
1103 // Stubs lib does not have dependency to other libraries. Don't proceed.
1104 return
1105 }
1106 }
1107 }
1108
Colin Cross32ec36c2016-12-15 07:39:51 -08001109 for _, lib := range deps.HeaderLibs {
1110 depTag := headerDepTag
1111 if inList(lib, deps.ReexportHeaderLibHeaders) {
1112 depTag = headerExportDepTag
1113 }
1114 actx.AddVariationDependencies(nil, depTag, lib)
1115 }
Colin Cross5950f382016-12-13 12:50:57 -08001116
Dan Willemsen59339a22018-07-22 21:18:45 -07001117 actx.AddVariationDependencies([]blueprint.Variation{
1118 {Mutator: "link", Variation: "static"},
1119 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001120
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001121 for _, lib := range deps.StaticLibs {
1122 depTag := staticDepTag
1123 if inList(lib, deps.ReexportStaticLibHeaders) {
1124 depTag = staticExportDepTag
1125 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001126 actx.AddVariationDependencies([]blueprint.Variation{
1127 {Mutator: "link", Variation: "static"},
1128 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001129 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001130
Dan Willemsen59339a22018-07-22 21:18:45 -07001131 actx.AddVariationDependencies([]blueprint.Variation{
1132 {Mutator: "link", Variation: "static"},
1133 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001134
Jiyong Park25fc6a92018-11-18 18:02:45 +09001135 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1136 var variations []blueprint.Variation
1137 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001138 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001139 if version != "" && versionVariantAvail {
1140 // Version is explicitly specified. i.e. libFoo#30
1141 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1142 depTag.explicitlyVersioned = true
1143 }
1144 actx.AddVariationDependencies(variations, depTag, name)
1145
1146 // If the version is not specified, add dependency to the latest stubs library.
1147 // The stubs library will be used when the depending module is built for APEX and
1148 // the dependent module is not in the same APEX.
1149 latestVersion := latestStubsVersionFor(actx.Config(), name)
1150 if version == "" && latestVersion != "" && versionVariantAvail {
1151 actx.AddVariationDependencies([]blueprint.Variation{
1152 {Mutator: "link", Variation: "shared"},
1153 {Mutator: "version", Variation: latestVersion},
1154 }, depTag, name)
1155 // Note that depTag.explicitlyVersioned is false in this case.
1156 }
1157 }
1158
Jiyong Park7ed9de32018-10-15 22:25:07 +09001159 // shared lib names without the #version suffix
1160 var sharedLibNames []string
1161
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001162 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001163 name, version := stubsLibNameAndVersion(lib)
1164 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001165 depTag := sharedDepTag
1166 if inList(lib, deps.ReexportSharedLibHeaders) {
1167 depTag = sharedExportDepTag
1168 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001169 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001170 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001171
Jiyong Park7ed9de32018-10-15 22:25:07 +09001172 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001173 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001174 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1175 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1176 // linking against both the stubs lib and the non-stubs lib at the same time.
1177 continue
1178 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001179 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001180 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001181
Dan Willemsen59339a22018-07-22 21:18:45 -07001182 actx.AddVariationDependencies([]blueprint.Variation{
1183 {Mutator: "link", Variation: "shared"},
1184 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001185
Colin Cross68861832016-07-08 10:41:41 -07001186 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001187
1188 for _, gen := range deps.GeneratedHeaders {
1189 depTag := genHeaderDepTag
1190 if inList(gen, deps.ReexportGeneratedHeaders) {
1191 depTag = genHeaderExportDepTag
1192 }
1193 actx.AddDependency(c, depTag, gen)
1194 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001195
Colin Cross42d48b72018-08-29 14:10:52 -07001196 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001197
1198 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001199 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001200 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001201 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001202 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001203 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001204 if deps.LinkerFlagsFile != "" {
1205 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1206 }
1207 if deps.DynamicLinker != "" {
1208 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001209 }
Dan Albert914449f2016-06-17 16:45:24 -07001210
1211 version := ctx.sdkVersion()
1212 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001213 {Mutator: "ndk_api", Variation: version},
1214 {Mutator: "link", Variation: "shared"},
1215 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001216 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001217 {Mutator: "ndk_api", Variation: version},
1218 {Mutator: "link", Variation: "shared"},
1219 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001220
1221 if vndkdep := c.vndkdep; vndkdep != nil {
1222 if vndkdep.isVndkExt() {
1223 baseModuleMode := vendorMode
1224 if actx.DeviceConfig().VndkVersion() == "" {
1225 baseModuleMode = coreMode
1226 }
1227 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001228 {Mutator: "image", Variation: baseModuleMode},
1229 {Mutator: "link", Variation: "shared"},
1230 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001231 }
1232 }
Colin Cross6362e272015-10-29 15:25:03 -07001233}
Colin Cross21b9a242015-03-24 14:15:58 -07001234
Colin Crosse40b4ea2018-10-02 22:25:58 -07001235func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001236 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1237 c.beginMutator(ctx)
1238 }
1239}
1240
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001241// Whether a module can link to another module, taking into
1242// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001243func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001244 if from.Target().Os != android.Android {
1245 // Host code is not restricted
1246 return
1247 }
1248 if from.Properties.UseVndk {
1249 // Though vendor code is limited by the vendor mutator,
1250 // each vendor-available module needs to check
1251 // link-type for VNDK.
1252 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001253 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001254 }
1255 return
1256 }
Nan Zhang0007d812017-11-07 10:57:05 -08001257 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001258 // Platform code can link to anything
1259 return
1260 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001261 if from.inRecovery() {
1262 // Recovery code is not NDK
1263 return
1264 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001265 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1266 // These are always allowed
1267 return
1268 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001269 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1270 // These are allowed, but they don't set sdk_version
1271 return
1272 }
1273 if _, ok := to.linker.(*stubDecorator); ok {
1274 // These aren't real libraries, but are the stub shared libraries that are included in
1275 // the NDK.
1276 return
1277 }
Nan Zhang0007d812017-11-07 10:57:05 -08001278 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001279 // NDK code linking to platform code is never okay.
1280 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1281 ctx.OtherModuleName(to))
1282 }
1283
1284 // At this point we know we have two NDK libraries, but we need to
1285 // check that we're not linking against anything built against a higher
1286 // API level, as it is only valid to link against older or equivalent
1287 // APIs.
1288
Inseob Kim01a28722018-04-11 09:48:45 +09001289 // Current can link against anything.
1290 if String(from.Properties.Sdk_version) != "current" {
1291 // Otherwise we need to check.
1292 if String(to.Properties.Sdk_version) == "current" {
1293 // Current can't be linked against by anything else.
1294 ctx.ModuleErrorf("links %q built against newer API version %q",
1295 ctx.OtherModuleName(to), "current")
1296 } else {
1297 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1298 if err != nil {
1299 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001300 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001301 String(from.Properties.Sdk_version))
1302 }
1303 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1304 if err != nil {
1305 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001306 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001307 String(to.Properties.Sdk_version))
1308 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001309
Inseob Kim01a28722018-04-11 09:48:45 +09001310 if toApi > fromApi {
1311 ctx.ModuleErrorf("links %q built against newer API version %q",
1312 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1313 }
1314 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001315 }
Dan Albert202fe492017-12-15 13:56:59 -08001316
1317 // Also check that the two STL choices are compatible.
1318 fromStl := from.stl.Properties.SelectedStl
1319 toStl := to.stl.Properties.SelectedStl
1320 if fromStl == "" || toStl == "" {
1321 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001322 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001323 // We can be permissive with the system "STL" since it is only the C++
1324 // ABI layer, but in the future we should make sure that everyone is
1325 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001326 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001327 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1328 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1329 to.stl.Properties.SelectedStl)
1330 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001331}
1332
Jiyong Park5fb8c102018-04-09 12:03:06 +09001333// Tests whether the dependent library is okay to be double loaded inside a single process.
1334// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1335// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1336// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1337func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1338 if _, ok := from.linker.(*libraryDecorator); !ok {
1339 return
1340 }
1341
1342 if inList(ctx.ModuleName(), llndkLibraries) ||
1343 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1344 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1345 depIsVndkSp := false
1346 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1347 depIsVndkSp = true
1348 }
1349 depIsVndk := false
1350 if to.vndkdep != nil && to.vndkdep.isVndk() {
1351 depIsVndk = true
1352 }
1353 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1354 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001355 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1356 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001357 ctx.OtherModuleName(to))
1358 }
1359 }
1360}
1361
Colin Crossc99deeb2016-04-11 15:06:20 -07001362// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001363func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001364 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001365
Jeff Gaston294356f2017-09-27 17:05:30 -07001366 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001367 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001368
Colin Crossd11fcda2017-10-23 17:59:01 -07001369 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001370 depName := ctx.OtherModuleName(dep)
1371 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001372
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001373 ccDep, _ := dep.(*Module)
1374 if ccDep == nil {
1375 // handling for a few module types that aren't cc Module but that are also supported
1376 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001377 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001378 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001379 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1380 genRule.GeneratedSourceFiles()...)
1381 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001382 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001383 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001384 // Support exported headers from a generated_sources dependency
1385 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001386 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001387 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001388 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001389 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001390 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001391 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001392 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001393 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001394 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001395 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001396 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1397 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1398
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001399 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001400 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001401 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001402 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001403 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001404 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001405 files := genRule.GeneratedSourceFiles()
1406 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001407 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001408 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001409 ctx.ModuleErrorf("module %q can only generate a single file if used for a linker flag file", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001410 }
1411 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001412 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001413 }
Colin Crossca860ac2016-01-04 14:34:37 -08001414 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001415 return
1416 }
1417
Colin Crossd11fcda2017-10-23 17:59:01 -07001418 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001419 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1420 return
1421 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001422 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001423 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001424 return
1425 }
1426
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001427 // re-exporting flags
1428 if depTag == reuseObjTag {
1429 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001430 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001431 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001432 depPaths.Objs = depPaths.Objs.Append(objs)
1433 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001434 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001435 return
1436 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001437 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001438
1439 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1440 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1441 // won't be matched to sharedDepTag and lateSharedDepTag.
1442 explicitlyVersioned := false
1443 if t, ok := depTag.(dependencyTag); ok {
1444 explicitlyVersioned = t.explicitlyVersioned
1445 t.explicitlyVersioned = false
1446 depTag = t
1447 }
1448
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001449 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001450 depIsStatic := false
1451 switch depTag {
1452 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1453 depIsStatic = true
1454 }
1455 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001456 depIsStubs := dependentLibrary.buildStubs()
1457 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001458 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
1459 depInPlatform := !android.DirectlyInAnyApex(depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001460
1461 var useThisDep bool
1462 if depIsStubs && explicitlyVersioned {
1463 // Always respect dependency to the versioned stubs (i.e. libX#10)
1464 useThisDep = true
1465 } else if !depHasStubs {
1466 // Use non-stub variant if that is the only choice
1467 // (i.e. depending on a lib without stubs.version property)
1468 useThisDep = true
1469 } else if c.IsForPlatform() {
1470 // If not building for APEX, use stubs only when it is from
1471 // an APEX (and not from platform)
1472 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001473 if c.inRecovery() || Bool(c.Properties.Bootstrap) {
1474 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001475 // always link to non-stub variant
1476 useThisDep = !depIsStubs
1477 }
1478 } else {
1479 // If building for APEX, use stubs only when it is not from
1480 // the same APEX
1481 useThisDep = (depInSameApex != depIsStubs)
1482 }
1483
1484 if !useThisDep {
1485 return // stop processing this dep
1486 }
1487 }
1488
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001489 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001490 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001491 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001492 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001493 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001494
1495 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001496 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001497 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001498 // 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 -07001499 // Re-exported shared library headers must be included as well since they can help us with type information
1500 // about template instantiations (instantiated from their headers).
1501 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001502 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001503 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001504
Logan Chienf3511742017-10-31 18:04:35 +08001505 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001506 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001507 }
1508
Colin Cross26c34ed2016-09-30 17:10:16 -07001509 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001510 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001511
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001512 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001513 depFile := android.OptionalPath{}
1514
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001515 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001516 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001517 ptr = &depPaths.SharedLibs
1518 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001519 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001520 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001521 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001522 ptr = &depPaths.LateSharedLibs
1523 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001524 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001525 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001526 ptr = nil
1527 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001528 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001529 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001530 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001531 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001532 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001533 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001534 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001535 return
1536 }
1537
1538 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001539 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001540 for i := range missingDeps {
1541 missingDeps[i] += postfix
1542 }
1543 ctx.AddMissingDependencies(missingDeps)
1544 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001545 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001546 case headerDepTag:
1547 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001548 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001549 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001550 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001551 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001552 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001553 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001554 case dynamicLinkerDepTag:
1555 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001556 }
1557
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001558 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001559 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001560 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001561 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001562 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001563 return
1564 }
1565
1566 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001567 // in static libraries act as if they were whole static libraries. The same goes for
1568 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001569 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1570 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001571 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1572 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001573
Dan Willemsen581341d2017-02-09 16:16:31 -08001574 }
1575
Colin Cross26c34ed2016-09-30 17:10:16 -07001576 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001577 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001578 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001579 return
1580 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001581 *ptr = append(*ptr, linkFile.Path())
1582 }
1583
Colin Crossc99deeb2016-04-11 15:06:20 -07001584 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001585 dep := depFile
1586 if !dep.Valid() {
1587 dep = linkFile
1588 }
1589 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001590 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001591
Logan Chien43d34c32017-12-20 01:17:32 +08001592 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001593 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001594 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001595 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001596 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001597 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001598 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1599 if c.useVndk() && bothVendorAndCoreVariantsExist {
1600 // The vendor module in Make will have been renamed to not conflict with the core
1601 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001602 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001603 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001604 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001605 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1606 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001607 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001608 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001609 }
Logan Chien43d34c32017-12-20 01:17:32 +08001610 }
1611
1612 // Export the shared libs to Make.
1613 switch depTag {
1614 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001615 // Dependency to the stubs lib which is already included in an APEX
1616 // is not added to the androidmk dependency
1617 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001618 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001619 // Also add the dependency to the APEX(es) providing the library so that
1620 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001621 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001622 c.Properties.ApexesProvidingSharedLibs = append(
1623 c.Properties.ApexesProvidingSharedLibs, an)
1624 }
1625 break
1626 }
1627 }
1628
Jiyong Park27b188b2017-07-18 13:23:39 +09001629 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001630 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001631 c.Properties.AndroidMkSharedLibs = append(
1632 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001633 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1634 c.Properties.AndroidMkStaticLibs = append(
1635 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001636 case runtimeDepTag:
1637 c.Properties.AndroidMkRuntimeLibs = append(
1638 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001639 case wholeStaticDepTag:
1640 c.Properties.AndroidMkWholeStaticLibs = append(
1641 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001642 }
Colin Crossca860ac2016-01-04 14:34:37 -08001643 })
1644
Jeff Gaston294356f2017-09-27 17:05:30 -07001645 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001646 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001647
Colin Crossdd84e052017-05-17 13:44:16 -07001648 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001649 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001650 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001651 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001652 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1653
1654 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001655 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001656 }
Colin Crossdd84e052017-05-17 13:44:16 -07001657
Colin Crossca860ac2016-01-04 14:34:37 -08001658 return depPaths
1659}
1660
1661func (c *Module) InstallInData() bool {
1662 if c.installer == nil {
1663 return false
1664 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001665 return c.installer.inData()
1666}
1667
1668func (c *Module) InstallInSanitizerDir() bool {
1669 if c.installer == nil {
1670 return false
1671 }
1672 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001673 return true
1674 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001675 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001676}
1677
Jiyong Parkf9332f12018-02-01 00:54:12 +09001678func (c *Module) InstallInRecovery() bool {
1679 return c.inRecovery()
1680}
1681
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001682func (c *Module) HostToolPath() android.OptionalPath {
1683 if c.installer == nil {
1684 return android.OptionalPath{}
1685 }
1686 return c.installer.hostToolPath()
1687}
1688
Nan Zhangd4e641b2017-07-12 12:55:28 -07001689func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1690 return c.outputFile
1691}
1692
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001693func (c *Module) Srcs() android.Paths {
1694 if c.outputFile.Valid() {
1695 return android.Paths{c.outputFile.Path()}
1696 }
1697 return android.Paths{}
1698}
1699
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001700func (c *Module) static() bool {
1701 if static, ok := c.linker.(interface {
1702 static() bool
1703 }); ok {
1704 return static.static()
1705 }
1706 return false
1707}
1708
Jiyong Park379de2f2018-12-19 02:47:14 +09001709func (c *Module) staticBinary() bool {
1710 if static, ok := c.linker.(interface {
1711 staticBinary() bool
1712 }); ok {
1713 return static.staticBinary()
1714 }
1715 return false
1716}
1717
Colin Crossb60190a2018-09-04 16:28:17 -07001718func (c *Module) getMakeLinkType() string {
1719 if c.useVndk() {
1720 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1721 if inList(c.Name(), vndkPrivateLibraries) {
1722 return "native:vndk_private"
1723 } else {
1724 return "native:vndk"
1725 }
1726 } else {
1727 return "native:vendor"
1728 }
1729 } else if c.inRecovery() {
1730 return "native:recovery"
1731 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1732 return "native:ndk:none:none"
1733 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1734 //family, link := getNdkStlFamilyAndLinkType(c)
1735 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1736 } else {
1737 return "native:platform"
1738 }
1739}
1740
Jiyong Park9d452992018-10-03 00:38:19 +09001741// Overrides ApexModule.IsInstallabeToApex()
1742// Only shared libraries are installable to APEX.
1743func (c *Module) IsInstallableToApex() bool {
1744 if shared, ok := c.linker.(interface {
1745 shared() bool
1746 }); ok {
1747 return shared.shared()
1748 }
1749 return false
1750}
1751
Colin Cross2ba19d92015-05-07 15:44:20 -07001752//
Colin Crosscfad1192015-11-02 16:43:11 -08001753// Defaults
1754//
Colin Crossca860ac2016-01-04 14:34:37 -08001755type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001756 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001757 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001758 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001759}
1760
Colin Cross635c3b02016-05-18 15:37:25 -07001761func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001762}
1763
Colin Cross1e676be2016-10-12 14:38:15 -07001764func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1765}
1766
Colin Cross36242852017-06-23 15:06:31 -07001767func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001768 return DefaultsFactory()
1769}
1770
Colin Cross36242852017-06-23 15:06:31 -07001771func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001772 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001773
Colin Cross36242852017-06-23 15:06:31 -07001774 module.AddProperties(props...)
1775 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001776 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001777 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001778 &BaseCompilerProperties{},
1779 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001780 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001781 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001782 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001783 &TestProperties{},
1784 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001785 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001786 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001787 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001788 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001789 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001790 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001791 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001792 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001793 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001794 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001795 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001796 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001797 )
Colin Crosscfad1192015-11-02 16:43:11 -08001798
Colin Cross1f44a3a2017-07-07 14:33:33 -07001799 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001800 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001801
1802 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001803}
1804
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001805const (
1806 // coreMode is the variant used for framework-private libraries, or
1807 // SDK libraries. (which framework-private libraries can use)
1808 coreMode = "core"
1809
1810 // vendorMode is the variant used for /vendor code that compiles
1811 // against the VNDK.
1812 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001813
1814 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001815)
1816
Jiyong Park6a43f042017-10-12 23:05:00 +09001817func squashVendorSrcs(m *Module) {
1818 if lib, ok := m.compiler.(*libraryDecorator); ok {
1819 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1820 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1821
1822 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1823 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1824 }
1825}
1826
Jiyong Parkf9332f12018-02-01 00:54:12 +09001827func squashRecoverySrcs(m *Module) {
1828 if lib, ok := m.compiler.(*libraryDecorator); ok {
1829 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1830 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1831
1832 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1833 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1834 }
1835}
1836
Jiyong Parkda6eb592018-12-19 17:12:36 +09001837func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001838 if mctx.Os() != android.Android {
1839 return
1840 }
1841
Jiyong Park7ed9de32018-10-15 22:25:07 +09001842 if g, ok := mctx.Module().(*genrule.Module); ok {
1843 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001844 var coreVariantNeeded bool = false
1845 var vendorVariantNeeded bool = false
1846 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001847 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001848 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001849 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001850 coreVariantNeeded = true
1851 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001852 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001853 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001854 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001855 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001856 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001857 if Bool(props.Recovery_available) {
1858 recoveryVariantNeeded = true
1859 }
1860
Jiyong Park413cc742018-06-19 01:46:06 +09001861 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001862 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001863 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001864 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001865 recoveryVariantNeeded = false
1866 }
1867 }
1868
Jiyong Park3f736c92018-05-24 13:36:56 +09001869 var variants []string
1870 if coreVariantNeeded {
1871 variants = append(variants, coreMode)
1872 }
1873 if vendorVariantNeeded {
1874 variants = append(variants, vendorMode)
1875 }
1876 if recoveryVariantNeeded {
1877 variants = append(variants, recoveryMode)
1878 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001879 mod := mctx.CreateVariations(variants...)
1880 for i, v := range variants {
1881 if v == recoveryMode {
1882 m := mod[i].(*genrule.Module)
1883 m.Extra.(*GenruleExtraProperties).InRecovery = true
1884 }
1885 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001886 }
1887 }
1888
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001889 m, ok := mctx.Module().(*Module)
1890 if !ok {
1891 return
1892 }
1893
1894 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001895 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09001896 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08001897
1898 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001899 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001900 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001901 return
1902 }
Logan Chienf3511742017-10-31 18:04:35 +08001903
1904 if vndkdep := m.vndkdep; vndkdep != nil {
1905 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09001906 if productSpecific {
1907 mctx.PropertyErrorf("product_specific",
1908 "product_specific must not be true when `vndk: {enabled: true}`")
1909 return
1910 }
Logan Chienf3511742017-10-31 18:04:35 +08001911 if vendorSpecific {
1912 if !vndkdep.isVndkExt() {
1913 mctx.PropertyErrorf("vndk",
1914 "must set `extends: \"...\"` to vndk extension")
1915 return
1916 }
1917 } else {
1918 if vndkdep.isVndkExt() {
1919 mctx.PropertyErrorf("vndk",
1920 "must set `vendor: true` to set `extends: %q`",
1921 m.getVndkExtendsModuleName())
1922 return
1923 }
1924 if m.VendorProperties.Vendor_available == nil {
1925 mctx.PropertyErrorf("vndk",
1926 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1927 return
1928 }
1929 }
1930 } else {
1931 if vndkdep.isVndkSp() {
1932 mctx.PropertyErrorf("vndk",
1933 "must set `enabled: true` to set `support_system_process: true`")
1934 return
1935 }
1936 if vndkdep.isVndkExt() {
1937 mctx.PropertyErrorf("vndk",
1938 "must set `enabled: true` to set `extends: %q`",
1939 m.getVndkExtendsModuleName())
1940 return
1941 }
Justin Yun8effde42017-06-23 19:24:43 +09001942 }
1943 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001944
Jiyong Parkf9332f12018-02-01 00:54:12 +09001945 var coreVariantNeeded bool = false
1946 var vendorVariantNeeded bool = false
1947 var recoveryVariantNeeded bool = false
1948
Justin Yun71549282017-11-17 12:10:28 +09001949 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001950 // If the device isn't compiling against the VNDK, we always
1951 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001952 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001953 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1954 // LL-NDK stubs only exist in the vendor variant, since the
1955 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001956 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001957 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1958 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001959 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001960 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001961 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1962 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001963 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001964 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001965 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001966 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001967 coreVariantNeeded = true
1968 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001969 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001970 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001971 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001972 } else {
1973 // This is either in /system (or similar: /data), or is a
1974 // modules built with the NDK. Modules built with the NDK
1975 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001976 coreVariantNeeded = true
1977 }
1978
1979 if Bool(m.Properties.Recovery_available) {
1980 recoveryVariantNeeded = true
1981 }
1982
1983 if m.ModuleBase.InstallInRecovery() {
1984 recoveryVariantNeeded = true
1985 coreVariantNeeded = false
1986 }
1987
Jiyong Park413cc742018-06-19 01:46:06 +09001988 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001989 primaryArch := mctx.Config().DevicePrimaryArchType()
1990 moduleArch := m.Target().Arch.ArchType
1991 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001992 recoveryVariantNeeded = false
1993 }
1994 }
1995
Jiyong Parkf9332f12018-02-01 00:54:12 +09001996 var variants []string
1997 if coreVariantNeeded {
1998 variants = append(variants, coreMode)
1999 }
2000 if vendorVariantNeeded {
2001 variants = append(variants, vendorMode)
2002 }
2003 if recoveryVariantNeeded {
2004 variants = append(variants, recoveryMode)
2005 }
2006 mod := mctx.CreateVariations(variants...)
2007 for i, v := range variants {
2008 if v == vendorMode {
2009 m := mod[i].(*Module)
2010 m.Properties.UseVndk = true
2011 squashVendorSrcs(m)
2012 } else if v == recoveryMode {
2013 m := mod[i].(*Module)
2014 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002015 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002016 squashRecoverySrcs(m)
2017 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002018 }
2019}
2020
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002021func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002022 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002023 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2024 }
Colin Cross6510f912017-11-29 00:27:14 -08002025 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002026}
2027
Colin Cross06a931b2015-10-28 17:23:31 -07002028var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002029var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002030var BoolPtr = proptools.BoolPtr
2031var String = proptools.String
2032var StringPtr = proptools.StringPtr