blob: bb24942a241d88587767c6b4b013bd2581a80761 [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 (
Logan Chien41eabe62019-04-10 13:33:58 +080022 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070023 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080024 "strings"
25
Colin Cross97ba0732015-03-23 17:50:24 -070026 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070027 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070028
Colin Cross635c3b02016-05-18 15:37:25 -070029 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070030 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070031 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080032)
33
Colin Cross463a90e2015-06-17 14:20:06 -070034func init() {
Colin Cross798bfce2016-10-12 14:28:16 -070035 android.RegisterModuleType("cc_defaults", defaultsFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070036
Colin Cross1e676be2016-10-12 14:38:15 -070037 android.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Jiyong Parkda6eb592018-12-19 17:12:36 +090038 ctx.BottomUp("image", ImageMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070039 ctx.BottomUp("link", LinkageMutator).Parallel()
Jiyong Parkda6eb592018-12-19 17:12:36 +090040 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070041 ctx.BottomUp("ndk_api", ndkApiMutator).Parallel()
42 ctx.BottomUp("test_per_src", testPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090043 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070044 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimc0907f12019-02-08 21:00:45 +090045 ctx.BottomUp("sysprop", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070046 })
Colin Cross16b23492016-01-06 14:41:07 -080047
Colin Cross1e676be2016-10-12 14:38:15 -070048 android.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
49 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
50 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080051
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070052 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
53 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
54
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000055 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
56 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
57
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080058 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
59 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
60
Colin Cross1e676be2016-10-12 14:38:15 -070061 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
62 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080063
Colin Cross6b753602018-06-21 13:03:07 -070064 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator)
Jiyong Park379de2f2018-12-19 02:47:14 +090065 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080066
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080067 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080068 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070069
70 ctx.TopDown("lto_deps", ltoDepsMutator)
71 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090072
73 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070074 })
Colin Crossb98c8b02016-07-29 13:44:28 -070075
76 pctx.Import("android/soong/cc/config")
Colin Cross463a90e2015-06-17 14:20:06 -070077}
78
Colin Crossca860ac2016-01-04 14:34:37 -080079type Deps struct {
80 SharedLibs, LateSharedLibs []string
81 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080082 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080083 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070084
Colin Cross5950f382016-12-13 12:50:57 -080085 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070086
Colin Cross81413472016-04-11 14:37:39 -070087 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070088
Dan Willemsenb40aab62016-04-20 14:21:14 -070089 GeneratedSources []string
90 GeneratedHeaders []string
91
Dan Willemsenb3454ab2016-09-28 17:34:58 -070092 ReexportGeneratedHeaders []string
93
Colin Cross97ba0732015-03-23 17:50:24 -070094 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -070095
96 // Used for host bionic
97 LinkerFlagsFile string
98 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -070099}
100
Colin Crossca860ac2016-01-04 14:34:37 -0800101type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700102 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900103 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700104 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900105 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700106 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700107 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700108
Colin Cross26c34ed2016-09-30 17:10:16 -0700109 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700110 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800111 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700112 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700113
Colin Cross26c34ed2016-09-30 17:10:16 -0700114 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700115 GeneratedSources android.Paths
116 GeneratedHeaders android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700117
Dan Willemsen76f08272016-07-09 00:14:08 -0700118 Flags, ReexportedFlags []string
Dan Willemsen847dcc72016-09-29 12:13:36 -0700119 ReexportedFlagsDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700122 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700123
124 // Path to the file container flags to use with the linker
125 LinkerFlagsFile android.OptionalPath
126
127 // Path to the dynamic linker binary
128 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129}
130
Colin Crossca860ac2016-01-04 14:34:37 -0800131type Flags struct {
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700132 GlobalFlags []string // Flags that apply to C, C++, and assembly source files
133 ArFlags []string // Flags that apply to ar
134 AsFlags []string // Flags that apply to assembly source files
135 CFlags []string // Flags that apply to C and C++ source files
136 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
137 ConlyFlags []string // Flags that apply to C source files
138 CppFlags []string // Flags that apply to C++ source files
139 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700140 aidlFlags []string // Flags that apply to aidl source files
141 rsFlags []string // Flags that apply to renderscript source files
142 LdFlags []string // Flags that apply to linker command lines
143 libFlags []string // Flags to add libraries early to the link order
144 TidyFlags []string // Flags that apply to clang-tidy
145 SAbiFlags []string // Flags that apply to header-abi-dumper
146 YasmFlags []string // Flags that apply to yasm assembly source files
Colin Cross28344522015-04-22 13:07:53 -0700147
Colin Crossc3199482017-03-30 15:03:04 -0700148 // Global include flags that apply to C, C++, and assembly source files
149 // These must be after any module include flags, which will be in GlobalFlags.
150 SystemIncludeFlags []string
151
Colin Crossb98c8b02016-07-29 13:44:28 -0700152 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700153 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800154 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800155 SAbiDump bool
Colin Crossca860ac2016-01-04 14:34:37 -0800156
157 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800158 DynamicLinker string
159
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700160 CFlagsDeps android.Paths // Files depended on by compiler flags
161 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800162
163 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800164
Colin Cross19878da2019-03-28 14:45:07 -0700165 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700166 protoC bool // Whether to use C instead of C++
167 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700168
169 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700170}
171
Colin Cross81413472016-04-11 14:37:39 -0700172type ObjectLinkerProperties struct {
173 // names of other cc_object modules to link into this module using partial linking
174 Objs []string `android:"arch_variant"`
Dan Willemsenefb1dd92017-09-18 22:47:20 -0700175
176 // if set, add an extra objcopy --prefix-symbols= step
Nan Zhang0007d812017-11-07 10:57:05 -0800177 Prefix_symbols *string
Colin Cross81413472016-04-11 14:37:39 -0700178}
179
Colin Crossca860ac2016-01-04 14:34:37 -0800180// Properties used to compile all C or C++ modules
181type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700182 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800183 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700184
185 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800186 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700187
Jiyong Parkde866cb2018-12-07 23:08:36 +0900188 AndroidMkSharedLibs []string `blueprint:"mutated"`
189 AndroidMkStaticLibs []string `blueprint:"mutated"`
190 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
191 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
192 HideFromMake bool `blueprint:"mutated"`
193 PreventInstall bool `blueprint:"mutated"`
194 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700195
196 UseVndk bool `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800197
198 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
199 // file
200 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900201
202 // Make this module available when building for recovery
203 Recovery_available *bool
204
205 InRecovery bool `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900206
207 // Allows this module to use non-APEX version of libraries. Useful
208 // for building binaries that are started before APEXes are activated.
209 Bootstrap *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700210}
211
212type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900213 // whether this module should be allowed to be directly depended by other
214 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
215 // If set to true, two variants will be built separately, one like
216 // normal, and the other limited to the set of libraries and headers
217 // that are exposed to /vendor modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700218 //
219 // The vendor variant may be used with a different (newer) /system,
220 // so it shouldn't have any unversioned runtime dependencies, or
221 // make assumptions about the system that may not be true in the
222 // future.
223 //
Jiyong Park82e2bf32017-08-16 14:05:54 +0900224 // If set to false, this module becomes inaccessible from /vendor modules.
225 //
226 // Default value is true when vndk: {enabled: true} or vendor: true.
227 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700228 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
229 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900230
231 // whether this module is capable of being loaded with other instance
232 // (possibly an older version) of the same module in the same process.
233 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
234 // can be double loaded in a vendor process if the library is also a
235 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
236 // explicitly marked as `double_loadable: true` by the owner, or the dependency
237 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
238 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800239}
240
Colin Crossca860ac2016-01-04 14:34:37 -0800241type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800242 static() bool
243 staticBinary() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700244 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700245 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800246 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700247 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800248 isNdk() bool
249 isLlndk() bool
250 isLlndkPublic() bool
251 isVndkPrivate() bool
Justin Yun8effde42017-06-23 19:24:43 +0900252 isVndk() bool
253 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800254 isVndkExt() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900255 inRecovery() bool
Logan Chien2f2b8902018-07-10 15:01:19 +0800256 shouldCreateVndkSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700257 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700258 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800259 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800260 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800261 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800262 useClangLld(actx ModuleContext) bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900263 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900264 hasStubsVariants() bool
265 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900266 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800267 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700268 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800269}
270
271type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700272 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800273 ModuleContextIntf
274}
275
276type BaseModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700277 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800278 ModuleContextIntf
279}
280
Colin Cross37047f12016-12-13 17:06:13 -0800281type DepsContext interface {
282 android.BottomUpMutatorContext
283 ModuleContextIntf
284}
285
Colin Crossca860ac2016-01-04 14:34:37 -0800286type feature interface {
287 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800288 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800289 flags(ctx ModuleContext, flags Flags) Flags
290 props() []interface{}
291}
292
293type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700294 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800295 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800296 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700297 compilerProps() []interface{}
298
Colin Cross76fada02016-07-27 10:31:13 -0700299 appendCflags([]string)
300 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700301 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800302}
303
304type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700305 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800306 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700307 linkerFlags(ctx ModuleContext, flags Flags) Flags
308 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800309 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700310
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700311 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700312 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900313 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700314
315 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800316}
317
318type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700319 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700320 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800321 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700322 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700323 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900324 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800325}
326
Colin Crossc99deeb2016-04-11 15:06:20 -0700327type dependencyTag struct {
328 blueprint.BaseDependencyTag
329 name string
330 library bool
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700331
332 reexportFlags bool
Jiyong Park25fc6a92018-11-18 18:02:45 +0900333
334 explicitlyVersioned bool
Colin Crossc99deeb2016-04-11 15:06:20 -0700335}
336
337var (
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700338 sharedDepTag = dependencyTag{name: "shared", library: true}
339 sharedExportDepTag = dependencyTag{name: "shared", library: true, reexportFlags: true}
Jiyong Park64a44f22019-01-18 14:37:08 +0900340 earlySharedDepTag = dependencyTag{name: "early_shared", library: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700341 lateSharedDepTag = dependencyTag{name: "late shared", library: true}
342 staticDepTag = dependencyTag{name: "static", library: true}
343 staticExportDepTag = dependencyTag{name: "static", library: true, reexportFlags: true}
344 lateStaticDepTag = dependencyTag{name: "late static", library: true}
345 wholeStaticDepTag = dependencyTag{name: "whole static", library: true, reexportFlags: true}
Colin Cross32ec36c2016-12-15 07:39:51 -0800346 headerDepTag = dependencyTag{name: "header", library: true}
347 headerExportDepTag = dependencyTag{name: "header", library: true, reexportFlags: true}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700348 genSourceDepTag = dependencyTag{name: "gen source"}
349 genHeaderDepTag = dependencyTag{name: "gen header"}
350 genHeaderExportDepTag = dependencyTag{name: "gen header", reexportFlags: true}
351 objDepTag = dependencyTag{name: "obj"}
352 crtBeginDepTag = dependencyTag{name: "crtbegin"}
353 crtEndDepTag = dependencyTag{name: "crtend"}
Dan Willemsena0790e32018-10-12 00:24:23 -0700354 linkerFlagsDepTag = dependencyTag{name: "linker flags file"}
355 dynamicLinkerDepTag = dependencyTag{name: "dynamic linker"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700356 reuseObjTag = dependencyTag{name: "reuse objects"}
Jiyong Parke4bb9862019-02-01 00:31:10 +0900357 staticVariantTag = dependencyTag{name: "static variant"}
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700358 ndkStubDepTag = dependencyTag{name: "ndk stub", library: true}
359 ndkLateStubDepTag = dependencyTag{name: "ndk late stub", library: true}
Logan Chienf3511742017-10-31 18:04:35 +0800360 vndkExtDepTag = dependencyTag{name: "vndk extends", library: true}
Logan Chien43d34c32017-12-20 01:17:32 +0800361 runtimeDepTag = dependencyTag{name: "runtime lib"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700362)
363
Colin Crossca860ac2016-01-04 14:34:37 -0800364// Module contains the properties and members used by all C/C++ module types, and implements
365// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
366// to construct the output file. Behavior can be customized with a Customizer interface
367type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700368 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700369 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900370 android.ApexModuleBase
Colin Crossc472d572015-03-17 15:06:21 -0700371
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700372 Properties BaseProperties
373 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700374
Colin Crossca860ac2016-01-04 14:34:37 -0800375 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700376 hod android.HostOrDeviceSupported
377 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700378
Colin Crossca860ac2016-01-04 14:34:37 -0800379 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700380 features []feature
381 compiler compiler
382 linker linker
383 installer installer
384 stl *stl
385 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800386 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800387 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900388 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700389 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700390 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800391 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800392
393 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700394
Colin Cross635c3b02016-05-18 15:37:25 -0700395 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800396
Colin Crossb98c8b02016-07-29 13:44:28 -0700397 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700398
399 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800400
401 // Flags used to compile this module
402 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700403
404 // 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 -0800405 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700406 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800407 depsInLinkOrder android.Paths
408
409 // only non-nil when this is a shared library that reuses the objects of a static library
410 staticVariant *Module
Colin Crossc472d572015-03-17 15:06:21 -0700411}
412
Jiyong Parkc20eee32018-09-05 22:36:17 +0900413func (c *Module) OutputFile() android.OptionalPath {
414 return c.outputFile
415}
416
Jiyong Park719b4462019-01-13 00:39:51 +0900417func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900418 if c.linker != nil {
419 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900420 }
421 return nil
422}
423
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900424func (c *Module) RelativeInstallPath() string {
425 if c.installer != nil {
426 return c.installer.relativeInstallPath()
427 }
428 return ""
429}
430
Colin Cross36242852017-06-23 15:06:31 -0700431func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700432 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800433 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700434 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800435 }
436 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700437 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800438 }
439 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700440 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800441 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700442 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700443 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700444 }
Colin Cross16b23492016-01-06 14:41:07 -0800445 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700446 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800447 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800448 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700449 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800450 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800451 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700452 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800453 }
Justin Yun8effde42017-06-23 19:24:43 +0900454 if c.vndkdep != nil {
455 c.AddProperties(c.vndkdep.props()...)
456 }
Stephen Craneba090d12017-05-09 15:44:35 -0700457 if c.lto != nil {
458 c.AddProperties(c.lto.props()...)
459 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700460 if c.pgo != nil {
461 c.AddProperties(c.pgo.props()...)
462 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800463 if c.xom != nil {
464 c.AddProperties(c.xom.props()...)
465 }
Colin Crossca860ac2016-01-04 14:34:37 -0800466 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700467 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800468 }
Colin Crossc472d572015-03-17 15:06:21 -0700469
Colin Crossa9d8bee2018-10-02 13:59:46 -0700470 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
471 switch class {
472 case android.Device:
473 return ctx.Config().DevicePrefer32BitExecutables()
474 case android.HostCross:
475 // Windows builds always prefer 32-bit
476 return true
477 default:
478 return false
479 }
480 })
Colin Cross36242852017-06-23 15:06:31 -0700481 android.InitAndroidArchModule(c, c.hod, c.multilib)
Colin Crossc472d572015-03-17 15:06:21 -0700482
Colin Cross1f44a3a2017-07-07 14:33:33 -0700483 android.InitDefaultableModule(c)
Colin Cross36242852017-06-23 15:06:31 -0700484
Jiyong Park9d452992018-10-03 00:38:19 +0900485 android.InitApexModule(c)
486
Colin Cross36242852017-06-23 15:06:31 -0700487 return c
Colin Crossc472d572015-03-17 15:06:21 -0700488}
489
Colin Crossb916a382016-07-29 17:28:03 -0700490// Returns true for dependency roots (binaries)
491// TODO(ccross): also handle dlopenable libraries
492func (c *Module) isDependencyRoot() bool {
493 if root, ok := c.linker.(interface {
494 isDependencyRoot() bool
495 }); ok {
496 return root.isDependencyRoot()
497 }
498 return false
499}
500
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700501func (c *Module) useVndk() bool {
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700502 return c.Properties.UseVndk
503}
504
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800505func (c *Module) isCoverageVariant() bool {
506 return c.coverage.Properties.IsCoverageVariant
507}
508
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800509func (c *Module) isNdk() bool {
510 return inList(c.Name(), ndkMigratedLibs)
511}
512
513func (c *Module) isLlndk() bool {
514 // Returns true for both LLNDK (public) and LLNDK-private libs.
515 return inList(c.Name(), llndkLibraries)
516}
517
518func (c *Module) isLlndkPublic() bool {
519 // Returns true only for LLNDK (public) libs.
520 return c.isLlndk() && !c.isVndkPrivate()
521}
522
523func (c *Module) isVndkPrivate() bool {
524 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
525 return inList(c.Name(), vndkPrivateLibraries)
526}
527
Justin Yun8effde42017-06-23 19:24:43 +0900528func (c *Module) isVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800529 if vndkdep := c.vndkdep; vndkdep != nil {
530 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900531 }
532 return false
533}
534
Yi Kong7e53c572018-02-14 18:16:12 +0800535func (c *Module) isPgoCompile() bool {
536 if pgo := c.pgo; pgo != nil {
537 return pgo.Properties.PgoCompile
538 }
539 return false
540}
541
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800542func (c *Module) isNDKStubLibrary() bool {
543 if _, ok := c.compiler.(*stubDecorator); ok {
544 return true
545 }
546 return false
547}
548
Logan Chienf3511742017-10-31 18:04:35 +0800549func (c *Module) isVndkSp() bool {
550 if vndkdep := c.vndkdep; vndkdep != nil {
551 return vndkdep.isVndkSp()
552 }
553 return false
554}
555
556func (c *Module) isVndkExt() bool {
557 if vndkdep := c.vndkdep; vndkdep != nil {
558 return vndkdep.isVndkExt()
559 }
560 return false
561}
562
Vic Yangefd249e2018-11-12 20:19:56 -0800563func (c *Module) mustUseVendorVariant() bool {
564 return c.isVndkSp() || inList(c.Name(), config.VndkMustUseVendorVariantList)
565}
566
Logan Chienf3511742017-10-31 18:04:35 +0800567func (c *Module) getVndkExtendsModuleName() string {
568 if vndkdep := c.vndkdep; vndkdep != nil {
569 return vndkdep.getVndkExtendsModuleName()
570 }
571 return ""
572}
573
Jiyong Park82e2bf32017-08-16 14:05:54 +0900574// Returns true only when this module is configured to have core and vendor
575// variants.
576func (c *Module) hasVendorVariant() bool {
577 return c.isVndk() || Bool(c.VendorProperties.Vendor_available)
578}
579
Jiyong Parkf9332f12018-02-01 00:54:12 +0900580func (c *Module) inRecovery() bool {
581 return c.Properties.InRecovery || c.ModuleBase.InstallInRecovery()
582}
583
584func (c *Module) onlyInRecovery() bool {
585 return c.ModuleBase.InstallInRecovery()
586}
587
Jiyong Park25fc6a92018-11-18 18:02:45 +0900588func (c *Module) IsStubs() bool {
589 if library, ok := c.linker.(*libraryDecorator); ok {
590 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900591 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
592 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900593 }
594 return false
595}
596
597func (c *Module) HasStubsVariants() bool {
598 if library, ok := c.linker.(*libraryDecorator); ok {
599 return len(library.Properties.Stubs.Versions) > 0
600 }
601 return false
602}
603
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900604func (c *Module) bootstrap() bool {
605 return Bool(c.Properties.Bootstrap)
606}
607
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700608func (c *Module) nativeCoverage() bool {
609 return c.linker != nil && c.linker.nativeCoverage()
610}
611
Jiyong Parkf1194352019-02-25 11:05:47 +0900612func isBionic(name string) bool {
613 switch name {
614 case "libc", "libm", "libdl", "linker":
615 return true
616 }
617 return false
618}
619
Colin Crossca860ac2016-01-04 14:34:37 -0800620type baseModuleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700621 android.BaseContext
Colin Crossca860ac2016-01-04 14:34:37 -0800622 moduleContextImpl
623}
624
Colin Cross37047f12016-12-13 17:06:13 -0800625type depsContext struct {
626 android.BottomUpMutatorContext
627 moduleContextImpl
628}
629
Colin Crossca860ac2016-01-04 14:34:37 -0800630type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700631 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800632 moduleContextImpl
633}
634
Jiyong Park2db76922017-11-08 16:03:48 +0900635func (ctx *moduleContext) SocSpecific() bool {
636 return ctx.ModuleContext.SocSpecific() ||
637 (ctx.mod.hasVendorVariant() && ctx.mod.useVndk() && !ctx.mod.isVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700638}
639
Colin Crossca860ac2016-01-04 14:34:37 -0800640type moduleContextImpl struct {
641 mod *Module
642 ctx BaseModuleContext
643}
644
Colin Crossb98c8b02016-07-29 13:44:28 -0700645func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -0800646 return ctx.mod.toolchain(ctx.ctx)
647}
648
649func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +0000650 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -0800651}
652
653func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +0900654 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -0800655}
656
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700657func (ctx *moduleContextImpl) useSdk() bool {
Doug Hornc32c6b02019-01-17 14:44:05 -0800658 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -0800659 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -0700660 }
661 return false
Colin Crossca860ac2016-01-04 14:34:37 -0800662}
663
664func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -0700665 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700666 if ctx.useVndk() {
Justin Yun732aa6a2018-03-23 17:43:47 +0900667 vndk_ver := ctx.ctx.DeviceConfig().VndkVersion()
Ryan Prichard05206112018-03-26 21:25:27 -0700668 if vndk_ver == "current" {
Justin Yun732aa6a2018-03-23 17:43:47 +0900669 platform_vndk_ver := ctx.ctx.DeviceConfig().PlatformVndkVersion()
670 if inList(platform_vndk_ver, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
671 return "current"
672 }
673 return platform_vndk_ver
674 }
675 return vndk_ver
Dan Willemsend2ede872016-11-18 14:54:24 -0800676 }
Justin Yun732aa6a2018-03-23 17:43:47 +0900677 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -0700678 }
679 return ""
Colin Crossca860ac2016-01-04 14:34:37 -0800680}
681
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700682func (ctx *moduleContextImpl) useVndk() bool {
683 return ctx.mod.useVndk()
684}
Justin Yun8effde42017-06-23 19:24:43 +0900685
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800686func (ctx *moduleContextImpl) isNdk() bool {
687 return ctx.mod.isNdk()
688}
689
690func (ctx *moduleContextImpl) isLlndk() bool {
691 return ctx.mod.isLlndk()
692}
693
694func (ctx *moduleContextImpl) isLlndkPublic() bool {
695 return ctx.mod.isLlndkPublic()
696}
697
698func (ctx *moduleContextImpl) isVndkPrivate() bool {
699 return ctx.mod.isVndkPrivate()
700}
701
Logan Chienf3511742017-10-31 18:04:35 +0800702func (ctx *moduleContextImpl) isVndk() bool {
703 return ctx.mod.isVndk()
704}
705
Yi Kong7e53c572018-02-14 18:16:12 +0800706func (ctx *moduleContextImpl) isPgoCompile() bool {
707 return ctx.mod.isPgoCompile()
708}
709
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800710func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
711 return ctx.mod.isNDKStubLibrary()
712}
713
Justin Yun8effde42017-06-23 19:24:43 +0900714func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800715 return ctx.mod.isVndkSp()
716}
717
718func (ctx *moduleContextImpl) isVndkExt() bool {
719 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +0900720}
721
Vic Yangefd249e2018-11-12 20:19:56 -0800722func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
723 return ctx.mod.mustUseVendorVariant()
724}
725
Jiyong Parkf9332f12018-02-01 00:54:12 +0900726func (ctx *moduleContextImpl) inRecovery() bool {
727 return ctx.mod.inRecovery()
728}
729
Logan Chien2f2b8902018-07-10 15:01:19 +0800730// Check whether ABI dumps should be created for this module.
731func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
732 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
733 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -0800734 }
Doug Hornc32c6b02019-01-17 14:44:05 -0800735
736 if ctx.ctx.Fuchsia() {
737 return false
738 }
739
Logan Chien2f2b8902018-07-10 15:01:19 +0800740 if sanitize := ctx.mod.sanitize; sanitize != nil {
741 if !sanitize.isVariantOnProductionDevice() {
742 return false
743 }
744 }
745 if !ctx.ctx.Device() {
746 // Host modules do not need ABI dumps.
747 return false
748 }
Logan Chienfa478c02018-12-28 16:25:39 +0800749 if !ctx.mod.IsForPlatform() {
750 // APEX variants do not need ABI dumps.
751 return false
752 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800753 if ctx.isNdk() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800754 return true
755 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800756 if ctx.isLlndkPublic() {
Logan Chienf4b79c62018-08-02 02:27:02 +0800757 return true
758 }
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800759 if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
Logan Chien2f2b8902018-07-10 15:01:19 +0800760 // Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
761 // VNDK-private.
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800762 return true
Logan Chien2f2b8902018-07-10 15:01:19 +0800763 }
764 return false
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800765}
766
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700767func (ctx *moduleContextImpl) selectedStl() string {
768 if stl := ctx.mod.stl; stl != nil {
769 return stl.Properties.SelectedStl
770 }
771 return ""
772}
773
Ivan Lozanobd721262018-11-27 14:33:03 -0800774func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
775 return ctx.mod.linker.useClangLld(actx)
776}
777
Colin Crossce75d2c2016-10-06 16:12:58 -0700778func (ctx *moduleContextImpl) baseModuleName() string {
779 return ctx.mod.ModuleBase.BaseModuleName()
780}
781
Logan Chienf3511742017-10-31 18:04:35 +0800782func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
783 return ctx.mod.getVndkExtendsModuleName()
784}
785
Jiyong Park58e364a2019-01-19 19:24:06 +0900786func (ctx *moduleContextImpl) apexName() string {
787 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +0900788}
789
Jiyong Parkb0788572018-12-20 22:10:17 +0900790func (ctx *moduleContextImpl) hasStubsVariants() bool {
791 return ctx.mod.HasStubsVariants()
792}
793
794func (ctx *moduleContextImpl) isStubs() bool {
795 return ctx.mod.IsStubs()
796}
797
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900798func (ctx *moduleContextImpl) bootstrap() bool {
799 return ctx.mod.bootstrap()
800}
801
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700802func (ctx *moduleContextImpl) nativeCoverage() bool {
803 return ctx.mod.nativeCoverage()
804}
805
Colin Cross635c3b02016-05-18 15:37:25 -0700806func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800807 return &Module{
808 hod: hod,
809 multilib: multilib,
810 }
811}
812
Colin Cross635c3b02016-05-18 15:37:25 -0700813func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -0800814 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700815 module.features = []feature{
816 &tidyFeature{},
817 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700818 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -0800819 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -0800820 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800821 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +0900822 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -0700823 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700824 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -0800825 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -0800826 return module
827}
828
Colin Crossce75d2c2016-10-06 16:12:58 -0700829func (c *Module) Prebuilt() *android.Prebuilt {
830 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
831 return p.prebuilt()
832 }
833 return nil
834}
835
836func (c *Module) Name() string {
837 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -0700838 if p, ok := c.linker.(interface {
839 Name(string) string
840 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -0700841 name = p.Name(name)
842 }
843 return name
844}
845
Alex Light3d673592019-01-18 14:37:31 -0800846func (c *Module) Symlinks() []string {
847 if p, ok := c.installer.(interface {
848 symlinkList() []string
849 }); ok {
850 return p.symlinkList()
851 }
852 return nil
853}
854
Jeff Gaston294356f2017-09-27 17:05:30 -0700855// orderDeps reorders dependencies into a list such that if module A depends on B, then
856// A will precede B in the resultant list.
857// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800858// Note that directSharedDeps should be the analogous static library for each shared lib dep
859func 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 -0700860 // If A depends on B, then
861 // Every list containing A will also contain B later in the list
862 // So, after concatenating all lists, the final instance of B will have come from the same
863 // original list as the final instance of A
864 // So, the final instance of B will be later in the concatenation than the final A
865 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
866 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800867 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -0700868 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800869 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
870 }
871 for _, dep := range directSharedDeps {
872 orderedAllDeps = append(orderedAllDeps, dep)
873 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -0700874 }
875
Colin Crossb6715442017-10-24 11:13:31 -0700876 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700877
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800878 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -0700879 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800880 // resultant list to only what the caller has chosen to include in directStaticDeps
881 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700882
883 return orderedAllDeps, orderedDeclaredDeps
884}
885
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800886func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*Module) (results []android.Path) {
887 // convert Module to Path
888 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
889 staticDepFiles := []android.Path{}
890 for _, dep := range staticDeps {
891 allTransitiveDeps[dep.outputFile.Path()] = dep.depsInLinkOrder
892 staticDepFiles = append(staticDepFiles, dep.outputFile.Path())
Jeff Gaston294356f2017-09-27 17:05:30 -0700893 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800894 sharedDepFiles := []android.Path{}
895 for _, sharedDep := range sharedDeps {
896 staticAnalogue := sharedDep.staticVariant
897 if staticAnalogue != nil {
898 allTransitiveDeps[staticAnalogue.outputFile.Path()] = staticAnalogue.depsInLinkOrder
899 sharedDepFiles = append(sharedDepFiles, staticAnalogue.outputFile.Path())
900 }
Jeff Gaston294356f2017-09-27 17:05:30 -0700901 }
902
903 // reorder the dependencies based on transitive dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800904 module.depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -0700905
906 return results
Jeff Gaston294356f2017-09-27 17:05:30 -0700907}
908
Colin Cross635c3b02016-05-18 15:37:25 -0700909func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Colin Crossca860ac2016-01-04 14:34:37 -0800910 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -0700911 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -0800912 moduleContextImpl: moduleContextImpl{
913 mod: c,
914 },
915 }
916 ctx.ctx = ctx
917
Colin Crossf18e1102017-11-16 14:33:08 -0800918 deps := c.depsToPaths(ctx)
919 if ctx.Failed() {
920 return
921 }
922
Dan Willemsen8536d6b2018-10-07 20:54:34 -0700923 if c.Properties.Clang != nil && *c.Properties.Clang == false {
924 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
925 }
926
Colin Crossca860ac2016-01-04 14:34:37 -0800927 flags := Flags{
928 Toolchain: c.toolchain(ctx),
Colin Crossca860ac2016-01-04 14:34:37 -0800929 }
Colin Crossca860ac2016-01-04 14:34:37 -0800930 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -0800931 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800932 }
933 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -0700934 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -0800935 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700936 if c.stl != nil {
937 flags = c.stl.flags(ctx, flags)
938 }
Colin Cross16b23492016-01-06 14:41:07 -0800939 if c.sanitize != nil {
940 flags = c.sanitize.flags(ctx, flags)
941 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800942 if c.coverage != nil {
943 flags = c.coverage.flags(ctx, flags)
944 }
Stephen Craneba090d12017-05-09 15:44:35 -0700945 if c.lto != nil {
946 flags = c.lto.flags(ctx, flags)
947 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700948 if c.pgo != nil {
949 flags = c.pgo.flags(ctx, flags)
950 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800951 if c.xom != nil {
952 flags = c.xom.flags(ctx, flags)
953 }
Colin Crossca860ac2016-01-04 14:34:37 -0800954 for _, feature := range c.features {
955 flags = feature.flags(ctx, flags)
956 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800957 if ctx.Failed() {
958 return
959 }
960
Colin Crossb98c8b02016-07-29 13:44:28 -0700961 flags.CFlags, _ = filterList(flags.CFlags, config.IllegalFlags)
962 flags.CppFlags, _ = filterList(flags.CppFlags, config.IllegalFlags)
963 flags.ConlyFlags, _ = filterList(flags.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -0800964
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800965 flags.GlobalFlags = append(flags.GlobalFlags, deps.Flags...)
966 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700967 // We need access to all the flags seen by a source file.
968 if c.sabi != nil {
969 flags = c.sabi.flags(ctx, flags)
970 }
Colin Crossca860ac2016-01-04 14:34:37 -0800971 // Optimization to reduce size of build.ninja
972 // Replace the long list of flags for each file with a module-local variable
973 ctx.Variable(pctx, "cflags", strings.Join(flags.CFlags, " "))
974 ctx.Variable(pctx, "cppflags", strings.Join(flags.CppFlags, " "))
975 ctx.Variable(pctx, "asflags", strings.Join(flags.AsFlags, " "))
976 flags.CFlags = []string{"$cflags"}
977 flags.CppFlags = []string{"$cppflags"}
978 flags.AsFlags = []string{"$asflags"}
979
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700980 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800981 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700982 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -0800983 if ctx.Failed() {
984 return
985 }
Colin Cross3f40fa42015-01-30 17:27:36 -0800986 }
987
Colin Crossca860ac2016-01-04 14:34:37 -0800988 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700989 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -0800990 if ctx.Failed() {
991 return
992 }
Colin Cross635c3b02016-05-18 15:37:25 -0700993 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +0900994
995 // If a lib is directly included in any of the APEXes, unhide the stubs
996 // variant having the latest version gets visible to make. In addition,
997 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
998 // force anything in the make world to link against the stubs library.
999 // (unless it is explicitly referenced via .bootstrap suffix or the
1000 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001001 if c.HasStubsVariants() &&
1002 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001003 !c.inRecovery() && !c.useVndk() && !c.static() && !c.isCoverageVariant() &&
1004 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001005 c.Properties.HideFromMake = false // unhide
1006 // Note: this is still non-installable
1007 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001008 }
Colin Cross5049f022015-03-18 13:28:46 -07001009
Jiyong Park9d452992018-10-03 00:38:19 +09001010 if c.installer != nil && !c.Properties.PreventInstall && c.IsForPlatform() && c.outputFile.Valid() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001011 c.installer.install(ctx, c.outputFile.Path())
1012 if ctx.Failed() {
1013 return
Colin Crossca860ac2016-01-04 14:34:37 -08001014 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001015 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001016}
1017
Jiyong Park379de2f2018-12-19 02:47:14 +09001018func (c *Module) toolchain(ctx android.BaseContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001019 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001020 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001021 }
Colin Crossca860ac2016-01-04 14:34:37 -08001022 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001023}
1024
Colin Crossca860ac2016-01-04 14:34:37 -08001025func (c *Module) begin(ctx BaseModuleContext) {
1026 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001027 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001028 }
Colin Crossca860ac2016-01-04 14:34:37 -08001029 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001030 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001031 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001032 if c.stl != nil {
1033 c.stl.begin(ctx)
1034 }
Colin Cross16b23492016-01-06 14:41:07 -08001035 if c.sanitize != nil {
1036 c.sanitize.begin(ctx)
1037 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001038 if c.coverage != nil {
1039 c.coverage.begin(ctx)
1040 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001041 if c.sabi != nil {
1042 c.sabi.begin(ctx)
1043 }
Justin Yun8effde42017-06-23 19:24:43 +09001044 if c.vndkdep != nil {
1045 c.vndkdep.begin(ctx)
1046 }
Stephen Craneba090d12017-05-09 15:44:35 -07001047 if c.lto != nil {
1048 c.lto.begin(ctx)
1049 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001050 if c.pgo != nil {
1051 c.pgo.begin(ctx)
1052 }
Colin Crossca860ac2016-01-04 14:34:37 -08001053 for _, feature := range c.features {
1054 feature.begin(ctx)
1055 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001056 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001057 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001058 if err != nil {
1059 ctx.PropertyErrorf("sdk_version", err.Error())
1060 }
Nan Zhang0007d812017-11-07 10:57:05 -08001061 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001062 }
Colin Crossca860ac2016-01-04 14:34:37 -08001063}
1064
Colin Cross37047f12016-12-13 17:06:13 -08001065func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001066 deps := Deps{}
1067
1068 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001069 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001070 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001071 // Add the PGO dependency (the clang_rt.profile runtime library), which
1072 // sometimes depends on symbols from libgcc, before libgcc gets added
1073 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001074 if c.pgo != nil {
1075 deps = c.pgo.deps(ctx, deps)
1076 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001077 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001078 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001079 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001080 if c.stl != nil {
1081 deps = c.stl.deps(ctx, deps)
1082 }
Colin Cross16b23492016-01-06 14:41:07 -08001083 if c.sanitize != nil {
1084 deps = c.sanitize.deps(ctx, deps)
1085 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001086 if c.coverage != nil {
1087 deps = c.coverage.deps(ctx, deps)
1088 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001089 if c.sabi != nil {
1090 deps = c.sabi.deps(ctx, deps)
1091 }
Justin Yun8effde42017-06-23 19:24:43 +09001092 if c.vndkdep != nil {
1093 deps = c.vndkdep.deps(ctx, deps)
1094 }
Stephen Craneba090d12017-05-09 15:44:35 -07001095 if c.lto != nil {
1096 deps = c.lto.deps(ctx, deps)
1097 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001098 for _, feature := range c.features {
1099 deps = feature.deps(ctx, deps)
1100 }
1101
Colin Crossb6715442017-10-24 11:13:31 -07001102 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1103 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1104 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1105 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1106 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1107 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001108 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001109
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001110 for _, lib := range deps.ReexportSharedLibHeaders {
1111 if !inList(lib, deps.SharedLibs) {
1112 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1113 }
1114 }
1115
1116 for _, lib := range deps.ReexportStaticLibHeaders {
1117 if !inList(lib, deps.StaticLibs) {
1118 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1119 }
1120 }
1121
Colin Cross5950f382016-12-13 12:50:57 -08001122 for _, lib := range deps.ReexportHeaderLibHeaders {
1123 if !inList(lib, deps.HeaderLibs) {
1124 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1125 }
1126 }
1127
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001128 for _, gen := range deps.ReexportGeneratedHeaders {
1129 if !inList(gen, deps.GeneratedHeaders) {
1130 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1131 }
1132 }
1133
Colin Crossc99deeb2016-04-11 15:06:20 -07001134 return deps
1135}
1136
Dan Albert7e9d2952016-08-04 13:02:36 -07001137func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001138 ctx := &baseModuleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001139 BaseContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001140 moduleContextImpl: moduleContextImpl{
1141 mod: c,
1142 },
1143 }
1144 ctx.ctx = ctx
1145
Colin Crossca860ac2016-01-04 14:34:37 -08001146 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001147}
1148
Jiyong Park7ed9de32018-10-15 22:25:07 +09001149// Split name#version into name and version
1150func stubsLibNameAndVersion(name string) (string, string) {
1151 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1152 version := name[sharp+1:]
1153 libname := name[:sharp]
1154 return libname, version
1155 }
1156 return name, ""
1157}
1158
Colin Cross1e676be2016-10-12 14:38:15 -07001159func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001160 ctx := &depsContext{
1161 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001162 moduleContextImpl: moduleContextImpl{
1163 mod: c,
1164 },
1165 }
1166 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001167
Colin Crossc99deeb2016-04-11 15:06:20 -07001168 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001169
Dan Albert914449f2016-06-17 16:45:24 -07001170 variantNdkLibs := []string{}
1171 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001172 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001173 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001174
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001175 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1176 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001177 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001178 // 1. Name of an NDK library that refers to a prebuilt module.
1179 // For each of these, it adds the name of the prebuilt module (which will be in
1180 // prebuilts/ndk) to the list of nonvariant libs.
1181 // 2. Name of an NDK library that refers to an ndk_library module.
1182 // For each of these, it adds the name of the ndk_library module to the list of
1183 // variant libs.
1184 // 3. Anything else (so anything that isn't an NDK library).
1185 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001186 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001187 // The caller can then know to add the variantLibs dependencies differently from the
1188 // nonvariantLibs
1189 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1190 variantLibs = []string{}
1191 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001192 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001193 // strip #version suffix out
1194 name, _ := stubsLibNameAndVersion(entry)
1195 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1196 if !inList(name, ndkMigratedLibs) {
1197 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001198 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001199 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001200 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09001201 } else if ctx.useVndk() && inList(name, llndkLibraries) {
1202 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
1203 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
1204 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001205 if actx.OtherModuleExists(vendorPublicLib) {
1206 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1207 } else {
1208 // This can happen if vendor_public_library module is defined in a
1209 // namespace that isn't visible to the current module. In that case,
1210 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001211 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001212 }
Dan Albert914449f2016-06-17 16:45:24 -07001213 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001214 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001215 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001216 }
1217 }
Dan Albert914449f2016-06-17 16:45:24 -07001218 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001219 }
1220
Dan Albert914449f2016-06-17 16:45:24 -07001221 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1222 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001223 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001224 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001225
Jiyong Park7e636d02019-01-28 16:16:54 +09001226 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001227 if c.linker != nil {
1228 if library, ok := c.linker.(*libraryDecorator); ok {
1229 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001230 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001231 }
1232 }
1233 }
1234
Colin Cross32ec36c2016-12-15 07:39:51 -08001235 for _, lib := range deps.HeaderLibs {
1236 depTag := headerDepTag
1237 if inList(lib, deps.ReexportHeaderLibHeaders) {
1238 depTag = headerExportDepTag
1239 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001240 if buildStubs {
Jiyong Park7e636d02019-01-28 16:16:54 +09001241 actx.AddFarVariationDependencies([]blueprint.Variation{
1242 {Mutator: "arch", Variation: ctx.Target().String()},
Jiyong Park3b1746a2019-01-29 11:15:04 +09001243 {Mutator: "image", Variation: c.imageVariation()},
Jiyong Park7e636d02019-01-28 16:16:54 +09001244 }, depTag, lib)
1245 } else {
1246 actx.AddVariationDependencies(nil, depTag, lib)
1247 }
1248 }
1249
1250 if buildStubs {
1251 // Stubs lib does not have dependency to other static/shared libraries.
1252 // Don't proceed.
1253 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001254 }
Colin Cross5950f382016-12-13 12:50:57 -08001255
Inseob Kimc0907f12019-02-08 21:00:45 +09001256 syspropImplLibraries := syspropImplLibraries(actx.Config())
1257
Jiyong Park5d1598f2019-02-25 22:14:17 +09001258 for _, lib := range deps.WholeStaticLibs {
1259 depTag := wholeStaticDepTag
1260 if impl, ok := syspropImplLibraries[lib]; ok {
1261 lib = impl
1262 }
1263 actx.AddVariationDependencies([]blueprint.Variation{
1264 {Mutator: "link", Variation: "static"},
1265 }, depTag, lib)
1266 }
1267
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001268 for _, lib := range deps.StaticLibs {
1269 depTag := staticDepTag
1270 if inList(lib, deps.ReexportStaticLibHeaders) {
1271 depTag = staticExportDepTag
1272 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001273
1274 if impl, ok := syspropImplLibraries[lib]; ok {
1275 lib = impl
1276 }
1277
Dan Willemsen59339a22018-07-22 21:18:45 -07001278 actx.AddVariationDependencies([]blueprint.Variation{
1279 {Mutator: "link", Variation: "static"},
1280 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001281 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001282
Dan Willemsen59339a22018-07-22 21:18:45 -07001283 actx.AddVariationDependencies([]blueprint.Variation{
1284 {Mutator: "link", Variation: "static"},
1285 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001286
Jiyong Park25fc6a92018-11-18 18:02:45 +09001287 addSharedLibDependencies := func(depTag dependencyTag, name string, version string) {
1288 var variations []blueprint.Variation
1289 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jiyong Park0fefdea2018-12-13 12:01:31 +09001290 versionVariantAvail := !ctx.useVndk() && !c.inRecovery()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001291 if version != "" && versionVariantAvail {
1292 // Version is explicitly specified. i.e. libFoo#30
1293 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
1294 depTag.explicitlyVersioned = true
1295 }
1296 actx.AddVariationDependencies(variations, depTag, name)
1297
1298 // If the version is not specified, add dependency to the latest stubs library.
1299 // The stubs library will be used when the depending module is built for APEX and
1300 // the dependent module is not in the same APEX.
1301 latestVersion := latestStubsVersionFor(actx.Config(), name)
1302 if version == "" && latestVersion != "" && versionVariantAvail {
1303 actx.AddVariationDependencies([]blueprint.Variation{
1304 {Mutator: "link", Variation: "shared"},
1305 {Mutator: "version", Variation: latestVersion},
1306 }, depTag, name)
1307 // Note that depTag.explicitlyVersioned is false in this case.
1308 }
1309 }
1310
Jiyong Park7ed9de32018-10-15 22:25:07 +09001311 // shared lib names without the #version suffix
1312 var sharedLibNames []string
1313
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001314 for _, lib := range deps.SharedLibs {
1315 depTag := sharedDepTag
1316 if inList(lib, deps.ReexportSharedLibHeaders) {
1317 depTag = sharedExportDepTag
1318 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001319
1320 if impl, ok := syspropImplLibraries[lib]; ok {
1321 lib = impl
1322 }
1323
1324 name, version := stubsLibNameAndVersion(lib)
1325 sharedLibNames = append(sharedLibNames, name)
1326
Jiyong Park25fc6a92018-11-18 18:02:45 +09001327 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001328 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001329
Jiyong Park7ed9de32018-10-15 22:25:07 +09001330 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001331 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001332 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1333 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1334 // linking against both the stubs lib and the non-stubs lib at the same time.
1335 continue
1336 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001337 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001338 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001339
Dan Willemsen59339a22018-07-22 21:18:45 -07001340 actx.AddVariationDependencies([]blueprint.Variation{
1341 {Mutator: "link", Variation: "shared"},
1342 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001343
Colin Cross68861832016-07-08 10:41:41 -07001344 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001345
1346 for _, gen := range deps.GeneratedHeaders {
1347 depTag := genHeaderDepTag
1348 if inList(gen, deps.ReexportGeneratedHeaders) {
1349 depTag = genHeaderExportDepTag
1350 }
1351 actx.AddDependency(c, depTag, gen)
1352 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001353
Colin Cross42d48b72018-08-29 14:10:52 -07001354 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001355
1356 if deps.CrtBegin != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001357 actx.AddVariationDependencies(nil, crtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001358 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001359 if deps.CrtEnd != "" {
Colin Cross42d48b72018-08-29 14:10:52 -07001360 actx.AddVariationDependencies(nil, crtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001361 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001362 if deps.LinkerFlagsFile != "" {
1363 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1364 }
1365 if deps.DynamicLinker != "" {
1366 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001367 }
Dan Albert914449f2016-06-17 16:45:24 -07001368
1369 version := ctx.sdkVersion()
1370 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001371 {Mutator: "ndk_api", Variation: version},
1372 {Mutator: "link", Variation: "shared"},
1373 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001374 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001375 {Mutator: "ndk_api", Variation: version},
1376 {Mutator: "link", Variation: "shared"},
1377 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001378
1379 if vndkdep := c.vndkdep; vndkdep != nil {
1380 if vndkdep.isVndkExt() {
1381 baseModuleMode := vendorMode
1382 if actx.DeviceConfig().VndkVersion() == "" {
1383 baseModuleMode = coreMode
1384 }
1385 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001386 {Mutator: "image", Variation: baseModuleMode},
1387 {Mutator: "link", Variation: "shared"},
1388 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001389 }
1390 }
Colin Cross6362e272015-10-29 15:25:03 -07001391}
Colin Cross21b9a242015-03-24 14:15:58 -07001392
Colin Crosse40b4ea2018-10-02 22:25:58 -07001393func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001394 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1395 c.beginMutator(ctx)
1396 }
1397}
1398
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001399// Whether a module can link to another module, taking into
1400// account NDK linking.
Logan Chienf3511742017-10-31 18:04:35 +08001401func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag dependencyTag) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001402 if from.Target().Os != android.Android {
1403 // Host code is not restricted
1404 return
1405 }
1406 if from.Properties.UseVndk {
1407 // Though vendor code is limited by the vendor mutator,
1408 // each vendor-available module needs to check
1409 // link-type for VNDK.
1410 if from.vndkdep != nil {
Logan Chienf3511742017-10-31 18:04:35 +08001411 from.vndkdep.vndkCheckLinkType(ctx, to, tag)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001412 }
1413 return
1414 }
Nan Zhang0007d812017-11-07 10:57:05 -08001415 if String(from.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001416 // Platform code can link to anything
1417 return
1418 }
Jiyong Parkf9332f12018-02-01 00:54:12 +09001419 if from.inRecovery() {
1420 // Recovery code is not NDK
1421 return
1422 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001423 if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
1424 // These are always allowed
1425 return
1426 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001427 if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
1428 // These are allowed, but they don't set sdk_version
1429 return
1430 }
1431 if _, ok := to.linker.(*stubDecorator); ok {
1432 // These aren't real libraries, but are the stub shared libraries that are included in
1433 // the NDK.
1434 return
1435 }
Logan Chien834b9a62019-01-14 15:39:03 +08001436
1437 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Name() == "libc++" {
1438 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1439 // to link to libc++ (non-NDK and without sdk_version).
1440 return
1441 }
1442
Nan Zhang0007d812017-11-07 10:57:05 -08001443 if String(to.Properties.Sdk_version) == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001444 // NDK code linking to platform code is never okay.
1445 ctx.ModuleErrorf("depends on non-NDK-built library %q",
1446 ctx.OtherModuleName(to))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001447 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001448 }
1449
1450 // At this point we know we have two NDK libraries, but we need to
1451 // check that we're not linking against anything built against a higher
1452 // API level, as it is only valid to link against older or equivalent
1453 // APIs.
1454
Inseob Kim01a28722018-04-11 09:48:45 +09001455 // Current can link against anything.
1456 if String(from.Properties.Sdk_version) != "current" {
1457 // Otherwise we need to check.
1458 if String(to.Properties.Sdk_version) == "current" {
1459 // Current can't be linked against by anything else.
1460 ctx.ModuleErrorf("links %q built against newer API version %q",
1461 ctx.OtherModuleName(to), "current")
1462 } else {
1463 fromApi, err := strconv.Atoi(String(from.Properties.Sdk_version))
1464 if err != nil {
1465 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001466 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001467 String(from.Properties.Sdk_version))
1468 }
1469 toApi, err := strconv.Atoi(String(to.Properties.Sdk_version))
1470 if err != nil {
1471 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001472 "Invalid sdk_version value (must be int or current): %q",
Inseob Kim01a28722018-04-11 09:48:45 +09001473 String(to.Properties.Sdk_version))
1474 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001475
Inseob Kim01a28722018-04-11 09:48:45 +09001476 if toApi > fromApi {
1477 ctx.ModuleErrorf("links %q built against newer API version %q",
1478 ctx.OtherModuleName(to), String(to.Properties.Sdk_version))
1479 }
1480 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001481 }
Dan Albert202fe492017-12-15 13:56:59 -08001482
1483 // Also check that the two STL choices are compatible.
1484 fromStl := from.stl.Properties.SelectedStl
1485 toStl := to.stl.Properties.SelectedStl
1486 if fromStl == "" || toStl == "" {
1487 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001488 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001489 // We can be permissive with the system "STL" since it is only the C++
1490 // ABI layer, but in the future we should make sure that everyone is
1491 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001492 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001493 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
1494 from.stl.Properties.SelectedStl, ctx.OtherModuleName(to),
1495 to.stl.Properties.SelectedStl)
1496 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001497}
1498
Jiyong Park5fb8c102018-04-09 12:03:06 +09001499// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001500// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1501// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001502// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001503func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1504 check := func(child, parent android.Module) bool {
1505 to, ok := child.(*Module)
1506 if !ok {
1507 // follow thru cc.Defaults, etc.
1508 return true
1509 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001510
Jooyung Hana70f0672019-01-18 15:20:43 +09001511 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1512 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001513 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001514
1515 // if target lib has no vendor variant, keep checking dependency graph
1516 if !to.hasVendorVariant() {
1517 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001518 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001519
1520 if to.isVndkSp() || inList(child.Name(), llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
1521 return false
1522 }
1523
1524 var stringPath []string
1525 for _, m := range ctx.GetWalkPath() {
1526 stringPath = append(stringPath, m.Name())
1527 }
1528 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
1529 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
1530 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
1531 return false
1532 }
1533 if module, ok := ctx.Module().(*Module); ok {
1534 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
1535 if inList(ctx.ModuleName(), llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
1536 ctx.WalkDeps(check)
1537 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001538 }
1539 }
1540}
1541
Colin Crossc99deeb2016-04-11 15:06:20 -07001542// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07001543func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08001544 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08001545
Jeff Gaston294356f2017-09-27 17:05:30 -07001546 directStaticDeps := []*Module{}
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001547 directSharedDeps := []*Module{}
Jeff Gaston294356f2017-09-27 17:05:30 -07001548
Colin Crossd11fcda2017-10-23 17:59:01 -07001549 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001550 depName := ctx.OtherModuleName(dep)
1551 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07001552
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001553 ccDep, _ := dep.(*Module)
1554 if ccDep == nil {
1555 // handling for a few module types that aren't cc Module but that are also supported
1556 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001557 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001558 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001559 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
1560 genRule.GeneratedSourceFiles()...)
1561 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001562 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001563 }
Colin Crosse90bfd12017-04-26 16:59:26 -07001564 // Support exported headers from a generated_sources dependency
1565 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001566 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001567 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07001568 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001569 genRule.GeneratedDeps()...)
Colin Cross5ed99c62016-11-22 12:55:55 -08001570 flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001571 depPaths.Flags = append(depPaths.Flags, flags)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001572 if depTag == genHeaderExportDepTag {
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001573 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001574 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08001575 genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001576 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
1577 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags)
1578
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001579 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001580 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001581 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07001582 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001583 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001584 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001585 files := genRule.GeneratedSourceFiles()
1586 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001587 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001588 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07001589 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 -07001590 }
1591 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001592 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001593 }
Colin Crossca860ac2016-01-04 14:34:37 -08001594 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001595 return
1596 }
1597
Colin Crossfe17f6f2019-03-28 19:30:56 -07001598 if depTag == android.ProtoPluginDepTag {
1599 return
1600 }
1601
Colin Crossd11fcda2017-10-23 17:59:01 -07001602 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001603 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
1604 return
1605 }
Colin Crossd11fcda2017-10-23 17:59:01 -07001606 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001607 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07001608 return
1609 }
1610
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001611 // re-exporting flags
1612 if depTag == reuseObjTag {
1613 if l, ok := ccDep.compiler.(libraryInterface); ok {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001614 c.staticVariant = ccDep
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001615 objs, flags, deps := l.reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07001616 depPaths.Objs = depPaths.Objs.Append(objs)
1617 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Colin Crossbbc9f4d2017-05-03 16:24:55 -07001618 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Colin Crossbba99042016-11-23 15:45:05 -08001619 return
1620 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001621 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001622
Jiyong Parke4bb9862019-02-01 00:31:10 +09001623 if depTag == staticVariantTag {
1624 if _, ok := ccDep.compiler.(libraryInterface); ok {
1625 c.staticVariant = ccDep
1626 return
1627 }
1628 }
1629
Jiyong Park25fc6a92018-11-18 18:02:45 +09001630 // Extract explicitlyVersioned field from the depTag and reset it inside the struct.
1631 // Otherwise, sharedDepTag and lateSharedDepTag with explicitlyVersioned set to true
1632 // won't be matched to sharedDepTag and lateSharedDepTag.
1633 explicitlyVersioned := false
1634 if t, ok := depTag.(dependencyTag); ok {
1635 explicitlyVersioned = t.explicitlyVersioned
1636 t.explicitlyVersioned = false
1637 depTag = t
1638 }
1639
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001640 if t, ok := depTag.(dependencyTag); ok && t.library {
Jiyong Park16e91a02018-12-20 18:18:08 +09001641 depIsStatic := false
1642 switch depTag {
1643 case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
1644 depIsStatic = true
1645 }
1646 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok && !depIsStatic {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001647 depIsStubs := dependentLibrary.buildStubs()
1648 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001649 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001650 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001651
1652 var useThisDep bool
1653 if depIsStubs && explicitlyVersioned {
1654 // Always respect dependency to the versioned stubs (i.e. libX#10)
1655 useThisDep = true
1656 } else if !depHasStubs {
1657 // Use non-stub variant if that is the only choice
1658 // (i.e. depending on a lib without stubs.version property)
1659 useThisDep = true
1660 } else if c.IsForPlatform() {
1661 // If not building for APEX, use stubs only when it is from
1662 // an APEX (and not from platform)
1663 useThisDep = (depInPlatform != depIsStubs)
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001664 if c.inRecovery() || c.bootstrap() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001665 // However, for recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09001666 // always link to non-stub variant
1667 useThisDep = !depIsStubs
1668 }
1669 } else {
1670 // If building for APEX, use stubs only when it is not from
1671 // the same APEX
1672 useThisDep = (depInSameApex != depIsStubs)
1673 }
1674
1675 if !useThisDep {
1676 return // stop processing this dep
1677 }
1678 }
1679
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001680 if i, ok := ccDep.linker.(exportedFlagsProducer); ok {
Dan Willemsen76f08272016-07-09 00:14:08 -07001681 flags := i.exportedFlags()
Dan Willemsen847dcc72016-09-29 12:13:36 -07001682 deps := i.exportedFlagsDeps()
Dan Willemsen76f08272016-07-09 00:14:08 -07001683 depPaths.Flags = append(depPaths.Flags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001684 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, deps...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001685
1686 if t.reexportFlags {
Dan Willemsen76f08272016-07-09 00:14:08 -07001687 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
Dan Willemsen847dcc72016-09-29 12:13:36 -07001688 depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, deps...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07001689 // 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 -07001690 // Re-exported shared library headers must be included as well since they can help us with type information
1691 // about template instantiations (instantiated from their headers).
1692 c.sabi.Properties.ReexportedIncludeFlags = append(c.sabi.Properties.ReexportedIncludeFlags, flags...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001693 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001694 }
Dan Willemsena96ff642016-06-07 12:34:45 -07001695
Logan Chienf3511742017-10-31 18:04:35 +08001696 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07001697 }
1698
Colin Cross26c34ed2016-09-30 17:10:16 -07001699 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07001700 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07001701
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001702 linkFile := ccDep.outputFile
Colin Cross26c34ed2016-09-30 17:10:16 -07001703 depFile := android.OptionalPath{}
1704
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001705 switch depTag {
Dan Albert914449f2016-06-17 16:45:24 -07001706 case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001707 ptr = &depPaths.SharedLibs
1708 depPtr = &depPaths.SharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001709 depFile = ccDep.linker.(libraryInterface).toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001710 directSharedDeps = append(directSharedDeps, ccDep)
Jiyong Park64a44f22019-01-18 14:37:08 +09001711 case earlySharedDepTag:
1712 ptr = &depPaths.EarlySharedLibs
1713 depPtr = &depPaths.EarlySharedLibsDeps
1714 depFile = ccDep.linker.(libraryInterface).toc()
1715 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07001716 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001717 ptr = &depPaths.LateSharedLibs
1718 depPtr = &depPaths.LateSharedLibsDeps
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001719 depFile = ccDep.linker.(libraryInterface).toc()
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001720 case staticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07001721 ptr = nil
1722 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07001723 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001724 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07001725 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001726 ptr = &depPaths.WholeStaticLibs
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001727 staticLib, ok := ccDep.linker.(libraryInterface)
Colin Crossb916a382016-07-29 17:28:03 -07001728 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001729 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07001730 return
1731 }
1732
1733 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001734 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
Colin Crossc99deeb2016-04-11 15:06:20 -07001735 for i := range missingDeps {
1736 missingDeps[i] += postfix
1737 }
1738 ctx.AddMissingDependencies(missingDeps)
1739 }
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001740 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
Colin Cross5950f382016-12-13 12:50:57 -08001741 case headerDepTag:
1742 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07001743 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001744 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Colin Crossc99deeb2016-04-11 15:06:20 -07001745 case crtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001746 depPaths.CrtBegin = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001747 case crtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07001748 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07001749 case dynamicLinkerDepTag:
1750 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07001751 }
1752
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001753 switch depTag {
Dan Willemsen581341d2017-02-09 16:16:31 -08001754 case staticDepTag, staticExportDepTag, lateStaticDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001755 staticLib, ok := ccDep.linker.(libraryInterface)
Dan Willemsen581341d2017-02-09 16:16:31 -08001756 if !ok || !staticLib.static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001757 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08001758 return
1759 }
1760
1761 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001762 // in static libraries act as if they were whole static libraries. The same goes for
1763 // source based Abi dump files.
Dan Willemsen581341d2017-02-09 16:16:31 -08001764 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
1765 staticLib.objs().coverageFiles...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001766 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
1767 staticLib.objs().sAbiDumpFiles...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001768
Dan Willemsen581341d2017-02-09 16:16:31 -08001769 }
1770
Colin Cross26c34ed2016-09-30 17:10:16 -07001771 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07001772 if !linkFile.Valid() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001773 ctx.ModuleErrorf("module %q missing output file", depName)
Colin Crossce75d2c2016-10-06 16:12:58 -07001774 return
1775 }
Colin Cross26c34ed2016-09-30 17:10:16 -07001776 *ptr = append(*ptr, linkFile.Path())
1777 }
1778
Colin Crossc99deeb2016-04-11 15:06:20 -07001779 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07001780 dep := depFile
1781 if !dep.Valid() {
1782 dep = linkFile
1783 }
1784 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08001785 }
Jiyong Park27b188b2017-07-18 13:23:39 +09001786
Logan Chien43d34c32017-12-20 01:17:32 +08001787 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001788 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09001789 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09001790 libName = strings.TrimPrefix(libName, "prebuilt_")
Jiyong Parkd5b18a52017-08-03 21:22:50 +09001791 isLLndk := inList(libName, llndkLibraries)
Jiyong Park374510b2018-03-19 18:23:01 +09001792 isVendorPublicLib := inList(libName, vendorPublicLibraries)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001793 bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08001794
1795 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
1796 // The vendor module is a no-vendor-variant VNDK library. Depend on the
1797 // core module instead.
1798 return libName
1799 } else if c.useVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001800 // The vendor module in Make will have been renamed to not conflict with the core
1801 // module, so update the dependency name here accordingly.
Logan Chien43d34c32017-12-20 01:17:32 +08001802 return libName + vendorSuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001803 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08001804 return libName + vendorPublicLibrarySuffix
Jiyong Parkf9332f12018-02-01 00:54:12 +09001805 } else if ccDep.inRecovery() && !ccDep.onlyInRecovery() {
1806 return libName + recoverySuffix
dimitry1f33e402019-03-26 12:39:31 +01001807 } else if ccDep.Target().NativeBridge == android.NativeBridgeEnabled {
1808 return libName + android.NativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001809 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08001810 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09001811 }
Logan Chien43d34c32017-12-20 01:17:32 +08001812 }
1813
1814 // Export the shared libs to Make.
1815 switch depTag {
Jiyong Park64a44f22019-01-18 14:37:08 +09001816 case sharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Jiyong Parkde866cb2018-12-07 23:08:36 +09001817 if dependentLibrary, ok := ccDep.linker.(*libraryDecorator); ok {
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001818 if dependentLibrary.buildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08001819 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09001820 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09001821 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09001822 c.Properties.ApexesProvidingSharedLibs = append(
1823 c.Properties.ApexesProvidingSharedLibs, an)
1824 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09001825 }
1826 }
1827
Jiyong Park27b188b2017-07-18 13:23:39 +09001828 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001829 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08001830 c.Properties.AndroidMkSharedLibs = append(
1831 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08001832 case ndkStubDepTag, ndkLateStubDepTag:
1833 ndkStub := ccDep.linker.(*stubDecorator)
1834 c.Properties.AndroidMkSharedLibs = append(
1835 c.Properties.AndroidMkSharedLibs,
1836 depName+"."+ndkStub.properties.ApiLevel)
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001837 case staticDepTag, staticExportDepTag, lateStaticDepTag:
1838 c.Properties.AndroidMkStaticLibs = append(
1839 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08001840 case runtimeDepTag:
1841 c.Properties.AndroidMkRuntimeLibs = append(
1842 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00001843 case wholeStaticDepTag:
1844 c.Properties.AndroidMkWholeStaticLibs = append(
1845 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09001846 }
Colin Crossca860ac2016-01-04 14:34:37 -08001847 })
1848
Jeff Gaston294356f2017-09-27 17:05:30 -07001849 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001850 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001851
Colin Crossdd84e052017-05-17 13:44:16 -07001852 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07001853 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001854 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Colin Crossb6715442017-10-24 11:13:31 -07001855 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001856 depPaths.ReexportedFlagsDeps = android.FirstUniquePaths(depPaths.ReexportedFlagsDeps)
1857
1858 if c.sabi != nil {
Colin Crossb6715442017-10-24 11:13:31 -07001859 c.sabi.Properties.ReexportedIncludeFlags = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludeFlags)
Dan Willemsenfe92c962017-08-29 12:28:37 -07001860 }
Colin Crossdd84e052017-05-17 13:44:16 -07001861
Colin Crossca860ac2016-01-04 14:34:37 -08001862 return depPaths
1863}
1864
1865func (c *Module) InstallInData() bool {
1866 if c.installer == nil {
1867 return false
1868 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001869 return c.installer.inData()
1870}
1871
1872func (c *Module) InstallInSanitizerDir() bool {
1873 if c.installer == nil {
1874 return false
1875 }
1876 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07001877 return true
1878 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07001879 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08001880}
1881
Jiyong Parkf9332f12018-02-01 00:54:12 +09001882func (c *Module) InstallInRecovery() bool {
1883 return c.inRecovery()
1884}
1885
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07001886func (c *Module) HostToolPath() android.OptionalPath {
1887 if c.installer == nil {
1888 return android.OptionalPath{}
1889 }
1890 return c.installer.hostToolPath()
1891}
1892
Nan Zhangd4e641b2017-07-12 12:55:28 -07001893func (c *Module) IntermPathForModuleOut() android.OptionalPath {
1894 return c.outputFile
1895}
1896
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07001897func (c *Module) Srcs() android.Paths {
1898 if c.outputFile.Valid() {
1899 return android.Paths{c.outputFile.Path()}
1900 }
1901 return android.Paths{}
1902}
1903
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001904func (c *Module) static() bool {
1905 if static, ok := c.linker.(interface {
1906 static() bool
1907 }); ok {
1908 return static.static()
1909 }
1910 return false
1911}
1912
Jiyong Park379de2f2018-12-19 02:47:14 +09001913func (c *Module) staticBinary() bool {
1914 if static, ok := c.linker.(interface {
1915 staticBinary() bool
1916 }); ok {
1917 return static.staticBinary()
1918 }
1919 return false
1920}
1921
Colin Crossb60190a2018-09-04 16:28:17 -07001922func (c *Module) getMakeLinkType() string {
1923 if c.useVndk() {
1924 if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
1925 if inList(c.Name(), vndkPrivateLibraries) {
1926 return "native:vndk_private"
1927 } else {
1928 return "native:vndk"
1929 }
1930 } else {
1931 return "native:vendor"
1932 }
1933 } else if c.inRecovery() {
1934 return "native:recovery"
1935 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
1936 return "native:ndk:none:none"
1937 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
1938 //family, link := getNdkStlFamilyAndLinkType(c)
1939 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Vic Yangefd249e2018-11-12 20:19:56 -08001940 } else if inList(c.Name(), vndkUsingCoreVariantLibraries) {
1941 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07001942 } else {
1943 return "native:platform"
1944 }
1945}
1946
Jiyong Park9d452992018-10-03 00:38:19 +09001947// Overrides ApexModule.IsInstallabeToApex()
1948// Only shared libraries are installable to APEX.
1949func (c *Module) IsInstallableToApex() bool {
1950 if shared, ok := c.linker.(interface {
1951 shared() bool
1952 }); ok {
1953 return shared.shared()
1954 }
1955 return false
1956}
1957
Jiyong Park3b1746a2019-01-29 11:15:04 +09001958func (c *Module) imageVariation() string {
1959 variation := "core"
1960 if c.useVndk() {
1961 variation = "vendor"
1962 } else if c.inRecovery() {
1963 variation = "recovery"
1964 }
1965 return variation
1966}
1967
bralee3f49f4d2019-03-04 06:58:15 +08001968func (c *Module) IDEInfo(dpInfo *android.IdeInfo) {
1969 dpInfo.Srcs = append(dpInfo.Srcs, c.Srcs().Strings()...)
1970}
1971
Logan Chien41eabe62019-04-10 13:33:58 +08001972func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
1973 if c.linker != nil {
1974 if library, ok := c.linker.(*libraryDecorator); ok {
1975 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
1976 }
1977 }
1978}
1979
Colin Cross2ba19d92015-05-07 15:44:20 -07001980//
Colin Crosscfad1192015-11-02 16:43:11 -08001981// Defaults
1982//
Colin Crossca860ac2016-01-04 14:34:37 -08001983type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001984 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07001985 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09001986 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08001987}
1988
Colin Cross635c3b02016-05-18 15:37:25 -07001989func (*Defaults) GenerateAndroidBuildActions(ctx android.ModuleContext) {
Colin Crosscfad1192015-11-02 16:43:11 -08001990}
1991
Patrice Arrudac249c712019-03-19 17:00:29 -07001992// cc_defaults provides a set of properties that can be inherited by other cc
1993// modules. A module can use the properties from a cc_defaults using
1994// `defaults: ["<:default_module_name>"]`. Properties of both modules are
1995// merged (when possible) by prepending the default module's values to the
1996// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07001997func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07001998 return DefaultsFactory()
1999}
2000
Colin Cross36242852017-06-23 15:06:31 -07002001func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002002 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002003
Colin Cross36242852017-06-23 15:06:31 -07002004 module.AddProperties(props...)
2005 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002006 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002007 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002008 &BaseCompilerProperties{},
2009 &BaseLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002010 &LibraryProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002011 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002012 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002013 &TestProperties{},
2014 &TestBinaryProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002015 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002016 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002017 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002018 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002019 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002020 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002021 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002022 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002023 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002024 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002025 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002026 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002027 )
Colin Crosscfad1192015-11-02 16:43:11 -08002028
Colin Cross1f44a3a2017-07-07 14:33:33 -07002029 android.InitDefaultsModule(module)
Jiyong Park9d452992018-10-03 00:38:19 +09002030 android.InitApexModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002031
2032 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002033}
2034
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002035const (
2036 // coreMode is the variant used for framework-private libraries, or
2037 // SDK libraries. (which framework-private libraries can use)
2038 coreMode = "core"
2039
2040 // vendorMode is the variant used for /vendor code that compiles
2041 // against the VNDK.
2042 vendorMode = "vendor"
Jiyong Parkf9332f12018-02-01 00:54:12 +09002043
2044 recoveryMode = "recovery"
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002045)
2046
Jiyong Park6a43f042017-10-12 23:05:00 +09002047func squashVendorSrcs(m *Module) {
2048 if lib, ok := m.compiler.(*libraryDecorator); ok {
2049 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2050 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2051
2052 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2053 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2054 }
2055}
2056
Jiyong Parkf9332f12018-02-01 00:54:12 +09002057func squashRecoverySrcs(m *Module) {
2058 if lib, ok := m.compiler.(*libraryDecorator); ok {
2059 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2060 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2061
2062 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2063 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2064 }
2065}
2066
Jiyong Parkda6eb592018-12-19 17:12:36 +09002067func ImageMutator(mctx android.BottomUpMutatorContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002068 if mctx.Os() != android.Android {
2069 return
2070 }
2071
Jiyong Park7ed9de32018-10-15 22:25:07 +09002072 if g, ok := mctx.Module().(*genrule.Module); ok {
2073 if props, ok := g.Extra.(*GenruleExtraProperties); ok {
Jiyong Park3f736c92018-05-24 13:36:56 +09002074 var coreVariantNeeded bool = false
2075 var vendorVariantNeeded bool = false
2076 var recoveryVariantNeeded bool = false
Justin Yun71549282017-11-17 12:10:28 +09002077 if mctx.DeviceConfig().VndkVersion() == "" {
Jiyong Park3f736c92018-05-24 13:36:56 +09002078 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002079 } else if Bool(props.Vendor_available) {
Jiyong Park3f736c92018-05-24 13:36:56 +09002080 coreVariantNeeded = true
2081 vendorVariantNeeded = true
Jiyong Park2db76922017-11-08 16:03:48 +09002082 } else if mctx.SocSpecific() || mctx.DeviceSpecific() {
Jiyong Park3f736c92018-05-24 13:36:56 +09002083 vendorVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002084 } else {
Jiyong Park3f736c92018-05-24 13:36:56 +09002085 coreVariantNeeded = true
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002086 }
Jiyong Park3f736c92018-05-24 13:36:56 +09002087 if Bool(props.Recovery_available) {
2088 recoveryVariantNeeded = true
2089 }
2090
Jiyong Park413cc742018-06-19 01:46:06 +09002091 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002092 primaryArch := mctx.Config().DevicePrimaryArchType()
Jiyong Park7ed9de32018-10-15 22:25:07 +09002093 moduleArch := g.Target().Arch.ArchType
Jiyong Park8d52f862018-07-07 18:02:07 +09002094 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002095 recoveryVariantNeeded = false
2096 }
2097 }
2098
Jiyong Park3f736c92018-05-24 13:36:56 +09002099 var variants []string
2100 if coreVariantNeeded {
2101 variants = append(variants, coreMode)
2102 }
2103 if vendorVariantNeeded {
2104 variants = append(variants, vendorMode)
2105 }
2106 if recoveryVariantNeeded {
2107 variants = append(variants, recoveryMode)
2108 }
Jiyong Park7ed9de32018-10-15 22:25:07 +09002109 mod := mctx.CreateVariations(variants...)
2110 for i, v := range variants {
2111 if v == recoveryMode {
2112 m := mod[i].(*genrule.Module)
2113 m.Extra.(*GenruleExtraProperties).InRecovery = true
2114 }
2115 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002116 }
2117 }
2118
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002119 m, ok := mctx.Module().(*Module)
2120 if !ok {
2121 return
2122 }
2123
2124 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002125 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002126 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002127
2128 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002129 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002130 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002131 return
2132 }
Logan Chienf3511742017-10-31 18:04:35 +08002133
2134 if vndkdep := m.vndkdep; vndkdep != nil {
2135 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002136 if productSpecific {
2137 mctx.PropertyErrorf("product_specific",
2138 "product_specific must not be true when `vndk: {enabled: true}`")
2139 return
2140 }
Logan Chienf3511742017-10-31 18:04:35 +08002141 if vendorSpecific {
2142 if !vndkdep.isVndkExt() {
2143 mctx.PropertyErrorf("vndk",
2144 "must set `extends: \"...\"` to vndk extension")
2145 return
2146 }
2147 } else {
2148 if vndkdep.isVndkExt() {
2149 mctx.PropertyErrorf("vndk",
2150 "must set `vendor: true` to set `extends: %q`",
2151 m.getVndkExtendsModuleName())
2152 return
2153 }
2154 if m.VendorProperties.Vendor_available == nil {
2155 mctx.PropertyErrorf("vndk",
2156 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
2157 return
2158 }
2159 }
2160 } else {
2161 if vndkdep.isVndkSp() {
2162 mctx.PropertyErrorf("vndk",
2163 "must set `enabled: true` to set `support_system_process: true`")
2164 return
2165 }
2166 if vndkdep.isVndkExt() {
2167 mctx.PropertyErrorf("vndk",
2168 "must set `enabled: true` to set `extends: %q`",
2169 m.getVndkExtendsModuleName())
2170 return
2171 }
Justin Yun8effde42017-06-23 19:24:43 +09002172 }
2173 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002174
Jiyong Parkf9332f12018-02-01 00:54:12 +09002175 var coreVariantNeeded bool = false
2176 var vendorVariantNeeded bool = false
2177 var recoveryVariantNeeded bool = false
2178
Justin Yun71549282017-11-17 12:10:28 +09002179 if mctx.DeviceConfig().VndkVersion() == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002180 // If the device isn't compiling against the VNDK, we always
2181 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002182 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002183 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
2184 // LL-NDK stubs only exist in the vendor variant, since the
2185 // real libraries will be used in the core variant.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002186 vendorVariantNeeded = true
Jiyong Park2a454122017-10-19 15:59:33 +09002187 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2188 // ... and LL-NDK headers as well
Jiyong Parkf9332f12018-02-01 00:54:12 +09002189 vendorVariantNeeded = true
Justin Yun312ccb92018-01-23 12:07:46 +09002190 } else if _, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002191 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2192 // PRODUCT_EXTRA_VNDK_VERSIONS.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002193 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002194 } else if m.hasVendorVariant() && !vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002195 // This will be available in both /system and /vendor
Justin Yun8effde42017-06-23 19:24:43 +09002196 // or a /system directory that is available to vendor.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002197 coreVariantNeeded = true
2198 vendorVariantNeeded = true
Logan Chienf3511742017-10-31 18:04:35 +08002199 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002200 // This will be available in /vendor (or /odm) only
Jiyong Parkf9332f12018-02-01 00:54:12 +09002201 vendorVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002202 } else {
2203 // This is either in /system (or similar: /data), or is a
2204 // modules built with the NDK. Modules built with the NDK
2205 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002206 coreVariantNeeded = true
2207 }
2208
2209 if Bool(m.Properties.Recovery_available) {
2210 recoveryVariantNeeded = true
2211 }
2212
2213 if m.ModuleBase.InstallInRecovery() {
2214 recoveryVariantNeeded = true
2215 coreVariantNeeded = false
2216 }
2217
Jiyong Park413cc742018-06-19 01:46:06 +09002218 if recoveryVariantNeeded {
Jiyong Park8d52f862018-07-07 18:02:07 +09002219 primaryArch := mctx.Config().DevicePrimaryArchType()
2220 moduleArch := m.Target().Arch.ArchType
2221 if moduleArch != primaryArch {
Jiyong Park413cc742018-06-19 01:46:06 +09002222 recoveryVariantNeeded = false
2223 }
2224 }
2225
Jiyong Parkf9332f12018-02-01 00:54:12 +09002226 var variants []string
2227 if coreVariantNeeded {
2228 variants = append(variants, coreMode)
2229 }
2230 if vendorVariantNeeded {
2231 variants = append(variants, vendorMode)
2232 }
2233 if recoveryVariantNeeded {
2234 variants = append(variants, recoveryMode)
2235 }
2236 mod := mctx.CreateVariations(variants...)
2237 for i, v := range variants {
2238 if v == vendorMode {
2239 m := mod[i].(*Module)
2240 m.Properties.UseVndk = true
2241 squashVendorSrcs(m)
2242 } else if v == recoveryMode {
2243 m := mod[i].(*Module)
2244 m.Properties.InRecovery = true
Jiyong Park5baac542018-08-28 09:55:37 +09002245 m.MakeAsPlatform()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002246 squashRecoverySrcs(m)
2247 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002248 }
2249}
2250
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002251func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002252 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002253 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2254 }
Colin Cross6510f912017-11-29 00:27:14 -08002255 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002256}
2257
Colin Cross06a931b2015-10-28 17:23:31 -07002258var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002259var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002260var BoolPtr = proptools.BoolPtr
2261var String = proptools.String
2262var StringPtr = proptools.StringPtr