blob: 2e55841ee753d84474395ad03419697af79f23ec [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 (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090045 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070046 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090047 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090049 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070050 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090051 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070052 })
Colin Cross16b23492016-01-06 14:41:07 -080053
Paul Duffin036e7002019-12-19 19:16:28 +000054 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070055 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
56 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080057
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070058 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
59 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
60
Mitch Phillipsbfeade62019-05-01 14:42:05 -070061 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
62 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
63
Jiyong Park1d1119f2019-07-29 21:27:18 +090064 // cfi mutator shouldn't run before sanitizers that return true for
65 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000066 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
67 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
68
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080069 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
70 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
71
Colin Cross1e676be2016-10-12 14:38:15 -070072 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
73 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080074
Colin Cross0b908332019-06-19 23:00:20 -070075 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090076 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080077
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080078 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080079 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070080
81 ctx.TopDown("lto_deps", ltoDepsMutator)
82 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090083
84 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070085 })
Colin Crossb98c8b02016-07-29 13:44:28 -070086
Sasha Smundak2a4549e2018-11-05 16:49:08 -080087 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070088}
89
Colin Crossca860ac2016-01-04 14:34:37 -080090type Deps struct {
91 SharedLibs, LateSharedLibs []string
92 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080093 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080094 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070095
Colin Cross5950f382016-12-13 12:50:57 -080096 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -070097
Colin Cross81413472016-04-11 14:37:39 -070098 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -070099
Dan Willemsenb40aab62016-04-20 14:21:14 -0700100 GeneratedSources []string
101 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900102 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700103
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700104 ReexportGeneratedHeaders []string
105
Colin Cross97ba0732015-03-23 17:50:24 -0700106 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700107
108 // Used for host bionic
109 LinkerFlagsFile string
110 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700111}
112
Colin Crossca860ac2016-01-04 14:34:37 -0800113type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700114 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900115 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700116 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900117 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700119 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700120
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700122 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800123 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700124 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700127 GeneratedSources android.Paths
128 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900129 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700130
Inseob Kimd110f872019-12-06 13:15:38 +0900131 Flags []string
132 IncludeDirs android.Paths
133 SystemIncludeDirs android.Paths
134 ReexportedDirs android.Paths
135 ReexportedSystemDirs android.Paths
136 ReexportedFlags []string
137 ReexportedGeneratedHeaders android.Paths
138 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700139
Colin Cross26c34ed2016-09-30 17:10:16 -0700140 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700141 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700142
143 // Path to the file container flags to use with the linker
144 LinkerFlagsFile android.OptionalPath
145
146 // Path to the dynamic linker binary
147 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700148}
149
Colin Cross4af21ed2019-11-04 09:37:55 -0800150// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
151// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
152// command line so they can be overridden by the local module flags).
153type LocalOrGlobalFlags struct {
154 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700155 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800156 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700157 CFlags []string // Flags that apply to C and C++ source files
158 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
159 ConlyFlags []string // Flags that apply to C source files
160 CppFlags []string // Flags that apply to C++ source files
161 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700162 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800163}
164
165type Flags struct {
166 Local LocalOrGlobalFlags
167 Global LocalOrGlobalFlags
168
169 aidlFlags []string // Flags that apply to aidl source files
170 rsFlags []string // Flags that apply to renderscript source files
171 libFlags []string // Flags to add libraries early to the link order
172 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
173 TidyFlags []string // Flags that apply to clang-tidy
174 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700175
Colin Crossc3199482017-03-30 15:03:04 -0700176 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800177 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700178 SystemIncludeFlags []string
179
Colin Crossb98c8b02016-07-29 13:44:28 -0700180 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700181 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800182 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800183 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800184 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800185
186 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800187 DynamicLinker string
188
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700189 CFlagsDeps android.Paths // Files depended on by compiler flags
190 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800191
Dan Willemsen98ab3112019-08-27 21:20:40 -0700192 AssemblerWithCpp bool
193 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800194
Colin Cross19878da2019-03-28 14:45:07 -0700195 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700196 protoC bool // Whether to use C instead of C++
197 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700198
199 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700200}
201
Colin Crossca860ac2016-01-04 14:34:37 -0800202// Properties used to compile all C or C++ modules
203type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700204 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800205 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700206
207 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800208 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700209
Jiyong Parkde866cb2018-12-07 23:08:36 +0900210 AndroidMkSharedLibs []string `blueprint:"mutated"`
211 AndroidMkStaticLibs []string `blueprint:"mutated"`
212 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
213 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
214 HideFromMake bool `blueprint:"mutated"`
215 PreventInstall bool `blueprint:"mutated"`
216 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700217
Justin Yun5f7f7e82019-11-18 19:52:14 +0900218 ImageVariationPrefix string `blueprint:"mutated"`
219 VndkVersion string `blueprint:"mutated"`
220 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800221
222 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
223 // file
224 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900225
Yifan Hong1b3348d2020-01-21 15:53:22 -0800226 // Make this module available when building for ramdisk
227 Ramdisk_available *bool
228
Jiyong Parkf9332f12018-02-01 00:54:12 +0900229 // Make this module available when building for recovery
230 Recovery_available *bool
231
Colin Crossae6c5202019-11-20 13:35:50 -0800232 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800233 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800234 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800235 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900236 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900237
238 // Allows this module to use non-APEX version of libraries. Useful
239 // for building binaries that are started before APEXes are activated.
240 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900241
242 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
243 // see soong/cc/config/vndk.go
244 MustUseVendorVariant bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700245}
246
247type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900248 // whether this module should be allowed to be directly depended by other
249 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900250 // In addition, this module should be allowed to be directly depended by
251 // product modules with `product_specific: true`.
252 // If set to true, three variants will be built separately, one like
253 // normal, another limited to the set of libraries and headers
254 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700255 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900256 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700257 // so it shouldn't have any unversioned runtime dependencies, or
258 // make assumptions about the system that may not be true in the
259 // future.
260 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900261 // If set to false, this module becomes inaccessible from /vendor or /product
262 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900263 //
264 // Default value is true when vndk: {enabled: true} or vendor: true.
265 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700266 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900267 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700268 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900269
270 // whether this module is capable of being loaded with other instance
271 // (possibly an older version) of the same module in the same process.
272 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
273 // can be double loaded in a vendor process if the library is also a
274 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
275 // explicitly marked as `double_loadable: true` by the owner, or the dependency
276 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
277 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800278}
279
Colin Crossca860ac2016-01-04 14:34:37 -0800280type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800281 static() bool
282 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900283 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700284 toolchain() config.Toolchain
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700285 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800286 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700287 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800288 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900289 isLlndk(config android.Config) bool
290 isLlndkPublic(config android.Config) bool
291 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900292 isVndk() bool
293 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800294 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900295 inProduct() bool
296 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800297 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900298 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800299 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700300 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700301 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800302 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800303 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800304 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800305 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800306 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900307 apexName() string
Jiyong Parkb0788572018-12-20 22:10:17 +0900308 hasStubsVariants() bool
309 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900310 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800311 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700312 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800313}
314
315type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700316 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800317 ModuleContextIntf
318}
319
320type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700321 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800322 ModuleContextIntf
323}
324
Colin Cross37047f12016-12-13 17:06:13 -0800325type DepsContext interface {
326 android.BottomUpMutatorContext
327 ModuleContextIntf
328}
329
Colin Crossca860ac2016-01-04 14:34:37 -0800330type feature interface {
331 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800332 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800333 flags(ctx ModuleContext, flags Flags) Flags
334 props() []interface{}
335}
336
337type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700338 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800339 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800340 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700341 compilerProps() []interface{}
342
Colin Cross76fada02016-07-27 10:31:13 -0700343 appendCflags([]string)
344 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700345 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800346}
347
348type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700349 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800350 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700351 linkerFlags(ctx ModuleContext, flags Flags) Flags
352 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800353 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700354
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700355 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700356 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900357 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700358
359 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900360 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800361}
362
363type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700364 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700365 install(ctx ModuleContext, path android.Path)
Colin Crossca860ac2016-01-04 14:34:37 -0800366 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700367 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700368 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900369 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800370}
371
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800372type xref interface {
373 XrefCcFiles() android.Paths
374}
375
Colin Crossc99deeb2016-04-11 15:06:20 -0700376var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700377 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
378 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
379 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
380 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
381 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
382 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
383 headerDepTag = DependencyTag{Name: "header", Library: true}
384 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
385 genSourceDepTag = DependencyTag{Name: "gen source"}
386 genHeaderDepTag = DependencyTag{Name: "gen header"}
387 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
388 objDepTag = DependencyTag{Name: "obj"}
389 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
390 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
391 reuseObjTag = DependencyTag{Name: "reuse objects"}
392 staticVariantTag = DependencyTag{Name: "static variant"}
393 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
394 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
395 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
396 runtimeDepTag = DependencyTag{Name: "runtime lib"}
397 coverageDepTag = DependencyTag{Name: "coverage"}
398 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700399)
400
Roland Levillainf89cd092019-07-29 16:22:59 +0100401func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700402 ccDepTag, ok := depTag.(DependencyTag)
403 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100404}
405
Jiyong Park83dc74b2020-01-14 18:38:44 +0900406func IsStaticDepTag(depTag blueprint.DependencyTag) bool {
407 ccDepTag, ok := depTag.(DependencyTag)
408 return ok && (ccDepTag == staticExportDepTag ||
409 ccDepTag == lateStaticDepTag ||
410 ccDepTag == wholeStaticDepTag)
411}
412
Roland Levillainf89cd092019-07-29 16:22:59 +0100413func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700414 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100415 return ok && ccDepTag == runtimeDepTag
416}
417
418func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700419 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100420 return ok && ccDepTag == testPerSrcDepTag
421}
422
Colin Crossca860ac2016-01-04 14:34:37 -0800423// Module contains the properties and members used by all C/C++ module types, and implements
424// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
425// to construct the output file. Behavior can be customized with a Customizer interface
426type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700427 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700428 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900429 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900430 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700431
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700432 Properties BaseProperties
433 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700434
Colin Crossca860ac2016-01-04 14:34:37 -0800435 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700436 hod android.HostOrDeviceSupported
437 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700438
Paul Duffina0843f62019-12-13 19:50:38 +0000439 // Allowable SdkMemberTypes of this module type.
440 sdkMemberTypes []android.SdkMemberType
441
Colin Crossca860ac2016-01-04 14:34:37 -0800442 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700443 features []feature
444 compiler compiler
445 linker linker
446 installer installer
447 stl *stl
448 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800449 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800450 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900451 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700452 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700453 pgo *pgo
Ivan Lozano074ec482018-11-21 08:59:37 -0800454 xom *xom
Colin Cross16b23492016-01-06 14:41:07 -0800455
456 androidMkSharedLibDeps []string
Colin Cross74d1ec02015-04-28 13:30:13 -0700457
Colin Cross635c3b02016-05-18 15:37:25 -0700458 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800459
Colin Crossb98c8b02016-07-29 13:44:28 -0700460 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700461
462 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800463
464 // Flags used to compile this module
465 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700466
467 // 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 -0800468 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700469 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800470 depsInLinkOrder android.Paths
471
472 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700473 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900474
475 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800476 // Kythe (source file indexer) paths for this compilation module
477 kytheFiles android.Paths
Jiyong Park83dc74b2020-01-14 18:38:44 +0900478
479 // name of the modules that are direct or indirect static deps of this module
480 allStaticDeps []string
Colin Crossc472d572015-03-17 15:06:21 -0700481}
482
Ivan Lozano52767be2019-10-18 14:49:46 -0700483func (c *Module) Toc() android.OptionalPath {
484 if c.linker != nil {
485 if library, ok := c.linker.(libraryInterface); ok {
486 return library.toc()
487 }
488 }
489 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
490}
491
492func (c *Module) ApiLevel() string {
493 if c.linker != nil {
494 if stub, ok := c.linker.(*stubDecorator); ok {
495 return stub.properties.ApiLevel
496 }
497 }
498 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
499}
500
501func (c *Module) Static() bool {
502 if c.linker != nil {
503 if library, ok := c.linker.(libraryInterface); ok {
504 return library.static()
505 }
506 }
507 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
508}
509
510func (c *Module) Shared() bool {
511 if c.linker != nil {
512 if library, ok := c.linker.(libraryInterface); ok {
513 return library.shared()
514 }
515 }
516 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
517}
518
519func (c *Module) SelectedStl() string {
520 return c.stl.Properties.SelectedStl
521}
522
523func (c *Module) ToolchainLibrary() bool {
524 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
525 return true
526 }
527 return false
528}
529
530func (c *Module) NdkPrebuiltStl() bool {
531 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
532 return true
533 }
534 return false
535}
536
537func (c *Module) StubDecorator() bool {
538 if _, ok := c.linker.(*stubDecorator); ok {
539 return true
540 }
541 return false
542}
543
544func (c *Module) SdkVersion() string {
545 return String(c.Properties.Sdk_version)
546}
547
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800548func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700549 if c.linker != nil {
550 if library, ok := c.linker.(exportedFlagsProducer); ok {
551 return library.exportedDirs()
552 }
553 }
554 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
555}
556
557func (c *Module) HasStaticVariant() bool {
558 if c.staticVariant != nil {
559 return true
560 }
561 return false
562}
563
564func (c *Module) GetStaticVariant() LinkableInterface {
565 return c.staticVariant
566}
567
568func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
569 c.depsInLinkOrder = depsInLinkOrder
570}
571
572func (c *Module) GetDepsInLinkOrder() []android.Path {
573 return c.depsInLinkOrder
574}
575
576func (c *Module) StubsVersions() []string {
577 if c.linker != nil {
578 if library, ok := c.linker.(*libraryDecorator); ok {
579 return library.Properties.Stubs.Versions
580 }
581 }
582 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
583}
584
585func (c *Module) CcLibrary() bool {
586 if c.linker != nil {
587 if _, ok := c.linker.(*libraryDecorator); ok {
588 return true
589 }
590 }
591 return false
592}
593
594func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700595 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700596 return true
597 }
598 return false
599}
600
Ivan Lozano2b262972019-11-21 12:30:50 -0800601func (c *Module) NonCcVariants() bool {
602 return false
603}
604
Ivan Lozano183a3212019-10-18 14:18:45 -0700605func (c *Module) SetBuildStubs() {
606 if c.linker != nil {
607 if library, ok := c.linker.(*libraryDecorator); ok {
608 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700609 c.Properties.HideFromMake = true
610 c.sanitize = nil
611 c.stl = nil
612 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700613 return
614 }
615 }
616 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
617}
618
Ivan Lozano52767be2019-10-18 14:49:46 -0700619func (c *Module) BuildStubs() bool {
620 if c.linker != nil {
621 if library, ok := c.linker.(*libraryDecorator); ok {
622 return library.buildStubs()
623 }
624 }
625 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
626}
627
Ivan Lozano183a3212019-10-18 14:18:45 -0700628func (c *Module) SetStubsVersions(version string) {
629 if c.linker != nil {
630 if library, ok := c.linker.(*libraryDecorator); ok {
631 library.MutatedProperties.StubsVersion = version
632 return
633 }
634 }
635 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
636}
637
638func (c *Module) SetStatic() {
639 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700640 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700641 library.setStatic()
642 return
643 }
644 }
645 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
646}
647
648func (c *Module) SetShared() {
649 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700650 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700651 library.setShared()
652 return
653 }
654 }
655 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
656}
657
658func (c *Module) BuildStaticVariant() bool {
659 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700660 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700661 return library.buildStatic()
662 }
663 }
664 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
665}
666
667func (c *Module) BuildSharedVariant() bool {
668 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700669 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700670 return library.buildShared()
671 }
672 }
673 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
674}
675
676func (c *Module) Module() android.Module {
677 return c
678}
679
Jiyong Parkc20eee32018-09-05 22:36:17 +0900680func (c *Module) OutputFile() android.OptionalPath {
681 return c.outputFile
682}
683
Ivan Lozano183a3212019-10-18 14:18:45 -0700684var _ LinkableInterface = (*Module)(nil)
685
Jiyong Park719b4462019-01-13 00:39:51 +0900686func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900687 if c.linker != nil {
688 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900689 }
690 return nil
691}
692
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900693func (c *Module) CoverageOutputFile() android.OptionalPath {
694 if c.linker != nil {
695 return c.linker.coverageOutputFilePath()
696 }
697 return android.OptionalPath{}
698}
699
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900700func (c *Module) RelativeInstallPath() string {
701 if c.installer != nil {
702 return c.installer.relativeInstallPath()
703 }
704 return ""
705}
706
Jooyung Han344d5432019-08-23 11:17:39 +0900707func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900708 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900709}
710
Colin Cross36242852017-06-23 15:06:31 -0700711func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700712 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800713 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700714 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800715 }
716 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700717 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800718 }
719 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700720 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800721 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700722 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700723 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700724 }
Colin Cross16b23492016-01-06 14:41:07 -0800725 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700726 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800727 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800728 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700729 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800730 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800731 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700732 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800733 }
Justin Yun8effde42017-06-23 19:24:43 +0900734 if c.vndkdep != nil {
735 c.AddProperties(c.vndkdep.props()...)
736 }
Stephen Craneba090d12017-05-09 15:44:35 -0700737 if c.lto != nil {
738 c.AddProperties(c.lto.props()...)
739 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700740 if c.pgo != nil {
741 c.AddProperties(c.pgo.props()...)
742 }
Ivan Lozano074ec482018-11-21 08:59:37 -0800743 if c.xom != nil {
744 c.AddProperties(c.xom.props()...)
745 }
Colin Crossca860ac2016-01-04 14:34:37 -0800746 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700747 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800748 }
Colin Crossc472d572015-03-17 15:06:21 -0700749
Colin Crossa9d8bee2018-10-02 13:59:46 -0700750 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
751 switch class {
752 case android.Device:
753 return ctx.Config().DevicePrefer32BitExecutables()
754 case android.HostCross:
755 // Windows builds always prefer 32-bit
756 return true
757 default:
758 return false
759 }
760 })
Colin Cross36242852017-06-23 15:06:31 -0700761 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900762 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900763 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900764 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900765
Colin Cross36242852017-06-23 15:06:31 -0700766 return c
Colin Crossc472d572015-03-17 15:06:21 -0700767}
768
Colin Crossb916a382016-07-29 17:28:03 -0700769// Returns true for dependency roots (binaries)
770// TODO(ccross): also handle dlopenable libraries
771func (c *Module) isDependencyRoot() bool {
772 if root, ok := c.linker.(interface {
773 isDependencyRoot() bool
774 }); ok {
775 return root.isDependencyRoot()
776 }
777 return false
778}
779
Justin Yun5f7f7e82019-11-18 19:52:14 +0900780// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
781// "product" and "vendor" variant modules return true for this function.
782// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
783// "soc_specific: true" and more vendor installed modules are included here.
784// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
785// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700786func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900787 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700788}
789
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800790func (c *Module) isCoverageVariant() bool {
791 return c.coverage.Properties.IsCoverageVariant
792}
793
Peter Collingbournead84f972019-12-17 16:46:18 -0800794func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800795 return inList(c.Name(), ndkMigratedLibs)
796}
797
Inseob Kim9516ee92019-05-09 10:56:13 +0900798func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800799 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900800 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800801}
802
Inseob Kim9516ee92019-05-09 10:56:13 +0900803func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800804 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900805 name := c.BaseModuleName()
806 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800807}
808
Inseob Kim9516ee92019-05-09 10:56:13 +0900809func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800810 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900811 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800812}
813
Ivan Lozano52767be2019-10-18 14:49:46 -0700814func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800815 if vndkdep := c.vndkdep; vndkdep != nil {
816 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900817 }
818 return false
819}
820
Yi Kong7e53c572018-02-14 18:16:12 +0800821func (c *Module) isPgoCompile() bool {
822 if pgo := c.pgo; pgo != nil {
823 return pgo.Properties.PgoCompile
824 }
825 return false
826}
827
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800828func (c *Module) isNDKStubLibrary() bool {
829 if _, ok := c.compiler.(*stubDecorator); ok {
830 return true
831 }
832 return false
833}
834
Logan Chienf3511742017-10-31 18:04:35 +0800835func (c *Module) isVndkSp() bool {
836 if vndkdep := c.vndkdep; vndkdep != nil {
837 return vndkdep.isVndkSp()
838 }
839 return false
840}
841
842func (c *Module) isVndkExt() bool {
843 if vndkdep := c.vndkdep; vndkdep != nil {
844 return vndkdep.isVndkExt()
845 }
846 return false
847}
848
Ivan Lozano52767be2019-10-18 14:49:46 -0700849func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900850 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800851}
852
Logan Chienf3511742017-10-31 18:04:35 +0800853func (c *Module) getVndkExtendsModuleName() string {
854 if vndkdep := c.vndkdep; vndkdep != nil {
855 return vndkdep.getVndkExtendsModuleName()
856 }
857 return ""
858}
859
Justin Yun5f7f7e82019-11-18 19:52:14 +0900860// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900861// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700862func (c *Module) HasVendorVariant() bool {
863 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900864}
865
Justin Yun5f7f7e82019-11-18 19:52:14 +0900866const (
867 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
868 // against the VNDK.
869 VendorVariationPrefix = "vendor."
870
871 // ProductVariationPrefix is the variant prefix used for /product code that compiles
872 // against the VNDK.
873 ProductVariationPrefix = "product."
874)
875
876// Returns true if the module is "product" variant. Usually these modules are installed in /product
877func (c *Module) inProduct() bool {
878 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
879}
880
881// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
882func (c *Module) inVendor() bool {
883 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
884}
885
Yifan Hong1b3348d2020-01-21 15:53:22 -0800886func (c *Module) InRamdisk() bool {
887 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
888}
889
Ivan Lozano52767be2019-10-18 14:49:46 -0700890func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800891 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900892}
893
Yifan Hong1b3348d2020-01-21 15:53:22 -0800894func (c *Module) OnlyInRamdisk() bool {
895 return c.ModuleBase.InstallInRamdisk()
896}
897
Ivan Lozano52767be2019-10-18 14:49:46 -0700898func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900899 return c.ModuleBase.InstallInRecovery()
900}
901
Jiyong Park25fc6a92018-11-18 18:02:45 +0900902func (c *Module) IsStubs() bool {
903 if library, ok := c.linker.(*libraryDecorator); ok {
904 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900905 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
906 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900907 }
908 return false
909}
910
911func (c *Module) HasStubsVariants() bool {
912 if library, ok := c.linker.(*libraryDecorator); ok {
913 return len(library.Properties.Stubs.Versions) > 0
914 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700915 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
916 return len(library.Properties.Stubs.Versions) > 0
917 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900918 return false
919}
920
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900921func (c *Module) bootstrap() bool {
922 return Bool(c.Properties.Bootstrap)
923}
924
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700925func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700926 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
927 if c.Target().NativeBridge == android.NativeBridgeEnabled {
928 return false
929 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700930 return c.linker != nil && c.linker.nativeCoverage()
931}
932
Jiyong Park73c54ee2019-10-22 20:31:18 +0900933func (c *Module) ExportedIncludeDirs() android.Paths {
934 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
935 return flagsProducer.exportedDirs()
936 }
Jiyong Park232e7852019-11-04 12:23:40 +0900937 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900938}
939
940func (c *Module) ExportedSystemIncludeDirs() android.Paths {
941 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
942 return flagsProducer.exportedSystemDirs()
943 }
Jiyong Park232e7852019-11-04 12:23:40 +0900944 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900945}
946
947func (c *Module) ExportedFlags() []string {
948 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
949 return flagsProducer.exportedFlags()
950 }
Jiyong Park232e7852019-11-04 12:23:40 +0900951 return nil
952}
953
954func (c *Module) ExportedDeps() android.Paths {
955 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
956 return flagsProducer.exportedDeps()
957 }
958 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900959}
960
Inseob Kimd110f872019-12-06 13:15:38 +0900961func (c *Module) ExportedGeneratedHeaders() android.Paths {
962 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
963 return flagsProducer.exportedGeneratedHeaders()
964 }
965 return nil
966}
967
Jiyong Parkf1194352019-02-25 11:05:47 +0900968func isBionic(name string) bool {
969 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +0000970 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +0900971 return true
972 }
973 return false
974}
975
Martin Stjernholm279de572019-09-10 23:18:20 +0100976func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700977 if name == "libclang_rt.hwasan-aarch64-android" {
978 return inList("hwaddress", config.SanitizeDevice())
979 }
980 return isBionic(name)
981}
982
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800983func (c *Module) XrefCcFiles() android.Paths {
984 return c.kytheFiles
985}
986
Colin Crossca860ac2016-01-04 14:34:37 -0800987type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700988 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800989 moduleContextImpl
990}
991
Colin Cross37047f12016-12-13 17:06:13 -0800992type depsContext struct {
993 android.BottomUpMutatorContext
994 moduleContextImpl
995}
996
Colin Crossca860ac2016-01-04 14:34:37 -0800997type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700998 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800999 moduleContextImpl
1000}
1001
Justin Yun5f7f7e82019-11-18 19:52:14 +09001002func (ctx *moduleContext) ProductSpecific() bool {
1003 return ctx.ModuleContext.ProductSpecific() ||
1004 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1005}
1006
Jiyong Park2db76922017-11-08 16:03:48 +09001007func (ctx *moduleContext) SocSpecific() bool {
1008 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001009 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001010}
1011
Colin Crossca860ac2016-01-04 14:34:37 -08001012type moduleContextImpl struct {
1013 mod *Module
1014 ctx BaseModuleContext
1015}
1016
Colin Crossb98c8b02016-07-29 13:44:28 -07001017func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001018 return ctx.mod.toolchain(ctx.ctx)
1019}
1020
1021func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001022 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001023}
1024
1025func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001026 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001027}
1028
Jiyong Park1d1119f2019-07-29 21:27:18 +09001029func (ctx *moduleContextImpl) header() bool {
1030 return ctx.mod.header()
1031}
1032
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001033func (ctx *moduleContextImpl) useSdk() bool {
Yifan Hong1b3348d2020-01-21 15:53:22 -08001034 if ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia() {
Nan Zhang0007d812017-11-07 10:57:05 -08001035 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001036 }
1037 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001038}
1039
1040func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001041 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001042 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001043 vndkVer := ctx.mod.VndkVersion()
1044 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1045 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001046 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001047 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001048 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001049 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001050 }
1051 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001052}
1053
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001054func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001055 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001056}
Justin Yun8effde42017-06-23 19:24:43 +09001057
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001058func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001059 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001060}
1061
Inseob Kim9516ee92019-05-09 10:56:13 +09001062func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1063 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001064}
1065
Inseob Kim9516ee92019-05-09 10:56:13 +09001066func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1067 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001068}
1069
Inseob Kim9516ee92019-05-09 10:56:13 +09001070func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1071 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001072}
1073
Logan Chienf3511742017-10-31 18:04:35 +08001074func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001075 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001076}
1077
Yi Kong7e53c572018-02-14 18:16:12 +08001078func (ctx *moduleContextImpl) isPgoCompile() bool {
1079 return ctx.mod.isPgoCompile()
1080}
1081
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001082func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1083 return ctx.mod.isNDKStubLibrary()
1084}
1085
Justin Yun8effde42017-06-23 19:24:43 +09001086func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001087 return ctx.mod.isVndkSp()
1088}
1089
1090func (ctx *moduleContextImpl) isVndkExt() bool {
1091 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001092}
1093
Vic Yangefd249e2018-11-12 20:19:56 -08001094func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001095 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001096}
1097
Justin Yun5f7f7e82019-11-18 19:52:14 +09001098func (ctx *moduleContextImpl) inProduct() bool {
1099 return ctx.mod.inProduct()
1100}
1101
1102func (ctx *moduleContextImpl) inVendor() bool {
1103 return ctx.mod.inVendor()
1104}
1105
Yifan Hong1b3348d2020-01-21 15:53:22 -08001106func (ctx *moduleContextImpl) inRamdisk() bool {
1107 return ctx.mod.InRamdisk()
1108}
1109
Jiyong Parkf9332f12018-02-01 00:54:12 +09001110func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001111 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001112}
1113
Logan Chien2f2b8902018-07-10 15:01:19 +08001114// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001115func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001116 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1117 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001118 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001119
1120 if ctx.ctx.Fuchsia() {
1121 return false
1122 }
1123
Logan Chien2f2b8902018-07-10 15:01:19 +08001124 if sanitize := ctx.mod.sanitize; sanitize != nil {
1125 if !sanitize.isVariantOnProductionDevice() {
1126 return false
1127 }
1128 }
1129 if !ctx.ctx.Device() {
1130 // Host modules do not need ABI dumps.
1131 return false
1132 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001133 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001134 // Stubs do not need ABI dumps.
1135 return false
1136 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001137 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001138}
1139
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001140func (ctx *moduleContextImpl) selectedStl() string {
1141 if stl := ctx.mod.stl; stl != nil {
1142 return stl.Properties.SelectedStl
1143 }
1144 return ""
1145}
1146
Ivan Lozanobd721262018-11-27 14:33:03 -08001147func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1148 return ctx.mod.linker.useClangLld(actx)
1149}
1150
Colin Crossce75d2c2016-10-06 16:12:58 -07001151func (ctx *moduleContextImpl) baseModuleName() string {
1152 return ctx.mod.ModuleBase.BaseModuleName()
1153}
1154
Logan Chienf3511742017-10-31 18:04:35 +08001155func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1156 return ctx.mod.getVndkExtendsModuleName()
1157}
1158
Logan Chiene274fc92019-12-03 11:18:32 -08001159func (ctx *moduleContextImpl) isForPlatform() bool {
1160 return ctx.mod.IsForPlatform()
1161}
1162
Jiyong Park58e364a2019-01-19 19:24:06 +09001163func (ctx *moduleContextImpl) apexName() string {
1164 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001165}
1166
Jiyong Parkb0788572018-12-20 22:10:17 +09001167func (ctx *moduleContextImpl) hasStubsVariants() bool {
1168 return ctx.mod.HasStubsVariants()
1169}
1170
1171func (ctx *moduleContextImpl) isStubs() bool {
1172 return ctx.mod.IsStubs()
1173}
1174
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001175func (ctx *moduleContextImpl) bootstrap() bool {
1176 return ctx.mod.bootstrap()
1177}
1178
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001179func (ctx *moduleContextImpl) nativeCoverage() bool {
1180 return ctx.mod.nativeCoverage()
1181}
1182
Colin Cross635c3b02016-05-18 15:37:25 -07001183func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001184 return &Module{
1185 hod: hod,
1186 multilib: multilib,
1187 }
1188}
1189
Colin Cross635c3b02016-05-18 15:37:25 -07001190func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001191 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001192 module.features = []feature{
1193 &tidyFeature{},
1194 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001195 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001196 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001197 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001198 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001199 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001200 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001201 module.pgo = &pgo{}
Ivan Lozano074ec482018-11-21 08:59:37 -08001202 module.xom = &xom{}
Colin Crossca860ac2016-01-04 14:34:37 -08001203 return module
1204}
1205
Colin Crossce75d2c2016-10-06 16:12:58 -07001206func (c *Module) Prebuilt() *android.Prebuilt {
1207 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1208 return p.prebuilt()
1209 }
1210 return nil
1211}
1212
1213func (c *Module) Name() string {
1214 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001215 if p, ok := c.linker.(interface {
1216 Name(string) string
1217 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001218 name = p.Name(name)
1219 }
1220 return name
1221}
1222
Alex Light3d673592019-01-18 14:37:31 -08001223func (c *Module) Symlinks() []string {
1224 if p, ok := c.installer.(interface {
1225 symlinkList() []string
1226 }); ok {
1227 return p.symlinkList()
1228 }
1229 return nil
1230}
1231
Jeff Gaston294356f2017-09-27 17:05:30 -07001232// orderDeps reorders dependencies into a list such that if module A depends on B, then
1233// A will precede B in the resultant list.
1234// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001235// Note that directSharedDeps should be the analogous static library for each shared lib dep
1236func 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 -07001237 // If A depends on B, then
1238 // Every list containing A will also contain B later in the list
1239 // So, after concatenating all lists, the final instance of B will have come from the same
1240 // original list as the final instance of A
1241 // So, the final instance of B will be later in the concatenation than the final A
1242 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1243 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001244 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001245 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001246 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1247 }
1248 for _, dep := range directSharedDeps {
1249 orderedAllDeps = append(orderedAllDeps, dep)
1250 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001251 }
1252
Colin Crossb6715442017-10-24 11:13:31 -07001253 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001254
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001255 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001256 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001257 // resultant list to only what the caller has chosen to include in directStaticDeps
1258 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001259
1260 return orderedAllDeps, orderedDeclaredDeps
1261}
1262
Ivan Lozano183a3212019-10-18 14:18:45 -07001263func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001264 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001265 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001266 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1267 staticDepFiles := []android.Path{}
1268 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001269 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1270 if dep.OutputFile().Valid() {
1271 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1272 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1273 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001274 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001275 sharedDepFiles := []android.Path{}
1276 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001277 if sharedDep.HasStaticVariant() {
1278 staticAnalogue := sharedDep.GetStaticVariant()
1279 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1280 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001281 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001282 }
1283
1284 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001285 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1286 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001287
1288 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001289}
1290
Jiyong Park83dc74b2020-01-14 18:38:44 +09001291func gatherTransitiveStaticDeps(staticDeps []LinkableInterface) []string {
1292 var ret []string
1293 for _, dep := range staticDeps {
1294 ret = append(ret, dep.Module().Name())
1295 ret = append(ret, dep.AllStaticDeps()...)
1296 }
1297 return android.FirstUniqueStrings(ret)
1298}
1299
Roland Levillainf89cd092019-07-29 16:22:59 +01001300func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1301 test, ok := c.linker.(testPerSrc)
1302 return ok && test.isAllTestsVariation()
1303}
1304
Justin Yun5f7f7e82019-11-18 19:52:14 +09001305func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1306 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1307 // "current", it will append the VNDK version to the name suffix.
1308 var vndkVersion string
1309 var nameSuffix string
1310 if c.inProduct() {
1311 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1312 nameSuffix = productSuffix
1313 } else {
1314 vndkVersion = ctx.DeviceConfig().VndkVersion()
1315 nameSuffix = vendorSuffix
1316 }
1317 if vndkVersion == "current" {
1318 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1319 }
1320 if c.Properties.VndkVersion != vndkVersion {
1321 // add version suffix only if the module is using different vndk version than the
1322 // version in product or vendor partition.
1323 nameSuffix += "." + c.Properties.VndkVersion
1324 }
1325 return nameSuffix
1326}
1327
Colin Cross635c3b02016-05-18 15:37:25 -07001328func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001329 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001330 //
1331 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1332 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1333 // module and return early, as this module does not produce an output file per se.
1334 if c.IsTestPerSrcAllTestsVariation() {
1335 c.outputFile = android.OptionalPath{}
1336 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001337 }
1338
Jooyung Han38002912019-05-16 04:01:54 +09001339 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001340
Inseob Kim64c43952019-08-26 16:52:35 +09001341 c.Properties.SubName = ""
1342
1343 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1344 c.Properties.SubName += nativeBridgeSuffix
1345 }
1346
Justin Yun5f7f7e82019-11-18 19:52:14 +09001347 _, llndk := c.linker.(*llndkStubDecorator)
1348 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1349 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1350 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1351 // added for product variant only when we have vendor and product variants with core
1352 // variant. The suffix is not added for vendor-only or product-only module.
1353 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1354 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001355 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1356 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1357 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001358 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1359 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001360 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001361 c.Properties.SubName += recoverySuffix
1362 }
1363
Colin Crossca860ac2016-01-04 14:34:37 -08001364 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001365 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001366 moduleContextImpl: moduleContextImpl{
1367 mod: c,
1368 },
1369 }
1370 ctx.ctx = ctx
1371
Colin Crossf18e1102017-11-16 14:33:08 -08001372 deps := c.depsToPaths(ctx)
1373 if ctx.Failed() {
1374 return
1375 }
1376
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001377 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1378 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1379 }
1380
Colin Crossca860ac2016-01-04 14:34:37 -08001381 flags := Flags{
1382 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001383 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001384 }
Colin Crossca860ac2016-01-04 14:34:37 -08001385 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001386 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001387 }
1388 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001389 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001390 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001391 if c.stl != nil {
1392 flags = c.stl.flags(ctx, flags)
1393 }
Colin Cross16b23492016-01-06 14:41:07 -08001394 if c.sanitize != nil {
1395 flags = c.sanitize.flags(ctx, flags)
1396 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001397 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001398 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001399 }
Stephen Craneba090d12017-05-09 15:44:35 -07001400 if c.lto != nil {
1401 flags = c.lto.flags(ctx, flags)
1402 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001403 if c.pgo != nil {
1404 flags = c.pgo.flags(ctx, flags)
1405 }
Ivan Lozano074ec482018-11-21 08:59:37 -08001406 if c.xom != nil {
1407 flags = c.xom.flags(ctx, flags)
1408 }
Colin Crossca860ac2016-01-04 14:34:37 -08001409 for _, feature := range c.features {
1410 flags = feature.flags(ctx, flags)
1411 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001412 if ctx.Failed() {
1413 return
1414 }
1415
Colin Cross4af21ed2019-11-04 09:37:55 -08001416 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1417 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1418 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001419
Colin Cross4af21ed2019-11-04 09:37:55 -08001420 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001421
1422 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001423 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001424 }
1425 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001426 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001427 }
1428
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001429 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001430 // We need access to all the flags seen by a source file.
1431 if c.sabi != nil {
1432 flags = c.sabi.flags(ctx, flags)
1433 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001434
Colin Cross4af21ed2019-11-04 09:37:55 -08001435 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001436
Colin Crossca860ac2016-01-04 14:34:37 -08001437 // Optimization to reduce size of build.ninja
1438 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001439 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1440 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1441 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1442 flags.Local.CFlags = []string{"$cflags"}
1443 flags.Local.CppFlags = []string{"$cppflags"}
1444 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001445
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001446 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001447 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001448 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001449 if ctx.Failed() {
1450 return
1451 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001452 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001453 }
1454
Colin Crossca860ac2016-01-04 14:34:37 -08001455 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001456 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001457 if ctx.Failed() {
1458 return
1459 }
Colin Cross635c3b02016-05-18 15:37:25 -07001460 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001461
1462 // If a lib is directly included in any of the APEXes, unhide the stubs
1463 // variant having the latest version gets visible to make. In addition,
1464 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1465 // force anything in the make world to link against the stubs library.
1466 // (unless it is explicitly referenced via .bootstrap suffix or the
1467 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001468 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001469 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001470 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001471 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001472 c.Properties.HideFromMake = false // unhide
1473 // Note: this is still non-installable
1474 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001475 }
Colin Cross5049f022015-03-18 13:28:46 -07001476
Inseob Kim1f086e22019-05-09 13:29:15 +09001477 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001478 c.installer.install(ctx, c.outputFile.Path())
1479 if ctx.Failed() {
1480 return
Colin Crossca860ac2016-01-04 14:34:37 -08001481 }
Dan Albertc403f7c2015-03-18 14:01:18 -07001482 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001483}
1484
Colin Cross0ea8ba82019-06-06 14:33:29 -07001485func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001486 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001487 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001488 }
Colin Crossca860ac2016-01-04 14:34:37 -08001489 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001490}
1491
Colin Crossca860ac2016-01-04 14:34:37 -08001492func (c *Module) begin(ctx BaseModuleContext) {
1493 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001494 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001495 }
Colin Crossca860ac2016-01-04 14:34:37 -08001496 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001497 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001498 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001499 if c.stl != nil {
1500 c.stl.begin(ctx)
1501 }
Colin Cross16b23492016-01-06 14:41:07 -08001502 if c.sanitize != nil {
1503 c.sanitize.begin(ctx)
1504 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001505 if c.coverage != nil {
1506 c.coverage.begin(ctx)
1507 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001508 if c.sabi != nil {
1509 c.sabi.begin(ctx)
1510 }
Justin Yun8effde42017-06-23 19:24:43 +09001511 if c.vndkdep != nil {
1512 c.vndkdep.begin(ctx)
1513 }
Stephen Craneba090d12017-05-09 15:44:35 -07001514 if c.lto != nil {
1515 c.lto.begin(ctx)
1516 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001517 if c.pgo != nil {
1518 c.pgo.begin(ctx)
1519 }
Colin Crossca860ac2016-01-04 14:34:37 -08001520 for _, feature := range c.features {
1521 feature.begin(ctx)
1522 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001523 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001524 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001525 if err != nil {
1526 ctx.PropertyErrorf("sdk_version", err.Error())
1527 }
Nan Zhang0007d812017-11-07 10:57:05 -08001528 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001529 }
Colin Crossca860ac2016-01-04 14:34:37 -08001530}
1531
Colin Cross37047f12016-12-13 17:06:13 -08001532func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001533 deps := Deps{}
1534
1535 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001536 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001537 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001538 // Add the PGO dependency (the clang_rt.profile runtime library), which
1539 // sometimes depends on symbols from libgcc, before libgcc gets added
1540 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001541 if c.pgo != nil {
1542 deps = c.pgo.deps(ctx, deps)
1543 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001544 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001545 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001546 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001547 if c.stl != nil {
1548 deps = c.stl.deps(ctx, deps)
1549 }
Colin Cross16b23492016-01-06 14:41:07 -08001550 if c.sanitize != nil {
1551 deps = c.sanitize.deps(ctx, deps)
1552 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001553 if c.coverage != nil {
1554 deps = c.coverage.deps(ctx, deps)
1555 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001556 if c.sabi != nil {
1557 deps = c.sabi.deps(ctx, deps)
1558 }
Justin Yun8effde42017-06-23 19:24:43 +09001559 if c.vndkdep != nil {
1560 deps = c.vndkdep.deps(ctx, deps)
1561 }
Stephen Craneba090d12017-05-09 15:44:35 -07001562 if c.lto != nil {
1563 deps = c.lto.deps(ctx, deps)
1564 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001565 for _, feature := range c.features {
1566 deps = feature.deps(ctx, deps)
1567 }
1568
Colin Crossb6715442017-10-24 11:13:31 -07001569 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1570 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1571 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1572 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1573 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1574 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001575 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001576
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001577 for _, lib := range deps.ReexportSharedLibHeaders {
1578 if !inList(lib, deps.SharedLibs) {
1579 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1580 }
1581 }
1582
1583 for _, lib := range deps.ReexportStaticLibHeaders {
1584 if !inList(lib, deps.StaticLibs) {
1585 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1586 }
1587 }
1588
Colin Cross5950f382016-12-13 12:50:57 -08001589 for _, lib := range deps.ReexportHeaderLibHeaders {
1590 if !inList(lib, deps.HeaderLibs) {
1591 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1592 }
1593 }
1594
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001595 for _, gen := range deps.ReexportGeneratedHeaders {
1596 if !inList(gen, deps.GeneratedHeaders) {
1597 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1598 }
1599 }
1600
Colin Crossc99deeb2016-04-11 15:06:20 -07001601 return deps
1602}
1603
Dan Albert7e9d2952016-08-04 13:02:36 -07001604func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001605 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001606 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001607 moduleContextImpl: moduleContextImpl{
1608 mod: c,
1609 },
1610 }
1611 ctx.ctx = ctx
1612
Colin Crossca860ac2016-01-04 14:34:37 -08001613 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001614}
1615
Jiyong Park7ed9de32018-10-15 22:25:07 +09001616// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001617func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001618 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1619 version := name[sharp+1:]
1620 libname := name[:sharp]
1621 return libname, version
1622 }
1623 return name, ""
1624}
1625
Colin Cross1e676be2016-10-12 14:38:15 -07001626func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Colin Cross37047f12016-12-13 17:06:13 -08001627 ctx := &depsContext{
1628 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001629 moduleContextImpl: moduleContextImpl{
1630 mod: c,
1631 },
1632 }
1633 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001634
Colin Crossc99deeb2016-04-11 15:06:20 -07001635 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001636
Dan Albert914449f2016-06-17 16:45:24 -07001637 variantNdkLibs := []string{}
1638 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001639 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001640 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001641
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001642 // rewriteNdkLibs takes a list of names of shared libraries and scans it for three types
1643 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001644 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001645 // 1. Name of an NDK library that refers to a prebuilt module.
1646 // For each of these, it adds the name of the prebuilt module (which will be in
1647 // prebuilts/ndk) to the list of nonvariant libs.
1648 // 2. Name of an NDK library that refers to an ndk_library module.
1649 // For each of these, it adds the name of the ndk_library module to the list of
1650 // variant libs.
1651 // 3. Anything else (so anything that isn't an NDK library).
1652 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001653 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001654 // The caller can then know to add the variantLibs dependencies differently from the
1655 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001656
Inseob Kim9516ee92019-05-09 10:56:13 +09001657 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001658 rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
1659 variantLibs = []string{}
1660 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001661 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001662 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001663 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001664 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1665 if !inList(name, ndkMigratedLibs) {
1666 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001667 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001668 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001669 }
Jooyung Han0302a842019-10-30 18:43:49 +09001670 } else if ctx.useVndk() && isLlndkLibrary(name, ctx.Config()) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001671 nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
Inseob Kim9516ee92019-05-09 10:56:13 +09001672 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001673 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001674 if actx.OtherModuleExists(vendorPublicLib) {
1675 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1676 } else {
1677 // This can happen if vendor_public_library module is defined in a
1678 // namespace that isn't visible to the current module. In that case,
1679 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001680 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001681 }
Dan Albert914449f2016-06-17 16:45:24 -07001682 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001683 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001684 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001685 }
1686 }
Dan Albert914449f2016-06-17 16:45:24 -07001687 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001688 }
1689
Dan Albert914449f2016-06-17 16:45:24 -07001690 deps.SharedLibs, variantNdkLibs = rewriteNdkLibs(deps.SharedLibs)
1691 deps.LateSharedLibs, variantLateNdkLibs = rewriteNdkLibs(deps.LateSharedLibs)
Jiyong Park4c35af02017-07-05 13:41:55 +09001692 deps.ReexportSharedLibHeaders, _ = rewriteNdkLibs(deps.ReexportSharedLibHeaders)
Dan Willemsen72d39932016-07-08 23:23:48 -07001693 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001694
Jiyong Park7e636d02019-01-28 16:16:54 +09001695 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001696 if c.linker != nil {
1697 if library, ok := c.linker.(*libraryDecorator); ok {
1698 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001699 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001700 }
1701 }
1702 }
1703
Colin Cross32ec36c2016-12-15 07:39:51 -08001704 for _, lib := range deps.HeaderLibs {
1705 depTag := headerDepTag
1706 if inList(lib, deps.ReexportHeaderLibHeaders) {
1707 depTag = headerExportDepTag
1708 }
Jiyong Park7e636d02019-01-28 16:16:54 +09001709 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001710 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001711 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001712 } else {
1713 actx.AddVariationDependencies(nil, depTag, lib)
1714 }
1715 }
1716
1717 if buildStubs {
1718 // Stubs lib does not have dependency to other static/shared libraries.
1719 // Don't proceed.
1720 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001721 }
Colin Cross5950f382016-12-13 12:50:57 -08001722
Inseob Kimc0907f12019-02-08 21:00:45 +09001723 syspropImplLibraries := syspropImplLibraries(actx.Config())
1724
Jiyong Park5d1598f2019-02-25 22:14:17 +09001725 for _, lib := range deps.WholeStaticLibs {
1726 depTag := wholeStaticDepTag
1727 if impl, ok := syspropImplLibraries[lib]; ok {
1728 lib = impl
1729 }
1730 actx.AddVariationDependencies([]blueprint.Variation{
1731 {Mutator: "link", Variation: "static"},
1732 }, depTag, lib)
1733 }
1734
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001735 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001736 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001737 if inList(lib, deps.ReexportStaticLibHeaders) {
1738 depTag = staticExportDepTag
1739 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001740
1741 if impl, ok := syspropImplLibraries[lib]; ok {
1742 lib = impl
1743 }
1744
Dan Willemsen59339a22018-07-22 21:18:45 -07001745 actx.AddVariationDependencies([]blueprint.Variation{
1746 {Mutator: "link", Variation: "static"},
1747 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001748 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001749
Dan Willemsen59339a22018-07-22 21:18:45 -07001750 actx.AddVariationDependencies([]blueprint.Variation{
1751 {Mutator: "link", Variation: "static"},
1752 }, lateStaticDepTag, deps.LateStaticLibs...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001753
Ivan Lozano183a3212019-10-18 14:18:45 -07001754 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001755 var variations []blueprint.Variation
1756 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Yifan Hong1b3348d2020-01-21 15:53:22 -08001757 versionVariantAvail := !ctx.useVndk() && !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001758 if version != "" && versionVariantAvail {
1759 // Version is explicitly specified. i.e. libFoo#30
1760 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001761 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001762 }
1763 actx.AddVariationDependencies(variations, depTag, name)
1764
1765 // If the version is not specified, add dependency to the latest stubs library.
1766 // The stubs library will be used when the depending module is built for APEX and
1767 // the dependent module is not in the same APEX.
Jiyong Park73c54ee2019-10-22 20:31:18 +09001768 latestVersion := LatestStubsVersionFor(actx.Config(), name)
Jiyong Park25fc6a92018-11-18 18:02:45 +09001769 if version == "" && latestVersion != "" && versionVariantAvail {
1770 actx.AddVariationDependencies([]blueprint.Variation{
1771 {Mutator: "link", Variation: "shared"},
1772 {Mutator: "version", Variation: latestVersion},
1773 }, depTag, name)
Ivan Lozano183a3212019-10-18 14:18:45 -07001774 // Note that depTag.ExplicitlyVersioned is false in this case.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001775 }
1776 }
1777
Jiyong Park7ed9de32018-10-15 22:25:07 +09001778 // shared lib names without the #version suffix
1779 var sharedLibNames []string
1780
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001781 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001782 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001783 if c.static() {
1784 depTag = SharedFromStaticDepTag
1785 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001786 if inList(lib, deps.ReexportSharedLibHeaders) {
1787 depTag = sharedExportDepTag
1788 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001789
1790 if impl, ok := syspropImplLibraries[lib]; ok {
1791 lib = impl
1792 }
1793
Jiyong Park73c54ee2019-10-22 20:31:18 +09001794 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001795 sharedLibNames = append(sharedLibNames, name)
1796
Jiyong Park25fc6a92018-11-18 18:02:45 +09001797 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001798 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001799
Jiyong Park7ed9de32018-10-15 22:25:07 +09001800 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001801 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001802 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1803 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1804 // linking against both the stubs lib and the non-stubs lib at the same time.
1805 continue
1806 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001807 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001808 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001809
Dan Willemsen59339a22018-07-22 21:18:45 -07001810 actx.AddVariationDependencies([]blueprint.Variation{
1811 {Mutator: "link", Variation: "shared"},
1812 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001813
Colin Cross68861832016-07-08 10:41:41 -07001814 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001815
1816 for _, gen := range deps.GeneratedHeaders {
1817 depTag := genHeaderDepTag
1818 if inList(gen, deps.ReexportGeneratedHeaders) {
1819 depTag = genHeaderExportDepTag
1820 }
1821 actx.AddDependency(c, depTag, gen)
1822 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001823
Colin Cross42d48b72018-08-29 14:10:52 -07001824 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001825
1826 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001827 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001828 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001829 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001830 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001831 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001832 if deps.LinkerFlagsFile != "" {
1833 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1834 }
1835 if deps.DynamicLinker != "" {
1836 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001837 }
Dan Albert914449f2016-06-17 16:45:24 -07001838
1839 version := ctx.sdkVersion()
1840 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001841 {Mutator: "ndk_api", Variation: version},
1842 {Mutator: "link", Variation: "shared"},
1843 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001844 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001845 {Mutator: "ndk_api", Variation: version},
1846 {Mutator: "link", Variation: "shared"},
1847 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001848
1849 if vndkdep := c.vndkdep; vndkdep != nil {
1850 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001851 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001852 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001853 {Mutator: "link", Variation: "shared"},
1854 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001855 }
1856 }
Colin Cross6362e272015-10-29 15:25:03 -07001857}
Colin Cross21b9a242015-03-24 14:15:58 -07001858
Colin Crosse40b4ea2018-10-02 22:25:58 -07001859func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001860 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1861 c.beginMutator(ctx)
1862 }
1863}
1864
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001865// Whether a module can link to another module, taking into
1866// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001867func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1868 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001869 // Host code is not restricted
1870 return
1871 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001872
1873 // VNDK is cc.Module supported only for now.
1874 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001875 // Though vendor code is limited by the vendor mutator,
1876 // each vendor-available module needs to check
1877 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001878 if ccTo, ok := to.(*Module); ok {
1879 if ccFrom.vndkdep != nil {
1880 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1881 }
1882 } else {
1883 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001884 }
1885 return
1886 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001887 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001888 // Platform code can link to anything
1889 return
1890 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001891 if from.InRamdisk() {
1892 // Ramdisk code is not NDK
1893 return
1894 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001895 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09001896 // Recovery code is not NDK
1897 return
1898 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001899 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001900 // These are always allowed
1901 return
1902 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001903 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001904 // These are allowed, but they don't set sdk_version
1905 return
1906 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001907 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001908 // These aren't real libraries, but are the stub shared libraries that are included in
1909 // the NDK.
1910 return
1911 }
Logan Chien834b9a62019-01-14 15:39:03 +08001912
Ivan Lozano52767be2019-10-18 14:49:46 -07001913 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08001914 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
1915 // to link to libc++ (non-NDK and without sdk_version).
1916 return
1917 }
1918
Ivan Lozano52767be2019-10-18 14:49:46 -07001919 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001920 // NDK code linking to platform code is never okay.
1921 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001922 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08001923 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001924 }
1925
1926 // At this point we know we have two NDK libraries, but we need to
1927 // check that we're not linking against anything built against a higher
1928 // API level, as it is only valid to link against older or equivalent
1929 // APIs.
1930
Inseob Kim01a28722018-04-11 09:48:45 +09001931 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07001932 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001933 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07001934 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09001935 // Current can't be linked against by anything else.
1936 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001937 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09001938 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07001939 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001940 if err != nil {
1941 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001942 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001943 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001944 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001945 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001946 if err != nil {
1947 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09001948 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001949 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001950 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001951
Inseob Kim01a28722018-04-11 09:48:45 +09001952 if toApi > fromApi {
1953 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001954 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09001955 }
1956 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001957 }
Dan Albert202fe492017-12-15 13:56:59 -08001958
1959 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07001960 fromStl := from.SelectedStl()
1961 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08001962 if fromStl == "" || toStl == "" {
1963 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09001964 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08001965 // We can be permissive with the system "STL" since it is only the C++
1966 // ABI layer, but in the future we should make sure that everyone is
1967 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07001968 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08001969 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07001970 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
1971 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08001972 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001973}
1974
Jiyong Park5fb8c102018-04-09 12:03:06 +09001975// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09001976// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
1977// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001978// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09001979func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
1980 check := func(child, parent android.Module) bool {
1981 to, ok := child.(*Module)
1982 if !ok {
1983 // follow thru cc.Defaults, etc.
1984 return true
1985 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09001986
Jooyung Hana70f0672019-01-18 15:20:43 +09001987 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
1988 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09001989 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001990
1991 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07001992 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09001993 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09001994 }
Jooyung Hana70f0672019-01-18 15:20:43 +09001995
Jooyung Han0302a842019-10-30 18:43:49 +09001996 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09001997 return false
1998 }
1999
2000 var stringPath []string
2001 for _, m := range ctx.GetWalkPath() {
2002 stringPath = append(stringPath, m.Name())
2003 }
2004 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2005 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2006 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2007 return false
2008 }
2009 if module, ok := ctx.Module().(*Module); ok {
2010 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002011 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002012 ctx.WalkDeps(check)
2013 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002014 }
2015 }
2016}
2017
Colin Crossc99deeb2016-04-11 15:06:20 -07002018// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002019func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002020 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002021
Ivan Lozano183a3212019-10-18 14:18:45 -07002022 directStaticDeps := []LinkableInterface{}
2023 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002024
Inseob Kim9516ee92019-05-09 10:56:13 +09002025 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2026
Inseob Kim69378442019-06-03 19:10:47 +09002027 reexportExporter := func(exporter exportedFlagsProducer) {
2028 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2029 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2030 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2031 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002032 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002033 }
2034
Colin Crossd11fcda2017-10-23 17:59:01 -07002035 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002036 depName := ctx.OtherModuleName(dep)
2037 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002038
Ivan Lozano52767be2019-10-18 14:49:46 -07002039 ccDep, ok := dep.(LinkableInterface)
2040 if !ok {
2041
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002042 // handling for a few module types that aren't cc Module but that are also supported
2043 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002044 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002045 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002046 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2047 genRule.GeneratedSourceFiles()...)
2048 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002049 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002050 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002051 // Support exported headers from a generated_sources dependency
2052 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002053 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002054 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002055 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002056 genRule.GeneratedSourceFiles()...)
2057 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002058 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002059 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002060 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002061 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002062 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002063 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2064 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002065 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002066 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
Jiyong Park74955042019-10-22 20:19:51 +09002067 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002068
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002069 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002070 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002071 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002072 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002073 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002074 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002075 files := genRule.GeneratedSourceFiles()
2076 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002077 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002078 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002079 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 -07002080 }
2081 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002082 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002083 }
Colin Crossca860ac2016-01-04 14:34:37 -08002084 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002085 return
2086 }
2087
Colin Crossfe17f6f2019-03-28 19:30:56 -07002088 if depTag == android.ProtoPluginDepTag {
2089 return
2090 }
2091
Colin Crossd11fcda2017-10-23 17:59:01 -07002092 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002093 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2094 return
2095 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002096 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002097 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002098 return
2099 }
2100
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002101 // re-exporting flags
2102 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002103 // reusing objects only make sense for cc.Modules.
2104 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002105 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002106 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002107 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002108 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002109 return
2110 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002111 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002112
Jiyong Parke4bb9862019-02-01 00:31:10 +09002113 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002114 // staticVariants are a cc.Module specific concept.
2115 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002116 c.staticVariant = ccDep
2117 return
2118 }
2119 }
2120
Ivan Lozano183a3212019-10-18 14:18:45 -07002121 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2122 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2123 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002124 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002125 if t, ok := depTag.(DependencyTag); ok {
2126 explicitlyVersioned = t.ExplicitlyVersioned
2127 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002128 depTag = t
2129 }
2130
Ivan Lozano183a3212019-10-18 14:18:45 -07002131 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002132 depIsStatic := false
2133 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002134 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002135 depIsStatic = true
2136 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002137 if ccDep.CcLibrary() && !depIsStatic {
2138 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002139 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002140 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002141 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002142
2143 var useThisDep bool
2144 if depIsStubs && explicitlyVersioned {
2145 // Always respect dependency to the versioned stubs (i.e. libX#10)
2146 useThisDep = true
2147 } else if !depHasStubs {
2148 // Use non-stub variant if that is the only choice
2149 // (i.e. depending on a lib without stubs.version property)
2150 useThisDep = true
2151 } else if c.IsForPlatform() {
2152 // If not building for APEX, use stubs only when it is from
2153 // an APEX (and not from platform)
2154 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002155 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2156 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002157 // always link to non-stub variant
2158 useThisDep = !depIsStubs
2159 }
2160 } else {
2161 // If building for APEX, use stubs only when it is not from
2162 // the same APEX
2163 useThisDep = (depInSameApex != depIsStubs)
2164 }
2165
2166 if !useThisDep {
2167 return // stop processing this dep
2168 }
2169 }
2170
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002171 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2172
Ivan Lozano52767be2019-10-18 14:49:46 -07002173 // Exporting flags only makes sense for cc.Modules
2174 if _, ok := ccDep.(*Module); ok {
2175 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002176 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002177 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2178 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002179 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002180
Ivan Lozano52767be2019-10-18 14:49:46 -07002181 if t.ReexportFlags {
2182 reexportExporter(i)
2183 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2184 // Re-exported shared library headers must be included as well since they can help us with type information
2185 // about template instantiations (instantiated from their headers).
2186 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2187 // scripts.
2188 c.sabi.Properties.ReexportedIncludes = append(
2189 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2190 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002191 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002192 }
Logan Chienf3511742017-10-31 18:04:35 +08002193 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002194 }
2195
Colin Cross26c34ed2016-09-30 17:10:16 -07002196 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002197 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002198
Ivan Lozano52767be2019-10-18 14:49:46 -07002199 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002200 depFile := android.OptionalPath{}
2201
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002202 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002203 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002204 ptr = &depPaths.SharedLibs
2205 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002206 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002207 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002208
Jiyong Park64a44f22019-01-18 14:37:08 +09002209 case earlySharedDepTag:
2210 ptr = &depPaths.EarlySharedLibs
2211 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002212 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002213 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002214 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002215 ptr = &depPaths.LateSharedLibs
2216 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002217 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002218 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002219 ptr = nil
2220 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002221 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002222 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002223 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002224 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002225 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002226 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002227 return
2228 }
2229
Ivan Lozano52767be2019-10-18 14:49:46 -07002230 // Because the static library objects are included, this only makes sense
2231 // in the context of proper cc.Modules.
2232 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2233 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2234 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2235 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2236 for i := range missingDeps {
2237 missingDeps[i] += postfix
2238 }
2239 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002240 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002241 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2242 } else {
2243 ctx.ModuleErrorf(
2244 "non-cc.Modules cannot be included as whole static libraries.", depName)
2245 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002246 }
Colin Cross5950f382016-12-13 12:50:57 -08002247 case headerDepTag:
2248 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002249 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002250 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002251 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002252 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002253 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002254 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002255 case dynamicLinkerDepTag:
2256 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002257 }
2258
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002259 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002260 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002261 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002262 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002263 return
2264 }
2265
2266 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002267 // in static libraries act as if they were whole static libraries. The same goes for
2268 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002269 // This should only be done for cc.Modules
2270 if c, ok := ccDep.(*Module); ok {
2271 staticLib := c.linker.(libraryInterface)
2272 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2273 staticLib.objs().coverageFiles...)
2274 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2275 staticLib.objs().sAbiDumpFiles...)
2276 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002277 }
2278
Colin Cross26c34ed2016-09-30 17:10:16 -07002279 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002280 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002281 if !ctx.Config().AllowMissingDependencies() {
2282 ctx.ModuleErrorf("module %q missing output file", depName)
2283 } else {
2284 ctx.AddMissingDependencies([]string{depName})
2285 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002286 return
2287 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002288 *ptr = append(*ptr, linkFile.Path())
2289 }
2290
Colin Crossc99deeb2016-04-11 15:06:20 -07002291 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002292 dep := depFile
2293 if !dep.Valid() {
2294 dep = linkFile
2295 }
2296 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002297 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002298
Logan Chien43d34c32017-12-20 01:17:32 +08002299 makeLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002300 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002301 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002302 libName = strings.TrimPrefix(libName, "prebuilt_")
Jooyung Han0302a842019-10-30 18:43:49 +09002303 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002304 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002305 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002306
Yifan Hong1b3348d2020-01-21 15:53:22 -08002307 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002308 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2309 // core module instead.
2310 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002311 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002312 // The vendor module in Make will have been renamed to not conflict with the core
2313 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002314 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002315 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002316 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002317 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2318 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002319 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002320 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002321 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002322 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002323 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002324 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002325 }
Logan Chien43d34c32017-12-20 01:17:32 +08002326 }
2327
2328 // Export the shared libs to Make.
2329 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002330 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002331 if ccDep.CcLibrary() {
2332 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002333 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002334 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002335 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002336 c.Properties.ApexesProvidingSharedLibs = append(
2337 c.Properties.ApexesProvidingSharedLibs, an)
2338 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002339 }
2340 }
2341
Jiyong Park27b188b2017-07-18 13:23:39 +09002342 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002343 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002344 c.Properties.AndroidMkSharedLibs = append(
2345 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002346 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002347 c.Properties.AndroidMkSharedLibs = append(
2348 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002349 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002350 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002351 c.Properties.AndroidMkStaticLibs = append(
2352 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002353 case runtimeDepTag:
2354 c.Properties.AndroidMkRuntimeLibs = append(
2355 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002356 case wholeStaticDepTag:
2357 c.Properties.AndroidMkWholeStaticLibs = append(
2358 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002359 }
Colin Crossca860ac2016-01-04 14:34:37 -08002360 })
2361
Jeff Gaston294356f2017-09-27 17:05:30 -07002362 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002363 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002364
Colin Crossdd84e052017-05-17 13:44:16 -07002365 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002366 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002367 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2368 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002369 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002370 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002371 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2372 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002373 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002374 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002375 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002376
2377 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002378 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002379 }
Colin Crossdd84e052017-05-17 13:44:16 -07002380
Jiyong Park83dc74b2020-01-14 18:38:44 +09002381 c.allStaticDeps = gatherTransitiveStaticDeps(directStaticDeps)
2382
Colin Crossca860ac2016-01-04 14:34:37 -08002383 return depPaths
2384}
2385
2386func (c *Module) InstallInData() bool {
2387 if c.installer == nil {
2388 return false
2389 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002390 return c.installer.inData()
2391}
2392
2393func (c *Module) InstallInSanitizerDir() bool {
2394 if c.installer == nil {
2395 return false
2396 }
2397 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002398 return true
2399 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002400 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002401}
2402
Yifan Hong1b3348d2020-01-21 15:53:22 -08002403func (c *Module) InstallInRamdisk() bool {
2404 return c.InRamdisk()
2405}
2406
Jiyong Parkf9332f12018-02-01 00:54:12 +09002407func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002408 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002409}
2410
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002411func (c *Module) HostToolPath() android.OptionalPath {
2412 if c.installer == nil {
2413 return android.OptionalPath{}
2414 }
2415 return c.installer.hostToolPath()
2416}
2417
Nan Zhangd4e641b2017-07-12 12:55:28 -07002418func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2419 return c.outputFile
2420}
2421
Colin Cross41955e82019-05-29 14:40:35 -07002422func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2423 switch tag {
2424 case "":
2425 if c.outputFile.Valid() {
2426 return android.Paths{c.outputFile.Path()}, nil
2427 }
2428 return android.Paths{}, nil
2429 default:
2430 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002431 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002432}
2433
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002434func (c *Module) static() bool {
2435 if static, ok := c.linker.(interface {
2436 static() bool
2437 }); ok {
2438 return static.static()
2439 }
2440 return false
2441}
2442
Jiyong Park379de2f2018-12-19 02:47:14 +09002443func (c *Module) staticBinary() bool {
2444 if static, ok := c.linker.(interface {
2445 staticBinary() bool
2446 }); ok {
2447 return static.staticBinary()
2448 }
2449 return false
2450}
2451
Jiyong Park1d1119f2019-07-29 21:27:18 +09002452func (c *Module) header() bool {
2453 if h, ok := c.linker.(interface {
2454 header() bool
2455 }); ok {
2456 return h.header()
2457 }
2458 return false
2459}
2460
Jooyung Han38002912019-05-16 04:01:54 +09002461func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002462 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002463 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2464 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002465 return "native:vndk"
2466 }
Jooyung Han38002912019-05-16 04:01:54 +09002467 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002468 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002469 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002470 if Bool(c.VendorProperties.Vendor_available) {
2471 return "native:vndk"
2472 }
2473 return "native:vndk_private"
2474 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002475 if c.inProduct() {
2476 return "native:product"
2477 }
Jooyung Han38002912019-05-16 04:01:54 +09002478 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002479 } else if c.InRamdisk() {
2480 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002481 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002482 return "native:recovery"
2483 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2484 return "native:ndk:none:none"
2485 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2486 //family, link := getNdkStlFamilyAndLinkType(c)
2487 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002488 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002489 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002490 } else {
2491 return "native:platform"
2492 }
2493}
2494
Jiyong Park9d452992018-10-03 00:38:19 +09002495// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002496// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002497func (c *Module) IsInstallableToApex() bool {
2498 if shared, ok := c.linker.(interface {
2499 shared() bool
2500 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002501 // Stub libs and prebuilt libs in a versioned SDK are not
2502 // installable to APEX even though they are shared libs.
2503 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002504 } else if _, ok := c.linker.(testPerSrc); ok {
2505 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002506 }
2507 return false
2508}
2509
Jiyong Parka90ca002019-10-07 15:47:24 +09002510func (c *Module) AvailableFor(what string) bool {
2511 if linker, ok := c.linker.(interface {
2512 availableFor(string) bool
2513 }); ok {
2514 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2515 } else {
2516 return c.ApexModuleBase.AvailableFor(what)
2517 }
2518}
2519
Inseob Kim1f086e22019-05-09 13:29:15 +09002520func (c *Module) installable() bool {
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002521 ret := c.installer != nil && !c.Properties.PreventInstall && c.outputFile.Valid()
2522
2523 // The platform variant doesn't need further condition. Apex variants however might not
2524 // be installable because it will likely to be included in the APEX and won't appear
2525 // in the system partition.
2526 if c.IsForPlatform() {
2527 return ret
2528 }
2529
2530 // Special case for modules that are configured to be installed to /data, which includes
2531 // test modules. For these modules, both APEX and non-APEX variants are considered as
2532 // installable. This is because even the APEX variants won't be included in the APEX, but
2533 // will anyway be installed to /data/*.
2534 // See b/146995717
2535 if c.InstallInData() {
2536 return ret
2537 }
2538
2539 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002540}
2541
Jiyong Park83dc74b2020-01-14 18:38:44 +09002542func (c *Module) AllStaticDeps() []string {
2543 return c.allStaticDeps
2544}
2545
Logan Chien41eabe62019-04-10 13:33:58 +08002546func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2547 if c.linker != nil {
2548 if library, ok := c.linker.(*libraryDecorator); ok {
2549 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2550 }
2551 }
2552}
2553
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002554func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002555 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002556 if cc, ok := dep.(*Module); ok {
2557 if cc.HasStubsVariants() && depTag.Shared && depTag.Library {
2558 // dynamic dep to a stubs lib crosses APEX boundary
2559 return false
2560 }
2561 if depTag.FromStatic {
2562 // shared_lib dependency from a static lib is considered as crossing
2563 // the APEX boundary because the dependency doesn't actually is
2564 // linked; the dependency is used only during the compilation phase.
2565 return false
2566 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002567 }
2568 }
2569 return true
2570}
2571
Colin Cross2ba19d92015-05-07 15:44:20 -07002572//
Colin Crosscfad1192015-11-02 16:43:11 -08002573// Defaults
2574//
Colin Crossca860ac2016-01-04 14:34:37 -08002575type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002576 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002577 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002578 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002579}
2580
Patrice Arrudac249c712019-03-19 17:00:29 -07002581// cc_defaults provides a set of properties that can be inherited by other cc
2582// modules. A module can use the properties from a cc_defaults using
2583// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2584// merged (when possible) by prepending the default module's values to the
2585// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002586func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002587 return DefaultsFactory()
2588}
2589
Colin Cross36242852017-06-23 15:06:31 -07002590func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002591 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002592
Colin Cross36242852017-06-23 15:06:31 -07002593 module.AddProperties(props...)
2594 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002595 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002596 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002597 &BaseCompilerProperties{},
2598 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002599 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002600 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002601 &StaticProperties{},
2602 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002603 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002604 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002605 &TestProperties{},
2606 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002607 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002608 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002609 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002610 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002611 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002612 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002613 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002614 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002615 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002616 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002617 &PgoProperties{},
Ivan Lozano074ec482018-11-21 08:59:37 -08002618 &XomProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002619 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002620 )
Colin Crosscfad1192015-11-02 16:43:11 -08002621
Jooyung Hancc372c52019-09-25 15:18:44 +09002622 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002623
2624 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002625}
2626
Jiyong Park6a43f042017-10-12 23:05:00 +09002627func squashVendorSrcs(m *Module) {
2628 if lib, ok := m.compiler.(*libraryDecorator); ok {
2629 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2630 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2631
2632 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2633 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2634 }
2635}
2636
Jiyong Parkf9332f12018-02-01 00:54:12 +09002637func squashRecoverySrcs(m *Module) {
2638 if lib, ok := m.compiler.(*libraryDecorator); ok {
2639 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2640 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2641
2642 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2643 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2644 }
2645}
2646
Colin Cross7228ecd2019-11-18 16:00:16 -08002647var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002648
Colin Cross7228ecd2019-11-18 16:00:16 -08002649func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002650 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002651 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002652 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002653
2654 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002655 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002656 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002657 }
Logan Chienf3511742017-10-31 18:04:35 +08002658
2659 if vndkdep := m.vndkdep; vndkdep != nil {
2660 if vndkdep.isVndk() {
Justin Yun9357f4a2018-11-28 15:14:47 +09002661 if productSpecific {
2662 mctx.PropertyErrorf("product_specific",
2663 "product_specific must not be true when `vndk: {enabled: true}`")
Justin Yun9357f4a2018-11-28 15:14:47 +09002664 }
Logan Chienf3511742017-10-31 18:04:35 +08002665 if vendorSpecific {
2666 if !vndkdep.isVndkExt() {
2667 mctx.PropertyErrorf("vndk",
2668 "must set `extends: \"...\"` to vndk extension")
Logan Chienf3511742017-10-31 18:04:35 +08002669 }
2670 } else {
2671 if vndkdep.isVndkExt() {
2672 mctx.PropertyErrorf("vndk",
2673 "must set `vendor: true` to set `extends: %q`",
2674 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002675 }
2676 if m.VendorProperties.Vendor_available == nil {
2677 mctx.PropertyErrorf("vndk",
2678 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002679 }
2680 }
2681 } else {
2682 if vndkdep.isVndkSp() {
2683 mctx.PropertyErrorf("vndk",
2684 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002685 }
2686 if vndkdep.isVndkExt() {
2687 mctx.PropertyErrorf("vndk",
2688 "must set `enabled: true` to set `extends: %q`",
2689 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002690 }
Justin Yun8effde42017-06-23 19:24:43 +09002691 }
2692 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002693
Jiyong Parkf9332f12018-02-01 00:54:12 +09002694 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002695 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002696 var recoveryVariantNeeded bool = false
2697
Inseob Kim64c43952019-08-26 16:52:35 +09002698 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002699 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002700
2701 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002702 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2703 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2704 if boardVndkVersion == "current" {
2705 boardVndkVersion = platformVndkVersion
2706 }
2707 if productVndkVersion == "current" {
2708 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002709 }
2710
Justin Yun5f7f7e82019-11-18 19:52:14 +09002711 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002712 // If the device isn't compiling against the VNDK, we always
2713 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002714 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002715 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002716 // LL-NDK stubs only exist in the vendor and product variants,
2717 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002718 vendorVariants = append(vendorVariants,
2719 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002720 boardVndkVersion,
2721 )
2722 productVariants = append(productVariants,
2723 platformVndkVersion,
2724 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002725 )
Jiyong Park2a454122017-10-19 15:59:33 +09002726 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2727 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002728 vendorVariants = append(vendorVariants,
2729 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002730 boardVndkVersion,
2731 )
2732 productVariants = append(productVariants,
2733 platformVndkVersion,
2734 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002735 )
2736 } else if lib, ok := m.linker.(*vndkPrebuiltLibraryDecorator); ok {
Justin Yun71549282017-11-17 12:10:28 +09002737 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2738 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kim64c43952019-08-26 16:52:35 +09002739 vendorVariants = append(vendorVariants, lib.version())
Ivan Lozano52767be2019-10-18 14:49:46 -07002740 } else if m.HasVendorVariant() && !vendorSpecific {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002741 // This will be available in /system, /vendor and /product
2742 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002743 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002744 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002745 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002746 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2747 // code is PLATFORM_VNDK_VERSION.
2748 // On the other hand, vendor_available modules which are not VNDK should
2749 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002750 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002751 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002752 vendorVariants = append(vendorVariants, boardVndkVersion)
2753 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002754 }
Logan Chienf3511742017-10-31 18:04:35 +08002755 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002756 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002757 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002758 } else {
2759 // This is either in /system (or similar: /data), or is a
2760 // modules built with the NDK. Modules built with the NDK
2761 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002762 coreVariantNeeded = true
2763 }
2764
Justin Yun5f7f7e82019-11-18 19:52:14 +09002765 if boardVndkVersion != "" && productVndkVersion != "" {
2766 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2767 // The module has "product_specific: true" that does not create core variant.
2768 coreVariantNeeded = false
2769 productVariants = append(productVariants, productVndkVersion)
2770 }
2771 } else {
2772 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2773 // restriction to use system libs.
2774 // No product variants defined in this case.
2775 productVariants = []string{}
2776 }
2777
Yifan Hong1b3348d2020-01-21 15:53:22 -08002778 if Bool(m.Properties.Ramdisk_available) {
2779 ramdiskVariantNeeded = true
2780 }
2781
2782 if m.ModuleBase.InstallInRamdisk() {
2783 ramdiskVariantNeeded = true
2784 coreVariantNeeded = false
2785 }
2786
Jiyong Parkf9332f12018-02-01 00:54:12 +09002787 if Bool(m.Properties.Recovery_available) {
2788 recoveryVariantNeeded = true
2789 }
2790
2791 if m.ModuleBase.InstallInRecovery() {
2792 recoveryVariantNeeded = true
2793 coreVariantNeeded = false
2794 }
2795
Inseob Kim64c43952019-08-26 16:52:35 +09002796 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002797 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2798 }
2799
2800 for _, variant := range android.FirstUniqueStrings(productVariants) {
2801 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002802 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002803
Yifan Hong1b3348d2020-01-21 15:53:22 -08002804 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002805 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
2806 m.Properties.CoreVariantNeeded = coreVariantNeeded
2807}
2808
2809func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
2810 return c.Properties.CoreVariantNeeded
2811}
2812
Yifan Hong1b3348d2020-01-21 15:53:22 -08002813func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
2814 return c.Properties.RamdiskVariantNeeded
2815}
2816
Colin Cross7228ecd2019-11-18 16:00:16 -08002817func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
2818 return c.Properties.RecoveryVariantNeeded
2819}
2820
2821func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002822 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08002823}
2824
2825func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
2826 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002827 if variant == android.RamdiskVariation {
2828 m.MakeAsPlatform()
2829 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08002830 m.MakeAsPlatform()
2831 squashRecoverySrcs(m)
2832 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002833 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08002834 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
2835 squashVendorSrcs(m)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002836 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
2837 m.Properties.ImageVariationPrefix = ProductVariationPrefix
2838 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
2839 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002840 }
2841}
2842
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002843func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08002844 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002845 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
2846 }
Colin Cross6510f912017-11-29 00:27:14 -08002847 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07002848}
2849
Sasha Smundak2a4549e2018-11-05 16:49:08 -08002850func kytheExtractAllFactory() android.Singleton {
2851 return &kytheExtractAllSingleton{}
2852}
2853
2854type kytheExtractAllSingleton struct {
2855}
2856
2857func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
2858 var xrefTargets android.Paths
2859 ctx.VisitAllModules(func(module android.Module) {
2860 if ccModule, ok := module.(xref); ok {
2861 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
2862 }
2863 })
2864 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
2865 if len(xrefTargets) > 0 {
2866 ctx.Build(pctx, android.BuildParams{
2867 Rule: blueprint.Phony,
2868 Output: android.PathForPhony(ctx, "xref_cxx"),
2869 Inputs: xrefTargets,
2870 //Default: true,
2871 })
2872 }
2873}
2874
Colin Cross06a931b2015-10-28 17:23:31 -07002875var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07002876var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08002877var BoolPtr = proptools.BoolPtr
2878var String = proptools.String
2879var StringPtr = proptools.StringPtr