blob: 85e3a6718398b489668d11e590a20ed50ee64c36 [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)
Ivan Lozano30c5db22018-02-21 15:49:20 -080063
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000064 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080065 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070066
67 ctx.TopDown("lto_deps", ltoDepsMutator)
68 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070069 })
Colin Crossb98c8b02016-07-29 13:44:28 -070070
71 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070072}
73
Colin Crossca860ac2016-01-04 14:34:37 -080074type Deps struct {
75 SharedLibs, LateSharedLibs []string
76 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080077 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080078 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070079
Colin Cross5950f382016-12-13 12:50:57 -080080 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070081
Colin Cross81413472016-04-11 14:37:39 -070082 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070083
Dan Willemsenb40aab62016-04-20 14:21:14 -070084 GeneratedSources []string
85 GeneratedHeaders []string
86
Dan Willemsenb3454ab2016-09-28 17:34:58 -070087 ReexportGeneratedHeaders []string
88
Colin Cross97ba0732015-03-23 17:50:24 -070089 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070090
91 // Used for host bionic
92 LinkerFlagsFile string
93 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070094}
95
Colin Crossca860ac2016-01-04 14:34:37 -080096type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070097 // Paths to .so files
98 SharedLibs, LateSharedLibs android.Paths
99 // Paths to the dependencies to use for .so files (.so.toc files)
100 SharedLibsDeps, LateSharedLibsDeps android.Paths
101 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700102 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Colin Cross26c34ed2016-09-30 17:10:16 -0700104 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700105 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800106 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700107 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700110 GeneratedSources android.Paths
111 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700112
Dan Willemsen76f08272016-07-09 00:14:08 -0700113 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700114 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700115
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700117 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700118
119 // Path to the file container flags to use with the linker
120 LinkerFlagsFile android.OptionalPath
121
122 // Path to the dynamic linker binary
123 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124}
125
Colin Crossca860ac2016-01-04 14:34:37 -0800126type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700127 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
128 ArFlags []string // Flags that apply to ar
129 AsFlags []string // Flags that apply to assembly source files
130 CFlags []string // Flags that apply to C and C++ source files
131 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
132 ConlyFlags []string // Flags that apply to C source files
133 CppFlags []string // Flags that apply to C++ source files
134 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
135 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700136 aidlFlags []string // Flags that apply to aidl source files
137 rsFlags []string // Flags that apply to renderscript source files
138 LdFlags []string // Flags that apply to linker command lines
139 libFlags []string // Flags to add libraries early to the link order
140 TidyFlags []string // Flags that apply to clang-tidy
141 SAbiFlags []string // Flags that apply to header-abi-dumper
142 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700143
Colin Crossc3199482017-03-30 15:03:04 -0700144 // Global include flags that apply to C, C++, and assembly source files
145 // These must be after any module include flags, which will be in GlobalFlags.
146 SystemIncludeFlags []string
147
Colin Crossb98c8b02016-07-29 13:44:28 -0700148 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700149 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800150 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800151 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800152
153 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800154 DynamicLinker string
155
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700156 CFlagsDeps android.Paths // Files depended on by compiler flags
157 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800158
159 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800160
161 protoDeps android.Paths
162 protoFlags []string // Flags that apply to proto source files
163 protoOutTypeFlag string // The output type, --cpp_out for example
164 protoOutParams []string // Flags that modify the output of proto generated files
165 protoC bool // Whether to use C instead of C++
166 protoOptionsFile bool // Whether to look for a .options file next to the .proto
167 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700168}
169
Colin Cross81413472016-04-11 14:37:39 -0700170type ObjectLinkerProperties struct {
171 // names of other cc_object modules to link into this module using partial linking
172 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700173
174 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800175 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700176}
177
Colin Crossca860ac2016-01-04 14:34:37 -0800178// Properties used to compile all C or C++ modules
179type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700180 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800181 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700182
183 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800184 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700185
Jiyong Parkde866cb2018-12-07 23:08:36 +0900186 AndroidMkSharedLibs []string `blueprint:"mutated"`
187 AndroidMkStaticLibs []string `blueprint:"mutated"`
188 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
189 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
190 HideFromMake bool `blueprint:"mutated"`
191 PreventInstall bool `blueprint:"mutated"`
192 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700193
194 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800195
196 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
197 // file
198 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900199
200 // Make this module available when building for recovery
201 Recovery_available *bool
202
203 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900204
205 // Allows this module to use non-APEX version of libraries. Useful
206 // for building binaries that are started before APEXes are activated.
207 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700208}
209
210type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900211 // whether this module should be allowed to be directly depended by other
212 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
213 // If set to true, two variants will be built separately, one like
214 // normal, and the other limited to the set of libraries and headers
215 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700216 //
217 // The vendor variant may be used with a different (newer) /system,
218 // so it shouldn't have any unversioned runtime dependencies, or
219 // make assumptions about the system that may not be true in the
220 // future.
221 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900222 // If set to false, this module becomes inaccessible from /vendor modules.
223 //
224 // Default value is true when vndk: {enabled: true} or vendor: true.
225 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700226 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
227 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900228
229 // whether this module is capable of being loaded with other instance
230 // (possibly an older version) of the same module in the same process.
231 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
232 // can be double loaded in a vendor process if the library is also a
233 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
234 // explicitly marked as `double_loadable: true` by the owner, or the dependency
235 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
236 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800237}
238
Colin Crossca860ac2016-01-04 14:34:37 -0800239type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800240 static() bool
241 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700242 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700243 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800244 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700245 useVndk() bool
Justin Yun8effde42017-06-23 19:24:43 +0900246 isVndk() bool
247 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800248 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900249 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800250 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700251 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700252 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800253 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800254 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800255 useClangLld(actx ModuleContext) bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900256 isApex() bool
Jiyong Parkb0788572018-12-20 22:10:17 +0900257 hasStubsVariants() bool
258 isStubs() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800259}
260
261type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700262 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800263 ModuleContextIntf
264}
265
266type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700267 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800268 ModuleContextIntf
269}
270
Colin Cross37047f12016-12-13 17:06:13 -0800271type DepsContext interface {
272 android.BottomUpMutatorContext
273 ModuleContextIntf
274}
275
Colin Crossca860ac2016-01-04 14:34:37 -0800276type feature interface {
277 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800278 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800279 flags(ctx ModuleContext, flags Flags) Flags
280 props() []interface{}
281}
282
283type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700284 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800285 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800286 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700287 compilerProps() []interface{}
288
Colin Cross76fada02016-07-27 10:31:13 -0700289 appendCflags([]string)
290 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700291 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800292}
293
294type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700295 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800296 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700297 linkerFlags(ctx ModuleContext, flags Flags) Flags
298 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800299 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700300
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700301 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700302 appendLdflags([]string)
Colin Crossca860ac2016-01-04 14:34:37 -0800303}
304
305type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700306 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700307 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800308 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700309 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700310 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800311}
312
Colin Crossc99deeb2016-04-11 15:06:20 -0700313type dependencyTag struct {
314 blueprint.BaseDependencyTag
315 name string
316 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700317
318 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900319
320 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700321}
322
323var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700324 sharedDepTag = dependencyTag{name: "shared", library: true}
325 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
326 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
327 staticDepTag = dependencyTag{name: "static", library: true}
328 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
329 lateStaticDepTag = dependencyTag{name: "late static", library: true}
330 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800331 headerDepTag = dependencyTag{name: "header", library: true}
332 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700333 genSourceDepTag = dependencyTag{name: "gen source"}
334 genHeaderDepTag = dependencyTag{name: "gen header"}
335 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
336 objDepTag = dependencyTag{name: "obj"}
337 crtBeginDepTag = dependencyTag{name: "crtbegin"}
338 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700339 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
340 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700341 reuseObjTag = dependencyTag{name: "reuse objects"}
342 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
343 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800344 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800345 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700346)
347
Colin Crossca860ac2016-01-04 14:34:37 -0800348// Module contains the properties and members used by all C/C++ module types, and implements
349// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
350// to construct the output file. Behavior can be customized with a Customizer interface
351type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700352 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700353 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900354 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700355
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700356 Properties BaseProperties
357 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700358
Colin Crossca860ac2016-01-04 14:34:37 -0800359 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700360 hod android.HostOrDeviceSupported
361 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700362
Colin Crossca860ac2016-01-04 14:34:37 -0800363 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700364 features []feature
365 compiler compiler
366 linker linker
367 installer installer
368 stl *stl
369 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800370 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800371 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900372 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700373 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700374 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800375 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800376
377 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700378
Colin Cross635c3b02016-05-18 15:37:25 -0700379 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800380
Colin Crossb98c8b02016-07-29 13:44:28 -0700381 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700382
383 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800384
385 // Flags used to compile this module
386 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700387
388 // 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 -0800389 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700390 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800391 depsInLinkOrder android.Paths
392
393 // only non-nil when this is a shared library that reuses the objects of a static library
394 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700395}
396
Jiyong Parkc20eee32018-09-05 22:36:17 +0900397func (c *Module) OutputFile() android.OptionalPath {
398 return c.outputFile
399}
400
Colin Cross36242852017-06-23 15:06:31 -0700401func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700402 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800403 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700404 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800405 }
406 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700407 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800408 }
409 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700410 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800411 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700412 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700413 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700414 }
Colin Cross16b23492016-01-06 14:41:07 -0800415 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700416 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800417 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800418 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700419 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800420 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800421 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700422 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800423 }
Justin Yun8effde42017-06-23 19:24:43 +0900424 if c.vndkdep != nil {
425 c.AddProperties(c.vndkdep.props()...)
426 }
Stephen Craneba090d12017-05-09 15:44:35 -0700427 if c.lto != nil {
428 c.AddProperties(c.lto.props()...)
429 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700430 if c.pgo != nil {
431 c.AddProperties(c.pgo.props()...)
432 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800433 if c.xom != nil {
434 c.AddProperties(c.xom.props()...)
435 }
Colin Crossca860ac2016-01-04 14:34:37 -0800436 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700437 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800438 }
Colin Crossc472d572015-03-17 15:06:21 -0700439
Colin Crossa9d8bee2018-10-02 13:59:46 -0700440 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
441 switch class {
442 case android.Device:
443 return ctx.Config().DevicePrefer32BitExecutables()
444 case android.HostCross:
445 // Windows builds always prefer 32-bit
446 return true
447 default:
448 return false
449 }
450 })
Colin Cross36242852017-06-23 15:06:31 -0700451 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700452
Colin Cross1f44a3a2017-07-07 14:33:33 -0700453 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700454
Jiyong Park9d452992018-10-03 00:38:19 +0900455 android.InitApexModule(c)
456
Colin Cross36242852017-06-23 15:06:31 -0700457 return c
Colin Crossc472d572015-03-17 15:06:21 -0700458}
459
Colin Crossb916a382016-07-29 17:28:03 -0700460// Returns true for dependency roots (binaries)
461// TODO(ccross): also handle dlopenable libraries
462func (c *Module) isDependencyRoot() bool {
463 if root, ok := c.linker.(interface {
464 isDependencyRoot() bool
465 }); ok {
466 return root.isDependencyRoot()
467 }
468 return false
469}
470
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700471func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700472 return c.Properties.UseVndk
473}
474
Justin Yun8effde42017-06-23 19:24:43 +0900475func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800476 if vndkdep := c.vndkdep; vndkdep != nil {
477 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900478 }
479 return false
480}
481
Yi Kong7e53c572018-02-14 18:16:12 +0800482func (c *Module) isPgoCompile() bool {
483 if pgo := c.pgo; pgo != nil {
484 return pgo.Properties.PgoCompile
485 }
486 return false
487}
488
Logan Chienf3511742017-10-31 18:04:35 +0800489func (c *Module) isVndkSp() bool {
490 if vndkdep := c.vndkdep; vndkdep != nil {
491 return vndkdep.isVndkSp()
492 }
493 return false
494}
495
496func (c *Module) isVndkExt() bool {
497 if vndkdep := c.vndkdep; vndkdep != nil {
498 return vndkdep.isVndkExt()
499 }
500 return false
501}
502
503func (c *Module) getVndkExtendsModuleName() string {
504 if vndkdep := c.vndkdep; vndkdep != nil {
505 return vndkdep.getVndkExtendsModuleName()
506 }
507 return ""
508}
509
Jiyong Park82e2bf32017-08-16 14:05:54 +0900510// Returns true only when this module is configured to have core and vendor
511// variants.
512func (c *Module) hasVendorVariant() bool {
513 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
514}
515
Jiyong Parkf9332f12018-02-01 00:54:12 +0900516func (c *Module) inRecovery() bool {
517 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
518}
519
520func (c *Module) onlyInRecovery() bool {
521 return c.ModuleBase.InstallInRecovery()
522}
523
Jiyong Park25fc6a92018-11-18 18:02:45 +0900524func (c *Module) IsStubs() bool {
525 if library, ok := c.linker.(*libraryDecorator); ok {
526 return library.buildStubs()
527 }
528 return false
529}
530
531func (c *Module) HasStubsVariants() bool {
532 if library, ok := c.linker.(*libraryDecorator); ok {
533 return len(library.Properties.Stubs.Versions) > 0
534 }
535 return false
536}
537
Colin Crossca860ac2016-01-04 14:34:37 -0800538type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700539 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800540 moduleContextImpl
541}
542
Colin Cross37047f12016-12-13 17:06:13 -0800543type depsContext struct {
544 android.BottomUpMutatorContext
545 moduleContextImpl
546}
547
Colin Crossca860ac2016-01-04 14:34:37 -0800548type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700549 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800550 moduleContextImpl
551}
552
Jiyong Park2db76922017-11-08 16:03:48 +0900553func (ctx *moduleContext) SocSpecific() bool {
554 return ctx.ModuleContext.SocSpecific() ||
555 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700556}
557
Colin Crossca860ac2016-01-04 14:34:37 -0800558type moduleContextImpl struct {
559 mod *Module
560 ctx BaseModuleContext
561}
562
Colin Crossb98c8b02016-07-29 13:44:28 -0700563func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800564 return ctx.mod.toolchain(ctx.ctx)
565}
566
567func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000568 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800569}
570
571func (ctx *moduleContextImpl) staticBinary() bool {
Colin Crossb916a382016-07-29 17:28:03 -0700572 if static, ok := ctx.mod.linker.(interface {
573 staticBinary() bool
574 }); ok {
575 return static.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800576 }
Colin Crossb916a382016-07-29 17:28:03 -0700577 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800578}
579
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700580func (ctx *moduleContextImpl) useSdk() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900581 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() {
Nan Zhang0007d812017-11-07 10:57:05 -0800582 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700583 }
584 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800585}
586
587func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700588 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700589 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900590 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700591 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900592 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
593 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
594 return "current"
595 }
596 return platform_vndk_ver
597 }
598 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800599 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900600 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700601 }
602 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800603}
604
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700605func (ctx *moduleContextImpl) useVndk() bool {
606 return ctx.mod.useVndk()
607}
Justin Yun8effde42017-06-23 19:24:43 +0900608
Logan Chienf3511742017-10-31 18:04:35 +0800609func (ctx *moduleContextImpl) isVndk() bool {
610 return ctx.mod.isVndk()
611}
612
Yi Kong7e53c572018-02-14 18:16:12 +0800613func (ctx *moduleContextImpl) isPgoCompile() bool {
614 return ctx.mod.isPgoCompile()
615}
616
Justin Yun8effde42017-06-23 19:24:43 +0900617func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800618 return ctx.mod.isVndkSp()
619}
620
621func (ctx *moduleContextImpl) isVndkExt() bool {
622 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900623}
624
Jiyong Parkf9332f12018-02-01 00:54:12 +0900625func (ctx *moduleContextImpl) inRecovery() bool {
626 return ctx.mod.inRecovery()
627}
628
Logan Chien2f2b8902018-07-10 15:01:19 +0800629// Check whether ABI dumps should be created for this module.
630func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
631 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
632 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800633 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800634 if sanitize := ctx.mod.sanitize; sanitize != nil {
635 if !sanitize.isVariantOnProductionDevice() {
636 return false
637 }
638 }
639 if !ctx.ctx.Device() {
640 // Host modules do not need ABI dumps.
641 return false
642 }
Logan Chienfa478c02018-12-28 16:25:39 +0800643 if !ctx.mod.IsForPlatform() {
644 // APEX variants do not need ABI dumps.
645 return false
646 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800647 if inList(ctx.baseModuleName(), llndkLibraries) {
648 return true
649 }
Logan Chienf4b79c62018-08-02 02:27:02 +0800650 if inList(ctx.baseModuleName(), ndkMigratedLibs) {
651 return true
652 }
Logan Chien2f2b8902018-07-10 15:01:19 +0800653 if ctx.useVndk() && ctx.isVndk() {
654 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
655 // VNDK-private.
656 return Bool(ctx.mod.VendorProperties.Vendor_available) || ctx.isVndkExt()
657 }
658 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800659}
660
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700661func (ctx *moduleContextImpl) selectedStl() string {
662 if stl := ctx.mod.stl; stl != nil {
663 return stl.Properties.SelectedStl
664 }
665 return ""
666}
667
Ivan Lozanobd721262018-11-27 14:33:03 -0800668func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
669 return ctx.mod.linker.useClangLld(actx)
670}
671
Colin Crossce75d2c2016-10-06 16:12:58 -0700672func (ctx *moduleContextImpl) baseModuleName() string {
673 return ctx.mod.ModuleBase.BaseModuleName()
674}
675
Logan Chienf3511742017-10-31 18:04:35 +0800676func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
677 return ctx.mod.getVndkExtendsModuleName()
678}
679
Jiyong Park25fc6a92018-11-18 18:02:45 +0900680// Tests if this module is built for APEX
681func (ctx *moduleContextImpl) isApex() bool {
682 return ctx.mod.ApexName() != ""
683}
684
Jiyong Parkb0788572018-12-20 22:10:17 +0900685func (ctx *moduleContextImpl) hasStubsVariants() bool {
686 return ctx.mod.HasStubsVariants()
687}
688
689func (ctx *moduleContextImpl) isStubs() bool {
690 return ctx.mod.IsStubs()
691}
692
Colin Cross635c3b02016-05-18 15:37:25 -0700693func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800694 return &Module{
695 hod: hod,
696 multilib: multilib,
697 }
698}
699
Colin Cross635c3b02016-05-18 15:37:25 -0700700func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800701 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700702 module.features = []feature{
703 &tidyFeature{},
704 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700705 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800706 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800707 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800708 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900709 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700710 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700711 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800712 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800713 return module
714}
715
Colin Crossce75d2c2016-10-06 16:12:58 -0700716func (c *Module) Prebuilt() *android.Prebuilt {
717 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
718 return p.prebuilt()
719 }
720 return nil
721}
722
723func (c *Module) Name() string {
724 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700725 if p, ok := c.linker.(interface {
726 Name(string) string
727 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700728 name = p.Name(name)
729 }
730 return name
731}
732
Jeff Gaston294356f2017-09-27 17:05:30 -0700733// orderDeps reorders dependencies into a list such that if module A depends on B, then
734// A will precede B in the resultant list.
735// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800736// Note that directSharedDeps should be the analogous static library for each shared lib dep
737func 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 -0700738 // If A depends on B, then
739 // Every list containing A will also contain B later in the list
740 // So, after concatenating all lists, the final instance of B will have come from the same
741 // original list as the final instance of A
742 // So, the final instance of B will be later in the concatenation than the final A
743 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
744 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800745 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700746 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800747 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
748 }
749 for _, dep := range directSharedDeps {
750 orderedAllDeps = append(orderedAllDeps, dep)
751 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700752 }
753
Colin Crossb6715442017-10-24 11:13:31 -0700754 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700755
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800756 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700757 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800758 // resultant list to only what the caller has chosen to include in directStaticDeps
759 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700760
761 return orderedAllDeps, orderedDeclaredDeps
762}
763
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800764func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
765 // convert Module to Path
766 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
767 staticDepFiles := []android.Path{}
768 for _, dep := range staticDeps {
769 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
770 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700771 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800772 sharedDepFiles := []android.Path{}
773 for _, sharedDep := range sharedDeps {
774 staticAnalogue := sharedDep.staticVariant
775 if staticAnalogue != nil {
776 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
777 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
778 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700779 }
780
781 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800782 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700783
784 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700785}
786
Colin Cross635c3b02016-05-18 15:37:25 -0700787func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800788 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700789 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800790 moduleContextImpl: moduleContextImpl{
791 mod: c,
792 },
793 }
794 ctx.ctx = ctx
795
Colin Crossf18e1102017-11-16 14:33:08 -0800796 deps := c.depsToPaths(ctx)
797 if ctx.Failed() {
798 return
799 }
800
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700801 if c.Properties.Clang != nil && *c.Properties.Clang == false {
802 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
803 }
804
Colin Crossca860ac2016-01-04 14:34:37 -0800805 flags := Flags{
806 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800807 }
Colin Crossca860ac2016-01-04 14:34:37 -0800808 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800809 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800810 }
811 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700812 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800813 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700814 if c.stl != nil {
815 flags = c.stl.flags(ctx, flags)
816 }
Colin Cross16b23492016-01-06 14:41:07 -0800817 if c.sanitize != nil {
818 flags = c.sanitize.flags(ctx, flags)
819 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800820 if c.coverage != nil {
821 flags = c.coverage.flags(ctx, flags)
822 }
Stephen Craneba090d12017-05-09 15:44:35 -0700823 if c.lto != nil {
824 flags = c.lto.flags(ctx, flags)
825 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700826 if c.pgo != nil {
827 flags = c.pgo.flags(ctx, flags)
828 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800829 if c.xom != nil {
830 flags = c.xom.flags(ctx, flags)
831 }
Colin Crossca860ac2016-01-04 14:34:37 -0800832 for _, feature := range c.features {
833 flags = feature.flags(ctx, flags)
834 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800835 if ctx.Failed() {
836 return
837 }
838
Colin Crossb98c8b02016-07-29 13:44:28 -0700839 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
840 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
841 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800842
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800843 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
844 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700845 // We need access to all the flags seen by a source file.
846 if c.sabi != nil {
847 flags = c.sabi.flags(ctx, flags)
848 }
Colin Crossca860ac2016-01-04 14:34:37 -0800849 // Optimization to reduce size of build.ninja
850 // Replace the long list of flags for each file with a module-local variable
851 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
852 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
853 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
854 flags.CFlags = []string{"$cflags"}
855 flags.CppFlags = []string{"$cppflags"}
856 flags.AsFlags = []string{"$asflags"}
857
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700858 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800859 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700860 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800861 if ctx.Failed() {
862 return
863 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800864 }
865
Colin Crossca860ac2016-01-04 14:34:37 -0800866 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700867 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800868 if ctx.Failed() {
869 return
870 }
Colin Cross635c3b02016-05-18 15:37:25 -0700871 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900872
873 // If a lib is directly included in any of the APEXes, unhide the stubs
874 // variant having the latest version gets visible to make. In addition,
875 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
876 // force anything in the make world to link against the stubs library.
877 // (unless it is explicitly referenced via .bootstrap suffix or the
878 // module is marked with 'bootstrap: true').
879 if c.HasStubsVariants() && android.DirectlyInAnyApex(ctx.baseModuleName()) &&
880 !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
881 c.Properties.HideFromMake = false // unhide
882 // Note: this is still non-installable
883 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700884 }
Colin Cross5049f022015-03-18 13:28:46 -0700885
Jiyong Park9d452992018-10-03 00:38:19 +0900886 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700887 c.installer.install(ctx, c.outputFile.Path())
888 if ctx.Failed() {
889 return
Colin Crossca860ac2016-01-04 14:34:37 -0800890 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700891 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800892}
893
Colin Crossb98c8b02016-07-29 13:44:28 -0700894func (c *Module) toolchain(ctx BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800895 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700896 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800897 }
Colin Crossca860ac2016-01-04 14:34:37 -0800898 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800899}
900
Colin Crossca860ac2016-01-04 14:34:37 -0800901func (c *Module) begin(ctx BaseModuleContext) {
902 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700903 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700904 }
Colin Crossca860ac2016-01-04 14:34:37 -0800905 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700906 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800907 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700908 if c.stl != nil {
909 c.stl.begin(ctx)
910 }
Colin Cross16b23492016-01-06 14:41:07 -0800911 if c.sanitize != nil {
912 c.sanitize.begin(ctx)
913 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800914 if c.coverage != nil {
915 c.coverage.begin(ctx)
916 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800917 if c.sabi != nil {
918 c.sabi.begin(ctx)
919 }
Justin Yun8effde42017-06-23 19:24:43 +0900920 if c.vndkdep != nil {
921 c.vndkdep.begin(ctx)
922 }
Stephen Craneba090d12017-05-09 15:44:35 -0700923 if c.lto != nil {
924 c.lto.begin(ctx)
925 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700926 if c.pgo != nil {
927 c.pgo.begin(ctx)
928 }
Colin Crossca860ac2016-01-04 14:34:37 -0800929 for _, feature := range c.features {
930 feature.begin(ctx)
931 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700932 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -0700933 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700934 if err != nil {
935 ctx.PropertyErrorf("sdk_version", err.Error())
936 }
Nan Zhang0007d812017-11-07 10:57:05 -0800937 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -0700938 }
Colin Crossca860ac2016-01-04 14:34:37 -0800939}
940
Colin Cross37047f12016-12-13 17:06:13 -0800941func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -0700942 deps := Deps{}
943
944 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700945 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700946 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000947 // Add the PGO dependency (the clang_rt.profile runtime library), which
948 // sometimes depends on symbols from libgcc, before libgcc gets added
949 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -0700950 if c.pgo != nil {
951 deps = c.pgo.deps(ctx, deps)
952 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700953 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700954 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -0700955 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700956 if c.stl != nil {
957 deps = c.stl.deps(ctx, deps)
958 }
Colin Cross16b23492016-01-06 14:41:07 -0800959 if c.sanitize != nil {
960 deps = c.sanitize.deps(ctx, deps)
961 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +0000962 if c.coverage != nil {
963 deps = c.coverage.deps(ctx, deps)
964 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800965 if c.sabi != nil {
966 deps = c.sabi.deps(ctx, deps)
967 }
Justin Yun8effde42017-06-23 19:24:43 +0900968 if c.vndkdep != nil {
969 deps = c.vndkdep.deps(ctx, deps)
970 }
Stephen Craneba090d12017-05-09 15:44:35 -0700971 if c.lto != nil {
972 deps = c.lto.deps(ctx, deps)
973 }
Colin Crossc99deeb2016-04-11 15:06:20 -0700974 for _, feature := range c.features {
975 deps = feature.deps(ctx, deps)
976 }
977
Colin Crossb6715442017-10-24 11:13:31 -0700978 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
979 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
980 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
981 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
982 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
983 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +0800984 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -0700985
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700986 for _, lib := range deps.ReexportSharedLibHeaders {
987 if !inList(lib, deps.SharedLibs) {
988 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
989 }
990 }
991
992 for _, lib := range deps.ReexportStaticLibHeaders {
993 if !inList(lib, deps.StaticLibs) {
994 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
995 }
996 }
997
Colin Cross5950f382016-12-13 12:50:57 -0800998 for _, lib := range deps.ReexportHeaderLibHeaders {
999 if !inList(lib, deps.HeaderLibs) {
1000 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1001 }
1002 }
1003
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001004 for _, gen := range deps.ReexportGeneratedHeaders {
1005 if !inList(gen, deps.GeneratedHeaders) {
1006 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1007 }
1008 }
1009
Colin Crossc99deeb2016-04-11 15:06:20 -07001010 return deps
1011}
1012
Dan Albert7e9d2952016-08-04 13:02:36 -07001013func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001014 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001015 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001016 moduleContextImpl: moduleContextImpl{
1017 mod: c,
1018 },
1019 }
1020 ctx.ctx = ctx
1021
Colin Crossca860ac2016-01-04 14:34:37 -08001022 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001023}
1024
Jiyong Park7ed9de32018-10-15 22:25:07 +09001025// Split name#version into name and version
1026func stubsLibNameAndVersion(name string) (string, string) {
1027 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1028 version := name[sharp+1:]
1029 libname := name[:sharp]
1030 return libname, version
1031 }
1032 return name, ""
1033}
1034
Colin Cross1e676be2016-10-12 14:38:15 -07001035func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001036 ctx := &depsContext{
1037 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001038 moduleContextImpl: moduleContextImpl{
1039 mod: c,
1040 },
1041 }
1042 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001043
Colin Crossc99deeb2016-04-11 15:06:20 -07001044 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001045
Dan Albert914449f2016-06-17 16:45:24 -07001046 variantNdkLibs := []string{}
1047 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001048 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001049 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001050
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001051 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1052 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001053 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001054 // 1. Name of an NDK library that refers to a prebuilt module.
1055 // For each of these, it adds the name of the prebuilt module (which will be in
1056 // prebuilts/ndk) to the list of nonvariant libs.
1057 // 2. Name of an NDK library that refers to an ndk_library module.
1058 // For each of these, it adds the name of the ndk_library module to the list of
1059 // variant libs.
1060 // 3. Anything else (so anything that isn't an NDK library).
1061 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001062 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001063 // The caller can then know to add the variantLibs dependencies differently from the
1064 // nonvariantLibs
1065 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1066 variantLibs = []string{}
1067 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001068 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001069 // strip #version suffix out
1070 name, _ := stubsLibNameAndVersion(entry)
1071 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1072 if !inList(name, ndkMigratedLibs) {
1073 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001074 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001075 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001076 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001077 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1078 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1079 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1080 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001081 if actx.OtherModuleExists(vendorPublicLib) {
1082 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1083 } else {
1084 // This can happen if vendor_public_library module is defined in a
1085 // namespace that isn't visible to the current module. In that case,
1086 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001087 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001088 }
Dan Albert914449f2016-06-17 16:45:24 -07001089 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001090 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001091 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001092 }
1093 }
Dan Albert914449f2016-06-17 16:45:24 -07001094 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001095 }
1096
Dan Albert914449f2016-06-17 16:45:24 -07001097 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1098 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001099 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001100 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001101
Jiyong Park7ed9de32018-10-15 22:25:07 +09001102 if c.linker != nil {
1103 if library, ok := c.linker.(*libraryDecorator); ok {
1104 if library.buildStubs() {
1105 // Stubs lib does not have dependency to other libraries. Don't proceed.
1106 return
1107 }
1108 }
1109 }
1110
Colin Cross32ec36c2016-12-15 07:39:51 -08001111 for _, lib := range deps.HeaderLibs {
1112 depTag := headerDepTag
1113 if inList(lib, deps.ReexportHeaderLibHeaders) {
1114 depTag = headerExportDepTag
1115 }
1116 actx.AddVariationDependencies(nil, depTag, lib)
1117 }
Colin Cross5950f382016-12-13 12:50:57 -08001118
Dan Willemsen59339a22018-07-22 21:18:45 -07001119 actx.AddVariationDependencies([]blueprint.Variation{
1120 {Mutator: "link", Variation: "static"},
1121 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001122
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001123 for _, lib := range deps.StaticLibs {
1124 depTag := staticDepTag
1125 if inList(lib, deps.ReexportStaticLibHeaders) {
1126 depTag = staticExportDepTag
1127 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001128 actx.AddVariationDependencies([]blueprint.Variation{
1129 {Mutator: "link", Variation: "static"},
1130 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001131 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001132
Dan Willemsen59339a22018-07-22 21:18:45 -07001133 actx.AddVariationDependencies([]blueprint.Variation{
1134 {Mutator: "link", Variation: "static"},
1135 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001136
Jiyong Park25fc6a92018-11-18 18:02:45 +09001137 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1138 var variations []blueprint.Variation
1139 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001140 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001141 if version != "" && versionVariantAvail {
1142 // Version is explicitly specified. i.e. libFoo#30
1143 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1144 depTag.explicitlyVersioned = true
1145 }
1146 actx.AddVariationDependencies(variations, depTag, name)
1147
1148 // If the version is not specified, add dependency to the latest stubs library.
1149 // The stubs library will be used when the depending module is built for APEX and
1150 // the dependent module is not in the same APEX.
1151 latestVersion := latestStubsVersionFor(actx.Config(), name)
1152 if version == "" && latestVersion != "" && versionVariantAvail {
1153 actx.AddVariationDependencies([]blueprint.Variation{
1154 {Mutator: "link", Variation: "shared"},
1155 {Mutator: "version", Variation: latestVersion},
1156 }, depTag, name)
1157 // Note that depTag.explicitlyVersioned is false in this case.
1158 }
1159 }
1160
Jiyong Park7ed9de32018-10-15 22:25:07 +09001161 // shared lib names without the #version suffix
1162 var sharedLibNames []string
1163
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001164 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001165 name, version := stubsLibNameAndVersion(lib)
1166 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001167 depTag := sharedDepTag
1168 if inList(lib, deps.ReexportSharedLibHeaders) {
1169 depTag = sharedExportDepTag
1170 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001171 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001172 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001173
Jiyong Park7ed9de32018-10-15 22:25:07 +09001174 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001175 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001176 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1177 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1178 // linking against both the stubs lib and the non-stubs lib at the same time.
1179 continue
1180 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001181 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001182 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001183
Dan Willemsen59339a22018-07-22 21:18:45 -07001184 actx.AddVariationDependencies([]blueprint.Variation{
1185 {Mutator: "link", Variation: "shared"},
1186 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001187
Colin Cross68861832016-07-08 10:41:41 -07001188 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001189
1190 for _, gen := range deps.GeneratedHeaders {
1191 depTag := genHeaderDepTag
1192 if inList(gen, deps.ReexportGeneratedHeaders) {
1193 depTag = genHeaderExportDepTag
1194 }
1195 actx.AddDependency(c, depTag, gen)
1196 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001197
Colin Cross42d48b72018-08-29 14:10:52 -07001198 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001199
1200 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001201 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001202 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001203 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001204 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001205 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001206 if deps.LinkerFlagsFile != "" {
1207 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1208 }
1209 if deps.DynamicLinker != "" {
1210 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001211 }
Dan Albert914449f2016-06-17 16:45:24 -07001212
1213 version := ctx.sdkVersion()
1214 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001215 {Mutator: "ndk_api", Variation: version},
1216 {Mutator: "link", Variation: "shared"},
1217 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001218 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001219 {Mutator: "ndk_api", Variation: version},
1220 {Mutator: "link", Variation: "shared"},
1221 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001222
1223 if vndkdep := c.vndkdep; vndkdep != nil {
1224 if vndkdep.isVndkExt() {
1225 baseModuleMode := vendorMode
1226 if actx.DeviceConfig().VndkVersion() == "" {
1227 baseModuleMode = coreMode
1228 }
1229 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001230 {Mutator: "image", Variation: baseModuleMode},
1231 {Mutator: "link", Variation: "shared"},
1232 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001233 }
1234 }
Colin Cross6362e272015-10-29 15:25:03 -07001235}
Colin Cross21b9a242015-03-24 14:15:58 -07001236
Colin Crosse40b4ea2018-10-02 22:25:58 -07001237func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001238 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1239 c.beginMutator(ctx)
1240 }
1241}
1242
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001243// Whether a module can link to another module, taking into
1244// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001245func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001246 if from.Target().Os != android.Android {
1247 // Host code is not restricted
1248 return
1249 }
1250 if from.Properties.UseVndk {
1251 // Though vendor code is limited by the vendor mutator,
1252 // each vendor-available module needs to check
1253 // link-type for VNDK.
1254 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001255 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001256 }
1257 return
1258 }
Nan Zhang0007d812017-11-07 10:57:05 -08001259 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001260 // Platform code can link to anything
1261 return
1262 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001263 if from.inRecovery() {
1264 // Recovery code is not NDK
1265 return
1266 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001267 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1268 // These are always allowed
1269 return
1270 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001271 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1272 // These are allowed, but they don't set sdk_version
1273 return
1274 }
1275 if _, ok := to.linker.(*stubDecorator); ok {
1276 // These aren't real libraries, but are the stub shared libraries that are included in
1277 // the NDK.
1278 return
1279 }
Nan Zhang0007d812017-11-07 10:57:05 -08001280 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001281 // NDK code linking to platform code is never okay.
1282 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1283 ctx.OtherModuleName(to))
1284 }
1285
1286 // At this point we know we have two NDK libraries, but we need to
1287 // check that we're not linking against anything built against a higher
1288 // API level, as it is only valid to link against older or equivalent
1289 // APIs.
1290
Inseob Kim01a28722018-04-11 09:48:45 +09001291 // Current can link against anything.
1292 if String(from.Properties.Sdk_version) != "current" {
1293 // Otherwise we need to check.
1294 if String(to.Properties.Sdk_version) == "current" {
1295 // Current can't be linked against by anything else.
1296 ctx.ModuleErrorf("links %q built against newer API version %q",
1297 ctx.OtherModuleName(to), "current")
1298 } else {
1299 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1300 if err != nil {
1301 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001302 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001303 String(from.Properties.Sdk_version))
1304 }
1305 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1306 if err != nil {
1307 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001308 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001309 String(to.Properties.Sdk_version))
1310 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001311
Inseob Kim01a28722018-04-11 09:48:45 +09001312 if toApi > fromApi {
1313 ctx.ModuleErrorf("links %q built against newer API version %q",
1314 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1315 }
1316 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001317 }
Dan Albert202fe492017-12-15 13:56:59 -08001318
1319 // Also check that the two STL choices are compatible.
1320 fromStl := from.stl.Properties.SelectedStl
1321 toStl := to.stl.Properties.SelectedStl
1322 if fromStl == "" || toStl == "" {
1323 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001324 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001325 // We can be permissive with the system "STL" since it is only the C++
1326 // ABI layer, but in the future we should make sure that everyone is
1327 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001328 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001329 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1330 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1331 to.stl.Properties.SelectedStl)
1332 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001333}
1334
Jiyong Park5fb8c102018-04-09 12:03:06 +09001335// Tests whether the dependent library is okay to be double loaded inside a single process.
1336// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1337// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1338// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1339func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1340 if _, ok := from.linker.(*libraryDecorator); !ok {
1341 return
1342 }
1343
1344 if inList(ctx.ModuleName(), llndkLibraries) ||
1345 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1346 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1347 depIsVndkSp := false
1348 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1349 depIsVndkSp = true
1350 }
1351 depIsVndk := false
1352 if to.vndkdep != nil && to.vndkdep.isVndk() {
1353 depIsVndk = true
1354 }
1355 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1356 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001357 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1358 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001359 ctx.OtherModuleName(to))
1360 }
1361 }
1362}
1363
Colin Crossc99deeb2016-04-11 15:06:20 -07001364// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001365func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001366 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001367
Jeff Gaston294356f2017-09-27 17:05:30 -07001368 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001369 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001370
Colin Crossd11fcda2017-10-23 17:59:01 -07001371 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001372 depName := ctx.OtherModuleName(dep)
1373 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001374
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001375 ccDep, _ := dep.(*Module)
1376 if ccDep == nil {
1377 // handling for a few module types that aren't cc Module but that are also supported
1378 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001379 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001380 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001381 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1382 genRule.GeneratedSourceFiles()...)
1383 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001384 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001385 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001386 // Support exported headers from a generated_sources dependency
1387 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001388 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001389 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001390 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001391 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001392 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001393 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001394 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001395 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001396 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001397 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001398 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1399 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1400
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001401 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001402 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001403 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001404 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001405 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001406 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001407 files := genRule.GeneratedSourceFiles()
1408 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001409 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001410 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001411 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 -07001412 }
1413 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001414 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001415 }
Colin Crossca860ac2016-01-04 14:34:37 -08001416 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001417 return
1418 }
1419
Colin Crossd11fcda2017-10-23 17:59:01 -07001420 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001421 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1422 return
1423 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001424 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001425 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001426 return
1427 }
1428
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001429 // re-exporting flags
1430 if depTag == reuseObjTag {
1431 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001432 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001433 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001434 depPaths.Objs = depPaths.Objs.Append(objs)
1435 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001436 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001437 return
1438 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001439 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001440
1441 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1442 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1443 // won't be matched to sharedDepTag and lateSharedDepTag.
1444 explicitlyVersioned := false
1445 if t, ok := depTag.(dependencyTag); ok {
1446 explicitlyVersioned = t.explicitlyVersioned
1447 t.explicitlyVersioned = false
1448 depTag = t
1449 }
1450
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001451 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001452 depIsStatic := false
1453 switch depTag {
1454 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1455 depIsStatic = true
1456 }
1457 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001458 depIsStubs := dependentLibrary.buildStubs()
1459 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001460 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
1461 depInPlatform := !android.DirectlyInAnyApex(depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001462
1463 var useThisDep bool
1464 if depIsStubs && explicitlyVersioned {
1465 // Always respect dependency to the versioned stubs (i.e. libX#10)
1466 useThisDep = true
1467 } else if !depHasStubs {
1468 // Use non-stub variant if that is the only choice
1469 // (i.e. depending on a lib without stubs.version property)
1470 useThisDep = true
1471 } else if c.IsForPlatform() {
1472 // If not building for APEX, use stubs only when it is from
1473 // an APEX (and not from platform)
1474 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parkb0788572018-12-20 22:10:17 +09001475 if c.inRecovery() || Bool(c.Properties.Bootstrap) {
1476 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001477 // always link to non-stub variant
1478 useThisDep = !depIsStubs
1479 }
1480 } else {
1481 // If building for APEX, use stubs only when it is not from
1482 // the same APEX
1483 useThisDep = (depInSameApex != depIsStubs)
1484 }
1485
1486 if !useThisDep {
1487 return // stop processing this dep
1488 }
1489 }
1490
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001491 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001492 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001493 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001494 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001495 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001496
1497 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001498 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001499 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001500 // 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 -07001501 // Re-exported shared library headers must be included as well since they can help us with type information
1502 // about template instantiations (instantiated from their headers).
1503 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001504 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001505 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001506
Logan Chienf3511742017-10-31 18:04:35 +08001507 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001508 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001509 }
1510
Colin Cross26c34ed2016-09-30 17:10:16 -07001511 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001512 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001513
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001514 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001515 depFile := android.OptionalPath{}
1516
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001517 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001518 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001519 ptr = &depPaths.SharedLibs
1520 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001521 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001522 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001523 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001524 ptr = &depPaths.LateSharedLibs
1525 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001526 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001527 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001528 ptr = nil
1529 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001530 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001531 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001532 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001533 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001534 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001535 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001536 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001537 return
1538 }
1539
1540 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001541 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001542 for i := range missingDeps {
1543 missingDeps[i] += postfix
1544 }
1545 ctx.AddMissingDependencies(missingDeps)
1546 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001547 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001548 case headerDepTag:
1549 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001550 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001551 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001552 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001553 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001554 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001555 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001556 case dynamicLinkerDepTag:
1557 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001558 }
1559
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001560 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001561 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001562 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001563 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001564 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001565 return
1566 }
1567
1568 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001569 // in static libraries act as if they were whole static libraries. The same goes for
1570 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001571 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1572 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001573 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1574 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001575
Dan Willemsen581341d2017-02-09 16:16:31 -08001576 }
1577
Colin Cross26c34ed2016-09-30 17:10:16 -07001578 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001579 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001580 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001581 return
1582 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001583 *ptr = append(*ptr, linkFile.Path())
1584 }
1585
Colin Crossc99deeb2016-04-11 15:06:20 -07001586 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001587 dep := depFile
1588 if !dep.Valid() {
1589 dep = linkFile
1590 }
1591 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001592 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001593
Logan Chien43d34c32017-12-20 01:17:32 +08001594 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001595 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001596 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001597 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001598 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001599 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001600 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1601 if c.useVndk() && bothVendorAndCoreVariantsExist {
1602 // The vendor module in Make will have been renamed to not conflict with the core
1603 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001604 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001605 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001606 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001607 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1608 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001609 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001610 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001611 }
Logan Chien43d34c32017-12-20 01:17:32 +08001612 }
1613
1614 // Export the shared libs to Make.
1615 switch depTag {
1616 case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001617 // Dependency to the stubs lib which is already included in an APEX
1618 // is not added to the androidmk dependency
1619 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001620 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001621 // Also add the dependency to the APEX(es) providing the library so that
1622 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001623 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001624 c.Properties.ApexesProvidingSharedLibs = append(
1625 c.Properties.ApexesProvidingSharedLibs, an)
1626 }
1627 break
1628 }
1629 }
1630
Jiyong Park27b188b2017-07-18 13:23:39 +09001631 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001632 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001633 c.Properties.AndroidMkSharedLibs = append(
1634 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001635 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1636 c.Properties.AndroidMkStaticLibs = append(
1637 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001638 case runtimeDepTag:
1639 c.Properties.AndroidMkRuntimeLibs = append(
1640 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001641 case wholeStaticDepTag:
1642 c.Properties.AndroidMkWholeStaticLibs = append(
1643 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001644 }
Colin Crossca860ac2016-01-04 14:34:37 -08001645 })
1646
Jeff Gaston294356f2017-09-27 17:05:30 -07001647 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001648 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001649
Colin Crossdd84e052017-05-17 13:44:16 -07001650 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001651 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001652 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001653 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001654 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1655
1656 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001657 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001658 }
Colin Crossdd84e052017-05-17 13:44:16 -07001659
Colin Crossca860ac2016-01-04 14:34:37 -08001660 return depPaths
1661}
1662
1663func (c *Module) InstallInData() bool {
1664 if c.installer == nil {
1665 return false
1666 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001667 return c.installer.inData()
1668}
1669
1670func (c *Module) InstallInSanitizerDir() bool {
1671 if c.installer == nil {
1672 return false
1673 }
1674 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001675 return true
1676 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001677 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001678}
1679
Jiyong Parkf9332f12018-02-01 00:54:12 +09001680func (c *Module) InstallInRecovery() bool {
1681 return c.inRecovery()
1682}
1683
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001684func (c *Module) HostToolPath() android.OptionalPath {
1685 if c.installer == nil {
1686 return android.OptionalPath{}
1687 }
1688 return c.installer.hostToolPath()
1689}
1690
Nan Zhangd4e641b2017-07-12 12:55:28 -07001691func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1692 return c.outputFile
1693}
1694
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001695func (c *Module) Srcs() android.Paths {
1696 if c.outputFile.Valid() {
1697 return android.Paths{c.outputFile.Path()}
1698 }
1699 return android.Paths{}
1700}
1701
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001702func (c *Module) static() bool {
1703 if static, ok := c.linker.(interface {
1704 static() bool
1705 }); ok {
1706 return static.static()
1707 }
1708 return false
1709}
1710
Colin Crossb60190a2018-09-04 16:28:17 -07001711func (c *Module) getMakeLinkType() string {
1712 if c.useVndk() {
1713 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1714 if inList(c.Name(), vndkPrivateLibraries) {
1715 return "native:vndk_private"
1716 } else {
1717 return "native:vndk"
1718 }
1719 } else {
1720 return "native:vendor"
1721 }
1722 } else if c.inRecovery() {
1723 return "native:recovery"
1724 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1725 return "native:ndk:none:none"
1726 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1727 //family, link := getNdkStlFamilyAndLinkType(c)
1728 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1729 } else {
1730 return "native:platform"
1731 }
1732}
1733
Jiyong Park9d452992018-10-03 00:38:19 +09001734// Overrides ApexModule.IsInstallabeToApex()
1735// Only shared libraries are installable to APEX.
1736func (c *Module) IsInstallableToApex() bool {
1737 if shared, ok := c.linker.(interface {
1738 shared() bool
1739 }); ok {
1740 return shared.shared()
1741 }
1742 return false
1743}
1744
Colin Cross2ba19d92015-05-07 15:44:20 -07001745//
Colin Crosscfad1192015-11-02 16:43:11 -08001746// Defaults
1747//
Colin Crossca860ac2016-01-04 14:34:37 -08001748type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001749 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001750 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001751 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001752}
1753
Colin Cross635c3b02016-05-18 15:37:25 -07001754func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001755}
1756
Colin Cross1e676be2016-10-12 14:38:15 -07001757func (d *Defaults) DepsMutator(ctx android.BottomUpMutatorContext) {
1758}
1759
Colin Cross36242852017-06-23 15:06:31 -07001760func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001761 return DefaultsFactory()
1762}
1763
Colin Cross36242852017-06-23 15:06:31 -07001764func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001765 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001766
Colin Cross36242852017-06-23 15:06:31 -07001767 module.AddProperties(props...)
1768 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001769 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001770 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001771 &BaseCompilerProperties{},
1772 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001773 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001774 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001775 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001776 &TestProperties{},
1777 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001778 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001779 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001780 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001781 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001782 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001783 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001784 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001785 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001786 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001787 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001788 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001789 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001790 )
Colin Crosscfad1192015-11-02 16:43:11 -08001791
Colin Cross1f44a3a2017-07-07 14:33:33 -07001792 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001793 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001794
1795 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001796}
1797
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001798const (
1799 // coreMode is the variant used for framework-private libraries, or
1800 // SDK libraries. (which framework-private libraries can use)
1801 coreMode = "core"
1802
1803 // vendorMode is the variant used for /vendor code that compiles
1804 // against the VNDK.
1805 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001806
1807 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001808)
1809
Jiyong Park6a43f042017-10-12 23:05:00 +09001810func squashVendorSrcs(m *Module) {
1811 if lib, ok := m.compiler.(*libraryDecorator); ok {
1812 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1813 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1814
1815 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1816 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1817 }
1818}
1819
Jiyong Parkf9332f12018-02-01 00:54:12 +09001820func squashRecoverySrcs(m *Module) {
1821 if lib, ok := m.compiler.(*libraryDecorator); ok {
1822 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1823 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1824
1825 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1826 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1827 }
1828}
1829
Jiyong Parkda6eb592018-12-19 17:12:36 +09001830func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001831 if mctx.Os() != android.Android {
1832 return
1833 }
1834
Jiyong Park7ed9de32018-10-15 22:25:07 +09001835 if g, ok := mctx.Module().(*genrule.Module); ok {
1836 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001837 var coreVariantNeeded bool = false
1838 var vendorVariantNeeded bool = false
1839 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001840 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001841 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001842 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001843 coreVariantNeeded = true
1844 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001845 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001846 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001847 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001848 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001849 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001850 if Bool(props.Recovery_available) {
1851 recoveryVariantNeeded = true
1852 }
1853
Jiyong Park413cc742018-06-19 01:46:06 +09001854 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001855 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001856 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001857 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001858 recoveryVariantNeeded = false
1859 }
1860 }
1861
Jiyong Park3f736c92018-05-24 13:36:56 +09001862 var variants []string
1863 if coreVariantNeeded {
1864 variants = append(variants, coreMode)
1865 }
1866 if vendorVariantNeeded {
1867 variants = append(variants, vendorMode)
1868 }
1869 if recoveryVariantNeeded {
1870 variants = append(variants, recoveryMode)
1871 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001872 mod := mctx.CreateVariations(variants...)
1873 for i, v := range variants {
1874 if v == recoveryMode {
1875 m := mod[i].(*genrule.Module)
1876 m.Extra.(*GenruleExtraProperties).InRecovery = true
1877 }
1878 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001879 }
1880 }
1881
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001882 m, ok := mctx.Module().(*Module)
1883 if !ok {
1884 return
1885 }
1886
1887 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08001888 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09001889 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08001890
1891 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001892 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09001893 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001894 return
1895 }
Logan Chienf3511742017-10-31 18:04:35 +08001896
1897 if vndkdep := m.vndkdep; vndkdep != nil {
1898 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09001899 if productSpecific {
1900 mctx.PropertyErrorf("product_specific",
1901 "product_specific must not be true when `vndk: {enabled: true}`")
1902 return
1903 }
Logan Chienf3511742017-10-31 18:04:35 +08001904 if vendorSpecific {
1905 if !vndkdep.isVndkExt() {
1906 mctx.PropertyErrorf("vndk",
1907 "must set `extends: \"...\"` to vndk extension")
1908 return
1909 }
1910 } else {
1911 if vndkdep.isVndkExt() {
1912 mctx.PropertyErrorf("vndk",
1913 "must set `vendor: true` to set `extends: %q`",
1914 m.getVndkExtendsModuleName())
1915 return
1916 }
1917 if m.VendorProperties.Vendor_available == nil {
1918 mctx.PropertyErrorf("vndk",
1919 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
1920 return
1921 }
1922 }
1923 } else {
1924 if vndkdep.isVndkSp() {
1925 mctx.PropertyErrorf("vndk",
1926 "must set `enabled: true` to set `support_system_process: true`")
1927 return
1928 }
1929 if vndkdep.isVndkExt() {
1930 mctx.PropertyErrorf("vndk",
1931 "must set `enabled: true` to set `extends: %q`",
1932 m.getVndkExtendsModuleName())
1933 return
1934 }
Justin Yun8effde42017-06-23 19:24:43 +09001935 }
1936 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001937
Jiyong Parkf9332f12018-02-01 00:54:12 +09001938 var coreVariantNeeded bool = false
1939 var vendorVariantNeeded bool = false
1940 var recoveryVariantNeeded bool = false
1941
Justin Yun71549282017-11-17 12:10:28 +09001942 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001943 // If the device isn't compiling against the VNDK, we always
1944 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001945 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001946 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
1947 // LL-NDK stubs only exist in the vendor variant, since the
1948 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001949 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09001950 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
1951 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09001952 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09001953 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09001954 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
1955 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001956 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001957 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001958 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09001959 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001960 coreVariantNeeded = true
1961 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08001962 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09001963 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09001964 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001965 } else {
1966 // This is either in /system (or similar: /data), or is a
1967 // modules built with the NDK. Modules built with the NDK
1968 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09001969 coreVariantNeeded = true
1970 }
1971
1972 if Bool(m.Properties.Recovery_available) {
1973 recoveryVariantNeeded = true
1974 }
1975
1976 if m.ModuleBase.InstallInRecovery() {
1977 recoveryVariantNeeded = true
1978 coreVariantNeeded = false
1979 }
1980
Jiyong Park413cc742018-06-19 01:46:06 +09001981 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001982 primaryArch := mctx.Config().DevicePrimaryArchType()
1983 moduleArch := m.Target().Arch.ArchType
1984 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001985 recoveryVariantNeeded = false
1986 }
1987 }
1988
Jiyong Parkf9332f12018-02-01 00:54:12 +09001989 var variants []string
1990 if coreVariantNeeded {
1991 variants = append(variants, coreMode)
1992 }
1993 if vendorVariantNeeded {
1994 variants = append(variants, vendorMode)
1995 }
1996 if recoveryVariantNeeded {
1997 variants = append(variants, recoveryMode)
1998 }
1999 mod := mctx.CreateVariations(variants...)
2000 for i, v := range variants {
2001 if v == vendorMode {
2002 m := mod[i].(*Module)
2003 m.Properties.UseVndk = true
2004 squashVendorSrcs(m)
2005 } else if v == recoveryMode {
2006 m := mod[i].(*Module)
2007 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002008 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002009 squashRecoverySrcs(m)
2010 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002011 }
2012}
2013
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002014func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002015 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002016 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2017 }
Colin Cross6510f912017-11-29 00:27:14 -08002018 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002019}
2020
Colin Cross06a931b2015-10-28 17:23:31 -07002021var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002022var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002023var BoolPtr = proptools.BoolPtr
2024var String = proptools.String
2025var StringPtr = proptools.StringPtr