blob: de07229f9984dfaa4d856f65797093ee31813c9e [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 Duffin0cb37b92020-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 Hanccce2f22020-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 Hanccce2f22020-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
Paul Duffin13f02712020-03-06 12:30:43 +0000373
374 // Get the deps that have been explicitly specified in the properties.
375 // Only updates the
376 linkerSpecifiedDeps(specifiedDeps specifiedDeps) specifiedDeps
377}
378
379type specifiedDeps struct {
380 sharedLibs []string
Martin Stjernholm10566a02020-03-24 01:19:52 +0000381 systemSharedLibs []string // Note nil and [] are semantically distinct.
Colin Crossca860ac2016-01-04 14:34:37 -0800382}
383
384type installer interface {
Colin Cross42742b82016-08-01 13:20:05 -0700385 installerProps() []interface{}
Colin Cross635c3b02016-05-18 15:37:25 -0700386 install(ctx ModuleContext, path android.Path)
Paul Duffin0cb37b92020-03-04 14:52:46 +0000387 everInstallable() bool
Colin Crossca860ac2016-01-04 14:34:37 -0800388 inData() bool
Vishwath Mohan1dd88392017-03-29 22:00:18 -0700389 inSanitizerDir() bool
Dan Willemsen4aa75ca2016-09-28 16:18:03 -0700390 hostToolPath() android.OptionalPath
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900391 relativeInstallPath() string
Colin Crossca860ac2016-01-04 14:34:37 -0800392}
393
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800394type xref interface {
395 XrefCcFiles() android.Paths
396}
397
Colin Crossc99deeb2016-04-11 15:06:20 -0700398var (
Ivan Lozano183a3212019-10-18 14:18:45 -0700399 sharedExportDepTag = DependencyTag{Name: "shared", Library: true, Shared: true, ReexportFlags: true}
400 earlySharedDepTag = DependencyTag{Name: "early_shared", Library: true, Shared: true}
401 lateSharedDepTag = DependencyTag{Name: "late shared", Library: true, Shared: true}
402 staticExportDepTag = DependencyTag{Name: "static", Library: true, ReexportFlags: true}
403 lateStaticDepTag = DependencyTag{Name: "late static", Library: true}
Peter Collingbournedc4f9862020-02-12 17:13:25 -0800404 staticUnwinderDepTag = DependencyTag{Name: "static unwinder", Library: true}
Ivan Lozano183a3212019-10-18 14:18:45 -0700405 wholeStaticDepTag = DependencyTag{Name: "whole static", Library: true, ReexportFlags: true}
406 headerDepTag = DependencyTag{Name: "header", Library: true}
407 headerExportDepTag = DependencyTag{Name: "header", Library: true, ReexportFlags: true}
408 genSourceDepTag = DependencyTag{Name: "gen source"}
409 genHeaderDepTag = DependencyTag{Name: "gen header"}
410 genHeaderExportDepTag = DependencyTag{Name: "gen header", ReexportFlags: true}
411 objDepTag = DependencyTag{Name: "obj"}
412 linkerFlagsDepTag = DependencyTag{Name: "linker flags file"}
413 dynamicLinkerDepTag = DependencyTag{Name: "dynamic linker"}
414 reuseObjTag = DependencyTag{Name: "reuse objects"}
415 staticVariantTag = DependencyTag{Name: "static variant"}
416 ndkStubDepTag = DependencyTag{Name: "ndk stub", Library: true}
417 ndkLateStubDepTag = DependencyTag{Name: "ndk late stub", Library: true}
418 vndkExtDepTag = DependencyTag{Name: "vndk extends", Library: true}
419 runtimeDepTag = DependencyTag{Name: "runtime lib"}
420 coverageDepTag = DependencyTag{Name: "coverage"}
421 testPerSrcDepTag = DependencyTag{Name: "test_per_src"}
Colin Crossc99deeb2016-04-11 15:06:20 -0700422)
423
Roland Levillainf89cd092019-07-29 16:22:59 +0100424func IsSharedDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700425 ccDepTag, ok := depTag.(DependencyTag)
426 return ok && ccDepTag.Shared
Roland Levillainf89cd092019-07-29 16:22:59 +0100427}
428
429func IsRuntimeDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700430 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100431 return ok && ccDepTag == runtimeDepTag
432}
433
434func IsTestPerSrcDepTag(depTag blueprint.DependencyTag) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -0700435 ccDepTag, ok := depTag.(DependencyTag)
Roland Levillainf89cd092019-07-29 16:22:59 +0100436 return ok && ccDepTag == testPerSrcDepTag
437}
438
Colin Crossca860ac2016-01-04 14:34:37 -0800439// Module contains the properties and members used by all C/C++ module types, and implements
440// the blueprint.Module interface. It delegates to compiler, linker, and installer interfaces
441// to construct the output file. Behavior can be customized with a Customizer interface
442type Module struct {
Colin Cross635c3b02016-05-18 15:37:25 -0700443 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -0700444 android.DefaultableModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +0900445 android.ApexModuleBase
Jiyong Parkd1063c12019-07-17 20:08:41 +0900446 android.SdkBase
Colin Crossc472d572015-03-17 15:06:21 -0700447
Dan Willemsen3e5bdf22017-09-13 18:37:08 -0700448 Properties BaseProperties
449 VendorProperties VendorProperties
Colin Crossfa138792015-04-24 17:31:52 -0700450
Colin Crossca860ac2016-01-04 14:34:37 -0800451 // initialize before calling Init
Colin Cross635c3b02016-05-18 15:37:25 -0700452 hod android.HostOrDeviceSupported
453 multilib android.Multilib
Colin Crossc472d572015-03-17 15:06:21 -0700454
Paul Duffina0843f62019-12-13 19:50:38 +0000455 // Allowable SdkMemberTypes of this module type.
456 sdkMemberTypes []android.SdkMemberType
457
Colin Crossca860ac2016-01-04 14:34:37 -0800458 // delegates, initialize before calling Init
Colin Crossb4ce0ec2016-09-13 13:41:39 -0700459 features []feature
460 compiler compiler
461 linker linker
462 installer installer
463 stl *stl
464 sanitize *sanitize
Dan Willemsen581341d2017-02-09 16:16:31 -0800465 coverage *coverage
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800466 sabi *sabi
Justin Yun8effde42017-06-23 19:24:43 +0900467 vndkdep *vndkdep
Stephen Craneba090d12017-05-09 15:44:35 -0700468 lto *lto
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700469 pgo *pgo
Colin Cross16b23492016-01-06 14:41:07 -0800470
Colin Cross635c3b02016-05-18 15:37:25 -0700471 outputFile android.OptionalPath
Colin Crossca860ac2016-01-04 14:34:37 -0800472
Colin Crossb98c8b02016-07-29 13:44:28 -0700473 cachedToolchain config.Toolchain
Colin Crossb916a382016-07-29 17:28:03 -0700474
475 subAndroidMkOnce map[subAndroidMkProvider]bool
Fabien Sanglardd61f1f42017-01-10 16:21:22 -0800476
477 // Flags used to compile this module
478 flags Flags
Jeff Gaston294356f2017-09-27 17:05:30 -0700479
480 // 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 -0800481 // line invocation. depsInLinkOrder stores the proper ordering of all of the transitive
Jeff Gaston294356f2017-09-27 17:05:30 -0700482 // deps of this module
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -0800483 depsInLinkOrder android.Paths
484
485 // only non-nil when this is a shared library that reuses the objects of a static library
Ivan Lozano52767be2019-10-18 14:49:46 -0700486 staticVariant LinkableInterface
Inseob Kim9516ee92019-05-09 10:56:13 +0900487
488 makeLinkType string
Sasha Smundak2a4549e2018-11-05 16:49:08 -0800489 // Kythe (source file indexer) paths for this compilation module
490 kytheFiles android.Paths
Colin Crossc472d572015-03-17 15:06:21 -0700491}
492
Ivan Lozano52767be2019-10-18 14:49:46 -0700493func (c *Module) Toc() android.OptionalPath {
494 if c.linker != nil {
495 if library, ok := c.linker.(libraryInterface); ok {
496 return library.toc()
497 }
498 }
499 panic(fmt.Errorf("Toc() called on non-library module: %q", c.BaseModuleName()))
500}
501
502func (c *Module) ApiLevel() string {
503 if c.linker != nil {
504 if stub, ok := c.linker.(*stubDecorator); ok {
505 return stub.properties.ApiLevel
506 }
507 }
508 panic(fmt.Errorf("ApiLevel() called on non-stub library module: %q", c.BaseModuleName()))
509}
510
511func (c *Module) Static() bool {
512 if c.linker != nil {
513 if library, ok := c.linker.(libraryInterface); ok {
514 return library.static()
515 }
516 }
517 panic(fmt.Errorf("Static() called on non-library module: %q", c.BaseModuleName()))
518}
519
520func (c *Module) Shared() bool {
521 if c.linker != nil {
522 if library, ok := c.linker.(libraryInterface); ok {
523 return library.shared()
524 }
525 }
526 panic(fmt.Errorf("Shared() called on non-library module: %q", c.BaseModuleName()))
527}
528
529func (c *Module) SelectedStl() string {
530 return c.stl.Properties.SelectedStl
531}
532
533func (c *Module) ToolchainLibrary() bool {
534 if _, ok := c.linker.(*toolchainLibraryDecorator); ok {
535 return true
536 }
537 return false
538}
539
540func (c *Module) NdkPrebuiltStl() bool {
541 if _, ok := c.linker.(*ndkPrebuiltStlLinker); ok {
542 return true
543 }
544 return false
545}
546
547func (c *Module) StubDecorator() bool {
548 if _, ok := c.linker.(*stubDecorator); ok {
549 return true
550 }
551 return false
552}
553
554func (c *Module) SdkVersion() string {
555 return String(c.Properties.Sdk_version)
556}
557
Ivan Lozanoe0833b12019-11-06 19:15:49 -0800558func (c *Module) IncludeDirs() android.Paths {
Ivan Lozano183a3212019-10-18 14:18:45 -0700559 if c.linker != nil {
560 if library, ok := c.linker.(exportedFlagsProducer); ok {
561 return library.exportedDirs()
562 }
563 }
564 panic(fmt.Errorf("IncludeDirs called on non-exportedFlagsProducer module: %q", c.BaseModuleName()))
565}
566
567func (c *Module) HasStaticVariant() bool {
568 if c.staticVariant != nil {
569 return true
570 }
571 return false
572}
573
574func (c *Module) GetStaticVariant() LinkableInterface {
575 return c.staticVariant
576}
577
578func (c *Module) SetDepsInLinkOrder(depsInLinkOrder []android.Path) {
579 c.depsInLinkOrder = depsInLinkOrder
580}
581
582func (c *Module) GetDepsInLinkOrder() []android.Path {
583 return c.depsInLinkOrder
584}
585
586func (c *Module) StubsVersions() []string {
587 if c.linker != nil {
588 if library, ok := c.linker.(*libraryDecorator); ok {
589 return library.Properties.Stubs.Versions
590 }
591 }
592 panic(fmt.Errorf("StubsVersions called on non-library module: %q", c.BaseModuleName()))
593}
594
595func (c *Module) CcLibrary() bool {
596 if c.linker != nil {
597 if _, ok := c.linker.(*libraryDecorator); ok {
598 return true
599 }
600 }
601 return false
602}
603
604func (c *Module) CcLibraryInterface() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -0700605 if _, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700606 return true
607 }
608 return false
609}
610
Ivan Lozano2b262972019-11-21 12:30:50 -0800611func (c *Module) NonCcVariants() bool {
612 return false
613}
614
Ivan Lozano183a3212019-10-18 14:18:45 -0700615func (c *Module) SetBuildStubs() {
616 if c.linker != nil {
617 if library, ok := c.linker.(*libraryDecorator); ok {
618 library.MutatedProperties.BuildStubs = true
Ivan Lozano52767be2019-10-18 14:49:46 -0700619 c.Properties.HideFromMake = true
620 c.sanitize = nil
621 c.stl = nil
622 c.Properties.PreventInstall = true
Ivan Lozano183a3212019-10-18 14:18:45 -0700623 return
624 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000625 if _, ok := c.linker.(*llndkStubDecorator); ok {
626 c.Properties.HideFromMake = true
627 return
628 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700629 }
630 panic(fmt.Errorf("SetBuildStubs called on non-library module: %q", c.BaseModuleName()))
631}
632
Ivan Lozano52767be2019-10-18 14:49:46 -0700633func (c *Module) BuildStubs() bool {
634 if c.linker != nil {
635 if library, ok := c.linker.(*libraryDecorator); ok {
636 return library.buildStubs()
637 }
638 }
639 panic(fmt.Errorf("BuildStubs called on non-library module: %q", c.BaseModuleName()))
640}
641
Ivan Lozano183a3212019-10-18 14:18:45 -0700642func (c *Module) SetStubsVersions(version string) {
643 if c.linker != nil {
644 if library, ok := c.linker.(*libraryDecorator); ok {
645 library.MutatedProperties.StubsVersion = version
646 return
647 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000648 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
649 llndk.libraryDecorator.MutatedProperties.StubsVersion = version
650 return
651 }
Ivan Lozano183a3212019-10-18 14:18:45 -0700652 }
653 panic(fmt.Errorf("SetStubsVersions called on non-library module: %q", c.BaseModuleName()))
654}
655
Jooyung Han03b51852020-02-26 22:45:42 +0900656func (c *Module) StubsVersion() string {
657 if c.linker != nil {
658 if library, ok := c.linker.(*libraryDecorator); ok {
659 return library.MutatedProperties.StubsVersion
660 }
Jooyung Han61b66e92020-03-21 14:21:46 +0000661 if llndk, ok := c.linker.(*llndkStubDecorator); ok {
662 return llndk.libraryDecorator.MutatedProperties.StubsVersion
663 }
Jooyung Han03b51852020-02-26 22:45:42 +0900664 }
665 panic(fmt.Errorf("StubsVersion called on non-library module: %q", c.BaseModuleName()))
666}
667
Ivan Lozano183a3212019-10-18 14:18:45 -0700668func (c *Module) SetStatic() {
669 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700670 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700671 library.setStatic()
672 return
673 }
674 }
675 panic(fmt.Errorf("SetStatic called on non-library module: %q", c.BaseModuleName()))
676}
677
678func (c *Module) SetShared() {
679 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700680 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700681 library.setShared()
682 return
683 }
684 }
685 panic(fmt.Errorf("SetShared called on non-library module: %q", c.BaseModuleName()))
686}
687
688func (c *Module) BuildStaticVariant() bool {
689 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700690 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700691 return library.buildStatic()
692 }
693 }
694 panic(fmt.Errorf("BuildStaticVariant called on non-library module: %q", c.BaseModuleName()))
695}
696
697func (c *Module) BuildSharedVariant() bool {
698 if c.linker != nil {
Ivan Lozano52767be2019-10-18 14:49:46 -0700699 if library, ok := c.linker.(libraryInterface); ok {
Ivan Lozano183a3212019-10-18 14:18:45 -0700700 return library.buildShared()
701 }
702 }
703 panic(fmt.Errorf("BuildSharedVariant called on non-library module: %q", c.BaseModuleName()))
704}
705
706func (c *Module) Module() android.Module {
707 return c
708}
709
Jiyong Parkc20eee32018-09-05 22:36:17 +0900710func (c *Module) OutputFile() android.OptionalPath {
711 return c.outputFile
712}
713
Ivan Lozano183a3212019-10-18 14:18:45 -0700714var _ LinkableInterface = (*Module)(nil)
715
Jiyong Park719b4462019-01-13 00:39:51 +0900716func (c *Module) UnstrippedOutputFile() android.Path {
Jiyong Parkaf6d8952019-01-31 12:21:23 +0900717 if c.linker != nil {
718 return c.linker.unstrippedOutputFilePath()
Jiyong Park719b4462019-01-13 00:39:51 +0900719 }
720 return nil
721}
722
Jiyong Parkee9a98d2019-08-09 14:44:36 +0900723func (c *Module) CoverageOutputFile() android.OptionalPath {
724 if c.linker != nil {
725 return c.linker.coverageOutputFilePath()
726 }
727 return android.OptionalPath{}
728}
729
Jiyong Parkb7c24df2019-02-01 12:03:59 +0900730func (c *Module) RelativeInstallPath() string {
731 if c.installer != nil {
732 return c.installer.relativeInstallPath()
733 }
734 return ""
735}
736
Jooyung Han344d5432019-08-23 11:17:39 +0900737func (c *Module) VndkVersion() string {
Justin Yun5f7f7e82019-11-18 19:52:14 +0900738 return c.Properties.VndkVersion
Jooyung Han344d5432019-08-23 11:17:39 +0900739}
740
Colin Cross36242852017-06-23 15:06:31 -0700741func (c *Module) Init() android.Module {
Dan Willemsenf923f2b2018-05-09 13:45:03 -0700742 c.AddProperties(&c.Properties, &c.VendorProperties)
Colin Crossca860ac2016-01-04 14:34:37 -0800743 if c.compiler != nil {
Colin Cross36242852017-06-23 15:06:31 -0700744 c.AddProperties(c.compiler.compilerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800745 }
746 if c.linker != nil {
Colin Cross36242852017-06-23 15:06:31 -0700747 c.AddProperties(c.linker.linkerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800748 }
749 if c.installer != nil {
Colin Cross36242852017-06-23 15:06:31 -0700750 c.AddProperties(c.installer.installerProps()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800751 }
Colin Crossa8e07cc2016-04-04 15:07:06 -0700752 if c.stl != nil {
Colin Cross36242852017-06-23 15:06:31 -0700753 c.AddProperties(c.stl.props()...)
Colin Crossa8e07cc2016-04-04 15:07:06 -0700754 }
Colin Cross16b23492016-01-06 14:41:07 -0800755 if c.sanitize != nil {
Colin Cross36242852017-06-23 15:06:31 -0700756 c.AddProperties(c.sanitize.props()...)
Colin Cross16b23492016-01-06 14:41:07 -0800757 }
Dan Willemsen581341d2017-02-09 16:16:31 -0800758 if c.coverage != nil {
Colin Cross36242852017-06-23 15:06:31 -0700759 c.AddProperties(c.coverage.props()...)
Dan Willemsen581341d2017-02-09 16:16:31 -0800760 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800761 if c.sabi != nil {
Colin Cross36242852017-06-23 15:06:31 -0700762 c.AddProperties(c.sabi.props()...)
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -0800763 }
Justin Yun8effde42017-06-23 19:24:43 +0900764 if c.vndkdep != nil {
765 c.AddProperties(c.vndkdep.props()...)
766 }
Stephen Craneba090d12017-05-09 15:44:35 -0700767 if c.lto != nil {
768 c.AddProperties(c.lto.props()...)
769 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -0700770 if c.pgo != nil {
771 c.AddProperties(c.pgo.props()...)
772 }
Colin Crossca860ac2016-01-04 14:34:37 -0800773 for _, feature := range c.features {
Colin Cross36242852017-06-23 15:06:31 -0700774 c.AddProperties(feature.props()...)
Colin Crossca860ac2016-01-04 14:34:37 -0800775 }
Colin Crossc472d572015-03-17 15:06:21 -0700776
Colin Crossa9d8bee2018-10-02 13:59:46 -0700777 c.Prefer32(func(ctx android.BaseModuleContext, base *android.ModuleBase, class android.OsClass) bool {
778 switch class {
779 case android.Device:
780 return ctx.Config().DevicePrefer32BitExecutables()
781 case android.HostCross:
782 // Windows builds always prefer 32-bit
783 return true
784 default:
785 return false
786 }
787 })
Colin Cross36242852017-06-23 15:06:31 -0700788 android.InitAndroidArchModule(c, c.hod, c.multilib)
Jiyong Park7916bfc2019-09-30 19:13:12 +0900789 android.InitApexModule(c)
Jiyong Parkd1063c12019-07-17 20:08:41 +0900790 android.InitSdkAwareModule(c)
Jooyung Han18020ea2019-11-13 10:50:48 +0900791 android.InitDefaultableModule(c)
Jiyong Park9d452992018-10-03 00:38:19 +0900792
Colin Cross36242852017-06-23 15:06:31 -0700793 return c
Colin Crossc472d572015-03-17 15:06:21 -0700794}
795
Colin Crossb916a382016-07-29 17:28:03 -0700796// Returns true for dependency roots (binaries)
797// TODO(ccross): also handle dlopenable libraries
798func (c *Module) isDependencyRoot() bool {
799 if root, ok := c.linker.(interface {
800 isDependencyRoot() bool
801 }); ok {
802 return root.isDependencyRoot()
803 }
804 return false
805}
806
Justin Yun5f7f7e82019-11-18 19:52:14 +0900807// Returns true if the module is using VNDK libraries instead of the libraries in /system/lib or /system/lib64.
808// "product" and "vendor" variant modules return true for this function.
809// When BOARD_VNDK_VERSION is set, vendor variants of "vendor_available: true", "vendor: true",
810// "soc_specific: true" and more vendor installed modules are included here.
811// When PRODUCT_PRODUCT_VNDK_VERSION is set, product variants of "vendor_available: true" or
812// "product_specific: true" modules are included here.
Ivan Lozano52767be2019-10-18 14:49:46 -0700813func (c *Module) UseVndk() bool {
Inseob Kim64c43952019-08-26 16:52:35 +0900814 return c.Properties.VndkVersion != ""
Dan Willemsen4416e5d2017-04-06 12:43:22 -0700815}
816
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800817func (c *Module) isCoverageVariant() bool {
818 return c.coverage.Properties.IsCoverageVariant
819}
820
Peter Collingbournead84f972019-12-17 16:46:18 -0800821func (c *Module) IsNdk() bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800822 return inList(c.Name(), ndkMigratedLibs)
823}
824
Inseob Kim9516ee92019-05-09 10:56:13 +0900825func (c *Module) isLlndk(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800826 // Returns true for both LLNDK (public) and LLNDK-private libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900827 return isLlndkLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800828}
829
Inseob Kim9516ee92019-05-09 10:56:13 +0900830func (c *Module) isLlndkPublic(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800831 // Returns true only for LLNDK (public) libs.
Jooyung Han0302a842019-10-30 18:43:49 +0900832 name := c.BaseModuleName()
833 return isLlndkLibrary(name, config) && !isVndkPrivateLibrary(name, config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800834}
835
Inseob Kim9516ee92019-05-09 10:56:13 +0900836func (c *Module) isVndkPrivate(config android.Config) bool {
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800837 // Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
Jooyung Han0302a842019-10-30 18:43:49 +0900838 return isVndkPrivateLibrary(c.BaseModuleName(), config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +0800839}
840
Ivan Lozano52767be2019-10-18 14:49:46 -0700841func (c *Module) IsVndk() bool {
Logan Chienf3511742017-10-31 18:04:35 +0800842 if vndkdep := c.vndkdep; vndkdep != nil {
843 return vndkdep.isVndk()
Justin Yun8effde42017-06-23 19:24:43 +0900844 }
845 return false
846}
847
Yi Kong7e53c572018-02-14 18:16:12 +0800848func (c *Module) isPgoCompile() bool {
849 if pgo := c.pgo; pgo != nil {
850 return pgo.Properties.PgoCompile
851 }
852 return false
853}
854
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -0800855func (c *Module) isNDKStubLibrary() bool {
856 if _, ok := c.compiler.(*stubDecorator); ok {
857 return true
858 }
859 return false
860}
861
Logan Chienf3511742017-10-31 18:04:35 +0800862func (c *Module) isVndkSp() bool {
863 if vndkdep := c.vndkdep; vndkdep != nil {
864 return vndkdep.isVndkSp()
865 }
866 return false
867}
868
869func (c *Module) isVndkExt() bool {
870 if vndkdep := c.vndkdep; vndkdep != nil {
871 return vndkdep.isVndkExt()
872 }
873 return false
874}
875
Ivan Lozano52767be2019-10-18 14:49:46 -0700876func (c *Module) MustUseVendorVariant() bool {
Jooyung Han097087b2019-10-22 19:32:18 +0900877 return c.isVndkSp() || c.Properties.MustUseVendorVariant
Vic Yangefd249e2018-11-12 20:19:56 -0800878}
879
Logan Chienf3511742017-10-31 18:04:35 +0800880func (c *Module) getVndkExtendsModuleName() string {
881 if vndkdep := c.vndkdep; vndkdep != nil {
882 return vndkdep.getVndkExtendsModuleName()
883 }
884 return ""
885}
886
Justin Yun5f7f7e82019-11-18 19:52:14 +0900887// Returns true only when this module is configured to have core, product and vendor
Jiyong Park82e2bf32017-08-16 14:05:54 +0900888// variants.
Ivan Lozano52767be2019-10-18 14:49:46 -0700889func (c *Module) HasVendorVariant() bool {
890 return c.IsVndk() || Bool(c.VendorProperties.Vendor_available)
Jiyong Park82e2bf32017-08-16 14:05:54 +0900891}
892
Justin Yun5f7f7e82019-11-18 19:52:14 +0900893const (
894 // VendorVariationPrefix is the variant prefix used for /vendor code that compiles
895 // against the VNDK.
896 VendorVariationPrefix = "vendor."
897
898 // ProductVariationPrefix is the variant prefix used for /product code that compiles
899 // against the VNDK.
900 ProductVariationPrefix = "product."
901)
902
903// Returns true if the module is "product" variant. Usually these modules are installed in /product
904func (c *Module) inProduct() bool {
905 return c.Properties.ImageVariationPrefix == ProductVariationPrefix
906}
907
908// Returns true if the module is "vendor" variant. Usually these modules are installed in /vendor
909func (c *Module) inVendor() bool {
910 return c.Properties.ImageVariationPrefix == VendorVariationPrefix
911}
912
Yifan Hong1b3348d2020-01-21 15:53:22 -0800913func (c *Module) InRamdisk() bool {
914 return c.ModuleBase.InRamdisk() || c.ModuleBase.InstallInRamdisk()
915}
916
Ivan Lozano52767be2019-10-18 14:49:46 -0700917func (c *Module) InRecovery() bool {
Colin Cross7228ecd2019-11-18 16:00:16 -0800918 return c.ModuleBase.InRecovery() || c.ModuleBase.InstallInRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +0900919}
920
Yifan Hong1b3348d2020-01-21 15:53:22 -0800921func (c *Module) OnlyInRamdisk() bool {
922 return c.ModuleBase.InstallInRamdisk()
923}
924
Ivan Lozano52767be2019-10-18 14:49:46 -0700925func (c *Module) OnlyInRecovery() bool {
Jiyong Parkf9332f12018-02-01 00:54:12 +0900926 return c.ModuleBase.InstallInRecovery()
927}
928
Jiyong Park25fc6a92018-11-18 18:02:45 +0900929func (c *Module) IsStubs() bool {
930 if library, ok := c.linker.(*libraryDecorator); ok {
931 return library.buildStubs()
Jiyong Park379de2f2018-12-19 02:47:14 +0900932 } else if _, ok := c.linker.(*llndkStubDecorator); ok {
933 return true
Jiyong Park25fc6a92018-11-18 18:02:45 +0900934 }
935 return false
936}
937
938func (c *Module) HasStubsVariants() bool {
939 if library, ok := c.linker.(*libraryDecorator); ok {
940 return len(library.Properties.Stubs.Versions) > 0
941 }
Peter Collingbourne3478bb22019-04-24 14:41:12 -0700942 if library, ok := c.linker.(*prebuiltLibraryLinker); ok {
943 return len(library.Properties.Stubs.Versions) > 0
944 }
Jiyong Park25fc6a92018-11-18 18:02:45 +0900945 return false
946}
947
Jiyong Parka4b9dd02019-01-16 22:53:13 +0900948func (c *Module) bootstrap() bool {
949 return Bool(c.Properties.Bootstrap)
950}
951
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700952func (c *Module) nativeCoverage() bool {
Pirama Arumuga Nainar5f69b9a2019-09-12 13:18:48 -0700953 // Bug: http://b/137883967 - native-bridge modules do not currently work with coverage
954 if c.Target().NativeBridge == android.NativeBridgeEnabled {
955 return false
956 }
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -0700957 return c.linker != nil && c.linker.nativeCoverage()
958}
959
Inseob Kim8471cda2019-11-15 09:59:12 +0900960func (c *Module) isSnapshotPrebuilt() bool {
Inseob Kimeec88e12020-01-22 11:11:29 +0900961 if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
962 return true
963 }
964 if _, ok := c.linker.(*vendorSnapshotLibraryDecorator); ok {
965 return true
966 }
967 if _, ok := c.linker.(*vendorSnapshotBinaryDecorator); ok {
968 return true
969 }
970 return false
Inseob Kim8471cda2019-11-15 09:59:12 +0900971}
972
Jiyong Park73c54ee2019-10-22 20:31:18 +0900973func (c *Module) ExportedIncludeDirs() android.Paths {
974 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
975 return flagsProducer.exportedDirs()
976 }
Jiyong Park232e7852019-11-04 12:23:40 +0900977 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900978}
979
980func (c *Module) ExportedSystemIncludeDirs() android.Paths {
981 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
982 return flagsProducer.exportedSystemDirs()
983 }
Jiyong Park232e7852019-11-04 12:23:40 +0900984 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900985}
986
987func (c *Module) ExportedFlags() []string {
988 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
989 return flagsProducer.exportedFlags()
990 }
Jiyong Park232e7852019-11-04 12:23:40 +0900991 return nil
992}
993
994func (c *Module) ExportedDeps() android.Paths {
995 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
996 return flagsProducer.exportedDeps()
997 }
998 return nil
Jiyong Park73c54ee2019-10-22 20:31:18 +0900999}
1000
Inseob Kimd110f872019-12-06 13:15:38 +09001001func (c *Module) ExportedGeneratedHeaders() android.Paths {
1002 if flagsProducer, ok := c.linker.(exportedFlagsProducer); ok {
1003 return flagsProducer.exportedGeneratedHeaders()
1004 }
1005 return nil
1006}
1007
Jiyong Parkf1194352019-02-25 11:05:47 +09001008func isBionic(name string) bool {
1009 switch name {
Martin Stjernholm203489b2019-11-11 15:33:27 +00001010 case "libc", "libm", "libdl", "libdl_android", "linker":
Jiyong Parkf1194352019-02-25 11:05:47 +09001011 return true
1012 }
1013 return false
1014}
1015
Martin Stjernholm279de572019-09-10 23:18:20 +01001016func InstallToBootstrap(name string, config android.Config) bool {
Peter Collingbourne3478bb22019-04-24 14:41:12 -07001017 if name == "libclang_rt.hwasan-aarch64-android" {
1018 return inList("hwaddress", config.SanitizeDevice())
1019 }
1020 return isBionic(name)
1021}
1022
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001023func (c *Module) XrefCcFiles() android.Paths {
1024 return c.kytheFiles
1025}
1026
Colin Crossca860ac2016-01-04 14:34:37 -08001027type baseModuleContext struct {
Colin Cross0ea8ba82019-06-06 14:33:29 -07001028 android.BaseModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001029 moduleContextImpl
1030}
1031
Colin Cross37047f12016-12-13 17:06:13 -08001032type depsContext struct {
1033 android.BottomUpMutatorContext
1034 moduleContextImpl
1035}
1036
Colin Crossca860ac2016-01-04 14:34:37 -08001037type moduleContext struct {
Colin Cross635c3b02016-05-18 15:37:25 -07001038 android.ModuleContext
Colin Crossca860ac2016-01-04 14:34:37 -08001039 moduleContextImpl
1040}
1041
Justin Yun5f7f7e82019-11-18 19:52:14 +09001042func (ctx *moduleContext) ProductSpecific() bool {
1043 return ctx.ModuleContext.ProductSpecific() ||
1044 (ctx.mod.HasVendorVariant() && ctx.mod.inProduct() && !ctx.mod.IsVndk())
1045}
1046
Jiyong Park2db76922017-11-08 16:03:48 +09001047func (ctx *moduleContext) SocSpecific() bool {
1048 return ctx.ModuleContext.SocSpecific() ||
Justin Yun5f7f7e82019-11-18 19:52:14 +09001049 (ctx.mod.HasVendorVariant() && ctx.mod.inVendor() && !ctx.mod.IsVndk())
Dan Willemsen4416e5d2017-04-06 12:43:22 -07001050}
1051
Colin Crossca860ac2016-01-04 14:34:37 -08001052type moduleContextImpl struct {
1053 mod *Module
1054 ctx BaseModuleContext
1055}
1056
Colin Crossb98c8b02016-07-29 13:44:28 -07001057func (ctx *moduleContextImpl) toolchain() config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001058 return ctx.mod.toolchain(ctx.ctx)
1059}
1060
1061func (ctx *moduleContextImpl) static() bool {
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00001062 return ctx.mod.static()
Colin Crossca860ac2016-01-04 14:34:37 -08001063}
1064
1065func (ctx *moduleContextImpl) staticBinary() bool {
Jiyong Park379de2f2018-12-19 02:47:14 +09001066 return ctx.mod.staticBinary()
Colin Crossca860ac2016-01-04 14:34:37 -08001067}
1068
Jiyong Park1d1119f2019-07-29 21:27:18 +09001069func (ctx *moduleContextImpl) header() bool {
1070 return ctx.mod.header()
1071}
1072
Jooyung Hanccce2f22020-03-07 03:45:53 +09001073func (ctx *moduleContextImpl) canUseSdk() bool {
1074 return ctx.ctx.Device() && !ctx.useVndk() && !ctx.inRamdisk() && !ctx.inRecovery() && !ctx.ctx.Fuchsia()
1075}
1076
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001077func (ctx *moduleContextImpl) useSdk() bool {
Jooyung Hanccce2f22020-03-07 03:45:53 +09001078 if ctx.canUseSdk() {
Nan Zhang0007d812017-11-07 10:57:05 -08001079 return String(ctx.mod.Properties.Sdk_version) != ""
Dan Willemsena96ff642016-06-07 12:34:45 -07001080 }
1081 return false
Colin Crossca860ac2016-01-04 14:34:37 -08001082}
1083
1084func (ctx *moduleContextImpl) sdkVersion() string {
Dan Willemsena96ff642016-06-07 12:34:45 -07001085 if ctx.ctx.Device() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001086 if ctx.useVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09001087 vndkVer := ctx.mod.VndkVersion()
1088 if inList(vndkVer, ctx.ctx.Config().PlatformVersionCombinedCodenames()) {
1089 return "current"
Justin Yun732aa6a2018-03-23 17:43:47 +09001090 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09001091 return vndkVer
Dan Willemsend2ede872016-11-18 14:54:24 -08001092 }
Justin Yun732aa6a2018-03-23 17:43:47 +09001093 return String(ctx.mod.Properties.Sdk_version)
Dan Willemsena96ff642016-06-07 12:34:45 -07001094 }
1095 return ""
Colin Crossca860ac2016-01-04 14:34:37 -08001096}
1097
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001098func (ctx *moduleContextImpl) useVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001099 return ctx.mod.UseVndk()
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001100}
Justin Yun8effde42017-06-23 19:24:43 +09001101
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001102func (ctx *moduleContextImpl) isNdk() bool {
Peter Collingbournead84f972019-12-17 16:46:18 -08001103 return ctx.mod.IsNdk()
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001104}
1105
Inseob Kim9516ee92019-05-09 10:56:13 +09001106func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
1107 return ctx.mod.isLlndk(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001108}
1109
Inseob Kim9516ee92019-05-09 10:56:13 +09001110func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
1111 return ctx.mod.isLlndkPublic(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001112}
1113
Inseob Kim9516ee92019-05-09 10:56:13 +09001114func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
1115 return ctx.mod.isVndkPrivate(config)
Logan Chienf6dbd9c2019-01-16 20:19:51 +08001116}
1117
Logan Chienf3511742017-10-31 18:04:35 +08001118func (ctx *moduleContextImpl) isVndk() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001119 return ctx.mod.IsVndk()
Logan Chienf3511742017-10-31 18:04:35 +08001120}
1121
Yi Kong7e53c572018-02-14 18:16:12 +08001122func (ctx *moduleContextImpl) isPgoCompile() bool {
1123 return ctx.mod.isPgoCompile()
1124}
1125
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001126func (ctx *moduleContextImpl) isNDKStubLibrary() bool {
1127 return ctx.mod.isNDKStubLibrary()
1128}
1129
Justin Yun8effde42017-06-23 19:24:43 +09001130func (ctx *moduleContextImpl) isVndkSp() bool {
Logan Chienf3511742017-10-31 18:04:35 +08001131 return ctx.mod.isVndkSp()
1132}
1133
1134func (ctx *moduleContextImpl) isVndkExt() bool {
1135 return ctx.mod.isVndkExt()
Justin Yun8effde42017-06-23 19:24:43 +09001136}
1137
Vic Yangefd249e2018-11-12 20:19:56 -08001138func (ctx *moduleContextImpl) mustUseVendorVariant() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001139 return ctx.mod.MustUseVendorVariant()
Vic Yangefd249e2018-11-12 20:19:56 -08001140}
1141
Justin Yun5f7f7e82019-11-18 19:52:14 +09001142func (ctx *moduleContextImpl) inProduct() bool {
1143 return ctx.mod.inProduct()
1144}
1145
1146func (ctx *moduleContextImpl) inVendor() bool {
1147 return ctx.mod.inVendor()
1148}
1149
Yifan Hong1b3348d2020-01-21 15:53:22 -08001150func (ctx *moduleContextImpl) inRamdisk() bool {
1151 return ctx.mod.InRamdisk()
1152}
1153
Jiyong Parkf9332f12018-02-01 00:54:12 +09001154func (ctx *moduleContextImpl) inRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07001155 return ctx.mod.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09001156}
1157
Logan Chien2f2b8902018-07-10 15:01:19 +08001158// Check whether ABI dumps should be created for this module.
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001159func (ctx *moduleContextImpl) shouldCreateSourceAbiDump() bool {
Logan Chien2f2b8902018-07-10 15:01:19 +08001160 if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
1161 return false
Jayant Chowdharyea0a2e12018-03-01 19:12:16 -08001162 }
Doug Hornc32c6b02019-01-17 14:44:05 -08001163
1164 if ctx.ctx.Fuchsia() {
1165 return false
1166 }
1167
Logan Chien2f2b8902018-07-10 15:01:19 +08001168 if sanitize := ctx.mod.sanitize; sanitize != nil {
1169 if !sanitize.isVariantOnProductionDevice() {
1170 return false
1171 }
1172 }
1173 if !ctx.ctx.Device() {
1174 // Host modules do not need ABI dumps.
1175 return false
1176 }
Hsin-Yi Chend2451682020-01-10 16:47:50 +08001177 if ctx.isStubs() || ctx.isNDKStubLibrary() {
Hsin-Yi Chenf6a95462019-06-25 14:46:52 +08001178 // Stubs do not need ABI dumps.
1179 return false
1180 }
Hsin-Yi Chenaf17d742019-07-29 17:46:59 +08001181 return true
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001182}
1183
Dan Willemsen8146b2f2016-03-30 21:00:30 -07001184func (ctx *moduleContextImpl) selectedStl() string {
1185 if stl := ctx.mod.stl; stl != nil {
1186 return stl.Properties.SelectedStl
1187 }
1188 return ""
1189}
1190
Ivan Lozanobd721262018-11-27 14:33:03 -08001191func (ctx *moduleContextImpl) useClangLld(actx ModuleContext) bool {
1192 return ctx.mod.linker.useClangLld(actx)
1193}
1194
Colin Crossce75d2c2016-10-06 16:12:58 -07001195func (ctx *moduleContextImpl) baseModuleName() string {
1196 return ctx.mod.ModuleBase.BaseModuleName()
1197}
1198
Logan Chienf3511742017-10-31 18:04:35 +08001199func (ctx *moduleContextImpl) getVndkExtendsModuleName() string {
1200 return ctx.mod.getVndkExtendsModuleName()
1201}
1202
Logan Chiene274fc92019-12-03 11:18:32 -08001203func (ctx *moduleContextImpl) isForPlatform() bool {
1204 return ctx.mod.IsForPlatform()
1205}
1206
Jiyong Park58e364a2019-01-19 19:24:06 +09001207func (ctx *moduleContextImpl) apexName() string {
1208 return ctx.mod.ApexName()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001209}
1210
Jooyung Hanccce2f22020-03-07 03:45:53 +09001211func (ctx *moduleContextImpl) apexSdkVersion() int {
1212 return ctx.mod.ApexProperties.Info.MinSdkVersion
1213}
1214
Jiyong Parkb0788572018-12-20 22:10:17 +09001215func (ctx *moduleContextImpl) hasStubsVariants() bool {
1216 return ctx.mod.HasStubsVariants()
1217}
1218
1219func (ctx *moduleContextImpl) isStubs() bool {
1220 return ctx.mod.IsStubs()
1221}
1222
Jiyong Parka4b9dd02019-01-16 22:53:13 +09001223func (ctx *moduleContextImpl) bootstrap() bool {
1224 return ctx.mod.bootstrap()
1225}
1226
Pirama Arumuga Nainar65c95ff2019-03-25 10:21:31 -07001227func (ctx *moduleContextImpl) nativeCoverage() bool {
1228 return ctx.mod.nativeCoverage()
1229}
1230
Colin Cross635c3b02016-05-18 15:37:25 -07001231func newBaseModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001232 return &Module{
1233 hod: hod,
1234 multilib: multilib,
1235 }
1236}
1237
Colin Cross635c3b02016-05-18 15:37:25 -07001238func newModule(hod android.HostOrDeviceSupported, multilib android.Multilib) *Module {
Colin Crossca860ac2016-01-04 14:34:37 -08001239 module := newBaseModule(hod, multilib)
Dan Willemsena03cf6d2016-09-26 15:45:04 -07001240 module.features = []feature{
1241 &tidyFeature{},
1242 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001243 module.stl = &stl{}
Colin Cross16b23492016-01-06 14:41:07 -08001244 module.sanitize = &sanitize{}
Dan Willemsen581341d2017-02-09 16:16:31 -08001245 module.coverage = &coverage{}
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001246 module.sabi = &sabi{}
Justin Yun8effde42017-06-23 19:24:43 +09001247 module.vndkdep = &vndkdep{}
Stephen Craneba090d12017-05-09 15:44:35 -07001248 module.lto = &lto{}
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001249 module.pgo = &pgo{}
Colin Crossca860ac2016-01-04 14:34:37 -08001250 return module
1251}
1252
Colin Crossce75d2c2016-10-06 16:12:58 -07001253func (c *Module) Prebuilt() *android.Prebuilt {
1254 if p, ok := c.linker.(prebuiltLinkerInterface); ok {
1255 return p.prebuilt()
1256 }
1257 return nil
1258}
1259
1260func (c *Module) Name() string {
1261 name := c.ModuleBase.Name()
Dan Willemsen01a90592017-04-07 15:21:13 -07001262 if p, ok := c.linker.(interface {
1263 Name(string) string
1264 }); ok {
Colin Crossce75d2c2016-10-06 16:12:58 -07001265 name = p.Name(name)
1266 }
1267 return name
1268}
1269
Alex Light3d673592019-01-18 14:37:31 -08001270func (c *Module) Symlinks() []string {
1271 if p, ok := c.installer.(interface {
1272 symlinkList() []string
1273 }); ok {
1274 return p.symlinkList()
1275 }
1276 return nil
1277}
1278
Jeff Gaston294356f2017-09-27 17:05:30 -07001279// orderDeps reorders dependencies into a list such that if module A depends on B, then
1280// A will precede B in the resultant list.
1281// This is convenient for passing into a linker.
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001282// Note that directSharedDeps should be the analogous static library for each shared lib dep
1283func 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 -07001284 // If A depends on B, then
1285 // Every list containing A will also contain B later in the list
1286 // So, after concatenating all lists, the final instance of B will have come from the same
1287 // original list as the final instance of A
1288 // So, the final instance of B will be later in the concatenation than the final A
1289 // So, keeping only the final instance of A and of B ensures that A is earlier in the output
1290 // list than B
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001291 for _, dep := range directStaticDeps {
Jeff Gaston294356f2017-09-27 17:05:30 -07001292 orderedAllDeps = append(orderedAllDeps, dep)
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001293 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
1294 }
1295 for _, dep := range directSharedDeps {
1296 orderedAllDeps = append(orderedAllDeps, dep)
1297 orderedAllDeps = append(orderedAllDeps, allTransitiveDeps[dep]...)
Jeff Gaston294356f2017-09-27 17:05:30 -07001298 }
1299
Colin Crossb6715442017-10-24 11:13:31 -07001300 orderedAllDeps = android.LastUniquePaths(orderedAllDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001301
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001302 // We don't want to add any new dependencies into directStaticDeps (to allow the caller to
Jeff Gaston294356f2017-09-27 17:05:30 -07001303 // intentionally exclude or replace any unwanted transitive dependencies), so we limit the
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001304 // resultant list to only what the caller has chosen to include in directStaticDeps
1305 _, orderedDeclaredDeps = android.FilterPathList(orderedAllDeps, directStaticDeps)
Jeff Gaston294356f2017-09-27 17:05:30 -07001306
1307 return orderedAllDeps, orderedDeclaredDeps
1308}
1309
Ivan Lozano183a3212019-10-18 14:18:45 -07001310func orderStaticModuleDeps(module LinkableInterface, staticDeps []LinkableInterface, sharedDeps []LinkableInterface) (results []android.Path) {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001311 // convert Module to Path
Ivan Lozano183a3212019-10-18 14:18:45 -07001312 var depsInLinkOrder []android.Path
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001313 allTransitiveDeps := make(map[android.Path][]android.Path, len(staticDeps))
1314 staticDepFiles := []android.Path{}
1315 for _, dep := range staticDeps {
Nicolas Geoffray0b787662020-02-04 18:27:55 +00001316 // The OutputFile may not be valid for a variant not present, and the AllowMissingDependencies flag is set.
1317 if dep.OutputFile().Valid() {
1318 allTransitiveDeps[dep.OutputFile().Path()] = dep.GetDepsInLinkOrder()
1319 staticDepFiles = append(staticDepFiles, dep.OutputFile().Path())
1320 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001321 }
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001322 sharedDepFiles := []android.Path{}
1323 for _, sharedDep := range sharedDeps {
Ivan Lozano183a3212019-10-18 14:18:45 -07001324 if sharedDep.HasStaticVariant() {
1325 staticAnalogue := sharedDep.GetStaticVariant()
1326 allTransitiveDeps[staticAnalogue.OutputFile().Path()] = staticAnalogue.GetDepsInLinkOrder()
1327 sharedDepFiles = append(sharedDepFiles, staticAnalogue.OutputFile().Path())
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08001328 }
Jeff Gaston294356f2017-09-27 17:05:30 -07001329 }
1330
1331 // reorder the dependencies based on transitive dependencies
Ivan Lozano183a3212019-10-18 14:18:45 -07001332 depsInLinkOrder, results = orderDeps(staticDepFiles, sharedDepFiles, allTransitiveDeps)
1333 module.SetDepsInLinkOrder(depsInLinkOrder)
Jeff Gaston294356f2017-09-27 17:05:30 -07001334
1335 return results
Jeff Gaston294356f2017-09-27 17:05:30 -07001336}
1337
Roland Levillainf89cd092019-07-29 16:22:59 +01001338func (c *Module) IsTestPerSrcAllTestsVariation() bool {
1339 test, ok := c.linker.(testPerSrc)
1340 return ok && test.isAllTestsVariation()
1341}
1342
Justin Yun5f7f7e82019-11-18 19:52:14 +09001343func (c *Module) getNameSuffixWithVndkVersion(ctx android.ModuleContext) string {
1344 // Returns the name suffix for product and vendor variants. If the VNDK version is not
1345 // "current", it will append the VNDK version to the name suffix.
1346 var vndkVersion string
1347 var nameSuffix string
1348 if c.inProduct() {
1349 vndkVersion = ctx.DeviceConfig().ProductVndkVersion()
1350 nameSuffix = productSuffix
1351 } else {
1352 vndkVersion = ctx.DeviceConfig().VndkVersion()
1353 nameSuffix = vendorSuffix
1354 }
1355 if vndkVersion == "current" {
1356 vndkVersion = ctx.DeviceConfig().PlatformVndkVersion()
1357 }
1358 if c.Properties.VndkVersion != vndkVersion {
1359 // add version suffix only if the module is using different vndk version than the
1360 // version in product or vendor partition.
1361 nameSuffix += "." + c.Properties.VndkVersion
1362 }
1363 return nameSuffix
1364}
1365
Colin Cross635c3b02016-05-18 15:37:25 -07001366func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
Roland Levillainf2fad972019-06-28 15:41:19 +01001367 // Handle the case of a test module split by `test_per_src` mutator.
Roland Levillainf89cd092019-07-29 16:22:59 +01001368 //
1369 // The `test_per_src` mutator adds an extra variation named "", depending on all the other
1370 // `test_per_src` variations of the test module. Set `outputFile` to an empty path for this
1371 // module and return early, as this module does not produce an output file per se.
1372 if c.IsTestPerSrcAllTestsVariation() {
1373 c.outputFile = android.OptionalPath{}
1374 return
Roland Levillainf2fad972019-06-28 15:41:19 +01001375 }
1376
Jooyung Han38002912019-05-16 04:01:54 +09001377 c.makeLinkType = c.getMakeLinkType(actx)
Inseob Kim9516ee92019-05-09 10:56:13 +09001378
Inseob Kim64c43952019-08-26 16:52:35 +09001379 c.Properties.SubName = ""
1380
1381 if c.Target().NativeBridge == android.NativeBridgeEnabled {
1382 c.Properties.SubName += nativeBridgeSuffix
1383 }
1384
Justin Yun5f7f7e82019-11-18 19:52:14 +09001385 _, llndk := c.linker.(*llndkStubDecorator)
1386 _, llndkHeader := c.linker.(*llndkHeadersDecorator)
1387 if llndk || llndkHeader || (c.UseVndk() && c.HasVendorVariant()) {
1388 // .vendor.{version} suffix is added for vendor variant or .product.{version} suffix is
1389 // added for product variant only when we have vendor and product variants with core
1390 // variant. The suffix is not added for vendor-only or product-only module.
1391 c.Properties.SubName += c.getNameSuffixWithVndkVersion(actx)
1392 } else if _, ok := c.linker.(*vndkPrebuiltLibraryDecorator); ok {
Inseob Kim64c43952019-08-26 16:52:35 +09001393 // .vendor suffix is added for backward compatibility with VNDK snapshot whose names with
1394 // such suffixes are already hard-coded in prebuilts/vndk/.../Android.bp.
1395 c.Properties.SubName += vendorSuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08001396 } else if c.InRamdisk() && !c.OnlyInRamdisk() {
1397 c.Properties.SubName += ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07001398 } else if c.InRecovery() && !c.OnlyInRecovery() {
Inseob Kim64c43952019-08-26 16:52:35 +09001399 c.Properties.SubName += recoverySuffix
1400 }
1401
Colin Crossca860ac2016-01-04 14:34:37 -08001402 ctx := &moduleContext{
Colin Cross635c3b02016-05-18 15:37:25 -07001403 ModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001404 moduleContextImpl: moduleContextImpl{
1405 mod: c,
1406 },
1407 }
1408 ctx.ctx = ctx
1409
Colin Crossf18e1102017-11-16 14:33:08 -08001410 deps := c.depsToPaths(ctx)
1411 if ctx.Failed() {
1412 return
1413 }
1414
Dan Willemsen8536d6b2018-10-07 20:54:34 -07001415 if c.Properties.Clang != nil && *c.Properties.Clang == false {
1416 ctx.PropertyErrorf("clang", "false (GCC) is no longer supported")
1417 }
1418
Colin Crossca860ac2016-01-04 14:34:37 -08001419 flags := Flags{
1420 Toolchain: c.toolchain(ctx),
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001421 EmitXrefs: ctx.Config().EmitXrefRules(),
Colin Crossca860ac2016-01-04 14:34:37 -08001422 }
Colin Crossca860ac2016-01-04 14:34:37 -08001423 if c.compiler != nil {
Colin Crossf18e1102017-11-16 14:33:08 -08001424 flags = c.compiler.compilerFlags(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001425 }
1426 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001427 flags = c.linker.linkerFlags(ctx, flags)
Colin Crossca860ac2016-01-04 14:34:37 -08001428 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001429 if c.stl != nil {
1430 flags = c.stl.flags(ctx, flags)
1431 }
Colin Cross16b23492016-01-06 14:41:07 -08001432 if c.sanitize != nil {
1433 flags = c.sanitize.flags(ctx, flags)
1434 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001435 if c.coverage != nil {
Pirama Arumuga Nainar82fe59b2019-07-02 14:55:35 -07001436 flags, deps = c.coverage.flags(ctx, flags, deps)
Dan Willemsen581341d2017-02-09 16:16:31 -08001437 }
Stephen Craneba090d12017-05-09 15:44:35 -07001438 if c.lto != nil {
1439 flags = c.lto.flags(ctx, flags)
1440 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001441 if c.pgo != nil {
1442 flags = c.pgo.flags(ctx, flags)
1443 }
Colin Crossca860ac2016-01-04 14:34:37 -08001444 for _, feature := range c.features {
1445 flags = feature.flags(ctx, flags)
1446 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001447 if ctx.Failed() {
1448 return
1449 }
1450
Colin Cross4af21ed2019-11-04 09:37:55 -08001451 flags.Local.CFlags, _ = filterList(flags.Local.CFlags, config.IllegalFlags)
1452 flags.Local.CppFlags, _ = filterList(flags.Local.CppFlags, config.IllegalFlags)
1453 flags.Local.ConlyFlags, _ = filterList(flags.Local.ConlyFlags, config.IllegalFlags)
Colin Cross3f40fa42015-01-30 17:27:36 -08001454
Colin Cross4af21ed2019-11-04 09:37:55 -08001455 flags.Local.CommonFlags = append(flags.Local.CommonFlags, deps.Flags...)
Inseob Kim69378442019-06-03 19:10:47 +09001456
1457 for _, dir := range deps.IncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001458 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-I"+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001459 }
1460 for _, dir := range deps.SystemIncludeDirs {
Colin Cross4af21ed2019-11-04 09:37:55 -08001461 flags.Local.CommonFlags = append(flags.Local.CommonFlags, "-isystem "+dir.String())
Inseob Kim69378442019-06-03 19:10:47 +09001462 }
1463
Fabien Sanglardd61f1f42017-01-10 16:21:22 -08001464 c.flags = flags
Jayant Chowdhary9677e8c2017-06-15 14:45:18 -07001465 // We need access to all the flags seen by a source file.
1466 if c.sabi != nil {
1467 flags = c.sabi.flags(ctx, flags)
1468 }
Dan Willemsen98ab3112019-08-27 21:20:40 -07001469
Colin Cross4af21ed2019-11-04 09:37:55 -08001470 flags.AssemblerWithCpp = inList("-xassembler-with-cpp", flags.Local.AsFlags)
Dan Willemsen98ab3112019-08-27 21:20:40 -07001471
Colin Crossca860ac2016-01-04 14:34:37 -08001472 // Optimization to reduce size of build.ninja
1473 // Replace the long list of flags for each file with a module-local variable
Colin Cross4af21ed2019-11-04 09:37:55 -08001474 ctx.Variable(pctx, "cflags", strings.Join(flags.Local.CFlags, " "))
1475 ctx.Variable(pctx, "cppflags", strings.Join(flags.Local.CppFlags, " "))
1476 ctx.Variable(pctx, "asflags", strings.Join(flags.Local.AsFlags, " "))
1477 flags.Local.CFlags = []string{"$cflags"}
1478 flags.Local.CppFlags = []string{"$cppflags"}
1479 flags.Local.AsFlags = []string{"$asflags"}
Colin Crossca860ac2016-01-04 14:34:37 -08001480
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001481 var objs Objects
Colin Crossca860ac2016-01-04 14:34:37 -08001482 if c.compiler != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001483 objs = c.compiler.compile(ctx, flags, deps)
Colin Crossca860ac2016-01-04 14:34:37 -08001484 if ctx.Failed() {
1485 return
1486 }
Sasha Smundak2a4549e2018-11-05 16:49:08 -08001487 c.kytheFiles = objs.kytheFiles
Colin Cross3f40fa42015-01-30 17:27:36 -08001488 }
1489
Colin Crossca860ac2016-01-04 14:34:37 -08001490 if c.linker != nil {
Dan Willemsen5cb580f2016-09-26 17:33:01 -07001491 outputFile := c.linker.link(ctx, flags, deps, objs)
Colin Crossca860ac2016-01-04 14:34:37 -08001492 if ctx.Failed() {
1493 return
1494 }
Colin Cross635c3b02016-05-18 15:37:25 -07001495 c.outputFile = android.OptionalPathForPath(outputFile)
Jiyong Parkb0788572018-12-20 22:10:17 +09001496
1497 // If a lib is directly included in any of the APEXes, unhide the stubs
1498 // variant having the latest version gets visible to make. In addition,
1499 // the non-stubs variant is renamed to <libname>.bootstrap. This is to
1500 // force anything in the make world to link against the stubs library.
1501 // (unless it is explicitly referenced via .bootstrap suffix or the
1502 // module is marked with 'bootstrap: true').
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00001503 if c.HasStubsVariants() &&
Yifan Hong1b3348d2020-01-21 15:53:22 -08001504 android.DirectlyInAnyApex(ctx, ctx.baseModuleName()) && !c.InRamdisk() &&
Ivan Lozano52767be2019-10-18 14:49:46 -07001505 !c.InRecovery() && !c.UseVndk() && !c.static() && !c.isCoverageVariant() &&
Pirama Arumuga Nainar1acd4472018-12-10 15:12:40 -08001506 c.IsStubs() {
Jiyong Parkb0788572018-12-20 22:10:17 +09001507 c.Properties.HideFromMake = false // unhide
1508 // Note: this is still non-installable
1509 }
Inseob Kimeda2e9c2020-03-03 22:06:32 +09001510
1511 // glob exported headers for snapshot, if BOARD_VNDK_VERSION is current.
1512 if i, ok := c.linker.(snapshotLibraryInterface); ok && ctx.DeviceConfig().VndkVersion() == "current" {
1513 if isSnapshotAware(ctx, c) {
1514 i.collectHeadersForSnapshot(ctx)
1515 }
1516 }
Colin Crossce75d2c2016-10-06 16:12:58 -07001517 }
Colin Cross5049f022015-03-18 13:28:46 -07001518
Inseob Kim1f086e22019-05-09 13:29:15 +09001519 if c.installable() {
Colin Crossce75d2c2016-10-06 16:12:58 -07001520 c.installer.install(ctx, c.outputFile.Path())
1521 if ctx.Failed() {
1522 return
Colin Crossca860ac2016-01-04 14:34:37 -08001523 }
Paul Duffin0cb37b92020-03-04 14:52:46 +00001524 } else if !proptools.BoolDefault(c.Properties.Installable, true) {
1525 // If the module has been specifically configure to not be installed then
1526 // skip the installation as otherwise it will break when running inside make
1527 // as the output path to install will not be specified. Not all uninstallable
1528 // modules can skip installation as some are needed for resolving make side
1529 // dependencies.
1530 c.SkipInstall()
Dan Albertc403f7c2015-03-18 14:01:18 -07001531 }
Colin Cross3f40fa42015-01-30 17:27:36 -08001532}
1533
Colin Cross0ea8ba82019-06-06 14:33:29 -07001534func (c *Module) toolchain(ctx android.BaseModuleContext) config.Toolchain {
Colin Crossca860ac2016-01-04 14:34:37 -08001535 if c.cachedToolchain == nil {
Colin Crossb98c8b02016-07-29 13:44:28 -07001536 c.cachedToolchain = config.FindToolchain(ctx.Os(), ctx.Arch())
Colin Cross3f40fa42015-01-30 17:27:36 -08001537 }
Colin Crossca860ac2016-01-04 14:34:37 -08001538 return c.cachedToolchain
Colin Cross3f40fa42015-01-30 17:27:36 -08001539}
1540
Colin Crossca860ac2016-01-04 14:34:37 -08001541func (c *Module) begin(ctx BaseModuleContext) {
1542 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001543 c.compiler.compilerInit(ctx)
Colin Cross21b9a242015-03-24 14:15:58 -07001544 }
Colin Crossca860ac2016-01-04 14:34:37 -08001545 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001546 c.linker.linkerInit(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001547 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001548 if c.stl != nil {
1549 c.stl.begin(ctx)
1550 }
Colin Cross16b23492016-01-06 14:41:07 -08001551 if c.sanitize != nil {
1552 c.sanitize.begin(ctx)
1553 }
Dan Willemsen581341d2017-02-09 16:16:31 -08001554 if c.coverage != nil {
1555 c.coverage.begin(ctx)
1556 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001557 if c.sabi != nil {
1558 c.sabi.begin(ctx)
1559 }
Justin Yun8effde42017-06-23 19:24:43 +09001560 if c.vndkdep != nil {
1561 c.vndkdep.begin(ctx)
1562 }
Stephen Craneba090d12017-05-09 15:44:35 -07001563 if c.lto != nil {
1564 c.lto.begin(ctx)
1565 }
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07001566 if c.pgo != nil {
1567 c.pgo.begin(ctx)
1568 }
Colin Crossca860ac2016-01-04 14:34:37 -08001569 for _, feature := range c.features {
1570 feature.begin(ctx)
1571 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001572 if ctx.useSdk() {
Dan Albertf5415d72017-08-17 16:19:59 -07001573 version, err := normalizeNdkApiLevel(ctx, ctx.sdkVersion(), ctx.Arch())
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001574 if err != nil {
1575 ctx.PropertyErrorf("sdk_version", err.Error())
1576 }
Nan Zhang0007d812017-11-07 10:57:05 -08001577 c.Properties.Sdk_version = StringPtr(version)
Dan Albert7fa7b2e2016-08-05 16:37:52 -07001578 }
Colin Crossca860ac2016-01-04 14:34:37 -08001579}
1580
Colin Cross37047f12016-12-13 17:06:13 -08001581func (c *Module) deps(ctx DepsContext) Deps {
Colin Crossc99deeb2016-04-11 15:06:20 -07001582 deps := Deps{}
1583
1584 if c.compiler != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001585 deps = c.compiler.compilerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001586 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001587 // Add the PGO dependency (the clang_rt.profile runtime library), which
1588 // sometimes depends on symbols from libgcc, before libgcc gets added
1589 // in linkerDeps().
Pirama Arumuga Nainar49b53d52017-10-04 16:47:29 -07001590 if c.pgo != nil {
1591 deps = c.pgo.deps(ctx, deps)
1592 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001593 if c.linker != nil {
Colin Cross42742b82016-08-01 13:20:05 -07001594 deps = c.linker.linkerDeps(ctx, deps)
Colin Crossc99deeb2016-04-11 15:06:20 -07001595 }
Colin Crossa8e07cc2016-04-04 15:07:06 -07001596 if c.stl != nil {
1597 deps = c.stl.deps(ctx, deps)
1598 }
Colin Cross16b23492016-01-06 14:41:07 -08001599 if c.sanitize != nil {
1600 deps = c.sanitize.deps(ctx, deps)
1601 }
Pirama Arumuga Nainar0b882f02018-04-23 22:44:39 +00001602 if c.coverage != nil {
1603 deps = c.coverage.deps(ctx, deps)
1604 }
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08001605 if c.sabi != nil {
1606 deps = c.sabi.deps(ctx, deps)
1607 }
Justin Yun8effde42017-06-23 19:24:43 +09001608 if c.vndkdep != nil {
1609 deps = c.vndkdep.deps(ctx, deps)
1610 }
Stephen Craneba090d12017-05-09 15:44:35 -07001611 if c.lto != nil {
1612 deps = c.lto.deps(ctx, deps)
1613 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001614 for _, feature := range c.features {
1615 deps = feature.deps(ctx, deps)
1616 }
1617
Colin Crossb6715442017-10-24 11:13:31 -07001618 deps.WholeStaticLibs = android.LastUniqueStrings(deps.WholeStaticLibs)
1619 deps.StaticLibs = android.LastUniqueStrings(deps.StaticLibs)
1620 deps.LateStaticLibs = android.LastUniqueStrings(deps.LateStaticLibs)
1621 deps.SharedLibs = android.LastUniqueStrings(deps.SharedLibs)
1622 deps.LateSharedLibs = android.LastUniqueStrings(deps.LateSharedLibs)
1623 deps.HeaderLibs = android.LastUniqueStrings(deps.HeaderLibs)
Logan Chien43d34c32017-12-20 01:17:32 +08001624 deps.RuntimeLibs = android.LastUniqueStrings(deps.RuntimeLibs)
Colin Crossc99deeb2016-04-11 15:06:20 -07001625
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001626 for _, lib := range deps.ReexportSharedLibHeaders {
1627 if !inList(lib, deps.SharedLibs) {
1628 ctx.PropertyErrorf("export_shared_lib_headers", "Shared library not in shared_libs: '%s'", lib)
1629 }
1630 }
1631
1632 for _, lib := range deps.ReexportStaticLibHeaders {
1633 if !inList(lib, deps.StaticLibs) {
1634 ctx.PropertyErrorf("export_static_lib_headers", "Static library not in static_libs: '%s'", lib)
1635 }
1636 }
1637
Colin Cross5950f382016-12-13 12:50:57 -08001638 for _, lib := range deps.ReexportHeaderLibHeaders {
1639 if !inList(lib, deps.HeaderLibs) {
1640 ctx.PropertyErrorf("export_header_lib_headers", "Header library not in header_libs: '%s'", lib)
1641 }
1642 }
1643
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001644 for _, gen := range deps.ReexportGeneratedHeaders {
1645 if !inList(gen, deps.GeneratedHeaders) {
1646 ctx.PropertyErrorf("export_generated_headers", "Generated header module not in generated_headers: '%s'", gen)
1647 }
1648 }
1649
Colin Crossc99deeb2016-04-11 15:06:20 -07001650 return deps
1651}
1652
Dan Albert7e9d2952016-08-04 13:02:36 -07001653func (c *Module) beginMutator(actx android.BottomUpMutatorContext) {
Colin Crossca860ac2016-01-04 14:34:37 -08001654 ctx := &baseModuleContext{
Colin Cross0ea8ba82019-06-06 14:33:29 -07001655 BaseModuleContext: actx,
Colin Crossca860ac2016-01-04 14:34:37 -08001656 moduleContextImpl: moduleContextImpl{
1657 mod: c,
1658 },
1659 }
1660 ctx.ctx = ctx
1661
Colin Crossca860ac2016-01-04 14:34:37 -08001662 c.begin(ctx)
Dan Albert7e9d2952016-08-04 13:02:36 -07001663}
1664
Jiyong Park7ed9de32018-10-15 22:25:07 +09001665// Split name#version into name and version
Jiyong Park73c54ee2019-10-22 20:31:18 +09001666func StubsLibNameAndVersion(name string) (string, string) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001667 if sharp := strings.LastIndex(name, "#"); sharp != -1 && sharp != len(name)-1 {
1668 version := name[sharp+1:]
1669 libname := name[:sharp]
1670 return libname, version
1671 }
1672 return name, ""
1673}
1674
Colin Cross1e676be2016-10-12 14:38:15 -07001675func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
Inseob Kimeec88e12020-01-22 11:11:29 +09001676 if !c.Enabled() {
1677 return
1678 }
1679
Colin Cross37047f12016-12-13 17:06:13 -08001680 ctx := &depsContext{
1681 BottomUpMutatorContext: actx,
Dan Albert7e9d2952016-08-04 13:02:36 -07001682 moduleContextImpl: moduleContextImpl{
1683 mod: c,
1684 },
1685 }
1686 ctx.ctx = ctx
Colin Crossca860ac2016-01-04 14:34:37 -08001687
Colin Crossc99deeb2016-04-11 15:06:20 -07001688 deps := c.deps(ctx)
Colin Crossca860ac2016-01-04 14:34:37 -08001689
Dan Albert914449f2016-06-17 16:45:24 -07001690 variantNdkLibs := []string{}
1691 variantLateNdkLibs := []string{}
Dan Willemsenb916b802017-03-19 13:44:32 -07001692 if ctx.Os() == android.Android {
Dan Albert914449f2016-06-17 16:45:24 -07001693 version := ctx.sdkVersion()
Dan Willemsen72d39932016-07-08 23:23:48 -07001694
Inseob Kimeec88e12020-01-22 11:11:29 +09001695 // rewriteLibs takes a list of names of shared libraries and scans it for three types
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001696 // of names:
Dan Albert914449f2016-06-17 16:45:24 -07001697 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001698 // 1. Name of an NDK library that refers to a prebuilt module.
1699 // For each of these, it adds the name of the prebuilt module (which will be in
1700 // prebuilts/ndk) to the list of nonvariant libs.
1701 // 2. Name of an NDK library that refers to an ndk_library module.
1702 // For each of these, it adds the name of the ndk_library module to the list of
1703 // variant libs.
1704 // 3. Anything else (so anything that isn't an NDK library).
1705 // It adds these to the nonvariantLibs list.
Dan Albert914449f2016-06-17 16:45:24 -07001706 //
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001707 // The caller can then know to add the variantLibs dependencies differently from the
1708 // nonvariantLibs
Inseob Kim9516ee92019-05-09 10:56:13 +09001709
Inseob Kim9516ee92019-05-09 10:56:13 +09001710 vendorPublicLibraries := vendorPublicLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001711 vendorSnapshotSharedLibs := vendorSnapshotSharedLibs(actx.Config())
1712
1713 rewriteVendorLibs := func(lib string) string {
1714 if isLlndkLibrary(lib, ctx.Config()) {
1715 return lib + llndkLibrarySuffix
1716 }
1717
1718 // only modules with BOARD_VNDK_VERSION uses snapshot.
1719 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1720 return lib
1721 }
1722
1723 if snapshot, ok := vendorSnapshotSharedLibs.get(lib, actx.Arch().ArchType); ok {
1724 return snapshot
1725 }
1726
1727 return lib
1728 }
1729
1730 rewriteLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001731 variantLibs = []string{}
1732 nonvariantLibs = []string{}
Dan Albert914449f2016-06-17 16:45:24 -07001733 for _, entry := range list {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001734 // strip #version suffix out
Jiyong Park73c54ee2019-10-22 20:31:18 +09001735 name, _ := StubsLibNameAndVersion(entry)
Jiyong Park7ed9de32018-10-15 22:25:07 +09001736 if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) {
1737 if !inList(name, ndkMigratedLibs) {
1738 nonvariantLibs = append(nonvariantLibs, name+".ndk."+version)
Dan Albert914449f2016-06-17 16:45:24 -07001739 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001740 variantLibs = append(variantLibs, name+ndkLibrarySuffix)
Dan Albert914449f2016-06-17 16:45:24 -07001741 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001742 } else if ctx.useVndk() {
1743 nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry))
Inseob Kim9516ee92019-05-09 10:56:13 +09001744 } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001745 vendorPublicLib := name + vendorPublicLibrarySuffix
Jiyong Park374510b2018-03-19 18:23:01 +09001746 if actx.OtherModuleExists(vendorPublicLib) {
1747 nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
1748 } else {
1749 // This can happen if vendor_public_library module is defined in a
1750 // namespace that isn't visible to the current module. In that case,
1751 // link to the original library.
Jiyong Park7ed9de32018-10-15 22:25:07 +09001752 nonvariantLibs = append(nonvariantLibs, name)
Jiyong Park374510b2018-03-19 18:23:01 +09001753 }
Dan Albert914449f2016-06-17 16:45:24 -07001754 } else {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001755 // put name#version back
Dan Willemsen7cbf5f82017-03-28 00:08:30 -07001756 nonvariantLibs = append(nonvariantLibs, entry)
Dan Willemsen72d39932016-07-08 23:23:48 -07001757 }
1758 }
Dan Albert914449f2016-06-17 16:45:24 -07001759 return nonvariantLibs, variantLibs
Dan Willemsen72d39932016-07-08 23:23:48 -07001760 }
1761
Inseob Kimeec88e12020-01-22 11:11:29 +09001762 deps.SharedLibs, variantNdkLibs = rewriteLibs(deps.SharedLibs)
1763 deps.LateSharedLibs, variantLateNdkLibs = rewriteLibs(deps.LateSharedLibs)
1764 deps.ReexportSharedLibHeaders, _ = rewriteLibs(deps.ReexportSharedLibHeaders)
1765 if ctx.useVndk() {
1766 for idx, lib := range deps.RuntimeLibs {
1767 deps.RuntimeLibs[idx] = rewriteVendorLibs(lib)
1768 }
1769 }
Dan Willemsen72d39932016-07-08 23:23:48 -07001770 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001771
Jiyong Park7e636d02019-01-28 16:16:54 +09001772 buildStubs := false
Jiyong Park7ed9de32018-10-15 22:25:07 +09001773 if c.linker != nil {
1774 if library, ok := c.linker.(*libraryDecorator); ok {
1775 if library.buildStubs() {
Jiyong Park7e636d02019-01-28 16:16:54 +09001776 buildStubs = true
Jiyong Park7ed9de32018-10-15 22:25:07 +09001777 }
1778 }
1779 }
1780
Inseob Kimeec88e12020-01-22 11:11:29 +09001781 rewriteSnapshotLibs := func(lib string, snapshotMap *snapshotMap) string {
1782 // only modules with BOARD_VNDK_VERSION uses snapshot.
1783 if c.VndkVersion() != actx.DeviceConfig().VndkVersion() {
1784 return lib
1785 }
1786
1787 if snapshot, ok := snapshotMap.get(lib, actx.Arch().ArchType); ok {
1788 return snapshot
1789 }
1790
1791 return lib
1792 }
1793
1794 vendorSnapshotHeaderLibs := vendorSnapshotHeaderLibs(actx.Config())
Colin Cross32ec36c2016-12-15 07:39:51 -08001795 for _, lib := range deps.HeaderLibs {
1796 depTag := headerDepTag
1797 if inList(lib, deps.ReexportHeaderLibHeaders) {
1798 depTag = headerExportDepTag
1799 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001800
1801 lib = rewriteSnapshotLibs(lib, vendorSnapshotHeaderLibs)
1802
Jiyong Park7e636d02019-01-28 16:16:54 +09001803 if buildStubs {
Colin Cross7228ecd2019-11-18 16:00:16 -08001804 actx.AddFarVariationDependencies(append(ctx.Target().Variations(), c.ImageVariation()),
Colin Cross0f7d2ef2019-10-16 11:03:10 -07001805 depTag, lib)
Jiyong Park7e636d02019-01-28 16:16:54 +09001806 } else {
1807 actx.AddVariationDependencies(nil, depTag, lib)
1808 }
1809 }
1810
1811 if buildStubs {
1812 // Stubs lib does not have dependency to other static/shared libraries.
1813 // Don't proceed.
1814 return
Colin Cross32ec36c2016-12-15 07:39:51 -08001815 }
Colin Cross5950f382016-12-13 12:50:57 -08001816
Inseob Kimc0907f12019-02-08 21:00:45 +09001817 syspropImplLibraries := syspropImplLibraries(actx.Config())
Inseob Kimeec88e12020-01-22 11:11:29 +09001818 vendorSnapshotStaticLibs := vendorSnapshotStaticLibs(actx.Config())
Inseob Kimc0907f12019-02-08 21:00:45 +09001819
Jiyong Park5d1598f2019-02-25 22:14:17 +09001820 for _, lib := range deps.WholeStaticLibs {
1821 depTag := wholeStaticDepTag
1822 if impl, ok := syspropImplLibraries[lib]; ok {
1823 lib = impl
1824 }
Inseob Kimeec88e12020-01-22 11:11:29 +09001825
1826 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1827
Jiyong Park5d1598f2019-02-25 22:14:17 +09001828 actx.AddVariationDependencies([]blueprint.Variation{
1829 {Mutator: "link", Variation: "static"},
1830 }, depTag, lib)
1831 }
1832
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001833 for _, lib := range deps.StaticLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001834 depTag := StaticDepTag
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001835 if inList(lib, deps.ReexportStaticLibHeaders) {
1836 depTag = staticExportDepTag
1837 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001838
1839 if impl, ok := syspropImplLibraries[lib]; ok {
1840 lib = impl
1841 }
1842
Inseob Kimeec88e12020-01-22 11:11:29 +09001843 lib = rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs)
1844
Dan Willemsen59339a22018-07-22 21:18:45 -07001845 actx.AddVariationDependencies([]blueprint.Variation{
1846 {Mutator: "link", Variation: "static"},
1847 }, depTag, lib)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001848 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001849
Peter Collingbournedc4f9862020-02-12 17:13:25 -08001850 if deps.StaticUnwinderIfLegacy && ctx.Config().UnbundledBuild() {
1851 actx.AddVariationDependencies([]blueprint.Variation{
1852 {Mutator: "link", Variation: "static"},
1853 }, staticUnwinderDepTag, staticUnwinder(actx))
1854 }
1855
Inseob Kimeec88e12020-01-22 11:11:29 +09001856 for _, lib := range deps.LateStaticLibs {
1857 actx.AddVariationDependencies([]blueprint.Variation{
1858 {Mutator: "link", Variation: "static"},
1859 }, lateStaticDepTag, rewriteSnapshotLibs(lib, vendorSnapshotStaticLibs))
1860 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001861
Ivan Lozano183a3212019-10-18 14:18:45 -07001862 addSharedLibDependencies := func(depTag DependencyTag, name string, version string) {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001863 var variations []blueprint.Variation
1864 variations = append(variations, blueprint.Variation{Mutator: "link", Variation: "shared"})
Jooyung Han61b66e92020-03-21 14:21:46 +00001865 versionVariantAvail := !c.InRecovery() && !c.InRamdisk()
Jiyong Park25fc6a92018-11-18 18:02:45 +09001866 if version != "" && versionVariantAvail {
1867 // Version is explicitly specified. i.e. libFoo#30
1868 variations = append(variations, blueprint.Variation{Mutator: "version", Variation: version})
Ivan Lozano183a3212019-10-18 14:18:45 -07001869 depTag.ExplicitlyVersioned = true
Jiyong Park25fc6a92018-11-18 18:02:45 +09001870 }
1871 actx.AddVariationDependencies(variations, depTag, name)
1872
Jooyung Han03b51852020-02-26 22:45:42 +09001873 // If the version is not specified, add dependency to all stubs libraries.
Jiyong Park25fc6a92018-11-18 18:02:45 +09001874 // The stubs library will be used when the depending module is built for APEX and
1875 // the dependent module is not in the same APEX.
Jooyung Han03b51852020-02-26 22:45:42 +09001876 if version == "" && versionVariantAvail {
1877 for _, ver := range stubsVersionsFor(actx.Config())[name] {
1878 // Note that depTag.ExplicitlyVersioned is false in this case.
1879 actx.AddVariationDependencies([]blueprint.Variation{
1880 {Mutator: "link", Variation: "shared"},
1881 {Mutator: "version", Variation: ver},
1882 }, depTag, name)
1883 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001884 }
1885 }
1886
Jiyong Park7ed9de32018-10-15 22:25:07 +09001887 // shared lib names without the #version suffix
1888 var sharedLibNames []string
1889
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001890 for _, lib := range deps.SharedLibs {
Ivan Lozano183a3212019-10-18 14:18:45 -07001891 depTag := SharedDepTag
Jiyong Parkd7536ba2020-01-16 17:14:23 +09001892 if c.static() {
1893 depTag = SharedFromStaticDepTag
1894 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001895 if inList(lib, deps.ReexportSharedLibHeaders) {
1896 depTag = sharedExportDepTag
1897 }
Inseob Kimc0907f12019-02-08 21:00:45 +09001898
1899 if impl, ok := syspropImplLibraries[lib]; ok {
1900 lib = impl
1901 }
1902
Jiyong Park73c54ee2019-10-22 20:31:18 +09001903 name, version := StubsLibNameAndVersion(lib)
Inseob Kimc0907f12019-02-08 21:00:45 +09001904 sharedLibNames = append(sharedLibNames, name)
1905
Jiyong Park25fc6a92018-11-18 18:02:45 +09001906 addSharedLibDependencies(depTag, name, version)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07001907 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001908
Jiyong Park7ed9de32018-10-15 22:25:07 +09001909 for _, lib := range deps.LateSharedLibs {
Jiyong Park25fc6a92018-11-18 18:02:45 +09001910 if inList(lib, sharedLibNames) {
Jiyong Park7ed9de32018-10-15 22:25:07 +09001911 // This is to handle the case that some of the late shared libs (libc, libdl, libm, ...)
1912 // are added also to SharedLibs with version (e.g., libc#10). If not skipped, we will be
1913 // linking against both the stubs lib and the non-stubs lib at the same time.
1914 continue
1915 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09001916 addSharedLibDependencies(lateSharedDepTag, lib, "")
Jiyong Park7ed9de32018-10-15 22:25:07 +09001917 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001918
Dan Willemsen59339a22018-07-22 21:18:45 -07001919 actx.AddVariationDependencies([]blueprint.Variation{
1920 {Mutator: "link", Variation: "shared"},
1921 }, runtimeDepTag, deps.RuntimeLibs...)
Logan Chien43d34c32017-12-20 01:17:32 +08001922
Colin Cross68861832016-07-08 10:41:41 -07001923 actx.AddDependency(c, genSourceDepTag, deps.GeneratedSources...)
Dan Willemsenb3454ab2016-09-28 17:34:58 -07001924
1925 for _, gen := range deps.GeneratedHeaders {
1926 depTag := genHeaderDepTag
1927 if inList(gen, deps.ReexportGeneratedHeaders) {
1928 depTag = genHeaderExportDepTag
1929 }
1930 actx.AddDependency(c, depTag, gen)
1931 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07001932
Colin Cross42d48b72018-08-29 14:10:52 -07001933 actx.AddVariationDependencies(nil, objDepTag, deps.ObjFiles...)
Colin Crossc99deeb2016-04-11 15:06:20 -07001934
1935 if deps.CrtBegin != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001936 actx.AddVariationDependencies(nil, CrtBeginDepTag, deps.CrtBegin)
Colin Crossca860ac2016-01-04 14:34:37 -08001937 }
Colin Crossc99deeb2016-04-11 15:06:20 -07001938 if deps.CrtEnd != "" {
Ivan Lozano183a3212019-10-18 14:18:45 -07001939 actx.AddVariationDependencies(nil, CrtEndDepTag, deps.CrtEnd)
Colin Cross21b9a242015-03-24 14:15:58 -07001940 }
Dan Willemsena0790e32018-10-12 00:24:23 -07001941 if deps.LinkerFlagsFile != "" {
1942 actx.AddDependency(c, linkerFlagsDepTag, deps.LinkerFlagsFile)
1943 }
1944 if deps.DynamicLinker != "" {
1945 actx.AddDependency(c, dynamicLinkerDepTag, deps.DynamicLinker)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07001946 }
Dan Albert914449f2016-06-17 16:45:24 -07001947
1948 version := ctx.sdkVersion()
1949 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001950 {Mutator: "ndk_api", Variation: version},
1951 {Mutator: "link", Variation: "shared"},
1952 }, ndkStubDepTag, variantNdkLibs...)
Dan Albert914449f2016-06-17 16:45:24 -07001953 actx.AddVariationDependencies([]blueprint.Variation{
Dan Willemsen59339a22018-07-22 21:18:45 -07001954 {Mutator: "ndk_api", Variation: version},
1955 {Mutator: "link", Variation: "shared"},
1956 }, ndkLateStubDepTag, variantLateNdkLibs...)
Logan Chienf3511742017-10-31 18:04:35 +08001957
1958 if vndkdep := c.vndkdep; vndkdep != nil {
1959 if vndkdep.isVndkExt() {
Logan Chienf3511742017-10-31 18:04:35 +08001960 actx.AddVariationDependencies([]blueprint.Variation{
Colin Cross7228ecd2019-11-18 16:00:16 -08001961 c.ImageVariation(),
Dan Willemsen59339a22018-07-22 21:18:45 -07001962 {Mutator: "link", Variation: "shared"},
1963 }, vndkExtDepTag, vndkdep.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08001964 }
1965 }
Colin Cross6362e272015-10-29 15:25:03 -07001966}
Colin Cross21b9a242015-03-24 14:15:58 -07001967
Colin Crosse40b4ea2018-10-02 22:25:58 -07001968func BeginMutator(ctx android.BottomUpMutatorContext) {
Dan Albert7e9d2952016-08-04 13:02:36 -07001969 if c, ok := ctx.Module().(*Module); ok && c.Enabled() {
1970 c.beginMutator(ctx)
1971 }
1972}
1973
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001974// Whether a module can link to another module, taking into
1975// account NDK linking.
Ivan Lozano52767be2019-10-18 14:49:46 -07001976func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface, tag DependencyTag) {
1977 if from.Module().Target().Os != android.Android {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001978 // Host code is not restricted
1979 return
1980 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001981
1982 // VNDK is cc.Module supported only for now.
1983 if ccFrom, ok := from.(*Module); ok && from.UseVndk() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001984 // Though vendor code is limited by the vendor mutator,
1985 // each vendor-available module needs to check
1986 // link-type for VNDK.
Ivan Lozano52767be2019-10-18 14:49:46 -07001987 if ccTo, ok := to.(*Module); ok {
1988 if ccFrom.vndkdep != nil {
1989 ccFrom.vndkdep.vndkCheckLinkType(ctx, ccTo, tag)
1990 }
1991 } else {
1992 ctx.ModuleErrorf("Attempting to link VNDK cc.Module with unsupported module type")
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001993 }
1994 return
1995 }
Ivan Lozano52767be2019-10-18 14:49:46 -07001996 if from.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07001997 // Platform code can link to anything
1998 return
1999 }
Yifan Hong1b3348d2020-01-21 15:53:22 -08002000 if from.InRamdisk() {
2001 // Ramdisk code is not NDK
2002 return
2003 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002004 if from.InRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002005 // Recovery code is not NDK
2006 return
2007 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002008 if to.ToolchainLibrary() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002009 // These are always allowed
2010 return
2011 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002012 if to.NdkPrebuiltStl() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002013 // These are allowed, but they don't set sdk_version
2014 return
2015 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002016 if to.StubDecorator() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002017 // These aren't real libraries, but are the stub shared libraries that are included in
2018 // the NDK.
2019 return
2020 }
Logan Chien834b9a62019-01-14 15:39:03 +08002021
Ivan Lozano52767be2019-10-18 14:49:46 -07002022 if strings.HasPrefix(ctx.ModuleName(), "libclang_rt.") && to.Module().Name() == "libc++" {
Logan Chien834b9a62019-01-14 15:39:03 +08002023 // Bug: http://b/121358700 - Allow libclang_rt.* shared libraries (with sdk_version)
2024 // to link to libc++ (non-NDK and without sdk_version).
2025 return
2026 }
2027
Ivan Lozano52767be2019-10-18 14:49:46 -07002028 if to.SdkVersion() == "" {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002029 // NDK code linking to platform code is never okay.
2030 ctx.ModuleErrorf("depends on non-NDK-built library %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002031 ctx.OtherModuleName(to.Module()))
Dan Willemsen155d17c2019-02-06 18:30:02 -08002032 return
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002033 }
2034
2035 // At this point we know we have two NDK libraries, but we need to
2036 // check that we're not linking against anything built against a higher
2037 // API level, as it is only valid to link against older or equivalent
2038 // APIs.
2039
Inseob Kim01a28722018-04-11 09:48:45 +09002040 // Current can link against anything.
Ivan Lozano52767be2019-10-18 14:49:46 -07002041 if from.SdkVersion() != "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002042 // Otherwise we need to check.
Ivan Lozano52767be2019-10-18 14:49:46 -07002043 if to.SdkVersion() == "current" {
Inseob Kim01a28722018-04-11 09:48:45 +09002044 // Current can't be linked against by anything else.
2045 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002046 ctx.OtherModuleName(to.Module()), "current")
Inseob Kim01a28722018-04-11 09:48:45 +09002047 } else {
Ivan Lozano52767be2019-10-18 14:49:46 -07002048 fromApi, err := strconv.Atoi(from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002049 if err != nil {
2050 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002051 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002052 from.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002053 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002054 toApi, err := strconv.Atoi(to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002055 if err != nil {
2056 ctx.PropertyErrorf("sdk_version",
Inseob Kim34b22832018-04-11 10:13:16 +09002057 "Invalid sdk_version value (must be int or current): %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002058 to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002059 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002060
Inseob Kim01a28722018-04-11 09:48:45 +09002061 if toApi > fromApi {
2062 ctx.ModuleErrorf("links %q built against newer API version %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002063 ctx.OtherModuleName(to.Module()), to.SdkVersion())
Inseob Kim01a28722018-04-11 09:48:45 +09002064 }
2065 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002066 }
Dan Albert202fe492017-12-15 13:56:59 -08002067
2068 // Also check that the two STL choices are compatible.
Ivan Lozano52767be2019-10-18 14:49:46 -07002069 fromStl := from.SelectedStl()
2070 toStl := to.SelectedStl()
Dan Albert202fe492017-12-15 13:56:59 -08002071 if fromStl == "" || toStl == "" {
2072 // Libraries that don't use the STL are unrestricted.
Inseob Kimda2171a2018-04-11 15:41:38 +09002073 } else if fromStl == "ndk_system" || toStl == "ndk_system" {
Dan Albert202fe492017-12-15 13:56:59 -08002074 // We can be permissive with the system "STL" since it is only the C++
2075 // ABI layer, but in the future we should make sure that everyone is
2076 // using either libc++ or nothing.
Colin Crossb60190a2018-09-04 16:28:17 -07002077 } else if getNdkStlFamily(from) != getNdkStlFamily(to) {
Dan Albert202fe492017-12-15 13:56:59 -08002078 ctx.ModuleErrorf("uses %q and depends on %q which uses incompatible %q",
Ivan Lozano52767be2019-10-18 14:49:46 -07002079 from.SelectedStl(), ctx.OtherModuleName(to.Module()),
2080 to.SelectedStl())
Dan Albert202fe492017-12-15 13:56:59 -08002081 }
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002082}
2083
Jiyong Park5fb8c102018-04-09 12:03:06 +09002084// Tests whether the dependent library is okay to be double loaded inside a single process.
Jooyung Hana70f0672019-01-18 15:20:43 +09002085// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
2086// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002087// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
Jooyung Hana70f0672019-01-18 15:20:43 +09002088func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
2089 check := func(child, parent android.Module) bool {
2090 to, ok := child.(*Module)
2091 if !ok {
2092 // follow thru cc.Defaults, etc.
2093 return true
2094 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002095
Jooyung Hana70f0672019-01-18 15:20:43 +09002096 if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
2097 return false
Jiyong Park5fb8c102018-04-09 12:03:06 +09002098 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002099
2100 // if target lib has no vendor variant, keep checking dependency graph
Ivan Lozano52767be2019-10-18 14:49:46 -07002101 if !to.HasVendorVariant() {
Jooyung Hana70f0672019-01-18 15:20:43 +09002102 return true
Jiyong Park5fb8c102018-04-09 12:03:06 +09002103 }
Jooyung Hana70f0672019-01-18 15:20:43 +09002104
Jooyung Han0302a842019-10-30 18:43:49 +09002105 if to.isVndkSp() || to.isLlndk(ctx.Config()) || Bool(to.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002106 return false
2107 }
2108
2109 var stringPath []string
2110 for _, m := range ctx.GetWalkPath() {
2111 stringPath = append(stringPath, m.Name())
2112 }
2113 ctx.ModuleErrorf("links a library %q which is not LL-NDK, "+
2114 "VNDK-SP, or explicitly marked as 'double_loadable:true'. "+
2115 "(dependency: %s)", ctx.OtherModuleName(to), strings.Join(stringPath, " -> "))
2116 return false
2117 }
2118 if module, ok := ctx.Module().(*Module); ok {
2119 if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
Jooyung Han0302a842019-10-30 18:43:49 +09002120 if module.isLlndk(ctx.Config()) || Bool(module.VendorProperties.Double_loadable) {
Jooyung Hana70f0672019-01-18 15:20:43 +09002121 ctx.WalkDeps(check)
2122 }
Jiyong Park5fb8c102018-04-09 12:03:06 +09002123 }
2124 }
2125}
2126
Colin Crossc99deeb2016-04-11 15:06:20 -07002127// Convert dependencies to paths. Returns a PathDeps containing paths
Colin Cross635c3b02016-05-18 15:37:25 -07002128func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
Colin Crossca860ac2016-01-04 14:34:37 -08002129 var depPaths PathDeps
Colin Crossca860ac2016-01-04 14:34:37 -08002130
Ivan Lozano183a3212019-10-18 14:18:45 -07002131 directStaticDeps := []LinkableInterface{}
2132 directSharedDeps := []LinkableInterface{}
Jeff Gaston294356f2017-09-27 17:05:30 -07002133
Inseob Kim9516ee92019-05-09 10:56:13 +09002134 vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
2135
Inseob Kim69378442019-06-03 19:10:47 +09002136 reexportExporter := func(exporter exportedFlagsProducer) {
2137 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, exporter.exportedDirs()...)
2138 depPaths.ReexportedSystemDirs = append(depPaths.ReexportedSystemDirs, exporter.exportedSystemDirs()...)
2139 depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, exporter.exportedFlags()...)
2140 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, exporter.exportedDeps()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002141 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders, exporter.exportedGeneratedHeaders()...)
Inseob Kim69378442019-06-03 19:10:47 +09002142 }
2143
Colin Crossd11fcda2017-10-23 17:59:01 -07002144 ctx.VisitDirectDeps(func(dep android.Module) {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002145 depName := ctx.OtherModuleName(dep)
2146 depTag := ctx.OtherModuleDependencyTag(dep)
Dan Albert9e10cd42016-08-03 14:12:14 -07002147
Ivan Lozano52767be2019-10-18 14:49:46 -07002148 ccDep, ok := dep.(LinkableInterface)
2149 if !ok {
2150
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002151 // handling for a few module types that aren't cc Module but that are also supported
2152 switch depTag {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002153 case genSourceDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002154 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002155 depPaths.GeneratedSources = append(depPaths.GeneratedSources,
2156 genRule.GeneratedSourceFiles()...)
2157 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002158 ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002159 }
Colin Crosse90bfd12017-04-26 16:59:26 -07002160 // Support exported headers from a generated_sources dependency
2161 fallthrough
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002162 case genHeaderDepTag, genHeaderExportDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002163 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenb40aab62016-04-20 14:21:14 -07002164 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
Inseob Kimd110f872019-12-06 13:15:38 +09002165 genRule.GeneratedSourceFiles()...)
2166 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps,
Dan Willemsen9da9d492018-02-21 18:28:18 -08002167 genRule.GeneratedDeps()...)
Jiyong Park74955042019-10-22 20:19:51 +09002168 dirs := genRule.GeneratedHeaderDirs()
Inseob Kim69378442019-06-03 19:10:47 +09002169 depPaths.IncludeDirs = append(depPaths.IncludeDirs, dirs...)
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002170 if depTag == genHeaderExportDepTag {
Inseob Kim69378442019-06-03 19:10:47 +09002171 depPaths.ReexportedDirs = append(depPaths.ReexportedDirs, dirs...)
Inseob Kimd110f872019-12-06 13:15:38 +09002172 depPaths.ReexportedGeneratedHeaders = append(depPaths.ReexportedGeneratedHeaders,
2173 genRule.GeneratedSourceFiles()...)
Inseob Kim69378442019-06-03 19:10:47 +09002174 depPaths.ReexportedDeps = append(depPaths.ReexportedDeps, genRule.GeneratedDeps()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002175 // 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 +09002176 c.sabi.Properties.ReexportedIncludes = append(c.sabi.Properties.ReexportedIncludes, dirs.Strings()...)
Jayant Chowdhary715cac32017-04-20 06:53:59 -07002177
Dan Willemsenb3454ab2016-09-28 17:34:58 -07002178 }
Dan Willemsenb40aab62016-04-20 14:21:14 -07002179 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002180 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenb40aab62016-04-20 14:21:14 -07002181 }
Dan Willemsena0790e32018-10-12 00:24:23 -07002182 case linkerFlagsDepTag:
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002183 if genRule, ok := dep.(genrule.SourceFileGenerator); ok {
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002184 files := genRule.GeneratedSourceFiles()
2185 if len(files) == 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002186 depPaths.LinkerFlagsFile = android.OptionalPathForPath(files[0])
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002187 } else if len(files) > 1 {
Dan Willemsena0790e32018-10-12 00:24:23 -07002188 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 -07002189 }
2190 } else {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002191 ctx.ModuleErrorf("module %q is not a genrule", depName)
Dan Willemsenc77a0b32017-09-18 23:19:12 -07002192 }
Colin Crossca860ac2016-01-04 14:34:37 -08002193 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002194 return
2195 }
2196
Colin Crossfe17f6f2019-03-28 19:30:56 -07002197 if depTag == android.ProtoPluginDepTag {
2198 return
2199 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002200 if depTag == llndkImplDep {
2201 return
2202 }
Colin Crossfe17f6f2019-03-28 19:30:56 -07002203
Colin Crossd11fcda2017-10-23 17:59:01 -07002204 if dep.Target().Os != ctx.Os() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002205 ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName)
2206 return
2207 }
Colin Crossd11fcda2017-10-23 17:59:01 -07002208 if dep.Target().Arch.ArchType != ctx.Arch().ArchType {
Jooyung Han61b66e92020-03-21 14:21:46 +00002209 ctx.ModuleErrorf("Arch mismatch between %q(%v) and %q(%v)",
2210 ctx.ModuleName(), ctx.Arch().ArchType, depName, dep.Target().Arch.ArchType)
Colin Crossa1ad8d12016-06-01 17:09:44 -07002211 return
2212 }
2213
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002214 // re-exporting flags
2215 if depTag == reuseObjTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002216 // reusing objects only make sense for cc.Modules.
2217 if ccReuseDep, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002218 c.staticVariant = ccDep
Ivan Lozano52767be2019-10-18 14:49:46 -07002219 objs, exporter := ccReuseDep.compiler.(libraryInterface).reuseObjs()
Colin Cross10d22312017-05-03 11:01:58 -07002220 depPaths.Objs = depPaths.Objs.Append(objs)
Inseob Kim69378442019-06-03 19:10:47 +09002221 reexportExporter(exporter)
Colin Crossbba99042016-11-23 15:45:05 -08002222 return
2223 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002224 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002225
Jiyong Parke4bb9862019-02-01 00:31:10 +09002226 if depTag == staticVariantTag {
Ivan Lozano52767be2019-10-18 14:49:46 -07002227 // staticVariants are a cc.Module specific concept.
2228 if _, ok := ccDep.(*Module); ok && ccDep.CcLibraryInterface() {
Jiyong Parke4bb9862019-02-01 00:31:10 +09002229 c.staticVariant = ccDep
2230 return
2231 }
2232 }
2233
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002234 if depTag == staticUnwinderDepTag {
Jooyung Han03b51852020-02-26 22:45:42 +09002235 // Use static unwinder for legacy (min_sdk_version = 29) apexes (b/144430859)
2236 if c.ShouldSupportAndroid10() {
Peter Collingbournedc4f9862020-02-12 17:13:25 -08002237 depTag = StaticDepTag
2238 } else {
2239 return
2240 }
2241 }
2242
Ivan Lozano183a3212019-10-18 14:18:45 -07002243 // Extract ExplicitlyVersioned field from the depTag and reset it inside the struct.
2244 // Otherwise, SharedDepTag and lateSharedDepTag with ExplicitlyVersioned set to true
2245 // won't be matched to SharedDepTag and lateSharedDepTag.
Jiyong Park25fc6a92018-11-18 18:02:45 +09002246 explicitlyVersioned := false
Ivan Lozano183a3212019-10-18 14:18:45 -07002247 if t, ok := depTag.(DependencyTag); ok {
2248 explicitlyVersioned = t.ExplicitlyVersioned
2249 t.ExplicitlyVersioned = false
Jiyong Park25fc6a92018-11-18 18:02:45 +09002250 depTag = t
2251 }
2252
Ivan Lozano183a3212019-10-18 14:18:45 -07002253 if t, ok := depTag.(DependencyTag); ok && t.Library {
Jiyong Park16e91a02018-12-20 18:18:08 +09002254 depIsStatic := false
2255 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002256 case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
Jiyong Park16e91a02018-12-20 18:18:08 +09002257 depIsStatic = true
2258 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002259 if ccDep.CcLibrary() && !depIsStatic {
2260 depIsStubs := ccDep.BuildStubs()
Jiyong Park25fc6a92018-11-18 18:02:45 +09002261 depHasStubs := ccDep.HasStubsVariants()
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002262 depInSameApex := android.DirectlyInApex(c.ApexName(), depName)
Nicolas Geoffrayc22c1bf2019-01-15 19:53:23 +00002263 depInPlatform := !android.DirectlyInAnyApex(ctx, depName)
Jiyong Park25fc6a92018-11-18 18:02:45 +09002264
2265 var useThisDep bool
2266 if depIsStubs && explicitlyVersioned {
2267 // Always respect dependency to the versioned stubs (i.e. libX#10)
2268 useThisDep = true
2269 } else if !depHasStubs {
2270 // Use non-stub variant if that is the only choice
2271 // (i.e. depending on a lib without stubs.version property)
2272 useThisDep = true
2273 } else if c.IsForPlatform() {
2274 // If not building for APEX, use stubs only when it is from
2275 // an APEX (and not from platform)
2276 useThisDep = (depInPlatform != depIsStubs)
Yifan Hong1b3348d2020-01-21 15:53:22 -08002277 if c.InRamdisk() || c.InRecovery() || c.bootstrap() {
2278 // However, for ramdisk, recovery or bootstrap modules,
Jiyong Park25fc6a92018-11-18 18:02:45 +09002279 // always link to non-stub variant
2280 useThisDep = !depIsStubs
2281 }
2282 } else {
2283 // If building for APEX, use stubs only when it is not from
2284 // the same APEX
2285 useThisDep = (depInSameApex != depIsStubs)
2286 }
2287
Jooyung Han03b51852020-02-26 22:45:42 +09002288 // when to use (unspecified) stubs, check min_sdk_version and choose the right one
2289 if useThisDep && depIsStubs && !explicitlyVersioned {
2290 useLatest := c.IsForPlatform() || (c.ShouldSupportAndroid10() && !ctx.Config().UnbundledBuild())
2291 versionToUse, err := c.ChooseSdkVersion(ccDep.StubsVersions(), useLatest)
2292 if err != nil {
2293 ctx.OtherModuleErrorf(dep, err.Error())
2294 return
2295 }
2296 if versionToUse != ccDep.StubsVersion() {
2297 useThisDep = false
2298 }
2299 }
2300
Jiyong Park25fc6a92018-11-18 18:02:45 +09002301 if !useThisDep {
2302 return // stop processing this dep
2303 }
2304 }
Jooyung Han61b66e92020-03-21 14:21:46 +00002305 if c.UseVndk() {
2306 if m, ok := ccDep.(*Module); ok && m.IsStubs() { // LLNDK
2307 // by default, use current version of LLNDK
2308 versionToUse := ""
2309 versions := stubsVersionsFor(ctx.Config())[depName]
2310 if c.ApexName() != "" && len(versions) > 0 {
2311 // if this is for use_vendor apex && dep has stubsVersions
2312 // apply the same rule of apex sdk enforcement to choose right version
2313 var err error
2314 useLatest := c.ShouldSupportAndroid10() && !ctx.Config().UnbundledBuild()
2315 versionToUse, err = c.ChooseSdkVersion(versions, useLatest)
2316 if err != nil {
2317 ctx.OtherModuleErrorf(dep, err.Error())
2318 return
2319 }
2320 }
2321 if versionToUse != ccDep.StubsVersion() {
2322 return
2323 }
2324 }
2325 }
Jiyong Park25fc6a92018-11-18 18:02:45 +09002326
Ivan Lozanoe0833b12019-11-06 19:15:49 -08002327 depPaths.IncludeDirs = append(depPaths.IncludeDirs, ccDep.IncludeDirs()...)
2328
Ivan Lozano52767be2019-10-18 14:49:46 -07002329 // Exporting flags only makes sense for cc.Modules
2330 if _, ok := ccDep.(*Module); ok {
2331 if i, ok := ccDep.(*Module).linker.(exportedFlagsProducer); ok {
Ivan Lozano52767be2019-10-18 14:49:46 -07002332 depPaths.SystemIncludeDirs = append(depPaths.SystemIncludeDirs, i.exportedSystemDirs()...)
Inseob Kimd110f872019-12-06 13:15:38 +09002333 depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, i.exportedGeneratedHeaders()...)
2334 depPaths.GeneratedDeps = append(depPaths.GeneratedDeps, i.exportedDeps()...)
Ivan Lozano52767be2019-10-18 14:49:46 -07002335 depPaths.Flags = append(depPaths.Flags, i.exportedFlags()...)
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002336
Ivan Lozano52767be2019-10-18 14:49:46 -07002337 if t.ReexportFlags {
2338 reexportExporter(i)
2339 // Add these re-exported flags to help header-abi-dumper to infer the abi exported by a library.
2340 // Re-exported shared library headers must be included as well since they can help us with type information
2341 // about template instantiations (instantiated from their headers).
2342 // -isystem headers are not included since for bionic libraries, abi-filtering is taken care of by version
2343 // scripts.
2344 c.sabi.Properties.ReexportedIncludes = append(
2345 c.sabi.Properties.ReexportedIncludes, i.exportedDirs().Strings()...)
2346 }
Dan Willemsen490a8dc2016-06-06 18:22:19 -07002347 }
Colin Crossc99deeb2016-04-11 15:06:20 -07002348 }
Logan Chienf3511742017-10-31 18:04:35 +08002349 checkLinkType(ctx, c, ccDep, t)
Colin Crossc99deeb2016-04-11 15:06:20 -07002350 }
2351
Colin Cross26c34ed2016-09-30 17:10:16 -07002352 var ptr *android.Paths
Colin Cross635c3b02016-05-18 15:37:25 -07002353 var depPtr *android.Paths
Colin Crossc99deeb2016-04-11 15:06:20 -07002354
Ivan Lozano52767be2019-10-18 14:49:46 -07002355 linkFile := ccDep.OutputFile()
Colin Cross26c34ed2016-09-30 17:10:16 -07002356 depFile := android.OptionalPath{}
2357
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002358 switch depTag {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002359 case ndkStubDepTag, SharedDepTag, SharedFromStaticDepTag, sharedExportDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002360 ptr = &depPaths.SharedLibs
2361 depPtr = &depPaths.SharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002362 depFile = ccDep.Toc()
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002363 directSharedDeps = append(directSharedDeps, ccDep)
Ivan Lozano183a3212019-10-18 14:18:45 -07002364
Jiyong Park64a44f22019-01-18 14:37:08 +09002365 case earlySharedDepTag:
2366 ptr = &depPaths.EarlySharedLibs
2367 depPtr = &depPaths.EarlySharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002368 depFile = ccDep.Toc()
Jiyong Park64a44f22019-01-18 14:37:08 +09002369 directSharedDeps = append(directSharedDeps, ccDep)
Dan Albert914449f2016-06-17 16:45:24 -07002370 case lateSharedDepTag, ndkLateStubDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002371 ptr = &depPaths.LateSharedLibs
2372 depPtr = &depPaths.LateSharedLibsDeps
Ivan Lozano52767be2019-10-18 14:49:46 -07002373 depFile = ccDep.Toc()
Ivan Lozano183a3212019-10-18 14:18:45 -07002374 case StaticDepTag, staticExportDepTag:
Jeff Gaston294356f2017-09-27 17:05:30 -07002375 ptr = nil
2376 directStaticDeps = append(directStaticDeps, ccDep)
Colin Crossc99deeb2016-04-11 15:06:20 -07002377 case lateStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002378 ptr = &depPaths.LateStaticLibs
Colin Crossc99deeb2016-04-11 15:06:20 -07002379 case wholeStaticDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002380 ptr = &depPaths.WholeStaticLibs
Ivan Lozano52767be2019-10-18 14:49:46 -07002381 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002382 ctx.ModuleErrorf("module %q not a static library", depName)
Colin Crossc99deeb2016-04-11 15:06:20 -07002383 return
2384 }
2385
Ivan Lozano52767be2019-10-18 14:49:46 -07002386 // Because the static library objects are included, this only makes sense
2387 // in the context of proper cc.Modules.
2388 if ccWholeStaticLib, ok := ccDep.(*Module); ok {
2389 staticLib := ccWholeStaticLib.linker.(libraryInterface)
2390 if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
2391 postfix := " (required by " + ctx.OtherModuleName(dep) + ")"
2392 for i := range missingDeps {
2393 missingDeps[i] += postfix
2394 }
2395 ctx.AddMissingDependencies(missingDeps)
Colin Crossc99deeb2016-04-11 15:06:20 -07002396 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002397 depPaths.WholeStaticLibObjs = depPaths.WholeStaticLibObjs.Append(staticLib.objs())
2398 } else {
2399 ctx.ModuleErrorf(
2400 "non-cc.Modules cannot be included as whole static libraries.", depName)
2401 return
Colin Crossc99deeb2016-04-11 15:06:20 -07002402 }
Colin Cross5950f382016-12-13 12:50:57 -08002403 case headerDepTag:
2404 // Nothing
Colin Crossc99deeb2016-04-11 15:06:20 -07002405 case objDepTag:
Dan Willemsen5cb580f2016-09-26 17:33:01 -07002406 depPaths.Objs.objFiles = append(depPaths.Objs.objFiles, linkFile.Path())
Ivan Lozano183a3212019-10-18 14:18:45 -07002407 case CrtBeginDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002408 depPaths.CrtBegin = linkFile
Ivan Lozano183a3212019-10-18 14:18:45 -07002409 case CrtEndDepTag:
Colin Cross26c34ed2016-09-30 17:10:16 -07002410 depPaths.CrtEnd = linkFile
Dan Willemsena0790e32018-10-12 00:24:23 -07002411 case dynamicLinkerDepTag:
2412 depPaths.DynamicLinker = linkFile
Colin Crossc99deeb2016-04-11 15:06:20 -07002413 }
2414
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002415 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002416 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002417 if !ccDep.CcLibraryInterface() || !ccDep.Static() {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002418 ctx.ModuleErrorf("module %q not a static library", depName)
Dan Willemsen581341d2017-02-09 16:16:31 -08002419 return
2420 }
2421
2422 // When combining coverage files for shared libraries and executables, coverage files
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002423 // in static libraries act as if they were whole static libraries. The same goes for
2424 // source based Abi dump files.
Ivan Lozano52767be2019-10-18 14:49:46 -07002425 // This should only be done for cc.Modules
2426 if c, ok := ccDep.(*Module); ok {
2427 staticLib := c.linker.(libraryInterface)
2428 depPaths.StaticLibObjs.coverageFiles = append(depPaths.StaticLibObjs.coverageFiles,
2429 staticLib.objs().coverageFiles...)
2430 depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
2431 staticLib.objs().sAbiDumpFiles...)
2432 }
Dan Willemsen581341d2017-02-09 16:16:31 -08002433 }
2434
Colin Cross26c34ed2016-09-30 17:10:16 -07002435 if ptr != nil {
Colin Crossce75d2c2016-10-06 16:12:58 -07002436 if !linkFile.Valid() {
Isaac Chen2c0a1802019-10-15 17:16:05 +08002437 if !ctx.Config().AllowMissingDependencies() {
2438 ctx.ModuleErrorf("module %q missing output file", depName)
2439 } else {
2440 ctx.AddMissingDependencies([]string{depName})
2441 }
Colin Crossce75d2c2016-10-06 16:12:58 -07002442 return
2443 }
Colin Cross26c34ed2016-09-30 17:10:16 -07002444 *ptr = append(*ptr, linkFile.Path())
2445 }
2446
Colin Crossc99deeb2016-04-11 15:06:20 -07002447 if depPtr != nil {
Colin Cross26c34ed2016-09-30 17:10:16 -07002448 dep := depFile
2449 if !dep.Valid() {
2450 dep = linkFile
2451 }
2452 *depPtr = append(*depPtr, dep.Path())
Colin Crossca860ac2016-01-04 14:34:37 -08002453 }
Jiyong Park27b188b2017-07-18 13:23:39 +09002454
Inseob Kimeec88e12020-01-22 11:11:29 +09002455 vendorSuffixModules := vendorSuffixModules(ctx.Config())
2456
2457 baseLibName := func(depName string) string {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002458 libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
Jiyong Park374510b2018-03-19 18:23:01 +09002459 libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
Jiyong Park27b188b2017-07-18 13:23:39 +09002460 libName = strings.TrimPrefix(libName, "prebuilt_")
Inseob Kimeec88e12020-01-22 11:11:29 +09002461 return libName
2462 }
2463
2464 makeLibName := func(depName string) string {
2465 libName := baseLibName(depName)
Jooyung Han0302a842019-10-30 18:43:49 +09002466 isLLndk := isLlndkLibrary(libName, ctx.Config())
Inseob Kim9516ee92019-05-09 10:56:13 +09002467 isVendorPublicLib := inList(libName, *vendorPublicLibraries)
Ivan Lozano52767be2019-10-18 14:49:46 -07002468 bothVendorAndCoreVariantsExist := ccDep.HasVendorVariant() || isLLndk
Vic Yangefd249e2018-11-12 20:19:56 -08002469
Inseob Kimeec88e12020-01-22 11:11:29 +09002470 if c, ok := ccDep.(*Module); ok {
2471 // Use base module name for snapshots when exporting to Makefile.
Inseob Kim752edec2020-03-14 01:30:34 +09002472 if c.isSnapshotPrebuilt() {
Inseob Kimeec88e12020-01-22 11:11:29 +09002473 baseName := c.BaseModuleName()
Inseob Kim752edec2020-03-14 01:30:34 +09002474
2475 if c.IsVndk() {
2476 return baseName + ".vendor"
2477 }
2478
Inseob Kimeec88e12020-01-22 11:11:29 +09002479 if vendorSuffixModules[baseName] {
2480 return baseName + ".vendor"
2481 } else {
2482 return baseName
2483 }
2484 }
2485 }
2486
Yifan Hong1b3348d2020-01-21 15:53:22 -08002487 if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.IsVndk() && !ccDep.MustUseVendorVariant() && !c.InRamdisk() && !c.InRecovery() {
Vic Yangefd249e2018-11-12 20:19:56 -08002488 // The vendor module is a no-vendor-variant VNDK library. Depend on the
2489 // core module instead.
2490 return libName
Ivan Lozano52767be2019-10-18 14:49:46 -07002491 } else if c.UseVndk() && bothVendorAndCoreVariantsExist {
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002492 // The vendor module in Make will have been renamed to not conflict with the core
2493 // module, so update the dependency name here accordingly.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002494 return libName + c.getNameSuffixWithVndkVersion(ctx)
Jiyong Park374510b2018-03-19 18:23:01 +09002495 } else if (ctx.Platform() || ctx.ProductSpecific()) && isVendorPublicLib {
Logan Chien43d34c32017-12-20 01:17:32 +08002496 return libName + vendorPublicLibrarySuffix
Yifan Hong1b3348d2020-01-21 15:53:22 -08002497 } else if ccDep.InRamdisk() && !ccDep.OnlyInRamdisk() {
2498 return libName + ramdiskSuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002499 } else if ccDep.InRecovery() && !ccDep.OnlyInRecovery() {
Jiyong Parkf9332f12018-02-01 00:54:12 +09002500 return libName + recoverySuffix
Ivan Lozano52767be2019-10-18 14:49:46 -07002501 } else if ccDep.Module().Target().NativeBridge == android.NativeBridgeEnabled {
dimitry43204492019-05-23 13:24:38 +02002502 return libName + nativeBridgeSuffix
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002503 } else {
Logan Chien43d34c32017-12-20 01:17:32 +08002504 return libName
Jiyong Park27b188b2017-07-18 13:23:39 +09002505 }
Logan Chien43d34c32017-12-20 01:17:32 +08002506 }
2507
2508 // Export the shared libs to Make.
2509 switch depTag {
Ivan Lozano183a3212019-10-18 14:18:45 -07002510 case SharedDepTag, sharedExportDepTag, lateSharedDepTag, earlySharedDepTag:
Ivan Lozano52767be2019-10-18 14:49:46 -07002511 if ccDep.CcLibrary() {
2512 if ccDep.BuildStubs() && android.InAnyApex(depName) {
Logan Chien09106e12019-01-18 14:57:48 +08002513 // Add the dependency to the APEX(es) providing the library so that
Jiyong Parkde866cb2018-12-07 23:08:36 +09002514 // m <module> can trigger building the APEXes as well.
Jiyong Park0ddfcd12018-12-11 01:35:25 +09002515 for _, an := range android.GetApexesForModule(depName) {
Jiyong Parkde866cb2018-12-07 23:08:36 +09002516 c.Properties.ApexesProvidingSharedLibs = append(
2517 c.Properties.ApexesProvidingSharedLibs, an)
2518 }
Jiyong Parkde866cb2018-12-07 23:08:36 +09002519 }
2520 }
2521
Jiyong Park27b188b2017-07-18 13:23:39 +09002522 // Note: the order of libs in this list is not important because
Jeff Gastonaf3cc2d2017-09-27 17:01:44 -07002523 // they merely serve as Make dependencies and do not affect this lib itself.
Logan Chien43d34c32017-12-20 01:17:32 +08002524 c.Properties.AndroidMkSharedLibs = append(
2525 c.Properties.AndroidMkSharedLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002526 // Record baseLibName for snapshots.
2527 c.Properties.SnapshotSharedLibs = append(c.Properties.SnapshotSharedLibs, baseLibName(depName))
Logan Chienc7f797e2019-01-14 15:35:08 +08002528 case ndkStubDepTag, ndkLateStubDepTag:
Logan Chienc7f797e2019-01-14 15:35:08 +08002529 c.Properties.AndroidMkSharedLibs = append(
2530 c.Properties.AndroidMkSharedLibs,
Ivan Lozano52767be2019-10-18 14:49:46 -07002531 depName+"."+ccDep.ApiLevel())
Ivan Lozano183a3212019-10-18 14:18:45 -07002532 case StaticDepTag, staticExportDepTag, lateStaticDepTag:
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002533 c.Properties.AndroidMkStaticLibs = append(
2534 c.Properties.AndroidMkStaticLibs, makeLibName(depName))
Logan Chien43d34c32017-12-20 01:17:32 +08002535 case runtimeDepTag:
2536 c.Properties.AndroidMkRuntimeLibs = append(
2537 c.Properties.AndroidMkRuntimeLibs, makeLibName(depName))
Inseob Kimeec88e12020-01-22 11:11:29 +09002538 // Record baseLibName for snapshots.
2539 c.Properties.SnapshotRuntimeLibs = append(c.Properties.SnapshotRuntimeLibs, baseLibName(depName))
Jaewoong Jung16c7d3d2018-11-16 01:19:56 +00002540 case wholeStaticDepTag:
2541 c.Properties.AndroidMkWholeStaticLibs = append(
2542 c.Properties.AndroidMkWholeStaticLibs, makeLibName(depName))
Jiyong Park27b188b2017-07-18 13:23:39 +09002543 }
Colin Crossca860ac2016-01-04 14:34:37 -08002544 })
2545
Jeff Gaston294356f2017-09-27 17:05:30 -07002546 // use the ordered dependencies as this module's dependencies
Jeff Gastonf5b6e8f2017-11-27 15:48:57 -08002547 depPaths.StaticLibs = append(depPaths.StaticLibs, orderStaticModuleDeps(c, directStaticDeps, directSharedDeps)...)
Jeff Gaston294356f2017-09-27 17:05:30 -07002548
Colin Crossdd84e052017-05-17 13:44:16 -07002549 // Dedup exported flags from dependencies
Colin Crossb6715442017-10-24 11:13:31 -07002550 depPaths.Flags = android.FirstUniqueStrings(depPaths.Flags)
Jiyong Park74955042019-10-22 20:19:51 +09002551 depPaths.IncludeDirs = android.FirstUniquePaths(depPaths.IncludeDirs)
2552 depPaths.SystemIncludeDirs = android.FirstUniquePaths(depPaths.SystemIncludeDirs)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002553 depPaths.GeneratedHeaders = android.FirstUniquePaths(depPaths.GeneratedHeaders)
Inseob Kimd110f872019-12-06 13:15:38 +09002554 depPaths.GeneratedDeps = android.FirstUniquePaths(depPaths.GeneratedDeps)
Jiyong Park74955042019-10-22 20:19:51 +09002555 depPaths.ReexportedDirs = android.FirstUniquePaths(depPaths.ReexportedDirs)
2556 depPaths.ReexportedSystemDirs = android.FirstUniquePaths(depPaths.ReexportedSystemDirs)
Colin Crossb6715442017-10-24 11:13:31 -07002557 depPaths.ReexportedFlags = android.FirstUniqueStrings(depPaths.ReexportedFlags)
Inseob Kim69378442019-06-03 19:10:47 +09002558 depPaths.ReexportedDeps = android.FirstUniquePaths(depPaths.ReexportedDeps)
Inseob Kimd110f872019-12-06 13:15:38 +09002559 depPaths.ReexportedGeneratedHeaders = android.FirstUniquePaths(depPaths.ReexportedGeneratedHeaders)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002560
2561 if c.sabi != nil {
Inseob Kim69378442019-06-03 19:10:47 +09002562 c.sabi.Properties.ReexportedIncludes = android.FirstUniqueStrings(c.sabi.Properties.ReexportedIncludes)
Dan Willemsenfe92c962017-08-29 12:28:37 -07002563 }
Colin Crossdd84e052017-05-17 13:44:16 -07002564
Colin Crossca860ac2016-01-04 14:34:37 -08002565 return depPaths
2566}
2567
2568func (c *Module) InstallInData() bool {
2569 if c.installer == nil {
2570 return false
2571 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002572 return c.installer.inData()
2573}
2574
2575func (c *Module) InstallInSanitizerDir() bool {
2576 if c.installer == nil {
2577 return false
2578 }
2579 if c.sanitize != nil && c.sanitize.inSanitizerDir() {
Colin Cross94610402016-08-29 13:41:32 -07002580 return true
2581 }
Vishwath Mohan1dd88392017-03-29 22:00:18 -07002582 return c.installer.inSanitizerDir()
Colin Crossca860ac2016-01-04 14:34:37 -08002583}
2584
Yifan Hong1b3348d2020-01-21 15:53:22 -08002585func (c *Module) InstallInRamdisk() bool {
2586 return c.InRamdisk()
2587}
2588
Jiyong Parkf9332f12018-02-01 00:54:12 +09002589func (c *Module) InstallInRecovery() bool {
Ivan Lozano52767be2019-10-18 14:49:46 -07002590 return c.InRecovery()
Jiyong Parkf9332f12018-02-01 00:54:12 +09002591}
2592
Dan Willemsen4aa75ca2016-09-28 16:18:03 -07002593func (c *Module) HostToolPath() android.OptionalPath {
2594 if c.installer == nil {
2595 return android.OptionalPath{}
2596 }
2597 return c.installer.hostToolPath()
2598}
2599
Nan Zhangd4e641b2017-07-12 12:55:28 -07002600func (c *Module) IntermPathForModuleOut() android.OptionalPath {
2601 return c.outputFile
2602}
2603
Colin Cross41955e82019-05-29 14:40:35 -07002604func (c *Module) OutputFiles(tag string) (android.Paths, error) {
2605 switch tag {
2606 case "":
2607 if c.outputFile.Valid() {
2608 return android.Paths{c.outputFile.Path()}, nil
2609 }
2610 return android.Paths{}, nil
2611 default:
2612 return nil, fmt.Errorf("unsupported module reference tag %q", tag)
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002613 }
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002614}
2615
Vishwath Mohanb743e9c2017-11-01 09:20:21 +00002616func (c *Module) static() bool {
2617 if static, ok := c.linker.(interface {
2618 static() bool
2619 }); ok {
2620 return static.static()
2621 }
2622 return false
2623}
2624
Jiyong Park379de2f2018-12-19 02:47:14 +09002625func (c *Module) staticBinary() bool {
2626 if static, ok := c.linker.(interface {
2627 staticBinary() bool
2628 }); ok {
2629 return static.staticBinary()
2630 }
2631 return false
2632}
2633
Jiyong Park1d1119f2019-07-29 21:27:18 +09002634func (c *Module) header() bool {
2635 if h, ok := c.linker.(interface {
2636 header() bool
2637 }); ok {
2638 return h.header()
2639 }
2640 return false
2641}
2642
Jooyung Han38002912019-05-16 04:01:54 +09002643func (c *Module) getMakeLinkType(actx android.ModuleContext) string {
Ivan Lozano52767be2019-10-18 14:49:46 -07002644 if c.UseVndk() {
Jooyung Han38002912019-05-16 04:01:54 +09002645 if lib, ok := c.linker.(*llndkStubDecorator); ok {
2646 if Bool(lib.Properties.Vendor_available) {
Colin Crossb60190a2018-09-04 16:28:17 -07002647 return "native:vndk"
2648 }
Jooyung Han38002912019-05-16 04:01:54 +09002649 return "native:vndk_private"
Colin Crossb60190a2018-09-04 16:28:17 -07002650 }
Ivan Lozano52767be2019-10-18 14:49:46 -07002651 if c.IsVndk() && !c.isVndkExt() {
Jooyung Han38002912019-05-16 04:01:54 +09002652 if Bool(c.VendorProperties.Vendor_available) {
2653 return "native:vndk"
2654 }
2655 return "native:vndk_private"
2656 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09002657 if c.inProduct() {
2658 return "native:product"
2659 }
Jooyung Han38002912019-05-16 04:01:54 +09002660 return "native:vendor"
Yifan Hong1b3348d2020-01-21 15:53:22 -08002661 } else if c.InRamdisk() {
2662 return "native:ramdisk"
Ivan Lozano52767be2019-10-18 14:49:46 -07002663 } else if c.InRecovery() {
Colin Crossb60190a2018-09-04 16:28:17 -07002664 return "native:recovery"
2665 } else if c.Target().Os == android.Android && String(c.Properties.Sdk_version) != "" {
2666 return "native:ndk:none:none"
2667 // TODO(b/114741097): use the correct ndk stl once build errors have been fixed
2668 //family, link := getNdkStlFamilyAndLinkType(c)
2669 //return fmt.Sprintf("native:ndk:%s:%s", family, link)
Ivan Lozano52767be2019-10-18 14:49:46 -07002670 } else if actx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
Vic Yangefd249e2018-11-12 20:19:56 -08002671 return "native:platform_vndk"
Colin Crossb60190a2018-09-04 16:28:17 -07002672 } else {
2673 return "native:platform"
2674 }
2675}
2676
Jiyong Park9d452992018-10-03 00:38:19 +09002677// Overrides ApexModule.IsInstallabeToApex()
Roland Levillainf89cd092019-07-29 16:22:59 +01002678// Only shared/runtime libraries and "test_per_src" tests are installable to APEX.
Jiyong Park9d452992018-10-03 00:38:19 +09002679func (c *Module) IsInstallableToApex() bool {
2680 if shared, ok := c.linker.(interface {
2681 shared() bool
2682 }); ok {
Jiyong Park73c54ee2019-10-22 20:31:18 +09002683 // Stub libs and prebuilt libs in a versioned SDK are not
2684 // installable to APEX even though they are shared libs.
2685 return shared.shared() && !c.IsStubs() && c.ContainingSdk().Unversioned()
Roland Levillainf89cd092019-07-29 16:22:59 +01002686 } else if _, ok := c.linker.(testPerSrc); ok {
2687 return true
Jiyong Park9d452992018-10-03 00:38:19 +09002688 }
2689 return false
2690}
2691
Jiyong Parka90ca002019-10-07 15:47:24 +09002692func (c *Module) AvailableFor(what string) bool {
2693 if linker, ok := c.linker.(interface {
2694 availableFor(string) bool
2695 }); ok {
2696 return c.ApexModuleBase.AvailableFor(what) || linker.availableFor(what)
2697 } else {
2698 return c.ApexModuleBase.AvailableFor(what)
2699 }
2700}
2701
Paul Duffin0cb37b92020-03-04 14:52:46 +00002702// Return true if the module is ever installable.
2703func (c *Module) EverInstallable() bool {
2704 return c.installer != nil &&
2705 // Check to see whether the module is actually ever installable.
2706 c.installer.everInstallable()
2707}
2708
Inseob Kim1f086e22019-05-09 13:29:15 +09002709func (c *Module) installable() bool {
Paul Duffin0cb37b92020-03-04 14:52:46 +00002710 ret := c.EverInstallable() &&
2711 // Check to see whether the module has been configured to not be installed.
2712 proptools.BoolDefault(c.Properties.Installable, true) &&
2713 !c.Properties.PreventInstall && c.outputFile.Valid()
Jiyong Parkfe9a4302020-01-07 16:59:44 +09002714
2715 // The platform variant doesn't need further condition. Apex variants however might not
2716 // be installable because it will likely to be included in the APEX and won't appear
2717 // in the system partition.
2718 if c.IsForPlatform() {
2719 return ret
2720 }
2721
2722 // Special case for modules that are configured to be installed to /data, which includes
2723 // test modules. For these modules, both APEX and non-APEX variants are considered as
2724 // installable. This is because even the APEX variants won't be included in the APEX, but
2725 // will anyway be installed to /data/*.
2726 // See b/146995717
2727 if c.InstallInData() {
2728 return ret
2729 }
2730
2731 return false
Inseob Kim1f086e22019-05-09 13:29:15 +09002732}
2733
Logan Chien41eabe62019-04-10 13:33:58 +08002734func (c *Module) AndroidMkWriteAdditionalDependenciesForSourceAbiDiff(w io.Writer) {
2735 if c.linker != nil {
2736 if library, ok := c.linker.(*libraryDecorator); ok {
2737 library.androidMkWriteAdditionalDependenciesForSourceAbiDiff(w)
2738 }
2739 }
2740}
2741
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002742func (c *Module) DepIsInSameApex(ctx android.BaseModuleContext, dep android.Module) bool {
Ivan Lozano183a3212019-10-18 14:18:45 -07002743 if depTag, ok := ctx.OtherModuleDependencyTag(dep).(DependencyTag); ok {
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002744 if cc, ok := dep.(*Module); ok {
Jiyong Park323a4c32020-03-01 17:29:06 +09002745 if cc.HasStubsVariants() {
2746 if depTag.Shared && depTag.Library {
2747 // dynamic dep to a stubs lib crosses APEX boundary
2748 return false
2749 }
2750 if IsRuntimeDepTag(depTag) {
2751 // runtime dep to a stubs lib also crosses APEX boundary
2752 return false
2753 }
Jiyong Parkd7536ba2020-01-16 17:14:23 +09002754 }
2755 if depTag.FromStatic {
2756 // shared_lib dependency from a static lib is considered as crossing
2757 // the APEX boundary because the dependency doesn't actually is
2758 // linked; the dependency is used only during the compilation phase.
2759 return false
2760 }
Jiyong Parka7bc8ad2019-10-15 15:20:07 +09002761 }
2762 }
2763 return true
2764}
2765
Colin Cross2ba19d92015-05-07 15:44:20 -07002766//
Colin Crosscfad1192015-11-02 16:43:11 -08002767// Defaults
2768//
Colin Crossca860ac2016-01-04 14:34:37 -08002769type Defaults struct {
Colin Cross635c3b02016-05-18 15:37:25 -07002770 android.ModuleBase
Colin Cross1f44a3a2017-07-07 14:33:33 -07002771 android.DefaultsModuleBase
Jiyong Park9d452992018-10-03 00:38:19 +09002772 android.ApexModuleBase
Colin Crosscfad1192015-11-02 16:43:11 -08002773}
2774
Patrice Arrudac249c712019-03-19 17:00:29 -07002775// cc_defaults provides a set of properties that can be inherited by other cc
2776// modules. A module can use the properties from a cc_defaults using
2777// `defaults: ["<:default_module_name>"]`. Properties of both modules are
2778// merged (when possible) by prepending the default module's values to the
2779// depending module's values.
Colin Cross36242852017-06-23 15:06:31 -07002780func defaultsFactory() android.Module {
Colin Crosse1d764e2016-08-18 14:18:32 -07002781 return DefaultsFactory()
2782}
2783
Colin Cross36242852017-06-23 15:06:31 -07002784func DefaultsFactory(props ...interface{}) android.Module {
Colin Crossca860ac2016-01-04 14:34:37 -08002785 module := &Defaults{}
Colin Crosscfad1192015-11-02 16:43:11 -08002786
Colin Cross36242852017-06-23 15:06:31 -07002787 module.AddProperties(props...)
2788 module.AddProperties(
Colin Crossca860ac2016-01-04 14:34:37 -08002789 &BaseProperties{},
Dan Willemsen3e5bdf22017-09-13 18:37:08 -07002790 &VendorProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002791 &BaseCompilerProperties{},
2792 &BaseLinkerProperties{},
Paul Duffina37832a2019-07-18 12:31:26 +01002793 &ObjectLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002794 &LibraryProperties{},
Colin Crosse1bb5d02019-09-24 14:55:04 -07002795 &StaticProperties{},
2796 &SharedProperties{},
Colin Cross919281a2016-04-05 16:42:05 -07002797 &FlagExporterProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002798 &BinaryLinkerProperties{},
Colin Crossb916a382016-07-29 17:28:03 -07002799 &TestProperties{},
2800 &TestBinaryProperties{},
Mitch Phillips4e4ab8a2019-09-13 17:32:50 -07002801 &FuzzProperties{},
Colin Crossca860ac2016-01-04 14:34:37 -08002802 &StlProperties{},
Colin Cross16b23492016-01-06 14:41:07 -08002803 &SanitizeProperties{},
Colin Cross665dce92016-04-28 14:50:03 -07002804 &StripProperties{},
Dan Willemsen7424d612016-09-01 13:45:39 -07002805 &InstallerProperties{},
Dan Willemsena03cf6d2016-09-26 15:45:04 -07002806 &TidyProperties{},
Dan Willemsen581341d2017-02-09 16:16:31 -08002807 &CoverageProperties{},
Jayant Chowdhary3e231fd2017-02-08 13:45:53 -08002808 &SAbiProperties{},
Justin Yun4b2382f2017-07-26 14:22:10 +09002809 &VndkProperties{},
Stephen Craneba090d12017-05-09 15:44:35 -07002810 &LTOProperties{},
Pirama Arumuga Nainarada83ec2017-08-31 23:38:27 -07002811 &PgoProperties{},
Dan Willemsen6424d172018-03-08 13:27:59 -08002812 &android.ProtoProperties{},
Colin Crosse1d764e2016-08-18 14:18:32 -07002813 )
Colin Crosscfad1192015-11-02 16:43:11 -08002814
Jooyung Hancc372c52019-09-25 15:18:44 +09002815 android.InitDefaultsModule(module)
Colin Cross36242852017-06-23 15:06:31 -07002816
2817 return module
Colin Crosscfad1192015-11-02 16:43:11 -08002818}
2819
Jiyong Park6a43f042017-10-12 23:05:00 +09002820func squashVendorSrcs(m *Module) {
2821 if lib, ok := m.compiler.(*libraryDecorator); ok {
2822 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2823 lib.baseCompiler.Properties.Target.Vendor.Srcs...)
2824
2825 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2826 lib.baseCompiler.Properties.Target.Vendor.Exclude_srcs...)
2827 }
2828}
2829
Jiyong Parkf9332f12018-02-01 00:54:12 +09002830func squashRecoverySrcs(m *Module) {
2831 if lib, ok := m.compiler.(*libraryDecorator); ok {
2832 lib.baseCompiler.Properties.Srcs = append(lib.baseCompiler.Properties.Srcs,
2833 lib.baseCompiler.Properties.Target.Recovery.Srcs...)
2834
2835 lib.baseCompiler.Properties.Exclude_srcs = append(lib.baseCompiler.Properties.Exclude_srcs,
2836 lib.baseCompiler.Properties.Target.Recovery.Exclude_srcs...)
2837 }
2838}
2839
Colin Cross7228ecd2019-11-18 16:00:16 -08002840var _ android.ImageInterface = (*Module)(nil)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002841
Colin Cross7228ecd2019-11-18 16:00:16 -08002842func (m *Module) ImageMutatorBegin(mctx android.BaseModuleContext) {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002843 // Sanity check
Logan Chienf3511742017-10-31 18:04:35 +08002844 vendorSpecific := mctx.SocSpecific() || mctx.DeviceSpecific()
Justin Yun9357f4a2018-11-28 15:14:47 +09002845 productSpecific := mctx.ProductSpecific()
Logan Chienf3511742017-10-31 18:04:35 +08002846
2847 if m.VendorProperties.Vendor_available != nil && vendorSpecific {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002848 mctx.PropertyErrorf("vendor_available",
Jiyong Park2db76922017-11-08 16:03:48 +09002849 "doesn't make sense at the same time as `vendor: true`, `proprietary: true`, or `device_specific:true`")
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002850 }
Logan Chienf3511742017-10-31 18:04:35 +08002851
2852 if vndkdep := m.vndkdep; vndkdep != nil {
2853 if vndkdep.isVndk() {
Justin Yun0ecf0b22020-02-28 15:07:59 +09002854 if vendorSpecific || productSpecific {
Logan Chienf3511742017-10-31 18:04:35 +08002855 if !vndkdep.isVndkExt() {
2856 mctx.PropertyErrorf("vndk",
2857 "must set `extends: \"...\"` to vndk extension")
Justin Yun0ecf0b22020-02-28 15:07:59 +09002858 } else if m.VendorProperties.Vendor_available != nil {
2859 mctx.PropertyErrorf("vendor_available",
2860 "must not set at the same time as `vndk: {extends: \"...\"}`")
Logan Chienf3511742017-10-31 18:04:35 +08002861 }
2862 } else {
2863 if vndkdep.isVndkExt() {
2864 mctx.PropertyErrorf("vndk",
Justin Yun0ecf0b22020-02-28 15:07:59 +09002865 "must set `vendor: true` or `product_specific: true` to set `extends: %q`",
Logan Chienf3511742017-10-31 18:04:35 +08002866 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002867 }
2868 if m.VendorProperties.Vendor_available == nil {
2869 mctx.PropertyErrorf("vndk",
2870 "vendor_available must be set to either true or false when `vndk: {enabled: true}`")
Logan Chienf3511742017-10-31 18:04:35 +08002871 }
2872 }
2873 } else {
2874 if vndkdep.isVndkSp() {
2875 mctx.PropertyErrorf("vndk",
2876 "must set `enabled: true` to set `support_system_process: true`")
Logan Chienf3511742017-10-31 18:04:35 +08002877 }
2878 if vndkdep.isVndkExt() {
2879 mctx.PropertyErrorf("vndk",
2880 "must set `enabled: true` to set `extends: %q`",
2881 m.getVndkExtendsModuleName())
Logan Chienf3511742017-10-31 18:04:35 +08002882 }
Justin Yun8effde42017-06-23 19:24:43 +09002883 }
2884 }
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002885
Jiyong Parkf9332f12018-02-01 00:54:12 +09002886 var coreVariantNeeded bool = false
Yifan Hong1b3348d2020-01-21 15:53:22 -08002887 var ramdiskVariantNeeded bool = false
Jiyong Parkf9332f12018-02-01 00:54:12 +09002888 var recoveryVariantNeeded bool = false
2889
Inseob Kim64c43952019-08-26 16:52:35 +09002890 var vendorVariants []string
Justin Yun5f7f7e82019-11-18 19:52:14 +09002891 var productVariants []string
Inseob Kim64c43952019-08-26 16:52:35 +09002892
2893 platformVndkVersion := mctx.DeviceConfig().PlatformVndkVersion()
Justin Yun5f7f7e82019-11-18 19:52:14 +09002894 boardVndkVersion := mctx.DeviceConfig().VndkVersion()
2895 productVndkVersion := mctx.DeviceConfig().ProductVndkVersion()
2896 if boardVndkVersion == "current" {
2897 boardVndkVersion = platformVndkVersion
2898 }
2899 if productVndkVersion == "current" {
2900 productVndkVersion = platformVndkVersion
Inseob Kim64c43952019-08-26 16:52:35 +09002901 }
2902
Justin Yun5f7f7e82019-11-18 19:52:14 +09002903 if boardVndkVersion == "" {
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002904 // If the device isn't compiling against the VNDK, we always
2905 // use the core mode.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002906 coreVariantNeeded = true
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002907 } else if _, ok := m.linker.(*llndkStubDecorator); ok {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002908 // LL-NDK stubs only exist in the vendor and product variants,
2909 // since the real libraries will be used in the core variant.
Inseob Kim64c43952019-08-26 16:52:35 +09002910 vendorVariants = append(vendorVariants,
2911 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002912 boardVndkVersion,
2913 )
2914 productVariants = append(productVariants,
2915 platformVndkVersion,
2916 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002917 )
Jiyong Park2a454122017-10-19 15:59:33 +09002918 } else if _, ok := m.linker.(*llndkHeadersDecorator); ok {
2919 // ... and LL-NDK headers as well
Inseob Kim64c43952019-08-26 16:52:35 +09002920 vendorVariants = append(vendorVariants,
2921 platformVndkVersion,
Justin Yun5f7f7e82019-11-18 19:52:14 +09002922 boardVndkVersion,
2923 )
2924 productVariants = append(productVariants,
2925 platformVndkVersion,
2926 productVndkVersion,
Inseob Kim64c43952019-08-26 16:52:35 +09002927 )
Inseob Kimeec88e12020-01-22 11:11:29 +09002928 } else if m.isSnapshotPrebuilt() {
Justin Yun71549282017-11-17 12:10:28 +09002929 // Make vendor variants only for the versions in BOARD_VNDK_VERSION and
2930 // PRODUCT_EXTRA_VNDK_VERSIONS.
Inseob Kimeec88e12020-01-22 11:11:29 +09002931 if snapshot, ok := m.linker.(interface {
2932 version() string
2933 }); ok {
2934 vendorVariants = append(vendorVariants, snapshot.version())
2935 } else {
2936 mctx.ModuleErrorf("version is unknown for snapshot prebuilt")
2937 }
Justin Yun0ecf0b22020-02-28 15:07:59 +09002938 } else if m.HasVendorVariant() && !m.isVndkExt() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002939 // This will be available in /system, /vendor and /product
2940 // or a /system directory that is available to vendor and product.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002941 coreVariantNeeded = true
Inseob Kim64c43952019-08-26 16:52:35 +09002942 vendorVariants = append(vendorVariants, platformVndkVersion)
Justin Yun5f7f7e82019-11-18 19:52:14 +09002943 productVariants = append(productVariants, platformVndkVersion)
Inseob Kimbc093672019-11-01 11:29:44 +09002944 // VNDK modules must not create BOARD_VNDK_VERSION variant because its
2945 // code is PLATFORM_VNDK_VERSION.
2946 // On the other hand, vendor_available modules which are not VNDK should
2947 // also build BOARD_VNDK_VERSION because it's installed in /vendor.
Justin Yun5f7f7e82019-11-18 19:52:14 +09002948 // vendor_available modules are also available to /product.
Inseob Kimbc093672019-11-01 11:29:44 +09002949 if !m.IsVndk() {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002950 vendorVariants = append(vendorVariants, boardVndkVersion)
2951 productVariants = append(productVariants, productVndkVersion)
Inseob Kim64c43952019-08-26 16:52:35 +09002952 }
Logan Chienf3511742017-10-31 18:04:35 +08002953 } else if vendorSpecific && String(m.Properties.Sdk_version) == "" {
Jiyong Park2db76922017-11-08 16:03:48 +09002954 // This will be available in /vendor (or /odm) only
Justin Yun5f7f7e82019-11-18 19:52:14 +09002955 vendorVariants = append(vendorVariants, boardVndkVersion)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07002956 } else {
2957 // This is either in /system (or similar: /data), or is a
2958 // modules built with the NDK. Modules built with the NDK
2959 // will be restricted using the existing link type checks.
Jiyong Parkf9332f12018-02-01 00:54:12 +09002960 coreVariantNeeded = true
2961 }
2962
Justin Yun5f7f7e82019-11-18 19:52:14 +09002963 if boardVndkVersion != "" && productVndkVersion != "" {
2964 if coreVariantNeeded && productSpecific && String(m.Properties.Sdk_version) == "" {
2965 // The module has "product_specific: true" that does not create core variant.
2966 coreVariantNeeded = false
2967 productVariants = append(productVariants, productVndkVersion)
2968 }
2969 } else {
2970 // Unless PRODUCT_PRODUCT_VNDK_VERSION is set, product partition has no
2971 // restriction to use system libs.
2972 // No product variants defined in this case.
2973 productVariants = []string{}
2974 }
2975
Yifan Hong1b3348d2020-01-21 15:53:22 -08002976 if Bool(m.Properties.Ramdisk_available) {
2977 ramdiskVariantNeeded = true
2978 }
2979
2980 if m.ModuleBase.InstallInRamdisk() {
2981 ramdiskVariantNeeded = true
2982 coreVariantNeeded = false
2983 }
2984
Jiyong Parkf9332f12018-02-01 00:54:12 +09002985 if Bool(m.Properties.Recovery_available) {
2986 recoveryVariantNeeded = true
2987 }
2988
2989 if m.ModuleBase.InstallInRecovery() {
2990 recoveryVariantNeeded = true
2991 coreVariantNeeded = false
2992 }
2993
Inseob Kim64c43952019-08-26 16:52:35 +09002994 for _, variant := range android.FirstUniqueStrings(vendorVariants) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09002995 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, VendorVariationPrefix+variant)
2996 }
2997
2998 for _, variant := range android.FirstUniqueStrings(productVariants) {
2999 m.Properties.ExtraVariants = append(m.Properties.ExtraVariants, ProductVariationPrefix+variant)
Jiyong Parkf9332f12018-02-01 00:54:12 +09003000 }
Colin Cross7228ecd2019-11-18 16:00:16 -08003001
Yifan Hong1b3348d2020-01-21 15:53:22 -08003002 m.Properties.RamdiskVariantNeeded = ramdiskVariantNeeded
Colin Cross7228ecd2019-11-18 16:00:16 -08003003 m.Properties.RecoveryVariantNeeded = recoveryVariantNeeded
3004 m.Properties.CoreVariantNeeded = coreVariantNeeded
3005}
3006
3007func (c *Module) CoreVariantNeeded(ctx android.BaseModuleContext) bool {
3008 return c.Properties.CoreVariantNeeded
3009}
3010
Yifan Hong1b3348d2020-01-21 15:53:22 -08003011func (c *Module) RamdiskVariantNeeded(ctx android.BaseModuleContext) bool {
3012 return c.Properties.RamdiskVariantNeeded
3013}
3014
Colin Cross7228ecd2019-11-18 16:00:16 -08003015func (c *Module) RecoveryVariantNeeded(ctx android.BaseModuleContext) bool {
3016 return c.Properties.RecoveryVariantNeeded
3017}
3018
3019func (c *Module) ExtraImageVariations(ctx android.BaseModuleContext) []string {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003020 return c.Properties.ExtraVariants
Colin Cross7228ecd2019-11-18 16:00:16 -08003021}
3022
3023func (c *Module) SetImageVariation(ctx android.BaseModuleContext, variant string, module android.Module) {
3024 m := module.(*Module)
Yifan Hong1b3348d2020-01-21 15:53:22 -08003025 if variant == android.RamdiskVariation {
3026 m.MakeAsPlatform()
3027 } else if variant == android.RecoveryVariation {
Colin Cross7228ecd2019-11-18 16:00:16 -08003028 m.MakeAsPlatform()
3029 squashRecoverySrcs(m)
3030 } else if strings.HasPrefix(variant, VendorVariationPrefix) {
Justin Yun5f7f7e82019-11-18 19:52:14 +09003031 m.Properties.ImageVariationPrefix = VendorVariationPrefix
Colin Cross7228ecd2019-11-18 16:00:16 -08003032 m.Properties.VndkVersion = strings.TrimPrefix(variant, VendorVariationPrefix)
3033 squashVendorSrcs(m)
Inseob Kimeec88e12020-01-22 11:11:29 +09003034
3035 // Makefile shouldn't know vendor modules other than BOARD_VNDK_VERSION.
3036 // Hide other vendor variants to avoid collision.
3037 vndkVersion := ctx.DeviceConfig().VndkVersion()
3038 if vndkVersion != "current" && vndkVersion != "" && vndkVersion != m.Properties.VndkVersion {
3039 m.Properties.HideFromMake = true
3040 m.SkipInstall()
3041 }
Justin Yun5f7f7e82019-11-18 19:52:14 +09003042 } else if strings.HasPrefix(variant, ProductVariationPrefix) {
3043 m.Properties.ImageVariationPrefix = ProductVariationPrefix
3044 m.Properties.VndkVersion = strings.TrimPrefix(variant, ProductVariationPrefix)
3045 squashVendorSrcs(m)
Dan Willemsen4416e5d2017-04-06 12:43:22 -07003046 }
3047}
3048
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003049func getCurrentNdkPrebuiltVersion(ctx DepsContext) string {
Colin Cross6510f912017-11-29 00:27:14 -08003050 if ctx.Config().PlatformSdkVersionInt() > config.NdkMaxPrebuiltVersionInt {
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003051 return strconv.Itoa(config.NdkMaxPrebuiltVersionInt)
3052 }
Colin Cross6510f912017-11-29 00:27:14 -08003053 return ctx.Config().PlatformSdkVersion()
Jayant Chowdhary6e8115a2017-05-09 10:21:52 -07003054}
3055
Sasha Smundak2a4549e2018-11-05 16:49:08 -08003056func kytheExtractAllFactory() android.Singleton {
3057 return &kytheExtractAllSingleton{}
3058}
3059
3060type kytheExtractAllSingleton struct {
3061}
3062
3063func (ks *kytheExtractAllSingleton) GenerateBuildActions(ctx android.SingletonContext) {
3064 var xrefTargets android.Paths
3065 ctx.VisitAllModules(func(module android.Module) {
3066 if ccModule, ok := module.(xref); ok {
3067 xrefTargets = append(xrefTargets, ccModule.XrefCcFiles()...)
3068 }
3069 })
3070 // TODO(asmundak): Perhaps emit a rule to output a warning if there were no xrefTargets
3071 if len(xrefTargets) > 0 {
3072 ctx.Build(pctx, android.BuildParams{
3073 Rule: blueprint.Phony,
3074 Output: android.PathForPhony(ctx, "xref_cxx"),
3075 Inputs: xrefTargets,
3076 //Default: true,
3077 })
3078 }
3079}
3080
Colin Cross06a931b2015-10-28 17:23:31 -07003081var Bool = proptools.Bool
Colin Cross38b40df2018-04-10 16:14:46 -07003082var BoolDefault = proptools.BoolDefault
Nan Zhang0007d812017-11-07 10:57:05 -08003083var BoolPtr = proptools.BoolPtr
3084var String = proptools.String
3085var StringPtr = proptools.StringPtr