blob: 794adf1346f8e84f2109585a8a7e1776f7942730 [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) {
Colin Cross82e192c2020-02-19 16:54:04 -080045 ctx.BottomUp("sdk", sdkMutator).Parallel()
Inseob Kim64c43952019-08-26 16:52:35 +090046 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070047 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090048 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010049 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090050 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070051 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090052 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090053 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
54 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070055 })
Colin Cross16b23492016-01-06 14:41:07 -080056
Paul Duffin036e7002019-12-19 19:16:28 +000057 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070058 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
59 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080060
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070061 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
62 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
63
Mitch Phillipsbfeade62019-05-01 14:42:05 -070064 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
65 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
66
Jiyong Park1d1119f2019-07-29 21:27:18 +090067 // cfi mutator shouldn't run before sanitizers that return true for
68 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000069 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
70 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
71
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080072 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
73 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
74
Colin Cross1e676be2016-10-12 14:38:15 -070075 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
76 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080077
Colin Cross0b908332019-06-19 23:00:20 -070078 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090079 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080080
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080081 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080082 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070083
84 ctx.TopDown("lto_deps", ltoDepsMutator)
85 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090086
87 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070088 })
Colin Crossb98c8b02016-07-29 13:44:28 -070089
Sasha Smundak2a4549e2018-11-05 16:49:08 -080090 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070091}
92
Colin Crossca860ac2016-01-04 14:34:37 -080093type Deps struct {
94 SharedLibs, LateSharedLibs []string
95 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080096 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080097 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070098
Peter Collingbournedc4f9862020-02-12 17:13:25 -080099 StaticUnwinderIfLegacy bool
100
Colin Cross5950f382016-12-13 12:50:57 -0800101 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700102
Colin Cross81413472016-04-11 14:37:39 -0700103 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700104
Dan Willemsenb40aab62016-04-20 14:21:14 -0700105 GeneratedSources []string
106 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900107 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700108
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700109 ReexportGeneratedHeaders []string
110
Colin Cross97ba0732015-03-23 17:50:24 -0700111 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700112
113 // Used for host bionic
114 LinkerFlagsFile string
115 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700116}
117
Colin Crossca860ac2016-01-04 14:34:37 -0800118type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700119 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900120 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700121 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900122 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700123 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700124 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700125
Colin Cross26c34ed2016-09-30 17:10:16 -0700126 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700127 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800128 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700129 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700130
Colin Cross26c34ed2016-09-30 17:10:16 -0700131 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700132 GeneratedSources android.Paths
133 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900134 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700135
Inseob Kimd110f872019-12-06 13:15:38 +0900136 Flags []string
137 IncludeDirs android.Paths
138 SystemIncludeDirs android.Paths
139 ReexportedDirs android.Paths
140 ReexportedSystemDirs android.Paths
141 ReexportedFlags []string
142 ReexportedGeneratedHeaders android.Paths
143 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700144
Colin Cross26c34ed2016-09-30 17:10:16 -0700145 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700146 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700147
148 // Path to the file container flags to use with the linker
149 LinkerFlagsFile android.OptionalPath
150
151 // Path to the dynamic linker binary
152 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700153}
154
Colin Cross4af21ed2019-11-04 09:37:55 -0800155// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
156// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
157// command line so they can be overridden by the local module flags).
158type LocalOrGlobalFlags struct {
159 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700160 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800161 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700162 CFlags []string // Flags that apply to C and C++ source files
163 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
164 ConlyFlags []string // Flags that apply to C source files
165 CppFlags []string // Flags that apply to C++ source files
166 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700167 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800168}
169
170type Flags struct {
171 Local LocalOrGlobalFlags
172 Global LocalOrGlobalFlags
173
174 aidlFlags []string // Flags that apply to aidl source files
175 rsFlags []string // Flags that apply to renderscript source files
176 libFlags []string // Flags to add libraries early to the link order
177 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
178 TidyFlags []string // Flags that apply to clang-tidy
179 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700180
Colin Crossc3199482017-03-30 15:03:04 -0700181 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800182 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700183 SystemIncludeFlags []string
184
Colin Crossb98c8b02016-07-29 13:44:28 -0700185 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700186 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800187 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800188 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800189 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800190
191 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800192 DynamicLinker string
193
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700194 CFlagsDeps android.Paths // Files depended on by compiler flags
195 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800196
Dan Willemsen98ab3112019-08-27 21:20:40 -0700197 AssemblerWithCpp bool
198 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800199
Colin Cross19878da2019-03-28 14:45:07 -0700200 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700201 protoC bool // Whether to use C instead of C++
202 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700203
204 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700205}
206
Colin Crossca860ac2016-01-04 14:34:37 -0800207// Properties used to compile all C or C++ modules
208type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700209 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800210 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700211
Colin Cross82e192c2020-02-19 16:54:04 -0800212 // Minimum sdk version supported when compiling against the ndk. Setting this property causes
213 // two variants to be built, one for the platform and one for apps.
Nan Zhang0007d812017-11-07 10:57:05 -0800214 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700215
Colin Cross82e192c2020-02-19 16:54:04 -0800216 // If true, always create an sdk variant and don't create a platform variant.
217 Sdk_variant_only *bool
218
Jiyong Parkde866cb2018-12-07 23:08:36 +0900219 AndroidMkSharedLibs []string `blueprint:"mutated"`
220 AndroidMkStaticLibs []string `blueprint:"mutated"`
221 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
222 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
223 HideFromMake bool `blueprint:"mutated"`
224 PreventInstall bool `blueprint:"mutated"`
225 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700226
Justin Yun5f7f7e82019-11-18 19:52:14 +0900227 ImageVariationPrefix string `blueprint:"mutated"`
228 VndkVersion string `blueprint:"mutated"`
229 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800230
231 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
232 // file
233 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900234
Yifan Hong1b3348d2020-01-21 15:53:22 -0800235 // Make this module available when building for ramdisk
236 Ramdisk_available *bool
237
Jiyong Parkf9332f12018-02-01 00:54:12 +0900238 // Make this module available when building for recovery
239 Recovery_available *bool
240
Colin Crossae6c5202019-11-20 13:35:50 -0800241 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800242 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800243 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800244 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900245 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900246
247 // Allows this module to use non-APEX version of libraries. Useful
248 // for building binaries that are started before APEXes are activated.
249 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900250
251 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
252 // see soong/cc/config/vndk.go
253 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900254
255 // Used by vendor snapshot to record dependencies from snapshot modules.
256 SnapshotSharedLibs []string `blueprint:"mutated"`
257 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffin0cb37b92020-03-04 14:52:46 +0000258
259 Installable *bool
Colin Cross82e192c2020-02-19 16:54:04 -0800260
261 // Set by factories of module types that can only be referenced from variants compiled against
262 // the SDK.
263 AlwaysSdk bool `blueprint:"mutated"`
264
265 // Variant is an SDK variant created by sdkMutator
266 IsSdkVariant bool `blueprint:"mutated"`
267 // Set when both SDK and platform variants are exported to Make to trigger renaming the SDK
268 // variant to have a ".sdk" suffix.
269 SdkAndPlatformVariantVisibleToMake bool `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700270}
271
272type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900273 // whether this module should be allowed to be directly depended by other
274 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900275 // In addition, this module should be allowed to be directly depended by
276 // product modules with `product_specific: true`.
277 // If set to true, three variants will be built separately, one like
278 // normal, another limited to the set of libraries and headers
279 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700280 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900281 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700282 // so it shouldn't have any unversioned runtime dependencies, or
283 // make assumptions about the system that may not be true in the
284 // future.
285 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900286 // If set to false, this module becomes inaccessible from /vendor or /product
287 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900288 //
289 // Default value is true when vndk: {enabled: true} or vendor: true.
290 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700291 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900292 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700293 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900294
295 // whether this module is capable of being loaded with other instance
296 // (possibly an older version) of the same module in the same process.
297 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
298 // can be double loaded in a vendor process if the library is also a
299 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
300 // explicitly marked as `double_loadable: true` by the owner, or the dependency
301 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
302 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800303}
304
Colin Crossca860ac2016-01-04 14:34:37 -0800305type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800306 static() bool
307 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900308 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700309 toolchain() config.Toolchain
Jooyung Hanccce2f22020-03-07 03:45:53 +0900310 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700311 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800312 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700313 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800314 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900315 isLlndk(config android.Config) bool
316 isLlndkPublic(config android.Config) bool
317 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900318 isVndk() bool
319 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800320 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900321 inProduct() bool
322 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800323 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900324 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800325 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700326 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700327 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800328 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800329 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800330 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800331 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800332 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900333 apexName() string
Jooyung Hanccce2f22020-03-07 03:45:53 +0900334 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900335 hasStubsVariants() bool
336 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900337 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800338 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700339 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800340}
341
342type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700343 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800344 ModuleContextIntf
345}
346
347type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700348 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800349 ModuleContextIntf
350}
351
Colin Cross37047f12016-12-13 17:06:13 -0800352type DepsContext interface {
353 android.BottomUpMutatorContext
354 ModuleContextIntf
355}
356
Colin Crossca860ac2016-01-04 14:34:37 -0800357type feature interface {
358 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800359 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800360 flags(ctx ModuleContext, flags Flags) Flags
361 props() []interface{}
362}
363
364type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700365 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800366 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800367 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700368 compilerProps() []interface{}
369
Colin Cross76fada02016-07-27 10:31:13 -0700370 appendCflags([]string)
371 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700372 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800373}
374
375type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700376 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800377 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700378 linkerFlags(ctx ModuleContext, flags Flags) Flags
379 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800380 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700381
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700382 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700383 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900384 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700385
386 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900387 coverageOutputFilePath() android.OptionalPath
Paul Duffin13f02712020-03-06 12:30:43 +0000388
389 // Get the deps that have been explicitly specified in the properties.
390 // Only updates the
391 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
392}
393
394type specifiedDeps struct {
395 sharedLibs []string
396 systemSharedLibs []string
Colin Crossca860ac2016-01-04 14:34:37 -0800397}
398
399type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700400 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700401 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000402 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800403 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700404 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700405 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900406 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800407}
408
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800409type xref interface {
410 XrefCcFiles() android.Paths
411}
412
Colin Crossc99deeb2016-04-11 15:06:20 -0700413var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700414 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
415 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
416 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
417 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
418 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800419 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700420 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
421 headerDepTag = DependencyTag{Name: "header", Library: true}
422 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
423 genSourceDepTag = DependencyTag{Name: "gen source"}
424 genHeaderDepTag = DependencyTag{Name: "gen header"}
425 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
426 objDepTag = DependencyTag{Name: "obj"}
427 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
428 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
429 reuseObjTag = DependencyTag{Name: "reuse objects"}
430 staticVariantTag = DependencyTag{Name: "static variant"}
431 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
432 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
433 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
434 runtimeDepTag = DependencyTag{Name: "runtime lib"}
435 coverageDepTag = DependencyTag{Name: "coverage"}
436 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700437)
438
Roland Levillainf89cd092019-07-29 16:22:59 +0100439func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700440 ccDepTag, ok := depTag.(DependencyTag)
441 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100442}
443
444func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700445 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100446 return ok && ccDepTag == runtimeDepTag
447}
448
449func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700450 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100451 return ok && ccDepTag == testPerSrcDepTag
452}
453
Colin Crossca860ac2016-01-04 14:34:37 -0800454// Module contains the properties and members used by all C/C++ module types, and implements
455// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
456// to construct the output file. Behavior can be customized with a Customizer interface
457type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700458 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700459 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900460 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900461 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700462
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700463 Properties BaseProperties
464 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700465
Colin Crossca860ac2016-01-04 14:34:37 -0800466 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700467 hod android.HostOrDeviceSupported
468 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700469
Paul Duffina0843f62019-12-13 19:50:38 +0000470 // Allowable SdkMemberTypes of this module type.
471 sdkMemberTypes []android.SdkMemberType
472
Colin Crossca860ac2016-01-04 14:34:37 -0800473 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700474 features []feature
475 compiler compiler
476 linker linker
477 installer installer
478 stl *stl
479 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800480 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800481 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900482 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700483 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700484 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800485
Colin Cross635c3b02016-05-18 15:37:25 -0700486 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800487
Colin Crossb98c8b02016-07-29 13:44:28 -0700488 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700489
490 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800491
492 // Flags used to compile this module
493 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700494
495 // 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 -0800496 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700497 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800498 depsInLinkOrder android.Paths
499
500 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700501 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900502
503 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800504 // Kythe (source file indexer) paths for this compilation module
505 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700506}
507
Ivan Lozano52767be2019-10-18 14:49:46 -0700508func (c *Module) Toc() android.OptionalPath {
509 if c.linker != nil {
510 if library, ok := c.linker.(libraryInterface); ok {
511 return library.toc()
512 }
513 }
514 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
515}
516
517func (c *Module) ApiLevel() string {
518 if c.linker != nil {
519 if stub, ok := c.linker.(*stubDecorator); ok {
520 return stub.properties.ApiLevel
521 }
522 }
523 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
524}
525
526func (c *Module) Static() bool {
527 if c.linker != nil {
528 if library, ok := c.linker.(libraryInterface); ok {
529 return library.static()
530 }
531 }
532 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
533}
534
535func (c *Module) Shared() bool {
536 if c.linker != nil {
537 if library, ok := c.linker.(libraryInterface); ok {
538 return library.shared()
539 }
540 }
541 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
542}
543
544func (c *Module) SelectedStl() string {
Colin Cross82e192c2020-02-19 16:54:04 -0800545 if c.stl != nil {
546 return c.stl.Properties.SelectedStl
547 }
548 return ""
Ivan Lozano52767be2019-10-18 14:49:46 -0700549}
550
551func (c *Module) ToolchainLibrary() bool {
552 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
553 return true
554 }
555 return false
556}
557
558func (c *Module) NdkPrebuiltStl() bool {
559 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
560 return true
561 }
562 return false
563}
564
565func (c *Module) StubDecorator() bool {
566 if _, ok := c.linker.(*stubDecorator); ok {
567 return true
568 }
569 return false
570}
571
572func (c *Module) SdkVersion() string {
573 return String(c.Properties.Sdk_version)
574}
575
Colin Cross82e192c2020-02-19 16:54:04 -0800576func (c *Module) AlwaysSdk() bool {
577 return c.Properties.AlwaysSdk || Bool(c.Properties.Sdk_variant_only)
578}
579
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800580func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700581 if c.linker != nil {
582 if library, ok := c.linker.(exportedFlagsProducer); ok {
583 return library.exportedDirs()
584 }
585 }
586 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
587}
588
589func (c *Module) HasStaticVariant() bool {
590 if c.staticVariant != nil {
591 return true
592 }
593 return false
594}
595
596func (c *Module) GetStaticVariant() LinkableInterface {
597 return c.staticVariant
598}
599
600func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
601 c.depsInLinkOrder = depsInLinkOrder
602}
603
604func (c *Module) GetDepsInLinkOrder() []android.Path {
605 return c.depsInLinkOrder
606}
607
608func (c *Module) StubsVersions() []string {
609 if c.linker != nil {
610 if library, ok := c.linker.(*libraryDecorator); ok {
611 return library.Properties.Stubs.Versions
612 }
613 }
614 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
615}
616
617func (c *Module) CcLibrary() bool {
618 if c.linker != nil {
619 if _, ok := c.linker.(*libraryDecorator); ok {
620 return true
621 }
622 }
623 return false
624}
625
626func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700627 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700628 return true
629 }
630 return false
631}
632
Ivan Lozano2b262972019-11-21 12:30:50 -0800633func (c *Module) NonCcVariants() bool {
634 return false
635}
636
Ivan Lozano183a3212019-10-18 14:18:45 -0700637func (c *Module) SetBuildStubs() {
638 if c.linker != nil {
639 if library, ok := c.linker.(*libraryDecorator); ok {
640 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700641 c.Properties.HideFromMake = true
642 c.sanitize = nil
643 c.stl = nil
644 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700645 return
646 }
647 }
648 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
649}
650
Ivan Lozano52767be2019-10-18 14:49:46 -0700651func (c *Module) BuildStubs() bool {
652 if c.linker != nil {
653 if library, ok := c.linker.(*libraryDecorator); ok {
654 return library.buildStubs()
655 }
656 }
657 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
658}
659
Ivan Lozano183a3212019-10-18 14:18:45 -0700660func (c *Module) SetStubsVersions(version string) {
661 if c.linker != nil {
662 if library, ok := c.linker.(*libraryDecorator); ok {
663 library.MutatedProperties.StubsVersion = version
664 return
665 }
666 }
667 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
668}
669
Jooyung Han03b51852020-02-26 22:45:42 +0900670func (c *Module) StubsVersion() string {
671 if c.linker != nil {
672 if library, ok := c.linker.(*libraryDecorator); ok {
673 return library.MutatedProperties.StubsVersion
674 }
675 }
676 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
677}
678
Ivan Lozano183a3212019-10-18 14:18:45 -0700679func (c *Module) SetStatic() {
680 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700681 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700682 library.setStatic()
683 return
684 }
685 }
686 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
687}
688
689func (c *Module) SetShared() {
690 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700691 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700692 library.setShared()
693 return
694 }
695 }
696 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
697}
698
699func (c *Module) BuildStaticVariant() bool {
700 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700701 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700702 return library.buildStatic()
703 }
704 }
705 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
706}
707
708func (c *Module) BuildSharedVariant() bool {
709 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700710 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700711 return library.buildShared()
712 }
713 }
714 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
715}
716
717func (c *Module) Module() android.Module {
718 return c
719}
720
Jiyong Parkc20eee32018-09-05 22:36:17 +0900721func (c *Module) OutputFile() android.OptionalPath {
722 return c.outputFile
723}
724
Ivan Lozano183a3212019-10-18 14:18:45 -0700725var _ LinkableInterface = (*Module)(nil)
726
Jiyong Park719b4462019-01-13 00:39:51 +0900727func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900728 if c.linker != nil {
729 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900730 }
731 return nil
732}
733
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900734func (c *Module) CoverageOutputFile() android.OptionalPath {
735 if c.linker != nil {
736 return c.linker.coverageOutputFilePath()
737 }
738 return android.OptionalPath{}
739}
740
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900741func (c *Module) RelativeInstallPath() string {
742 if c.installer != nil {
743 return c.installer.relativeInstallPath()
744 }
745 return ""
746}
747
Jooyung Han344d5432019-08-23 11:17:39 +0900748func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900749 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900750}
751
Colin Cross36242852017-06-23 15:06:31 -0700752func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700753 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800754 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700755 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800756 }
757 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700758 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800759 }
760 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700761 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800762 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700763 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700764 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700765 }
Colin Cross16b23492016-01-06 14:41:07 -0800766 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700767 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800768 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800769 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700770 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800771 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800772 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700773 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800774 }
Justin Yun8effde42017-06-23 19:24:43 +0900775 if c.vndkdep != nil {
776 c.AddProperties(c.vndkdep.props()...)
777 }
Stephen Craneba090d12017-05-09 15:44:35 -0700778 if c.lto != nil {
779 c.AddProperties(c.lto.props()...)
780 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700781 if c.pgo != nil {
782 c.AddProperties(c.pgo.props()...)
783 }
Colin Crossca860ac2016-01-04 14:34:37 -0800784 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700785 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800786 }
Colin Crossc472d572015-03-17 15:06:21 -0700787
Colin Crossa9d8bee2018-10-02 13:59:46 -0700788 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
789 switch class {
790 case android.Device:
791 return ctx.Config().DevicePrefer32BitExecutables()
792 case android.HostCross:
793 // Windows builds always prefer 32-bit
794 return true
795 default:
796 return false
797 }
798 })
Colin Cross36242852017-06-23 15:06:31 -0700799 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900800 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900801 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900802 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900803
Colin Cross36242852017-06-23 15:06:31 -0700804 return c
Colin Crossc472d572015-03-17 15:06:21 -0700805}
806
Colin Crossb916a382016-07-29 17:28:03 -0700807// Returns true for dependency roots (binaries)
808// TODO(ccross): also handle dlopenable libraries
809func (c *Module) isDependencyRoot() bool {
810 if root, ok := c.linker.(interface {
811 isDependencyRoot() bool
812 }); ok {
813 return root.isDependencyRoot()
814 }
815 return false
816}
817
Justin Yun5f7f7e82019-11-18 19:52:14 +0900818// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
819// "product" and "vendor" variant modules return true for this function.
820// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
821// "soc_specific: true" and more vendor installed modules are included here.
822// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
823// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700824func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900825 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700826}
827
Colin Cross82e192c2020-02-19 16:54:04 -0800828func (c *Module) canUseSdk() bool {
829 return c.Os() == android.Android && !c.UseVndk() && !c.InRamdisk() && !c.InRecovery()
830}
831
832func (c *Module) UseSdk() bool {
833 if c.canUseSdk() {
834 return String(c.Properties.Sdk_version) != ""
835 }
836 return false
837}
838
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800839func (c *Module) isCoverageVariant() bool {
840 return c.coverage.Properties.IsCoverageVariant
841}
842
Peter Collingbournead84f972019-12-17 16:46:18 -0800843func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800844 return inList(c.Name(), ndkMigratedLibs)
845}
846
Inseob Kim9516ee92019-05-09 10:56:13 +0900847func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800848 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900849 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800850}
851
Inseob Kim9516ee92019-05-09 10:56:13 +0900852func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800853 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900854 name := c.BaseModuleName()
855 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800856}
857
Inseob Kim9516ee92019-05-09 10:56:13 +0900858func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800859 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900860 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800861}
862
Ivan Lozano52767be2019-10-18 14:49:46 -0700863func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800864 if vndkdep := c.vndkdep; vndkdep != nil {
865 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900866 }
867 return false
868}
869
Yi Kong7e53c572018-02-14 18:16:12 +0800870func (c *Module) isPgoCompile() bool {
871 if pgo := c.pgo; pgo != nil {
872 return pgo.Properties.PgoCompile
873 }
874 return false
875}
876
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800877func (c *Module) isNDKStubLibrary() bool {
878 if _, ok := c.compiler.(*stubDecorator); ok {
879 return true
880 }
881 return false
882}
883
Logan Chienf3511742017-10-31 18:04:35 +0800884func (c *Module) isVndkSp() bool {
885 if vndkdep := c.vndkdep; vndkdep != nil {
886 return vndkdep.isVndkSp()
887 }
888 return false
889}
890
891func (c *Module) isVndkExt() bool {
892 if vndkdep := c.vndkdep; vndkdep != nil {
893 return vndkdep.isVndkExt()
894 }
895 return false
896}
897
Ivan Lozano52767be2019-10-18 14:49:46 -0700898func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900899 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800900}
901
Logan Chienf3511742017-10-31 18:04:35 +0800902func (c *Module) getVndkExtendsModuleName() string {
903 if vndkdep := c.vndkdep; vndkdep != nil {
904 return vndkdep.getVndkExtendsModuleName()
905 }
906 return ""
907}
908
Justin Yun5f7f7e82019-11-18 19:52:14 +0900909// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900910// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700911func (c *Module) HasVendorVariant() bool {
912 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900913}
914
Justin Yun5f7f7e82019-11-18 19:52:14 +0900915const (
916 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
917 // against the VNDK.
918 VendorVariationPrefix = "vendor."
919
920 // ProductVariationPrefix is the variant prefix used for /product code that compiles
921 // against the VNDK.
922 ProductVariationPrefix = "product."
923)
924
925// Returns true if the module is "product" variant. Usually these modules are installed in /product
926func (c *Module) inProduct() bool {
927 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
928}
929
930// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
931func (c *Module) inVendor() bool {
932 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
933}
934
Yifan Hong1b3348d2020-01-21 15:53:22 -0800935func (c *Module) InRamdisk() bool {
936 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
937}
938
Ivan Lozano52767be2019-10-18 14:49:46 -0700939func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800940 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900941}
942
Yifan Hong1b3348d2020-01-21 15:53:22 -0800943func (c *Module) OnlyInRamdisk() bool {
944 return c.ModuleBase.InstallInRamdisk()
945}
946
Ivan Lozano52767be2019-10-18 14:49:46 -0700947func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900948 return c.ModuleBase.InstallInRecovery()
949}
950
Jiyong Park25fc6a92018-11-18 18:02:45 +0900951func (c *Module) IsStubs() bool {
952 if library, ok := c.linker.(*libraryDecorator); ok {
953 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900954 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
955 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900956 }
957 return false
958}
959
960func (c *Module) HasStubsVariants() bool {
961 if library, ok := c.linker.(*libraryDecorator); ok {
962 return len(library.Properties.Stubs.Versions) > 0
963 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700964 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
965 return len(library.Properties.Stubs.Versions) > 0
966 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900967 return false
968}
969
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900970func (c *Module) bootstrap() bool {
971 return Bool(c.Properties.Bootstrap)
972}
973
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700974func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700975 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
976 if c.Target().NativeBridge == android.NativeBridgeEnabled {
977 return false
978 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700979 return c.linker != nil && c.linker.nativeCoverage()
980}
981
Inseob Kim8471cda2019-11-15 09:59:12 +0900982func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900983 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
984 return true
985 }
986 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
987 return true
988 }
989 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
990 return true
991 }
992 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900993}
994
Jiyong Park73c54ee2019-10-22 20:31:18 +0900995func (c *Module) ExportedIncludeDirs() android.Paths {
996 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
997 return flagsProducer.exportedDirs()
998 }
Jiyong Park232e7852019-11-04 12:23:40 +0900999 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001000}
1001
1002func (c *Module) ExportedSystemIncludeDirs() android.Paths {
1003 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1004 return flagsProducer.exportedSystemDirs()
1005 }
Jiyong Park232e7852019-11-04 12:23:40 +09001006 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001007}
1008
1009func (c *Module) ExportedFlags() []string {
1010 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1011 return flagsProducer.exportedFlags()
1012 }
Jiyong Park232e7852019-11-04 12:23:40 +09001013 return nil
1014}
1015
1016func (c *Module) ExportedDeps() android.Paths {
1017 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1018 return flagsProducer.exportedDeps()
1019 }
1020 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +09001021}
1022
Inseob Kimd110f872019-12-06 13:15:38 +09001023func (c *Module) ExportedGeneratedHeaders() android.Paths {
1024 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1025 return flagsProducer.exportedGeneratedHeaders()
1026 }
1027 return nil
1028}
1029
Jiyong Parkf1194352019-02-25 11:05:47 +09001030func isBionic(name string) bool {
1031 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001032 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001033 return true
1034 }
1035 return false
1036}
1037
Martin Stjernholm279de572019-09-10 23:18:20 +01001038func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001039 if name == "libclang_rt.hwasan-aarch64-android" {
1040 return inList("hwaddress", config.SanitizeDevice())
1041 }
1042 return isBionic(name)
1043}
1044
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001045func (c *Module) XrefCcFiles() android.Paths {
1046 return c.kytheFiles
1047}
1048
Colin Crossca860ac2016-01-04 14:34:37 -08001049type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001050 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001051 moduleContextImpl
1052}
1053
Colin Cross37047f12016-12-13 17:06:13 -08001054type depsContext struct {
1055 android.BottomUpMutatorContext
1056 moduleContextImpl
1057}
1058
Colin Crossca860ac2016-01-04 14:34:37 -08001059type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001060 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001061 moduleContextImpl
1062}
1063
Justin Yun5f7f7e82019-11-18 19:52:14 +09001064func (ctx *moduleContext) ProductSpecific() bool {
1065 return ctx.ModuleContext.ProductSpecific() ||
1066 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1067}
1068
Jiyong Park2db76922017-11-08 16:03:48 +09001069func (ctx *moduleContext) SocSpecific() bool {
1070 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001071 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001072}
1073
Colin Crossca860ac2016-01-04 14:34:37 -08001074type moduleContextImpl struct {
1075 mod *Module
1076 ctx BaseModuleContext
1077}
1078
Colin Crossb98c8b02016-07-29 13:44:28 -07001079func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001080 return ctx.mod.toolchain(ctx.ctx)
1081}
1082
1083func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001084 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001085}
1086
1087func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001088 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001089}
1090
Jiyong Park1d1119f2019-07-29 21:27:18 +09001091func (ctx *moduleContextImpl) header() bool {
1092 return ctx.mod.header()
1093}
1094
Jooyung Hanccce2f22020-03-07 03:45:53 +09001095func (ctx *moduleContextImpl) canUseSdk() bool {
Colin Cross82e192c2020-02-19 16:54:04 -08001096 return ctx.mod.canUseSdk()
Jooyung Hanccce2f22020-03-07 03:45:53 +09001097}
1098
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001099func (ctx *moduleContextImpl) useSdk() bool {
Colin Cross82e192c2020-02-19 16:54:04 -08001100 return ctx.mod.UseSdk()
Colin Crossca860ac2016-01-04 14:34:37 -08001101}
1102
1103func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001104 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001105 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001106 vndkVer := ctx.mod.VndkVersion()
1107 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1108 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001109 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001110 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001111 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001112 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001113 }
1114 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001115}
1116
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001117func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001118 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001119}
Justin Yun8effde42017-06-23 19:24:43 +09001120
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001121func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001122 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001123}
1124
Inseob Kim9516ee92019-05-09 10:56:13 +09001125func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1126 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001127}
1128
Inseob Kim9516ee92019-05-09 10:56:13 +09001129func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1130 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001131}
1132
Inseob Kim9516ee92019-05-09 10:56:13 +09001133func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1134 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001135}
1136
Logan Chienf3511742017-10-31 18:04:35 +08001137func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001138 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001139}
1140
Yi Kong7e53c572018-02-14 18:16:12 +08001141func (ctx *moduleContextImpl) isPgoCompile() bool {
1142 return ctx.mod.isPgoCompile()
1143}
1144
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001145func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1146 return ctx.mod.isNDKStubLibrary()
1147}
1148
Justin Yun8effde42017-06-23 19:24:43 +09001149func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001150 return ctx.mod.isVndkSp()
1151}
1152
1153func (ctx *moduleContextImpl) isVndkExt() bool {
1154 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001155}
1156
Vic Yangefd249e2018-11-12 20:19:56 -08001157func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001158 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001159}
1160
Justin Yun5f7f7e82019-11-18 19:52:14 +09001161func (ctx *moduleContextImpl) inProduct() bool {
1162 return ctx.mod.inProduct()
1163}
1164
1165func (ctx *moduleContextImpl) inVendor() bool {
1166 return ctx.mod.inVendor()
1167}
1168
Yifan Hong1b3348d2020-01-21 15:53:22 -08001169func (ctx *moduleContextImpl) inRamdisk() bool {
1170 return ctx.mod.InRamdisk()
1171}
1172
Jiyong Parkf9332f12018-02-01 00:54:12 +09001173func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001174 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001175}
1176
Logan Chien2f2b8902018-07-10 15:01:19 +08001177// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001178func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001179 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1180 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001181 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001182
1183 if ctx.ctx.Fuchsia() {
1184 return false
1185 }
1186
Logan Chien2f2b8902018-07-10 15:01:19 +08001187 if sanitize := ctx.mod.sanitize; sanitize != nil {
1188 if !sanitize.isVariantOnProductionDevice() {
1189 return false
1190 }
1191 }
1192 if !ctx.ctx.Device() {
1193 // Host modules do not need ABI dumps.
1194 return false
1195 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001196 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001197 // Stubs do not need ABI dumps.
1198 return false
1199 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001200 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001201}
1202
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001203func (ctx *moduleContextImpl) selectedStl() string {
1204 if stl := ctx.mod.stl; stl != nil {
1205 return stl.Properties.SelectedStl
1206 }
1207 return ""
1208}
1209
Ivan Lozanobd721262018-11-27 14:33:03 -08001210func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1211 return ctx.mod.linker.useClangLld(actx)
1212}
1213
Colin Crossce75d2c2016-10-06 16:12:58 -07001214func (ctx *moduleContextImpl) baseModuleName() string {
1215 return ctx.mod.ModuleBase.BaseModuleName()
1216}
1217
Logan Chienf3511742017-10-31 18:04:35 +08001218func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1219 return ctx.mod.getVndkExtendsModuleName()
1220}
1221
Logan Chiene274fc92019-12-03 11:18:32 -08001222func (ctx *moduleContextImpl) isForPlatform() bool {
1223 return ctx.mod.IsForPlatform()
1224}
1225
Jiyong Park58e364a2019-01-19 19:24:06 +09001226func (ctx *moduleContextImpl) apexName() string {
1227 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001228}
1229
Jooyung Hanccce2f22020-03-07 03:45:53 +09001230func (ctx *moduleContextImpl) apexSdkVersion() int {
1231 return ctx.mod.ApexProperties.Info.MinSdkVersion
1232}
1233
Jiyong Parkb0788572018-12-20 22:10:17 +09001234func (ctx *moduleContextImpl) hasStubsVariants() bool {
1235 return ctx.mod.HasStubsVariants()
1236}
1237
1238func (ctx *moduleContextImpl) isStubs() bool {
1239 return ctx.mod.IsStubs()
1240}
1241
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001242func (ctx *moduleContextImpl) bootstrap() bool {
1243 return ctx.mod.bootstrap()
1244}
1245
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001246func (ctx *moduleContextImpl) nativeCoverage() bool {
1247 return ctx.mod.nativeCoverage()
1248}
1249
Colin Cross635c3b02016-05-18 15:37:25 -07001250func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001251 return &Module{
1252 hod: hod,
1253 multilib: multilib,
1254 }
1255}
1256
Colin Cross635c3b02016-05-18 15:37:25 -07001257func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001258 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001259 module.features = []feature{
1260 &tidyFeature{},
1261 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001262 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001263 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001264 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001265 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001266 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001267 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001268 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001269 return module
1270}
1271
Colin Crossce75d2c2016-10-06 16:12:58 -07001272func (c *Module) Prebuilt() *android.Prebuilt {
1273 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1274 return p.prebuilt()
1275 }
1276 return nil
1277}
1278
1279func (c *Module) Name() string {
1280 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001281 if p, ok := c.linker.(interface {
1282 Name(string) string
1283 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001284 name = p.Name(name)
1285 }
1286 return name
1287}
1288
Alex Light3d673592019-01-18 14:37:31 -08001289func (c *Module) Symlinks() []string {
1290 if p, ok := c.installer.(interface {
1291 symlinkList() []string
1292 }); ok {
1293 return p.symlinkList()
1294 }
1295 return nil
1296}
1297
Jeff Gaston294356f2017-09-27 17:05:30 -07001298// orderDeps reorders dependencies into a list such that if module A depends on B, then
1299// A will precede B in the resultant list.
1300// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001301// Note that directSharedDeps should be the analogous static library for each shared lib dep
1302func 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 -07001303 // If A depends on B, then
1304 // Every list containing A will also contain B later in the list
1305 // So, after concatenating all lists, the final instance of B will have come from the same
1306 // original list as the final instance of A
1307 // So, the final instance of B will be later in the concatenation than the final A
1308 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1309 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001310 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001311 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001312 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1313 }
1314 for _, dep := range directSharedDeps {
1315 orderedAllDeps = append(orderedAllDeps, dep)
1316 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001317 }
1318
Colin Crossb6715442017-10-24 11:13:31 -07001319 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001320
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001321 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001322 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001323 // resultant list to only what the caller has chosen to include in directStaticDeps
1324 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001325
1326 return orderedAllDeps, orderedDeclaredDeps
1327}
1328
Ivan Lozano183a3212019-10-18 14:18:45 -07001329func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001330 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001331 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001332 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1333 staticDepFiles := []android.Path{}
1334 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001335 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1336 if dep.OutputFile().Valid() {
1337 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1338 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1339 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001340 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001341 sharedDepFiles := []android.Path{}
1342 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001343 if sharedDep.HasStaticVariant() {
1344 staticAnalogue := sharedDep.GetStaticVariant()
1345 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1346 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001347 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001348 }
1349
1350 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001351 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1352 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001353
1354 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001355}
1356
Roland Levillainf89cd092019-07-29 16:22:59 +01001357func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1358 test, ok := c.linker.(testPerSrc)
1359 return ok && test.isAllTestsVariation()
1360}
1361
Justin Yun5f7f7e82019-11-18 19:52:14 +09001362func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1363 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1364 // "current", it will append the VNDK version to the name suffix.
1365 var vndkVersion string
1366 var nameSuffix string
1367 if c.inProduct() {
1368 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1369 nameSuffix = productSuffix
1370 } else {
1371 vndkVersion = ctx.DeviceConfig().VndkVersion()
1372 nameSuffix = vendorSuffix
1373 }
1374 if vndkVersion == "current" {
1375 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1376 }
1377 if c.Properties.VndkVersion != vndkVersion {
1378 // add version suffix only if the module is using different vndk version than the
1379 // version in product or vendor partition.
1380 nameSuffix += "." + c.Properties.VndkVersion
1381 }
1382 return nameSuffix
1383}
1384
Colin Cross635c3b02016-05-18 15:37:25 -07001385func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001386 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001387 //
1388 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1389 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1390 // module and return early, as this module does not produce an output file per se.
1391 if c.IsTestPerSrcAllTestsVariation() {
1392 c.outputFile = android.OptionalPath{}
1393 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001394 }
1395
Jooyung Han38002912019-05-16 04:01:54 +09001396 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001397
Inseob Kim64c43952019-08-26 16:52:35 +09001398 c.Properties.SubName = ""
1399
1400 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1401 c.Properties.SubName += nativeBridgeSuffix
1402 }
1403
Justin Yun5f7f7e82019-11-18 19:52:14 +09001404 _, llndk := c.linker.(*llndkStubDecorator)
1405 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1406 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1407 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1408 // added for product variant only when we have vendor and product variants with core
1409 // variant. The suffix is not added for vendor-only or product-only module.
1410 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1411 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001412 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1413 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1414 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001415 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1416 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001417 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001418 c.Properties.SubName += recoverySuffix
Colin Cross82e192c2020-02-19 16:54:04 -08001419 } else if c.Properties.IsSdkVariant && c.Properties.SdkAndPlatformVariantVisibleToMake {
1420 c.Properties.SubName += sdkSuffix
Inseob Kim64c43952019-08-26 16:52:35 +09001421 }
1422
Colin Crossca860ac2016-01-04 14:34:37 -08001423 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001424 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001425 moduleContextImpl: moduleContextImpl{
1426 mod: c,
1427 },
1428 }
1429 ctx.ctx = ctx
1430
Colin Crossf18e1102017-11-16 14:33:08 -08001431 deps := c.depsToPaths(ctx)
1432 if ctx.Failed() {
1433 return
1434 }
1435
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001436 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1437 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1438 }
1439
Colin Crossca860ac2016-01-04 14:34:37 -08001440 flags := Flags{
1441 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001442 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001443 }
Colin Crossca860ac2016-01-04 14:34:37 -08001444 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001445 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001446 }
1447 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001448 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001449 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001450 if c.stl != nil {
1451 flags = c.stl.flags(ctx, flags)
1452 }
Colin Cross16b23492016-01-06 14:41:07 -08001453 if c.sanitize != nil {
1454 flags = c.sanitize.flags(ctx, flags)
1455 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001456 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001457 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001458 }
Stephen Craneba090d12017-05-09 15:44:35 -07001459 if c.lto != nil {
1460 flags = c.lto.flags(ctx, flags)
1461 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001462 if c.pgo != nil {
1463 flags = c.pgo.flags(ctx, flags)
1464 }
Colin Crossca860ac2016-01-04 14:34:37 -08001465 for _, feature := range c.features {
1466 flags = feature.flags(ctx, flags)
1467 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001468 if ctx.Failed() {
1469 return
1470 }
1471
Colin Cross4af21ed2019-11-04 09:37:55 -08001472 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1473 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1474 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001475
Colin Cross4af21ed2019-11-04 09:37:55 -08001476 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001477
1478 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001479 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001480 }
1481 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001482 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001483 }
1484
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001485 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001486 // We need access to all the flags seen by a source file.
1487 if c.sabi != nil {
1488 flags = c.sabi.flags(ctx, flags)
1489 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001490
Colin Cross4af21ed2019-11-04 09:37:55 -08001491 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001492
Colin Crossca860ac2016-01-04 14:34:37 -08001493 // Optimization to reduce size of build.ninja
1494 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001495 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1496 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1497 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1498 flags.Local.CFlags = []string{"$cflags"}
1499 flags.Local.CppFlags = []string{"$cppflags"}
1500 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001501
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001502 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001503 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001504 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001505 if ctx.Failed() {
1506 return
1507 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001508 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001509 }
1510
Colin Crossca860ac2016-01-04 14:34:37 -08001511 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001512 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001513 if ctx.Failed() {
1514 return
1515 }
Colin Cross635c3b02016-05-18 15:37:25 -07001516 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001517
1518 // If a lib is directly included in any of the APEXes, unhide the stubs
1519 // variant having the latest version gets visible to make. In addition,
1520 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1521 // force anything in the make world to link against the stubs library.
1522 // (unless it is explicitly referenced via .bootstrap suffix or the
1523 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001524 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001525 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001526 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001527 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001528 c.Properties.HideFromMake = false // unhide
1529 // Note: this is still non-installable
1530 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001531
1532 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1533 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1534 if isSnapshotAware(ctx, c) {
1535 i.collectHeadersForSnapshot(ctx)
1536 }
1537 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001538 }
Colin Cross5049f022015-03-18 13:28:46 -07001539
Inseob Kim1f086e22019-05-09 13:29:15 +09001540 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001541 c.installer.install(ctx, c.outputFile.Path())
1542 if ctx.Failed() {
1543 return
Colin Crossca860ac2016-01-04 14:34:37 -08001544 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001545 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1546 // If the module has been specifically configure to not be installed then
1547 // skip the installation as otherwise it will break when running inside make
1548 // as the output path to install will not be specified. Not all uninstallable
1549 // modules can skip installation as some are needed for resolving make side
1550 // dependencies.
1551 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001552 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001553}
1554
Colin Cross0ea8ba82019-06-06 14:33:29 -07001555func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001556 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001557 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001558 }
Colin Crossca860ac2016-01-04 14:34:37 -08001559 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001560}
1561
Colin Crossca860ac2016-01-04 14:34:37 -08001562func (c *Module) begin(ctx BaseModuleContext) {
1563 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001564 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001565 }
Colin Crossca860ac2016-01-04 14:34:37 -08001566 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001567 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001568 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001569 if c.stl != nil {
1570 c.stl.begin(ctx)
1571 }
Colin Cross16b23492016-01-06 14:41:07 -08001572 if c.sanitize != nil {
1573 c.sanitize.begin(ctx)
1574 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001575 if c.coverage != nil {
1576 c.coverage.begin(ctx)
1577 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001578 if c.sabi != nil {
1579 c.sabi.begin(ctx)
1580 }
Justin Yun8effde42017-06-23 19:24:43 +09001581 if c.vndkdep != nil {
1582 c.vndkdep.begin(ctx)
1583 }
Stephen Craneba090d12017-05-09 15:44:35 -07001584 if c.lto != nil {
1585 c.lto.begin(ctx)
1586 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001587 if c.pgo != nil {
1588 c.pgo.begin(ctx)
1589 }
Colin Crossca860ac2016-01-04 14:34:37 -08001590 for _, feature := range c.features {
1591 feature.begin(ctx)
1592 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001593 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001594 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001595 if err != nil {
1596 ctx.PropertyErrorf("sdk_version", err.Error())
1597 }
Nan Zhang0007d812017-11-07 10:57:05 -08001598 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001599 }
Colin Crossca860ac2016-01-04 14:34:37 -08001600}
1601
Colin Cross37047f12016-12-13 17:06:13 -08001602func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001603 deps := Deps{}
1604
1605 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001606 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001607 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001608 // Add the PGO dependency (the clang_rt.profile runtime library), which
1609 // sometimes depends on symbols from libgcc, before libgcc gets added
1610 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001611 if c.pgo != nil {
1612 deps = c.pgo.deps(ctx, deps)
1613 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001614 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001615 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001616 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001617 if c.stl != nil {
1618 deps = c.stl.deps(ctx, deps)
1619 }
Colin Cross16b23492016-01-06 14:41:07 -08001620 if c.sanitize != nil {
1621 deps = c.sanitize.deps(ctx, deps)
1622 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001623 if c.coverage != nil {
1624 deps = c.coverage.deps(ctx, deps)
1625 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001626 if c.sabi != nil {
1627 deps = c.sabi.deps(ctx, deps)
1628 }
Justin Yun8effde42017-06-23 19:24:43 +09001629 if c.vndkdep != nil {
1630 deps = c.vndkdep.deps(ctx, deps)
1631 }
Stephen Craneba090d12017-05-09 15:44:35 -07001632 if c.lto != nil {
1633 deps = c.lto.deps(ctx, deps)
1634 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001635 for _, feature := range c.features {
1636 deps = feature.deps(ctx, deps)
1637 }
1638
Colin Crossb6715442017-10-24 11:13:31 -07001639 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1640 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1641 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1642 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1643 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1644 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001645 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001646
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001647 for _, lib := range deps.ReexportSharedLibHeaders {
1648 if !inList(lib, deps.SharedLibs) {
1649 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1650 }
1651 }
1652
1653 for _, lib := range deps.ReexportStaticLibHeaders {
1654 if !inList(lib, deps.StaticLibs) {
1655 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1656 }
1657 }
1658
Colin Cross5950f382016-12-13 12:50:57 -08001659 for _, lib := range deps.ReexportHeaderLibHeaders {
1660 if !inList(lib, deps.HeaderLibs) {
1661 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1662 }
1663 }
1664
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001665 for _, gen := range deps.ReexportGeneratedHeaders {
1666 if !inList(gen, deps.GeneratedHeaders) {
1667 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1668 }
1669 }
1670
Colin Crossc99deeb2016-04-11 15:06:20 -07001671 return deps
1672}
1673
Dan Albert7e9d2952016-08-04 13:02:36 -07001674func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001675 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001676 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001677 moduleContextImpl: moduleContextImpl{
1678 mod: c,
1679 },
1680 }
1681 ctx.ctx = ctx
1682
Colin Crossca860ac2016-01-04 14:34:37 -08001683 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001684}
1685
Jiyong Park7ed9de32018-10-15 22:25:07 +09001686// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001687func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001688 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1689 version := name[sharp+1:]
1690 libname := name[:sharp]
1691 return libname, version
1692 }
1693 return name, ""
1694}
1695
Colin Cross1e676be2016-10-12 14:38:15 -07001696func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001697 if !c.Enabled() {
1698 return
1699 }
1700
Colin Cross37047f12016-12-13 17:06:13 -08001701 ctx := &depsContext{
1702 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001703 moduleContextImpl: moduleContextImpl{
1704 mod: c,
1705 },
1706 }
1707 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001708
Colin Crossc99deeb2016-04-11 15:06:20 -07001709 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001710
Dan Albert914449f2016-06-17 16:45:24 -07001711 variantNdkLibs := []string{}
1712 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001713 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001714 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001715
Inseob Kimeec88e12020-01-22 11:11:29 +09001716 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001717 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001718 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001719 // 1. Name of an NDK library that refers to a prebuilt module.
1720 // For each of these, it adds the name of the prebuilt module (which will be in
1721 // prebuilts/ndk) to the list of nonvariant libs.
1722 // 2. Name of an NDK library that refers to an ndk_library module.
1723 // For each of these, it adds the name of the ndk_library module to the list of
1724 // variant libs.
1725 // 3. Anything else (so anything that isn't an NDK library).
1726 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001727 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001728 // The caller can then know to add the variantLibs dependencies differently from the
1729 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001730
Inseob Kim9516ee92019-05-09 10:56:13 +09001731 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001732 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1733
1734 rewriteVendorLibs := func(lib string) string {
1735 if isLlndkLibrary(lib, ctx.Config()) {
1736 return lib + llndkLibrarySuffix
1737 }
1738
1739 // only modules with BOARD_VNDK_VERSION uses snapshot.
1740 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1741 return lib
1742 }
1743
1744 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1745 return snapshot
1746 }
1747
1748 return lib
1749 }
1750
1751 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001752 variantLibs = []string{}
1753 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001754 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001755 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001756 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001757 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1758 if !inList(name, ndkMigratedLibs) {
1759 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001760 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001761 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001762 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001763 } else if ctx.useVndk() {
1764 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001765 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001766 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001767 if actx.OtherModuleExists(vendorPublicLib) {
1768 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1769 } else {
1770 // This can happen if vendor_public_library module is defined in a
1771 // namespace that isn't visible to the current module. In that case,
1772 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001773 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001774 }
Dan Albert914449f2016-06-17 16:45:24 -07001775 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001776 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001777 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001778 }
1779 }
Dan Albert914449f2016-06-17 16:45:24 -07001780 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001781 }
1782
Inseob Kimeec88e12020-01-22 11:11:29 +09001783 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1784 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1785 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1786 if ctx.useVndk() {
1787 for idx, lib := range deps.RuntimeLibs {
1788 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1789 }
1790 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001791 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001792
Jiyong Park7e636d02019-01-28 16:16:54 +09001793 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001794 if c.linker != nil {
1795 if library, ok := c.linker.(*libraryDecorator); ok {
1796 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001797 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001798 }
1799 }
1800 }
1801
Inseob Kimeec88e12020-01-22 11:11:29 +09001802 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1803 // only modules with BOARD_VNDK_VERSION uses snapshot.
1804 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1805 return lib
1806 }
1807
1808 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1809 return snapshot
1810 }
1811
1812 return lib
1813 }
1814
1815 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001816 for _, lib := range deps.HeaderLibs {
1817 depTag := headerDepTag
1818 if inList(lib, deps.ReexportHeaderLibHeaders) {
1819 depTag = headerExportDepTag
1820 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001821
1822 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1823
Jiyong Park7e636d02019-01-28 16:16:54 +09001824 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001825 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001826 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001827 } else {
1828 actx.AddVariationDependencies(nil, depTag, lib)
1829 }
1830 }
1831
1832 if buildStubs {
1833 // Stubs lib does not have dependency to other static/shared libraries.
1834 // Don't proceed.
1835 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001836 }
Colin Cross5950f382016-12-13 12:50:57 -08001837
Inseob Kimc0907f12019-02-08 21:00:45 +09001838 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001839 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001840
Jiyong Park5d1598f2019-02-25 22:14:17 +09001841 for _, lib := range deps.WholeStaticLibs {
1842 depTag := wholeStaticDepTag
1843 if impl, ok := syspropImplLibraries[lib]; ok {
1844 lib = impl
1845 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001846
1847 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1848
Jiyong Park5d1598f2019-02-25 22:14:17 +09001849 actx.AddVariationDependencies([]blueprint.Variation{
1850 {Mutator: "link", Variation: "static"},
1851 }, depTag, lib)
1852 }
1853
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001854 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001855 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001856 if inList(lib, deps.ReexportStaticLibHeaders) {
1857 depTag = staticExportDepTag
1858 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001859
1860 if impl, ok := syspropImplLibraries[lib]; ok {
1861 lib = impl
1862 }
1863
Inseob Kimeec88e12020-01-22 11:11:29 +09001864 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1865
Dan Willemsen59339a22018-07-22 21:18:45 -07001866 actx.AddVariationDependencies([]blueprint.Variation{
1867 {Mutator: "link", Variation: "static"},
1868 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001869 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001870
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001871 if deps.StaticUnwinderIfLegacy && ctx.Config().UnbundledBuild() {
1872 actx.AddVariationDependencies([]blueprint.Variation{
1873 {Mutator: "link", Variation: "static"},
1874 }, staticUnwinderDepTag, staticUnwinder(actx))
1875 }
1876
Inseob Kimeec88e12020-01-22 11:11:29 +09001877 for _, lib := range deps.LateStaticLibs {
1878 actx.AddVariationDependencies([]blueprint.Variation{
1879 {Mutator: "link", Variation: "static"},
1880 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1881 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001882
Ivan Lozano183a3212019-10-18 14:18:45 -07001883 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001884 var variations []blueprint.Variation
1885 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Hanbacf34d2020-03-21 13:58:19 +00001886 versionVariantAvail := !ctx.useVndk() && !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001887 if version != "" && versionVariantAvail {
1888 // Version is explicitly specified. i.e. libFoo#30
1889 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001890 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001891 }
1892 actx.AddVariationDependencies(variations, depTag, name)
1893
Jooyung Han03b51852020-02-26 22:45:42 +09001894 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001895 // The stubs library will be used when the depending module is built for APEX and
1896 // the dependent module is not in the same APEX.
Jooyung Han03b51852020-02-26 22:45:42 +09001897 if version == "" && versionVariantAvail {
1898 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1899 // Note that depTag.ExplicitlyVersioned is false in this case.
1900 actx.AddVariationDependencies([]blueprint.Variation{
1901 {Mutator: "link", Variation: "shared"},
1902 {Mutator: "version", Variation: ver},
1903 }, depTag, name)
1904 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001905 }
1906 }
1907
Jiyong Park7ed9de32018-10-15 22:25:07 +09001908 // shared lib names without the #version suffix
1909 var sharedLibNames []string
1910
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001911 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001912 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001913 if c.static() {
1914 depTag = SharedFromStaticDepTag
1915 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001916 if inList(lib, deps.ReexportSharedLibHeaders) {
1917 depTag = sharedExportDepTag
1918 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001919
1920 if impl, ok := syspropImplLibraries[lib]; ok {
1921 lib = impl
1922 }
1923
Jiyong Park73c54ee2019-10-22 20:31:18 +09001924 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001925 sharedLibNames = append(sharedLibNames, name)
1926
Jiyong Park25fc6a92018-11-18 18:02:45 +09001927 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001928 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001929
Jiyong Park7ed9de32018-10-15 22:25:07 +09001930 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001931 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001932 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1933 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1934 // linking against both the stubs lib and the non-stubs lib at the same time.
1935 continue
1936 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001937 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001938 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001939
Dan Willemsen59339a22018-07-22 21:18:45 -07001940 actx.AddVariationDependencies([]blueprint.Variation{
1941 {Mutator: "link", Variation: "shared"},
1942 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001943
Colin Cross68861832016-07-08 10:41:41 -07001944 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001945
1946 for _, gen := range deps.GeneratedHeaders {
1947 depTag := genHeaderDepTag
1948 if inList(gen, deps.ReexportGeneratedHeaders) {
1949 depTag = genHeaderExportDepTag
1950 }
1951 actx.AddDependency(c, depTag, gen)
1952 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001953
Colin Cross42d48b72018-08-29 14:10:52 -07001954 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001955
1956 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001957 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001958 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001959 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001960 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001961 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001962 if deps.LinkerFlagsFile != "" {
1963 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1964 }
1965 if deps.DynamicLinker != "" {
1966 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001967 }
Dan Albert914449f2016-06-17 16:45:24 -07001968
1969 version := ctx.sdkVersion()
1970 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001971 {Mutator: "ndk_api", Variation: version},
1972 {Mutator: "link", Variation: "shared"},
1973 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001974 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001975 {Mutator: "ndk_api", Variation: version},
1976 {Mutator: "link", Variation: "shared"},
1977 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001978
1979 if vndkdep := c.vndkdep; vndkdep != nil {
1980 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001981 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001982 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001983 {Mutator: "link", Variation: "shared"},
1984 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001985 }
1986 }
Colin Cross6362e272015-10-29 15:25:03 -07001987}
Colin Cross21b9a242015-03-24 14:15:58 -07001988
Colin Crosse40b4ea2018-10-02 22:25:58 -07001989func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001990 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1991 c.beginMutator(ctx)
1992 }
1993}
1994
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001995// Whether a module can link to another module, taking into
1996// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001997func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1998 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001999 // Host code is not restricted
2000 return
2001 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002002
2003 // VNDK is cc.Module supported only for now.
2004 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002005 // Though vendor code is limited by the vendor mutator,
2006 // each vendor-available module needs to check
2007 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07002008 if ccTo, ok := to.(*Module); ok {
2009 if ccFrom.vndkdep != nil {
2010 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
2011 }
2012 } else {
2013 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002014 }
2015 return
2016 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002017 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002018 // Platform code can link to anything
2019 return
2020 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002021 if from.InRamdisk() {
2022 // Ramdisk code is not NDK
2023 return
2024 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002025 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002026 // Recovery code is not NDK
2027 return
2028 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002029 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002030 // These are always allowed
2031 return
2032 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002033 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002034 // These are allowed, but they don't set sdk_version
2035 return
2036 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002037 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002038 // These aren't real libraries, but are the stub shared libraries that are included in
2039 // the NDK.
2040 return
2041 }
Logan Chien834b9a62019-01-14 15:39:03 +08002042
Ivan Lozano52767be2019-10-18 14:49:46 -07002043 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002044 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2045 // to link to libc++ (non-NDK and without sdk_version).
2046 return
2047 }
2048
Ivan Lozano52767be2019-10-18 14:49:46 -07002049 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002050 // NDK code linking to platform code is never okay.
2051 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002052 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002053 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002054 }
2055
2056 // At this point we know we have two NDK libraries, but we need to
2057 // check that we're not linking against anything built against a higher
2058 // API level, as it is only valid to link against older or equivalent
2059 // APIs.
2060
Inseob Kim01a28722018-04-11 09:48:45 +09002061 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002062 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002063 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002064 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002065 // Current can't be linked against by anything else.
2066 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002067 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002068 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002069 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002070 if err != nil {
2071 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002072 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002073 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002074 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002075 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002076 if err != nil {
2077 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002078 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002079 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002080 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002081
Inseob Kim01a28722018-04-11 09:48:45 +09002082 if toApi > fromApi {
2083 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002084 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002085 }
2086 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002087 }
Dan Albert202fe492017-12-15 13:56:59 -08002088
2089 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002090 fromStl := from.SelectedStl()
2091 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002092 if fromStl == "" || toStl == "" {
2093 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002094 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002095 // We can be permissive with the system "STL" since it is only the C++
2096 // ABI layer, but in the future we should make sure that everyone is
2097 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002098 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002099 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002100 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2101 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002102 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002103}
2104
Jiyong Park5fb8c102018-04-09 12:03:06 +09002105// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002106// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2107// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002108// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002109func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2110 check := func(child, parent android.Module) bool {
2111 to, ok := child.(*Module)
2112 if !ok {
2113 // follow thru cc.Defaults, etc.
2114 return true
2115 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002116
Jooyung Hana70f0672019-01-18 15:20:43 +09002117 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2118 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002119 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002120
2121 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002122 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002123 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002124 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002125
Jooyung Han0302a842019-10-30 18:43:49 +09002126 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002127 return false
2128 }
2129
2130 var stringPath []string
2131 for _, m := range ctx.GetWalkPath() {
2132 stringPath = append(stringPath, m.Name())
2133 }
2134 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2135 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2136 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2137 return false
2138 }
2139 if module, ok := ctx.Module().(*Module); ok {
2140 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002141 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002142 ctx.WalkDeps(check)
2143 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002144 }
2145 }
2146}
2147
Colin Crossc99deeb2016-04-11 15:06:20 -07002148// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002149func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002150 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002151
Ivan Lozano183a3212019-10-18 14:18:45 -07002152 directStaticDeps := []LinkableInterface{}
2153 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002154
Inseob Kim9516ee92019-05-09 10:56:13 +09002155 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2156
Inseob Kim69378442019-06-03 19:10:47 +09002157 reexportExporter := func(exporter exportedFlagsProducer) {
2158 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2159 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2160 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2161 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002162 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002163 }
2164
Colin Crossd11fcda2017-10-23 17:59:01 -07002165 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002166 depName := ctx.OtherModuleName(dep)
2167 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002168
Ivan Lozano52767be2019-10-18 14:49:46 -07002169 ccDep, ok := dep.(LinkableInterface)
2170 if !ok {
2171
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002172 // handling for a few module types that aren't cc Module but that are also supported
2173 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002174 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002175 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002176 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2177 genRule.GeneratedSourceFiles()...)
2178 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002179 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002180 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002181 // Support exported headers from a generated_sources dependency
2182 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002183 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002184 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002185 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002186 genRule.GeneratedSourceFiles()...)
2187 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002188 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002189 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002190 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002191 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002192 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002193 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2194 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002195 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002196 // 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 +09002197 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002198
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002199 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002200 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002201 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002202 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002203 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002204 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002205 files := genRule.GeneratedSourceFiles()
2206 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002207 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002208 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002209 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 -07002210 }
2211 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002212 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002213 }
Colin Crossca860ac2016-01-04 14:34:37 -08002214 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002215 return
2216 }
2217
Colin Crossfe17f6f2019-03-28 19:30:56 -07002218 if depTag == android.ProtoPluginDepTag {
2219 return
2220 }
2221
Colin Crossd11fcda2017-10-23 17:59:01 -07002222 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002223 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2224 return
2225 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002226 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Hanbacf34d2020-03-21 13:58:19 +00002227 ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002228 return
2229 }
2230
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002231 // re-exporting flags
2232 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002233 // reusing objects only make sense for cc.Modules.
2234 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002235 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002236 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002237 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002238 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002239 return
2240 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002241 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002242
Jiyong Parke4bb9862019-02-01 00:31:10 +09002243 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002244 // staticVariants are a cc.Module specific concept.
2245 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002246 c.staticVariant = ccDep
2247 return
2248 }
2249 }
2250
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002251 if depTag == staticUnwinderDepTag {
Jooyung Han03b51852020-02-26 22:45:42 +09002252 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2253 if c.ShouldSupportAndroid10() {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002254 depTag = StaticDepTag
2255 } else {
2256 return
2257 }
2258 }
2259
Ivan Lozano183a3212019-10-18 14:18:45 -07002260 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2261 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2262 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002263 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002264 if t, ok := depTag.(DependencyTag); ok {
2265 explicitlyVersioned = t.ExplicitlyVersioned
2266 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002267 depTag = t
2268 }
2269
Ivan Lozano183a3212019-10-18 14:18:45 -07002270 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002271 depIsStatic := false
2272 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002273 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002274 depIsStatic = true
2275 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002276 if ccDep.CcLibrary() && !depIsStatic {
2277 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002278 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002279 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002280 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002281
2282 var useThisDep bool
2283 if depIsStubs && explicitlyVersioned {
2284 // Always respect dependency to the versioned stubs (i.e. libX#10)
2285 useThisDep = true
2286 } else if !depHasStubs {
2287 // Use non-stub variant if that is the only choice
2288 // (i.e. depending on a lib without stubs.version property)
2289 useThisDep = true
2290 } else if c.IsForPlatform() {
2291 // If not building for APEX, use stubs only when it is from
2292 // an APEX (and not from platform)
2293 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002294 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2295 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002296 // always link to non-stub variant
2297 useThisDep = !depIsStubs
2298 }
2299 } else {
2300 // If building for APEX, use stubs only when it is not from
2301 // the same APEX
2302 useThisDep = (depInSameApex != depIsStubs)
2303 }
2304
Jooyung Han03b51852020-02-26 22:45:42 +09002305 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2306 if useThisDep && depIsStubs && !explicitlyVersioned {
2307 useLatest := c.IsForPlatform() || (c.ShouldSupportAndroid10() && !ctx.Config().UnbundledBuild())
2308 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), useLatest)
2309 if err != nil {
2310 ctx.OtherModuleErrorf(dep, err.Error())
2311 return
2312 }
2313 if versionToUse != ccDep.StubsVersion() {
2314 useThisDep = false
2315 }
2316 }
2317
Jiyong Park25fc6a92018-11-18 18:02:45 +09002318 if !useThisDep {
2319 return // stop processing this dep
2320 }
2321 }
2322
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002323 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2324
Ivan Lozano52767be2019-10-18 14:49:46 -07002325 // Exporting flags only makes sense for cc.Modules
2326 if _, ok := ccDep.(*Module); ok {
2327 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002328 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002329 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2330 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002331 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002332
Ivan Lozano52767be2019-10-18 14:49:46 -07002333 if t.ReexportFlags {
2334 reexportExporter(i)
2335 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2336 // Re-exported shared library headers must be included as well since they can help us with type information
2337 // about template instantiations (instantiated from their headers).
2338 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2339 // scripts.
2340 c.sabi.Properties.ReexportedIncludes = append(
2341 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2342 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002343 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002344 }
Logan Chienf3511742017-10-31 18:04:35 +08002345 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002346 }
2347
Colin Cross26c34ed2016-09-30 17:10:16 -07002348 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002349 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002350
Ivan Lozano52767be2019-10-18 14:49:46 -07002351 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002352 depFile := android.OptionalPath{}
2353
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002354 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002355 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002356 ptr = &depPaths.SharedLibs
2357 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002358 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002359 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002360
Jiyong Park64a44f22019-01-18 14:37:08 +09002361 case earlySharedDepTag:
2362 ptr = &depPaths.EarlySharedLibs
2363 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002364 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002365 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002366 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002367 ptr = &depPaths.LateSharedLibs
2368 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002369 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002370 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002371 ptr = nil
2372 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002373 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002374 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002375 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002376 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002377 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002378 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002379 return
2380 }
2381
Ivan Lozano52767be2019-10-18 14:49:46 -07002382 // Because the static library objects are included, this only makes sense
2383 // in the context of proper cc.Modules.
2384 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2385 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2386 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2387 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2388 for i := range missingDeps {
2389 missingDeps[i] += postfix
2390 }
2391 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002392 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002393 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2394 } else {
2395 ctx.ModuleErrorf(
2396 "non-cc.Modules cannot be included as whole static libraries.", depName)
2397 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002398 }
Colin Cross5950f382016-12-13 12:50:57 -08002399 case headerDepTag:
2400 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002401 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002402 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002403 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002404 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002405 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002406 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002407 case dynamicLinkerDepTag:
2408 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002409 }
2410
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002411 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002412 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002413 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002414 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002415 return
2416 }
2417
2418 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002419 // in static libraries act as if they were whole static libraries. The same goes for
2420 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002421 // This should only be done for cc.Modules
2422 if c, ok := ccDep.(*Module); ok {
2423 staticLib := c.linker.(libraryInterface)
2424 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2425 staticLib.objs().coverageFiles...)
2426 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2427 staticLib.objs().sAbiDumpFiles...)
2428 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002429 }
2430
Colin Cross26c34ed2016-09-30 17:10:16 -07002431 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002432 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002433 if !ctx.Config().AllowMissingDependencies() {
2434 ctx.ModuleErrorf("module %q missing output file", depName)
2435 } else {
2436 ctx.AddMissingDependencies([]string{depName})
2437 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002438 return
2439 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002440 *ptr = append(*ptr, linkFile.Path())
2441 }
2442
Colin Crossc99deeb2016-04-11 15:06:20 -07002443 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002444 dep := depFile
2445 if !dep.Valid() {
2446 dep = linkFile
2447 }
2448 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002449 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002450
Inseob Kimeec88e12020-01-22 11:11:29 +09002451 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2452
2453 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002454 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002455 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002456 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002457 return libName
2458 }
2459
2460 makeLibName := func(depName string) string {
2461 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002462 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002463 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002464 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002465
Inseob Kimeec88e12020-01-22 11:11:29 +09002466 if c, ok := ccDep.(*Module); ok {
2467 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim752edec2020-03-14 01:30:34 +09002468 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002469 baseName := c.BaseModuleName()
Inseob Kim752edec2020-03-14 01:30:34 +09002470
2471 if c.IsVndk() {
2472 return baseName + ".vendor"
2473 }
2474
Inseob Kimeec88e12020-01-22 11:11:29 +09002475 if vendorSuffixModules[baseName] {
2476 return baseName + ".vendor"
2477 } else {
2478 return baseName
2479 }
2480 }
2481 }
2482
Yifan Hong1b3348d2020-01-21 15:53:22 -08002483 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002484 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2485 // core module instead.
2486 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002487 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002488 // The vendor module in Make will have been renamed to not conflict with the core
2489 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002490 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002491 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002492 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002493 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2494 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002495 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002496 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002497 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002498 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002499 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002500 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002501 }
Logan Chien43d34c32017-12-20 01:17:32 +08002502 }
2503
2504 // Export the shared libs to Make.
2505 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002506 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002507 if ccDep.CcLibrary() {
2508 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002509 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002510 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002511 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002512 c.Properties.ApexesProvidingSharedLibs = append(
2513 c.Properties.ApexesProvidingSharedLibs, an)
2514 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002515 }
2516 }
2517
Jiyong Park27b188b2017-07-18 13:23:39 +09002518 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002519 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002520 c.Properties.AndroidMkSharedLibs = append(
2521 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002522 // Record baseLibName for snapshots.
2523 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002524 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002525 c.Properties.AndroidMkSharedLibs = append(
2526 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002527 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002528 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002529 c.Properties.AndroidMkStaticLibs = append(
2530 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002531 case runtimeDepTag:
2532 c.Properties.AndroidMkRuntimeLibs = append(
2533 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002534 // Record baseLibName for snapshots.
2535 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002536 case wholeStaticDepTag:
2537 c.Properties.AndroidMkWholeStaticLibs = append(
2538 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002539 }
Colin Crossca860ac2016-01-04 14:34:37 -08002540 })
2541
Jeff Gaston294356f2017-09-27 17:05:30 -07002542 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002543 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002544
Colin Crossdd84e052017-05-17 13:44:16 -07002545 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002546 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002547 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2548 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002549 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002550 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002551 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2552 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002553 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002554 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002555 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002556
2557 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002558 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002559 }
Colin Crossdd84e052017-05-17 13:44:16 -07002560
Colin Crossca860ac2016-01-04 14:34:37 -08002561 return depPaths
2562}
2563
2564func (c *Module) InstallInData() bool {
2565 if c.installer == nil {
2566 return false
2567 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002568 return c.installer.inData()
2569}
2570
2571func (c *Module) InstallInSanitizerDir() bool {
2572 if c.installer == nil {
2573 return false
2574 }
2575 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002576 return true
2577 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002578 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002579}
2580
Yifan Hong1b3348d2020-01-21 15:53:22 -08002581func (c *Module) InstallInRamdisk() bool {
2582 return c.InRamdisk()
2583}
2584
Jiyong Parkf9332f12018-02-01 00:54:12 +09002585func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002586 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002587}
2588
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002589func (c *Module) HostToolPath() android.OptionalPath {
2590 if c.installer == nil {
2591 return android.OptionalPath{}
2592 }
2593 return c.installer.hostToolPath()
2594}
2595
Nan Zhangd4e641b2017-07-12 12:55:28 -07002596func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2597 return c.outputFile
2598}
2599
Colin Cross41955e82019-05-29 14:40:35 -07002600func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2601 switch tag {
2602 case "":
2603 if c.outputFile.Valid() {
2604 return android.Paths{c.outputFile.Path()}, nil
2605 }
2606 return android.Paths{}, nil
2607 default:
2608 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002609 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002610}
2611
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002612func (c *Module) static() bool {
2613 if static, ok := c.linker.(interface {
2614 static() bool
2615 }); ok {
2616 return static.static()
2617 }
2618 return false
2619}
2620
Jiyong Park379de2f2018-12-19 02:47:14 +09002621func (c *Module) staticBinary() bool {
2622 if static, ok := c.linker.(interface {
2623 staticBinary() bool
2624 }); ok {
2625 return static.staticBinary()
2626 }
2627 return false
2628}
2629
Jiyong Park1d1119f2019-07-29 21:27:18 +09002630func (c *Module) header() bool {
2631 if h, ok := c.linker.(interface {
2632 header() bool
2633 }); ok {
2634 return h.header()
2635 }
2636 return false
2637}
2638
Jooyung Han38002912019-05-16 04:01:54 +09002639func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002640 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002641 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2642 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002643 return "native:vndk"
2644 }
Jooyung Han38002912019-05-16 04:01:54 +09002645 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002646 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002647 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002648 if Bool(c.VendorProperties.Vendor_available) {
2649 return "native:vndk"
2650 }
2651 return "native:vndk_private"
2652 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002653 if c.inProduct() {
2654 return "native:product"
2655 }
Jooyung Han38002912019-05-16 04:01:54 +09002656 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002657 } else if c.InRamdisk() {
2658 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002659 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002660 return "native:recovery"
2661 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2662 return "native:ndk:none:none"
2663 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2664 //family, link := getNdkStlFamilyAndLinkType(c)
2665 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002666 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002667 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002668 } else {
2669 return "native:platform"
2670 }
2671}
2672
Jiyong Park9d452992018-10-03 00:38:19 +09002673// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002674// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002675func (c *Module) IsInstallableToApex() bool {
2676 if shared, ok := c.linker.(interface {
2677 shared() bool
2678 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002679 // Stub libs and prebuilt libs in a versioned SDK are not
2680 // installable to APEX even though they are shared libs.
2681 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002682 } else if _, ok := c.linker.(testPerSrc); ok {
2683 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002684 }
2685 return false
2686}
2687
Jiyong Parka90ca002019-10-07 15:47:24 +09002688func (c *Module) AvailableFor(what string) bool {
2689 if linker, ok := c.linker.(interface {
2690 availableFor(string) bool
2691 }); ok {
2692 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2693 } else {
2694 return c.ApexModuleBase.AvailableFor(what)
2695 }
2696}
2697
Paul Duffin0cb37b92020-03-04 14:52:46 +00002698// Return true if the module is ever installable.
2699func (c *Module) EverInstallable() bool {
2700 return c.installer != nil &&
2701 // Check to see whether the module is actually ever installable.
2702 c.installer.everInstallable()
2703}
2704
Inseob Kim1f086e22019-05-09 13:29:15 +09002705func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002706 ret := c.EverInstallable() &&
2707 // Check to see whether the module has been configured to not be installed.
2708 proptools.BoolDefault(c.Properties.Installable, true) &&
2709 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002710
2711 // The platform variant doesn't need further condition. Apex variants however might not
2712 // be installable because it will likely to be included in the APEX and won't appear
2713 // in the system partition.
2714 if c.IsForPlatform() {
2715 return ret
2716 }
2717
2718 // Special case for modules that are configured to be installed to /data, which includes
2719 // test modules. For these modules, both APEX and non-APEX variants are considered as
2720 // installable. This is because even the APEX variants won't be included in the APEX, but
2721 // will anyway be installed to /data/*.
2722 // See b/146995717
2723 if c.InstallInData() {
2724 return ret
2725 }
2726
2727 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002728}
2729
Logan Chien41eabe62019-04-10 13:33:58 +08002730func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2731 if c.linker != nil {
2732 if library, ok := c.linker.(*libraryDecorator); ok {
2733 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2734 }
2735 }
2736}
2737
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002738func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002739 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002740 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002741 if cc.HasStubsVariants() {
2742 if depTag.Shared && depTag.Library {
2743 // dynamic dep to a stubs lib crosses APEX boundary
2744 return false
2745 }
2746 if IsRuntimeDepTag(depTag) {
2747 // runtime dep to a stubs lib also crosses APEX boundary
2748 return false
2749 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002750 }
2751 if depTag.FromStatic {
2752 // shared_lib dependency from a static lib is considered as crossing
2753 // the APEX boundary because the dependency doesn't actually is
2754 // linked; the dependency is used only during the compilation phase.
2755 return false
2756 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002757 }
2758 }
2759 return true
2760}
2761
Colin Cross2ba19d92015-05-07 15:44:20 -07002762//
Colin Crosscfad1192015-11-02 16:43:11 -08002763// Defaults
2764//
Colin Crossca860ac2016-01-04 14:34:37 -08002765type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002766 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002767 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002768 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002769}
2770
Patrice Arrudac249c712019-03-19 17:00:29 -07002771// cc_defaults provides a set of properties that can be inherited by other cc
2772// modules. A module can use the properties from a cc_defaults using
2773// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2774// merged (when possible) by prepending the default module's values to the
2775// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002776func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002777 return DefaultsFactory()
2778}
2779
Colin Cross36242852017-06-23 15:06:31 -07002780func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002781 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002782
Colin Cross36242852017-06-23 15:06:31 -07002783 module.AddProperties(props...)
2784 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002785 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002786 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002787 &BaseCompilerProperties{},
2788 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002789 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002790 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002791 &StaticProperties{},
2792 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002793 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002794 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002795 &TestProperties{},
2796 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002797 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002798 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002799 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002800 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002801 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002802 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002803 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002804 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002805 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002806 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002807 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002808 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002809 )
Colin Crosscfad1192015-11-02 16:43:11 -08002810
Jooyung Hancc372c52019-09-25 15:18:44 +09002811 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002812
2813 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002814}
2815
Jiyong Park6a43f042017-10-12 23:05:00 +09002816func squashVendorSrcs(m *Module) {
2817 if lib, ok := m.compiler.(*libraryDecorator); ok {
2818 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2819 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2820
2821 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2822 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2823 }
2824}
2825
Jiyong Parkf9332f12018-02-01 00:54:12 +09002826func squashRecoverySrcs(m *Module) {
2827 if lib, ok := m.compiler.(*libraryDecorator); ok {
2828 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2829 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2830
2831 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2832 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2833 }
2834}
2835
Colin Cross7228ecd2019-11-18 16:00:16 -08002836var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002837
Colin Cross7228ecd2019-11-18 16:00:16 -08002838func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002839 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002840 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002841 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002842
2843 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002844 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002845 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002846 }
Logan Chienf3511742017-10-31 18:04:35 +08002847
2848 if vndkdep := m.vndkdep; vndkdep != nil {
2849 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09002850 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002851 if !vndkdep.isVndkExt() {
2852 mctx.PropertyErrorf("vndk",
2853 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09002854 } else if m.VendorProperties.Vendor_available != nil {
2855 mctx.PropertyErrorf("vendor_available",
2856 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002857 }
2858 } else {
2859 if vndkdep.isVndkExt() {
2860 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09002861 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002862 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002863 }
2864 if m.VendorProperties.Vendor_available == nil {
2865 mctx.PropertyErrorf("vndk",
2866 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002867 }
2868 }
2869 } else {
2870 if vndkdep.isVndkSp() {
2871 mctx.PropertyErrorf("vndk",
2872 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002873 }
2874 if vndkdep.isVndkExt() {
2875 mctx.PropertyErrorf("vndk",
2876 "must set `enabled: true` to set `extends: %q`",
2877 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002878 }
Justin Yun8effde42017-06-23 19:24:43 +09002879 }
2880 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002881
Jiyong Parkf9332f12018-02-01 00:54:12 +09002882 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002883 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002884 var recoveryVariantNeeded bool = false
2885
Inseob Kim64c43952019-08-26 16:52:35 +09002886 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002887 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002888
2889 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002890 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2891 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2892 if boardVndkVersion == "current" {
2893 boardVndkVersion = platformVndkVersion
2894 }
2895 if productVndkVersion == "current" {
2896 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002897 }
2898
Justin Yun5f7f7e82019-11-18 19:52:14 +09002899 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002900 // If the device isn't compiling against the VNDK, we always
2901 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002902 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002903 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002904 // LL-NDK stubs only exist in the vendor and product variants,
2905 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002906 vendorVariants = append(vendorVariants,
2907 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002908 boardVndkVersion,
2909 )
2910 productVariants = append(productVariants,
2911 platformVndkVersion,
2912 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002913 )
Jiyong Park2a454122017-10-19 15:59:33 +09002914 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2915 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002916 vendorVariants = append(vendorVariants,
2917 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002918 boardVndkVersion,
2919 )
2920 productVariants = append(productVariants,
2921 platformVndkVersion,
2922 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002923 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002924 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002925 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2926 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002927 if snapshot, ok := m.linker.(interface {
2928 version() string
2929 }); ok {
2930 vendorVariants = append(vendorVariants, snapshot.version())
2931 } else {
2932 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2933 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09002934 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002935 // This will be available in /system, /vendor and /product
2936 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002937 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002938 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002939 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002940 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2941 // code is PLATFORM_VNDK_VERSION.
2942 // On the other hand, vendor_available modules which are not VNDK should
2943 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002944 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002945 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002946 vendorVariants = append(vendorVariants, boardVndkVersion)
2947 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002948 }
Logan Chienf3511742017-10-31 18:04:35 +08002949 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002950 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002951 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002952 } else {
2953 // This is either in /system (or similar: /data), or is a
2954 // modules built with the NDK. Modules built with the NDK
2955 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002956 coreVariantNeeded = true
2957 }
2958
Justin Yun5f7f7e82019-11-18 19:52:14 +09002959 if boardVndkVersion != "" && productVndkVersion != "" {
2960 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2961 // The module has "product_specific: true" that does not create core variant.
2962 coreVariantNeeded = false
2963 productVariants = append(productVariants, productVndkVersion)
2964 }
2965 } else {
2966 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2967 // restriction to use system libs.
2968 // No product variants defined in this case.
2969 productVariants = []string{}
2970 }
2971
Yifan Hong1b3348d2020-01-21 15:53:22 -08002972 if Bool(m.Properties.Ramdisk_available) {
2973 ramdiskVariantNeeded = true
2974 }
2975
2976 if m.ModuleBase.InstallInRamdisk() {
2977 ramdiskVariantNeeded = true
2978 coreVariantNeeded = false
2979 }
2980
Jiyong Parkf9332f12018-02-01 00:54:12 +09002981 if Bool(m.Properties.Recovery_available) {
2982 recoveryVariantNeeded = true
2983 }
2984
2985 if m.ModuleBase.InstallInRecovery() {
2986 recoveryVariantNeeded = true
2987 coreVariantNeeded = false
2988 }
2989
Inseob Kim64c43952019-08-26 16:52:35 +09002990 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002991 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2992 }
2993
2994 for _, variant := range android.FirstUniqueStrings(productVariants) {
2995 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09002996 }
Colin Cross7228ecd2019-11-18 16:00:16 -08002997
Yifan Hong1b3348d2020-01-21 15:53:22 -08002998 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08002999 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3000 m.Properties.CoreVariantNeeded = coreVariantNeeded
3001}
3002
3003func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3004 return c.Properties.CoreVariantNeeded
3005}
3006
Yifan Hong1b3348d2020-01-21 15:53:22 -08003007func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3008 return c.Properties.RamdiskVariantNeeded
3009}
3010
Colin Cross7228ecd2019-11-18 16:00:16 -08003011func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3012 return c.Properties.RecoveryVariantNeeded
3013}
3014
3015func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003016 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003017}
3018
3019func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3020 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003021 if variant == android.RamdiskVariation {
3022 m.MakeAsPlatform()
3023 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003024 m.MakeAsPlatform()
3025 squashRecoverySrcs(m)
3026 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003027 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003028 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3029 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003030
3031 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3032 // Hide other vendor variants to avoid collision.
3033 vndkVersion := ctx.DeviceConfig().VndkVersion()
3034 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3035 m.Properties.HideFromMake = true
3036 m.SkipInstall()
3037 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003038 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3039 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3040 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3041 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003042 }
3043}
3044
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003045func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003046 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003047 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3048 }
Colin Cross6510f912017-11-29 00:27:14 -08003049 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003050}
3051
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003052func kytheExtractAllFactory() android.Singleton {
3053 return &kytheExtractAllSingleton{}
3054}
3055
3056type kytheExtractAllSingleton struct {
3057}
3058
3059func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3060 var xrefTargets android.Paths
3061 ctx.VisitAllModules(func(module android.Module) {
3062 if ccModule, ok := module.(xref); ok {
3063 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3064 }
3065 })
3066 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3067 if len(xrefTargets) > 0 {
3068 ctx.Build(pctx, android.BuildParams{
3069 Rule: blueprint.Phony,
3070 Output: android.PathForPhony(ctx, "xref_cxx"),
3071 Inputs: xrefTargets,
3072 //Default: true,
3073 })
3074 }
3075}
3076
Colin Cross06a931b2015-10-28 17:23:31 -07003077var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003078var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003079var BoolPtr = proptools.BoolPtr
3080var String = proptools.String
3081var StringPtr = proptools.StringPtr