blob: 778531ad568618d3d2f3ed252308cde8488147a4 [file] [log] [blame]
Colin Cross5049f022015-03-18 13:28:46 -07001// Copyright 2015 Google Inc. All rights reserved.
Colin Cross3f40fa42015-01-30 17:27:36 -08002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package cc
16
17// This file contains the module types for compiling C/C++ for Android, and converts the properties
18// into the flags and filenames necessary to pass to the compiler. The final creation of the rules
19// is handled in builder.go
20
21import (
Colin Cross41955e82019-05-29 14:40:35 -070022 "fmt"
Logan Chien41eabe62019-04-10 13:33:58 +080023 "io"
Dan Albert9e10cd42016-08-03 14:12:14 -070024 "strconv"
Colin Cross3f40fa42015-01-30 17:27:36 -080025 "strings"
26
Colin Cross97ba0732015-03-23 17:50:24 -070027 "github.com/google/blueprint"
Colin Cross06a931b2015-10-28 17:23:31 -070028 "github.com/google/blueprint/proptools"
Colin Cross97ba0732015-03-23 17:50:24 -070029
Colin Cross635c3b02016-05-18 15:37:25 -070030 "android/soong/android"
Colin Crossb98c8b02016-07-29 13:44:28 -070031 "android/soong/cc/config"
Colin Cross5049f022015-03-18 13:28:46 -070032 "android/soong/genrule"
Colin Cross3f40fa42015-01-30 17:27:36 -080033)
34
Colin Cross463a90e2015-06-17 14:20:06 -070035func init() {
Paul Duffin036e7002019-12-19 19:16:28 +000036 RegisterCCBuildComponents(android.InitRegistrationContext)
Colin Cross463a90e2015-06-17 14:20:06 -070037
Paul Duffin036e7002019-12-19 19:16:28 +000038 pctx.Import("android/soong/cc/config")
39}
40
41func RegisterCCBuildComponents(ctx android.RegistrationContext) {
42 ctx.RegisterModuleType("cc_defaults", defaultsFactory)
43
44 ctx.PreDepsMutators(func(ctx android.RegisterMutatorsContext) {
Inseob Kim64c43952019-08-26 16:52:35 +090045 ctx.BottomUp("vndk", VndkMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070046 ctx.BottomUp("link", LinkageMutator).Parallel()
Jooyung Hanb90e4912019-12-09 18:21:48 +090047 ctx.BottomUp("ndk_api", NdkApiMutator).Parallel()
Roland Levillain9b5fde92019-06-28 15:41:19 +010048 ctx.BottomUp("test_per_src", TestPerSrcMutator).Parallel()
Jiyong Park25fc6a92018-11-18 18:02:45 +090049 ctx.BottomUp("version", VersionMutator).Parallel()
Colin Crosse40b4ea2018-10-02 22:25:58 -070050 ctx.BottomUp("begin", BeginMutator).Parallel()
Inseob Kimac1e9862019-12-09 18:15:47 +090051 ctx.BottomUp("sysprop_cc", SyspropMutator).Parallel()
Inseob Kimeec88e12020-01-22 11:11:29 +090052 ctx.BottomUp("vendor_snapshot", VendorSnapshotMutator).Parallel()
53 ctx.BottomUp("vendor_snapshot_source", VendorSnapshotSourceMutator).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070054 })
Colin Cross16b23492016-01-06 14:41:07 -080055
Paul Duffin036e7002019-12-19 19:16:28 +000056 ctx.PostDepsMutators(func(ctx android.RegisterMutatorsContext) {
Colin Cross1e676be2016-10-12 14:38:15 -070057 ctx.TopDown("asan_deps", sanitizerDepsMutator(asan))
58 ctx.BottomUp("asan", sanitizerMutator(asan)).Parallel()
Colin Cross16b23492016-01-06 14:41:07 -080059
Evgenii Stepanovd97a6e92018-08-02 16:19:13 -070060 ctx.TopDown("hwasan_deps", sanitizerDepsMutator(hwasan))
61 ctx.BottomUp("hwasan", sanitizerMutator(hwasan)).Parallel()
62
Mitch Phillipsbfeade62019-05-01 14:42:05 -070063 ctx.TopDown("fuzzer_deps", sanitizerDepsMutator(fuzzer))
64 ctx.BottomUp("fuzzer", sanitizerMutator(fuzzer)).Parallel()
65
Jiyong Park1d1119f2019-07-29 21:27:18 +090066 // cfi mutator shouldn't run before sanitizers that return true for
67 // incompatibleWithCfi()
Vishwath Mohanb743e9c2017-11-01 09:20:21 +000068 ctx.TopDown("cfi_deps", sanitizerDepsMutator(cfi))
69 ctx.BottomUp("cfi", sanitizerMutator(cfi)).Parallel()
70
Peter Collingbourne8c7e6e22018-11-19 16:03:58 -080071 ctx.TopDown("scs_deps", sanitizerDepsMutator(scs))
72 ctx.BottomUp("scs", sanitizerMutator(scs)).Parallel()
73
Colin Cross1e676be2016-10-12 14:38:15 -070074 ctx.TopDown("tsan_deps", sanitizerDepsMutator(tsan))
75 ctx.BottomUp("tsan", sanitizerMutator(tsan)).Parallel()
Dan Willemsen581341d2017-02-09 16:16:31 -080076
Colin Cross0b908332019-06-19 23:00:20 -070077 ctx.TopDown("sanitize_runtime_deps", sanitizerRuntimeDepsMutator).Parallel()
Jiyong Park379de2f2018-12-19 02:47:14 +090078 ctx.BottomUp("sanitize_runtime", sanitizerRuntimeMutator).Parallel()
Ivan Lozano30c5db22018-02-21 15:49:20 -080079
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -080080 ctx.BottomUp("coverage", coverageMutator).Parallel()
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -080081 ctx.TopDown("vndk_deps", sabiDepsMutator)
Stephen Craneba090d12017-05-09 15:44:35 -070082
83 ctx.TopDown("lto_deps", ltoDepsMutator)
84 ctx.BottomUp("lto", ltoMutator).Parallel()
Jooyung Hana70f0672019-01-18 15:20:43 +090085
86 ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
Colin Cross1e676be2016-10-12 14:38:15 -070087 })
Colin Crossb98c8b02016-07-29 13:44:28 -070088
Sasha Smundak2a4549e2018-11-05 16:49:08 -080089 android.RegisterSingletonType("kythe_extract_all", kytheExtractAllFactory)
Colin Cross463a90e2015-06-17 14:20:06 -070090}
91
Colin Crossca860ac2016-01-04 14:34:37 -080092type Deps struct {
93 SharedLibs, LateSharedLibs []string
94 StaticLibs, LateStaticLibs, WholeStaticLibs []string
Colin Cross5950f382016-12-13 12:50:57 -080095 HeaderLibs []string
Logan Chien43d34c32017-12-20 01:17:32 +080096 RuntimeLibs []string
Colin Crossc472d572015-03-17 15:06:21 -070097
Peter Collingbournedc4f9862020-02-12 17:13:25 -080098 StaticUnwinderIfLegacy bool
99
Colin Cross5950f382016-12-13 12:50:57 -0800100 ReexportSharedLibHeaders, ReexportStaticLibHeaders, ReexportHeaderLibHeaders []string
Dan Willemsen490a8dc2016-06-06 18:22:19 -0700101
Colin Cross81413472016-04-11 14:37:39 -0700102 ObjFiles []string
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700103
Dan Willemsenb40aab62016-04-20 14:21:14 -0700104 GeneratedSources []string
105 GeneratedHeaders []string
Inseob Kimd110f872019-12-06 13:15:38 +0900106 GeneratedDeps []string
Dan Willemsenb40aab62016-04-20 14:21:14 -0700107
Dan Willemsenb3454ab2016-09-28 17:34:58 -0700108 ReexportGeneratedHeaders []string
109
Colin Cross97ba0732015-03-23 17:50:24 -0700110 CrtBegin, CrtEnd string
Dan Willemsena0790e32018-10-12 00:24:23 -0700111
112 // Used for host bionic
113 LinkerFlagsFile string
114 DynamicLinker string
Colin Crossc472d572015-03-17 15:06:21 -0700115}
116
Colin Crossca860ac2016-01-04 14:34:37 -0800117type PathDeps struct {
Colin Cross26c34ed2016-09-30 17:10:16 -0700118 // Paths to .so files
Jiyong Park64a44f22019-01-18 14:37:08 +0900119 SharedLibs, EarlySharedLibs, LateSharedLibs android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700120 // Paths to the dependencies to use for .so files (.so.toc files)
Jiyong Park64a44f22019-01-18 14:37:08 +0900121 SharedLibsDeps, EarlySharedLibsDeps, LateSharedLibsDeps android.Paths
Colin Cross26c34ed2016-09-30 17:10:16 -0700122 // Paths to .a files
Colin Cross635c3b02016-05-18 15:37:25 -0700123 StaticLibs, LateStaticLibs, WholeStaticLibs android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700124
Colin Cross26c34ed2016-09-30 17:10:16 -0700125 // Paths to .o files
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700126 Objs Objects
Dan Willemsen581341d2017-02-09 16:16:31 -0800127 StaticLibObjs Objects
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700128 WholeStaticLibObjs Objects
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700129
Colin Cross26c34ed2016-09-30 17:10:16 -0700130 // Paths to generated source files
Colin Cross635c3b02016-05-18 15:37:25 -0700131 GeneratedSources android.Paths
132 GeneratedHeaders android.Paths
Inseob Kimd110f872019-12-06 13:15:38 +0900133 GeneratedDeps android.Paths
Dan Willemsenb40aab62016-04-20 14:21:14 -0700134
Inseob Kimd110f872019-12-06 13:15:38 +0900135 Flags []string
136 IncludeDirs android.Paths
137 SystemIncludeDirs android.Paths
138 ReexportedDirs android.Paths
139 ReexportedSystemDirs android.Paths
140 ReexportedFlags []string
141 ReexportedGeneratedHeaders android.Paths
142 ReexportedDeps android.Paths
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700143
Colin Cross26c34ed2016-09-30 17:10:16 -0700144 // Paths to crt*.o files
Colin Cross635c3b02016-05-18 15:37:25 -0700145 CrtBegin, CrtEnd android.OptionalPath
Dan Willemsena0790e32018-10-12 00:24:23 -0700146
147 // Path to the file container flags to use with the linker
148 LinkerFlagsFile android.OptionalPath
149
150 // Path to the dynamic linker binary
151 DynamicLinker android.OptionalPath
Dan Willemsen34cc69e2015-09-23 15:26:20 -0700152}
153
Colin Cross4af21ed2019-11-04 09:37:55 -0800154// LocalOrGlobalFlags contains flags that need to have values set globally by the build system or locally by the module
155// tracked separately, in order to maintain the required ordering (most of the global flags need to go first on the
156// command line so they can be overridden by the local module flags).
157type LocalOrGlobalFlags struct {
158 CommonFlags []string // Flags that apply to C, C++, and assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700159 AsFlags []string // Flags that apply to assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800160 YasmFlags []string // Flags that apply to yasm assembly source files
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700161 CFlags []string // Flags that apply to C and C++ source files
162 ToolingCFlags []string // Flags that apply to C and C++ source files parsed by clang LibTooling tools
163 ConlyFlags []string // Flags that apply to C source files
164 CppFlags []string // Flags that apply to C++ source files
165 ToolingCppFlags []string // Flags that apply to C++ source files parsed by clang LibTooling tools
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -0700166 LdFlags []string // Flags that apply to linker command lines
Colin Cross4af21ed2019-11-04 09:37:55 -0800167}
168
169type Flags struct {
170 Local LocalOrGlobalFlags
171 Global LocalOrGlobalFlags
172
173 aidlFlags []string // Flags that apply to aidl source files
174 rsFlags []string // Flags that apply to renderscript source files
175 libFlags []string // Flags to add libraries early to the link order
176 extraLibFlags []string // Flags to add libraries late in the link order after LdFlags
177 TidyFlags []string // Flags that apply to clang-tidy
178 SAbiFlags []string // Flags that apply to header-abi-dumper
Colin Cross28344522015-04-22 13:07:53 -0700179
Colin Crossc3199482017-03-30 15:03:04 -0700180 // Global include flags that apply to C, C++, and assembly source files
Colin Cross4af21ed2019-11-04 09:37:55 -0800181 // These must be after any module include flags, which will be in CommonFlags.
Colin Crossc3199482017-03-30 15:03:04 -0700182 SystemIncludeFlags []string
183
Colin Crossb98c8b02016-07-29 13:44:28 -0700184 Toolchain config.Toolchain
Dan Willemsena03cf6d2016-09-26 15:45:04 -0700185 Tidy bool
Dan Willemsen581341d2017-02-09 16:16:31 -0800186 Coverage bool
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800187 SAbiDump bool
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800188 EmitXrefs bool // If true, generate Ninja rules to generate emitXrefs input files for Kythe
Colin Crossca860ac2016-01-04 14:34:37 -0800189
190 RequiredInstructionSet string
Colin Cross16b23492016-01-06 14:41:07 -0800191 DynamicLinker string
192
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700193 CFlagsDeps android.Paths // Files depended on by compiler flags
194 LdFlagsDeps android.Paths // Files depended on by linker flags
Colin Cross18c0c5a2016-12-01 14:45:23 -0800195
Dan Willemsen98ab3112019-08-27 21:20:40 -0700196 AssemblerWithCpp bool
197 GroupStaticLibs bool
Dan Willemsen60e62f02018-11-16 21:05:32 -0800198
Colin Cross19878da2019-03-28 14:45:07 -0700199 proto android.ProtoFlags
Colin Cross19878da2019-03-28 14:45:07 -0700200 protoC bool // Whether to use C instead of C++
201 protoOptionsFile bool // Whether to look for a .options file next to the .proto
Dan Willemsen4e0aa232019-04-10 22:59:54 -0700202
203 Yacc *YaccProperties
Colin Crossc472d572015-03-17 15:06:21 -0700204}
205
Colin Crossca860ac2016-01-04 14:34:37 -0800206// Properties used to compile all C or C++ modules
207type BaseProperties struct {
Dan Willemsen742a5452018-07-23 17:19:36 -0700208 // Deprecated. true is the default, false is invalid.
Colin Crossca860ac2016-01-04 14:34:37 -0800209 Clang *bool `android:"arch_variant"`
Colin Cross7d5136f2015-05-11 13:39:40 -0700210
211 // Minimum sdk version supported when compiling against the ndk
Nan Zhang0007d812017-11-07 10:57:05 -0800212 Sdk_version *string
Colin Cross7d5136f2015-05-11 13:39:40 -0700213
Jiyong Parkde866cb2018-12-07 23:08:36 +0900214 AndroidMkSharedLibs []string `blueprint:"mutated"`
215 AndroidMkStaticLibs []string `blueprint:"mutated"`
216 AndroidMkRuntimeLibs []string `blueprint:"mutated"`
217 AndroidMkWholeStaticLibs []string `blueprint:"mutated"`
218 HideFromMake bool `blueprint:"mutated"`
219 PreventInstall bool `blueprint:"mutated"`
220 ApexesProvidingSharedLibs []string `blueprint:"mutated"`
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700221
Justin Yun5f7f7e82019-11-18 19:52:14 +0900222 ImageVariationPrefix string `blueprint:"mutated"`
223 VndkVersion string `blueprint:"mutated"`
224 SubName string `blueprint:"mutated"`
Colin Cross5beccee2017-12-07 15:28:59 -0800225
226 // *.logtags files, to combine together in order to generate the /system/etc/event-log-tags
227 // file
228 Logtags []string
Jiyong Parkf9332f12018-02-01 00:54:12 +0900229
Yifan Hong1b3348d2020-01-21 15:53:22 -0800230 // Make this module available when building for ramdisk
231 Ramdisk_available *bool
232
Jiyong Parkf9332f12018-02-01 00:54:12 +0900233 // Make this module available when building for recovery
234 Recovery_available *bool
235
Colin Crossae6c5202019-11-20 13:35:50 -0800236 // Set by imageMutator
Colin Cross7228ecd2019-11-18 16:00:16 -0800237 CoreVariantNeeded bool `blueprint:"mutated"`
Yifan Hong1b3348d2020-01-21 15:53:22 -0800238 RamdiskVariantNeeded bool `blueprint:"mutated"`
Colin Cross7228ecd2019-11-18 16:00:16 -0800239 RecoveryVariantNeeded bool `blueprint:"mutated"`
Justin Yun5f7f7e82019-11-18 19:52:14 +0900240 ExtraVariants []string `blueprint:"mutated"`
Jiyong Parkb0788572018-12-20 22:10:17 +0900241
242 // Allows this module to use non-APEX version of libraries. Useful
243 // for building binaries that are started before APEXes are activated.
244 Bootstrap *bool
Jooyung Han097087b2019-10-22 19:32:18 +0900245
246 // Even if DeviceConfig().VndkUseCoreVariant() is set, this module must use vendor variant.
247 // see soong/cc/config/vndk.go
248 MustUseVendorVariant bool `blueprint:"mutated"`
Inseob Kim8471cda2019-11-15 09:59:12 +0900249
250 // Used by vendor snapshot to record dependencies from snapshot modules.
251 SnapshotSharedLibs []string `blueprint:"mutated"`
252 SnapshotRuntimeLibs []string `blueprint:"mutated"`
Paul Duffinf51768a2020-03-04 14:52:46 +0000253
254 Installable *bool
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700255}
256
257type VendorProperties struct {
Jiyong Park82e2bf32017-08-16 14:05:54 +0900258 // whether this module should be allowed to be directly depended by other
259 // modules with `vendor: true`, `proprietary: true`, or `vendor_available:true`.
Justin Yun5f7f7e82019-11-18 19:52:14 +0900260 // In addition, this module should be allowed to be directly depended by
261 // product modules with `product_specific: true`.
262 // If set to true, three variants will be built separately, one like
263 // normal, another limited to the set of libraries and headers
264 // that are exposed to /vendor modules, and the other to /product modules.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700265 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900266 // The vendor and product variants may be used with a different (newer) /system,
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700267 // so it shouldn't have any unversioned runtime dependencies, or
268 // make assumptions about the system that may not be true in the
269 // future.
270 //
Justin Yun5f7f7e82019-11-18 19:52:14 +0900271 // If set to false, this module becomes inaccessible from /vendor or /product
272 // modules.
Jiyong Park82e2bf32017-08-16 14:05:54 +0900273 //
274 // Default value is true when vndk: {enabled: true} or vendor: true.
275 //
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700276 // Nothing happens if BOARD_VNDK_VERSION isn't set in the BoardConfig.mk
Justin Yun5f7f7e82019-11-18 19:52:14 +0900277 // If PRODUCT_PRODUCT_VNDK_VERSION isn't set, product variant will not be used.
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700278 Vendor_available *bool
Jiyong Park5fb8c102018-04-09 12:03:06 +0900279
280 // whether this module is capable of being loaded with other instance
281 // (possibly an older version) of the same module in the same process.
282 // Currently, a shared library that is a member of VNDK (vndk: {enabled: true})
283 // can be double loaded in a vendor process if the library is also a
284 // (direct and indirect) dependency of an LLNDK library. Such libraries must be
285 // explicitly marked as `double_loadable: true` by the owner, or the dependency
286 // from the LLNDK lib should be cut if the lib is not designed to be double loaded.
287 Double_loadable *bool
Colin Crossca860ac2016-01-04 14:34:37 -0800288}
289
Colin Crossca860ac2016-01-04 14:34:37 -0800290type ModuleContextIntf interface {
Colin Crossca860ac2016-01-04 14:34:37 -0800291 static() bool
292 staticBinary() bool
Jiyong Park1d1119f2019-07-29 21:27:18 +0900293 header() bool
Colin Crossb98c8b02016-07-29 13:44:28 -0700294 toolchain() config.Toolchain
Jooyung Han61c41542020-03-07 03:45:53 +0900295 canUseSdk() bool
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700296 useSdk() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800297 sdkVersion() string
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -0700298 useVndk() bool
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800299 isNdk() bool
Inseob Kim9516ee92019-05-09 10:56:13 +0900300 isLlndk(config android.Config) bool
301 isLlndkPublic(config android.Config) bool
302 isVndkPrivate(config android.Config) bool
Justin Yun8effde42017-06-23 19:24:43 +0900303 isVndk() bool
304 isVndkSp() bool
Logan Chienf3511742017-10-31 18:04:35 +0800305 isVndkExt() bool
Justin Yun5f7f7e82019-11-18 19:52:14 +0900306 inProduct() bool
307 inVendor() bool
Yifan Hong1b3348d2020-01-21 15:53:22 -0800308 inRamdisk() bool
Jiyong Parkf9332f12018-02-01 00:54:12 +0900309 inRecovery() bool
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +0800310 shouldCreateSourceAbiDump() bool
Dan Willemsen8146b2f2016-03-30 21:00:30 -0700311 selectedStl() string
Colin Crossce75d2c2016-10-06 16:12:58 -0700312 baseModuleName() string
Logan Chienf3511742017-10-31 18:04:35 +0800313 getVndkExtendsModuleName() string
Yi Kong7e53c572018-02-14 18:16:12 +0800314 isPgoCompile() bool
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800315 isNDKStubLibrary() bool
Ivan Lozanobd721262018-11-27 14:33:03 -0800316 useClangLld(actx ModuleContext) bool
Logan Chiene274fc92019-12-03 11:18:32 -0800317 isForPlatform() bool
Jiyong Park58e364a2019-01-19 19:24:06 +0900318 apexName() string
Jooyung Han61c41542020-03-07 03:45:53 +0900319 apexSdkVersion() int
Jiyong Parkb0788572018-12-20 22:10:17 +0900320 hasStubsVariants() bool
321 isStubs() bool
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900322 bootstrap() bool
Vic Yangefd249e2018-11-12 20:19:56 -0800323 mustUseVendorVariant() bool
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700324 nativeCoverage() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800325}
326
327type ModuleContext interface {
Colin Cross635c3b02016-05-18 15:37:25 -0700328 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800329 ModuleContextIntf
330}
331
332type BaseModuleContext interface {
Colin Cross0ea8ba82019-06-06 14:33:29 -0700333 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -0800334 ModuleContextIntf
335}
336
Colin Cross37047f12016-12-13 17:06:13 -0800337type DepsContext interface {
338 android.BottomUpMutatorContext
339 ModuleContextIntf
340}
341
Colin Crossca860ac2016-01-04 14:34:37 -0800342type feature interface {
343 begin(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800344 deps(ctx DepsContext, deps Deps) Deps
Colin Crossca860ac2016-01-04 14:34:37 -0800345 flags(ctx ModuleContext, flags Flags) Flags
346 props() []interface{}
347}
348
349type compiler interface {
Colin Cross42742b82016-08-01 13:20:05 -0700350 compilerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800351 compilerDeps(ctx DepsContext, deps Deps) Deps
Colin Crossf18e1102017-11-16 14:33:08 -0800352 compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags
Colin Cross42742b82016-08-01 13:20:05 -0700353 compilerProps() []interface{}
354
Colin Cross76fada02016-07-27 10:31:13 -0700355 appendCflags([]string)
356 appendAsflags([]string)
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700357 compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects
Colin Crossca860ac2016-01-04 14:34:37 -0800358}
359
360type linker interface {
Colin Cross42742b82016-08-01 13:20:05 -0700361 linkerInit(ctx BaseModuleContext)
Colin Cross37047f12016-12-13 17:06:13 -0800362 linkerDeps(ctx DepsContext, deps Deps) Deps
Colin Cross42742b82016-08-01 13:20:05 -0700363 linkerFlags(ctx ModuleContext, flags Flags) Flags
364 linkerProps() []interface{}
Ivan Lozanobd721262018-11-27 14:33:03 -0800365 useClangLld(actx ModuleContext) bool
Colin Cross42742b82016-08-01 13:20:05 -0700366
Dan Willemsen5cb580f2016-09-26 17:33:01 -0700367 link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path
Colin Cross76fada02016-07-27 10:31:13 -0700368 appendLdflags([]string)
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900369 unstrippedOutputFilePath() android.Path
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700370
371 nativeCoverage() bool
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900372 coverageOutputFilePath() android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800373}
374
375type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700376 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700377 install(ctx ModuleContext, path android.Path)
Paul Duffinf51768a2020-03-04 14:52:46 +0000378 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800379 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700380 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700381 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900382 relativeInstallPath() string
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +0100383 skipInstall(mod *Module)
Colin Crossca860ac2016-01-04 14:34:37 -0800384}
385
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800386type xref interface {
387 XrefCcFiles() android.Paths
388}
389
Colin Crossc99deeb2016-04-11 15:06:20 -0700390var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700391 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
392 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
393 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
394 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
395 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800396 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700397 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
398 headerDepTag = DependencyTag{Name: "header", Library: true}
399 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
400 genSourceDepTag = DependencyTag{Name: "gen source"}
401 genHeaderDepTag = DependencyTag{Name: "gen header"}
402 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
403 objDepTag = DependencyTag{Name: "obj"}
404 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
405 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
406 reuseObjTag = DependencyTag{Name: "reuse objects"}
407 staticVariantTag = DependencyTag{Name: "static variant"}
408 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
409 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
410 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
411 runtimeDepTag = DependencyTag{Name: "runtime lib"}
412 coverageDepTag = DependencyTag{Name: "coverage"}
413 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700414)
415
Roland Levillainf89cd092019-07-29 16:22:59 +0100416func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700417 ccDepTag, ok := depTag.(DependencyTag)
418 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100419}
420
421func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700422 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100423 return ok && ccDepTag == runtimeDepTag
424}
425
426func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700427 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100428 return ok && ccDepTag == testPerSrcDepTag
429}
430
Colin Crossca860ac2016-01-04 14:34:37 -0800431// Module contains the properties and members used by all C/C++ module types, and implements
432// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
433// to construct the output file. Behavior can be customized with a Customizer interface
434type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700435 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700436 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900437 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900438 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700439
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700440 Properties BaseProperties
441 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700442
Colin Crossca860ac2016-01-04 14:34:37 -0800443 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700444 hod android.HostOrDeviceSupported
445 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700446
Paul Duffina0843f62019-12-13 19:50:38 +0000447 // Allowable SdkMemberTypes of this module type.
448 sdkMemberTypes []android.SdkMemberType
449
Colin Crossca860ac2016-01-04 14:34:37 -0800450 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700451 features []feature
452 compiler compiler
453 linker linker
454 installer installer
455 stl *stl
456 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800457 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800458 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900459 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700460 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700461 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800462
Colin Cross635c3b02016-05-18 15:37:25 -0700463 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800464
Colin Crossb98c8b02016-07-29 13:44:28 -0700465 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700466
467 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800468
469 // Flags used to compile this module
470 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700471
472 // 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 -0800473 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700474 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800475 depsInLinkOrder android.Paths
476
477 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700478 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900479
480 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800481 // Kythe (source file indexer) paths for this compilation module
482 kytheFiles android.Paths
Jooyung Han74066602020-03-20 04:29:24 +0900483
484 // For apex variants, this is set as apex.min_sdk_version
485 apexSdkVersion int
Colin Crossc472d572015-03-17 15:06:21 -0700486}
487
Ivan Lozano52767be2019-10-18 14:49:46 -0700488func (c *Module) Toc() android.OptionalPath {
489 if c.linker != nil {
490 if library, ok := c.linker.(libraryInterface); ok {
491 return library.toc()
492 }
493 }
494 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
495}
496
497func (c *Module) ApiLevel() string {
498 if c.linker != nil {
499 if stub, ok := c.linker.(*stubDecorator); ok {
500 return stub.properties.ApiLevel
501 }
502 }
503 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
504}
505
506func (c *Module) Static() bool {
507 if c.linker != nil {
508 if library, ok := c.linker.(libraryInterface); ok {
509 return library.static()
510 }
511 }
512 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
513}
514
515func (c *Module) Shared() bool {
516 if c.linker != nil {
517 if library, ok := c.linker.(libraryInterface); ok {
518 return library.shared()
519 }
520 }
521 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
522}
523
524func (c *Module) SelectedStl() string {
525 return c.stl.Properties.SelectedStl
526}
527
528func (c *Module) ToolchainLibrary() bool {
529 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
530 return true
531 }
532 return false
533}
534
535func (c *Module) NdkPrebuiltStl() bool {
536 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
537 return true
538 }
539 return false
540}
541
542func (c *Module) StubDecorator() bool {
543 if _, ok := c.linker.(*stubDecorator); ok {
544 return true
545 }
546 return false
547}
548
549func (c *Module) SdkVersion() string {
550 return String(c.Properties.Sdk_version)
551}
552
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800553func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700554 if c.linker != nil {
555 if library, ok := c.linker.(exportedFlagsProducer); ok {
556 return library.exportedDirs()
557 }
558 }
559 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
560}
561
562func (c *Module) HasStaticVariant() bool {
563 if c.staticVariant != nil {
564 return true
565 }
566 return false
567}
568
569func (c *Module) GetStaticVariant() LinkableInterface {
570 return c.staticVariant
571}
572
573func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
574 c.depsInLinkOrder = depsInLinkOrder
575}
576
577func (c *Module) GetDepsInLinkOrder() []android.Path {
578 return c.depsInLinkOrder
579}
580
581func (c *Module) StubsVersions() []string {
582 if c.linker != nil {
583 if library, ok := c.linker.(*libraryDecorator); ok {
584 return library.Properties.Stubs.Versions
585 }
586 }
587 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
588}
589
590func (c *Module) CcLibrary() bool {
591 if c.linker != nil {
592 if _, ok := c.linker.(*libraryDecorator); ok {
593 return true
594 }
595 }
596 return false
597}
598
599func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700600 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700601 return true
602 }
603 return false
604}
605
Ivan Lozano2b262972019-11-21 12:30:50 -0800606func (c *Module) NonCcVariants() bool {
607 return false
608}
609
Ivan Lozano183a3212019-10-18 14:18:45 -0700610func (c *Module) SetBuildStubs() {
611 if c.linker != nil {
612 if library, ok := c.linker.(*libraryDecorator); ok {
613 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700614 c.Properties.HideFromMake = true
615 c.sanitize = nil
616 c.stl = nil
617 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700618 return
619 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900620 if _, ok := c.linker.(*llndkStubDecorator); ok {
621 c.Properties.HideFromMake = true
622 return
623 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700624 }
625 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
626}
627
Ivan Lozano52767be2019-10-18 14:49:46 -0700628func (c *Module) BuildStubs() bool {
629 if c.linker != nil {
630 if library, ok := c.linker.(*libraryDecorator); ok {
631 return library.buildStubs()
632 }
633 }
634 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
635}
636
Ivan Lozano183a3212019-10-18 14:18:45 -0700637func (c *Module) SetStubsVersions(version string) {
638 if c.linker != nil {
639 if library, ok := c.linker.(*libraryDecorator); ok {
640 library.MutatedProperties.StubsVersion = version
641 return
642 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900643 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
644 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
645 return
646 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700647 }
648 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
649}
650
Jooyung Han0c4e0162020-02-26 22:45:42 +0900651func (c *Module) StubsVersion() string {
652 if c.linker != nil {
653 if library, ok := c.linker.(*libraryDecorator); ok {
654 return library.MutatedProperties.StubsVersion
655 }
Jooyung Han67a96cd2020-03-13 15:23:36 +0900656 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
657 return llndk.libraryDecorator.MutatedProperties.StubsVersion
658 }
Jooyung Han0c4e0162020-02-26 22:45:42 +0900659 }
660 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
661}
662
Ivan Lozano183a3212019-10-18 14:18:45 -0700663func (c *Module) SetStatic() {
664 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700665 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700666 library.setStatic()
667 return
668 }
669 }
670 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
671}
672
673func (c *Module) SetShared() {
674 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700675 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700676 library.setShared()
677 return
678 }
679 }
680 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
681}
682
683func (c *Module) BuildStaticVariant() bool {
684 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700685 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700686 return library.buildStatic()
687 }
688 }
689 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
690}
691
692func (c *Module) BuildSharedVariant() bool {
693 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700694 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700695 return library.buildShared()
696 }
697 }
698 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
699}
700
701func (c *Module) Module() android.Module {
702 return c
703}
704
Jiyong Parkc20eee32018-09-05 22:36:17 +0900705func (c *Module) OutputFile() android.OptionalPath {
706 return c.outputFile
707}
708
Ivan Lozano183a3212019-10-18 14:18:45 -0700709var _ LinkableInterface = (*Module)(nil)
710
Jiyong Park719b4462019-01-13 00:39:51 +0900711func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900712 if c.linker != nil {
713 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900714 }
715 return nil
716}
717
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900718func (c *Module) CoverageOutputFile() android.OptionalPath {
719 if c.linker != nil {
720 return c.linker.coverageOutputFilePath()
721 }
722 return android.OptionalPath{}
723}
724
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900725func (c *Module) RelativeInstallPath() string {
726 if c.installer != nil {
727 return c.installer.relativeInstallPath()
728 }
729 return ""
730}
731
Jooyung Han344d5432019-08-23 11:17:39 +0900732func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900733 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900734}
735
Colin Cross36242852017-06-23 15:06:31 -0700736func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700737 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800738 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700739 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800740 }
741 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700742 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800743 }
744 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700745 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800746 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700747 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700748 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700749 }
Colin Cross16b23492016-01-06 14:41:07 -0800750 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700751 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800752 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800753 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700754 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800755 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800756 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700757 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800758 }
Justin Yun8effde42017-06-23 19:24:43 +0900759 if c.vndkdep != nil {
760 c.AddProperties(c.vndkdep.props()...)
761 }
Stephen Craneba090d12017-05-09 15:44:35 -0700762 if c.lto != nil {
763 c.AddProperties(c.lto.props()...)
764 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700765 if c.pgo != nil {
766 c.AddProperties(c.pgo.props()...)
767 }
Colin Crossca860ac2016-01-04 14:34:37 -0800768 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700769 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800770 }
Colin Crossc472d572015-03-17 15:06:21 -0700771
Colin Crossa9d8bee2018-10-02 13:59:46 -0700772 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
773 switch class {
774 case android.Device:
775 return ctx.Config().DevicePrefer32BitExecutables()
776 case android.HostCross:
777 // Windows builds always prefer 32-bit
778 return true
779 default:
780 return false
781 }
782 })
Colin Cross36242852017-06-23 15:06:31 -0700783 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900784 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900785 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900786 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900787
Colin Cross36242852017-06-23 15:06:31 -0700788 return c
Colin Crossc472d572015-03-17 15:06:21 -0700789}
790
Colin Crossb916a382016-07-29 17:28:03 -0700791// Returns true for dependency roots (binaries)
792// TODO(ccross): also handle dlopenable libraries
793func (c *Module) isDependencyRoot() bool {
794 if root, ok := c.linker.(interface {
795 isDependencyRoot() bool
796 }); ok {
797 return root.isDependencyRoot()
798 }
799 return false
800}
801
Justin Yun5f7f7e82019-11-18 19:52:14 +0900802// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
803// "product" and "vendor" variant modules return true for this function.
804// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
805// "soc_specific: true" and more vendor installed modules are included here.
806// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
807// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700808func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900809 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700810}
811
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800812func (c *Module) isCoverageVariant() bool {
813 return c.coverage.Properties.IsCoverageVariant
814}
815
Peter Collingbournead84f972019-12-17 16:46:18 -0800816func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800817 return inList(c.Name(), ndkMigratedLibs)
818}
819
Inseob Kim9516ee92019-05-09 10:56:13 +0900820func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800821 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900822 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800823}
824
Inseob Kim9516ee92019-05-09 10:56:13 +0900825func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800826 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900827 name := c.BaseModuleName()
828 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800829}
830
Inseob Kim9516ee92019-05-09 10:56:13 +0900831func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800832 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900833 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800834}
835
Ivan Lozano52767be2019-10-18 14:49:46 -0700836func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800837 if vndkdep := c.vndkdep; vndkdep != nil {
838 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900839 }
840 return false
841}
842
Yi Kong7e53c572018-02-14 18:16:12 +0800843func (c *Module) isPgoCompile() bool {
844 if pgo := c.pgo; pgo != nil {
845 return pgo.Properties.PgoCompile
846 }
847 return false
848}
849
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800850func (c *Module) isNDKStubLibrary() bool {
851 if _, ok := c.compiler.(*stubDecorator); ok {
852 return true
853 }
854 return false
855}
856
Logan Chienf3511742017-10-31 18:04:35 +0800857func (c *Module) isVndkSp() bool {
858 if vndkdep := c.vndkdep; vndkdep != nil {
859 return vndkdep.isVndkSp()
860 }
861 return false
862}
863
864func (c *Module) isVndkExt() bool {
865 if vndkdep := c.vndkdep; vndkdep != nil {
866 return vndkdep.isVndkExt()
867 }
868 return false
869}
870
Ivan Lozano52767be2019-10-18 14:49:46 -0700871func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900872 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800873}
874
Logan Chienf3511742017-10-31 18:04:35 +0800875func (c *Module) getVndkExtendsModuleName() string {
876 if vndkdep := c.vndkdep; vndkdep != nil {
877 return vndkdep.getVndkExtendsModuleName()
878 }
879 return ""
880}
881
Justin Yun5f7f7e82019-11-18 19:52:14 +0900882// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900883// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700884func (c *Module) HasVendorVariant() bool {
885 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900886}
887
Justin Yun5f7f7e82019-11-18 19:52:14 +0900888const (
889 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
890 // against the VNDK.
891 VendorVariationPrefix = "vendor."
892
893 // ProductVariationPrefix is the variant prefix used for /product code that compiles
894 // against the VNDK.
895 ProductVariationPrefix = "product."
896)
897
898// Returns true if the module is "product" variant. Usually these modules are installed in /product
899func (c *Module) inProduct() bool {
900 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
901}
902
903// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
904func (c *Module) inVendor() bool {
905 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
906}
907
Yifan Hong1b3348d2020-01-21 15:53:22 -0800908func (c *Module) InRamdisk() bool {
909 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
910}
911
Ivan Lozano52767be2019-10-18 14:49:46 -0700912func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800913 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900914}
915
Yifan Hong1b3348d2020-01-21 15:53:22 -0800916func (c *Module) OnlyInRamdisk() bool {
917 return c.ModuleBase.InstallInRamdisk()
918}
919
Ivan Lozano52767be2019-10-18 14:49:46 -0700920func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900921 return c.ModuleBase.InstallInRecovery()
922}
923
Jiyong Park25fc6a92018-11-18 18:02:45 +0900924func (c *Module) IsStubs() bool {
925 if library, ok := c.linker.(*libraryDecorator); ok {
926 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900927 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
928 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900929 }
930 return false
931}
932
933func (c *Module) HasStubsVariants() bool {
934 if library, ok := c.linker.(*libraryDecorator); ok {
935 return len(library.Properties.Stubs.Versions) > 0
936 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700937 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
938 return len(library.Properties.Stubs.Versions) > 0
939 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900940 return false
941}
942
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900943func (c *Module) bootstrap() bool {
944 return Bool(c.Properties.Bootstrap)
945}
946
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700947func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700948 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
949 if c.Target().NativeBridge == android.NativeBridgeEnabled {
950 return false
951 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700952 return c.linker != nil && c.linker.nativeCoverage()
953}
954
Inseob Kim8471cda2019-11-15 09:59:12 +0900955func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900956 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
957 return true
958 }
959 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
960 return true
961 }
962 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
963 return true
964 }
965 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900966}
967
Jiyong Park73c54ee2019-10-22 20:31:18 +0900968func (c *Module) ExportedIncludeDirs() android.Paths {
969 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
970 return flagsProducer.exportedDirs()
971 }
Jiyong Park232e7852019-11-04 12:23:40 +0900972 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900973}
974
975func (c *Module) ExportedSystemIncludeDirs() android.Paths {
976 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
977 return flagsProducer.exportedSystemDirs()
978 }
Jiyong Park232e7852019-11-04 12:23:40 +0900979 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900980}
981
982func (c *Module) ExportedFlags() []string {
983 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
984 return flagsProducer.exportedFlags()
985 }
Jiyong Park232e7852019-11-04 12:23:40 +0900986 return nil
987}
988
989func (c *Module) ExportedDeps() android.Paths {
990 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
991 return flagsProducer.exportedDeps()
992 }
993 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900994}
995
Inseob Kimd110f872019-12-06 13:15:38 +0900996func (c *Module) ExportedGeneratedHeaders() android.Paths {
997 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
998 return flagsProducer.exportedGeneratedHeaders()
999 }
1000 return nil
1001}
1002
Jiyong Parkf1194352019-02-25 11:05:47 +09001003func isBionic(name string) bool {
1004 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001005 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001006 return true
1007 }
1008 return false
1009}
1010
Martin Stjernholm279de572019-09-10 23:18:20 +01001011func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001012 if name == "libclang_rt.hwasan-aarch64-android" {
1013 return inList("hwaddress", config.SanitizeDevice())
1014 }
1015 return isBionic(name)
1016}
1017
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001018func (c *Module) XrefCcFiles() android.Paths {
1019 return c.kytheFiles
1020}
1021
Colin Crossca860ac2016-01-04 14:34:37 -08001022type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001023 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001024 moduleContextImpl
1025}
1026
Colin Cross37047f12016-12-13 17:06:13 -08001027type depsContext struct {
1028 android.BottomUpMutatorContext
1029 moduleContextImpl
1030}
1031
Colin Crossca860ac2016-01-04 14:34:37 -08001032type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001033 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001034 moduleContextImpl
1035}
1036
Justin Yun5f7f7e82019-11-18 19:52:14 +09001037func (ctx *moduleContext) ProductSpecific() bool {
1038 return ctx.ModuleContext.ProductSpecific() ||
1039 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1040}
1041
Jiyong Park2db76922017-11-08 16:03:48 +09001042func (ctx *moduleContext) SocSpecific() bool {
1043 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001044 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001045}
1046
Colin Crossca860ac2016-01-04 14:34:37 -08001047type moduleContextImpl struct {
1048 mod *Module
1049 ctx BaseModuleContext
1050}
1051
Colin Crossb98c8b02016-07-29 13:44:28 -07001052func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001053 return ctx.mod.toolchain(ctx.ctx)
1054}
1055
1056func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001057 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001058}
1059
1060func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001061 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001062}
1063
Jiyong Park1d1119f2019-07-29 21:27:18 +09001064func (ctx *moduleContextImpl) header() bool {
1065 return ctx.mod.header()
1066}
1067
Jooyung Han61c41542020-03-07 03:45:53 +09001068func (ctx *moduleContextImpl) canUseSdk() bool {
1069 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1070}
1071
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001072func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Han61c41542020-03-07 03:45:53 +09001073 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001074 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001075 }
1076 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001077}
1078
1079func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001080 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001081 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001082 vndkVer := ctx.mod.VndkVersion()
Jooyung Han424175d2020-04-08 09:22:26 +09001083 if inList(vndkVer, ctx.ctx.Config().PlatformVersionActiveCodenames()) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001084 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001085 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001086 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001087 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001088 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001089 }
1090 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001091}
1092
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001093func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001094 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001095}
Justin Yun8effde42017-06-23 19:24:43 +09001096
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001097func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001098 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001099}
1100
Inseob Kim9516ee92019-05-09 10:56:13 +09001101func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1102 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001103}
1104
Inseob Kim9516ee92019-05-09 10:56:13 +09001105func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1106 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001107}
1108
Inseob Kim9516ee92019-05-09 10:56:13 +09001109func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1110 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001111}
1112
Logan Chienf3511742017-10-31 18:04:35 +08001113func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001114 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001115}
1116
Yi Kong7e53c572018-02-14 18:16:12 +08001117func (ctx *moduleContextImpl) isPgoCompile() bool {
1118 return ctx.mod.isPgoCompile()
1119}
1120
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001121func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1122 return ctx.mod.isNDKStubLibrary()
1123}
1124
Justin Yun8effde42017-06-23 19:24:43 +09001125func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001126 return ctx.mod.isVndkSp()
1127}
1128
1129func (ctx *moduleContextImpl) isVndkExt() bool {
1130 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001131}
1132
Vic Yangefd249e2018-11-12 20:19:56 -08001133func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001134 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001135}
1136
Justin Yun5f7f7e82019-11-18 19:52:14 +09001137func (ctx *moduleContextImpl) inProduct() bool {
1138 return ctx.mod.inProduct()
1139}
1140
1141func (ctx *moduleContextImpl) inVendor() bool {
1142 return ctx.mod.inVendor()
1143}
1144
Yifan Hong1b3348d2020-01-21 15:53:22 -08001145func (ctx *moduleContextImpl) inRamdisk() bool {
1146 return ctx.mod.InRamdisk()
1147}
1148
Jiyong Parkf9332f12018-02-01 00:54:12 +09001149func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001150 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001151}
1152
Logan Chien2f2b8902018-07-10 15:01:19 +08001153// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001154func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001155 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1156 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001157 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001158
1159 if ctx.ctx.Fuchsia() {
1160 return false
1161 }
1162
Logan Chien2f2b8902018-07-10 15:01:19 +08001163 if sanitize := ctx.mod.sanitize; sanitize != nil {
1164 if !sanitize.isVariantOnProductionDevice() {
1165 return false
1166 }
1167 }
1168 if !ctx.ctx.Device() {
1169 // Host modules do not need ABI dumps.
1170 return false
1171 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001172 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001173 // Stubs do not need ABI dumps.
1174 return false
1175 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001176 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001177}
1178
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001179func (ctx *moduleContextImpl) selectedStl() string {
1180 if stl := ctx.mod.stl; stl != nil {
1181 return stl.Properties.SelectedStl
1182 }
1183 return ""
1184}
1185
Ivan Lozanobd721262018-11-27 14:33:03 -08001186func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1187 return ctx.mod.linker.useClangLld(actx)
1188}
1189
Colin Crossce75d2c2016-10-06 16:12:58 -07001190func (ctx *moduleContextImpl) baseModuleName() string {
1191 return ctx.mod.ModuleBase.BaseModuleName()
1192}
1193
Logan Chienf3511742017-10-31 18:04:35 +08001194func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1195 return ctx.mod.getVndkExtendsModuleName()
1196}
1197
Logan Chiene274fc92019-12-03 11:18:32 -08001198func (ctx *moduleContextImpl) isForPlatform() bool {
1199 return ctx.mod.IsForPlatform()
1200}
1201
Jiyong Park58e364a2019-01-19 19:24:06 +09001202func (ctx *moduleContextImpl) apexName() string {
1203 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001204}
1205
Jooyung Han61c41542020-03-07 03:45:53 +09001206func (ctx *moduleContextImpl) apexSdkVersion() int {
Jooyung Han74066602020-03-20 04:29:24 +09001207 return ctx.mod.apexSdkVersion
Jooyung Han61c41542020-03-07 03:45:53 +09001208}
1209
Jiyong Parkb0788572018-12-20 22:10:17 +09001210func (ctx *moduleContextImpl) hasStubsVariants() bool {
1211 return ctx.mod.HasStubsVariants()
1212}
1213
1214func (ctx *moduleContextImpl) isStubs() bool {
1215 return ctx.mod.IsStubs()
1216}
1217
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001218func (ctx *moduleContextImpl) bootstrap() bool {
1219 return ctx.mod.bootstrap()
1220}
1221
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001222func (ctx *moduleContextImpl) nativeCoverage() bool {
1223 return ctx.mod.nativeCoverage()
1224}
1225
Colin Cross635c3b02016-05-18 15:37:25 -07001226func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001227 return &Module{
1228 hod: hod,
1229 multilib: multilib,
1230 }
1231}
1232
Colin Cross635c3b02016-05-18 15:37:25 -07001233func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001234 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001235 module.features = []feature{
1236 &tidyFeature{},
1237 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001238 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001239 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001240 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001241 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001242 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001243 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001244 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001245 return module
1246}
1247
Colin Crossce75d2c2016-10-06 16:12:58 -07001248func (c *Module) Prebuilt() *android.Prebuilt {
1249 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1250 return p.prebuilt()
1251 }
1252 return nil
1253}
1254
1255func (c *Module) Name() string {
1256 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001257 if p, ok := c.linker.(interface {
1258 Name(string) string
1259 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001260 name = p.Name(name)
1261 }
1262 return name
1263}
1264
Alex Light3d673592019-01-18 14:37:31 -08001265func (c *Module) Symlinks() []string {
1266 if p, ok := c.installer.(interface {
1267 symlinkList() []string
1268 }); ok {
1269 return p.symlinkList()
1270 }
1271 return nil
1272}
1273
Jeff Gaston294356f2017-09-27 17:05:30 -07001274// orderDeps reorders dependencies into a list such that if module A depends on B, then
1275// A will precede B in the resultant list.
1276// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001277// Note that directSharedDeps should be the analogous static library for each shared lib dep
1278func 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 -07001279 // If A depends on B, then
1280 // Every list containing A will also contain B later in the list
1281 // So, after concatenating all lists, the final instance of B will have come from the same
1282 // original list as the final instance of A
1283 // So, the final instance of B will be later in the concatenation than the final A
1284 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1285 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001286 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001287 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001288 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1289 }
1290 for _, dep := range directSharedDeps {
1291 orderedAllDeps = append(orderedAllDeps, dep)
1292 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001293 }
1294
Colin Crossb6715442017-10-24 11:13:31 -07001295 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001296
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001297 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001298 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001299 // resultant list to only what the caller has chosen to include in directStaticDeps
1300 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001301
1302 return orderedAllDeps, orderedDeclaredDeps
1303}
1304
Ivan Lozano183a3212019-10-18 14:18:45 -07001305func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001306 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001307 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001308 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1309 staticDepFiles := []android.Path{}
1310 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001311 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1312 if dep.OutputFile().Valid() {
1313 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1314 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1315 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001316 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001317 sharedDepFiles := []android.Path{}
1318 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001319 if sharedDep.HasStaticVariant() {
1320 staticAnalogue := sharedDep.GetStaticVariant()
1321 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1322 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001323 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001324 }
1325
1326 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001327 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1328 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001329
1330 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001331}
1332
Roland Levillainf89cd092019-07-29 16:22:59 +01001333func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1334 test, ok := c.linker.(testPerSrc)
1335 return ok && test.isAllTestsVariation()
1336}
1337
Justin Yun5f7f7e82019-11-18 19:52:14 +09001338func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1339 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1340 // "current", it will append the VNDK version to the name suffix.
1341 var vndkVersion string
1342 var nameSuffix string
1343 if c.inProduct() {
1344 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1345 nameSuffix = productSuffix
1346 } else {
1347 vndkVersion = ctx.DeviceConfig().VndkVersion()
1348 nameSuffix = vendorSuffix
1349 }
1350 if vndkVersion == "current" {
1351 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1352 }
1353 if c.Properties.VndkVersion != vndkVersion {
1354 // add version suffix only if the module is using different vndk version than the
1355 // version in product or vendor partition.
1356 nameSuffix += "." + c.Properties.VndkVersion
1357 }
1358 return nameSuffix
1359}
1360
Colin Cross635c3b02016-05-18 15:37:25 -07001361func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001362 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001363 //
1364 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1365 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1366 // module and return early, as this module does not produce an output file per se.
1367 if c.IsTestPerSrcAllTestsVariation() {
1368 c.outputFile = android.OptionalPath{}
1369 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001370 }
1371
Jooyung Han38002912019-05-16 04:01:54 +09001372 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001373
Inseob Kim64c43952019-08-26 16:52:35 +09001374 c.Properties.SubName = ""
1375
1376 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1377 c.Properties.SubName += nativeBridgeSuffix
1378 }
1379
Justin Yun5f7f7e82019-11-18 19:52:14 +09001380 _, llndk := c.linker.(*llndkStubDecorator)
1381 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1382 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1383 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1384 // added for product variant only when we have vendor and product variants with core
1385 // variant. The suffix is not added for vendor-only or product-only module.
1386 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1387 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001388 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1389 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1390 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001391 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1392 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001393 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001394 c.Properties.SubName += recoverySuffix
1395 }
1396
Colin Crossca860ac2016-01-04 14:34:37 -08001397 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001398 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001399 moduleContextImpl: moduleContextImpl{
1400 mod: c,
1401 },
1402 }
1403 ctx.ctx = ctx
1404
Colin Crossf18e1102017-11-16 14:33:08 -08001405 deps := c.depsToPaths(ctx)
1406 if ctx.Failed() {
1407 return
1408 }
1409
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001410 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1411 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1412 }
1413
Colin Crossca860ac2016-01-04 14:34:37 -08001414 flags := Flags{
1415 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001416 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001417 }
Colin Crossca860ac2016-01-04 14:34:37 -08001418 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001419 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001420 }
1421 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001422 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001423 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001424 if c.stl != nil {
1425 flags = c.stl.flags(ctx, flags)
1426 }
Colin Cross16b23492016-01-06 14:41:07 -08001427 if c.sanitize != nil {
1428 flags = c.sanitize.flags(ctx, flags)
1429 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001430 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001431 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001432 }
Stephen Craneba090d12017-05-09 15:44:35 -07001433 if c.lto != nil {
1434 flags = c.lto.flags(ctx, flags)
1435 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001436 if c.pgo != nil {
1437 flags = c.pgo.flags(ctx, flags)
1438 }
Colin Crossca860ac2016-01-04 14:34:37 -08001439 for _, feature := range c.features {
1440 flags = feature.flags(ctx, flags)
1441 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001442 if ctx.Failed() {
1443 return
1444 }
1445
Colin Cross4af21ed2019-11-04 09:37:55 -08001446 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1447 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1448 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001449
Colin Cross4af21ed2019-11-04 09:37:55 -08001450 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001451
1452 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001453 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001454 }
1455 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001456 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001457 }
1458
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001459 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001460 // We need access to all the flags seen by a source file.
1461 if c.sabi != nil {
1462 flags = c.sabi.flags(ctx, flags)
1463 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001464
Colin Cross4af21ed2019-11-04 09:37:55 -08001465 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001466
Colin Crossca860ac2016-01-04 14:34:37 -08001467 // Optimization to reduce size of build.ninja
1468 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001469 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1470 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1471 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1472 flags.Local.CFlags = []string{"$cflags"}
1473 flags.Local.CppFlags = []string{"$cppflags"}
1474 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001475
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001476 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001477 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001478 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001479 if ctx.Failed() {
1480 return
1481 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001482 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001483 }
1484
Colin Crossca860ac2016-01-04 14:34:37 -08001485 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001486 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001487 if ctx.Failed() {
1488 return
1489 }
Colin Cross635c3b02016-05-18 15:37:25 -07001490 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001491
1492 // If a lib is directly included in any of the APEXes, unhide the stubs
1493 // variant having the latest version gets visible to make. In addition,
1494 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1495 // force anything in the make world to link against the stubs library.
1496 // (unless it is explicitly referenced via .bootstrap suffix or the
1497 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001498 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001499 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001500 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001501 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001502 c.Properties.HideFromMake = false // unhide
1503 // Note: this is still non-installable
1504 }
Inseob Kimac775b22020-03-03 22:06:32 +09001505
1506 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1507 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1508 if isSnapshotAware(ctx, c) {
1509 i.collectHeadersForSnapshot(ctx)
1510 }
1511 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001512 }
Colin Cross5049f022015-03-18 13:28:46 -07001513
Inseob Kim1f086e22019-05-09 13:29:15 +09001514 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001515 c.installer.install(ctx, c.outputFile.Path())
1516 if ctx.Failed() {
1517 return
Colin Crossca860ac2016-01-04 14:34:37 -08001518 }
Paul Duffinf51768a2020-03-04 14:52:46 +00001519 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1520 // If the module has been specifically configure to not be installed then
1521 // skip the installation as otherwise it will break when running inside make
1522 // as the output path to install will not be specified. Not all uninstallable
1523 // modules can skip installation as some are needed for resolving make side
1524 // dependencies.
1525 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001526 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001527}
1528
Colin Cross0ea8ba82019-06-06 14:33:29 -07001529func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001530 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001531 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001532 }
Colin Crossca860ac2016-01-04 14:34:37 -08001533 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001534}
1535
Colin Crossca860ac2016-01-04 14:34:37 -08001536func (c *Module) begin(ctx BaseModuleContext) {
1537 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001538 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001539 }
Colin Crossca860ac2016-01-04 14:34:37 -08001540 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001541 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001542 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001543 if c.stl != nil {
1544 c.stl.begin(ctx)
1545 }
Colin Cross16b23492016-01-06 14:41:07 -08001546 if c.sanitize != nil {
1547 c.sanitize.begin(ctx)
1548 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001549 if c.coverage != nil {
1550 c.coverage.begin(ctx)
1551 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001552 if c.sabi != nil {
1553 c.sabi.begin(ctx)
1554 }
Justin Yun8effde42017-06-23 19:24:43 +09001555 if c.vndkdep != nil {
1556 c.vndkdep.begin(ctx)
1557 }
Stephen Craneba090d12017-05-09 15:44:35 -07001558 if c.lto != nil {
1559 c.lto.begin(ctx)
1560 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001561 if c.pgo != nil {
1562 c.pgo.begin(ctx)
1563 }
Colin Crossca860ac2016-01-04 14:34:37 -08001564 for _, feature := range c.features {
1565 feature.begin(ctx)
1566 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001567 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001568 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001569 if err != nil {
1570 ctx.PropertyErrorf("sdk_version", err.Error())
1571 }
Nan Zhang0007d812017-11-07 10:57:05 -08001572 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001573 }
Colin Crossca860ac2016-01-04 14:34:37 -08001574}
1575
Colin Cross37047f12016-12-13 17:06:13 -08001576func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001577 deps := Deps{}
1578
1579 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001580 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001581 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001582 // Add the PGO dependency (the clang_rt.profile runtime library), which
1583 // sometimes depends on symbols from libgcc, before libgcc gets added
1584 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001585 if c.pgo != nil {
1586 deps = c.pgo.deps(ctx, deps)
1587 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001588 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001589 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001590 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001591 if c.stl != nil {
1592 deps = c.stl.deps(ctx, deps)
1593 }
Colin Cross16b23492016-01-06 14:41:07 -08001594 if c.sanitize != nil {
1595 deps = c.sanitize.deps(ctx, deps)
1596 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001597 if c.coverage != nil {
1598 deps = c.coverage.deps(ctx, deps)
1599 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001600 if c.sabi != nil {
1601 deps = c.sabi.deps(ctx, deps)
1602 }
Justin Yun8effde42017-06-23 19:24:43 +09001603 if c.vndkdep != nil {
1604 deps = c.vndkdep.deps(ctx, deps)
1605 }
Stephen Craneba090d12017-05-09 15:44:35 -07001606 if c.lto != nil {
1607 deps = c.lto.deps(ctx, deps)
1608 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001609 for _, feature := range c.features {
1610 deps = feature.deps(ctx, deps)
1611 }
1612
Colin Crossb6715442017-10-24 11:13:31 -07001613 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1614 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1615 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1616 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1617 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1618 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001619 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001620
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001621 for _, lib := range deps.ReexportSharedLibHeaders {
1622 if !inList(lib, deps.SharedLibs) {
1623 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1624 }
1625 }
1626
1627 for _, lib := range deps.ReexportStaticLibHeaders {
1628 if !inList(lib, deps.StaticLibs) {
1629 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1630 }
1631 }
1632
Colin Cross5950f382016-12-13 12:50:57 -08001633 for _, lib := range deps.ReexportHeaderLibHeaders {
1634 if !inList(lib, deps.HeaderLibs) {
1635 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1636 }
1637 }
1638
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001639 for _, gen := range deps.ReexportGeneratedHeaders {
1640 if !inList(gen, deps.GeneratedHeaders) {
1641 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1642 }
1643 }
1644
Colin Crossc99deeb2016-04-11 15:06:20 -07001645 return deps
1646}
1647
Dan Albert7e9d2952016-08-04 13:02:36 -07001648func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001649 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001650 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001651 moduleContextImpl: moduleContextImpl{
1652 mod: c,
1653 },
1654 }
1655 ctx.ctx = ctx
1656
Colin Crossca860ac2016-01-04 14:34:37 -08001657 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001658}
1659
Jiyong Park7ed9de32018-10-15 22:25:07 +09001660// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001661func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001662 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1663 version := name[sharp+1:]
1664 libname := name[:sharp]
1665 return libname, version
1666 }
1667 return name, ""
1668}
1669
Colin Cross1e676be2016-10-12 14:38:15 -07001670func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001671 if !c.Enabled() {
1672 return
1673 }
1674
Colin Cross37047f12016-12-13 17:06:13 -08001675 ctx := &depsContext{
1676 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001677 moduleContextImpl: moduleContextImpl{
1678 mod: c,
1679 },
1680 }
1681 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001682
Colin Crossc99deeb2016-04-11 15:06:20 -07001683 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001684
Dan Albert914449f2016-06-17 16:45:24 -07001685 variantNdkLibs := []string{}
1686 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001687 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001688 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001689
Inseob Kimeec88e12020-01-22 11:11:29 +09001690 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001691 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001692 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001693 // 1. Name of an NDK library that refers to a prebuilt module.
1694 // For each of these, it adds the name of the prebuilt module (which will be in
1695 // prebuilts/ndk) to the list of nonvariant libs.
1696 // 2. Name of an NDK library that refers to an ndk_library module.
1697 // For each of these, it adds the name of the ndk_library module to the list of
1698 // variant libs.
1699 // 3. Anything else (so anything that isn't an NDK library).
1700 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001701 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001702 // The caller can then know to add the variantLibs dependencies differently from the
1703 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001704
Inseob Kim9516ee92019-05-09 10:56:13 +09001705 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001706 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1707
1708 rewriteVendorLibs := func(lib string) string {
1709 if isLlndkLibrary(lib, ctx.Config()) {
1710 return lib + llndkLibrarySuffix
1711 }
1712
1713 // only modules with BOARD_VNDK_VERSION uses snapshot.
1714 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1715 return lib
1716 }
1717
1718 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1719 return snapshot
1720 }
1721
1722 return lib
1723 }
1724
1725 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001726 variantLibs = []string{}
1727 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001728 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001729 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001730 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001731 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1732 if !inList(name, ndkMigratedLibs) {
1733 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001734 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001735 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001736 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001737 } else if ctx.useVndk() {
1738 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001739 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001740 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001741 if actx.OtherModuleExists(vendorPublicLib) {
1742 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1743 } else {
1744 // This can happen if vendor_public_library module is defined in a
1745 // namespace that isn't visible to the current module. In that case,
1746 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001747 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001748 }
Dan Albert914449f2016-06-17 16:45:24 -07001749 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001750 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001751 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001752 }
1753 }
Dan Albert914449f2016-06-17 16:45:24 -07001754 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001755 }
1756
Inseob Kimeec88e12020-01-22 11:11:29 +09001757 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1758 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1759 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1760 if ctx.useVndk() {
1761 for idx, lib := range deps.RuntimeLibs {
1762 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1763 }
1764 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001765 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001766
Jiyong Park7e636d02019-01-28 16:16:54 +09001767 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001768 if c.linker != nil {
1769 if library, ok := c.linker.(*libraryDecorator); ok {
1770 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001771 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001772 }
1773 }
1774 }
1775
Inseob Kimeec88e12020-01-22 11:11:29 +09001776 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1777 // only modules with BOARD_VNDK_VERSION uses snapshot.
1778 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1779 return lib
1780 }
1781
1782 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1783 return snapshot
1784 }
1785
1786 return lib
1787 }
1788
1789 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001790 for _, lib := range deps.HeaderLibs {
1791 depTag := headerDepTag
1792 if inList(lib, deps.ReexportHeaderLibHeaders) {
1793 depTag = headerExportDepTag
1794 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001795
1796 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1797
Jiyong Park7e636d02019-01-28 16:16:54 +09001798 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001799 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001800 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001801 } else {
1802 actx.AddVariationDependencies(nil, depTag, lib)
1803 }
1804 }
1805
1806 if buildStubs {
1807 // Stubs lib does not have dependency to other static/shared libraries.
1808 // Don't proceed.
1809 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001810 }
Colin Cross5950f382016-12-13 12:50:57 -08001811
Inseob Kimc0907f12019-02-08 21:00:45 +09001812 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001813 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001814
Jiyong Park5d1598f2019-02-25 22:14:17 +09001815 for _, lib := range deps.WholeStaticLibs {
1816 depTag := wholeStaticDepTag
1817 if impl, ok := syspropImplLibraries[lib]; ok {
1818 lib = impl
1819 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001820
1821 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1822
Jiyong Park5d1598f2019-02-25 22:14:17 +09001823 actx.AddVariationDependencies([]blueprint.Variation{
1824 {Mutator: "link", Variation: "static"},
1825 }, depTag, lib)
1826 }
1827
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001828 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001829 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001830 if inList(lib, deps.ReexportStaticLibHeaders) {
1831 depTag = staticExportDepTag
1832 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001833
1834 if impl, ok := syspropImplLibraries[lib]; ok {
1835 lib = impl
1836 }
1837
Inseob Kimeec88e12020-01-22 11:11:29 +09001838 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1839
Dan Willemsen59339a22018-07-22 21:18:45 -07001840 actx.AddVariationDependencies([]blueprint.Variation{
1841 {Mutator: "link", Variation: "static"},
1842 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001843 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001844
Jooyung Han74066602020-03-20 04:29:24 +09001845 // staticUnwinderDep is treated as staticDep for Q apexes
1846 // so that native libraries/binaries are linked with static unwinder
1847 // because Q libc doesn't have unwinder APIs
1848 if deps.StaticUnwinderIfLegacy {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001849 actx.AddVariationDependencies([]blueprint.Variation{
1850 {Mutator: "link", Variation: "static"},
1851 }, staticUnwinderDepTag, staticUnwinder(actx))
1852 }
1853
Inseob Kimeec88e12020-01-22 11:11:29 +09001854 for _, lib := range deps.LateStaticLibs {
1855 actx.AddVariationDependencies([]blueprint.Variation{
1856 {Mutator: "link", Variation: "static"},
1857 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1858 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001859
Ivan Lozano183a3212019-10-18 14:18:45 -07001860 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001861 var variations []blueprint.Variation
1862 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Hanc40b5192020-04-10 12:57:24 +09001863 if version != "" && VersionVariantAvailable(c) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001864 // Version is explicitly specified. i.e. libFoo#30
1865 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001866 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001867 }
1868 actx.AddVariationDependencies(variations, depTag, name)
1869
Jooyung Han0c4e0162020-02-26 22:45:42 +09001870 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001871 // The stubs library will be used when the depending module is built for APEX and
1872 // the dependent module is not in the same APEX.
Jooyung Hanc40b5192020-04-10 12:57:24 +09001873 if version == "" && VersionVariantAvailable(c) {
Jooyung Han0c4e0162020-02-26 22:45:42 +09001874 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1875 // Note that depTag.ExplicitlyVersioned is false in this case.
1876 actx.AddVariationDependencies([]blueprint.Variation{
1877 {Mutator: "link", Variation: "shared"},
1878 {Mutator: "version", Variation: ver},
1879 }, depTag, name)
1880 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001881 }
1882 }
1883
Jiyong Park7ed9de32018-10-15 22:25:07 +09001884 // shared lib names without the #version suffix
1885 var sharedLibNames []string
1886
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001887 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001888 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001889 if c.static() {
1890 depTag = SharedFromStaticDepTag
1891 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001892 if inList(lib, deps.ReexportSharedLibHeaders) {
1893 depTag = sharedExportDepTag
1894 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001895
1896 if impl, ok := syspropImplLibraries[lib]; ok {
1897 lib = impl
1898 }
1899
Jiyong Park73c54ee2019-10-22 20:31:18 +09001900 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001901 sharedLibNames = append(sharedLibNames, name)
1902
Jiyong Park25fc6a92018-11-18 18:02:45 +09001903 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001904 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001905
Jiyong Park7ed9de32018-10-15 22:25:07 +09001906 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001907 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001908 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1909 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1910 // linking against both the stubs lib and the non-stubs lib at the same time.
1911 continue
1912 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001913 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001914 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001915
Dan Willemsen59339a22018-07-22 21:18:45 -07001916 actx.AddVariationDependencies([]blueprint.Variation{
1917 {Mutator: "link", Variation: "shared"},
1918 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001919
Colin Cross68861832016-07-08 10:41:41 -07001920 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001921
1922 for _, gen := range deps.GeneratedHeaders {
1923 depTag := genHeaderDepTag
1924 if inList(gen, deps.ReexportGeneratedHeaders) {
1925 depTag = genHeaderExportDepTag
1926 }
1927 actx.AddDependency(c, depTag, gen)
1928 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001929
Colin Cross42d48b72018-08-29 14:10:52 -07001930 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001931
1932 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001933 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001934 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001935 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001936 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001937 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001938 if deps.LinkerFlagsFile != "" {
1939 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1940 }
1941 if deps.DynamicLinker != "" {
1942 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001943 }
Dan Albert914449f2016-06-17 16:45:24 -07001944
1945 version := ctx.sdkVersion()
1946 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001947 {Mutator: "ndk_api", Variation: version},
1948 {Mutator: "link", Variation: "shared"},
1949 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001950 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001951 {Mutator: "ndk_api", Variation: version},
1952 {Mutator: "link", Variation: "shared"},
1953 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001954
1955 if vndkdep := c.vndkdep; vndkdep != nil {
1956 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001957 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001958 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001959 {Mutator: "link", Variation: "shared"},
1960 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001961 }
1962 }
Colin Cross6362e272015-10-29 15:25:03 -07001963}
Colin Cross21b9a242015-03-24 14:15:58 -07001964
Colin Crosse40b4ea2018-10-02 22:25:58 -07001965func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001966 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1967 c.beginMutator(ctx)
1968 }
1969}
1970
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001971// Whether a module can link to another module, taking into
1972// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001973func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1974 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001975 // Host code is not restricted
1976 return
1977 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001978
1979 // VNDK is cc.Module supported only for now.
1980 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001981 // Though vendor code is limited by the vendor mutator,
1982 // each vendor-available module needs to check
1983 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001984 if ccTo, ok := to.(*Module); ok {
1985 if ccFrom.vndkdep != nil {
1986 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1987 }
1988 } else {
1989 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001990 }
1991 return
1992 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001993 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001994 // Platform code can link to anything
1995 return
1996 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08001997 if from.InRamdisk() {
1998 // Ramdisk code is not NDK
1999 return
2000 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002001 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002002 // Recovery code is not NDK
2003 return
2004 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002005 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002006 // These are always allowed
2007 return
2008 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002009 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002010 // These are allowed, but they don't set sdk_version
2011 return
2012 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002013 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002014 // These aren't real libraries, but are the stub shared libraries that are included in
2015 // the NDK.
2016 return
2017 }
Logan Chien834b9a62019-01-14 15:39:03 +08002018
Ivan Lozano52767be2019-10-18 14:49:46 -07002019 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002020 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2021 // to link to libc++ (non-NDK and without sdk_version).
2022 return
2023 }
2024
Ivan Lozano52767be2019-10-18 14:49:46 -07002025 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002026 // NDK code linking to platform code is never okay.
2027 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002028 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002029 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002030 }
2031
2032 // At this point we know we have two NDK libraries, but we need to
2033 // check that we're not linking against anything built against a higher
2034 // API level, as it is only valid to link against older or equivalent
2035 // APIs.
2036
Inseob Kim01a28722018-04-11 09:48:45 +09002037 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002038 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002039 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002040 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002041 // Current can't be linked against by anything else.
2042 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002043 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002044 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002045 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002046 if err != nil {
2047 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002048 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002049 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002050 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002051 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002052 if err != nil {
2053 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002054 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002055 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002056 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002057
Inseob Kim01a28722018-04-11 09:48:45 +09002058 if toApi > fromApi {
2059 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002060 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002061 }
2062 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002063 }
Dan Albert202fe492017-12-15 13:56:59 -08002064
2065 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002066 fromStl := from.SelectedStl()
2067 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002068 if fromStl == "" || toStl == "" {
2069 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002070 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002071 // We can be permissive with the system "STL" since it is only the C++
2072 // ABI layer, but in the future we should make sure that everyone is
2073 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002074 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002075 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002076 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2077 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002078 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002079}
2080
Jiyong Park5fb8c102018-04-09 12:03:06 +09002081// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002082// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2083// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002084// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002085func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2086 check := func(child, parent android.Module) bool {
2087 to, ok := child.(*Module)
2088 if !ok {
2089 // follow thru cc.Defaults, etc.
2090 return true
2091 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002092
Jooyung Hana70f0672019-01-18 15:20:43 +09002093 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2094 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002095 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002096
2097 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002098 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002099 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002100 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002101
Jooyung Han0302a842019-10-30 18:43:49 +09002102 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002103 return false
2104 }
2105
2106 var stringPath []string
2107 for _, m := range ctx.GetWalkPath() {
2108 stringPath = append(stringPath, m.Name())
2109 }
2110 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2111 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2112 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2113 return false
2114 }
2115 if module, ok := ctx.Module().(*Module); ok {
2116 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002117 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002118 ctx.WalkDeps(check)
2119 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002120 }
2121 }
2122}
2123
Colin Crossc99deeb2016-04-11 15:06:20 -07002124// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002125func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002126 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002127
Ivan Lozano183a3212019-10-18 14:18:45 -07002128 directStaticDeps := []LinkableInterface{}
2129 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002130
Inseob Kim9516ee92019-05-09 10:56:13 +09002131 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2132
Inseob Kim69378442019-06-03 19:10:47 +09002133 reexportExporter := func(exporter exportedFlagsProducer) {
2134 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2135 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2136 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2137 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002138 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002139 }
2140
Colin Crossd11fcda2017-10-23 17:59:01 -07002141 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002142 depName := ctx.OtherModuleName(dep)
2143 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002144
Ivan Lozano52767be2019-10-18 14:49:46 -07002145 ccDep, ok := dep.(LinkableInterface)
2146 if !ok {
2147
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002148 // handling for a few module types that aren't cc Module but that are also supported
2149 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002150 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002152 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2153 genRule.GeneratedSourceFiles()...)
2154 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002155 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002156 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002157 // Support exported headers from a generated_sources dependency
2158 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002159 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002160 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002161 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002162 genRule.GeneratedSourceFiles()...)
2163 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002164 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002165 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002166 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002167 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002168 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002169 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2170 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002171 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002172 // 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 +09002173 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002174
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002175 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002176 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002177 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002178 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002179 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002180 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002181 files := genRule.GeneratedSourceFiles()
2182 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002183 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002184 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002185 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 -07002186 }
2187 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002188 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002189 }
Colin Crossca860ac2016-01-04 14:34:37 -08002190 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002191 return
2192 }
2193
Colin Crossfe17f6f2019-03-28 19:30:56 -07002194 if depTag == android.ProtoPluginDepTag {
2195 return
2196 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002197 if depTag == llndkImplDep {
2198 return
2199 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002200
Colin Crossd11fcda2017-10-23 17:59:01 -07002201 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002202 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2203 return
2204 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002205 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han67a96cd2020-03-13 15:23:36 +09002206 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2207 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002208 return
2209 }
2210
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002211 // re-exporting flags
2212 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002213 // reusing objects only make sense for cc.Modules.
2214 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002215 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002216 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002217 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002218 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002219 return
2220 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002221 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002222
Jiyong Parke4bb9862019-02-01 00:31:10 +09002223 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002224 // staticVariants are a cc.Module specific concept.
2225 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002226 c.staticVariant = ccDep
2227 return
2228 }
2229 }
2230
Jooyung Han74066602020-03-20 04:29:24 +09002231 // For the dependency from platform to apex, use the latest stubs
2232 c.apexSdkVersion = android.FutureApiLevel
2233 if !c.IsForPlatform() {
2234 c.apexSdkVersion = c.ApexProperties.Info.MinSdkVersion
2235 }
2236
2237 if android.InList("hwaddress", ctx.Config().SanitizeDevice()) {
2238 // In hwasan build, we override apexSdkVersion to the FutureApiLevel(10000)
2239 // so that even Q(29/Android10) apexes could use the dynamic unwinder by linking the newer stubs(e.g libc(R+)).
2240 // (b/144430859)
2241 c.apexSdkVersion = android.FutureApiLevel
2242 }
2243
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002244 if depTag == staticUnwinderDepTag {
Jooyung Han74066602020-03-20 04:29:24 +09002245 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2246 if c.apexSdkVersion <= android.SdkVersion_Android10 {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002247 depTag = StaticDepTag
2248 } else {
2249 return
2250 }
2251 }
2252
Ivan Lozano183a3212019-10-18 14:18:45 -07002253 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2254 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2255 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002256 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002257 if t, ok := depTag.(DependencyTag); ok {
2258 explicitlyVersioned = t.ExplicitlyVersioned
2259 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002260 depTag = t
2261 }
2262
Ivan Lozano183a3212019-10-18 14:18:45 -07002263 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002264 depIsStatic := false
2265 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002266 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002267 depIsStatic = true
2268 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002269 if ccDep.CcLibrary() && !depIsStatic {
2270 depIsStubs := ccDep.BuildStubs()
Jooyung Hanc40b5192020-04-10 12:57:24 +09002271 depHasStubs := VersionVariantAvailable(c) && ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002272 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002273 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002274
2275 var useThisDep bool
2276 if depIsStubs && explicitlyVersioned {
2277 // Always respect dependency to the versioned stubs (i.e. libX#10)
2278 useThisDep = true
2279 } else if !depHasStubs {
2280 // Use non-stub variant if that is the only choice
2281 // (i.e. depending on a lib without stubs.version property)
2282 useThisDep = true
2283 } else if c.IsForPlatform() {
2284 // If not building for APEX, use stubs only when it is from
2285 // an APEX (and not from platform)
2286 useThisDep = (depInPlatform != depIsStubs)
Jooyung Hanc40b5192020-04-10 12:57:24 +09002287 if c.bootstrap() {
2288 // However, for host, ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002289 // always link to non-stub variant
2290 useThisDep = !depIsStubs
2291 }
2292 } else {
2293 // If building for APEX, use stubs only when it is not from
2294 // the same APEX
2295 useThisDep = (depInSameApex != depIsStubs)
2296 }
2297
Jooyung Han0c4e0162020-02-26 22:45:42 +09002298 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2299 if useThisDep && depIsStubs && !explicitlyVersioned {
Jooyung Han74066602020-03-20 04:29:24 +09002300 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), c.apexSdkVersion)
Jooyung Han0c4e0162020-02-26 22:45:42 +09002301 if err != nil {
2302 ctx.OtherModuleErrorf(dep, err.Error())
2303 return
2304 }
2305 if versionToUse != ccDep.StubsVersion() {
2306 useThisDep = false
2307 }
2308 }
2309
Jiyong Park25fc6a92018-11-18 18:02:45 +09002310 if !useThisDep {
2311 return // stop processing this dep
2312 }
2313 }
Jooyung Han67a96cd2020-03-13 15:23:36 +09002314 if c.UseVndk() {
2315 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2316 // by default, use current version of LLNDK
2317 versionToUse := ""
2318 versions := stubsVersionsFor(ctx.Config())[depName]
2319 if c.ApexName() != "" && len(versions) > 0 {
2320 // if this is for use_vendor apex && dep has stubsVersions
2321 // apply the same rule of apex sdk enforcement to choose right version
2322 var err error
Jooyung Han74066602020-03-20 04:29:24 +09002323 versionToUse, err = c.ChooseSdkVersion(versions, c.apexSdkVersion)
Jooyung Han67a96cd2020-03-13 15:23:36 +09002324 if err != nil {
2325 ctx.OtherModuleErrorf(dep, err.Error())
2326 return
2327 }
2328 }
2329 if versionToUse != ccDep.StubsVersion() {
2330 return
2331 }
2332 }
2333 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002334
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002335 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2336
Ivan Lozano52767be2019-10-18 14:49:46 -07002337 // Exporting flags only makes sense for cc.Modules
2338 if _, ok := ccDep.(*Module); ok {
2339 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002340 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002341 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2342 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002343 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002344
Ivan Lozano52767be2019-10-18 14:49:46 -07002345 if t.ReexportFlags {
2346 reexportExporter(i)
2347 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2348 // Re-exported shared library headers must be included as well since they can help us with type information
2349 // about template instantiations (instantiated from their headers).
2350 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2351 // scripts.
2352 c.sabi.Properties.ReexportedIncludes = append(
2353 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2354 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002355 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002356 }
Logan Chienf3511742017-10-31 18:04:35 +08002357 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002358 }
2359
Colin Cross26c34ed2016-09-30 17:10:16 -07002360 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002361 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002362
Ivan Lozano52767be2019-10-18 14:49:46 -07002363 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002364 depFile := android.OptionalPath{}
2365
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002366 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002367 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002368 ptr = &depPaths.SharedLibs
2369 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002370 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002371 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002372
Jiyong Park64a44f22019-01-18 14:37:08 +09002373 case earlySharedDepTag:
2374 ptr = &depPaths.EarlySharedLibs
2375 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002376 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002377 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002378 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002379 ptr = &depPaths.LateSharedLibs
2380 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002381 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002382 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002383 ptr = nil
2384 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002385 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002386 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002387 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002388 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002389 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002390 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002391 return
2392 }
2393
Ivan Lozano52767be2019-10-18 14:49:46 -07002394 // Because the static library objects are included, this only makes sense
2395 // in the context of proper cc.Modules.
2396 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2397 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2398 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2399 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2400 for i := range missingDeps {
2401 missingDeps[i] += postfix
2402 }
2403 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002404 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002405 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2406 } else {
2407 ctx.ModuleErrorf(
2408 "non-cc.Modules cannot be included as whole static libraries.", depName)
2409 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002410 }
Colin Cross5950f382016-12-13 12:50:57 -08002411 case headerDepTag:
2412 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002413 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002414 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002415 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002416 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002417 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002418 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002419 case dynamicLinkerDepTag:
2420 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002421 }
2422
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002423 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002424 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002425 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002426 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002427 return
2428 }
2429
2430 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002431 // in static libraries act as if they were whole static libraries. The same goes for
2432 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002433 // This should only be done for cc.Modules
2434 if c, ok := ccDep.(*Module); ok {
2435 staticLib := c.linker.(libraryInterface)
2436 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2437 staticLib.objs().coverageFiles...)
2438 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2439 staticLib.objs().sAbiDumpFiles...)
2440 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002441 }
2442
Colin Cross26c34ed2016-09-30 17:10:16 -07002443 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002444 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002445 if !ctx.Config().AllowMissingDependencies() {
2446 ctx.ModuleErrorf("module %q missing output file", depName)
2447 } else {
2448 ctx.AddMissingDependencies([]string{depName})
2449 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002450 return
2451 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002452 *ptr = append(*ptr, linkFile.Path())
2453 }
2454
Colin Crossc99deeb2016-04-11 15:06:20 -07002455 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002456 dep := depFile
2457 if !dep.Valid() {
2458 dep = linkFile
2459 }
2460 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002461 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002462
Inseob Kimeec88e12020-01-22 11:11:29 +09002463 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2464
2465 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002466 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002467 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002468 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002469 return libName
2470 }
2471
2472 makeLibName := func(depName string) string {
2473 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002474 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002475 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002476 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002477
Inseob Kimeec88e12020-01-22 11:11:29 +09002478 if c, ok := ccDep.(*Module); ok {
2479 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002480 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002481 baseName := c.BaseModuleName()
Inseob Kim7ac1fa72020-03-14 01:30:34 +09002482
2483 if c.IsVndk() {
2484 return baseName + ".vendor"
2485 }
2486
Inseob Kimeec88e12020-01-22 11:11:29 +09002487 if vendorSuffixModules[baseName] {
2488 return baseName + ".vendor"
2489 } else {
2490 return baseName
2491 }
2492 }
2493 }
2494
Yifan Hong1b3348d2020-01-21 15:53:22 -08002495 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002496 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2497 // core module instead.
2498 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002499 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002500 // The vendor module in Make will have been renamed to not conflict with the core
2501 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002502 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002503 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002504 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002505 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2506 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002507 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002508 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002509 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002510 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002511 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002512 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002513 }
Logan Chien43d34c32017-12-20 01:17:32 +08002514 }
2515
2516 // Export the shared libs to Make.
2517 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002518 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002519 if ccDep.CcLibrary() {
2520 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002521 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002522 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002523 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002524 c.Properties.ApexesProvidingSharedLibs = append(
2525 c.Properties.ApexesProvidingSharedLibs, an)
2526 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002527 }
2528 }
2529
Jiyong Park27b188b2017-07-18 13:23:39 +09002530 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002531 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002532 c.Properties.AndroidMkSharedLibs = append(
2533 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002534 // Record baseLibName for snapshots.
2535 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002536 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002537 c.Properties.AndroidMkSharedLibs = append(
2538 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002539 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002540 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002541 c.Properties.AndroidMkStaticLibs = append(
2542 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002543 case runtimeDepTag:
2544 c.Properties.AndroidMkRuntimeLibs = append(
2545 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002546 // Record baseLibName for snapshots.
2547 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002548 case wholeStaticDepTag:
2549 c.Properties.AndroidMkWholeStaticLibs = append(
2550 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002551 }
Colin Crossca860ac2016-01-04 14:34:37 -08002552 })
2553
Jeff Gaston294356f2017-09-27 17:05:30 -07002554 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002555 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002556
Colin Crossdd84e052017-05-17 13:44:16 -07002557 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002558 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002559 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2560 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002561 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002562 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002563 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2564 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002565 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002566 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002567 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002568
2569 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002570 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002571 }
Colin Crossdd84e052017-05-17 13:44:16 -07002572
Colin Crossca860ac2016-01-04 14:34:37 -08002573 return depPaths
2574}
2575
2576func (c *Module) InstallInData() bool {
2577 if c.installer == nil {
2578 return false
2579 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002580 return c.installer.inData()
2581}
2582
2583func (c *Module) InstallInSanitizerDir() bool {
2584 if c.installer == nil {
2585 return false
2586 }
2587 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002588 return true
2589 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002590 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002591}
2592
Yifan Hong1b3348d2020-01-21 15:53:22 -08002593func (c *Module) InstallInRamdisk() bool {
2594 return c.InRamdisk()
2595}
2596
Jiyong Parkf9332f12018-02-01 00:54:12 +09002597func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002598 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002599}
2600
Martin Stjernholm2a6e9d02020-03-31 16:05:34 +01002601func (c *Module) SkipInstall() {
2602 if c.installer == nil {
2603 c.ModuleBase.SkipInstall()
2604 return
2605 }
2606 c.installer.skipInstall(c)
2607}
2608
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002609func (c *Module) HostToolPath() android.OptionalPath {
2610 if c.installer == nil {
2611 return android.OptionalPath{}
2612 }
2613 return c.installer.hostToolPath()
2614}
2615
Nan Zhangd4e641b2017-07-12 12:55:28 -07002616func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2617 return c.outputFile
2618}
2619
Colin Cross41955e82019-05-29 14:40:35 -07002620func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2621 switch tag {
2622 case "":
2623 if c.outputFile.Valid() {
2624 return android.Paths{c.outputFile.Path()}, nil
2625 }
2626 return android.Paths{}, nil
2627 default:
2628 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002629 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002630}
2631
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002632func (c *Module) static() bool {
2633 if static, ok := c.linker.(interface {
2634 static() bool
2635 }); ok {
2636 return static.static()
2637 }
2638 return false
2639}
2640
Jiyong Park379de2f2018-12-19 02:47:14 +09002641func (c *Module) staticBinary() bool {
2642 if static, ok := c.linker.(interface {
2643 staticBinary() bool
2644 }); ok {
2645 return static.staticBinary()
2646 }
2647 return false
2648}
2649
Jiyong Park1d1119f2019-07-29 21:27:18 +09002650func (c *Module) header() bool {
2651 if h, ok := c.linker.(interface {
2652 header() bool
2653 }); ok {
2654 return h.header()
2655 }
2656 return false
2657}
2658
Jooyung Han38002912019-05-16 04:01:54 +09002659func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002660 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002661 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2662 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002663 return "native:vndk"
2664 }
Jooyung Han38002912019-05-16 04:01:54 +09002665 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002666 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002667 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002668 if Bool(c.VendorProperties.Vendor_available) {
2669 return "native:vndk"
2670 }
2671 return "native:vndk_private"
2672 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002673 if c.inProduct() {
2674 return "native:product"
2675 }
Jooyung Han38002912019-05-16 04:01:54 +09002676 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002677 } else if c.InRamdisk() {
2678 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002679 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002680 return "native:recovery"
2681 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2682 return "native:ndk:none:none"
2683 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2684 //family, link := getNdkStlFamilyAndLinkType(c)
2685 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002686 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002687 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002688 } else {
2689 return "native:platform"
2690 }
2691}
2692
Jiyong Park9d452992018-10-03 00:38:19 +09002693// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002694// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002695func (c *Module) IsInstallableToApex() bool {
2696 if shared, ok := c.linker.(interface {
2697 shared() bool
2698 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002699 // Stub libs and prebuilt libs in a versioned SDK are not
2700 // installable to APEX even though they are shared libs.
2701 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002702 } else if _, ok := c.linker.(testPerSrc); ok {
2703 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002704 }
2705 return false
2706}
2707
Jiyong Parka90ca002019-10-07 15:47:24 +09002708func (c *Module) AvailableFor(what string) bool {
2709 if linker, ok := c.linker.(interface {
2710 availableFor(string) bool
2711 }); ok {
2712 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2713 } else {
2714 return c.ApexModuleBase.AvailableFor(what)
2715 }
2716}
2717
Paul Duffinf51768a2020-03-04 14:52:46 +00002718// Return true if the module is ever installable.
2719func (c *Module) EverInstallable() bool {
2720 return c.installer != nil &&
2721 // Check to see whether the module is actually ever installable.
2722 c.installer.everInstallable()
2723}
2724
Inseob Kim1f086e22019-05-09 13:29:15 +09002725func (c *Module) installable() bool {
Paul Duffinf51768a2020-03-04 14:52:46 +00002726 ret := c.EverInstallable() &&
2727 // Check to see whether the module has been configured to not be installed.
2728 proptools.BoolDefault(c.Properties.Installable, true) &&
2729 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002730
2731 // The platform variant doesn't need further condition. Apex variants however might not
2732 // be installable because it will likely to be included in the APEX and won't appear
2733 // in the system partition.
2734 if c.IsForPlatform() {
2735 return ret
2736 }
2737
2738 // Special case for modules that are configured to be installed to /data, which includes
2739 // test modules. For these modules, both APEX and non-APEX variants are considered as
2740 // installable. This is because even the APEX variants won't be included in the APEX, but
2741 // will anyway be installed to /data/*.
2742 // See b/146995717
2743 if c.InstallInData() {
2744 return ret
2745 }
2746
2747 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002748}
2749
Logan Chien41eabe62019-04-10 13:33:58 +08002750func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2751 if c.linker != nil {
2752 if library, ok := c.linker.(*libraryDecorator); ok {
2753 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2754 }
2755 }
2756}
2757
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002758func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002759 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002760 if cc, ok := dep.(*Module); ok {
Jiyong Park9f14b9b2020-03-01 17:29:06 +09002761 if cc.HasStubsVariants() {
2762 if depTag.Shared && depTag.Library {
2763 // dynamic dep to a stubs lib crosses APEX boundary
2764 return false
2765 }
2766 if IsRuntimeDepTag(depTag) {
2767 // runtime dep to a stubs lib also crosses APEX boundary
2768 return false
2769 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002770 }
2771 if depTag.FromStatic {
2772 // shared_lib dependency from a static lib is considered as crossing
2773 // the APEX boundary because the dependency doesn't actually is
2774 // linked; the dependency is used only during the compilation phase.
2775 return false
2776 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002777 }
2778 }
2779 return true
2780}
2781
Colin Cross2ba19d92015-05-07 15:44:20 -07002782//
Colin Crosscfad1192015-11-02 16:43:11 -08002783// Defaults
2784//
Colin Crossca860ac2016-01-04 14:34:37 -08002785type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002786 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002787 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002788 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002789}
2790
Patrice Arrudac249c712019-03-19 17:00:29 -07002791// cc_defaults provides a set of properties that can be inherited by other cc
2792// modules. A module can use the properties from a cc_defaults using
2793// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2794// merged (when possible) by prepending the default module's values to the
2795// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002796func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002797 return DefaultsFactory()
2798}
2799
Colin Cross36242852017-06-23 15:06:31 -07002800func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002801 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002802
Colin Cross36242852017-06-23 15:06:31 -07002803 module.AddProperties(props...)
2804 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002805 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002806 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002807 &BaseCompilerProperties{},
2808 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002809 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002810 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002811 &StaticProperties{},
2812 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002813 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002814 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002815 &TestProperties{},
2816 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002817 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002818 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002819 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002820 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002821 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002822 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002823 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002824 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002825 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002826 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002827 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002828 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002829 )
Colin Crosscfad1192015-11-02 16:43:11 -08002830
Jooyung Hancc372c52019-09-25 15:18:44 +09002831 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002832
2833 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002834}
2835
Jiyong Park6a43f042017-10-12 23:05:00 +09002836func squashVendorSrcs(m *Module) {
2837 if lib, ok := m.compiler.(*libraryDecorator); ok {
2838 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2839 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2840
2841 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2842 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2843 }
2844}
2845
Jiyong Parkf9332f12018-02-01 00:54:12 +09002846func squashRecoverySrcs(m *Module) {
2847 if lib, ok := m.compiler.(*libraryDecorator); ok {
2848 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2849 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2850
2851 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2852 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2853 }
2854}
2855
Colin Cross7228ecd2019-11-18 16:00:16 -08002856var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002857
Colin Cross7228ecd2019-11-18 16:00:16 -08002858func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002859 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002860 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002861 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002862
2863 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002864 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002865 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002866 }
Logan Chienf3511742017-10-31 18:04:35 +08002867
2868 if vndkdep := m.vndkdep; vndkdep != nil {
2869 if vndkdep.isVndk() {
Justin Yun98df0d12020-02-28 15:07:59 +09002870 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002871 if !vndkdep.isVndkExt() {
2872 mctx.PropertyErrorf("vndk",
2873 "must set `extends: \"...\"` to vndk extension")
Justin Yun98df0d12020-02-28 15:07:59 +09002874 } else if m.VendorProperties.Vendor_available != nil {
2875 mctx.PropertyErrorf("vendor_available",
2876 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002877 }
2878 } else {
2879 if vndkdep.isVndkExt() {
2880 mctx.PropertyErrorf("vndk",
Justin Yun98df0d12020-02-28 15:07:59 +09002881 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002882 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002883 }
2884 if m.VendorProperties.Vendor_available == nil {
2885 mctx.PropertyErrorf("vndk",
2886 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002887 }
2888 }
2889 } else {
2890 if vndkdep.isVndkSp() {
2891 mctx.PropertyErrorf("vndk",
2892 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002893 }
2894 if vndkdep.isVndkExt() {
2895 mctx.PropertyErrorf("vndk",
2896 "must set `enabled: true` to set `extends: %q`",
2897 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002898 }
Justin Yun8effde42017-06-23 19:24:43 +09002899 }
2900 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002901
Jiyong Parkf9332f12018-02-01 00:54:12 +09002902 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002903 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002904 var recoveryVariantNeeded bool = false
2905
Inseob Kim64c43952019-08-26 16:52:35 +09002906 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002907 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002908
2909 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002910 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2911 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2912 if boardVndkVersion == "current" {
2913 boardVndkVersion = platformVndkVersion
2914 }
2915 if productVndkVersion == "current" {
2916 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002917 }
2918
Justin Yun5f7f7e82019-11-18 19:52:14 +09002919 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002920 // If the device isn't compiling against the VNDK, we always
2921 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002922 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002923 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002924 // LL-NDK stubs only exist in the vendor and product variants,
2925 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002926 vendorVariants = append(vendorVariants,
2927 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002928 boardVndkVersion,
2929 )
2930 productVariants = append(productVariants,
2931 platformVndkVersion,
2932 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002933 )
Jiyong Park2a454122017-10-19 15:59:33 +09002934 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2935 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002936 vendorVariants = append(vendorVariants,
2937 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002938 boardVndkVersion,
2939 )
2940 productVariants = append(productVariants,
2941 platformVndkVersion,
2942 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002943 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002944 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002945 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2946 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002947 if snapshot, ok := m.linker.(interface {
2948 version() string
2949 }); ok {
2950 vendorVariants = append(vendorVariants, snapshot.version())
2951 } else {
2952 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2953 }
Justin Yun98df0d12020-02-28 15:07:59 +09002954 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002955 // This will be available in /system, /vendor and /product
2956 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002957 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002958 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002959 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002960 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2961 // code is PLATFORM_VNDK_VERSION.
2962 // On the other hand, vendor_available modules which are not VNDK should
2963 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002964 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002965 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002966 vendorVariants = append(vendorVariants, boardVndkVersion)
2967 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002968 }
Logan Chienf3511742017-10-31 18:04:35 +08002969 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002970 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002971 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002972 } else {
2973 // This is either in /system (or similar: /data), or is a
2974 // modules built with the NDK. Modules built with the NDK
2975 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002976 coreVariantNeeded = true
2977 }
2978
Justin Yun5f7f7e82019-11-18 19:52:14 +09002979 if boardVndkVersion != "" && productVndkVersion != "" {
2980 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2981 // The module has "product_specific: true" that does not create core variant.
2982 coreVariantNeeded = false
2983 productVariants = append(productVariants, productVndkVersion)
2984 }
2985 } else {
2986 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2987 // restriction to use system libs.
2988 // No product variants defined in this case.
2989 productVariants = []string{}
2990 }
2991
Yifan Hong1b3348d2020-01-21 15:53:22 -08002992 if Bool(m.Properties.Ramdisk_available) {
2993 ramdiskVariantNeeded = true
2994 }
2995
2996 if m.ModuleBase.InstallInRamdisk() {
2997 ramdiskVariantNeeded = true
2998 coreVariantNeeded = false
2999 }
3000
Jiyong Parkf9332f12018-02-01 00:54:12 +09003001 if Bool(m.Properties.Recovery_available) {
3002 recoveryVariantNeeded = true
3003 }
3004
3005 if m.ModuleBase.InstallInRecovery() {
3006 recoveryVariantNeeded = true
3007 coreVariantNeeded = false
3008 }
3009
Inseob Kim64c43952019-08-26 16:52:35 +09003010 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003011 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
3012 }
3013
3014 for _, variant := range android.FirstUniqueStrings(productVariants) {
3015 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003016 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003017
Yifan Hong1b3348d2020-01-21 15:53:22 -08003018 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003019 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3020 m.Properties.CoreVariantNeeded = coreVariantNeeded
3021}
3022
3023func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3024 return c.Properties.CoreVariantNeeded
3025}
3026
Yifan Hong1b3348d2020-01-21 15:53:22 -08003027func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3028 return c.Properties.RamdiskVariantNeeded
3029}
3030
Colin Cross7228ecd2019-11-18 16:00:16 -08003031func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3032 return c.Properties.RecoveryVariantNeeded
3033}
3034
3035func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003036 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003037}
3038
3039func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3040 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003041 if variant == android.RamdiskVariation {
3042 m.MakeAsPlatform()
3043 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003044 m.MakeAsPlatform()
3045 squashRecoverySrcs(m)
3046 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003047 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003048 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3049 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003050
3051 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3052 // Hide other vendor variants to avoid collision.
3053 vndkVersion := ctx.DeviceConfig().VndkVersion()
3054 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3055 m.Properties.HideFromMake = true
3056 m.SkipInstall()
3057 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003058 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3059 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3060 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3061 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003062 }
3063}
3064
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003065func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003066 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003067 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3068 }
Colin Cross6510f912017-11-29 00:27:14 -08003069 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003070}
3071
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003072func kytheExtractAllFactory() android.Singleton {
3073 return &kytheExtractAllSingleton{}
3074}
3075
3076type kytheExtractAllSingleton struct {
3077}
3078
3079func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3080 var xrefTargets android.Paths
3081 ctx.VisitAllModules(func(module android.Module) {
3082 if ccModule, ok := module.(xref); ok {
3083 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3084 }
3085 })
3086 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3087 if len(xrefTargets) > 0 {
3088 ctx.Build(pctx, android.BuildParams{
3089 Rule: blueprint.Phony,
3090 Output: android.PathForPhony(ctx, "xref_cxx"),
3091 Inputs: xrefTargets,
3092 //Default: true,
3093 })
3094 }
3095}
3096
Colin Cross06a931b2015-10-28 17:23:31 -07003097var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003098var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003099var BoolPtr = proptools.BoolPtr
3100var String = proptools.String
3101var StringPtr = proptools.StringPtr