blob: 5a2f0ae728c9c49e9af9e782f7818fa958ae2833 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Dan Albert9e10cd42016-08-03 14:12:14 -070022 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080023 "strings"
24
Colin Cross97ba0732015-03-23 17:50:24 -070025 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070026 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070027
Colin Cross635c3b02016-05-18 15:37:25 -070028 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070029 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070030 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080031)
32
Colin Cross463a90e2015-06-17 14:20:06 -070033func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070034 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070035
Colin Cross1e676be2016-10-12 14:38:15 -070036 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090037 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070038 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090039 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070040 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
41 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090042 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070043 ctx.BottomUp("begin", BeginMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070044 })
Colin Cross16b23492016-01-06 14:41:07 -080045
Colin Cross1e676be2016-10-12 14:38:15 -070046 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
47 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
48 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080049
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070050 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
51 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
52
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000053 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
54 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
55
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080056 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
57 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
58
Colin Cross1e676be2016-10-12 14:38:15 -070059 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
60 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080061
Colin Cross6b753602018-06-21 13:03:07 -070062 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090063 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080064
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +000065 ctx.BottomUp("coverage", coverageLinkingMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080066 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070067
68 ctx.TopDown("lto_deps", ltoDepsMutator)
69 ctx.BottomUp("lto", ltoMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070070 })
Colin Crossb98c8b02016-07-29 13:44:28 -070071
72 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070073}
74
Colin Crossca860ac2016-01-04 14:34:37 -080075type Deps struct {
76 SharedLibs, LateSharedLibs []string
77 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080078 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080079 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070080
Colin Cross5950f382016-12-13 12:50:57 -080081 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070082
Colin Cross81413472016-04-11 14:37:39 -070083 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070084
Dan Willemsenb40aab62016-04-20 14:21:14 -070085 GeneratedSources []string
86 GeneratedHeaders []string
87
Dan Willemsenb3454ab2016-09-28 17:34:58 -070088 ReexportGeneratedHeaders []string
89
Colin Cross97ba0732015-03-23 17:50:24 -070090 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070091
92 // Used for host bionic
93 LinkerFlagsFile string
94 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070095}
96
Colin Crossca860ac2016-01-04 14:34:37 -080097type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -070098 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +090099 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700100 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900101 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700102 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700103 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Colin Cross26c34ed2016-09-30 17:10:16 -0700105 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700106 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800107 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700108 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700109
Colin Cross26c34ed2016-09-30 17:10:16 -0700110 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700111 GeneratedSources android.Paths
112 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700113
Dan Willemsen76f08272016-07-09 00:14:08 -0700114 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700115 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700116
Colin Cross26c34ed2016-09-30 17:10:16 -0700117 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700118 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700119
120 // Path to the file container flags to use with the linker
121 LinkerFlagsFile android.OptionalPath
122
123 // Path to the dynamic linker binary
124 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125}
126
Colin Crossca860ac2016-01-04 14:34:37 -0800127type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700128 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
129 ArFlags []string // Flags that apply to ar
130 AsFlags []string // Flags that apply to assembly source files
131 CFlags []string // Flags that apply to C and C++ source files
132 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
133 ConlyFlags []string // Flags that apply to C source files
134 CppFlags []string // Flags that apply to C++ source files
135 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
136 YaccFlags []string // Flags that apply to Yacc source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700137 aidlFlags []string // Flags that apply to aidl source files
138 rsFlags []string // Flags that apply to renderscript source files
139 LdFlags []string // Flags that apply to linker command lines
140 libFlags []string // Flags to add libraries early to the link order
141 TidyFlags []string // Flags that apply to clang-tidy
142 SAbiFlags []string // Flags that apply to header-abi-dumper
143 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700144
Colin Crossc3199482017-03-30 15:03:04 -0700145 // Global include flags that apply to C, C++, and assembly source files
146 // These must be after any module include flags, which will be in GlobalFlags.
147 SystemIncludeFlags []string
148
Colin Crossb98c8b02016-07-29 13:44:28 -0700149 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700150 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800151 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800152 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800153
154 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800155 DynamicLinker string
156
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700157 CFlagsDeps android.Paths // Files depended on by compiler flags
158 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800159
160 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800161
162 protoDeps android.Paths
163 protoFlags []string // Flags that apply to proto source files
164 protoOutTypeFlag string // The output type, --cpp_out for example
165 protoOutParams []string // Flags that modify the output of proto generated files
166 protoC bool // Whether to use C instead of C++
167 protoOptionsFile bool // Whether to look for a .options file next to the .proto
168 ProtoRoot bool
Colin Crossc472d572015-03-17 15:06:21 -0700169}
170
Colin Cross81413472016-04-11 14:37:39 -0700171type ObjectLinkerProperties struct {
172 // names of other cc_object modules to link into this module using partial linking
173 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700174
175 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800176 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700177}
178
Colin Crossca860ac2016-01-04 14:34:37 -0800179// Properties used to compile all C or C++ modules
180type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700181 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800182 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700183
184 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800185 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700186
Jiyong Parkde866cb2018-12-07 23:08:36 +0900187 AndroidMkSharedLibs []string `blueprint:"mutated"`
188 AndroidMkStaticLibs []string `blueprint:"mutated"`
189 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
190 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
191 HideFromMake bool `blueprint:"mutated"`
192 PreventInstall bool `blueprint:"mutated"`
193 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700194
195 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800196
197 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
198 // file
199 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900200
201 // Make this module available when building for recovery
202 Recovery_available *bool
203
204 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900205
206 // Allows this module to use non-APEX version of libraries. Useful
207 // for building binaries that are started before APEXes are activated.
208 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700209}
210
211type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900212 // whether this module should be allowed to be directly depended by other
213 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
214 // If set to true, two variants will be built separately, one like
215 // normal, and the other limited to the set of libraries and headers
216 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700217 //
218 // The vendor variant may be used with a different (newer) /system,
219 // so it shouldn't have any unversioned runtime dependencies, or
220 // make assumptions about the system that may not be true in the
221 // future.
222 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900223 // If set to false, this module becomes inaccessible from /vendor modules.
224 //
225 // Default value is true when vndk: {enabled: true} or vendor: true.
226 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700227 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
228 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900229
230 // whether this module is capable of being loaded with other instance
231 // (possibly an older version) of the same module in the same process.
232 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
233 // can be double loaded in a vendor process if the library is also a
234 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
235 // explicitly marked as `double_loadable: true` by the owner, or the dependency
236 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
237 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800238}
239
Colin Crossca860ac2016-01-04 14:34:37 -0800240type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800241 static() bool
242 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700243 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700244 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800245 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700246 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800247 isNdk() bool
248 isLlndk() bool
249 isLlndkPublic() bool
250 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900251 isVndk() bool
252 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800253 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900254 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800255 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700256 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700257 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800258 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800259 isPgoCompile() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800260 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900261 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900262 hasStubsVariants() bool
263 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900264 bootstrap() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800265}
266
267type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700268 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800269 ModuleContextIntf
270}
271
272type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700273 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800274 ModuleContextIntf
275}
276
Colin Cross37047f12016-12-13 17:06:13 -0800277type DepsContext interface {
278 android.BottomUpMutatorContext
279 ModuleContextIntf
280}
281
Colin Crossca860ac2016-01-04 14:34:37 -0800282type feature interface {
283 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800284 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800285 flags(ctx ModuleContext, flags Flags) Flags
286 props() []interface{}
287}
288
289type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700290 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800291 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800292 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700293 compilerProps() []interface{}
294
Colin Cross76fada02016-07-27 10:31:13 -0700295 appendCflags([]string)
296 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700297 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800298}
299
300type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700301 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800302 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700303 linkerFlags(ctx ModuleContext, flags Flags) Flags
304 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800305 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700306
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700307 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700308 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900309 unstrippedOutputFilePath() android.Path
Colin Crossca860ac2016-01-04 14:34:37 -0800310}
311
312type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700313 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700314 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800315 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700316 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700317 hostToolPath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800318}
319
Colin Crossc99deeb2016-04-11 15:06:20 -0700320type dependencyTag struct {
321 blueprint.BaseDependencyTag
322 name string
323 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700324
325 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900326
327 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700328}
329
330var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700331 sharedDepTag = dependencyTag{name: "shared", library: true}
332 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900333 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700334 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
335 staticDepTag = dependencyTag{name: "static", library: true}
336 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
337 lateStaticDepTag = dependencyTag{name: "late static", library: true}
338 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800339 headerDepTag = dependencyTag{name: "header", library: true}
340 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700341 genSourceDepTag = dependencyTag{name: "gen source"}
342 genHeaderDepTag = dependencyTag{name: "gen header"}
343 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
344 objDepTag = dependencyTag{name: "obj"}
345 crtBeginDepTag = dependencyTag{name: "crtbegin"}
346 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700347 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
348 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700349 reuseObjTag = dependencyTag{name: "reuse objects"}
350 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
351 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800352 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800353 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700354)
355
Colin Crossca860ac2016-01-04 14:34:37 -0800356// Module contains the properties and members used by all C/C++ module types, and implements
357// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
358// to construct the output file. Behavior can be customized with a Customizer interface
359type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700360 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700361 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900362 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700363
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700364 Properties BaseProperties
365 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700366
Colin Crossca860ac2016-01-04 14:34:37 -0800367 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700368 hod android.HostOrDeviceSupported
369 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700370
Colin Crossca860ac2016-01-04 14:34:37 -0800371 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700372 features []feature
373 compiler compiler
374 linker linker
375 installer installer
376 stl *stl
377 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800378 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800379 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900380 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700381 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700382 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800383 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800384
385 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700386
Colin Cross635c3b02016-05-18 15:37:25 -0700387 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800388
Colin Crossb98c8b02016-07-29 13:44:28 -0700389 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700390
391 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800392
393 // Flags used to compile this module
394 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700395
396 // 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 -0800397 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700398 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800399 depsInLinkOrder android.Paths
400
401 // only non-nil when this is a shared library that reuses the objects of a static library
402 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700403}
404
Jiyong Parkc20eee32018-09-05 22:36:17 +0900405func (c *Module) OutputFile() android.OptionalPath {
406 return c.outputFile
407}
408
Jiyong Park719b4462019-01-13 00:39:51 +0900409func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900410 if c.linker != nil {
411 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900412 }
413 return nil
414}
415
Colin Cross36242852017-06-23 15:06:31 -0700416func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700417 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800418 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700419 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800420 }
421 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700422 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800423 }
424 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700425 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800426 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700427 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700428 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700429 }
Colin Cross16b23492016-01-06 14:41:07 -0800430 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700431 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800432 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800433 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700434 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800435 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800436 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700437 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800438 }
Justin Yun8effde42017-06-23 19:24:43 +0900439 if c.vndkdep != nil {
440 c.AddProperties(c.vndkdep.props()...)
441 }
Stephen Craneba090d12017-05-09 15:44:35 -0700442 if c.lto != nil {
443 c.AddProperties(c.lto.props()...)
444 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700445 if c.pgo != nil {
446 c.AddProperties(c.pgo.props()...)
447 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800448 if c.xom != nil {
449 c.AddProperties(c.xom.props()...)
450 }
Colin Crossca860ac2016-01-04 14:34:37 -0800451 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700452 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800453 }
Colin Crossc472d572015-03-17 15:06:21 -0700454
Colin Crossa9d8bee2018-10-02 13:59:46 -0700455 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
456 switch class {
457 case android.Device:
458 return ctx.Config().DevicePrefer32BitExecutables()
459 case android.HostCross:
460 // Windows builds always prefer 32-bit
461 return true
462 default:
463 return false
464 }
465 })
Colin Cross36242852017-06-23 15:06:31 -0700466 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700467
Colin Cross1f44a3a2017-07-07 14:33:33 -0700468 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700469
Jiyong Park9d452992018-10-03 00:38:19 +0900470 android.InitApexModule(c)
471
Colin Cross36242852017-06-23 15:06:31 -0700472 return c
Colin Crossc472d572015-03-17 15:06:21 -0700473}
474
Colin Crossb916a382016-07-29 17:28:03 -0700475// Returns true for dependency roots (binaries)
476// TODO(ccross): also handle dlopenable libraries
477func (c *Module) isDependencyRoot() bool {
478 if root, ok := c.linker.(interface {
479 isDependencyRoot() bool
480 }); ok {
481 return root.isDependencyRoot()
482 }
483 return false
484}
485
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700486func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700487 return c.Properties.UseVndk
488}
489
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800490func (c *Module) isNdk() bool {
491 return inList(c.Name(), ndkMigratedLibs)
492}
493
494func (c *Module) isLlndk() bool {
495 // Returns true for both LLNDK (public) and LLNDK-private libs.
496 return inList(c.Name(), llndkLibraries)
497}
498
499func (c *Module) isLlndkPublic() bool {
500 // Returns true only for LLNDK (public) libs.
501 return c.isLlndk() && !c.isVndkPrivate()
502}
503
504func (c *Module) isVndkPrivate() bool {
505 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
506 return inList(c.Name(), vndkPrivateLibraries)
507}
508
Justin Yun8effde42017-06-23 19:24:43 +0900509func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800510 if vndkdep := c.vndkdep; vndkdep != nil {
511 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900512 }
513 return false
514}
515
Yi Kong7e53c572018-02-14 18:16:12 +0800516func (c *Module) isPgoCompile() bool {
517 if pgo := c.pgo; pgo != nil {
518 return pgo.Properties.PgoCompile
519 }
520 return false
521}
522
Logan Chienf3511742017-10-31 18:04:35 +0800523func (c *Module) isVndkSp() bool {
524 if vndkdep := c.vndkdep; vndkdep != nil {
525 return vndkdep.isVndkSp()
526 }
527 return false
528}
529
530func (c *Module) isVndkExt() bool {
531 if vndkdep := c.vndkdep; vndkdep != nil {
532 return vndkdep.isVndkExt()
533 }
534 return false
535}
536
537func (c *Module) getVndkExtendsModuleName() string {
538 if vndkdep := c.vndkdep; vndkdep != nil {
539 return vndkdep.getVndkExtendsModuleName()
540 }
541 return ""
542}
543
Jiyong Park82e2bf32017-08-16 14:05:54 +0900544// Returns true only when this module is configured to have core and vendor
545// variants.
546func (c *Module) hasVendorVariant() bool {
547 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
548}
549
Jiyong Parkf9332f12018-02-01 00:54:12 +0900550func (c *Module) inRecovery() bool {
551 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
552}
553
554func (c *Module) onlyInRecovery() bool {
555 return c.ModuleBase.InstallInRecovery()
556}
557
Jiyong Park25fc6a92018-11-18 18:02:45 +0900558func (c *Module) IsStubs() bool {
559 if library, ok := c.linker.(*libraryDecorator); ok {
560 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900561 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
562 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900563 }
564 return false
565}
566
567func (c *Module) HasStubsVariants() bool {
568 if library, ok := c.linker.(*libraryDecorator); ok {
569 return len(library.Properties.Stubs.Versions) > 0
570 }
571 return false
572}
573
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900574func (c *Module) bootstrap() bool {
575 return Bool(c.Properties.Bootstrap)
576}
577
Colin Crossca860ac2016-01-04 14:34:37 -0800578type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700579 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800580 moduleContextImpl
581}
582
Colin Cross37047f12016-12-13 17:06:13 -0800583type depsContext struct {
584 android.BottomUpMutatorContext
585 moduleContextImpl
586}
587
Colin Crossca860ac2016-01-04 14:34:37 -0800588type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700589 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800590 moduleContextImpl
591}
592
Jiyong Park2db76922017-11-08 16:03:48 +0900593func (ctx *moduleContext) SocSpecific() bool {
594 return ctx.ModuleContext.SocSpecific() ||
595 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700596}
597
Colin Crossca860ac2016-01-04 14:34:37 -0800598type moduleContextImpl struct {
599 mod *Module
600 ctx BaseModuleContext
601}
602
Colin Crossb98c8b02016-07-29 13:44:28 -0700603func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800604 return ctx.mod.toolchain(ctx.ctx)
605}
606
607func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000608 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800609}
610
611func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900612 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800613}
614
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700615func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800616 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800617 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700618 }
619 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800620}
621
622func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700623 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700624 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900625 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700626 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900627 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
628 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
629 return "current"
630 }
631 return platform_vndk_ver
632 }
633 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800634 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900635 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700636 }
637 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800638}
639
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700640func (ctx *moduleContextImpl) useVndk() bool {
641 return ctx.mod.useVndk()
642}
Justin Yun8effde42017-06-23 19:24:43 +0900643
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800644func (ctx *moduleContextImpl) isNdk() bool {
645 return ctx.mod.isNdk()
646}
647
648func (ctx *moduleContextImpl) isLlndk() bool {
649 return ctx.mod.isLlndk()
650}
651
652func (ctx *moduleContextImpl) isLlndkPublic() bool {
653 return ctx.mod.isLlndkPublic()
654}
655
656func (ctx *moduleContextImpl) isVndkPrivate() bool {
657 return ctx.mod.isVndkPrivate()
658}
659
Logan Chienf3511742017-10-31 18:04:35 +0800660func (ctx *moduleContextImpl) isVndk() bool {
661 return ctx.mod.isVndk()
662}
663
Yi Kong7e53c572018-02-14 18:16:12 +0800664func (ctx *moduleContextImpl) isPgoCompile() bool {
665 return ctx.mod.isPgoCompile()
666}
667
Justin Yun8effde42017-06-23 19:24:43 +0900668func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800669 return ctx.mod.isVndkSp()
670}
671
672func (ctx *moduleContextImpl) isVndkExt() bool {
673 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900674}
675
Jiyong Parkf9332f12018-02-01 00:54:12 +0900676func (ctx *moduleContextImpl) inRecovery() bool {
677 return ctx.mod.inRecovery()
678}
679
Logan Chien2f2b8902018-07-10 15:01:19 +0800680// Check whether ABI dumps should be created for this module.
681func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
682 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
683 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800684 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800685
686 if ctx.ctx.Fuchsia() {
687 return false
688 }
689
Logan Chien2f2b8902018-07-10 15:01:19 +0800690 if sanitize := ctx.mod.sanitize; sanitize != nil {
691 if !sanitize.isVariantOnProductionDevice() {
692 return false
693 }
694 }
695 if !ctx.ctx.Device() {
696 // Host modules do not need ABI dumps.
697 return false
698 }
Logan Chienfa478c02018-12-28 16:25:39 +0800699 if !ctx.mod.IsForPlatform() {
700 // APEX variants do not need ABI dumps.
701 return false
702 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800703 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800704 return true
705 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800706 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800707 return true
708 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800709 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800710 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
711 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800712 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800713 }
714 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800715}
716
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700717func (ctx *moduleContextImpl) selectedStl() string {
718 if stl := ctx.mod.stl; stl != nil {
719 return stl.Properties.SelectedStl
720 }
721 return ""
722}
723
Ivan Lozanobd721262018-11-27 14:33:03 -0800724func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
725 return ctx.mod.linker.useClangLld(actx)
726}
727
Colin Crossce75d2c2016-10-06 16:12:58 -0700728func (ctx *moduleContextImpl) baseModuleName() string {
729 return ctx.mod.ModuleBase.BaseModuleName()
730}
731
Logan Chienf3511742017-10-31 18:04:35 +0800732func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
733 return ctx.mod.getVndkExtendsModuleName()
734}
735
Jiyong Park58e364a2019-01-19 19:24:06 +0900736func (ctx *moduleContextImpl) apexName() string {
737 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900738}
739
Jiyong Parkb0788572018-12-20 22:10:17 +0900740func (ctx *moduleContextImpl) hasStubsVariants() bool {
741 return ctx.mod.HasStubsVariants()
742}
743
744func (ctx *moduleContextImpl) isStubs() bool {
745 return ctx.mod.IsStubs()
746}
747
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900748func (ctx *moduleContextImpl) bootstrap() bool {
749 return ctx.mod.bootstrap()
750}
751
Colin Cross635c3b02016-05-18 15:37:25 -0700752func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800753 return &Module{
754 hod: hod,
755 multilib: multilib,
756 }
757}
758
Colin Cross635c3b02016-05-18 15:37:25 -0700759func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800760 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700761 module.features = []feature{
762 &tidyFeature{},
763 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700764 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800765 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800766 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800767 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900768 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700769 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700770 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800771 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800772 return module
773}
774
Colin Crossce75d2c2016-10-06 16:12:58 -0700775func (c *Module) Prebuilt() *android.Prebuilt {
776 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
777 return p.prebuilt()
778 }
779 return nil
780}
781
782func (c *Module) Name() string {
783 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700784 if p, ok := c.linker.(interface {
785 Name(string) string
786 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700787 name = p.Name(name)
788 }
789 return name
790}
791
Alex Light3d673592019-01-18 14:37:31 -0800792func (c *Module) Symlinks() []string {
793 if p, ok := c.installer.(interface {
794 symlinkList() []string
795 }); ok {
796 return p.symlinkList()
797 }
798 return nil
799}
800
Jeff Gaston294356f2017-09-27 17:05:30 -0700801// orderDeps reorders dependencies into a list such that if module A depends on B, then
802// A will precede B in the resultant list.
803// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800804// Note that directSharedDeps should be the analogous static library for each shared lib dep
805func 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 -0700806 // If A depends on B, then
807 // Every list containing A will also contain B later in the list
808 // So, after concatenating all lists, the final instance of B will have come from the same
809 // original list as the final instance of A
810 // So, the final instance of B will be later in the concatenation than the final A
811 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
812 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800813 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700814 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800815 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
816 }
817 for _, dep := range directSharedDeps {
818 orderedAllDeps = append(orderedAllDeps, dep)
819 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700820 }
821
Colin Crossb6715442017-10-24 11:13:31 -0700822 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700823
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800824 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700825 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800826 // resultant list to only what the caller has chosen to include in directStaticDeps
827 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700828
829 return orderedAllDeps, orderedDeclaredDeps
830}
831
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800832func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
833 // convert Module to Path
834 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
835 staticDepFiles := []android.Path{}
836 for _, dep := range staticDeps {
837 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
838 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700839 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800840 sharedDepFiles := []android.Path{}
841 for _, sharedDep := range sharedDeps {
842 staticAnalogue := sharedDep.staticVariant
843 if staticAnalogue != nil {
844 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
845 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
846 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700847 }
848
849 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800850 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700851
852 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700853}
854
Colin Cross635c3b02016-05-18 15:37:25 -0700855func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800856 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700857 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800858 moduleContextImpl: moduleContextImpl{
859 mod: c,
860 },
861 }
862 ctx.ctx = ctx
863
Colin Crossf18e1102017-11-16 14:33:08 -0800864 deps := c.depsToPaths(ctx)
865 if ctx.Failed() {
866 return
867 }
868
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700869 if c.Properties.Clang != nil && *c.Properties.Clang == false {
870 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
871 }
872
Colin Crossca860ac2016-01-04 14:34:37 -0800873 flags := Flags{
874 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800875 }
Colin Crossca860ac2016-01-04 14:34:37 -0800876 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800877 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800878 }
879 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700880 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800881 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700882 if c.stl != nil {
883 flags = c.stl.flags(ctx, flags)
884 }
Colin Cross16b23492016-01-06 14:41:07 -0800885 if c.sanitize != nil {
886 flags = c.sanitize.flags(ctx, flags)
887 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800888 if c.coverage != nil {
889 flags = c.coverage.flags(ctx, flags)
890 }
Stephen Craneba090d12017-05-09 15:44:35 -0700891 if c.lto != nil {
892 flags = c.lto.flags(ctx, flags)
893 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700894 if c.pgo != nil {
895 flags = c.pgo.flags(ctx, flags)
896 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800897 if c.xom != nil {
898 flags = c.xom.flags(ctx, flags)
899 }
Colin Crossca860ac2016-01-04 14:34:37 -0800900 for _, feature := range c.features {
901 flags = feature.flags(ctx, flags)
902 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800903 if ctx.Failed() {
904 return
905 }
906
Colin Crossb98c8b02016-07-29 13:44:28 -0700907 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
908 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
909 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800910
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800911 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
912 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700913 // We need access to all the flags seen by a source file.
914 if c.sabi != nil {
915 flags = c.sabi.flags(ctx, flags)
916 }
Colin Crossca860ac2016-01-04 14:34:37 -0800917 // Optimization to reduce size of build.ninja
918 // Replace the long list of flags for each file with a module-local variable
919 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
920 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
921 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
922 flags.CFlags = []string{"$cflags"}
923 flags.CppFlags = []string{"$cppflags"}
924 flags.AsFlags = []string{"$asflags"}
925
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700926 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800927 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700928 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800929 if ctx.Failed() {
930 return
931 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800932 }
933
Colin Crossca860ac2016-01-04 14:34:37 -0800934 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700935 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800936 if ctx.Failed() {
937 return
938 }
Colin Cross635c3b02016-05-18 15:37:25 -0700939 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900940
941 // If a lib is directly included in any of the APEXes, unhide the stubs
942 // variant having the latest version gets visible to make. In addition,
943 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
944 // force anything in the make world to link against the stubs library.
945 // (unless it is explicitly referenced via .bootstrap suffix or the
946 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +0000947 if c.HasStubsVariants() &&
948 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Jiyong Parkb0788572018-12-20 22:10:17 +0900949 !c.inRecovery() && !c.useVndk() && !c.static() && c.IsStubs() {
950 c.Properties.HideFromMake = false // unhide
951 // Note: this is still non-installable
952 }
Colin Crossce75d2c2016-10-06 16:12:58 -0700953 }
Colin Cross5049f022015-03-18 13:28:46 -0700954
Jiyong Park9d452992018-10-03 00:38:19 +0900955 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -0700956 c.installer.install(ctx, c.outputFile.Path())
957 if ctx.Failed() {
958 return
Colin Crossca860ac2016-01-04 14:34:37 -0800959 }
Dan Albertc403f7c2015-03-18 14:01:18 -0700960 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800961}
962
Jiyong Park379de2f2018-12-19 02:47:14 +0900963func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800964 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -0700965 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -0800966 }
Colin Crossca860ac2016-01-04 14:34:37 -0800967 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -0800968}
969
Colin Crossca860ac2016-01-04 14:34:37 -0800970func (c *Module) begin(ctx BaseModuleContext) {
971 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700972 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -0700973 }
Colin Crossca860ac2016-01-04 14:34:37 -0800974 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700975 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -0800976 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700977 if c.stl != nil {
978 c.stl.begin(ctx)
979 }
Colin Cross16b23492016-01-06 14:41:07 -0800980 if c.sanitize != nil {
981 c.sanitize.begin(ctx)
982 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800983 if c.coverage != nil {
984 c.coverage.begin(ctx)
985 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800986 if c.sabi != nil {
987 c.sabi.begin(ctx)
988 }
Justin Yun8effde42017-06-23 19:24:43 +0900989 if c.vndkdep != nil {
990 c.vndkdep.begin(ctx)
991 }
Stephen Craneba090d12017-05-09 15:44:35 -0700992 if c.lto != nil {
993 c.lto.begin(ctx)
994 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700995 if c.pgo != nil {
996 c.pgo.begin(ctx)
997 }
Colin Crossca860ac2016-01-04 14:34:37 -0800998 for _, feature := range c.features {
999 feature.begin(ctx)
1000 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001001 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001002 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001003 if err != nil {
1004 ctx.PropertyErrorf("sdk_version", err.Error())
1005 }
Nan Zhang0007d812017-11-07 10:57:05 -08001006 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001007 }
Colin Crossca860ac2016-01-04 14:34:37 -08001008}
1009
Colin Cross37047f12016-12-13 17:06:13 -08001010func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001011 deps := Deps{}
1012
1013 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001014 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001015 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001016 // Add the PGO dependency (the clang_rt.profile runtime library), which
1017 // sometimes depends on symbols from libgcc, before libgcc gets added
1018 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001019 if c.pgo != nil {
1020 deps = c.pgo.deps(ctx, deps)
1021 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001022 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001023 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001024 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001025 if c.stl != nil {
1026 deps = c.stl.deps(ctx, deps)
1027 }
Colin Cross16b23492016-01-06 14:41:07 -08001028 if c.sanitize != nil {
1029 deps = c.sanitize.deps(ctx, deps)
1030 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001031 if c.coverage != nil {
1032 deps = c.coverage.deps(ctx, deps)
1033 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001034 if c.sabi != nil {
1035 deps = c.sabi.deps(ctx, deps)
1036 }
Justin Yun8effde42017-06-23 19:24:43 +09001037 if c.vndkdep != nil {
1038 deps = c.vndkdep.deps(ctx, deps)
1039 }
Stephen Craneba090d12017-05-09 15:44:35 -07001040 if c.lto != nil {
1041 deps = c.lto.deps(ctx, deps)
1042 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001043 for _, feature := range c.features {
1044 deps = feature.deps(ctx, deps)
1045 }
1046
Colin Crossb6715442017-10-24 11:13:31 -07001047 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1048 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1049 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1050 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1051 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1052 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001053 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001054
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001055 for _, lib := range deps.ReexportSharedLibHeaders {
1056 if !inList(lib, deps.SharedLibs) {
1057 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1058 }
1059 }
1060
1061 for _, lib := range deps.ReexportStaticLibHeaders {
1062 if !inList(lib, deps.StaticLibs) {
1063 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1064 }
1065 }
1066
Colin Cross5950f382016-12-13 12:50:57 -08001067 for _, lib := range deps.ReexportHeaderLibHeaders {
1068 if !inList(lib, deps.HeaderLibs) {
1069 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1070 }
1071 }
1072
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001073 for _, gen := range deps.ReexportGeneratedHeaders {
1074 if !inList(gen, deps.GeneratedHeaders) {
1075 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1076 }
1077 }
1078
Colin Crossc99deeb2016-04-11 15:06:20 -07001079 return deps
1080}
1081
Dan Albert7e9d2952016-08-04 13:02:36 -07001082func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001083 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001084 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001085 moduleContextImpl: moduleContextImpl{
1086 mod: c,
1087 },
1088 }
1089 ctx.ctx = ctx
1090
Colin Crossca860ac2016-01-04 14:34:37 -08001091 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001092}
1093
Jiyong Park7ed9de32018-10-15 22:25:07 +09001094// Split name#version into name and version
1095func stubsLibNameAndVersion(name string) (string, string) {
1096 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1097 version := name[sharp+1:]
1098 libname := name[:sharp]
1099 return libname, version
1100 }
1101 return name, ""
1102}
1103
Colin Cross1e676be2016-10-12 14:38:15 -07001104func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001105 ctx := &depsContext{
1106 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001107 moduleContextImpl: moduleContextImpl{
1108 mod: c,
1109 },
1110 }
1111 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001112
Colin Crossc99deeb2016-04-11 15:06:20 -07001113 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001114
Dan Albert914449f2016-06-17 16:45:24 -07001115 variantNdkLibs := []string{}
1116 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001117 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001118 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001119
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001120 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1121 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001122 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001123 // 1. Name of an NDK library that refers to a prebuilt module.
1124 // For each of these, it adds the name of the prebuilt module (which will be in
1125 // prebuilts/ndk) to the list of nonvariant libs.
1126 // 2. Name of an NDK library that refers to an ndk_library module.
1127 // For each of these, it adds the name of the ndk_library module to the list of
1128 // variant libs.
1129 // 3. Anything else (so anything that isn't an NDK library).
1130 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001131 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001132 // The caller can then know to add the variantLibs dependencies differently from the
1133 // nonvariantLibs
1134 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1135 variantLibs = []string{}
1136 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001137 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001138 // strip #version suffix out
1139 name, _ := stubsLibNameAndVersion(entry)
1140 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1141 if !inList(name, ndkMigratedLibs) {
1142 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001143 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001144 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001145 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001146 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1147 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1148 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1149 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001150 if actx.OtherModuleExists(vendorPublicLib) {
1151 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1152 } else {
1153 // This can happen if vendor_public_library module is defined in a
1154 // namespace that isn't visible to the current module. In that case,
1155 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001156 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001157 }
Dan Albert914449f2016-06-17 16:45:24 -07001158 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001159 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001160 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001161 }
1162 }
Dan Albert914449f2016-06-17 16:45:24 -07001163 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001164 }
1165
Dan Albert914449f2016-06-17 16:45:24 -07001166 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1167 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001168 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001169 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001170
Jiyong Park7e636d02019-01-28 16:16:54 +09001171 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001172 if c.linker != nil {
1173 if library, ok := c.linker.(*libraryDecorator); ok {
1174 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001175 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001176 }
1177 }
1178 }
1179
Colin Cross32ec36c2016-12-15 07:39:51 -08001180 for _, lib := range deps.HeaderLibs {
1181 depTag := headerDepTag
1182 if inList(lib, deps.ReexportHeaderLibHeaders) {
1183 depTag = headerExportDepTag
1184 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001185 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001186 actx.AddFarVariationDependencies([]blueprint.Variation{
1187 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001188 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001189 }, depTag, lib)
1190 } else {
1191 actx.AddVariationDependencies(nil, depTag, lib)
1192 }
1193 }
1194
1195 if buildStubs {
1196 // Stubs lib does not have dependency to other static/shared libraries.
1197 // Don't proceed.
1198 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001199 }
Colin Cross5950f382016-12-13 12:50:57 -08001200
Dan Willemsen59339a22018-07-22 21:18:45 -07001201 actx.AddVariationDependencies([]blueprint.Variation{
1202 {Mutator: "link", Variation: "static"},
1203 }, wholeStaticDepTag, deps.WholeStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001204
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001205 for _, lib := range deps.StaticLibs {
1206 depTag := staticDepTag
1207 if inList(lib, deps.ReexportStaticLibHeaders) {
1208 depTag = staticExportDepTag
1209 }
Dan Willemsen59339a22018-07-22 21:18:45 -07001210 actx.AddVariationDependencies([]blueprint.Variation{
1211 {Mutator: "link", Variation: "static"},
1212 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001213 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001214
Dan Willemsen59339a22018-07-22 21:18:45 -07001215 actx.AddVariationDependencies([]blueprint.Variation{
1216 {Mutator: "link", Variation: "static"},
1217 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001218
Jiyong Park25fc6a92018-11-18 18:02:45 +09001219 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1220 var variations []blueprint.Variation
1221 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001222 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001223 if version != "" && versionVariantAvail {
1224 // Version is explicitly specified. i.e. libFoo#30
1225 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1226 depTag.explicitlyVersioned = true
1227 }
1228 actx.AddVariationDependencies(variations, depTag, name)
1229
1230 // If the version is not specified, add dependency to the latest stubs library.
1231 // The stubs library will be used when the depending module is built for APEX and
1232 // the dependent module is not in the same APEX.
1233 latestVersion := latestStubsVersionFor(actx.Config(), name)
1234 if version == "" && latestVersion != "" && versionVariantAvail {
1235 actx.AddVariationDependencies([]blueprint.Variation{
1236 {Mutator: "link", Variation: "shared"},
1237 {Mutator: "version", Variation: latestVersion},
1238 }, depTag, name)
1239 // Note that depTag.explicitlyVersioned is false in this case.
1240 }
1241 }
1242
Jiyong Park7ed9de32018-10-15 22:25:07 +09001243 // shared lib names without the #version suffix
1244 var sharedLibNames []string
1245
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001246 for _, lib := range deps.SharedLibs {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001247 name, version := stubsLibNameAndVersion(lib)
1248 sharedLibNames = append(sharedLibNames, name)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001249 depTag := sharedDepTag
1250 if inList(lib, deps.ReexportSharedLibHeaders) {
1251 depTag = sharedExportDepTag
1252 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001253 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001254 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001255
Jiyong Park7ed9de32018-10-15 22:25:07 +09001256 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001257 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001258 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1259 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1260 // linking against both the stubs lib and the non-stubs lib at the same time.
1261 continue
1262 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001263 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001264 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001265
Dan Willemsen59339a22018-07-22 21:18:45 -07001266 actx.AddVariationDependencies([]blueprint.Variation{
1267 {Mutator: "link", Variation: "shared"},
1268 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001269
Colin Cross68861832016-07-08 10:41:41 -07001270 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001271
1272 for _, gen := range deps.GeneratedHeaders {
1273 depTag := genHeaderDepTag
1274 if inList(gen, deps.ReexportGeneratedHeaders) {
1275 depTag = genHeaderExportDepTag
1276 }
1277 actx.AddDependency(c, depTag, gen)
1278 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001279
Colin Cross42d48b72018-08-29 14:10:52 -07001280 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001281
1282 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001283 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001284 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001285 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001286 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001287 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001288 if deps.LinkerFlagsFile != "" {
1289 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1290 }
1291 if deps.DynamicLinker != "" {
1292 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001293 }
Dan Albert914449f2016-06-17 16:45:24 -07001294
1295 version := ctx.sdkVersion()
1296 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001297 {Mutator: "ndk_api", Variation: version},
1298 {Mutator: "link", Variation: "shared"},
1299 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001300 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001301 {Mutator: "ndk_api", Variation: version},
1302 {Mutator: "link", Variation: "shared"},
1303 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001304
1305 if vndkdep := c.vndkdep; vndkdep != nil {
1306 if vndkdep.isVndkExt() {
1307 baseModuleMode := vendorMode
1308 if actx.DeviceConfig().VndkVersion() == "" {
1309 baseModuleMode = coreMode
1310 }
1311 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001312 {Mutator: "image", Variation: baseModuleMode},
1313 {Mutator: "link", Variation: "shared"},
1314 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001315 }
1316 }
Colin Cross6362e272015-10-29 15:25:03 -07001317}
Colin Cross21b9a242015-03-24 14:15:58 -07001318
Colin Crosse40b4ea2018-10-02 22:25:58 -07001319func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001320 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1321 c.beginMutator(ctx)
1322 }
1323}
1324
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001325// Whether a module can link to another module, taking into
1326// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001327func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001328 if from.Target().Os != android.Android {
1329 // Host code is not restricted
1330 return
1331 }
1332 if from.Properties.UseVndk {
1333 // Though vendor code is limited by the vendor mutator,
1334 // each vendor-available module needs to check
1335 // link-type for VNDK.
1336 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001337 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001338 }
1339 return
1340 }
Nan Zhang0007d812017-11-07 10:57:05 -08001341 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001342 // Platform code can link to anything
1343 return
1344 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001345 if from.inRecovery() {
1346 // Recovery code is not NDK
1347 return
1348 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001349 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1350 // These are always allowed
1351 return
1352 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001353 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1354 // These are allowed, but they don't set sdk_version
1355 return
1356 }
1357 if _, ok := to.linker.(*stubDecorator); ok {
1358 // These aren't real libraries, but are the stub shared libraries that are included in
1359 // the NDK.
1360 return
1361 }
Logan Chien834b9a62019-01-14 15:39:03 +08001362
1363 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1364 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1365 // to link to libc++ (non-NDK and without sdk_version).
1366 return
1367 }
1368
Nan Zhang0007d812017-11-07 10:57:05 -08001369 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001370 // NDK code linking to platform code is never okay.
1371 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1372 ctx.OtherModuleName(to))
1373 }
1374
1375 // At this point we know we have two NDK libraries, but we need to
1376 // check that we're not linking against anything built against a higher
1377 // API level, as it is only valid to link against older or equivalent
1378 // APIs.
1379
Inseob Kim01a28722018-04-11 09:48:45 +09001380 // Current can link against anything.
1381 if String(from.Properties.Sdk_version) != "current" {
1382 // Otherwise we need to check.
1383 if String(to.Properties.Sdk_version) == "current" {
1384 // Current can't be linked against by anything else.
1385 ctx.ModuleErrorf("links %q built against newer API version %q",
1386 ctx.OtherModuleName(to), "current")
1387 } else {
1388 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1389 if err != nil {
1390 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001391 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001392 String(from.Properties.Sdk_version))
1393 }
1394 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1395 if err != nil {
1396 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001397 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001398 String(to.Properties.Sdk_version))
1399 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001400
Inseob Kim01a28722018-04-11 09:48:45 +09001401 if toApi > fromApi {
1402 ctx.ModuleErrorf("links %q built against newer API version %q",
1403 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1404 }
1405 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001406 }
Dan Albert202fe492017-12-15 13:56:59 -08001407
1408 // Also check that the two STL choices are compatible.
1409 fromStl := from.stl.Properties.SelectedStl
1410 toStl := to.stl.Properties.SelectedStl
1411 if fromStl == "" || toStl == "" {
1412 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001413 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001414 // We can be permissive with the system "STL" since it is only the C++
1415 // ABI layer, but in the future we should make sure that everyone is
1416 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001417 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001418 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1419 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1420 to.stl.Properties.SelectedStl)
1421 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001422}
1423
Jiyong Park5fb8c102018-04-09 12:03:06 +09001424// Tests whether the dependent library is okay to be double loaded inside a single process.
1425// If a library is a member of VNDK and at the same time dependencies of an LLNDK library,
1426// it is subject to be double loaded. Such lib should be explicitly marked as double_loaded: true
1427// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
1428func checkDoubleLoadableLibries(ctx android.ModuleContext, from *Module, to *Module) {
1429 if _, ok := from.linker.(*libraryDecorator); !ok {
1430 return
1431 }
1432
1433 if inList(ctx.ModuleName(), llndkLibraries) ||
1434 (from.useVndk() && Bool(from.VendorProperties.Double_loadable)) {
1435 _, depIsLlndk := to.linker.(*llndkStubDecorator)
1436 depIsVndkSp := false
1437 if to.vndkdep != nil && to.vndkdep.isVndkSp() {
1438 depIsVndkSp = true
1439 }
1440 depIsVndk := false
1441 if to.vndkdep != nil && to.vndkdep.isVndk() {
1442 depIsVndk = true
1443 }
1444 depIsDoubleLoadable := Bool(to.VendorProperties.Double_loadable)
1445 if !depIsLlndk && !depIsVndkSp && !depIsDoubleLoadable && depIsVndk {
Steven Moreland742989e2018-11-26 12:41:04 -08001446 ctx.ModuleErrorf("links VNDK library %q that isn't double loadable (not also LL-NDK, "+
1447 "VNDK-SP, or explicitly marked as 'double_loadable').",
Jiyong Park5fb8c102018-04-09 12:03:06 +09001448 ctx.OtherModuleName(to))
1449 }
1450 }
1451}
1452
Colin Crossc99deeb2016-04-11 15:06:20 -07001453// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001454func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001455 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001456
Jeff Gaston294356f2017-09-27 17:05:30 -07001457 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001458 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001459
Colin Crossd11fcda2017-10-23 17:59:01 -07001460 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001461 depName := ctx.OtherModuleName(dep)
1462 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001463
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001464 ccDep, _ := dep.(*Module)
1465 if ccDep == nil {
1466 // handling for a few module types that aren't cc Module but that are also supported
1467 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001468 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001469 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001470 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1471 genRule.GeneratedSourceFiles()...)
1472 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001473 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001474 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001475 // Support exported headers from a generated_sources dependency
1476 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001477 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001478 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001479 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001480 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001481 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001482 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001483 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001484 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001485 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001486 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001487 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1488 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1489
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001490 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001491 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001492 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001493 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001494 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001495 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001496 files := genRule.GeneratedSourceFiles()
1497 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001498 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001499 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001500 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 -07001501 }
1502 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001503 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001504 }
Colin Crossca860ac2016-01-04 14:34:37 -08001505 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001506 return
1507 }
1508
Colin Crossd11fcda2017-10-23 17:59:01 -07001509 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001510 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1511 return
1512 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001513 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001514 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001515 return
1516 }
1517
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001518 // re-exporting flags
1519 if depTag == reuseObjTag {
1520 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001521 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001522 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001523 depPaths.Objs = depPaths.Objs.Append(objs)
1524 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001525 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001526 return
1527 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001528 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001529
1530 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1531 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1532 // won't be matched to sharedDepTag and lateSharedDepTag.
1533 explicitlyVersioned := false
1534 if t, ok := depTag.(dependencyTag); ok {
1535 explicitlyVersioned = t.explicitlyVersioned
1536 t.explicitlyVersioned = false
1537 depTag = t
1538 }
1539
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001540 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001541 depIsStatic := false
1542 switch depTag {
1543 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1544 depIsStatic = true
1545 }
1546 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001547 depIsStubs := dependentLibrary.buildStubs()
1548 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001549 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001550 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001551
1552 var useThisDep bool
1553 if depIsStubs && explicitlyVersioned {
1554 // Always respect dependency to the versioned stubs (i.e. libX#10)
1555 useThisDep = true
1556 } else if !depHasStubs {
1557 // Use non-stub variant if that is the only choice
1558 // (i.e. depending on a lib without stubs.version property)
1559 useThisDep = true
1560 } else if c.IsForPlatform() {
1561 // If not building for APEX, use stubs only when it is from
1562 // an APEX (and not from platform)
1563 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001564 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001565 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001566 // always link to non-stub variant
1567 useThisDep = !depIsStubs
1568 }
1569 } else {
1570 // If building for APEX, use stubs only when it is not from
1571 // the same APEX
1572 useThisDep = (depInSameApex != depIsStubs)
1573 }
1574
1575 if !useThisDep {
1576 return // stop processing this dep
1577 }
1578 }
1579
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001580 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001581 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001582 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001583 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001584 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001585
1586 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001587 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001588 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001589 // 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 -07001590 // Re-exported shared library headers must be included as well since they can help us with type information
1591 // about template instantiations (instantiated from their headers).
1592 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001593 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001594 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001595
Logan Chienf3511742017-10-31 18:04:35 +08001596 checkLinkType(ctx, c, ccDep, t)
Jiyong Park5fb8c102018-04-09 12:03:06 +09001597 checkDoubleLoadableLibries(ctx, c, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001598 }
1599
Colin Cross26c34ed2016-09-30 17:10:16 -07001600 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001601 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001602
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001603 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001604 depFile := android.OptionalPath{}
1605
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001606 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001607 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001608 ptr = &depPaths.SharedLibs
1609 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001610 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001611 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001612 case earlySharedDepTag:
1613 ptr = &depPaths.EarlySharedLibs
1614 depPtr = &depPaths.EarlySharedLibsDeps
1615 depFile = ccDep.linker.(libraryInterface).toc()
1616 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001617 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001618 ptr = &depPaths.LateSharedLibs
1619 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001620 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001621 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001622 ptr = nil
1623 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001624 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001625 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001626 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001627 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001628 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001629 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001630 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001631 return
1632 }
1633
1634 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001635 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001636 for i := range missingDeps {
1637 missingDeps[i] += postfix
1638 }
1639 ctx.AddMissingDependencies(missingDeps)
1640 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001641 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001642 case headerDepTag:
1643 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001644 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001645 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001646 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001647 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001648 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001649 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001650 case dynamicLinkerDepTag:
1651 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001652 }
1653
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001654 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001655 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001656 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001657 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001658 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001659 return
1660 }
1661
1662 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001663 // in static libraries act as if they were whole static libraries. The same goes for
1664 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001665 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1666 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001667 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1668 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001669
Dan Willemsen581341d2017-02-09 16:16:31 -08001670 }
1671
Colin Cross26c34ed2016-09-30 17:10:16 -07001672 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001673 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001674 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001675 return
1676 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001677 *ptr = append(*ptr, linkFile.Path())
1678 }
1679
Colin Crossc99deeb2016-04-11 15:06:20 -07001680 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001681 dep := depFile
1682 if !dep.Valid() {
1683 dep = linkFile
1684 }
1685 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001686 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001687
Logan Chien43d34c32017-12-20 01:17:32 +08001688 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001689 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001690 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001691 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001692 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001693 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001694 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
1695 if c.useVndk() && bothVendorAndCoreVariantsExist {
1696 // The vendor module in Make will have been renamed to not conflict with the core
1697 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001698 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001699 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001700 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001701 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1702 return libName + recoverySuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001703 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001704 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001705 }
Logan Chien43d34c32017-12-20 01:17:32 +08001706 }
1707
1708 // Export the shared libs to Make.
1709 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001710 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001711 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001712 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001713 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001714 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001715 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001716 c.Properties.ApexesProvidingSharedLibs = append(
1717 c.Properties.ApexesProvidingSharedLibs, an)
1718 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001719 }
1720 }
1721
Jiyong Park27b188b2017-07-18 13:23:39 +09001722 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001723 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001724 c.Properties.AndroidMkSharedLibs = append(
1725 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001726 case ndkStubDepTag, ndkLateStubDepTag:
1727 ndkStub := ccDep.linker.(*stubDecorator)
1728 c.Properties.AndroidMkSharedLibs = append(
1729 c.Properties.AndroidMkSharedLibs,
1730 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001731 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1732 c.Properties.AndroidMkStaticLibs = append(
1733 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001734 case runtimeDepTag:
1735 c.Properties.AndroidMkRuntimeLibs = append(
1736 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001737 case wholeStaticDepTag:
1738 c.Properties.AndroidMkWholeStaticLibs = append(
1739 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001740 }
Colin Crossca860ac2016-01-04 14:34:37 -08001741 })
1742
Jeff Gaston294356f2017-09-27 17:05:30 -07001743 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001744 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001745
Colin Crossdd84e052017-05-17 13:44:16 -07001746 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001747 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001748 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001749 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001750 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1751
1752 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001753 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001754 }
Colin Crossdd84e052017-05-17 13:44:16 -07001755
Colin Crossca860ac2016-01-04 14:34:37 -08001756 return depPaths
1757}
1758
1759func (c *Module) InstallInData() bool {
1760 if c.installer == nil {
1761 return false
1762 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001763 return c.installer.inData()
1764}
1765
1766func (c *Module) InstallInSanitizerDir() bool {
1767 if c.installer == nil {
1768 return false
1769 }
1770 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001771 return true
1772 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001773 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001774}
1775
Jiyong Parkf9332f12018-02-01 00:54:12 +09001776func (c *Module) InstallInRecovery() bool {
1777 return c.inRecovery()
1778}
1779
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001780func (c *Module) HostToolPath() android.OptionalPath {
1781 if c.installer == nil {
1782 return android.OptionalPath{}
1783 }
1784 return c.installer.hostToolPath()
1785}
1786
Nan Zhangd4e641b2017-07-12 12:55:28 -07001787func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1788 return c.outputFile
1789}
1790
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001791func (c *Module) Srcs() android.Paths {
1792 if c.outputFile.Valid() {
1793 return android.Paths{c.outputFile.Path()}
1794 }
1795 return android.Paths{}
1796}
1797
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001798func (c *Module) static() bool {
1799 if static, ok := c.linker.(interface {
1800 static() bool
1801 }); ok {
1802 return static.static()
1803 }
1804 return false
1805}
1806
Jiyong Park379de2f2018-12-19 02:47:14 +09001807func (c *Module) staticBinary() bool {
1808 if static, ok := c.linker.(interface {
1809 staticBinary() bool
1810 }); ok {
1811 return static.staticBinary()
1812 }
1813 return false
1814}
1815
Colin Crossb60190a2018-09-04 16:28:17 -07001816func (c *Module) getMakeLinkType() string {
1817 if c.useVndk() {
1818 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1819 if inList(c.Name(), vndkPrivateLibraries) {
1820 return "native:vndk_private"
1821 } else {
1822 return "native:vndk"
1823 }
1824 } else {
1825 return "native:vendor"
1826 }
1827 } else if c.inRecovery() {
1828 return "native:recovery"
1829 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1830 return "native:ndk:none:none"
1831 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1832 //family, link := getNdkStlFamilyAndLinkType(c)
1833 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
1834 } else {
1835 return "native:platform"
1836 }
1837}
1838
Jiyong Park9d452992018-10-03 00:38:19 +09001839// Overrides ApexModule.IsInstallabeToApex()
1840// Only shared libraries are installable to APEX.
1841func (c *Module) IsInstallableToApex() bool {
1842 if shared, ok := c.linker.(interface {
1843 shared() bool
1844 }); ok {
1845 return shared.shared()
1846 }
1847 return false
1848}
1849
Jiyong Park3b1746a2019-01-29 11:15:04 +09001850func (c *Module) imageVariation() string {
1851 variation := "core"
1852 if c.useVndk() {
1853 variation = "vendor"
1854 } else if c.inRecovery() {
1855 variation = "recovery"
1856 }
1857 return variation
1858}
1859
Colin Cross2ba19d92015-05-07 15:44:20 -07001860//
Colin Crosscfad1192015-11-02 16:43:11 -08001861// Defaults
1862//
Colin Crossca860ac2016-01-04 14:34:37 -08001863type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001864 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001865 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001866 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001867}
1868
Colin Cross635c3b02016-05-18 15:37:25 -07001869func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001870}
1871
Colin Cross36242852017-06-23 15:06:31 -07001872func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001873 return DefaultsFactory()
1874}
1875
Colin Cross36242852017-06-23 15:06:31 -07001876func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001877 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08001878
Colin Cross36242852017-06-23 15:06:31 -07001879 module.AddProperties(props...)
1880 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08001881 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001882 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001883 &BaseCompilerProperties{},
1884 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001885 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07001886 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001887 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07001888 &TestProperties{},
1889 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08001890 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08001891 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07001892 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07001893 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001894 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08001895 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001896 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09001897 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07001898 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001899 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08001900 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08001901 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07001902 )
Colin Crosscfad1192015-11-02 16:43:11 -08001903
Colin Cross1f44a3a2017-07-07 14:33:33 -07001904 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09001905 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07001906
1907 return module
Colin Crosscfad1192015-11-02 16:43:11 -08001908}
1909
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001910const (
1911 // coreMode is the variant used for framework-private libraries, or
1912 // SDK libraries. (which framework-private libraries can use)
1913 coreMode = "core"
1914
1915 // vendorMode is the variant used for /vendor code that compiles
1916 // against the VNDK.
1917 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09001918
1919 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001920)
1921
Jiyong Park6a43f042017-10-12 23:05:00 +09001922func squashVendorSrcs(m *Module) {
1923 if lib, ok := m.compiler.(*libraryDecorator); ok {
1924 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1925 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
1926
1927 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1928 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
1929 }
1930}
1931
Jiyong Parkf9332f12018-02-01 00:54:12 +09001932func squashRecoverySrcs(m *Module) {
1933 if lib, ok := m.compiler.(*libraryDecorator); ok {
1934 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
1935 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
1936
1937 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
1938 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
1939 }
1940}
1941
Jiyong Parkda6eb592018-12-19 17:12:36 +09001942func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001943 if mctx.Os() != android.Android {
1944 return
1945 }
1946
Jiyong Park7ed9de32018-10-15 22:25:07 +09001947 if g, ok := mctx.Module().(*genrule.Module); ok {
1948 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09001949 var coreVariantNeeded bool = false
1950 var vendorVariantNeeded bool = false
1951 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09001952 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09001953 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001954 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09001955 coreVariantNeeded = true
1956 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09001957 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09001958 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001959 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09001960 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001961 }
Jiyong Park3f736c92018-05-24 13:36:56 +09001962 if Bool(props.Recovery_available) {
1963 recoveryVariantNeeded = true
1964 }
1965
Jiyong Park413cc742018-06-19 01:46:06 +09001966 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09001967 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09001968 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09001969 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09001970 recoveryVariantNeeded = false
1971 }
1972 }
1973
Jiyong Park3f736c92018-05-24 13:36:56 +09001974 var variants []string
1975 if coreVariantNeeded {
1976 variants = append(variants, coreMode)
1977 }
1978 if vendorVariantNeeded {
1979 variants = append(variants, vendorMode)
1980 }
1981 if recoveryVariantNeeded {
1982 variants = append(variants, recoveryMode)
1983 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001984 mod := mctx.CreateVariations(variants...)
1985 for i, v := range variants {
1986 if v == recoveryMode {
1987 m := mod[i].(*genrule.Module)
1988 m.Extra.(*GenruleExtraProperties).InRecovery = true
1989 }
1990 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001991 }
1992 }
1993
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001994 m, ok := mctx.Module().(*Module)
1995 if !ok {
1996 return
1997 }
1998
1999 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002000 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002001 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002002
2003 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002004 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002005 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002006 return
2007 }
Logan Chienf3511742017-10-31 18:04:35 +08002008
2009 if vndkdep := m.vndkdep; vndkdep != nil {
2010 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002011 if productSpecific {
2012 mctx.PropertyErrorf("product_specific",
2013 "product_specific must not be true when `vndk: {enabled: true}`")
2014 return
2015 }
Logan Chienf3511742017-10-31 18:04:35 +08002016 if vendorSpecific {
2017 if !vndkdep.isVndkExt() {
2018 mctx.PropertyErrorf("vndk",
2019 "must set `extends: \"...\"` to vndk extension")
2020 return
2021 }
2022 } else {
2023 if vndkdep.isVndkExt() {
2024 mctx.PropertyErrorf("vndk",
2025 "must set `vendor: true` to set `extends: %q`",
2026 m.getVndkExtendsModuleName())
2027 return
2028 }
2029 if m.VendorProperties.Vendor_available == nil {
2030 mctx.PropertyErrorf("vndk",
2031 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2032 return
2033 }
2034 }
2035 } else {
2036 if vndkdep.isVndkSp() {
2037 mctx.PropertyErrorf("vndk",
2038 "must set `enabled: true` to set `support_system_process: true`")
2039 return
2040 }
2041 if vndkdep.isVndkExt() {
2042 mctx.PropertyErrorf("vndk",
2043 "must set `enabled: true` to set `extends: %q`",
2044 m.getVndkExtendsModuleName())
2045 return
2046 }
Justin Yun8effde42017-06-23 19:24:43 +09002047 }
2048 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002049
Jiyong Parkf9332f12018-02-01 00:54:12 +09002050 var coreVariantNeeded bool = false
2051 var vendorVariantNeeded bool = false
2052 var recoveryVariantNeeded bool = false
2053
Justin Yun71549282017-11-17 12:10:28 +09002054 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002055 // If the device isn't compiling against the VNDK, we always
2056 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002057 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002058 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2059 // LL-NDK stubs only exist in the vendor variant, since the
2060 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002061 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002062 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2063 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002064 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002065 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002066 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2067 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002068 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002069 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002070 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002071 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002072 coreVariantNeeded = true
2073 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002074 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002075 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002076 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002077 } else {
2078 // This is either in /system (or similar: /data), or is a
2079 // modules built with the NDK. Modules built with the NDK
2080 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002081 coreVariantNeeded = true
2082 }
2083
2084 if Bool(m.Properties.Recovery_available) {
2085 recoveryVariantNeeded = true
2086 }
2087
2088 if m.ModuleBase.InstallInRecovery() {
2089 recoveryVariantNeeded = true
2090 coreVariantNeeded = false
2091 }
2092
Jiyong Park413cc742018-06-19 01:46:06 +09002093 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002094 primaryArch := mctx.Config().DevicePrimaryArchType()
2095 moduleArch := m.Target().Arch.ArchType
2096 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002097 recoveryVariantNeeded = false
2098 }
2099 }
2100
Jiyong Parkf9332f12018-02-01 00:54:12 +09002101 var variants []string
2102 if coreVariantNeeded {
2103 variants = append(variants, coreMode)
2104 }
2105 if vendorVariantNeeded {
2106 variants = append(variants, vendorMode)
2107 }
2108 if recoveryVariantNeeded {
2109 variants = append(variants, recoveryMode)
2110 }
2111 mod := mctx.CreateVariations(variants...)
2112 for i, v := range variants {
2113 if v == vendorMode {
2114 m := mod[i].(*Module)
2115 m.Properties.UseVndk = true
2116 squashVendorSrcs(m)
2117 } else if v == recoveryMode {
2118 m := mod[i].(*Module)
2119 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002120 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002121 squashRecoverySrcs(m)
2122 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002123 }
2124}
2125
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002126func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002127 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002128 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2129 }
Colin Cross6510f912017-11-29 00:27:14 -08002130 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002131}
2132
Colin Cross06a931b2015-10-28 17:23:31 -07002133var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002134var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002135var BoolPtr = proptools.BoolPtr
2136var String = proptools.String
2137var StringPtr = proptools.StringPtr